[webmin-devel] Virtualmin: Check_Config and Feature_Details

paddy <[email protected]>
Newsgroups gmane.comp.web.webmin.devel
Message-ID <[email protected]>
Jamie,

Sorry this has taken me a while to get around to.

Attached are two patches, but they are as yet rather rough.

They attempt to implement the following on edit_domain:

	config option for 'check_config on page load'
	button for check_config
	features table is now 1x4, instead of 2x2
		col1: feature
		col2: enabled?
		col3: configured?
		col4: details (if -x details-$feature.cgi)
	individual check_$feature_config subs in each feature-$f.pl
	individual details-$feature.cgi redirects

The flaws are no doubt legion, but I feel I should highlight
that _at least_ the following are still on my todo list:

	lang support: 'ui text' -> $test{'ui_text'} as appropriate
	feature plugins
	webalizer (mine is broken ?)
	make details-dir redirect to file manager ? (get my java working)

My approach to 'configured?' is rough and ready.  I started with a 
free-form text return rather than a specific coding, and I've yet to
arrive at position on where such an interface should go.  At least once
I've reached for a check_$feature_config routine for a reassuring binary
'yes we can do that', even though I generally believe in 'try it and
return an error if necessary'.  Given the typical cost of a 
check_$feature_config, more could be done both in terms of checking and
in terms of feedback.  Also, I'm peripherally aware of html techniques that
enable population of a slow rendering table after the rest of the page,
but I'd need to look up the implementation, and I've no idea whether
such a technique would fit in well with webmin. I would have put the 
'check' button at the top or bottom of the column, if I could easily
have worked out how :)

With the 'details' links, I have chosen the easy route with individual 
cgi's and treating the relationship between site and feature as essentially
one-to-one (with the exception of mail which was already there, maybe I've
overlooked others ?).  Nowhere is the latter hack more painfully obvious to 
me than in details-logrotate.

Martin, I really have tried to avoid <td></td> and use <td>&nbsp;</td> :)

Anyway, enough waffle from me.

Please see attached code, feel free to tell me what you think!

Regards,
Paddy
-- 
Perl 6 will give you the big knob. -- Larry Wall
virtualmin_checkconfig_1 (text/plain, 10.1 KB)
diff -urN webmin.orig/virtual-server/config.info webmin/virtual-server/config.info
--- webmin.orig/virtual-server/config.info	2004-10-27 07:01:52.000000000 +0100
+++ webmin/virtual-server/config.info	2004-12-07 16:46:10.000000000 +0000
@@ -21,6 +21,7 @@
 all_namevirtual=All Apache virtual servers are name-based?,1,1-Yes,0-No
 show_features=Show server features on main page?,1,1-Yes,0-No
 ldap=Store users and groups,1,1-In LDAP database,0-In local files
+check_config_upfront=Check configuration status on server page load?,1,1-Yes,0-No
 
 line1.5=Domain owner permissions,11
 edit_afiles=Can edit alias include and reply files?,1,1-Yes,0-No
diff -urN webmin.orig/virtual-server/edit_domain.cgi webmin/virtual-server/edit_domain.cgi
--- webmin.orig/virtual-server/edit_domain.cgi	2004-12-06 15:17:02.000000000 +0000
+++ webmin/virtual-server/edit_domain.cgi	2004-12-07 16:48:36.000000000 +0000
@@ -277,8 +277,12 @@
 	print $fields;
 	}
 
+print "</table></td></tr>\n";
+
 # Show buttons for turning features on and off (if allowed)
