*/ include 'common.php'; /* * Plz do mind to configure sudo the right way */ $allowed_exec = array( "lvrouted" => "/usr/local/etc/rc.d/lvrouted.sh restart", "isc-dhcpd" => "/usr/local/etc/rc.d/isc-dhcpd.sh restart", "syslogd" => "/etc/rc.d/syslogd restart", "named" => "/etc/rc.d/named restart", "reboot" => "/sbin/reboot", "pen" => "/usr/local/etc/rc.d/pen.sh restart", ); $exec_pid = array ( "lvrouted" => "/var/run/lvrouted.pid", "isc-dhcpd" => "/var/run/dhcpd/dhcpd.pid", "named" => "/var/run/named/pid", "syslogd" => "/var/run/syslog.pid", "reboot" => "Handle with care", "pen" => "/var/run/pen.pid", ); $output=exec("ps -ax | awk 'NR > 1 {print $1}'| tr '\n' ' '"); $running_pids=split(" ", $output); function execute_action($command,$verbose) { global $allowed_exec; $command="/usr/local/bin/sudo /bin/sh $allowed_exec[$command]"; if ( $verbose == 1 ) { print "
\n"; system("$command 2>&1",$retval); print "\n"; } else { system("$command 2>/dev/null 1>/dev/null",$retval); } return $retval; } function file2status($file) { global $running_pids; if(file_exists($file)) { if(is_readable($file)) { $file_content = file($file); $pid = (int)$file_content[0]; } else { $file_content = exec("/usr/local/bin/sudo /bin/cat $file"); $pid = (int)$file_content; } if( $pid == 0 ) { $pid = -1; }; if( in_array($pid, $running_pids) ) { $result="running (pid: $pid)"; } else { $result="stopped (pid: $pid)"; } } else { if( $file[0] == "/" ) { $result="stopped (pid: -2)"; } else { $result = $file; } } return($result); } parse_str($_SERVER['QUERY_STRING'], $output); if ( array_key_exists($output['process'], $allowed_exec) ) { $process = $output['process']; html_header($allowed_exec[$process]); print ""; print "$allowed_exec[$process]"; execute_action($process, 1); print ""; html_end(); } else { html_header("action list"); print "\n"; print "
Process | Status | Action |
$process | $status | $restart |
"; print "Pid -1 = access denied reading pid\n"; print "Pid -2 = pid file not found\n"; print ""; print "\n"; html_end(); } ?>