#!/usr/bin/perl # # SmoothWall CGIs # # This code is distributed under the terms of the GPL # # (c) The SmoothWall Team # use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require 'CONFIG_ROOT/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; my %cgiparams=(); my $death = 0; my $rebirth = 0; my $default_time = '03:15'; &Header::showhttpheaders(); $cgiparams{'ACTION'} = ''; &Header::getcgihash(\%cgiparams); if ($cgiparams{'ACTION'} eq $Lang::tr{'shutdown'}) { $death = 1; &General::log($Lang::tr{'shutting down ipfire'}); #system '/usr/local/bin/ipfiredeath'; system '/usr/local/bin/ipfirereboot down'; } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reboot'}) { $rebirth = 1; &General::log($Lang::tr{'rebooting ipfire'}); #system '/usr/local/bin/ipfirerebirth'; system '/usr/local/bin/ipfirereboot boot'; } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { my $days=''; my $n = 1; # build list of days map ($cgiparams{$_} eq 'on' ? $days .= ",".$n++ : $n++ , ('MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY','SUNDAY') ); # if days is empty, it is a remove else it is a change if (length ($days)){ substr($days,0,1) = ''; #kill front comma &General::log("Scheduling reboot on $days at $cgiparams{'TIME'}"); my $min; my $hour; ($hour,$min) = split (':', $cgiparams{'TIME'}); $days = "'*'" if ($days eq '1,2,3,4,5,6,7'); my $mode = ($cgiparams{'MODE'} eq 'halt') ? '-h' : '-r'; system "/usr/local/bin/ipfirereboot cron+ $min $hour $days $mode"; #reboot checks values of $hour & $min } else { &General::log("Remove scheduled reboot"); system '/usr/local/bin/ipfirereboot cron-'; } } if ($death == 0 && $rebirth == 0) { &Header::openpage($Lang::tr{'shutdown control'}, 1, ''); &Header::openbigbox('100%', 'left'); print "
\n"; &Header::openbox('100%', 'left', $Lang::tr{'shutdown2'}); print < END ; &Header::closebox(); &Header::openbox('100%', 'left', $Lang::tr{'reboot schedule'}); my %checked=(); my $reboot_at = $default_time; my $days = ''; #decode the shutdown line stored in crontab #get the line open(FILE, "/usr/local/bin/ipfirereboot cron?|"); my $schedule = ; close (FILE); if ($schedule) { # something exist $schedule =~ /(\d+) (\d+) \* \* ([1234567*,]+) .* (-[h|r])/; $reboot_at = sprintf("%.02d",$2) . ':' . sprintf("%.02d",$1); # hour (03:45) $days = $3; # 1,2,3... or * if ($4 eq '-h') { $checked{'MODE'}{'halt'} = "checked='checked'"; } else { $checked{'MODE'}{'reboot'} = "checked='checked'"; } } #decode $days if ($days eq '*') { $checked{'MONDAY'} = "checked='checked'"; $checked{'TUESDAY'} = "checked='checked'"; $checked{'WEDNESDAY'} = "checked='checked'"; $checked{'THURSDAY'} = "checked='checked'"; $checked{'FRIDAY'} = "checked='checked'"; $checked{'SATURDAY'} = "checked='checked'"; $checked{'SUNDAY'} = "checked='checked'"; } else { $checked{'MONDAY'} = "checked='checked'" if ($days =~ /1/); $checked{'TUESDAY'} = "checked='checked'" if ($days =~ /2/); $checked{'WEDNESDAY'} = "checked='checked'" if ($days =~ /3/); $checked{'THURSDAY'} = "checked='checked'" if ($days =~ /4/); $checked{'FRIDAY'} = "checked='checked'" if ($days =~ /5/); $checked{'SATURDAY'} = "checked='checked'" if ($days =~ /6/); $checked{'SUNDAY'} = "checked='checked'" if ($days =~ /7/); } print < $Lang::tr{'time'} $Lang::tr{'day'} $Lang::tr{'action'} END ; print "", &select_hour_var("TIME", $reboot_at); print < $Lang::tr{'monday'} $Lang::tr{'reboot'} $Lang::tr{'tuesday'} $Lang::tr{'shutdown'}   $Lang::tr{'wednesday'}   $Lang::tr{'thursday'}   $Lang::tr{'friday'}   $Lang::tr{'saturday'}   $Lang::tr{'sunday'}
 
END ; &Header::closebox(); print "\n"; } else { my $message=''; my $title=''; my $refresh = ""; if ($death) { $title = $Lang::tr{'shutting down'}; $message = $Lang::tr{'ipfire has now shutdown'}; } else { $title = $Lang::tr{'rebooting'}; $message = $Lang::tr{'ipfire has now rebooted'}; } &Header::openpage($title, 0, $refresh); &Header::openbigbox('100%', 'center'); print <






$message END ; } &Header::closebigbox(); &Header::closepage(); # Create a named select box containing valid times from quarter to quarter. sub select_hour_var { # Create a variable containing the SELECT with selected value variable name and current value selected my $select_hour_var = shift; my $selected_hour = shift; my $select_hour = "\n"; return ($select_hour); }