[webmin-devel] Bind8 module patch for DDNS zone

"Clément VERET" <[email protected]>
Newsgroups gmane.comp.web.webmin.devel
Message-ID <[email protected]>
Hi everyone,

I just writed a little patch in order to add to buttons to the Webmin
BIND8 interface when editing a master zone.

This add a "Freeze the zone" and an "Unfreeze the zone" button, in
order to launch the "rndc freeze ZONE" or "rndc thaw ZONE". Those
actions are imperative when you need to update manually a DDNS zone.

This is my first Webmin patch so this is probably a little crappy. I'm
sorry about that.

Hope it can help.

P.S. : the patch applies directly to Webmin 1.37 source.
-- 
Clément Véret

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

-
Forwarded by the Webmin development list at [email protected]
To remove yourself from this list, go to
http://lists.sourceforge.net/lists/listinfo/webadmin-devel
freeze_thaw_dynamic_zone.patch (application/octet-stream, 6.8 KB)
diff -aburN webmin-1.370.ori/bind8/edit_master.cgi webmin-1.370/bind8/edit_master.cgi
--- webmin-1.370.ori/bind8/edit_master.cgi	2007-09-21 23:26:23.000000000 +0200
+++ webmin-1.370/bind8/edit_master.cgi	2007-10-27 22:54:39.000000000 +0200
@@ -138,6 +138,32 @@
 			"<tt>$cmd reload $args</tt>");
 		print "</td> </tr></form>\n";
 		}
+	if ($apply) {
+		print "<form action=freeze_zone.cgi>\n";
+		print "<input type=hidden name=index value=\"$in{'index'}\">\n";
+		print "<input type=hidden name=view value=\"$in{'view'}\">\n";
+		print "<tr><td>\n";
+		print "<input type=submit value=\"$text{'master_freeze'}\">\n";
+		$args = $view ? "$dom IN $view->{'value'}" : $dom;
+		$cmd = &has_ndc() == 2 ? $config{'rndc_cmd'}
+	: $config{'ndc_cmd'};
+		print "</td> <td>",&text('master_freezemsg',
+			"<tt>$cmd freeze $args</tt>");
+		print "</td> </tr></form>\n";
+		}
+	if ($apply) {
+		print "<form action=unfreeze_zone.cgi>\n";
+		print "<input type=hidden name=index value=\"$in{'index'}\">\n";
+		print "<input type=hidden name=view value=\"$in{'view'}\">\n";
+		print "<tr><td>\n";
+		print "<input type=submit value=\"$text{'master_unfreeze'}\">\n";
+		$args = $view ? "$dom IN $view->{'value'}" : $dom;
+		$cmd = &has_ndc() == 2 ? $config{'rndc_cmd'}
+	: $config{'ndc_cmd'};
+		print "</td> <td>",&text('master_unfreezemsg',
+			"<tt>$cmd thaw $args</tt>");
+		print "</td> </tr></form>\n";
+		}
 
 	print "</table>\n";
 	}
