Example #1
0
function StopServer()
{
    $unix = new unix();
    $openvpn = $unix->find_program("openvpn");
    $brctl = $unix->find_program("brctl");
    $ifconfig = $unix->find_program("ifconfig");
    $ip_tools = $unix->find_program("ip");
    $pgrep = $unix->find_program("pgrep");
    $kill = $unix->find_program("kill");
    $ini = new Bs_IniHandler();
    $sock = new sockets();
    $ini->loadString($sock->GET_INFO("ArticaOpenVPNSettings"));
    $BRIDGE_ETH = $ini->_params["GLOBAL"]["BRIDGE_ETH"];
    $ENABLE_BRIDGE_MODE = $ini->_params["GLOBAL"]["ENABLE_BRIDGE_MODE"];
    if (!is_numeric($ENABLE_BRIDGE_MODE)) {
        $ENABLE_BRIDGE_MODE = 0;
    }
    echo "Stopping OpenVPN......................: Mode Bridge = {$ENABLE_BRIDGE_MODE}\n";
    if ($ENABLE_BRIDGE_MODE == 1) {
        echo "Stopping OpenVPN......................: Stopping Server bridged on={$BRIDGE_ETH}\n";
        if (preg_match("#(.+?):([0-9]+)#", $BRIDGE_ETH, $re)) {
            $original_eth = $re[1];
        }
        if ($original_eth != null) {
            $array_ip = BuildBridgeServer_eth_infos($BRIDGE_ETH);
            echo "Stopping OpenVPN......................: checking bridges and {$original_eth}\n";
            $array = GetBridgeExists("br0");
            if (is_array($array)) {
                echo "Stopping OpenVPN......................: Bridge br0 exists\n";
                system("{$ifconfig} br0 down");
                while (list($num, $ligne) = each($array)) {
                    echo "Stopping OpenVPN......................: remove {$ligne} from br0\n";
                    system("brctl delif br0 {$ligne}");
                }
                echo "Stopping OpenVPN......................: remove br0\n";
                system("brctl delbr br0");
                system("{$ifconfig} {$original_eth} down");
            }
            echo "Stopping OpenVPN......................: rebuild {$original_eth} settings\n";
            system("{$ifconfig} {$original_eth} up");
            if (GetIpaddrOf($original_eth) == null) {
                if (preg_match("#^(.+?)\\.([0-9]+)\$#", $array_ip["IPADDR"], $re)) {
                    $eth_broadcast = "broadcast {$re[1]}.255";
                }
                system("{$ifconfig} {$original_eth} {$array_ip["IPADDR"]} netmask {$array_ip["NETMASK"]} {$eth_broadcast}");
            }
            system("{$ip_tools} route add default via {$array_ip["GATEWAY"]} dev {$original_eth}  proto static");
        }
    }
    echo "Stopping OpenVPN......................: Find ghost processes\n";
    exec("{$pgrep} -l -f \"{$openvpn} --port.+?--dev\" 2>&1", $results);
    while (list($num, $ligne) = each($results)) {
        if (preg_match("#^([0-9]+)\\s+#", $ligne, $re)) {
            if ($unix->process_exists($re[1])) {
                echo "Stopping OpenVPN......................: {$re[1]} PID\n";
                unix_system_kill_force($re[1]);
            }
        }
    }
    iptables_delete_rules();
}
Example #2
0
function StopServer(){
	$unix=new unix();
    $openvpn=$unix->find_program("openvpn");
    $brctl=$unix->find_program("brctl");
    $ifconfig=$unix->find_program("ifconfig");
    $ip_tools=$unix->find_program("ip");	
    $pgrep=$unix->find_program("pgrep");
    $kill=$unix->find_program("kill");
	$ini=new Bs_IniHandler();
    $sock=new sockets();
    $ini->loadString($sock->GET_INFO("ArticaOpenVPNSettings"));
    $BRIDGE_ETH=$ini->_params["GLOBAL"]["BRIDGE_ETH"]; 
    echo "Stopping OpenVPN......................: stopping server bridged on=$BRIDGE_ETH\n";   
	if(preg_match("#(.+?):([0-9]+)#",$BRIDGE_ETH,$re)){$original_eth=$re[1];}
	if($original_eth<>null){
		$array_ip=BuildBridgeServer_eth_infos($BRIDGE_ETH);
		echo "Stopping OpenVPN......................: checking bridges and $original_eth\n";
		$array=GetBridgeExists("br0");
	
		if(is_array($array)){
			echo "Stopping OpenVPN......................: Bridge br0 exists\n";
			system("$ifconfig br0 down");
			while (list ($num, $ligne) = each ($array) ){
				echo "Stopping OpenVPN......................: remove $ligne from br0\n";
				system("brctl delif br0 $ligne");
			}
			
			echo "Stopping OpenVPN......................: remove br0\n";
			system("brctl delbr br0");
			system("$ifconfig $original_eth down");
			}
			
			echo "Stopping OpenVPN......................: rebuild $original_eth settings\n";
			system("$ifconfig $original_eth up");
			if(GetIpaddrOf($original_eth)==null){
				if(preg_match("#^(.+?)\.([0-9]+)$#",$array_ip["IPADDR"],$re)){$eth_broadcast="broadcast {$re[1]}.255";}
				system("$ifconfig $original_eth {$array_ip["IPADDR"]} netmask {$array_ip["NETMASK"]} $eth_broadcast");
			}
			system("$ip_tools route add default via {$array_ip["GATEWAY"]} dev $original_eth  proto static");
	}
	
	
	echo "Stopping OpenVPN......................: find ghost processes\n";
	exec("$pgrep -l -f \"$openvpn --port.+?--dev\" 2>&1",$results);
	while (list ($num, $ligne) = each ($results) ){
		if(preg_match("#^([0-9]+)\s+#", $ligne,$re)){
			if($unix->process_exists($re[1])){
				echo "Stopping OpenVPN......................: {$re[1]} PID\n"; 
				shell_exec("$kill -9 {$re[1]} >/dev/null 2>&1");
			}
		}
		
	}
	
	
	
	iptables_delete_rules();

}
Example #3
0
function StopServer()
{
    $unix = new unix();
    $openvpn = $unix->find_program("openvpn");
    $brctl = $unix->find_program("brctl");
    $ifconfig = $unix->find_program("ifconfig");
    $ip_tools = $unix->find_program("ip");
    $ini = new Bs_IniHandler();
    $sock = new sockets();
    $ini->loadString($sock->GET_INFO("ArticaOpenVPNSettings"));
    $BRIDGE_ETH = $ini->_params["GLOBAL"]["BRIDGE_ETH"];
    echo "Stopping OpenVPN......................: stopping server bridged on={$BRIDGE_ETH}\n";
    if (preg_match("#(.+?):([0-9]+)#", $BRIDGE_ETH, $re)) {
        $original_eth = $re[1];
    }
    if ($original_eth != null) {
        $array_ip = BuildBridgeServer_eth_infos($BRIDGE_ETH);
        echo "Stopping OpenVPN......................: checking bridges and {$original_eth}\n";
        $array = GetBridgeExists("br0");
        if (is_array($array)) {
            echo "Stopping OpenVPN......................: Bridge br0 exists\n";
            system("{$ifconfig} br0 down");
            while (list($num, $ligne) = each($array)) {
                echo "Stopping OpenVPN......................: remove {$ligne} from br0\n";
                system("brctl delif br0 {$ligne}");
            }
            echo "Stopping OpenVPN......................: remove br0\n";
            system("brctl delbr br0");
            system("{$ifconfig} {$original_eth} down");
        }
        echo "Stopping OpenVPN......................: rebuild {$original_eth} settings\n";
        system("{$ifconfig} {$original_eth} up");
        if (GetIpaddrOf($original_eth) == null) {
            if (preg_match("#^(.+?)\\.([0-9]+)\$#", $array_ip["IPADDR"], $re)) {
                $eth_broadcast = "broadcast {$re[1]}.255";
            }
            system("{$ifconfig} {$original_eth} {$array_ip["IPADDR"]} netmask {$array_ip["NETMASK"]} {$eth_broadcast}");
        }
        system("{$ip_tools} route add default via {$array_ip["GATEWAY"]} dev {$original_eth}  proto static");
    }
    iptables_delete_rules();
}