-print "<tr> <td colspan=4><hr></td> </tr>\n";
+
+print "<tr $cb> <td><table width=100%>\n";
+
 if ($d->{'disabled'}) {
 	# Disabled, so tell the user that features cannot be changed
 	print "<tr> <td colspan=4 align=center>&nbsp;<br><font color=#ff0000>",
@@ -288,6 +292,17 @@
 	}
 else {
 	# Show features for this domain
+
+	print "<tr $tb> ";
+	print "<td><b>feature</b></td>";
+	print "<td><b>enabled?</b></td>";
+	print "<td>";
+		print "<b>configured?</b>";
+		#print "<input type=submit value='check_config'>";
+	print "</td>";
+	print "<td><b>details</b></td>";
+	print " </tr>\n";
+
 	$i = 0;
 	@dom_features = $aliasdom ? @opt_alias_features : @opt_features;
 	foreach $f (@dom_features) {
@@ -300,7 +315,7 @@
 		# Cannot enable features not in alias
 		next if ($aliasdom && !$aliasdom->{$f});
 
-		print "<tr>\n" if ($i%2 == 0);
+		print "<tr>\n";
 		local $txt = $parentdom ? $text{'edit_sub'.$f} : undef;
 		$txt ||= $text{'edit_'.$f};
 		print "<td><b>",$txt,"</b></td>\n";
@@ -315,9 +330,23 @@
 				$d->{$f} ? "" : "checked", $text{'no'};
 			}
 		else {
-			print "<td><i>$text{'form_unavail'}</i></td>\n";
+			print "<td colspan=3 align=center><i>$text{'form_unavail'}</i></td>\n";
+			next;
 			}
-		print "</tr>\n" if ($i++%2 == 1);
+		if ($config{'check_config_upfront'} || $in{'check_config'}) {
+			local $cfunc = "check_${f}_configured";
+			print "<td>" . &$cfunc($d) . "&nbsp;</td>";
+			}
+		else {
+			print "<td>click below</td>";
+			}
+		if (-x "details-$f.cgi") {
+			print "<td><a href='details-$f.cgi?dom=$d->{'id'}'>$f details</a></td>";
+			}
+		else {
+			print "<td>&nbsp;</td>";
+			}
+		print "</tr>\n"; 
 		}
 
 	foreach $f (@feature_plugins) {
@@ -338,7 +367,7 @@
 			printf"<input type=radio name=$f value=0 %s> %s</td>\n",
 				$d->{$f} ? "" : "checked", $text{'no'};
 			}
-		print "</tr>\n" if ($i++%2 == 1);
+		print "</tr>\n"; 
 		}
 
 	print "</tr>\n";
@@ -355,6 +384,13 @@
 print "<input type=submit value='$text{'edit_save'}'>\n";
 print "</form>\n";
 
+# Check Config button		
+print "<form action=edit_domain.cgi>\n";
+print "<input type=hidden name=dom value='$in{'dom'}'>\n";
+print "<tr><td><input type=submit name='check_config' value='check_config'></td>\n";
+print "<td>check_configdesc</td> </tr>\n";
+print "</form>\n";
+
 print "<hr>\n";
 print "<table>\n";
 
diff -urN webmin.orig/virtual-server/feature-dir.pl webmin/virtual-server/feature-dir.pl
--- webmin.orig/virtual-server/feature-dir.pl	2004-10-28 00:18:42.000000000 +0100
+++ webmin/virtual-server/feature-dir.pl	2004-12-06 16:45:22.000000000 +0000
@@ -91,6 +91,12 @@
 return 0;
 }
 
+# check_dir_configured(&domain)
+sub check_dir_configured
+{
+return (-d $_[0]->{'home'}) ? "exists" : "not there!";
+}
+
 # backup_dir(&domain, file)
 # Backs up the server's home directory in tar format to the given file
 sub backup_dir
diff -urN webmin.orig/virtual-server/feature-dns.pl webmin/virtual-server/feature-dns.pl
--- webmin.orig/virtual-server/feature-dns.pl	2004-10-08 09:09:11.000000000 +0100
+++ webmin/virtual-server/feature-dns.pl	2004-12-06 17:34:35.000000000 +0000
@@ -522,6 +522,16 @@
 return 0;
 }
 
+# check_dns_configured(&domain)
+sub check_dns_configured
+{
+# the way check_clash does it ... (whatabout .disabled?)
+#require_bind(); # presumably
+local ($czone) = &get_bind_zone($_[0]->{'dom'});
+return $czone ? "exists" : "not there!";
+# poor man's version ... bind8 has C style comments and recursive includes ?
+}
+
 # get_bind_pid()
 sub get_bind_pid
 {
diff -urN webmin.orig/virtual-server/feature-ftp.pl webmin/virtual-server/feature-ftp.pl
--- webmin.orig/virtual-server/feature-ftp.pl	2004-09-02 04:25:13.000000000 +0100
+++ webmin/virtual-server/feature-ftp.pl	2004-12-06 18:49:15.000000000 +0000
@@ -258,6 +258,13 @@
 return 0;
 }
 
+# check_ftp_configured(domain)
+sub check_ftp_configured
+{
+local ($cvirt, $cconf) = &get_proftpd_virtual($_[0]->{'ip'});
+return $cvirt ? "exists" : "not there!";
+}
+
 # backup_ftp(&domain, file)
 # Save the virtual server's ProFTPd config as a separate file
 sub backup_ftp
