Пример #1
1
function SAVE_SERVER()
{
    $tpl = new templates();
    if (isset($_POST["OpenVpnPasswordCert"])) {
        $sock = new sockets();
        $oldpassword = $sock->GET_INFO("OpenVpnPasswordCert");
        if ($oldpassword == null) {
            $oldpassword = "******";
        }
        if ($oldpassword != $_POST["OpenVpnPasswordCert"]) {
            echo $tpl->javascript_parse_text("{OPENVPN_PASSWORD_CHANGED}");
        }
        $sock->SET_INFO("OpenVpnPasswordCert", $_POST["OpenVpnPasswordCert"]);
    }
    $vpn = new openvpn();
    while (list($num, $ligne) = each($_POST)) {
        $vpn->main_array["GLOBAL"][$num] = $ligne;
    }
    $vpn->Save();
}
Пример #2
0
function config_popup()
{
    $vpn = new openvpn();
    $config = $vpn->BuildClientconf($_SESSION["uid"]);
    $tbconfig = explode("\n", $config);
    $html_logs[] = htmlentities("VPN config -> " . strlen($config) . " bytes length (" . count($tbconfig) . " lines)");
    $uid = $_SESSION["uid"];
    writelogs("VPN config -> " . strlen($config) . " bytes length (" . count($tbconfig) . " lines)", __FUNCTION__, __FILE__, __LINE__);
    $sock = new sockets();
    if (!$sock->SaveConfigFile($config, "{$uid}.ovpn")) {
        $html_logs[] = htmlentities("Framework error while saving  -> {$uid}.ovpn;" . strlen($config) . " bytes length (" . count($tbconfig) . " lines)");
    }
    writelogs("sockets() OK", __FUNCTION__, __FILE__, __LINE__);
    //$datas=$sock->getfile('OpenVPNGenerate:'.$uid);
    $datas = $sock->getFrameWork("openvpn.php?build-vpn-user={$_SESSION["uid"]}&basepath=" . dirname(__FILE__));
    $tbl = explode("\n", $datas);
    $tbl = array_reverse($tbl);
    while (list($num, $line) = each($tbl)) {
        if (trim($line) == null) {
            continue;
        }
        $html_logs[] = "<div><code style='font-size:10px;color:black;'>" . htmlentities($line) . "</code></div>";
    }
    if (is_file('ressources/logs/' . $uid . '.zip')) {
        $download = "\n\t\t<center>\n\t\t\t<a href='ressources/logs/" . $uid . ".zip'><img src='img/download-64.png' title=\"{DOWNLOAD_CONFIG_FILES}\" style='padding:8Px;border:1px solid #055447;margin:3px'></a>\n\t\t</center>\n\t\t";
    }
    $html = "\n\t\n\t{$download}\n\t<H3>{events}</H3>\n\t" . ParagrapheTXT("<div style='width:100%;height:200px;overflow:auto'>" . implode("\n", $html_logs) . "</div>");
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
Пример #3
0
function buildconfig()
{
    $vpn = new openvpn();
    $connection_name = trim(strtolower($_POST["connection_name"]));
    if ($connection_name == null) {
        $connection_name = time();
    }
    $connection_name = str_replace(" ", "-", $connection_name);
    $connection_name = replace_accents($connection_name);
    $connection_name = str_replace("/", "-", $connection_name);
    $connection_name = str_replace('\\', "-", $connection_name);
    $tools = new htmltools_inc();
    $connection_name = $tools->StripSpecialsChars($connection_name);
    $vpn->ComputerOS = $_POST["ComputerOS"];
    $html_logs[] = "<div><code style='font-size:10px;color:black;'>Operating system : {$config->ComputerOS}</div>";
    $html_logs[] = "<div><code style='font-size:10px;color:black;'>Connection name. : {$connection_name}</div>";
    $config = $vpn->BuildClientconf($connection_name);
    $tbconfig = explode("\n", $config);
    $html_logs[] = htmlentities("VPN config -> " . strlen($config) . " bytes length (" . count($tbconfig) . " lines)");
    $uid = $_SESSION["uid"];
    writelogs("VPN config -> " . strlen($config) . " bytes length (" . count($tbconfig) . " lines)", __FUNCTION__, __FILE__, __LINE__);
    $sock = new sockets();
    if (!$sock->SaveConfigFile($config, "{$connection_name}.ovpn")) {
        $html_logs[] = htmlentities("Framework error while saving  -> {$connection_name}.ovpn;" . strlen($config) . " bytes length (" . count($tbconfig) . " lines)");
    }
    writelogs("sockets() OK", __FUNCTION__, __FILE__, __LINE__);
    //$datas=$sock->getfile('OpenVPNGenerate:'.$uid);
    $datas = $sock->getFrameWork("openvpn.php?build-vpn-user={$connection_name}&basepath=" . dirname(__FILE__));
    $tbl = explode("\n", $datas);
    $tbl = array_reverse($tbl);
    while (list($num, $line) = each($tbl)) {
        if (trim($line) == null) {
            continue;
        }
        $html_logs[] = "<div><code style='font-size:10px;color:black;'>" . htmlentities($line) . "</code></div>";
    }
    if (is_file('ressources/logs/' . $connection_name . '.zip')) {
        $download = "\n\t\t<center>\n\t\t<div style='width:320px;border:2px solid #CCCCCC;padding:5px;margin:10px'>\n\t\t\t<div style='font-size:14px'>{click_here}</div>\n\t\t\t<a href='ressources/logs/" . $connection_name . ".zip'>\n\t\t\t\t<img src='img/download-64.png' title=\"{DOWNLOAD_CONFIG_FILES}\" style='padding:8Px;border:1px solid #055447;margin:3px'></a>\n\t\t\t\t<br>\n\t\t\t\t<a href='ressources/logs/" . $connection_name . ".zip' style='font-size:16px;text-decoration:underline'>{$connection_name}.zip</a>\n\t\t</div>\t\t\n\t\t\t\t\n\t\t</center>\n\t\t";
    }
    $html = "\n\t\n\t{$download}\n\t<div style='font-size:16px'>{events}</div>\n\t<div style='width:100%;height:200px;overflow:auto'>" . implode("\n", $html_logs) . "</div>";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
Пример #4
0
function xrun()
{
    $unix = new unix();
    build_progress("{enable_service}", 15);
    $vpn = new openvpn();
    $vpn->main_array["GLOBAL"]["ENABLE_SERVER"] = 1;
    @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableOPenVPNServerMode", 1);
    $vpn->Save(true);
    build_progress("{building_configuration}", 50);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.openvpn.php --server-conf");
    system("{$php} /usr/share/artica-postfix/exec.initslapd.php --openvpn-server");
    build_progress("{restart_service}", 90);
    system("/etc/init.d/openvpn-server restart");
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        build_progress("{done}", 100);
    } else {
        build_progress("{failed}", 100);
    }
}
Пример #5
0
function generatefiles()
{
    $vpn = new openvpn();
    $config = $vpn->BuildClientconf($_SESSION["uid"]);
    $uid = $_SESSION["uid"];
    $sock = new sockets();
    $sock->SaveConfigFile($config, "{$uid}.ovpn");
    $datas = $sock->getFrameWork("openvpn.php?build-vpn-user={$_SESSION["uid"]}&basepath=" . dirname(__FILE__));
    $tbl = explode("\n", $datas);
    $tbl = array_reverse($tbl);
    while (list($num, $line) = each($tbl)) {
        if (trim($line) == null) {
            continue;
        }
        $html = $html . "<div><code style='font-size:11px'>" . htmlentities($line) . "</code></div>";
    }
    if (is_file('ressources/logs/' . $uid . '.zip')) {
        $download = "\n\t\t<center>\n\t\t\t<a href='ressources/logs/" . $uid . ".zip'><img src='img/disk-save-64.png'></a>\n\t\t</center>\n\t\t";
    }
    $html = "\n\t<H1>{DOWNLOAD_CONFIG_FILES}</H1>\n\t{$download}\n\t" . RoundedLightWhite("\n\t<div style='width:100%;height:200px;overflow:auto'>\n\t\n\t{$html}</div>") . "\n\t\n\t\n\t";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
Пример #6
0
function windows_client($uid){
	$vpn=new openvpn();
	$config=$vpn->BuildClientconf($uid);
	@file_put_contents("/etc/artica-postfix/settings/Daemons/$uid.ovpn",$config);	
	$sock=new sockets();
	@mkdir("/tmp/$uid",0666,true);
	if($GLOBALS["VERBOSE"]){$verbose="&verbose=yes";}
	if($GLOBALS["VERBOSE"]){echo "openvpn.php?build-vpn-user=$uid&basepath=/tmp/$uid$verbose\n";}
	echo $sock->getFrameWork("openvpn.php?build-vpn-user=$uid&basepath=/tmp/$uid$verbose");
	@unlink("/etc/artica-postfix/settings/Daemons/$uid.ovpn");
}
Пример #7
0
function _export_ovpn($uid)
{
    include_once dirname(__FILE__) . '/ressources/class.openvpn.inc';
    $vpn = new openvpn();
    $config = $vpn->BuildClientconf($uid);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/{$uid}.ovpn", $config);
    @mkdir("/var/cache/openvpn-users", 0666, true);
    $sock = new sockets();
    $datas = $sock->getFrameWork("openvpn.php?build-vpn-user={$uid}&basepath=/var/cache/openvpn-users");
    $tbl = explode("\n", $datas);
    $tbl = array_reverse($tbl);
    while (list($num, $line) = each($tbl)) {
        if (trim($line) == null) {
            continue;
        }
        events("{$line}", __FUNCTION__, __FILE__, __LINE__);
        $GLOBALS["html_logs"][] = $line;
    }
    if (!is_file("/var/cache/openvpn-users/ressources/logs/{$uid}.zip")) {
        return false;
    }
    @unlink("/etc/artica-postfix/settings/Daemons/{$uid}.ovpn");
    return "/var/cache/openvpn-users/ressources/logs/{$uid}.zip";
}
function import_ovpn($filepath)
{
    $openvpn = new openvpn();
    if (!$openvpn->ImportConcentrateur($filepath)) {
        return $openvpn->events;
    }
    $sock = new sockets();
    $sock->getFrameWork("cmd.php?artica-meta-openvpn-sites=yes");
}
Пример #9
0
function SaveBridgeMode()
{
    $vpn = new openvpn();
    $vpn->main_array["GLOBAL"]["ENABLE_BRIDGE_MODE"] = $_GET["ENABLE_BRIDGE"];
    $vpn->Save();
}
Пример #10
0
function OPENVPN_CONCENTRATEUR($value)
{
    $unix = new unix();
    $unzip = $unix->find_program("unzip");
    events("Decoding parameters", __FUNCTION__, __FILE__, __LINE__);
    $array = unserialize(base64_decode($value));
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    $reload_datas = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-openvpn-sites >/dev/null 2>&1 &";
    if (strlen($unzip) == 0) {
        events("Unable to stat unzip, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (unzip no such file)", null, "VPN");
        return true;
    }
    if (!is_array($array)) {
        events("Corrupted data, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (corrupted datas)", null, "VPN");
        return true;
    }
    $master = $array["MASTER"];
    $sitename = $array["SITENAME"];
    events("download configuration file for master:{$master} and site name: {$sitename}", __FUNCTION__, __FILE__, __LINE__);
    $meta = new artica_meta(true);
    $http = new httpget();
    $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY));
    $body = $http->send("{$meta->ArticaMetaHostname}/lic.query.server.php", "post", array("DATAS" => $datasToSend, "GET_OVPN_REMOTE_SITE" => "yes", "master_uuid" => "{$master}", "sitename" => "{$sitename}"));
    if (strlen($body) < 10) {
        events("Corrupted data after downloading, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (corrupted datas after download)", null, "VPN");
        return true;
    }
    @mkdir("/tmp/{$sitename}", 666, true);
    @file_put_contents("/tmp/{$sitename}/conf.zip", $body);
    shell_exec("{$unzip} -j -o /tmp/{$sitename}/conf.zip -d /tmp/{$sitename}/ >/tmp/{$sitename}/unzip.txt 2>&1");
    include_once "ressources/class.openvpn.inc";
    $openvpn = new openvpn();
    $handle = opendir("/tmp/{$sitename}");
    $f = false;
    while (false !== ($file = readdir($handle))) {
        if (preg_match("#(.+?).ovpn\$#", $file)) {
            if (!$openvpn->ImportConcentrateur("/tmp/{$sitename}/{$file}", $master)) {
                events("ImportConcentrateur() failed" . @implode("\n", $openvpn->events), __FUNCTION__, __FILE__, __LINE__);
                send_email_events("Failed to import concentrator parameters ()", @implode("\n", $openvpn->events), "VPN");
                return true;
            }
            $f = true;
        }
    }
    if (!$f) {
        events("Corrupted data after downloading, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (unable to find ovpn file after uncompress)", null, "VPN");
    }
    shell_exec($reload_datas);
    events("Restarting OpenVPN", __FUNCTION__, __FILE__, __LINE__);
    shell_exec("/etc/init.d/artica-postfix restart openvpn &");
    return true;
}
Пример #11
0
function SAVE_SERVER()
{
    $tpl = new templates();
    if (trim($vpn->main_array["GLOBAL"]["IP_START"]) == null) {
        $vpn->main_array["GLOBAL"]["IP_START"] = "10.8.0.0";
    }
    if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.#", $vpn->main_array["GLOBAL"]["IP_START"], $re)) {
        $IP_START_CONFIG = "{$re[1]}.{$re[2]}.{$re[3]}";
    }
    if (isset($_POST["IP_START"])) {
        preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.#", $_POST["IP_START"], $re);
        $startip = "{$re[1]}.{$re[2]}.{$re[3]}";
        $ips = new networking();
        $ipsArray = $ips->ALL_IPS_GET_ARRAY();
        while (list($localip, $ligne) = each($ipsArray)) {
            preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.#", $localip, $re);
            $currentIP = "{$re[1]}.{$re[2]}.{$re[3]}";
            if ($currentIP == $IP_START_CONFIG) {
                continue;
            }
            if ($currentIP == $startip) {
                echo $tpl->javascript_parse_text("{ERROR_OPENVPN_CLIENTISSAMEIPSERVER}\n`{$currentIP}` = `{$startip}`");
                $_POST["IP_START"] = "10.8.0.0";
                return;
            }
        }
    }
    $vpn = new openvpn();
    while (list($num, $ligne) = each($_POST)) {
        $vpn->main_array["GLOBAL"][$num] = $ligne;
    }
    $vpn->Save();
}
Пример #12
0
function remote_site_config()
{
    $vpn = new openvpn();
    $siteid = $_GET["config-site"];
    $q = new mysql();
    $sql = "SELECT * FROM vpnclient WHERE ID='{$siteid}'";
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    $sitename = $ligne["sitename"];
    $sitename = str_replace(" ", "_", $sitename);
    $sitename = strtolower($sitename);
    $config = $vpn->BuildClientconf($sitename);
    $uid = $sitename;
    $sock = new sockets();
    $sock->SaveConfigFile($config, "{$uid}.ovpn");
    //$datas=$sock->getfile('OpenVPNGenerate:'.$uid);
    $datas = $sock->getFrameWork("openvpn.php?build-vpn-user={$uid}&basepath=" . dirname(__FILE__));
    $tbl = explode("\n", $datas);
    $tbl = array_reverse($tbl);
    while (list($num, $line) = each($tbl)) {
        if (trim($line) == null) {
            continue;
        }
        $color = "black";
        if (preg_match("#error#", $line)) {
            $color = "red";
        }
        if (preg_match("#warning#", $line)) {
            $color = "red";
        }
        if (preg_match("#unable to#", $line)) {
            $color = "red";
        }
        $html = $html . "<div><code style='font-size:10px;color:{$color};'>" . htmlentities($line) . "</code></div>";
    }
    if (is_file('ressources/logs/' . $uid . '.zip')) {
        $download = "\n\t\t<center>\n\t\t\t<a href='ressources/logs/" . $uid . ".zip'><img src='img/download-64.png' title=\"{DOWNLOAD_CONFIG_FILES}\" style='padding:8Px;border:1px solid #055447;margin:3px'></a>\n\t\t</center>\n\t\t";
    }
    $download = RoundedLightWhite($download) . "<hr>";
    $html = "\n\t<H1>{DOWNLOAD_CONFIG_FILES}</H1>\n\t\n\t{$download}\n\t<H3>{events}</H3>\n\t" . RoundedLightWhite("<div style='width:100%;height:200px;overflow:auto'>{$html}</div>");
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
Пример #13
0
function routes_delete()
{
    $vpn = new openvpn();
    unset($vpn->routes[$_POST["DELETE_ROUTE_FROM"]]);
    $vpn->Save();
}
function xrun($commonname)
{
    if ($commonname == "OpenVPN-MASTER") {
        build_server();
        exit;
    }
    if (isset($_GET["site-id"])) {
        $site_id = $_GET["site-id"];
    }
    $unix = new unix();
    $rm = $unix->find_program("rm");
    $q = new mysql();
    $sql = "SELECT ComputerOS FROM openvpn_clients WHERE uid='{$commonname}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        build_progress(110, "{failed}");
        echo "ERROR: {$q->mysql_error}\n";
        exit;
    }
    $vpn = new openvpn();
    $vpn->ComputerOS = $ligne["ComputerOS"];
    $config = $vpn->BuildClientconf($commonname);
    $workingDir = "/etc/artica-postfix/openvpn/{$commonname}";
    $basepath = $workingDir;
    if (is_dir($workingDir)) {
        system("{$rm} -rf {$workingDir}");
    }
    @mkdir($workingDir, 0755, true);
    @mkdir("{$workingDir}/newcerts");
    @file_put_contents("{$workingDir}/{$commonname}.ovpn", $config);
    if (!is_file('/usr/bin/zip')) {
        build_progress(110, "{failed}");
        echo "ERROR: unable to stat \"zip\", please advise your Administrator\n";
        exit;
    }
    //http://www.drazzib.com/docs/admin/openvpn.html
    $filesize = filesize("{$workingDir}/{$commonname}.ovpn");
    if ($filesize == 0) {
        build_progress(110, "{failed}");
        echo "ERROR: corrupted \"{$commonname}.ovpn\" 0 bytes, please advise your Administrator\n";
        exit;
    }
    $ini = new Bs_IniHandler();
    $sock = new sockets();
    $ini->loadString($sock->GET_INFO("ArticaOpenVPNSettings"));
    $ligne = unserialize($sock->GET_INFO("OpenVPNCertificateSettings"));
    $hostname = $unix->hostname_g();
    $cp = $unix->find_program("cp");
    $rm = $unix->find_program("rm");
    $php = $unix->LOCATE_PHP5_BIN();
    $openssl = $unix->find_program("openssl");
    $CertificateMaxDays = intval($ligne["CertificateMaxDays"]);
    if ($CertificateMaxDays < 5) {
        $CertificateMaxDays = 730;
    }
    if (trim($ligne["password"]) == null) {
        $ldap = new clladp();
        $ligne["password"] = $ldap->ldap_password;
    }
    $zipfile = "{$workingDir}/{$commonname}.zip";
    if (is_file($zipfile)) {
        @unlink($zipfile);
    }
    build_config($workingDir, $unix->hostname_g());
    $password = $ligne["password"];
    $config_path = "{$workingDir}/openssl.cf";
    if (!is_file($config_path)) {
        echo "{$config_path} no such file\n";
        build_progress(110, "{failed}");
        if (is_dir($workingDir)) {
            system("{$rm} -rf {$workingDir}");
        }
        return;
    }
    chdir($workingDir);
    $filetemp = $unix->FILE_TEMP();
    shell_exec("source {$workingDir}/vars");
    $open_vpn_ca_crt = "/etc/artica-postfix/openvpn/keys/allca.crt";
    //$open_vpn_ca_crt="/etc/artica-postfix/openvpn/keys/openvpn-ca.crt";
    copy("{$open_vpn_ca_crt}", "{$workingDir}/{$commonname}.ca");
    if (!is_file($open_vpn_ca_crt)) {
        echo "{$open_vpn_ca_crt} no such file\n";
        build_progress(110, "{failed}");
        if (is_dir($workingDir)) {
            system("{$rm} -rf {$workingDir}");
        }
        return;
    }
    if (!is_file("{$workingDir}/{$commonname}.ca")) {
        echo "{$workingDir}/{$commonname}.ca no such file\n";
        build_progress(110, "{failed}");
        if (is_dir($workingDir)) {
            system("{$rm} -rf {$workingDir}");
        }
        return;
    }
    @unlink("/etc/artica-postfix/openvpn/{$commonname}.ovpn");
    @unlink("{$workingDir}/keys/index.txt");
    shell_exec("/bin/touch {$workingDir}/index.txt");
    $cmd = "echo 01 > {$workingDir}/serial";
    shell_exec("{$cmd}");
    @unlink("/etc/artica-postfix/openvpn/keys/index.txt");
    shell_exec("/bin/touch /etc/artica-postfix/openvpn/keys/index.txt");
    $cmd = "echo 01 > /etc/artica-postfix/openvpn/keys/serial";
    shell_exec("{$cmd}");
    $subj = @file_get_contents("{$workingDir}/subj.cf");
    $subjAndConfig = "{$subj} -config {$workingDir}/openssl.cf";
    $cmd = "{$openssl} req -nodes -new -keyout \"{$workingDir}/{$commonname}.key\" -out \"{$workingDir}/{$commonname}.csr\" -batch {$subjAndConfig}";
    echo "{$cmd}\n";
    system("{$cmd}");
    if (!check_file("{$workingDir}/{$commonname}.key")) {
        echo "{$workingDir}/{$commonname}.key no such file\n";
        build_progress(110, "{failed}");
        if (is_dir($workingDir)) {
            system("{$rm} -rf {$workingDir}");
        }
        return;
    }
    if (!check_file("{$workingDir}/{$commonname}.csr")) {
        echo "{$workingDir}/{$commonname}.csr no such file\n";
        build_progress(110, "{failed}");
        if (is_dir($workingDir)) {
            system("{$rm} -rf {$workingDir}");
        }
        return;
    }
    $open_vpn_ca_key = "/etc/artica-postfix/openvpn/keys/openvpn-ca.key";
    $open_vpn_ca_crt = "/etc/artica-postfix/openvpn/keys/openvpn-ca.crt";
    $cmd = "{$openssl} ca -keyfile {$open_vpn_ca_key} -cert {$open_vpn_ca_crt}  -out \"{$workingDir}/{$commonname}.crt\" -in \"{$workingDir}/{$commonname}.csr\"  -batch {$subjAndConfig}  -passin pass:{$password}";
    echo "{$cmd}\n";
    system("{$cmd}");
    if (!check_file("{$workingDir}/{$commonname}.crt")) {
        echo "{$workingDir}/{$commonname}.crt no such file\n";
        build_progress(110, "{failed}");
        if (is_dir($workingDir)) {
            system("{$rm} -rf {$workingDir}");
        }
        return;
    }
    $mycurrentdir = getcwd();
    chdir($workingDir);
    @file_put_contents("{$workingDir}/password", $password);
    $cmd = "/usr/bin/zip {$zipfile}";
    $cmd = $cmd . " {$commonname}.crt {$commonname}.csr {$commonname}.key {$commonname}.ovpn {$commonname}.ca password";
    echo "{$cmd}\n";
    system($cmd);
    chdir($mycurrentdir);
    @chmod($zipfile, 0777);
    @chmod($workingDir, 0777);
    $filesize = @filesize($zipfile);
    $sql = "UPDATE openvpn_clients SET \n      `zipcontent`=LOAD_FILE('{$zipfile}'),\n      `zipsize`='{$filesize}'\n\t   WHERE uid='{$commonname}'";
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        @unlink($filetemp);
        @unlink($zipfile);
        system("{$rm} -rf {$workingDir}");
        echo $q->mysql_error;
        build_progress(110, "{failed}");
        return;
    }
    build_progress(100, "{success}...");
}
Пример #15
0
        }
        $extension = strtolower(strrchr($_FILES['file']['name'], '.'));
        if (!in_array($extension, array('.crt', '.key'))) {
            throw new Exception('Extension du fichier non valide (autorisé .crt .key) : ' . $extension);
        }
        if (filesize($_FILES['file']['tmp_name']) > 1000000) {
            throw new Exception(__('Le fichier est trop gros (maximum 1mo)', __FILE__));
        }
        switch (init('type')) {
            case 'ca':
                $filepath = dirname(__FILE__) . '/../../data/ca_' . $eqLogic->getConfiguration('key') . '.crt';
                break;
            case 'caClient':
                $filepath = dirname(__FILE__) . '/../../data/cert_' . $eqLogic->getConfiguration('key') . '.crt';
                break;
            case 'keyClient':
                $filepath = dirname(__FILE__) . '/../../data/key_' . $eqLogic->getConfiguration('key') . '.key';
                break;
        }
        file_put_contents($filepath, file_get_contents($_FILES['file']['tmp_name']));
        ajax::success();
    }
    if (init('action') == 'updateOpenvpn') {
        openvpn::updateOpenvpn();
        ajax::success();
    }
    throw new Exception(__('Aucune méthode correspondante à : ', __FILE__) . init('action'));
    /*     * *********Catch exeption*************** */
} catch (Exception $e) {
    ajax::error(displayExeption($e), $e->getCode());
}