#!/usr/local/bin/perl
# restart.cgi
# Restart the running dhcpd

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

&error_setup($text{'restart_errmsg1'});
if ($config{'restart_cmd'}) {
	# Run the restart script
	$out = &backquote_logged("$config{'restart_cmd'} 2>&1");
	if ($?) {
		&error("<pre>$out</pre>");
		}
	}
else {
	# Kill and re-run the server
	&kill_logged('TERM', $in{'pid'}) ||
		&error("$text{'restart_errmsg2'} $in{'pid'} : $!");
	if ($config{'start_cmd'}) {
		$out = &backquote_logged("$config{'start_cmd'} 2>&1");
		}
	else {
		$out = &backquote_logged("$config{'dhcpd_path'} -cf $config{'dhcpd_conf'} -lf $config{'lease_file'} $config{'interfaces'} 2>&1");
		}
	if ($?) {
		&error("<pre>$out</pre>");
		}
	}
&webmin_log("apply");
&redirect("");

