Control: retile -1 bandwidthd-pgsql: incorrect use of dbconfig-common
Control: tags -1 patch

Hi Andreas,

On 02-07-15 20:21, Paul Gevers wrote:
> On 01-07-15 10:25, Andreas Henriksson wrote:
>> Feel free to reassign back if/when you're confident in dbconfig-common
>> working as expected and think action should be taken on the
>> bandwidthd(-pgsql) side.
> 
> Maybe it needs fixes on both sides :) . Anyways, I will investigate
> further, but I am currently short on time. Probably the weekend will see
> progress.

Yes, I am confident that the change only exposed problems in
bandwidth-pgsql that were there before. So I think your "fix" just aids
to hide the problem again. (And yes, I was surprised to read in the
man-page of sh that if the first part of an && list fails, the shell
doesn't fail with set -e.)

I installed bandwidthd-pgsql on my Jessie system and had to fix multiple
issues in the php files before even the web-pages worked. Also I think
it is your intend that the package has a local postgresql database, so I
suggest you recommend the server package. I found a typo in the prerm
script calling dbc's postrm script instead of the prerm script. This
messed up de-installs. And lastly the order in postinst proved to be
wrong. The answers that I gave to dbconfig-common only propagated to the
other configuration files during re-installation, and not during the run
where I answered those questions.

Lastly, with the attached debdiff (feel free to use all or part, however
you like), I was able to install the package and have it running with
only one manual tweak at the default debconf level: I had to set the
host in the configuration files to "127.0.0.1" instead of empty
(localhost probably works too), because by default postgresql doesn't
allow password login via Unix sockets and the user that runs the
web-site is www-data and not the bandwidthdpgsql user. This last item IS
something that needs improvement in dbconfig-common, there is a bug for
this, #703277, which I finally really understand.

Bottom line, with postgresql installed and my changes, the
bandwidth-pgsql package installs and is working straight from there. (I
am surprised to see that there is no index.php file, you now have to
know what specific URL you want to look at.)

Please feel free to ask for advice if needed.

Paul

PS, even with the webpages fixed, my apache error log is full of very
similar messages like the following:
[Sat Jul 04 14:56:13.791124 2015] [:error] [pid 13635] [client
::1:49677] PHP Notice:  Undefined offset: 1016 in
/var/lib/bandwidthd/htdocs/graph.php on line 38, referer:
http://localhost/bandwidthd/sensors.php?sensor_id=1&interval=86400&limit=20&graphs=on&subnet=0.0.0.0%2F0
diff -Nru bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.config 
bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.config
--- bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.config 2013-06-14 
00:41:25.000000000 +0200
+++ bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.config 2015-07-03 
11:53:57.000000000 +0200
@@ -126,3 +126,11 @@
 
 db_input low bandwidthd/promisc || true
 db_go || true
+
+# source dbconfig-common shell library, and call the hook function
+if [ -f /usr/share/dbconfig-common/dpkg/config.pgsql ]; then
+       . /usr/share/dbconfig-common/dpkg/config.pgsql 
+               dbc_first_version="2.0.1+cvs20050208-12"
+               dbc_load_include="php:/etc/bandwidthd/debian-db.php"
+               dbc_go bandwidthd-pgsql $@
+fi
diff -Nru bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.postinst 
bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.postinst
--- bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.postinst       
2013-06-14 00:41:25.000000000 +0200
+++ bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.postinst       
2015-07-03 21:59:36.000000000 +0200
@@ -13,6 +13,14 @@
 # Source dbconfig-common library.
 . /usr/share/dbconfig-common/dpkg/postinst.pgsql
 
+# Calling dbc first because we are using the answers later
+dbc_first_version="2.0.1+cvs20050208-12"
+
+dbc_generate_include=php:/etc/bandwidthd/debian-db.php
+dbc_generate_include_owner="www-data:www-data"
+dbc_generate_include_perms="660"
+dbc_go bandwidthd-pgsql $@
+
 # -------------------------------------------------------------
 # Create bandwidthd.conf based on debconf data, and install it.
 # -------------------------------------------------------------
@@ -126,15 +134,6 @@
 
 
 
-       dbc_first_version="2.0.1+cvs20050208-12"
-
-       dbc_generate_include=php:/etc/bandwidthd/debian-db.php
-       dbc_generate_include_owner="www-data:www-data"
-       dbc_generate_include_perms="660"
-       dbc_dbfile_owner="www-data:www-data"
-       dbc_dbfile_perms="0660"
-
-       dbc_go bandwidthd-pgsql $@
 
 
 
diff -Nru bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.prerm 
bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.prerm
--- bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.prerm  2012-03-08 
18:02:09.000000000 +0100
+++ bandwidthd-2.0.1+cvs20090917/debian/bandwidthd-pgsql.prerm  2015-07-03 
16:50:58.000000000 +0200
@@ -8,7 +8,7 @@
 
 # Hook up the dbconfig-common library.
 . /usr/share/debconf/confmodule
-. /usr/share/dbconfig-common/dpkg/postrm
+. /usr/share/dbconfig-common/dpkg/prerm
 dbc_go bandwidthd-pgsql $@
 
 #DEBHELPER#
diff -Nru bandwidthd-2.0.1+cvs20090917/debian/changelog 
bandwidthd-2.0.1+cvs20090917/debian/changelog
--- bandwidthd-2.0.1+cvs20090917/debian/changelog       2015-06-16 
14:51:31.000000000 +0200
+++ bandwidthd-2.0.1+cvs20090917/debian/changelog       2015-07-04 
15:48:00.000000000 +0200
@@ -1,3 +1,19 @@
+bandwidthd (2.0.1+cvs20090917-8.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Improve use of dbconfig-common for bandwidthd-pgsql (Closes: #789445)
+    - it never created a working configuration file
+    - it didn't ask for cleanup
+    - it didn't recommend postgresl server
+    - the answers from dbconfig-common were used before the questions
+      were asked, yielding old answers upon upgrade, and non-functional
+      defaults when installing
+    - Typo in prerm script prevented proper clean-up on removal
+  * Add patch to change short <? notation to <?php
+  * Add patch to replace deprecated $HTTP_GET_VARS by $_GET
+  
+ -- Paul Gevers <elb...@debian.org>  Fri, 03 Jul 2015 11:16:32 +0200
+
 bandwidthd (2.0.1+cvs20090917-8) unstable; urgency=medium
 
   * Add debian/patches/fix-gcc-5-ftbfs.patch (Closes: #777794)
diff -Nru bandwidthd-2.0.1+cvs20090917/debian/control 
bandwidthd-2.0.1+cvs20090917/debian/control
--- bandwidthd-2.0.1+cvs20090917/debian/control 2013-07-20 18:25:40.000000000 
+0200
+++ bandwidthd-2.0.1+cvs20090917/debian/control 2015-07-04 16:03:35.000000000 
+0200
@@ -34,7 +34,7 @@
          ucf,
          ${misc:Depends},
          ${shlibs:Depends}
-Recommends: php5, php5-gd, php5-pgsql
+Recommends: php5, php5-gd, php5-pgsql, postgresql
 Suggests: apache2
 Conflicts: apache2 (<< 2.4), bandwidthd
 Description: Tracks usage of TCP/IP and builds html files with graphs
diff -Nru 
bandwidthd-2.0.1+cvs20090917/debian/patches/convert_short_php_syntax_to_long.patch
 
bandwidthd-2.0.1+cvs20090917/debian/patches/convert_short_php_syntax_to_long.patch
--- 
bandwidthd-2.0.1+cvs20090917/debian/patches/convert_short_php_syntax_to_long.patch
  1970-01-01 01:00:00.000000000 +0100
+++ 
bandwidthd-2.0.1+cvs20090917/debian/patches/convert_short_php_syntax_to_long.patch
  2015-07-03 23:06:15.000000000 +0200
@@ -0,0 +1,92 @@
+Description: Multiple php file were missing the php magic syntax
+ causing the rendering to go wrong and errors like:
+ Call to undefined function connectdb() in XXX
+Author: Paul Gevers <elb...@debian.org>
+
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/include.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/include.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/include.php
+@@ -1,4 +1,4 @@
+-<?
++<?php
+ // Emulate register_globals off
+ if (ini_get('register_globals')) {
+    $superglobals = array($_SERVER, $_ENV,
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/failures.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/failures.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/failures.php
+@@ -1,4 +1,4 @@
+-<?
++<?php
+ include("include.php");
+ $subtitle = "Failure Report";
+ include("header.php");
+@@ -15,7 +15,7 @@ if ($HTTP_GET_VARS['reset_links'] != "")
+ ?>
+ 
+ <h3>Failed Routers</h3>
+-<?
++<?php
+ $res = pg_query("
+ SELECT sensor_name, management_url, name as loc_name, date_trunc('seconds', 
min(now()-last_connection))- interval '4 minutes' as missing 
+ FROM sensors, locations 
+@@ -43,7 +43,7 @@ else
+ <TABLE width=100% cellpadding=0 cellspacing=0>
+ <TR><TH class=row-header-left>First Tower<TH class=row-header-middle>Second 
Tower<TH class=row-header-middle>First Router
+ <TH class=row-header-middle>Second Router<TH class=row-header-right>Last 
Update
+-<?
++<?php
+ $links = pg_query("
+ SELECT loc_a.name as loc_a_name, loc_b.name as loc_b_name, sens_a.sensor_id 
as sens_a_id, sens_a.sensor_name as sens_a_name,
+     sens_a.interface as sens_a_interface, sens_b.sensor_id as sens_b_id, 
sens_b.sensor_name as sens_b_name,
+@@ -69,7 +69,7 @@ while ($r = @pg_fetch_array($links))
+ </table>
+ <h3>Low Rates</h3>
+ </CENTER>
+-<?
++<?php
+ /*$res = pg_query("SELECT sensor_name, interface, management_url, signal, 
wireless from sensors, extension_log 
+       WHERE sensors.sensor_id = extension_log.sensor_id and wireless like 
'%Frequency:5.%'    
+               and wireless not like '%Bit Rate:0kb/s%' order by signal
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/details.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/details.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/details.php
+@@ -1,4 +1,4 @@
+-<?
++<?php
+ include("include.php");
+ include("header.php");
+ 
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/location_statistics.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/location_statistics.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/location_statistics.php
+@@ -1,10 +1,10 @@
+-<?
++<?php
+ include("include.php");
+ $subtitle = "Location Statistics";
+ include("header.php");
+ ?>
+ <center><img src="legend.gif"></center>
+-<?
++<?php
+ $db = ConnectDb();
+ 
+ $location_id = $HTTP_GET_VARS['location_id'];
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/sensors.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/sensors.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/sensors.php
+@@ -32,7 +32,7 @@ $db = ConnectDb();
+ <table width="100%" cellspacing=0 cellpadding=5 border=1>
+ <tr>
+ <td>
+-<?
++<?php
+ $sql = "SELECT sensor_name, interface, sensor_id from sensors order by 
sensor_name, interface;";
+ $result = @pg_query($sql);
+ if (!$result)
diff -Nru 
bandwidthd-2.0.1+cvs20090917/debian/patches/replace_depricated_HTTP_GET_VARS_by_GET.patch
 
bandwidthd-2.0.1+cvs20090917/debian/patches/replace_depricated_HTTP_GET_VARS_by_GET.patch
--- 
bandwidthd-2.0.1+cvs20090917/debian/patches/replace_depricated_HTTP_GET_VARS_by_GET.patch
   1970-01-01 01:00:00.000000000 +0100
+++ 
bandwidthd-2.0.1+cvs20090917/debian/patches/replace_depricated_HTTP_GET_VARS_by_GET.patch
   2015-07-04 14:48:00.000000000 +0200
@@ -0,0 +1,61 @@
+Description: HTTP_GET_VARS is deprecated, replace with _GET
+Author: Paul Gevers <elb...@debian.org>
+
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/failures.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/failures.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/failures.php
+@@ -7,7 +7,7 @@ $db = ConnectDb();
+ 
+ $PHP_SELF = "failures.php";
+ 
+-if ($HTTP_GET_VARS['reset_links'] != "")
++if ($_GET['reset_links'] != "")
+       {
+       pg_query("delete from links where last_update < now()-interval '10 
minutes';");
+       header("Location: $PHP_SELF");
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/location_statistics.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/location_statistics.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/location_statistics.php
+@@ -7,7 +7,7 @@ include("header.php");
+ <?php
+ $db = ConnectDb();
+ 
+-$location_id = $HTTP_GET_VARS['location_id'];
++$location_id = $_GET['location_id'];
+ $locations = pg_query("SELECT * from locations where id = $location_id");
+ if (!$locations)
+     echo "<TR><TD>No matching locations in database...</center>";
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/manage/manage_sensors.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/manage/manage_sensors.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/manage/manage_sensors.php
+@@ -22,9 +22,9 @@ if ($HTTP_POST_VARS['submit'] == "Update
+ 
+ include("manage_header.php");
+ 
+-if ($HTTP_GET_VARS['del_sensor'] != "")
++if ($_GET['del_sensor'] != "")
+     {
+-      $result = pg_query("select * from sensors where sensor_name = 
'".$HTTP_GET_VARS['del_sensor']."';");
++      $result = pg_query("select * from sensors where sensor_name = 
'".$_GET['del_sensor']."';");
+       while ($r = @pg_fetch_array($result))
+               {
+               echo("Please wait while deleting records from tables...<BR>\n");
+Index: bandwidthd-2.0.1+cvs20090917/phphtdocs/manage/manage_symbols.php
+===================================================================
+--- bandwidthd-2.0.1+cvs20090917.orig/phphtdocs/manage/manage_symbols.php
++++ bandwidthd-2.0.1+cvs20090917/phphtdocs/manage/manage_symbols.php
+@@ -12,9 +12,9 @@ if ($HTTP_POST_VARS['submit'] == "Add Sl
+       exit(0);
+       }
+ 
+-if ($HTTP_GET_VARS['del_slice'] != "")
++if ($_GET['del_slice'] != "")
+       {
+-      pg_query("delete from slices where id = 
".$HTTP_GET_VARS['del_slice'].";");
++      pg_query("delete from slices where id = ".$_GET['del_slice'].";");
+       header("Location: ".$PHP_SELF);
+       exit(0);        
+       }
diff -Nru bandwidthd-2.0.1+cvs20090917/debian/patches/series 
bandwidthd-2.0.1+cvs20090917/debian/patches/series
--- bandwidthd-2.0.1+cvs20090917/debian/patches/series  2015-06-16 
14:48:10.000000000 +0200
+++ bandwidthd-2.0.1+cvs20090917/debian/patches/series  2015-07-04 
14:11:17.000000000 +0200
@@ -10,3 +10,5 @@
 0010-Add-proper-script-header-and-use-for-loop-since-echo.patch
 0011-Fetch-database-credentials-from-external-file.patch
 fix-gcc-5-ftbfs.patch
+convert_short_php_syntax_to_long.patch
+replace_depricated_HTTP_GET_VARS_by_GET.patch

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to