Skip to content

Commit

Permalink
Show more error context, remove blink tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed May 5, 2009
1 parent faaa22e commit ee60bc6
Show file tree
Hide file tree
Showing 23 changed files with 59 additions and 38 deletions.
1 change: 1 addition & 0 deletions dhcpd/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ String custom options are now always quoted.
Converted buttons on the module's main page to use the Webmin UI library.
Expired leases are no longer counted towards usage on the DHCP Leases page.
Added a mode to the DHCP Leases page to show usage by subnet, thanks to a suggestion by Coles.
When applying the configuration fails with an error mentioning a line in the config file, 10 lines around that will also be displayed by Webmin in the error.
1 change: 0 additions & 1 deletion dhcpd/acl_security.pl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ sub acl_security_save
{
if ($in{'r_sub'} < $in{'w_sub'} || $in{'r_sha'} < $in{'w_sha'} ||
$in{'r_hst'} < $in{'w_hst'} || $in{'r_grp'} < $in{'w_grp'}) {
$whatfailed = $text{'acl_err'};
&error($text{'acl_ernow'});
}
$_[0]->{'apply'}=$in{'apply'};
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/confirm_delete.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ foreach $i ($in{'sidx'}, $in{'uidx'}, $in{'idx'}) {

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});

@host = &find("host", $par->{'members'});
@group = &find("group", $par->{'members'});
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/delete_all.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $to_del = $parconf->[$in{'idx'}];

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($to_del->{'name'} eq "group") {
&error("$text{'eacl_np'} $text{'eacl_pdg'}")
if !&can('rw', \%access, $to_del, 1);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/delete_lease.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require './dhcpd-lib.pl';
&ReadParse();

%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if( !($access{'w_leases'} && $access{'r_leases'}) ) {
&error("$text{'eacl_np'} $text{'eacl_pdl'}");
}
Expand Down
25 changes: 22 additions & 3 deletions dhcpd/dhcpd-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ sub restart_dhcpd
if ($config{'restart_cmd'}) {
# Run the restart script
$out = &backquote_logged("$config{'restart_cmd'} 2>&1");
return "<pre>$out</pre>" if ($?);
}
else {
# Kill and re-run the server
Expand All @@ -836,11 +835,31 @@ sub restart_dhcpd
else {
$out = &backquote_logged("$config{'dhcpd_path'} -cf $config{'dhcpd_conf'} -lf $config{'lease_file'} $config{'interfaces'} 2>&1");
}
return "<pre>$out</pre>" if ($?);
}
if ($?) {
return &parse_error_out($out);
}
return undef;
}

# Find and add config file lines around those in an error message
sub parse_error_out
{
local ($out) = @_;
local $conftext;
if ($out =~ /(\S+)\s+line\s+(\d+):/) {
local ($file, $line) = ($1, $2);
local $lref = &read_file_lines($file, 1);
local $start = $line - 5;
local $end = $line + 5;
$start = 0 if ($start < 0);
$end = @$lref-1 if ($end > @$lref-1);
$conftext = &text('restart_conftext', $line, $file)."<br>".
"<pre>".&html_escape(join("\n", @$lref[$start .. $end]))."</pre>";
}
return "<pre>".&html_escape($out)."</pre>".$conftext;
}

# stop_dhcpd()
# Stop the running DHCP server. Returns undef on success, or an error message
# on failure.
Expand Down Expand Up @@ -881,7 +900,7 @@ sub start_dhcpd
$out = &backquote_logged("$config{'dhcpd_path'} -cf $config{'dhcpd_conf'} -lf $config{'lease_file'} $config{'interfaces'} 2>&1");
}
if ($? || $out =~ /error|failed/i) {
return "<pre>$out</pre>";
return &parse_error_out($out);
}
else {
return undef;
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_group.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $mems = $par->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'new'}) {
&error("$text{'eacl_np'} $text{'eacl_pig'}")
unless &can('c', \%access, $group) && &can('rw', \%access, $par);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_host.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $hconf = $host->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'new'} ) {
&error("$text{'eacl_np'} $text{'eacl_pih'}")
unless &can('c', \%access, $host) && &can('rw', \%access, $par);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_keys.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $conf = &get_config();

# check acls
# %access = &get_module_acl();
# &error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
# &error_setup($text{'eacl_aviol'});
# &error("$text{'eacl_np'} $text{'eacl_pss'}") if !&can('r',\%access,$sub);

if ($in{'new'}) {
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_options.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require './params-lib.pl';
$conf = &get_config();

%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});

