hi there,

i did work on a fix for rc bug  #603427[1], but before uploading i would like 
to get some feedback from you, if that would be sufficient, as it isn't a 
small fix.

changelog:

ipplan (4.92a-2) unstable; urgency=low

  * Implement proper configuration handling (Closes: #603427)
    - Add ucf to Pre-Depends
    - Move 'debconf (>= 0.2.26) | debconf-2.0' to Pre-Depends
    - Write database settings collected via debconf into /etc/ipplan/db.php
    - Register /etc/ipplan/db.php via ucf in postinst
    - Deregister /etc/ipplan/db.php via ucf and remove variants in postrm on
      purge
    - Migrate /etc/ipplan/config.php to /etc/ipplan/local_conf.php, if user
      has modified the file
    - Adjust README.Debian related to our new way to configure ipplan
  * Add 11_user_config.dpatch to patch shipped config to also read our config
    files
  * Add 05_fix_config_syntax.dpatch to fix broken default config
  * Only call postinst and config if we install the package or on
    dpkg-reconfigure

 -- Jan Wagner <w...@cyconet.org>  Tue, 16 Nov 2010 21:00:25 +0100

diffstat:

 README.Debian                       |   15 +++---
 changelog                           |   20 ++++++++
 config                              |   18 ++++---
 control                             |    3 -
 dirs                                |    2 
 local_conf.php                      |    4 +
 patches/00list                      |    2 
 patches/05_fix_config_syntax.dpatch |   18 +++++++
 patches/11_user_config.dpatch       |   16 ++++++
 postinst                            |   68 ++++++++++++++++++-----------
 postrm                              |   17 +++++++
 preinst                             |   84 
++++++++++++++++++++++++++++++++++++
 rules                               |   17 +++----
 13 files changed, 233 insertions(+), 51 deletions(-)

many thanks, jan.
[1] http://bugs.debian.org/603427
-- 
Never write mail to <w...@spamfalle.info>, you have been warned!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d-- s+: a C+++ UL++++ P+ L+++ E--- W+++ N+++ o++ K++ w--- O M V- PS PE Y++
PGP++ t-- 5 X R tv- b+ DI D+ G++ e++ h---- r+++ y++++ 
------END GEEK CODE BLOCK------
Index: control
===================================================================
--- control	(revision 2130)
+++ control	(revision 2268)
@@ -10,7 +10,8 @@
 
 Package: ipplan
 Architecture: all
-Depends: ${misc:Depends}, apache2 | httpd, php5 | php5-cgi | libapache2-mod-php5 | libapache-mod-php5 | php4 | php4-cgi | libapache2-mod-php4 | libapache-mod-php4, debconf (>= 0.2.26) | debconf-2.0, mysql-client | postgresql-client, wwwconfig-common, php5-mysql | php4-mysql | php5-pgsql | php4-pgsql, libphp-adodb, libphp-phplayersmenu, libphp-phpmailer
+Pre-Depends: ucf (>= 2.0020), debconf (>= 0.2.26) | debconf-2.0
+Depends: ${misc:Depends}, apache2 | httpd, php5 | php5-cgi | libapache2-mod-php5 | libapache-mod-php5 | php4 | php4-cgi | libapache2-mod-php4 | libapache-mod-php4, mysql-client | postgresql-client, wwwconfig-common, php5-mysql | php4-mysql | php5-pgsql | php4-pgsql, libphp-adodb, libphp-phplayersmenu, libphp-phpmailer
 Recommends: mysql-server, postgresql, php5-snmp | php4-snmp
 Suggests: nmap
 Description: web-based IP address manager and tracker
Index: postinst
===================================================================
--- postinst	(revision 2130)
+++ postinst	(revision 2268)
@@ -2,11 +2,14 @@
 
 set -e
 
+MCONFDIR=/usr/share/ipplan/mconf/
+
+# only if we install the package and on dpkg-reconfigure
+if [ "${DEBCONF_RECONFIGURE}" = "1" ]  || [ "$1" = "configure" ] && [ -z "$2" ]; then
+
 . /usr/share/debconf/confmodule
 db_version 2.0 || [ $? -lt 30 ]
 
-if [ "$1" = "configure" ]; then
-
     db_get ipplan/webserver_type
     webservers="$RET"
     restart=""
@@ -64,36 +67,31 @@
 	. /usr/share/wwwconfig-common/mysql-createdb.sh
 	# create user
 	. /usr/share/wwwconfig-common/mysql-createuser.sh
-    fi
 
-    db_stop
+	# write database options into config
+	echo "<?php" > $MCONFDIR/db.php
+	echo "// Please don't edit this file, use local_conf.php to overwrite" >> $MCONFDIR/db.php
+	echo "// You can change this settings with 'dpkg-reconfigure -plow ipplan'." >> $MCONFDIR/db.php
+	echo "defined(\"DBF_TYPE\")|| define(\"DBF_TYPE\", 'mysql');" >> $MCONFDIR/db.php
+	echo "defined(\"DBF_HOST\")|| define(\"DBF_HOST\", '$dbserver');" >> $MCONFDIR/db.php
+	echo "defined(\"DBF_USER\")|| define(\"DBF_USER\", '$dbuser');" >> $MCONFDIR/db.php
+	echo "defined(\"DBF_NAME\")|| define(\"DBF_NAME\", '$dbname');" >> $MCONFDIR/db.php
+	echo "defined(\"DBF_PASSWORD\")|| define(\"DBF_PASSWORD\", '$dbpass');" >> $MCONFDIR/db.php
+	echo "?>" >> $MCONFDIR/db.php
 
-    # write database options into config
-    if [ -e /etc/ipplan/config.php ]; then
-	sed -i -e \
-	"
-	s/\(\.*\"DBF_TYPE\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1mysql\2/;
-	s/\(\.*\"DBF_HOST\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1$dbserver\2/;
-	s/\(\.*\"DBF_USER\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1$dbuser\2/;
-	s/\(\.*\"DBF_NAME\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1$dbname\2/;
-	s/\(\.*\"DBF_PASSWORD\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1$dbpass\2/
-	" \
-	/etc/ipplan/config.php
+    else
 
-	# NOT USING FOR NOW
-	## generate new initial admin passwd
-	#if [ `grep "define(\"ADMINPASSWD\", 'ADMINCRYPTPWD');" /etc/ipplan/config.php | wc -l` -eq "1" ]; then
-	#	adminpasswd=$(tr -dc "[:alnum:]" < /dev/urandom | head -c 10)
-	#	sed -i -e \
-	#	"
-	#	s/\(\.*\"ADMINPASSWD\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1$adminpasswd\2/
-	#	" \
-	#	/etc/ipplan/config.php
-	#fi
+	# leave note, that database has to be configured local
+	echo "<?php" > $MCONFDIR/db.php
+	echo "// You have decided to configure you database yourself!" > $MCONFDIR/db.php
+	echo "// You can change that with 'dpkg-reconfigure -plow ipplan'." > $MCONFDIR/db.php
+	echo "// Please don't edit this file, use local_conf.php to overwrite" >> $MCONFDIR/db.php
+	echo "?>" >> $MCONFDIR/db.php
 
-	chown www-data /usr/share/ipplan/config.php
     fi
 
+    db_stop
+
     # drop owner to www-data of uploaddir
     if ! [ -d /var/spool/ipplan ]; then
 	mkdir /var/spool/ipplan
@@ -113,4 +111,22 @@
     done
 fi
 
+# register config files
+for conffile in db.php ; do
+    # Tell ucf that the file in /usr/share/ipplan is the latest
+    # maintainer version, and let it handle how to manage the real
+    # configuration file in /etc/ipplan.
+    ucf $MCONFDIR/$conffile /etc/ipplan/$conffile
+    ucfr ipplan /etc/ipplan/$conffile
+    # set permissions
+    if [ -f "/etc/ipplan/$conffile" ]; then
+            chown root:www-data /etc/ipplan/$conffile
+            if [ "$conffile" != "db.php" ]; then
+                    chmod 640 /etc/ipplan/$conffile
+            else
+                    chmod 644 /etc/ipplan/$conffile
+            fi
+    fi
+done
+
 #DEBHELPER#
Index: postrm
===================================================================
--- postrm	(revision 2130)
+++ postrm	(revision 2268)
@@ -78,6 +78,23 @@
 
 	if [ "$1" = "purge" ]; then
 		db_purge
+	        for conffile in /etc/ipplan/db.php; do
+			# we mimic dpkg as closely as possible, so we remove configuration
+			# files with dpkg backup extensions too:
+			for ext in '~' '%' .bak .dpkg-tmp .dpkg-new .dpkg-old .dpkg-dist .dpkg-bak .dpkg-del;  do
+				rm -f $conffile$ext
+			done
+			# remove the configuration file itself
+			rm -f $conffile
+			# and finally clear it out from the ucf database
+			if which ucf >/dev/null; then
+				ucf --purge $conffile
+			fi
+			if which ucfr >/dev/null; then
+				ucfr --purge ipplan $conffile
+			fi
+			rm /usr/share/ipplan/mconf/`basename $conffile`
+		done
 	fi
     fi
 fi
Index: preinst
===================================================================
--- preinst	(revision 0)
+++ preinst	(revision 2268)
@@ -0,0 +1,84 @@
+#!/bin/sh
+set -e
+
+# check if we upgrade from a version we have mixed our config with shiped config
+if [ "$1" = "upgrade" ] && [ "$2" ] && dpkg --compare-versions "$2" le "4.92a-1"; then
+	MCONFDIR="/usr/share/ipplan/mconf/"
+	OLDCONFFILE="/etc/ipplan/config.php"
+        # get values from debconf database
+	. /usr/share/debconf/confmodule
+	db_version 2.0 || [ $? -lt 30 ]
+
+	db_get ipplan/mysql/configure
+	if [ "$RET" = true ]; then
+		# collect values
+		db_get ipplan/mysql/dbserver
+		dbserver=$RET
+		db_get ipplan/mysql/dbname
+		dbname=$RET
+		db_get ipplan/mysql/dbuser
+		dbuser=$RET
+	fi
+	db_stop
+
+	# get values from existing config
+	confdbtype=`grep DBF_TYPE $OLDCONFFILE | awk -F"'" {'print $2'}`
+	confdbserver=`grep DBF_HOST $OLDCONFFILE | awk -F"'" {'print $2'}`
+	confdbuser=`grep DBF_USER $OLDCONFFILE | awk -F"'" {'print $2'}`
+	confdbname=`grep DBF_NAME $OLDCONFFILE | awk -F"'" {'print $2'}`
+	confdbpass=`grep DBF_PASSWORD $OLDCONFFILE | awk -F"'" {'print $2'}`
+
+	# if we got all data
+	if [ $confdbtype = "mysql" -a $dbserver = $confdbserver -a $dbuser = $confdbuser -a $dbname = $confdbname ]; then
+		# write setting to seperate db.php
+		if [ ! -d $MCONFDIR ]; then
+			mkdir -p $MCONFDIR
+		fi
+		echo "<?php" > $MCONFDIR/db.php
+		echo "// Please don't edit this file, use local_conf.php to overwrite" >> $MCONFDIR/db.php
+		echo "defined(\"DBF_TYPE\")|| define(\"DBF_TYPE\", '$confdbtype');" >> $MCONFDIR/db.php
+		echo "defined(\"DBF_HOST\")|| define(\"DBF_HOST\", '$confdbserver');" >> $MCONFDIR/db.php
+		echo "defined(\"DBF_USER\")|| define(\"DBF_USER\", '$confdbuser');" >> $MCONFDIR/db.php
+		echo "defined(\"DBF_NAME\")|| define(\"DBF_NAME\", '$confdbname');" >> $MCONFDIR/db.php
+		echo "defined(\"DBF_PASSWORD\")|| define(\"DBF_PASSWORD\", '$confdbpass');" >> $MCONFDIR/db.php
+		echo "?>" >> $MCONFDIR/db.php
+
+		# remove these settings from the existing config
+		sed -i '/^define("DBF_TYPE/d' $OLDCONFFILE
+		sed -i '/^define("DBF_HOST/d' $OLDCONFFILE
+		sed -i '/^define("DBF_USER/d' $OLDCONFFILE
+		sed -i '/^define("DBF_NAME/d' $OLDCONFFILE
+		sed -i '/^define("DBF_PASSWORD/d' $OLDCONFFILE
+	fi
+
+	# move config settings to local_conf.php
+	# create md5sum of our actual config
+	md5sum="$(md5sum $OLDCONFFILE | sed -e 's/ .*//')"
+	# list of md5sums of all configs since etch (with removed database config)
+	old_md5sums="97e0ae5b01f24cf473617dec6fc3fe60 1c9f7955ddc76c300232555a8b3ca80c 25efefcea64c5c87afbe4a7522329d8d a5d713989df3ea8f23f7364c61fa3e26 ff511785e7b164a1d43466d07046c0fb 2be7834668f7b8cfd82331c3adde0402"
+	# check if one of our md5sums matches
+	for old_md5sum in $old_md5sums; do
+		if [ "$md5sum" = "$old_md5sum" ]; then
+			unmodified="1"
+		fi
+	done
+	# migrate config
+	if [ "${unmodified:-0}" = "1" ]; then
+		echo "Obsolete conffile $OLDCONFFILE has been modified by you."
+		echo "Saving as /etc/ipplan/local_conf.php ..."
+		mv -f "$OLDCONFFILE" "$OLDCONFFILE".dpkg-bak
+	else
+		echo "Removing obsolete conffile $OLDCONFFILE ..."
+		mv -f "$OLDCONFFILE" "$OLDCONFFILE".dpkg-del
+	fi
+	echo "<?php" > /etc/ipplan/local_conf.php
+	echo "// This file is intended to overwrite system settings by the user" >> /etc/ipplan/local_conf.php
+	echo "// Please make your config changes in THIS file" >> /etc/ipplan/local_conf.php
+	if [ -x $OLDCONFFILE.dpkg-bak ]; then
+		tail --lines=+2 $OLDCONFFILE | grep -v "^//" >> /etc/ipplan/local_conf.php
+	else
+		echo "?>" >> /etc/ipplan/local_conf.php
+	fi
+
+fi
+#DEBHELPER#
Index: local_conf.php
===================================================================
--- local_conf.php	(revision 0)
+++ local_conf.php	(revision 2268)
@@ -0,0 +1,4 @@
+<?php
+// This file is intended to overwrite system settings by the user
+// Please make your config changes in THIS file
+?>
Index: changelog
===================================================================
--- changelog	(revision 2130)
+++ changelog	(revision 2268)
@@ -1,3 +1,23 @@
+ipplan (4.92a-2) unstable; urgency=low
+
+  * Implement proper configuration handling (Closes: #603427)
+    - Add ucf to Pre-Depends
+    - Move 'debconf (>= 0.2.26) | debconf-2.0' to Pre-Depends
+    - Write database settings collected via debconf into /etc/ipplan/db.php
+    - Register /etc/ipplan/db.php via ucf in postinst
+    - Deregister /etc/ipplan/db.php via ucf and remove variants in postrm on
+      purge
+    - Migrate /etc/ipplan/config.php to /etc/ipplan/local_conf.php, if user
+      has modified the file
+    - Adjust README.Debian related to our new way to configure ipplan
+  * Add 11_user_config.dpatch to patch shipped config to also read our config
+    files
+  * Add 05_fix_config_syntax.dpatch to fix broken default config
+  * Only call postinst and config if we install the package or on
+    dpkg-reconfigure
+
+ -- Jan Wagner <w...@cyconet.org>  Tue, 16 Nov 2010 21:00:25 +0100
+
 ipplan (4.92a-1) unstable; urgency=low
 
   * New Upstream Release
Index: patches/11_user_config.dpatch
===================================================================
--- patches/11_user_config.dpatch	(revision 0)
+++ patches/11_user_config.dpatch	(revision 2268)
@@ -0,0 +1,16 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## 11_user_config.dpatch by Jan Wagner <w...@cyconet.org>
+##
+## DP: Enable use configuration.
+
+...@dpatch@
+diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' ipplan-4.92a~/config.php ipplan-4.92a/config.php
+--- ipplan-4.92a~/config.php	2010-11-19 00:15:48.000000000 +0100
++++ ipplan-4.92a/config.php	2010-11-19 00:17:19.000000000 +0100
+@@ -1,4 +1,6 @@
+ <?php
++require_once("/etc/ipplan/local_conf.php");
++require_once("/etc/ipplan/db.php");
+ 
+ // IPplan v4.92a
+ // Aug 24, 2001

Property changes on: patches/11_user_config.dpatch
___________________________________________________________________
Added: svn:executable
   + *

Index: patches/05_fix_config_syntax.dpatch
===================================================================
--- patches/05_fix_config_syntax.dpatch	(revision 0)
+++ patches/05_fix_config_syntax.dpatch	(revision 2268)
@@ -0,0 +1,18 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## 05_fix_config_syntax.dpatch by Jan Wagner <w...@cyconet.org>
+##
+## DP: Fix broken config statment.
+
+...@dpatch@
+diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' ipplan-4.92a~/config.php ipplan-4.92a/config.php
+--- ipplan-4.92a~/config.php	2009-08-17 23:43:43.000000000 +0200
++++ ipplan-4.92a/config.php	2010-11-19 10:04:33.000000000 +0100
+@@ -48,7 +48,7 @@
+ define("DEBUG", FALSE);
+ // fix possible adodb issues with Oracle - this is the default,
+ // but oci8po driver appears to ignore setting?
+-define ("ADODB_ASSOC_CASE", 0);
++define("ADODB_ASSOC_CASE", 0);
+ 
+ // define some global variables for authentication
+ define("REALM", 'IPplan authentication');

Property changes on: patches/05_fix_config_syntax.dpatch
___________________________________________________________________
Added: svn:executable
   + *

Index: patches/00list
===================================================================
--- patches/00list	(revision 2130)
+++ patches/00list	(revision 2268)
@@ -1 +1,3 @@
+05_fix_config_syntax.dpatch
 10_custom_templates.dpatch
+11_user_config.dpatch
Index: rules
===================================================================
--- rules	(revision 2130)
+++ rules	(revision 2268)
@@ -19,7 +19,6 @@
 	dh_testroot
 	dh_clean -k  --exclude ./themes/default.css.orig
 	dh_installdirs
-	install -d -m 0755 debian/ipplan/usr/share/ipplan/
 	# install php scripts
 	dh_install admin usr/share/ipplan
 	dh_install adodb usr/share/ipplan
@@ -43,19 +42,19 @@
 	# remove unneeded license file
 	rm -rf debian/ipplan/usr/share/ipplan/adodb/license.txt
 	# create config in /etc
-	install -d -m 0755 debian/ipplan/etc/ipplan/
 	install -m 644 debian/apache.conf debian/ipplan/etc/ipplan/
-	mv debian/ipplan/usr/share/ipplan/config.php debian/ipplan/etc/ipplan/
-	dh_link etc/ipplan/config.php usr/share/ipplan/config.php
+	install -m 644 debian/local_conf.php debian/ipplan/etc/ipplan/
 	# secure rights for config
-	chmod 640 debian/ipplan/etc/ipplan/config.php
-	# create symlink to libphp-phplayersmenu
-	dh_link usr/share/php/libphp-phplayersmenu usr/share/ipplan/menus
+	chmod 640 debian/ipplan/usr/share/ipplan/config.php
+	# just add checks, if constants already defined
+	sed -ie 's/define(\(".*"\),/defined(\1) || define(\1,/' debian/ipplan/usr/share/ipplan/config.php
 	# fix some unsecure stuff
 	sed -i -e "s/\\"DNSENABLED\",\ TRUE/\\"DNSENABLED\",\ FALSE/" \
-	debian/ipplan/etc/ipplan/config.php
+	debian/ipplan/usr/share/ipplan/config.php
 	sed -i -e "s/\(\.*\"UPLOADDIRECTORY\"[^'\"]*['\"]\)[^'\"]*\(['\"].*\)/\1\/var\/spool\/ipplan\2/" \
-	debian/ipplan/etc/ipplan/config.php
+	debian/ipplan/usr/share/ipplan/config.php
+	# create symlink to libphp-phplayersmenu
+	dh_link usr/share/php/libphp-phplayersmenu usr/share/ipplan/menus
 
 # Build architecture-independent files here.
 binary-indep: build install
Index: dirs
===================================================================
--- dirs	(revision 0)
+++ dirs	(revision 2268)
@@ -0,0 +1,2 @@
+etc/ipplan/
+usr/share/ipplan/mconf/
Index: config
===================================================================
--- config	(revision 2130)
+++ config	(revision 2268)
@@ -18,12 +18,14 @@
 
 db_get ipplan/mysql/configure || true
 if [ "$RET" = "true" ]; then
-   db_input critical ipplan/mysql/dbserver || true
-   db_input critical ipplan/mysql/dbadmin || true
-   db_input critical ipplan/mysql/dbadmpass || true
-   db_input critical ipplan/mysql/dbuser || true
-   db_input critical ipplan/mysql/dbpass || true
-   db_input medium ipplan/purge || true
-   db_input medium ipplan/mysql/dbname || true
-   db_go || true
+   if [ "$1" = "configure" ] && [ -z "$2" ] || [ "$1" = "reconfigure" ]; then
+	db_input critical ipplan/mysql/dbserver || true
+	db_input critical ipplan/mysql/dbadmin || true
+	db_input critical ipplan/mysql/dbadmpass || true
+	db_input critical ipplan/mysql/dbuser || true
+	db_input critical ipplan/mysql/dbpass || true
+	db_input medium ipplan/purge || true
+	db_input medium ipplan/mysql/dbname || true
+	db_go || true
+   fi
 fi
Index: README.Debian
===================================================================
--- README.Debian	(revision 2130)
+++ README.Debian	(revision 2268)
@@ -44,9 +44,10 @@
 1.3) If you are using InnoDB transaction safe tables, make sure to enable
      transaction support in config.php
 
-2) Modify the password for the admin user and maybe the username in the
-   config.php script.
-   Additional settings can be changed in the config.php script at this stage
+2) Modify the password for the admin user and maybe the username in
+   /etc/ipplan/local_conf.php (see /usr/share/ipplan/config.php for settings
+   you may want to change, but don't edit this file itself!).
+   Additional settings can be changed in local_conf.php script at this stage
    too. See the /usr/share/doc/ipplan/README.gz for more information.
 
 3) Open a web browser and point it to the installation script in the admin
@@ -79,12 +80,12 @@
      php_admin_value open_basedir 'none'
 
 6) For 'Importing using NMAP' (see 14.2 of /usr/share/doc/ipplan/README.gz) you
-   need to set 'define("NMAP", '/usr/bin/nmap');' in /etc/ipplan/config.php and
-   install nmap.
+   need to set 'define("NMAP", '/usr/bin/nmap');' in /etc/ipplan/
+   local_conf.php and install nmap.
 
 7) You can provide custom templates[1]. You may adjust "CUSTOM_CONFIG_DIR"
-   in /etc/ipplan/config.php, just create the directory 'templates/display/' in
-   the custom config directory and place your templates files there.
+   in /etc/ipplan/local_conf.php, just create the directory 'templates/display/'
+   in the custom config directory and place your templates files there.
 
  -- Jan Wagner <w...@cyconet.org>  Sat, 18 Nov 2006 23:53:55 +0100
 [1] http://iptrack.sourceforge.net/documentation/templates.html

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to