diff -aburN webmin-1.370.ori/bind8/freeze_zone.cgi webmin-1.370/bind8/freeze_zone.cgi
--- webmin-1.370.ori/bind8/freeze_zone.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin-1.370/bind8/freeze_zone.cgi	2007-10-27 22:54:39.000000000 +0200
@@ -0,0 +1,50 @@
+#!/usr/local/bin/perl
+# freeze_zone.cgi
+# Apply changes to one zone only using the ndc command
+
+require './bind8-lib.pl';
+&ReadParse();
+$access{'ro'} && &error($text{'restart_ecannot'});
+$access{'apply'} || &error($text{'restart_ecannot'});
+$zone = &get_zone_name($in{'index'}, $in{'view'});
+if ($zone->{'view'}) {
+	# Reload a zone in a view
+	$dom = $zone->{'name'};
+	&can_edit_zone($zone) || &error($text{'restart_ecannot'});
+	$out = &try_cmd("freeze '$dom' IN '$zone->{'view'}'");
+	}
+else {
+	# Just reload one top-level zone
+	$dom = $zone->{'name'};
+	&can_edit_zone($zone) || &error($text{'restart_ecannot'});
+	$out = &try_cmd("freeze '$dom' 2>&1 </dev/null");
+	}
+if ($? || $out =~ /failed|not found|error/i) {
+	&error(&text('restart_endc', "<tt>$out</tt>"));
+	}
+&webmin_log("freeze", $dom);
+
+$tv = $zone->{'type'};
+&redirect(($tv eq "master" ? "edit_master.cgi" :
+	  $tv eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi").
+	  "?index=$in{'index'}&view=$in{'view'}");
+
+# try_cmd(args, [rndc-args])
+sub try_cmd
+{
+local $args = $_[0];
+local $rndc_args = $_[1] || $_[0];
+local $out;
+if (&has_ndc() == 2) {
+	# Try with rndc
+	$out = &backquote_logged("$config{'rndc_cmd'} $rndc_args 2>&1 </dev/null");
+	}
+if (&has_ndc() != 2 || $out =~ /connect\s+failed/i) {
+	if (&has_ndc(2)) {
+		# Try with rndc if rndc is not install or failed
+		$out = &backquote_logged("$config{'ndc_cmd'} $args 2>&1 </dev/null");
+		}
+	}
+return $out;
+}
+
diff -aburN webmin-1.370.ori/bind8/lang/en webmin-1.370/bind8/lang/en
--- webmin-1.370.ori/bind8/lang/en	2007-09-21 23:26:23.000000000 +0200
+++ webmin-1.370/bind8/lang/en	2007-10-27 22:54:39.000000000 +0200
@@ -16,6 +16,10 @@
 index_addmass=Create zones from batch file.
 index_apply=Apply Changes
 index_applymsg=Click this button to restart the running BIND server. This will cause the current configuration to become active
+master_freeze=Freeze the zone
+master_freezemsg=Click this button to freeze a dynamic zone before updating it. This will send the command $1 to the zone.
+master_unfreeze=Unfreeze the zone
+master_unfreezemsg=Click this button to unfreeze a dynamic zone after having updated it. This will send the command $1 to the zone.
 index_applymsg2=Click this button to restart the running BIND server and all cluster slaves. This will cause the current configuration to become active.
 index_start=Start Name Server
 index_startmsg=Click this button to start the BIND server, and load the current configuration.
diff -aburN webmin-1.370.ori/bind8/lang/fr webmin-1.370/bind8/lang/fr
--- webmin-1.370.ori/bind8/lang/fr	2007-09-21 23:26:23.000000000 +0200
+++ webmin-1.370/bind8/lang/fr	2007-10-27 22:57:27.000000000 +0200
@@ -107,6 +107,10 @@
 master_eserial=Le numéro de série doit être une chaîne de nombres
 master_apply=Appliquer les changements
 master_applymsg=Cliquez sur ce bouton pour appliquer les changements pour cette zone uniquement, à l'aide de la commande $1. Ce comportement ne fonctionnera que si les changements ont été appliqués pour le serveur entier au moins une fois depuis que la zone a été créée.
+master_freeze=Geler la zone
+master_freezemsg=Si la zone fait partie d'un DNS dynamique, cela permet de la geler avant de la mettre à jour.
+master_unfreeze=Dégeler la zone
+master_unfreezemsg=Si la zone fait partie d'un DNS dynamique, cela permet de la dégeler une fois les mises à jour appliquées.
 master_defttl=Durée de vie par défaut des enregistrements
 master_edefttl="$1' n'est pas une durée de vie par défaut valide pour les enregistrements
 
diff -aburN webmin-1.370.ori/bind8/unfreeze_zone.cgi webmin-1.370/bind8/unfreeze_zone.cgi
--- webmin-1.370.ori/bind8/unfreeze_zone.cgi	1970-01-01 01:00:00.000000000 +0100
+++ webmin-1.370/bind8/unfreeze_zone.cgi	2007-10-27 22:54:39.000000000 +0200
@@ -0,0 +1,50 @@
+#!/usr/local/bin/perl
+# unfreeze_zone.cgi
+# Apply changes to one zone only using the ndc command
+
+require './bind8-lib.pl';
+&ReadParse();
+$access{'ro'} && &error($text{'restart_ecannot'});
+$access{'apply'} || &error($text{'restart_ecannot'});
+$zone = &get_zone_name($in{'index'}, $in{'view'});
+if ($zone->{'view'}) {
+	# Reload a zone in a view
+	$dom = $zone->{'name'};
+	&can_edit_zone($zone) || &error($text{'restart_ecannot'});
+	$out = &try_cmd("thaw '$dom' IN '$zone->{'view'}'");
+	}
+else {
+	# Just reload one top-level zone
+	$dom = $zone->{'name'};
+	&can_edit_zone($zone) || &error($text{'restart_ecannot'});
+	$out = &try_cmd("thaw '$dom' 2>&1 </dev/null");
+	}
+if ($? || $out =~ /failed|not found|error/i) {
+	&error(&text('restart_endc', "<tt>$out</tt>"));
+	}
+&webmin_log("thaw", $dom);
+
+$tv = $zone->{'type'};
+&redirect(($tv eq "master" ? "edit_master.cgi" :
+	  $tv eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi").
+	  "?index=$in{'index'}&view=$in{'view'}");
+
+# try_cmd(args, [rndc-args])
+sub try_cmd
+{
+local $args = $_[0];
+local $rndc_args = $_[1] || $_[0];
+local $out;
+if (&has_ndc() == 2) {
+	# Try with rndc
+	$out = &backquote_logged("$config{'rndc_cmd'} $rndc_args 2>&1 </dev/null");
+	}
+if (&has_ndc() != 2 || $out =~ /connect\s+failed/i) {
+	if (&has_ndc(2)) {
+		# Try with rndc if rndc is not install or failed
+		$out = &backquote_logged("$config{'ndc_cmd'} $args 2>&1 </dev/null");
+		}
+	}
+return $out;
+}
+
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.