Beispiel #1
0
function BuildOpenVpnSingleClient($ID){
	chdir("/root");
	$main_path="/etc/artica-postfix/openvpn/clients";
	$sql="SELECT * FROM vpnclient WHERE ID=$ID";
	$q=new mysql();	
	$ligne=@mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));	
	if(!$q->ok){echo "Starting......:  OpenVPN client ID $ID, mysql database error, starting from cache\n";return null;}
	$subpath="$main_path/$ID";
	@mkdir("$subpath",0666,true);
	$password=base64_decode($ligne["keypassword"]);
	if($password==null){$password="******";}
	echo "Starting......: OpenVPN client ID $ID, building configuration for {$ligne["connexion_name"]}\n";
	@file_put_contents("$subpath/ca.crt",$ligne["ca_bin"]);
	@file_put_contents("$subpath/certificate.crt",$ligne["cert_bin"]);
	@file_put_contents("$subpath/master-key.key",$ligne["key_bin"]);
	@file_put_contents("$subpath/settings.ovpn",$ligne["ovpn"]);
	@file_put_contents("$subpath/ethlink",$ligne["ethlisten"]);
	@file_put_contents("$subpath/keypassword",$password);
	@file_put_contents("$subpath/routes_additionnal",$ligne["routes_additionnal"]);
	@unlink("$subpath/auth-user-pass");
	if($ligne["EnableAuth"]==1){
		echo "Starting......: OpenVPN client ID $ID, remote authentication is enabled for {$ligne["connexion_name"]}\n";
		@file_put_contents("$subpath/auth-user-pass","{$ligne["AuthUsername"]}\n{$ligne["AuthPassword"]}");
	}	
	BuildOpenVpnClients_changeConfig($subpath,$ID);	
	
	
}
Beispiel #2
0
function BuildOpenVpnClients()
{
    chdir("/root");
    iptables_delete_client_rules();
    $main_path = "/etc/artica-postfix/openvpn/clients";
    $sql = "SELECT * FROM vpnclient WHERE connexion_type=2 and enabled=1 ORDER BY ID";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "Starting......: OpenVPN client, mysql database error, starting from cache\n";
        return null;
    }
    @mkdir("/etc/artica-postfix/openvpn/clients", 0666, true);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $subpath = "{$main_path}/{$ligne["ID"]}";
        @mkdir("{$subpath}", 0666, true);
        $password = base64_decode($ligne["keypassword"]);
        if ($password == null) {
            $password = "******";
        }
        echo "Starting......: OpenVPN client, building configuration for {$ligne["connexion_name"]}\n";
        @file_put_contents("{$subpath}/ca.crt", $ligne["ca_bin"]);
        @file_put_contents("{$subpath}/certificate.crt", $ligne["cert_bin"]);
        @file_put_contents("{$subpath}/master-key.key", $ligne["key_bin"]);
        @file_put_contents("{$subpath}/settings.ovpn", $ligne["ovpn"]);
        @file_put_contents("{$subpath}/ethlink", $ligne["ethlisten"]);
        @file_put_contents("{$subpath}/keypassword", $password);
        BuildOpenVpnClients_changeConfig($subpath, "{$ligne["ID"]}");
    }
}