Exemple #1
0
function BuildBridgeServer(){
	$unix=new unix();
	if(isset($GLOBALS["CLASS_SOCKETS"])){$sock=$GLOBALS["CLASS_SOCKETS"];}else{$GLOBALS["CLASS_SOCKETS"]=new sockets();$sock=$GLOBALS["CLASS_SOCKETS"];}
    $openvpn=$unix->find_program("openvpn");
    $brctl=$unix->find_program("brctl");
    $ifconfig=$unix->find_program("ifconfig");
    $ip_tools=$unix->find_program("ip");
    $routess=array();
    if($openvpn==null){
    	echo "Starting......: OpenVPN bridge unable to stat openvpn binary\n";
    	@unlink("/etc/openvpn/cmdline.conf");
    	exit;
    }
    
    if($brctl==null){
    	echo "Starting......: OpenVPN bridge unable to stat brctl binary\n";
    	@unlink("/etc/openvpn/cmdline.conf");
    	exit;
    }  

    if($ifconfig==null){
    	echo "Starting......: OpenVPN bridge unable to stat ifconfig binary\n";
    	@unlink("/etc/openvpn/cmdline.conf");
    	exit;
    }

    if($ip_tools==null){
    	echo "Starting......: OpenVPN bridge unable to stat ip binary\n";
    	@unlink("/etc/openvpn/cmdline.conf");
    	exit;
    }      
    
    $servername=$unix->hostname_g();	
  	if(preg_match("#^(.+?)\.#",$servername,$re)){$servername=$re[1];}
    $servername=strtoupper($servername);    	
    $ini=new Bs_IniHandler();
    $sock=new sockets();
    $ini->loadString($sock->GET_INFO("ArticaOpenVPNSettings"));
    $BRIDGE_ETH=$ini->_params["GLOBAL"]["BRIDGE_ETH"];
    $BRIDGE_ADDR=$ini->_params["GLOBAL"]["BRIDGE_ADDR"];
    $array_ip=BuildBridgeServer_eth_infos($BRIDGE_ETH);
    
    
   $ca='/etc/artica-postfix/openvpn/keys/allca.crt';
   $dh='/etc/artica-postfix/openvpn/keys/dh1024.pem';
   $key="/etc/artica-postfix/openvpn/keys/vpn-server.key";
   $crt="/etc/artica-postfix/openvpn/keys/vpn-server.crt";    
    
    if(preg_match("#(.+?):([0-9]+)#",$BRIDGE_ETH,$re)){$original_eth=$re[1];}
    
    if($array_ip["IPADDR"]==null){
    	echo "Starting......: OpenVPN bridge for $BRIDGE_ETH (failed to get IP informations)...\n";	
    	return;
    }
    
if(preg_match("#^(.+?)\.([0-9]+)$#",$array_ip["IPADDR"],$re)){$eth_broadcast=$re[1].".255";}
    echo "Starting......: OpenVPN bridge for tap0 -> $original_eth {$array_ip["IPADDR"]}/$eth_broadcast...\n";
    $br0_ip=GetIpaddrOf("br0");
    echo "Starting......: OpenVPN bridge for br0=$br0_ip\n";
    
    if($br0_ip==null){
    	echo "Starting......: OpenVPN bridge creating tap0\n";
    	system("$openvpn --mktun --dev tap0");
    	system("$brctl addbr br0");
    	system("$brctl addif br0 tap0");
    	system("$brctl addif br0 $original_eth");
    	system("$ifconfig $original_eth 0.0.0.0 promisc up");
    	system("$ifconfig tap0 0.0.0.0 promisc up");
    	system("$ifconfig br0 {$array_ip["IPADDR"]} netmask {$array_ip["NETMASK"]} broadcast $eth_broadcast");
		$br0_ip=GetIpaddrOf("br0");  
		if($br0_ip==null){
			   echo "Starting......: OpenVPN failed to create bridge rolling back\n";
			   StopServer();
			   return; 
		}
		system("$ip_tools route add default via {$array_ip["GATEWAY"]} dev br0 proto static");
		
    }
		
		
    $OpenVpnPasswordCert=$sock->GET_INFO("OpenVpnPasswordCert");
	if($OpenVpnPasswordCert==null){$OpenVpnPasswordCert="MyKey";}
   
   	if(is_file("/etc/artica-postfix/openvpn/keys/password")){
   		$askpass="******";
   	}		
	
   	$routess=$routess+GetRoutes();
   	if(is_array($routess)){$routes=implode(" ",$routess);}
		
   $port=$ini->_params["GLOBAL"]["LISTEN_PORT"];
   $server_bridge="--server-bridge $BRIDGE_ADDR {$array_ip["NETMASK"]} {$ini->_params["GLOBAL"]["VPN_DHCP_FROM"]} {$ini->_params["GLOBAL"]["VPN_DHCP_TO"]}";
   $cmd=" --port $port --dev tap0 $server_bridge --comp-lzo $local --ca $ca --dh $dh --key $key --cert $crt";
   $cmd=$cmd. " --ifconfig-pool-persist /etc/artica-postfix/openvpn/ipp.txt $routes";
   $cmd=$cmd. " $askpass--client-to-client -persist-tun -verb 5 --daemon --writepid /var/run/openvpn/openvpn-server.pid --log \"/var/log/openvpn/openvpn.log\"";
   $cmd=$cmd. " --status /var/log/openvpn/openvpn-status.log 10";
   @file_put_contents("/etc/openvpn/cmdline.conf",$cmd);

   
   
    
	
}
Exemple #2
0
function stop_server()
{
    echo '<div class="block">';
    $output = array();
    echo '<center>Shutdown NZBGet server</center><br>';
    echo 'Executing stop-script:<br>';
    $retval = StopServer($output);
    if (count($output) > 0) {
        foreach ($output as $line) {
            echo $line . '<br>';
        }
    } else {
        echo '<font color="#00BB00">Stop-command executed successfully.</font><br><br>';
    }
    echo '</div><br>';
}