$client = &get_parent_config();
push(@parents, $client);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_pool.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else { $sub = $conf->[$in{'uidx'}]; }

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
&error("$text{'eacl_np'} $text{'eacl_pss'}") if !&can('r',\%access,$sub);

# display
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_shared.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $sconf = $sha->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'new'} ) {
&error("$text{'eacl_np'} $text{'eacl_pin'}")
unless &can('c', \%access, $sha) && &can('rw', \%access, $par);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/edit_subnet.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $sconf = $sub->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'new'}) {
&error("$text{'eacl_np'} $text{'eacl_pis'}")
unless &can('c', \%access, $sub) && &can('rw', \%access, $par);
Expand Down
1 change: 1 addition & 0 deletions dhcpd/lang/en
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ listl_pc=Percentage
restart_errmsg1=Failed to restart dhcpd
restart_errmsg2=Failed to signal process
start_failstart=Failed to start dhcpd
restart_conftext=Lines around $1 in $2 :

sgroup_faildel=Failed to delete group
sgroup_failsave=Failed to save group
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/list_leases.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require 'timelocal.pl';
$timenow = time();

%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
&error("$text{'eacl_np'} $text{'eacl_psl'}") unless $access{'r_leases'};

if ($in{'network'}) {
Expand Down
10 changes: 5 additions & 5 deletions dhcpd/save_group.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $parconf = $par->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'delete'}) {
&error("$text{'eacl_np'} $text{'eacl_pdg'}")
if !&can('rw', \%access, $group, 1);
Expand All @@ -38,8 +38,8 @@ if ($in{'options'}) {
exit;
}
else {
$whatfailed = $in{'delete'} ? $text{'sgroup_faildel'} :
$text{'sgroup_failsave'};
&error_setup($in{'delete'} ? $text{'sgroup_faildel'} :
$text{'sgroup_failsave'});

# Move hosts into or out of this group
@wasin = &find("host", $group->{'members'});
Expand All @@ -58,7 +58,7 @@ else {
}
}

$whatfailed = "<blink><font color=red>$text{'eacl_aviol'}</font></blink>";
&error_setup($text{'eacl_aviol'});
foreach $h (&unique(@wasin, @nowin)) {
$was = &indexof($h, @wasin) != -1;
$now = &indexof($h, @nowin) != -1;
Expand All @@ -85,7 +85,7 @@ else {
$group->{'comment'} = $in{'desc'};
&parse_params($group, $indent+1);

$whatfailed = $text{'sgroup_failsave'};
&error_setup($text{'sgroup_failsave'});
@partypes = ( "", "shared-network", "subnet" );
if (!$npar || $in{'assign'} > 0 && $npar->{'name'} ne $partypes[$in{'assign'}]) {
if ($in{'jsquirk'}) {
Expand Down
4 changes: 2 additions & 2 deletions dhcpd/save_host.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require './params-lib.pl';

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'delete'}) {
&error("$text{'eacl_np'} $text{'eacl_pdh'}")
if !&can('rw', \%access, $host, 1);
Expand All @@ -35,7 +35,7 @@ else {
# save
if ($in{'delete'}) {
# Delete this host
$whatfailed = $text{'shost_faildel'};
&error_setup($text{'shost_faildel'});
&save_directive($par, [ $host ], [ ], 0);
&drop_dhcpd_acl('hst', \%access, $host->{'values'}->[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/save_options.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ foreach $i ($in{'sidx'}, $in{'uidx'}, $in{'gidx'}, $in{'idx'}) {

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($client->{'name'} eq 'subnet') {
&error("$text{'eacl_np'} $text{'eacl_pus'}")
if !&can('rw', \%access, $client);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/save_pool.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ else {

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
&error("$text{'eacl_np'} $text{'eacl_pus'}") if !&can('rw', \%access, $sub);

# save
Expand Down
10 changes: 5 additions & 5 deletions dhcpd/save_shared.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $parconf = $par->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'delete'}) {
&error("$text{'eacl_np'} $text{'eacl_pdn'}")
if !&can('rw', \%access, $sha, 1);
Expand Down Expand Up @@ -44,10 +44,10 @@ if ($in{'options'}) {
}
else {
if ($in{'delete'}) {
$whatfailed = $text{'sshared_faildel'};
&error_setup($text{'sshared_faildel'});
}
else {
$whatfailed = $text{'sshared_failsave'};
&error_setup($text{'sshared_failsave'});
$in{'name'} =~ /^\S+$/ ||
&error($text{'sshared_invalidsname'});
$sha->{'values'} = [ $in{'name'} ];
Expand Down Expand Up @@ -101,7 +101,7 @@ else {
}
}

$whatfailed = "<blink><font color=red>$text{'eacl_aviol'}</font></blink>";
&error_setup($text{'eacl_aviol'});
foreach $h (&unique(@wasin, @nowin)) {
$was = &indexof($h, @wasin) != -1;
$now = &indexof($h, @nowin) != -1;
Expand Down Expand Up @@ -205,7 +205,7 @@ sub check_subnets
local(@subnets);
@subnets = &find("subnet", $_[0]->{'members'});
if (@subnets == 0) {
$whatfailed = $text{'sshared_failsave'};
&error_setup($text{'sshared_failsave'});
&error(&text('sshared_nosubnet', $_[0]->{'values'}->[0]));
}
}
Expand Down
10 changes: 5 additions & 5 deletions dhcpd/save_subnet.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $parconf = $par->{'members'};

# check acls
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
if ($in{'delete'}) {
&error("$text{'eacl_np'} $text{'eacl_pds'}")
if !&can('rw', \%access, $sub, 1);
Expand Down Expand Up @@ -52,7 +52,7 @@ elsif ($in{'leases'}) {
}
else {
if ($in{'delete'}) {
$whatfailed = $text{'ssub_faildel'};
&error_setup($text{'ssub_faildel'});
if ($par->{'name'} eq "shared-network") {
@subnets = &find("subnet", $par->{'members'});
if (@subnets < 2) {
Expand All @@ -61,7 +61,7 @@ else {
}
}
else {
$whatfailed = $text{'ssub_failsave'};
&error_setup($text{'ssub_failsave'});
# Validate and save inputs
gethostbyname($in{'network'}) || &check_ipaddress($in{'network'}) ||
&error("'$in{'network'}' $text{'ssub_invalidsubaddr'}");
Expand Down Expand Up @@ -102,7 +102,7 @@ else {
}
}

$whatfailed = "<blink><font color=red>$text{'eacl_aviol'}</font></blink>";
&error_setup($text{'eacl_aviol'});
foreach $h (&unique(@wasin, @nowin)) {
$was = &indexof($h, @wasin) != -1;
$now = &indexof($h, @nowin) != -1;
Expand Down Expand Up @@ -143,7 +143,7 @@ else {
}

if (!$in{'delete'}) {
$whatfailed = $text{'ssub_failsave'};
&error_setup($text{'ssub_failsave'});
for($i=0; defined($low = $in{"range_low_$i"}); $i++) {
next if (!$low);
$hi = $in{"range_hi_$i"}; $dyn = $in{"range_dyn_$i"};
Expand Down
5 changes: 3 additions & 2 deletions dhcpd/start.cgi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/local/bin/perl
# start.cgi
# Attempt to start dhcpd

require './dhcpd-lib.pl';
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
&error("$text{'eacl_np'} $text{'eacl_papply'}") unless $access{'apply'};

$whatfailed = $text{'start_failstart'};
&error_setup($text{'start_failstart'});
$err = &start_dhcpd();
&error($err) if ($err);
&webmin_log("start");
Expand Down
4 changes: 2 additions & 2 deletions dhcpd/stop.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

require './dhcpd-lib.pl';
%access = &get_module_acl();
&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
&error_setup($text{'eacl_aviol'});
&error("$text{'eacl_np'} $text{'eacl_papply'}") unless $access{'apply'};

$whatfailed = $text{'stop_err'};
&error_setup($text{'stop_err'});
$err = &stop_dhcpd();
&error($err) if ($err);
&webmin_log("stop");
Expand Down

0 comments on commit ee60bc6

Please sign in to comment.