#!/usr/local/bin/perl
# apply.cgi
# Shut down and re-start the PPTP server

require './pptp-server-lib.pl';
&error_setup($text{'apply_err'});

# Stop first
if ($config{'stop_cmd'}) {
	$out = &backquote_logged("$config{'stop_cmd'} 2>&1 </dev/null");
	&error("<pre>$out</pre>") if ($?);
	}
else {
	$pid = &get_pptpd_pid();
	if (!$pid || !&kill_logged('TERM', $pid)) {
		&error($text{'stop_egone'});
		}
	}

# Re-start
$cmd = $config{'start_cmd'} || $config{'pptpd'};
$temp = &tempname();
$rv = &system_logged("$cmd >$temp 2>&1 </dev/null");
$out = `cat $temp`;
unlink($temp);
if ($rv) {
	&error("<pre>$out</pre>");
	}

&webmin_log("apply");
&redirect("");