diff -urN webmin.orig/virtual-server/feature-logrotate.pl webmin/virtual-server/feature-logrotate.pl
--- webmin.orig/virtual-server/feature-logrotate.pl	2004-10-05 12:21:14.000000000 +0100
+++ webmin/virtual-server/feature-logrotate.pl	2004-12-07 17:03:58.000000000 +0000
@@ -115,6 +115,22 @@
 return 0;
 }
 
+# check_logrotate_configured(domain)
+sub check_logrotate_configured
+{
+# return 'yes' if -e "/etc/logrotate.d/$_[0]->{'dom'}"; # :)
+&require_logrotate();
+local $conf = &logrotate::get_config();
+foreach $c (@$conf) {
+	if ($c->{'members'}) {
+		foreach $n (@{$c->{'name'}}) {
+			return 'yes' if $n =~ /^$_[0]->{'home'}/;
+			}
+		}
+	}
+return 'no';
+}
+
 # backup_logrotate(&domain, file)
 # Saves the log rotation section for this domain to a file
 sub backup_logrotate
diff -urN webmin.orig/virtual-server/feature-mail.pl webmin/virtual-server/feature-mail.pl
--- webmin.orig/virtual-server/feature-mail.pl	2004-10-28 00:18:52.000000000 +0100
+++ webmin/virtual-server/feature-mail.pl	2004-12-06 18:12:34.000000000 +0000
@@ -263,6 +263,14 @@
 return 0;
 }
 
+# check_mail_configured(domain)
+sub check_mail_configured
+{
+&require_mail();
+local $cfound = is_local_domain($_[0]);
+return ($cfound > 0) ? "yup!" : "nope!".$cfound;
+}
+
 # is_local_domain(domain)
 # Returns 1 if some domain is used for mail on this system, 0 if not
 sub is_local_domain
diff -urN webmin.orig/virtual-server/feature-mysql.pl webmin/virtual-server/feature-mysql.pl
--- webmin.orig/virtual-server/feature-mysql.pl	2004-11-06 00:27:47.000000000 +0000
+++ webmin/virtual-server/feature-mysql.pl	2004-12-06 16:23:17.000000000 +0000
@@ -178,6 +178,12 @@
 return 0;
 }
 
+# check_mysql_configured(domain)
+sub check_mysql_configured
+{
+return "test";
+}
+
 # backup_mysql(&domain, file)
 # Dumps this domain's mysql database to a backup file
 sub backup_mysql
diff -urN webmin.orig/virtual-server/feature-postgres.pl webmin/virtual-server/feature-postgres.pl
--- webmin.orig/virtual-server/feature-postgres.pl	2004-11-06 00:27:31.000000000 +0000
+++ webmin/virtual-server/feature-postgres.pl	2004-12-06 18:51:57.000000000 +0000
@@ -21,6 +21,12 @@
 return 0;
 }
 
+# check_postgres_configured(domain)
+sub check_postgres_configured
+{
+return (check_postgres_clash($_[0]) == 1) ? "exists" : "not there";
+}
+
 # postgres_user_exists(&domain)
 # Returns 1 if some user exists in PostgreSQL
 sub postgres_user_exists
diff -urN webmin.orig/virtual-server/feature-ssl.pl webmin/virtual-server/feature-ssl.pl
--- webmin.orig/virtual-server/feature-ssl.pl	2004-09-11 08:34:25.000000000 +0100
+++ webmin/virtual-server/feature-ssl.pl	2004-12-06 16:24:55.000000000 +0000
@@ -158,6 +158,12 @@
 return 0;
 }
 
+# check_ssl_configured(domain)
+sub check_ssl_configured
+{
+return "test";
+}
+
 # disable_ssl(&domain)
 # Adds a directive to force all requests to show an error page
 sub disable_ssl
diff -urN webmin.orig/virtual-server/feature-unix.pl webmin/virtual-server/feature-unix.pl
--- webmin.orig/virtual-server/feature-unix.pl	2004-11-24 05:10:59.000000000 +0000
+++ webmin/virtual-server/feature-unix.pl	2004-12-06 16:46:55.000000000 +0000
@@ -157,6 +157,12 @@
 return 0;
 }
 
