Skip to content

Commit

Permalink
Request reloads through the CLI request-reload.
Browse files Browse the repository at this point in the history
Also make the request-reload command configurable in the hostdb.ini like

     [interface]
     request_reload_cmd = /path/to/my/request-reload

This makes the use of JEvent to send reload requests to DNS and DHCP
servers totally optional (although still the default). If you want to
use another mechanism, implement it in a command compatible with
request-reload and point it out through configuration.

It also makes us truly not Depend on libjevent-perl, so the Recommends
becomes true.
  • Loading branch information
Fredrik Thulin committed Apr 7, 2010
1 parent e6db9d4 commit e219f34
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
1 change: 1 addition & 0 deletions debian/control
Expand Up @@ -51,6 +51,7 @@ Package: hostdb-cgi
Architecture: all
Depends: ${perl:Depends},
${misc:Depends},
libfile-searchpath-perl,
libhostdb-perl
Recommends: libjevent-perl
Description: CGI scripts to access Stockholm university HOSTDB.
Expand Down
74 changes: 45 additions & 29 deletions home.cgi
Expand Up @@ -10,8 +10,8 @@ use strict;
use HOSTDB;
use SUCGI2;
use Config::IniFiles;
use JEvent;
use XML::Simple;
use File::SearchPath qw/ searchpath /;


my $table_blank_line = "<tr><td COLSPAN='3'>&nbsp;</td></tr>\n";
my $table_hr_line = "<tr><td COLSPAN='3'><hr></td></tr>\n";
Expand Down Expand Up @@ -77,12 +77,8 @@ EOH

my ($subnets_ref, $zones_ref) = home_form ($q, $hostdb, $remote_user, $is_admin, $is_helpdesk);

my $jevent_ini = Config::IniFiles->new(-file=> HOSTDB::get_inifile('JEvent'));
my $je = JEvent->new (Config => $jevent_ini);
$je->Connect ();

if (defined ($q->param ('action') and $q->param ('action') eq 'Activate changes')) {
activate_changes ($hostdb, $q, $je,
activate_changes ($hostdb, $q, $hostdbini,
$subnets_ref, $zones_ref, $is_admin, $is_helpdesk, $remote_user);
}

Expand Down Expand Up @@ -317,7 +313,7 @@ sub activate_changes
{
my $hostdb = shift;
my $q = shift;
my $je = shift;
my $hostdbini = shift;
my $subnets_ref = shift;
my $zones_ref = shift;
my $is_admin = shift;
Expand Down Expand Up @@ -372,7 +368,7 @@ sub activate_changes
}
}

my $res = request_reload ($je, $subnets_ref, $zones_ref, $q, $remote_user);
my $res = request_reload ($hostdbini, $subnets_ref, $zones_ref, $q, $remote_user);

if ($res) {
my $time = localtime ();
Expand All @@ -395,7 +391,7 @@ EOH

sub request_reload
{
my $je = shift;
my $hostdbini = shift;
my $subnets_ref = shift;
my $zones_ref = shift;
my $q = shift;
Expand All @@ -420,37 +416,57 @@ sub request_reload
my $num_zones = scalar @zonelist;
my $num_subnets = scalar @$subnets_ref;

my $thishost = Sys::Hostname::hostname();
if ($num_subnets or $num_zones) {
if ($num_subnets) {
warn ("$i: user '$remote_user' requests reload of the following $num_subnets subnets : " . join (', ', @$subnets_ref) . "\n");
}
if ($num_zones) {
warn ("$i: user '$remote_user' requests reload of the following $num_zones zones : " . join (', ', @zonelist) . "\n");
}
my %data = ('type' => 'activate-request',
'source' => 'home.cgi',
'requestor' => $remote_user,
'requestor-host' => $thishost,
'items' => {
'zone' => [sort @zonelist],
'subnet' => [@$subnets_ref]
}
);
my %XMLoptions = (RootName => 'hostdb',
AttrIndent => 1
);

my $xml = XMLout(\%data, %XMLoptions);

warn ("JEvent XML :\n$xml\n\n") if ($debug);

$je->Publish(Content => $xml) or die ("$0: Failed publishing event\n");

my $cmd = get_request_reload_command ($hostdbini);
if ($cmd) {
my @args = ($cmd,
'--source', 'home.cgi',
'--requestor', $remote_user
);

system (@args) == 0
or die ("Failed executing command '$cmd'");
} else {
warn ("Failed locating a 'request-reload' command, configure one " .
"in hostdb.ini [interface] -> request_reload_cmd\n");
return 0;
}
} else {
warn ("Found no zones or subnets to reload");
return 0;
}

return 1;
}

sub get_request_reload_command
{
my $hostdbini = shift;

my $cmd = $hostdbini->val ('interface', 'request_reload_cmd');

return $cmd if ($cmd);

# when not found, look in PATH for hostdb request-reload command.
$cmd = searchpath('request-reload',
env => 'PATH',
exe => 1
);

if ($cmd) {
warn ("Requesting reload through $cmd found in PATH.\n");
}

return $cmd;
}

sub error_line
{
my $q = shift;
Expand Down

0 comments on commit e219f34

Please sign in to comment.