+# check_unix_configured(&domain)
+sub check_unix_configured
+{
+return (defined(getpwnam($_[0]->{'user'}))) ? "exists" : "not there!";
+}
+
 # disable_unix(&domain)
 # Lock out the password of this domain's Unix user
 sub disable_unix
diff -urN webmin.orig/virtual-server/feature-web.pl webmin/virtual-server/feature-web.pl
--- webmin.orig/virtual-server/feature-web.pl	2004-11-28 22:41:37.000000000 +0000
+++ webmin/virtual-server/feature-web.pl	2004-12-06 17:41:40.000000000 +0000
@@ -453,6 +453,16 @@
 return 0;
 }
 
+# check_web_configured(domain)
+sub check_web_configured
+{
+#require_apache();
+local $web_port = $_[0]->{'web_port'} || 80;
+local ($cvirt, $cconf) = &get_apache_virtual($_[0]->{'dom'}, $web_port);
+return $cvirt ? "exists" : "not there!";
+# poor man's version ??
+}
+
 # restart_apache([restart])
 # Tell Apache to re-read its config file
 sub restart_apache
diff -urN webmin.orig/virtual-server/feature-webalizer.pl webmin/virtual-server/feature-webalizer.pl
--- webmin.orig/virtual-server/feature-webalizer.pl	2004-10-28 01:22:58.000000000 +0100
+++ webmin/virtual-server/feature-webalizer.pl	2004-12-07 17:16:45.000000000 +0000
@@ -199,6 +199,14 @@
 return 0;
 }
 
+# check_webalizer_configured(domain)
+sub check_webalizer_configured
+{
+# I don't yet understand how the webalizer setup here works
+# I suspect its broken on my setup just now ...
+return "fix me";
+}
+
 sub enable_webalizer
 {
 # Does nothing yet
diff -urN webmin.orig/virtual-server/feature-webmin.pl webmin/virtual-server/feature-webmin.pl
--- webmin.orig/virtual-server/feature-webmin.pl	2004-10-01 05:58:37.000000000 +0100
+++ webmin/virtual-server/feature-webmin.pl	2004-12-06 18:00:18.000000000 +0000
@@ -508,6 +508,17 @@
 return 0;
 }
 
+# check_webmin_configured(domain)
+sub check_webmin_configured
+{
+&require_acl();
+local $u;
+foreach $u (&acl::list_users(), &acl::list_groups()) {
+	return "yup!" if ($u->{'name'} eq $_[0]->{'user'});
+	}
+return "no";
+}
+
 # modify_all_webmin()
 # Updates the Webmin users for all domains
 sub modify_all_webmin
virtualmin_details_1 (text/plain, 5.5 KB)
diff -urN webmin.orig/virtual-server/details-dns.cgi webmin/virtual-server/details-dns.cgi
--- webmin.orig/virtual-server/details-dns.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-dns.cgi	2004-12-06 21:21:55.000000000 +0000
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl'; 	# ??
+&ReadParse();
+
+#&ui_print_header(undef, "details", "");
+
+$d = &get_domain($in{'dom'});
+
+&foreign_require("bind8", "bind8-lib.pl");
+
+$conf = &bind8::get_config();
+foreach $z (@$conf) {
+#	print "$z->{'value'} <p>\n";
+	if ($z->{'value'} eq $d->{'dom'}) {
+		$i = $z->{'index'};
+		}
+	}
+
+
+#print "redirect to ../bind8/edit_master.cgi?index=$i <p>\n";
+
+&redirect("../bind8/edit_master.cgi?index=$i");
+
+#&ui_print_footer("", $text{'index_return'});
+
diff -urN webmin.orig/virtual-server/details-ftp.cgi webmin/virtual-server/details-ftp.cgi
--- webmin.orig/virtual-server/details-ftp.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-ftp.cgi	2004-12-07 16:04:36.000000000 +0000
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl';
+&ReadParse();
+$d = &get_domain($in{'dom'});
+
+&foreign_require("proftpd", "proftpd-lib.pl");
+local $conf = &proftpd::get_config();
+@virt = &proftpd::find_directive_struct("VirtualHost", $conf);
+foreach $v (&proftpd::find_directive_struct("VirtualHost", $conf)) {
+	if ($v->{'words'}->[0] eq $d->{'ip'}) {
+		$i = &indexof($v, @$conf);
+		}
+	}
+
+&redirect("../proftpd/virt_index.cgi?virt=$i");
+
+
diff -urN webmin.orig/virtual-server/details-logrotate.cgi webmin/virtual-server/details-logrotate.cgi
--- webmin.orig/virtual-server/details-logrotate.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-logrotate.cgi	2004-12-07 15:38:35.000000000 +0000
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl';
+&ReadParse();
+$d = &get_domain($in{'dom'});
+
+#&ui_print_header(undef, "details", "");
+
+&foreign_require("logrotate", "logrotate-lib.pl");
+local $conf = &logrotate::get_config();
+foreach $c (@$conf) {
+	if ($c->{'members'}) {
+		#print "$c->{'index'} <br>\n";
+		#print join('<br>\n',@{$c->{'name'}}). "<br>\n<p>\n";
+		foreach $n (@{$c->{'name'}}) {
+			if ($n =~ /^$d->{'home'}/) {
+				$i = $c->{'index'}; 
+				#print "like $i $n <br>\n";
+				}
+			}
+		}
+	}
+
+&redirect("../logrotate/edit_log.cgi?idx=$i");
+
+#&ui_print_footer("", $text{'index_return'});
diff -urN webmin.orig/virtual-server/details-mail.cgi webmin/virtual-server/details-mail.cgi
--- webmin.orig/virtual-server/details-mail.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-mail.cgi	2004-12-07 14:12:26.000000000 +0000
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl'; 	# ??
+&ReadParse();
+
+#&ui_print_header(undef, "details", "");
+
+&redirect("list_users.cgi?dom=$in{'dom'}");
+
+#&ui_print_footer("", $text{'index_return'});
+
diff -urN webmin.orig/virtual-server/details-postgres.cgi webmin/virtual-server/details-postgres.cgi
--- webmin.orig/virtual-server/details-postgres.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-postgres.cgi	2004-12-07 13:06:19.000000000 +0000
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl'; 	# ??
+&ReadParse();
+
+#&ui_print_header(undef, "details", "");
+
+$d = &get_domain($in{'dom'});
+
+# check_postgres_configured ??
+
+&redirect("../postgresql/edit_dbase.cgi?db=$d->{'db'}");
+
+#&ui_print_footer("", $text{'index_return'});
+
diff -urN webmin.orig/virtual-server/details-unix.cgi webmin/virtual-server/details-unix.cgi
--- webmin.orig/virtual-server/details-unix.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-unix.cgi	2004-12-07 14:45:09.000000000 +0000
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl'; 	# ??
+&ReadParse();
+
+#&ui_print_header(undef, "details", "");
+
+$d = &get_domain($in{'dom'});
+
+&foreign_require("useradmin", "user-lib.pl");
+@allulist = &useradmin::list_users();
+@ulist = &useradmin::list_allowed_users(\%access, \@allulist);
+foreach $u (@ulist) {
+	$i = $u->{'num'} if $u->{'user'} == $d->{'user'};
+	}
+
+&redirect("../useradmin/edit_user.cgi?num=$i");
+
+#&ui_print_footer("", $text{'index_return'});
+
diff -urN webmin.orig/virtual-server/details-web.cgi webmin/virtual-server/details-web.cgi
--- webmin.orig/virtual-server/details-web.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-web.cgi	2004-12-06 21:08:48.000000000 +0000
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl'; 	# ??
+&ReadParse();
+
+&foreign_require("apache", "apache-lib.pl");
+
+$d = &get_domain($in{'dom'});
+
+local $conf = &apache::get_config();
+@virt = &apache::find_directive_struct("VirtualHost", $conf);
+foreach $v (@virt) {
+	# check port first
+	local $sn = &apache::find_directive("ServerName");
+	if ($sn == $d->{'dom'}) {
+		$i = &indexof($v, @$conf);
+		}
+	#print "dump: $v->{value} $sn <p>\n";
+	}
+
+# did we get anything ?
+
+&redirect("../apache/virt_index.cgi?virt=$i");
+
+
diff -urN webmin.orig/virtual-server/details-webmin.cgi webmin/virtual-server/details-webmin.cgi
--- webmin.orig/virtual-server/details-webmin.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin/virtual-server/details-webmin.cgi	2004-12-07 14:07:24.000000000 +0000
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+require './virtual-server-lib.pl'; 	# ??
+&ReadParse();
+
+#&ui_print_header(undef, "details", "");
+
+$d = &get_domain($in{'dom'});
+
+&redirect("../acl/edit_user.cgi?user=$d->{'user'}");
+
+
+#&ui_print_footer("", $text{'index_return'});
+
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.