function xstart()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $tar = $unix->find_program("tar");
    build_progress("{downloading} roundcubeemail-1.1.2.tar.gz", 20);
    $tmpfile = $unix->FILE_TEMP();
    $curl = new ccurl("http://articatech.net/download/postfix-debian7/roundcubeemail-1.1.2.tar.gz");
    if (!$curl->GetFile($tmpfile)) {
        echo "Failed: " . $curl->error . "\n";
        @unlink($tmpfile);
        build_progress("{failed} roundcubeemail-1.1.2.tar.gz", 110);
        return;
    }
    build_progress("{uncompressing} roundcubeemail-1.1.2.tar.gz", 50);
    system("{$tar} xf {$tmpfile} -C /");
    @unlink($tmpfile);
    if (!is_file("/usr/share/roundcube/index.php")) {
        build_progress("{uncompressing} roundcubeemail-1.1.2.tar.gz {failed}", 110);
        return;
    }
    build_progress("{verify_database}", 60);
    system("{$php} /usr/share/artica-postfix/exec.roundcube.php --database");
    build_progress("{restarting_service}", 70);
    system("{$php} /usr/share/artica-postfix/exec.roundcube.php --restart");
    system("/etc/init.d/artica-status restart");
    build_progress("{installing} roundcubeemail-1.1.2.tar.gz {success}", 100);
}
function Import()
{
    $curl = new ccurl("http://www.privacyonline.org.uk/downloads/privacyonline-btl.tpl");
    $curl->NoHTTP_POST = true;
    $curl->GetFile("/tmp/privacyonline-btl.tpl");
    $f = file("/tmp/privacyonline-btl.tpl");
    @unlink("/tmp/privacyonline-btl.tpl");
    while (list($indx, $line) = each($f)) {
        $line = trim($line);
        $line = str_replace("\n", "", $line);
        $line = str_replace("\r", "", $line);
        if (!preg_match("#^\\-d\\s+(.+)#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "SKIP \"{$line}\"\n";
            }
            continue;
        }
        $line = $re[1];
        if (strpos($line, " ") > 0) {
            if ($GLOBALS["VERBOSE"]) {
                echo "SKIP \"{$line}\"\n";
            }
            continue;
        }
        if (strpos($line, "/") > 0) {
            if ($GLOBALS["VERBOSE"]) {
                echo "SKIP \"{$line}\"\n";
            }
            continue;
        }
        $domain[$line] = $line;
    }
    return $domain;
}
Beispiel #3
0
function iprulesDNS()
{
    $unix = new unix();
    $IPCHAIN = "dnsfilter";
    $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($unix->process_exists(@file_get_contents($pidfile), basename(__FILE__))) {
        echo "Starting......: " . date("H:i:s") . " iptables configurator already executed PID " . @file_get_contents($pidfile) . "\n";
        die;
    }
    $pid = getmypid();
    file_put_contents($pidfile, $pid);
    $sock = new sockets();
    $EnableIptablesDNS = $sock->GET_INFO("EnableIptablesDNS");
    if (!is_numeric($EnableIptablesDNS)) {
        $EnableIptablesDNS = 1;
    }
    if ($EnableIptablesDNS == 0) {
        $ip = new iptables_exec();
        if ($ip->is_chain_exists($IPCHAIN)) {
            shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}");
            shell_exec("{$GLOBALS["iptables"]} -X {$IPCHAIN}");
        }
        return;
    }
    $tmpfile = $unix->FILE_TEMP();
    $curl = new ccurl("https://raw.github.com/smurfmonitor/dns-iptables-rules/master/domain-blacklist.txt");
    $curl->NoHTTP_POST = true;
    if ($curl->GetFile($tmpfile)) {
        $size = @filesize($tmpfile);
        if ($size < 100) {
            $tmpfile = "/usr/share/artica-postfix/bin/install/iptables_defaults.txt";
        }
    }
    $ip = new iptables_exec();
    if (!$ip->is_chain_exists($IPCHAIN)) {
        echo "Adding chain {$IPCHAIN}\n";
        shell_exec("{$GLOBALS["iptables"]} -N {$IPCHAIN}");
        shell_exec("{$GLOBALS["iptables"]} -I INPUT -p udp --dport 53 -j {$IPCHAIN}");
    } else {
        echo "chain {$IPCHAIN} exists...\n";
    }
    shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}");
    shell_exec("{$GLOBALS["iptables"]} -A {$IPCHAIN} -j RETURN");
    $f = explode("\n", @file_get_contents($tmpfile));
    while (list($num, $ligne) = each($f)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        $ligne = str_replace("INPUT", $IPCHAIN, $ligne);
        $ligne = str_replace("iptables", $GLOBALS["iptables"], $ligne);
        $results = array();
        exec($ligne, $results);
        echo "{$ligne}\n";
        while (list($a, $b) = each($results)) {
            echo "{$b}\n";
        }
    }
}
function GetDomains($i)
{
    $unix = new unix();
    $tmpfile = $unix->FILE_TEMP();
    $curl = new ccurl("http://0675.com.cn/newwebsite_20120101_list._page0.html");
    $curl->NoHTTP_POST = true;
    echo "Get page {$i}\n";
    if (!$curl->GetFile($tmpfile)) {
        echo "http://0675.com.cn/newwebsite_20120101_list._page{$i}.html -> error: \n" . $curl->error . "\n";
        return;
    }
    $datas = @file($tmpfile);
    $size = strlen(@implode("", $datas)) / 1024;
    echo "Page[{$i}]:: {$tmpfile} Size: {$size} Ko\n";
    while (list($num, $ligne) = each($datas)) {
        if (preg_match("#<div class=.*?newdomain.*?>(.*)#", $ligne)) {
            echo "Sure line {$num}";
            $newdata = str_replace("</li>", "", $ligne);
            $newdata = str_replace("</div>", "", $newdata);
            $f = explode("<li>", $newdata);
        }
    }
    $q = new mysql_squid_builder();
    while (list($num, $www) = each($f)) {
        if (preg_match("#^\\.(.+)#", $www, $re)) {
            $www = $re[1];
        }
        if (strpos($www, ",") > 0) {
            continue;
        }
        if (strpos($www, " ") > 0) {
            continue;
        }
        if (strpos($www, ":") > 0) {
            continue;
        }
        if (strpos($www, "%") > 0) {
            continue;
        }
        if (strpos($www, ">") > 0) {
            continue;
        }
        if (strpos($www, "<") > 0) {
            continue;
        }
        if (preg_match("#^www\\.(.+)#", $www, $re)) {
            $www = $re[1];
        }
        $articacats = trim($q->GET_CATEGORIES($www, true, false));
        if ($articacats != null) {
            echo "\"{$www}\" SUCCESS - {$articacats} -\n";
            continue;
        }
        echo "\"{$www}\" FAILED\n";
    }
}
function download()
{
    $unix = new unix();
    build_progress("{downloading}", 10);
    $URI = "http://wordpress.org/latest.tar.gz";
    $TMP_FILE = $unix->FILE_TEMP() . ".gz";
    $TMP_DIR = $unix->TEMP_DIR();
    echo "Downloading {$URI}\n";
    $curl = new ccurl($URI);
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "download_progress";
    if (!$curl->GetFile($TMP_FILE)) {
        build_progress("{downloading} {failed}", 110);
        echo $curl->error;
        return;
    }
    echo "Extracting {$TMP_FILE} in {$TMP_DIR}\n";
    $tar = $unix->find_program("tar");
    $cmd = "{$tar} xf {$TMP_FILE} -C {$TMP_DIR}/";
    build_progress("{uncompress}", 50);
    shell_exec("{$tar} xf {$TMP_FILE} -C {$TMP_DIR}/");
    @unlink($TMP_FILE);
    $dirs = $unix->dirdir($TMP_DIR);
    $WDP_DIR = null;
    while (list($num, $ligne) = each($dirs)) {
        if (!is_file("{$ligne}/wp-admin/install.php")) {
            continue;
        }
        $WDP_DIR = $ligne;
        break;
        echo "Find Directory {$ligne}\n";
    }
    if (!is_dir($WDP_DIR)) {
        build_progress("Find directory failed", 110);
        echo "Find directory failed\n";
        return;
    }
    build_progress("{installing}", 80);
    @mkdir("/usr/share/wordpress-src", 0755, true);
    $cp = $unix->find_program("cp");
    $rm = $unix->find_program("rm");
    shell_exec("cp -rfv {$WDP_DIR}/* /usr/share/wordpress-src/");
    if (is_dir($WDP_DIR)) {
        echo "Removing {$WDP_DIR}\n";
        shell_exec("{$rm} -rf {$WDP_DIR}");
    }
    $sock = new sockets();
    $sock->SET_INFO("EnableFreeWeb", 1);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/WordPressInstalled", 1);
    system("/etc/init.d/artica-status restart --force");
    build_progress("{success}", 100);
    $nohup = $unix->find_program("nohup");
    $sock = new sockets();
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 --verbose 654646 >/dev/null 2>&1 &");
}
function subdomains()
{
    $subdomains = "https://ransomwaretracker.abuse.ch/downloads/RW_DOMBL.txt";
    $MAIN = unserialize(@file_get_contents("/root/ransomwaretracker.db"));
    $curl = new ccurl($subdomains);
    if ($curl->GetFile("/root/RW_DOMBL.txt")) {
        $f = explode("\n", @file_get_contents("/root/RW_DOMBL.txt"));
        while (list($index, $line) = each($f)) {
            $line = trim($line);
            if (substr($line, 0, 1) == "#") {
                continue;
            }
            $MAIN["DOMAINS"][$line] = true;
        }
    } else {
        echo "{$subdomains} failed\n";
    }
    $ips = "https://ransomwaretracker.abuse.ch/downloads/RW_IPBL.txt";
    $curl = new ccurl($ips);
    if ($curl->GetFile("/root/RW_IPBL.txt")) {
        $f = explode("\n", @file_get_contents("/root/RW_IPBL.txt"));
        while (list($index, $line) = each($f)) {
            $line = trim($line);
            if (substr($line, 0, 1) == "#") {
                continue;
            }
            $MAIN["IPS"][$line] = true;
        }
    } else {
        echo "{$ips} failed\n";
    }
    $uris = "https://ransomwaretracker.abuse.ch/downloads/RW_URLBL.txt";
    $curl = new ccurl($uris);
    if ($curl->GetFile("/root/RW_URLBL.txt")) {
        $f = explode("\n", @file_get_contents("/root/RW_URLBL.txt"));
        while (list($index, $line) = each($f)) {
            $line = trim($line);
            if (substr($line, 0, 1) == "#") {
                continue;
            }
            $MAIN["URIS"][$line] = true;
        }
    } else {
        echo "{$uris} failed\n";
    }
    $MAIN2["TIME"] = time();
    $MAIN2["MD5"] = md5(serialize($MAIN));
    @file_put_contents("/root/ransomwaretracker.db", serialize($MAIN));
    @file_put_contents("/root/ransomwaretracker.txt", serialize($MAIN2));
    $unix = new unix();
    $unix->compress("/root/ransomwaretracker.db", "/root/ransomwaretracker.gz");
    PushToRepo("/root/ransomwaretracker.txt");
    PushToRepo("/root/ransomwaretracker.gz");
}
Beispiel #7
0
function update()
{
    if (system_is_overloaded()) {
        return;
    }
    $unix = new unix();
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/exec.ipblock.php.update.pid";
    $pidtime = "/etc/artica-postfix/pids/exec.ipblock.php.update.time";
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($unix->process_exists($pid)) {
            echo "Already running pid {$pid}\n";
            return;
        }
    }
    include_once dirname(__FILE__) . '/ressources/class.ccurl.inc';
    if (!is_file($pidtime)) {
        @file_put_contents($pidtime, time());
    }
    if (!$GLOBALS["FORCE"]) {
        if ($unix->file_time_min($pidtime) > 720) {
            @unlink($pidtime);
            @file_put_contents($pidtime, time());
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    $EnableIpBlocks = intval($sock->GET_INFO("EnableIpBlocks"));
    if ($EnableIpBlocks == 0) {
        return;
    }
    $DIR_TEMP = $unix->TEMP_DIR();
    $curl = new ccurl("http://www.ipdeny.com/ipblocks/data/countries/all-zones.tar.gz");
    if (!$curl->GetFile("{$DIR_TEMP}/all-zones.tar.gz")) {
        system_admin_events(0, "Fatal, Unable to download all-zones.tar.gz from ipdeny.com", __FILE__, __LINE__);
        return;
    }
    $OldMd5 = $sock->GET_INFO("IpBlocksMD5");
    $md5File = md5_file("{$DIR_TEMP}/all-zones.tar.gz");
    if ($md5File == $OldMd5) {
        ipblocks();
        return;
    }
    $tar = $unix->find_program("tar");
    @mkdir("/home/artica/ipblocks", 0755, true);
    shell_exec("{$tar} xf {$DIR_TEMP}/all-zones.tar.gz -C  /home/artica/ipblocks/");
    if (ipblocks()) {
        $sock->SET_INFO("IpBlocksMD5", "{$md5File}");
        system_admin_events(0, "Restarting Firewall in order to refresh countries blocking");
    }
}
Beispiel #8
0
function Get_owncloud()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = @file_get_contents($pidfile);
    $unix = new unix();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid} since {$time}mn\n";
        }
        die;
    }
    $uri = download();
    if ($uri == null) {
        return;
    }
    $curl = new ccurl($uri);
    $curl->NoHTTP_POST = true;
    $cp = $unix->find_program("cp");
    $rm = $unix->find_program("rm");
    progress("Downloading Owncloud package...", 25);
    if (!$curl->GetFile("/root/owncloud.tar.gz")) {
        progress("Failed download owncloud package", 110);
        return;
    }
    if (is_dir("/usr/share/owncloud")) {
        shell_exec("{$rm} -rf /usr/share/owncloud");
    }
    @mkdir("/usr/share/owncloud", 0755, true);
    if (!is_dir("/usr/share/owncloud")) {
        progress("/usr/share/owncloud permission denied", 110);
        @unlink("/root/owncloud.tar.gz");
        return;
    }
    $tar = $unix->find_program("tar");
    progress("Extracting package...", 35);
    shell_exec("{$tar} xf /root/owncloud.tar.gz -C /usr/share/owncloud/");
    @unlink("/root/owncloud.tar.gz");
    if (is_dir("/usr/share/owncloud/owncloud")) {
        shell_exec("{$cp} -rf /usr/share/owncloud/owncloud/* /usr/share/owncloud/");
        shell_exec("{$rm} -rf /usr/share/owncloud/owncloud");
    }
    if (is_file("/usr/share/owncloud/settings/settings.php")) {
        progress("Success...", 100);
        $unix->Process1(true);
        return;
    }
    progress("Failed...", 110);
}
function download_install($key)
{
    $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/squid.install.progress";
    $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/squid.install.progress.txt";
    $sock = new sockets();
    $ArticaTechNetSquidRepo = unserialize(base64_decode($sock->GET_INFO("ArticaTechNetSquidRepo")));
    $array = $ArticaTechNetSquidRepo[$key];
    $URL = $array["URL"];
    $VERSION = $array["VERSION"];
    $FILESIZE = $array["FILESIZE"];
    $FILENAME = $array["FILENAME"];
    $MD5 = $array["MD5"];
    $tarballs_file = "/usr/share/artica-postfix/ressources/conf/upload/{$FILENAME}";
    echo "Url......................: {$URL}\n";
    echo "Version..................: {$VERSION}\n";
    echo "File size................: {$FILESIZE}\n";
    echo "Filename.................: {$FILENAME}\n";
    echo "MD5......................: {$MD5}\n";
    if ($URL == null) {
        build_progress("{downloading} {$FILENAME} {failed}...", 110);
        die;
    }
    build_progress("{downloading} {$FILENAME} {please_wait}...", 5);
    $curl = new ccurl($URL);
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "download_progress";
    if (!$curl->GetFile($tarballs_file)) {
        build_progress("{downloading} {$FILENAME} {failed}...", 110);
        @unlink($tarballs_file);
        echo $curl->error;
        die;
    }
    build_progress("{checking} {$FILENAME} {please_wait}...", 9);
    $filesize = @filesize($tarballs_file);
    $md5file = md5_file($tarballs_file);
    echo "File size................: {$filesize}\n";
    echo "MD5......................: {$md5file}\n";
    if ($filesize < 50) {
        print_r($curl->CURL_ALL_INFOS);
        echo @file_get_contents($tarballs_file);
    }
    if ($md5file != $MD5) {
        @unlink($tarballs_file);
        echo "Md5 failed, corrupted file...\n";
        build_progress("{checking} {$FILENAME} {failed}...", 110);
        die;
    }
    install($FILENAME);
}
function xinstall()
{
    $unix = new unix();
    $curl = new ccurl();
    $tmpfile = $unix->FILE_TEMP();
    $tmpdir = $unix->TEMP_DIR();
    build_progress("{downloading} v3.1.0-25", 15);
    $curl = new ccurl("http://articatech.net/download/UpdateUtility/updateutility-3.1.0-25.tar.gz");
    if (!$curl->GetFile($tmpfile)) {
        @unlink($tmpfile);
        build_progress("{downloading} {failed}", 110);
        return;
    }
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    @mkdir("{$tmpdir}/updateutility", 0755);
    build_progress("{uncompress}", 20);
    shell_exec("{$tar} -xf {$tmpfile} -C {$tmpdir}/updateutility/");
    build_progress("{find_source_directory}", 25);
    $dirs = $unix->dirdir("{$tmpdir}/updateutility");
    $SOURCE_DIRECTORY = null;
    while (list($num, $ligne) = each($dirs)) {
        build_progress("{scanning} {$ligne}", 25);
        if (is_file("{$ligne}/UpdateUtility-Console")) {
            $SOURCE_DIRECTORY = $ligne;
            break;
        }
    }
    if ($SOURCE_DIRECTORY == null) {
        echo "Unable to find source directory\n";
        build_progress("{installing} {failed}", 110);
        shell_exec("{$rm} -rf {$tmpdir}/updateutility");
        return;
    }
    echo "Using directory {$SOURCE_DIRECTORY}\n";
    build_progress("{installing}...", 80);
    $cp = $unix->find_program("cp");
    @mkdir("/etc/UpdateUtility", 0755, true);
    shell_exec("{$cp} -rfv {$SOURCE_DIRECTORY}/* /etc/UpdateUtility/");
    shell_exec("{$rm} -rf {$tmpdir}/updateutility");
    if (!is_file("/etc/UpdateUtility/UpdateUtility-Console")) {
        echo "/etc/UpdateUtility/UpdateUtility-Console no such binary\n";
        build_progress("{installing} {failed}", 110);
    }
    build_progress("{installing} {success}", 100);
}
Beispiel #11
0
function ufdbguard_remote()
{
    include_once dirname(__FILE__) . "/ressources/class.ccurl.inc";
    $users = new usersMenus();
    $sock = new sockets();
    $unix = new unix();
    $trace = debug_backtrace();
    if (isset($trace[1])) {
        $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
    }
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($unix->file_time_min($timeFile) < 5) {
        writelogs("too short time to change settings, aborting {$called}...", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    @mkdir("/etc/ufdbguard", null, true);
    $tar = $unix->find_program("tar");
    $RemoteStatisticsApplianceSettings = unserialize(base64_decode($sock->GET_INFO("RemoteStatisticsApplianceSettings")));
    if (!is_numeric($RemoteStatisticsApplianceSettings["SSL"])) {
        $RemoteStatisticsApplianceSettings["SSL"] = 1;
    }
    if (!is_numeric($RemoteStatisticsApplianceSettings["PORT"])) {
        $RemoteStatisticsApplianceSettings["PORT"] = 9000;
    }
    $GLOBALS["REMOTE_SSERVER"] = $RemoteStatisticsApplianceSettings["SERVER"];
    $GLOBALS["REMOTE_SPORT"] = $RemoteStatisticsApplianceSettings["PORT"];
    $GLOBALS["REMOTE_SSL"] = $RemoteStatisticsApplianceSettings["SSL"];
    if ($GLOBALS["REMOTE_SSL"] == 1) {
        $refix = "https";
    } else {
        $refix = "http";
    }
    $DenyUfdbWriteConf = $sock->GET_INFO("DenyUfdbWriteConf");
    if (!is_numeric($DenyUfdbWriteConf)) {
        $DenyUfdbWriteConf = 0;
    }
    $baseUri = "{$refix}://{$GLOBALS["REMOTE_SSERVER"]}:{$GLOBALS["REMOTE_SPORT"]}/ressources/databases";
    if ($DenyUfdbWriteConf == 0) {
        $uri = "{$baseUri}/ufdbGuard.conf";
        $curl = new ccurl($uri, true);
        if ($curl->GetFile("/tmp/ufdbGuard.conf")) {
            @file_put_contents("/etc/ufdbguard/ufdbGuard.conf", @file_get_contents("/tmp/ufdbGuard.conf"));
            @file_put_contents("/etc/squid3/ufdbGuard.conf", @file_get_contents("/tmp/ufdbGuard.conf"));
        } else {
            ufdbguard_admin_events("Failed to download ufdbGuard.conf aborting `{$curl->error}`", __FUNCTION__, __FILE__, __LINE__, "global-compile");
        }
    }
    $uri = "{$baseUri}/blacklist.tar.gz";
    $curl = new ccurl($uri, true);
    if ($curl->GetFile("/tmp/blacklist.tar.gz")) {
        $cmd = "{$tar} -xf /tmp/blacklist.tar.gz -C /var/lib/squidguard/";
        writelogs($cmd, __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    } else {
        ufdbguard_admin_events("Failed to download blacklist.tar.gz aborting `{$curl->error}`", __FUNCTION__, __FILE__, __LINE__, "global-compile");
    }
    $uri = "{$baseUri}/ftpunivtlse1fr.tar.gz";
    $curl = new ccurl($uri, true);
    if ($curl->GetFile("/tmp/ftpunivtlse1fr.tar.gz")) {
        $cmd = "{$tar} -xf /tmp/ftpunivtlse1fr.tar.gz -C /var/lib/ftpunivtlse1fr/";
        writelogs($cmd, __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    } else {
        ufdbguard_admin_events("Failed to download ftpunivtlse1fr.tar.gz aborting `{$curl->error}`", __FUNCTION__, __FILE__, __LINE__, "global-compile");
    }
    Dansguardian_remote();
    CheckPermissions();
    ufdbguard_schedule();
    if ($unix->Ufdbguard_remote_srvc_bool()) {
        ufdbguard_admin_events("Using a remote UfdbGuard service, aborting", __FUNCTION__, __FILE__, __LINE__, "config");
        return;
    }
    ufdbguard_admin_events("Service will be rebuiled and restarted", __FUNCTION__, __FILE__, __LINE__, "config");
    build_ufdbguard_HUP();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    if (is_file($GLOBALS["SQUIDBIN"])) {
        echo "Starting......: " . date("H:i:s") . " Squid reloading service\n";
        shell_exec("{$nohup} {$php5} " . basename(__FILE__) . "/exec.squid.php --reconfigure-squid >/dev/null 2>&1");
    }
    $datas = @file_get_contents("/etc/ufdbguard/ufdbGuard.conf");
    send_email_events("SquidGuard/ufdbGuard/Dansguardian rules was rebuilded", basename(__FILE__) . "\nFunction:" . __FUNCTION__ . "\nLine:" . __LINE__ . "\n" . "This is new configuration file of the squidGuard/ufdbGuard:\n-------------------------------------\n{$datas}", "proxy");
    shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.c-icap.php --maint-schedule");
}
function vxvault()
{
    $unix = new unix();
    $q = new mysql_squid_builder();
    $curl = new ccurl("http://vxvault.net/URL_List.php");
    $targetpath = $unix->FILE_TEMP();
    if (!$curl->GetFile($targetpath)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "DOWNLOAD FAILED {$targetpath}\n";
        }
        @unlink($targetpath);
        return false;
    }
    $lastmd5 = @file_get_contents("/etc/artica-postfix/settings/Daemons/vxvault.md5");
    $Currentmd5 = md5_file($targetpath);
    if (!$GLOBALS["FORCE"]) {
        if ($lastmd5 == $Currentmd5) {
            return;
        }
    }
    $fp = @fopen($targetpath, "r");
    if (!$fp) {
        if ($GLOBALS["DEBUG_GREP"]) {
            echo "{$targetpath} BAD FD\n";
        }
        @unlink($targetpath);
        return array();
    }
    $c = 0;
    $t = array();
    while (!feof($fp)) {
        $line = trim(fgets($fp));
        $line = str_replace("\r\n", "", $line);
        $line = str_replace("\n", "", $line);
        $line = str_replace("\r", "", $line);
        $line = str_replace("\\", "/", $line);
        if (!preg_match("#^http#", $line)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "SKIP {$line}\n";
            }
            continue;
        }
        if (preg_match("#http:\\/\\/(.+?)#", $line, $re)) {
            $line = $re[1];
        }
        if (preg_match("#https:\\/\\/(.+?)#", $line, $re)) {
            $line = $re[1];
        }
        $md5 = md5($line);
        $SQLZ[] = "('{$md5}',NOW(),'{$line}',1)";
        if (count($SQLZ) > 500) {
            $q->QUERY_SQL($GLOBALS["PREFIX"] . @implode(",", $SQLZ));
            if (!$q->ok) {
                echo $q->mysql_error;
                @fclose($fp);
                @unlink($targetpath);
                return;
            }
        }
    }
    @fclose($fp);
    @unlink($targetpath);
    if (count($SQLZ) > 0) {
        $q->QUERY_SQL($GLOBALS["PREFIX"] . @implode(",", $SQLZ));
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    @file_put_contents("/etc/artica-postfix/settings/Daemons/vxvault.md5", $Currentmd5);
}
Beispiel #13
0
function analyze()
{
    if ($GLOBALS["VERBOSE"]) {
        echo "analyze<br>\n";
    }
    $page = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_squid_builder();
    $uri = $_GET["uri"];
    $curl = new ccurl($uri);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$uri}<br>\n";
    }
    $filename = md5($uri);
    if (!$curl->GetFile("ressources/logs/web/{$filename}")) {
        echo "<H2>" . $curl->error . "</H2>";
        return;
    }
    $ARRY = array();
    if ($GLOBALS["VERBOSE"]) {
        echo "Open ressources/logs/web/{$filename}<br>\n";
    }
    $datas = @file_get_contents("ressources/logs/web/{$filename}");
    $tb = explode("\n", $datas);
    @unlink("ressources/logs/web/{$filename}");
    if (preg_match("#google\\..+?#", $uri)) {
        if (preg_match_all('#<h3 class="r"><a href="(.+?)"#', $datas, $re)) {
            while (list($num, $uri) = each($re[1])) {
                if (preg_match("#^(?:[^/]+://)?([^/:]+)#", $uri, $ri)) {
                    $sitename = $ri[1];
                    if (substr($sitename, 0, 1) == "#") {
                        continue;
                    }
                    if (preg_match("#^www\\.(.+)#", $sitename, $ri)) {
                        $sitename = $ri[1];
                    }
                    if (preg_match("#\\.php\\?#", $sitename)) {
                        continue;
                    }
                    if (preg_match("#\\.php\$#", $sitename)) {
                        continue;
                    }
                    $ARRY[$sitename] = $sitename;
                }
            }
        }
    }
    while (list($num, $line) = each($tb)) {
        if (preg_match("#<a\\s+href=(.*)\\.([a-z]+)#i", $line, $re)) {
            $uri = trim($re[1] . "." . $re[2]);
            $uri = str_replace("\"", "", $uri);
            $uri = str_replace("'", "", $uri);
            if (strpos($uri, ">") > 0) {
                $uri = substr($uri, 0, strpos($uri, ">"));
            }
            if (preg_match("#^(?:[^/]+://)?([^/:]+)#", $uri, $re)) {
                $sitename = $re[1];
                if (substr($sitename, 0, 1) == "#") {
                    continue;
                }
                if (preg_match("#^www\\.(.+)#", $sitename, $ri)) {
                    $sitename = $ri[1];
                }
                if (preg_match("#\\.php\\?#", $sitename)) {
                    continue;
                }
                if (preg_match("#\\.php\\s+[a-z]#", $sitename)) {
                    continue;
                }
                if (preg_match("#\\.php\$#", $sitename)) {
                    continue;
                }
                if (strpos($sitename, ".") == 0) {
                    continue;
                }
                if (strpos($sitename, "{") > 0) {
                    continue;
                }
                if (strpos($sitename, "}") > 0) {
                    continue;
                }
                if (strpos($sitename, "\$") > 0) {
                    continue;
                }
                $ARRY[trim(strtolower($sitename))] = trim(strtolower($sitename));
            }
        }
    }
    $html = "\n\t";
    $f = 0;
    $s = 0;
    $t = 0;
    while (list($num, $line) = each($ARRY)) {
        if (strlen($num) < 3) {
            continue;
        }
        if ($num == "javascript") {
            continue;
        }
        if (strpos($num, ".") == 0) {
            continue;
        }
        if (strpos($num, "{") > 0) {
            continue;
        }
        if (strpos($num, " ") > 0) {
            continue;
        }
        if (strpos($num, "}") > 0) {
            continue;
        }
        if (strpos($num, "\$") > 0) {
            continue;
        }
        $tz = explode(".", $num);
        if ($tz[count($tz) - 1] == "php") {
            continue;
        }
        if ($tz[count($tz) - 1] == "html") {
            continue;
        }
        if ($tz[count($tz) - 1] == "htm") {
            continue;
        }
        if (preg_match("#\\.php\\?#", $num)) {
            continue;
        }
        if (preg_match("#\\.php\$#", $num)) {
            continue;
        }
        $t++;
        if ($t > 200) {
            break;
        }
        $cats = $q->GET_CATEGORIES($num);
        $mustcat = "&nbsp;";
        $color = "black";
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        if ($cats == null) {
            $tt = explode(".", $num);
            $familysite = $tt[count($tt) - 2] . "." . $tt[count($tt) - 1];
            $q->QUERY_SQL("INSERT IGNORE INTO visited_sites (sitename,familysite) VALUES ('{$num}','{$familysite}')");
            $f++;
            $cats = "&nbsp;";
            $mustcat = imgtootltip("add-database-32.png", "{categorize}", "Loadjs('squid.categorize.php?www={$num}')");
            $color = "#CC0A0A";
        } else {
            $s++;
        }
        $html = $html . "\n\t\t<tr class={$classtr}>\n\t\t<td style='font-size:14px;color:{$color}'>{$num}</td>\n\t\t<td style='font-size:14px'>{$cats}</td>\n\t\t<td width=1%>{$mustcat}</td>\n\t\t</tr>\n\t\t";
    }
    //javascript:Loadjs('squid.categorize.php?www=api161.thefilter.com&day=&week=');
    $purc = round($s / $t * 100, 2);
    $html = "<center><table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n\t<thead class='thead'>\n\t<tr>\n\t<th>{$t} {websites} {$f} {failed} {$s} {success} {$purc}%</th>\n\t<th>{category}</th>\n\t<th>&nbsp;</th>\n\t</tr>\n</thead>\n<tbody>{$html}</tbody></table><span id='webalyzer-lock'></span>";
    echo $tpl->_ENGINE_parse_body($html);
}
function youtube_infos($VIDEOID)
{
    if (isset($GLOBALS["youtubeid"][$VIDEOID])) {
        return true;
    }
    $uri = "https://gdata.youtube.com/feeds/api/videos/{$VIDEOID}?v=2&alt=jsonc";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$VIDEOID}:: {$uri} -> \n";
    }
    $curl = new ccurl($uri);
    $error = null;
    if (!$curl->GetFile("/tmp/jsonc.inc")) {
        youtube_events("gdata.youtube.com = Failed = > {$curl->error}", __LINE__);
        return false;
    }
    $infox = @file_get_contents("/tmp/jsonc.inc");
    $infos = json_decode($infox);
    $uploaded = $infos->data->uploaded;
    $title = $infos->data->title;
    if ($title == null) {
        $error = $infos->error->message;
        if ($error == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "data->title NULL ({$error})\n";
                var_dump($infos);
            }
            return false;
        } else {
            $title = $error;
        }
    }
    $category = $infos->data->category;
    if ($category == null) {
        if ($error != null) {
            $category = $error;
        }
    }
    $q = new mysql_squid_builder();
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT `youtubeid` FROM youtube_objects WHERE `youtubeid`='{$VIDEOID}'"));
    if (!$q->ok) {
        if (strpos("youtube_objects' doesn't exist", $q->mysql_error) > 0) {
            $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT `youtubeid` FROM youtube_objects WHERE `youtubeid`='{$VIDEOID}'"));
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$q->mysql_error}\n";
        }
        return;
    }
    if ($ligne["youtubeid"] != null) {
        $GLOBALS["youtubeid"][$VIDEOID] = true;
        if ($GLOBALS["VERBOSE"]) {
            echo "{$VIDEOID} already exists in table\n";
        }
        return true;
    }
    $tumbnail = $infos->data->thumbnail->sqDefault;
    $curl = new ccurl($tumbnail);
    $curl->GetFile("/tmp/thumbnail");
    $CATZ["Autos & Vehicles"] = "automobile/cars";
    $CATZ["Film & Animation"] = "movies";
    $CATZ["Gaming"] = "games";
    $CATZ["Education"] = "recreation/schools";
    $CATZ["Music"] = "music";
    $CATZ["News & Politics"] = "news";
    $CATZ["People & Blogs"] = "hobby/pets";
    $CATZ["Science & Technology"] = "sciences";
    $CATZ["Sports"] = "recreation/sports";
    $CATZ["Travel & Events"] = "recreation/travel";
    if (isset($CATZ[$category])) {
        $category = $CATZ[$category];
    }
    $date = strtotime($uploaded);
    $zDate = date("Y-m-d H:i:s");
    $infox_enc = base64_encode($infox);
    $title = addslashes($title);
    $category = addslashes($category);
    $duration = $infos->data->duration;
    $thumbnail = addslashes(@file_get_contents("/tmp/thumbnail"));
    $sql = "INSERT INTO youtube_objects (youtubeid,category,title,content,uploaded,duration,thumbnail) \n\tVALUES('{$VIDEOID}','{$category}','{$title}','{$infox_enc}','{$zDate}','{$duration}','{$thumbnail}')";
    $q->QUERY_SQL($sql, "artica");
    if (!$q->ok) {
        if (strpos("youtube_objects' doesn", " {$q->mysql_error}") > 0) {
            $q->CheckTables();
            $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT `youtubeid` FROM youtube_objects WHERE `youtubeid`='{$VIDEOID}'"));
        }
    }
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$q->mysql_error}\n";
        }
        return false;
    }
    return true;
}
Beispiel #15
0
function xstart()
{
    $curl = new ccurl();
    $unix = new unix();
    $Pidfile = "/etc/artica-postfix/pids/exec.abuse-ch.pid";
    $PidTime = "/etc/artica-postfix/pids/exec.abuse-ch.time";
    $pid = $unix->get_pid_from_file($Pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Aborting Task already running pid {$pid} " . __FUNCTION__ . "()\n";
        }
        return;
    }
    @file_put_contents($Pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $time = $unix->file_time_min($PidTime);
        if ($time < 10) {
            echo "Only each 10mn\n";
            die;
        }
        @unlink($PidTime);
        @file_put_contents($PidTime, time());
    }
    $curl = new ccurl("http://articatech.net/WebfilterDBS/ransomwaretracker.txt");
    $tmpfile = $unix->TEMP_DIR();
    if (!$curl->GetFile("{$tmpfile}/ransomwaretracker.txt")) {
        squid_admin_mysql(0, "ransomwaretracker.txt unable to get index file", $curl->error, __FILE__, __LINE__);
        return;
    }
    $array = unserialize(@file_get_contents("{$tmpfile}/ransomwaretracker.txt"));
    $TIME = $array["TIME"];
    if (!isset($array["MD5"])) {
        squid_admin_mysql(0, "ransomwaretracker.txt corrupted file", $curl->error, __FILE__, __LINE__);
        return;
    }
    @unlink("{$tmpfile}/ransomwaretracker.txt");
    $CurrentMD5 = @file_get_contents("/etc/artica-postfix/settings/Daemons/ransomwaretrackerMD5");
    if ($CurrentMD5 == $array["MD5"]) {
        return;
    }
    $curl = new ccurl("http://articatech.net/WebfilterDBS/ransomwaretracker.gz");
    if (!$curl->GetFile("{$tmpfile}/ransomwaretracker.gz")) {
        squid_admin_mysql(0, "ransomwaretracker.gz unable to get pattern file", $curl->error, __FILE__, __LINE__);
        return;
    }
    if (!$unix->uncompress("{$tmpfile}/ransomwaretracker.gz", "{$tmpfile}/ransomwaretracker.db")) {
        squid_admin_mysql(0, "ransomwaretracker.gz unable to extract file", $curl->error, __FILE__, __LINE__);
        return;
    }
    $ARRAY = unserialize(@file_get_contents("{$tmpfile}/ransomwaretracker.db"));
    if (!isset($ARRAY["URIS"])) {
        squid_admin_mysql(0, "ransomwaretracker.db corrupted database", $curl->error, __FILE__, __LINE__);
        return;
    }
    if (is_file("/etc/squid3/ransomwaretracker.db")) {
        @unlink("/etc/squid3/ransomwaretracker.db");
    }
    @copy("{$tmpfile}/ransomwaretracker.db", "/etc/squid3/ransomwaretracker.db");
    if (!is_file("/etc/artica-postfix/settings/Daemons/RansomwareReloaded")) {
        squid_admin_mysql(1, "Reloading Proxy service for updating Ranswomware function", null, __FILE__, __LINE__);
        $squid = $unix->LOCATE_SQUID_BIN();
        shell_exec("{$squid} -f /etc/squid3/squid.conf -k reconfigure");
        @touch("/etc/artica-postfix/settings/Daemons/RansomwareReloaded");
    }
    squid_admin_mysql(2, "Success updating ranswomware database v{$TIME}", null, __FILE__, __LINE__);
}
function download_mydb()
{
    $sock = new sockets();
    $unix = new unix();
    $chmod = $unix->find_program("chmod");
    $squidbin = $unix->find_program("squid3");
    if (!is_file($squidbin)) {
        $squidbin = $unix->find_program("squid");
    }
    if (!is_file($squidbin)) {
        return;
    }
    $RemoteStatisticsApplianceSettings = unserialize(base64_decode($sock->GET_INFO("RemoteStatisticsApplianceSettings")));
    if (!is_numeric($RemoteStatisticsApplianceSettings["SSL"])) {
        $RemoteStatisticsApplianceSettings["SSL"] = 1;
    }
    if (!is_numeric($RemoteStatisticsApplianceSettings["PORT"])) {
        $RemoteStatisticsApplianceSettings["PORT"] = 9000;
    }
    $GLOBALS["REMOTE_SSERVER"] = $RemoteStatisticsApplianceSettings["SERVER"];
    $GLOBALS["REMOTE_SPORT"] = $RemoteStatisticsApplianceSettings["PORT"];
    $GLOBALS["REMOTE_SSL"] = $RemoteStatisticsApplianceSettings["SSL"];
    if ($GLOBALS["REMOTE_SSL"] == 1) {
        $refix = "https";
    } else {
        $refix = "http";
    }
    $baseUri = "{$refix}://{$GLOBALS["REMOTE_SSERVER"]}:{$GLOBALS["REMOTE_SPORT"]}/ressources/databases";
    $uri = "{$baseUri}/usersMacs.db";
    $curl = new ccurl($uri, true);
    if ($curl->GetFile("/etc/squid3/usersMacs.db")) {
        shell_exec("{$chmod} 755 /etc/squid3/usersMacs.db");
        ufdbguard_admin_events("download usersMacs.db success", __FUNCTION__, __FILE__, __LINE__, "global-compile");
    } else {
        ufdbguard_admin_events("Failed to download ufdbGuard.conf aborting `{$curl->error}`", __FUNCTION__, __FILE__, __LINE__, "global-compile");
        return;
    }
    $cmd = "/etc/init.d/squid reload --script=" . basename(__FILE__);
    shell_exec("{$cmd} >/dev/null 2>&1");
}
function install($filekey = 0, $OS)
{
    include_once dirname(__FILE__) . "/ressources/class.ccurl.inc";
    $unix = new unix();
    $filename = null;
    $MD5 = null;
    $DebianVersion = DebianVersion();
    if ($OS != $DebianVersion) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, influxdb Debian version incompatible!\n";
        }
        build_progress_idb("Incompatible system {$OS}<>{$DebianVersion}!", 110);
        die;
    }
    if ($filekey != 0) {
        $sock = new sockets();
        $ArticaTechNetHaProxyRepo = unserialize(base64_decode($sock->GET_INFO("ArticaTechNetHaProxyRepo")));
        $version = $ArticaTechNetHaProxyRepo[$filekey][$OS]["VERSION"];
        $filename = $ArticaTechNetHaProxyRepo[$filekey][$OS]["FILENAME"];
        $MD5 = $ArticaTechNetHaProxyRepo[$filekey][$OS]["MD5"];
        $URL = $ArticaTechNetHaProxyRepo[$filekey][$OS]["URL"];
    }
    $rmmod = $unix->find_program("rmmod");
    $depmod = $unix->find_program("depmod");
    $modprobe = $unix->find_program("modprobe");
    $ldconfig = $unix->find_program("ldconfig");
    echo "Downloading {$URL}\n";
    $curl = new ccurl($URL);
    $tmpdir = $unix->TEMP_DIR();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress_idb("{downloading}", 1);
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "download_progress";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Downloading {$filename}\n";
    }
    if (!$curl->GetFile("{$tmpdir}/{$filename}")) {
        build_progress_idb("{$curl->error}", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$curl->error}\n";
        }
        while (list($key, $value) = each($curl->errors)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$value}\n";
            }
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, HaProxy unable to install....\n";
        }
        @unlink("{$tmpdir}/{$filename}");
        return;
    }
    if ($MD5 != null) {
        $DESTMD5 = md5_file("{$tmpdir}/{$filename}");
        if ($DESTMD5 != $MD5) {
            echo "{$DESTMD5}<>{$MD5}\n";
            @unlink("{$tmpdir}/{$filename}");
            build_progress_idb("{install_failed} {corrupted_package}", 110);
            return;
        }
    }
    build_progress_idb("{stopping_service}", 95);
    if (!is_file("/etc/init.d/haproxy")) {
        system("{$php} /usr/share/artica-postfix/exec.initslapd.php --haproxy");
    }
    system("/etc/init.d/firehol stop");
    system("/etc/init.d/haproxy stop");
    build_progress_idb("{extracting}", 96);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, extracting....\n";
    }
    $tar = $unix->find_program("tar");
    shell_exec("{$tar} xvf {$tmpdir}/{$filename} -C /");
    build_progress_idb("{installing} 1/1", 96);
    system("{$ldconfig}");
    if ($GLOBALS["PROGRESS"]) {
        build_progress_idb("{restarting_service}", 97);
        system("{$php} /usr/share/artica-postfix/exec.status.php --haproxy >/dev/null");
        system("/etc/init.d/artica-status restart --force");
        build_progress_idb("{restarting_service} 1/2", 98);
        system("/etc/init.d/haproxy restart");
        build_progress_idb("{restarting_service} 2/2", 98);
        system("/etc/init.d/firehol restart");
    }
    build_progress_idb("{refresh_status}", 98);
    build_progress_idb("{done}", 100);
}
Beispiel #18
0
function nightly()
{
    @mkdir("/var/log/artica-postfix", 0755, true);
    $GLOBALS["MasterIndexFile"] = "/usr/share/artica-postfix/ressources/index.ini";
    $unix = new unix();
    $sock = new sockets();
    $autoinstall = true;
    $timefile = "/etc/artica-postfix/croned.1/nightly";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = @file_get_contents($pidfile);
    $kill = $unix->find_program("kill");
    $tmpdir = $unix->TEMP_DIR();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " nightly build already executed PID: {$pid} since {$time}Mn\n";
        system_admin_events("nightly build already executed PID: {$pid} since {$time}Mn", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        if ($time < 120) {
            if (!$GLOBALS["FORCE"]) {
                die;
            }
        }
        unix_system_kill_force($pid);
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $EnableScheduleUpdates = $sock->GET_INFO("EnableScheduleUpdates");
    if (!is_numeric($EnableScheduleUpdates)) {
        $EnableScheduleUpdates = 0;
    }
    if ($GLOBALS["FORCE"]) {
        _artica_update_event(1, "Update task pid {$mypid} is forced by an human.", null, __FILE__, __LINE__);
    }
    if ($EnableScheduleUpdates == 1) {
        if (!$GLOBALS["FORCE"]) {
            if (!$GLOBALS["BYCRON"]) {
                _artica_update_event(2, "Operation must be only executed by scheduler ( use --force to by pass)", null, __FILE__, __LINE__);
                @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
                return;
            }
        }
    }
    $ini = new iniFrameWork();
    $ini->loadFile('/etc/artica-postfix/artica-update.conf');
    if (!isset($ini->_params["AUTOUPDATE"]["enabled"])) {
        $ini->_params["AUTOUPDATE"]["enabled"] = "yes";
    }
    if (trim($ini->_params["AUTOUPDATE"]["enabled"]) == null) {
        $ini->_params["AUTOUPDATE"]["enabled"] = "yes";
    }
    if ($ini->_params["AUTOUPDATE"]["enabled"] == null) {
        $ini->_params["AUTOUPDATE"]["enabled"] = "yes";
    }
    if (trim($ini->_params["AUTOUPDATE"]["uri"]) == null) {
        $ini->_params["AUTOUPDATE"]["uri"] = "http://www.articatech.net/auto.update.php";
    }
    if ($ini->_params["AUTOUPDATE"]["enabled"] == 1) {
        $ini->_params["AUTOUPDATE"]["enabled"] = 'yes';
    }
    if (!is_numeric(trim($ini->_params["AUTOUPDATE"]["CheckEveryMinutes"]))) {
        $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"] = 60;
    }
    if ($ini->_params["AUTOUPDATE"]["enabled"] != 'yes') {
        echo "Starting......: " . date("H:i:s") . " Artica Update feature is disabled (enabled = {$ini->_params["AUTOUPDATE"]["enabled"]} )\n";
        return;
    }
    $CheckEveryMinutes = $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"];
    $uri = $ini->_params["AUTOUPDATE"]["uri"];
    $arrayURI = parse_url($uri);
    $MAIN_URI = "{$arrayURI["scheme"]}://{$arrayURI["host"]}";
    $MAIN_URI = str_replace("www.artica.fr", "www.articatech.net", $MAIN_URI);
    if (!$GLOBALS["FORCE"]) {
        if ($EnableScheduleUpdates == 0) {
            if ($unix->file_time_min($timefile) < $CheckEveryMinutes) {
                echo "Starting......: " . date("H:i:s") . " update feature (too short time, require {$CheckEveryMinutes}mn)\n";
                @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
                return;
            }
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    if ($GLOBALS["FORCE"]) {
        if (is_file("/root/artica-latest.tgz")) {
            echo "Starting......: " . date("H:i:s") . " Installing old downloaded package\n";
            if (install_package("/root/artica-latest.tgz")) {
                return;
            }
        }
    }
    // ----------------------- LANCEMENT ------------------------------------------------------------------------------
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    if ($EnableArticaMetaClient == 1) {
        echo "Starting......: " . date("H:i:s") . " Nightly builds using Artica Meta console\n";
        system("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --artica-updates >/dev/null 2>&1 &");
        die;
    }
    echo "Starting......: " . date("H:i:s") . " Nightly builds checking an official release first\n";
    if (update_release()) {
        return;
    }
    $nightly = trim(strtolower($ini->_params["AUTOUPDATE"]["nightlybuild"]));
    if ($nightly == 1) {
        $nightly = "yes";
    }
    if ($GLOBALS["FORCE"]) {
        $nightly = "yes";
    }
    if ($GLOBALS["FORCE_NIGHTLY"]) {
        $nightly = "yes";
    }
    if ($nightly != 'yes') {
        echo "Starting......: " . date("H:i:s") . " Nightly builds feature is disabled [{$nightly}]\n";
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100);
        return;
    }
    if ($ini->_params["AUTOUPDATE"]["autoinstall"] == 1) {
        $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes";
    }
    if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == null) {
        $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes";
    }
    if ($ini->_params["AUTOUPDATE"]["autoinstall"] != "yes") {
        $autoinstall = false;
    }
    @file_put_contents("/usr/share/artica-postfix/download_progress", 0);
    $MyCurrentVersion = GetCurrentVersion();
    echo "Starting......: " . date("H:i:s") . " Current version: {$MyCurrentVersion}\n";
    $Lastest = trim(strtolower($GLOBALS["lastest-nightly"]));
    echo "Starting......: " . date("H:i:s") . " Nightly builds version \"{$Lastest}\" on repository\n";
    $MyNextVersion = intval(str_replace(".", "", $Lastest));
    echo "Starting......: " . date("H:i:s") . " nightly builds Cur:{$MyCurrentVersion}, Next:{$MyNextVersion}\n";
    if ($MyNextVersion == $MyCurrentVersion) {
        echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Same version\"\n";
        @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
        return;
    }
    if ($MyCurrentVersion > $MyNextVersion) {
        echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Most updated\"\n";
        @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
        return;
    }
    $t1 = time();
    _artica_update_event(2, "nightly builds Downloading new version {$Lastest}", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " nightly builds Downloading new version {$Lastest}, please wait\n";
    events("Downloading new version {$Lastest}");
    $uri = "{$MAIN_URI}/nightbuilds/artica-{$Lastest}.tgz";
    $ArticaFileTemp = "{$tmpdir}/{$Lastest}/artica-{$Lastest}.tgz";
    @mkdir("{$tmpdir}/{$Lastest}", 0755, true);
    $curl = new ccurl($uri);
    $curl->Timeout = 2400;
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "nightly_progress";
    $t = time();
    if (!$curl->GetFile($ArticaFileTemp)) {
        _artica_update_event(0, "nightly builds Unable to download latest nightly build with error {$curl->error}", null, __FILE__, __LINE__);
        events("Unable to download latest nightly build with error {$curl->error}");
        system_admin_events("Unable to download latest nightly build with error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        @unlink($ArticaFileTemp);
        return;
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    _artica_update_event(2, "artica-{$Lastest}.tgz download, took {$took}", null, __FILE__, __LINE__);
    system_admin_events("artica-{$Lastest}.tgz download, took {$took}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
    events("artica-{$Lastest}.tgz download, took {$took}");
    $size = @filesize($ArticaFileTemp);
    $size = FormatBytes($size / 1024, true);
    ArticaMeta_nightly($ArticaFileTemp);
    echo "Starting......: " . date("H:i:s") . " nightly builds took {$took}\n";
    if (!$GLOBALS["FORCE"]) {
        if ($autoinstall == false) {
            _artica_update_event(2, "artica-latest.tgz will be stored in /root", null, __FILE__, __LINE__);
            @copy("{$ArticaFileTemp}", "/root/artica-latest.tgz");
            @unlink($ArticaFileTemp);
            _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size}) waiting order", null, __FILE__, __LINE__);
            system_admin_events("New Artica update v.{$Lastest} waiting your order", __FUNCTION__, __FILE__, __LINE__, "artica-update");
            return;
        } else {
        }
    }
    events("Now, installing the newest version in {$ArticaFileTemp} package...");
    $size = @filesize($ArticaFileTemp);
    $size = FormatBytes($size / 1024, true);
    if (!install_package($ArticaFileTemp, $Lastest)) {
        events("Install package Failed...");
        return false;
    }
    events("New Artica update v.{$Lastest}");
    _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size})", null, __FILE__, __LINE__);
    system_admin_events("New Artica update v.{$Lastest}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
}
function BlockIPs()
{
    $ipClass = new IP();
    $unix = new unix();
    $tmpdir = $unix->TEMP_DIR();
    $curl = new ccurl("https://rules.emergingthreatspro.com/fwrules/emerging-Block-IPs.txt");
    $targetpath = "{$tmpdir}/emerging-Block-IPs.txt";
    if (!$curl->GetFile($targetpath)) {
        echo "{$targetpath} failed\n";
        artica_update_event(0, "Unable to download emerging-Block-IPs.txt", $curl->errors, __FILE__, __LINE__);
        return;
    }
    $f = explode("\n", @file_get_contents($targetpath));
    $proxyname = $unix->hostname_g();
    $q = new postgres_sql();
    $q->suricata_tables();
    $tr = array();
    while (list($num, $ligne) = each($f)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        if (strpos(" {$ligne}", "#") > 0) {
            continue;
        }
        if (!$ipClass->isIPAddressOrRange($ligne)) {
            continue;
        }
        $zdate = date("Y-m-d H:i:s");
        $proto = "TCP";
        $dest_port = 0;
        $src_ip = $ligne;
        $uduniq = md5("0,{$src_ip},{$dest_port},{$proto}");
        if ($GLOBALS["VERBOSE"]) {
            echo "0,{$src_ip},{$dest_port},{$proto}\n";
        }
        $tr[] = "('{$zdate}','{$uduniq}','0','{$src_ip}','{$dest_port}','{$proto}','{$proxyname}',1)";
    }
    if (count($tr) > 0) {
        $q->QUERY_SQL("DELETE FROM suricata_firewall WHERE xauto=1");
    }
    $content = @implode(",", $tr);
    $prefix = "INSERT INTO suricata_firewall (zdate,uduniq,signature,src_ip,dst_port,proto,proxyname,xauto) VALUES ";
    $q->QUERY_SQL("{$prefix} {$content} ON CONFLICT DO NOTHING");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    shell_exec("{$php} /usr/share/artica-postfix/exec.suricata-fw.php --run");
}
Beispiel #20
0
function config($servername)
{
    $GLOBALS["SERVICE_NAME"] = "Wordpress {$servername}";
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$servername}.pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        build_progress("{$servername} Already executed", 110);
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $q = new mysql();
    $cp = $unix->find_program("cp");
    $sock = new sockets();
    $Salts = null;
    $DB_HOST = $q->mysql_server;
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL host: {$DB_HOST}\n";
    }
    if ($q->mysql_server == "127.0.0.1" or $q->mysql_server == "localhost" or $q->mysql_server == "localhost:") {
        if ($q->SocketPath == null) {
            $q->SocketPath = "/var/run/mysqld/mysqld.sock";
        }
        $DB_HOST = "localhost:{$q->SocketPath}";
    }
    if (!is_file("/usr/share/artica-postfix/bin/wp-cli.phar")) {
        build_progress("wp-cli.phar: no such binary", 110);
        return;
    }
    @chmod("/usr/share/artica-postfix/bin/wp-cli.phar", 0755);
    build_progress("{$servername}: {testing_configuration}", 40);
    $free = new freeweb($servername);
    $WORKING_DIRECTORY = $free->www_dir;
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Directory: {$WORKING_DIRECTORY}\n";
    }
    @unlink("{$WORKING_DIRECTORY}/wp-config.php");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Duplicate: {$free->groupware_duplicate}\n";
    }
    if ($free->groupware_duplicate != null) {
        build_progress("{$servername}: {duplicate} {from} {$free->groupware_duplicate}", 40);
        if (!duplicate_wordpress($servername)) {
            build_progress("{$servername}: {installing} {failed}...", 110);
            apache_admin_mysql(0, "Failed to duplicate {$servername} from {$free->groupware_duplicate}", null, __FILE__, __LINE__);
            return;
        }
        apache_admin_mysql(2, "Success duplicate {$servername} from {$free->groupware_duplicate}", null, __FILE__, __LINE__);
        $free = new freeweb($servername);
    } else {
        if (!scan($WORKING_DIRECTORY)) {
            build_progress("{$servername}: {installing}...", 42);
            @mkdir($WORKING_DIRECTORY);
            shell_exec("{$cp} -rf /usr/share/wordpress-src/* {$WORKING_DIRECTORY}/");
            if (!scan($WORKING_DIRECTORY)) {
                apache_admin_mysql(0, "Failed to install {$servername} from /usr/share/wordpress-src", null, __FILE__, __LINE__);
                build_progress("{$servername}: {installing} {failed}...", 110);
                return;
            }
            apache_admin_mysql(2, "Success to install {$servername} from /usr/share/wordpress-src", null, __FILE__, __LINE__);
        }
    }
    $wordpressDB = $free->mysql_database;
    if ($wordpressDB == null) {
        $wordpressDB = $free->CreateDatabaseName();
        $free->mysql_database = $wordpressDB;
        $free->CreateSite(true);
    }
    $WordPressDBPass = $free->mysql_password;
    $DB_USER = $free->mysql_username;
    if ($DB_USER == "wordpress") {
        $DB_USER = null;
    }
    if ($DB_USER == null) {
        $DB_USER = "******" . time();
        $free->mysql_username = $DB_USER;
        $free->CreateSite(true);
    }
    if ($WordPressDBPass == null) {
        $WordPressDBPass = md5(time());
        $free->mysql_password = $WordPressDBPass;
        $free->CreateSite(true);
    }
    $DB_PASSWORD = $WordPressDBPass;
    if (is_file("{$WORKING_DIRECTORY}/salts.php")) {
        $Salts = @file_get_contents("{$WORKING_DIRECTORY}/salts.php");
    }
    if ($Salts == null) {
        $TMP = $unix->FILE_TEMP();
        build_progress("{$servername}: Acquiring Salts...", 44);
        $curl = new ccurl("https://api.wordpress.org/secret-key/1.1/salt/");
        if (!$curl->GetFile("{$TMP}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Unable to download salts !!\n";
            }
            build_progress("{$servername}: Acquiring Salts {failed}...", 110);
            return;
        }
        $ASASLT = false;
        $fa = explode("\n", @file_get_contents($TMP));
        @unlink($TMP);
        while (list($num, $ligne) = each($fa)) {
            if (preg_match("#define\\(#", $ligne)) {
                $ASASLT = true;
                break;
            }
        }
        if (!$ASASLT) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Unable to download salts !!\n";
            }
            build_progress("{$servername}: Acquiring Salts {failed}...", 110);
            return;
        }
        @file_put_contents("{$WORKING_DIRECTORY}/salts.php", @implode("\n", $fa));
    }
    build_progress("{$servername}: checking...", 48);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL host...........: \"{$DB_HOST}\"\n";
    }
    if (!$q->DATABASE_EXISTS($wordpressDB)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Create MySQL database: \"{$wordpressDB}\"\n";
        }
        $q->CREATE_DATABASE($wordpressDB);
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL database.......: \"{$wordpressDB}\"\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL user...........: \"{$DB_USER}\"\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL Password.......: \"{$DB_PASSWORD}\"\n";
    }
    $q->PRIVILEGES($DB_USER, $WordPressDBPass, $wordpressDB);
    $f[] = "<?php";
    $f[] = $Salts;
    $f[] = "/**";
    $f[] = " * The base configurations of the WordPress.";
    $f[] = " *";
    $f[] = " * This file has the following configurations: MySQL settings, Table Prefix,";
    $f[] = " * Secret Keys, WordPress Language, and ABSPATH. You can find more information";
    $f[] = " * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing";
    $f[] = " * wp-config.php} Codex page. You can get the MySQL settings from your web host.";
    $f[] = " *";
    $f[] = " * This file is used by the wp-config.php creation script during the";
    $f[] = " * installation. You don't have to use the web site, you can just copy this file";
    $f[] = " * to \"wp-config.php\" and fill in the values.";
    $f[] = " *";
    $f[] = " * @package WordPress";
    $f[] = " */";
    $f[] = "";
    $f[] = "// ** MySQL settings - You can get this info from your web host ** //";
    $f[] = "/** The name of the database for WordPress */";
    $f[] = "define('DB_NAME', '{$wordpressDB}');";
    $f[] = "";
    $f[] = "/** MySQL database username */";
    $f[] = "define('DB_USER', '{$DB_USER}');";
    $f[] = "";
    $f[] = "/** MySQL database password */";
    $f[] = "define('DB_PASSWORD', '{$DB_PASSWORD}');";
    $f[] = "";
    $f[] = "/** MySQL hostname */";
    $f[] = "define('DB_HOST', '{$DB_HOST}');";
    $f[] = "";
    $f[] = "/** Database Charset to use in creating database tables. */";
    $f[] = "define('DB_CHARSET', 'utf8');";
    $f[] = "";
    $f[] = "/** The Database Collate type. Don't change this if in doubt. */";
    $f[] = "define('DB_COLLATE', '');";
    $f[] = "";
    $f[] = "/**#@+";
    $f[] = " * Authentication Unique Keys and Salts.";
    $f[] = " *";
    $f[] = " * Change these to different unique phrases!";
    $f[] = " * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}";
    $f[] = " * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.";
    $f[] = " *";
    $f[] = " * @since 2.6.0";
    $f[] = " */";
    $f[] = "";
    $f[] = "/**#@-*/";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * WordPress Database Table prefix.";
    $f[] = " *";
    $f[] = " * You can have multiple installations in one database if you give each a unique";
    $f[] = " * prefix. Only numbers, letters, and underscores please!";
    $f[] = " */";
    $f[] = "\$table_prefix  = 'wp_';";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * WordPress Localized Language, defaults to English.";
    $f[] = " *";
    $f[] = " * Change this to localize WordPress. A corresponding MO file for the chosen";
    $f[] = " * language must be installed to wp-content/languages. For example, install";
    $f[] = " * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German";
    $f[] = " * language support.";
    $f[] = " */";
    $f[] = "define('WPLANG', '');";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * For developers: WordPress debugging mode.";
    $f[] = " *";
    $f[] = " * Change this to true to enable the display of notices during development.";
    $f[] = " * It is strongly recommended that plugin and theme developers use WP_DEBUG";
    $f[] = " * in their development environments.";
    $f[] = " */";
    $f[] = "define('WP_DEBUG', false);";
    $f[] = "";
    $f[] = "/* That's all, stop editing! Happy blogging. */";
    $f[] = "";
    $f[] = "/** Absolute path to the WordPress directory. */";
    $f[] = "if ( !defined('ABSPATH') )";
    $f[] = "\tdefine('ABSPATH', dirname(__FILE__) . '/');";
    $f[] = "";
    $f[] = "/** Sets up WordPress vars and included files. */";
    $f[] = "require_once(ABSPATH . 'wp-settings.php');";
    $f[] = "?>";
    @file_put_contents("{$WORKING_DIRECTORY}/wp-config.php", @implode("\n", $f));
    build_progress("{$servername}: wp-config.php {done}...", 50);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$WORKING_DIRECTORY}/wp-config.php done...\n";
    }
    $f = array();
    $f[] = "<?php";
    $f[] = "/*";
    $f[] = "WP-Cache Config Sample File";
    $f[] = "";
    $f[] = "See wp-cache.php for author details.";
    $f[] = "*/";
    $f[] = "";
    $f[] = "if ( ! defined('WPCACHEHOME') )";
    $f[] = "\tdefine( 'WPCACHEHOME', WP_PLUGIN_DIR . '/wp-super-cache/' );";
    $f[] = "";
    $f[] = "\$cache_compression = 0; // Super cache compression";
    $f[] = "\$cache_enabled = false;";
    $f[] = "\$super_cache_enabled = false;";
    $f[] = "\$cache_max_time = 3600; //in seconds";
    $f[] = "//\$use_flock = true; // Set it true or false if you know what to use";
    $f[] = "\$cache_path = WP_CONTENT_DIR . '/cache/';";
    $f[] = "\$file_prefix = 'wp-cache-';";
    $f[] = "\$ossdlcdn = 0;";
    $f[] = "";
    $f[] = "// Array of files that have 'wp-' but should still be cached";
    $f[] = "\$cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' );";
    $f[] = "";
    $f[] = "\$cache_rejected_uri = array('wp-.*\\.php', 'index\\.php');";
    $f[] = "\$cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider', 5 => 'Yandex' );";
    $f[] = "";
    $f[] = "\$cache_rebuild_files = 1;";
    $f[] = "";
    $f[] = "// Disable the file locking system.";
    $f[] = "// If you are experiencing problems with clearing or creating cache files";
    $f[] = "// uncommenting this may help.";
    $f[] = "\$wp_cache_mutex_disabled = 1;";
    $f[] = "";
    $f[] = "// Just modify it if you have conflicts with semaphores";
    $f[] = "\$sem_id = 5419;";
    $f[] = "";
    $f[] = "if ( '/' != substr(\$cache_path, -1)) {";
    $f[] = "\t\$cache_path .= '/';";
    $f[] = "}";
    $f[] = "";
    $f[] = "\$wp_cache_mobile = 0;";
    $f[] = "\$wp_cache_mobile_whitelist = 'Stand Alone/QNws';";
    $f[] = "\$wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';";
    $f[] = "";
    $f[] = "// change to relocate the supercache plugins directory";
    $f[] = "\$wp_cache_plugins_dir = WPCACHEHOME . 'plugins';";
    $f[] = "// set to 1 to do garbage collection during normal process shutdown instead of wp-cron";
    $f[] = "\$wp_cache_shutdown_gc = 0;";
    $f[] = "\$wp_super_cache_late_init = 0;";
    $f[] = "";
    $f[] = "// uncomment the next line to enable advanced debugging features";
    $f[] = "\$wp_super_cache_advanced_debug = 0;";
    $f[] = "\$wp_super_cache_front_page_text = '';";
    $f[] = "\$wp_super_cache_front_page_clear = 0;";
    $f[] = "\$wp_super_cache_front_page_check = 0;";
    $f[] = "\$wp_super_cache_front_page_notification = '0';";
    $f[] = "";
    $f[] = "\$wp_cache_object_cache = 0;";
    $f[] = "\$wp_cache_anon_only = 0;";
    $f[] = "\$wp_supercache_cache_list = 0;";
    $f[] = "\$wp_cache_debug_to_file = 0;";
    $f[] = "\$wp_super_cache_debug = 0;";
    $f[] = "\$wp_cache_debug_level = 5;";
    $f[] = "\$wp_cache_debug_ip = '';";
    $f[] = "\$wp_cache_debug_log = '';";
    $f[] = "\$wp_cache_debug_email = '';";
    $f[] = "\$wp_cache_pages[ \"search\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"feed\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"category\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"home\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"frontpage\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"tag\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"archives\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"pages\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"single\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"author\" ] = 0;";
    $f[] = "\$wp_cache_hide_donation = 0;";
    $f[] = "\$wp_cache_not_logged_in = 0;";
    $f[] = "\$wp_cache_clear_on_post_edit = 0;";
    $f[] = "\$wp_cache_hello_world = 0;";
    $f[] = "\$wp_cache_mobile_enabled = 0;";
    $f[] = "\$wp_cache_cron_check = 0;";
    $f[] = "?>";
    if (is_file("{$WORKING_DIRECTORY}/wp-content/plugins/wp-super-cache/wp-cache-config-sample.php")) {
        @file_put_contents("{$WORKING_DIRECTORY}/wp-content/plugins/wp-super-cache/wp-cache-config.php", @implode("\n", $f));
    }
    @file_put_contents("{$WORKING_DIRECTORY}/wp-config.php", @implode("\n", $f));
    build_progress("{$servername}: wp-config.php {done}...", 50);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$WORKING_DIRECTORY}/wp-config.php done...\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Testing configuration...\n";
    }
    if ($free->groupware_admin == null) {
        $ldap = new clladp();
        $free->groupware_admin = $ldap->ldap_admin;
        $free->groupware_password = $ldap->ldap_password;
    }
    $admin = $unix->shellEscapeChars($free->groupware_admin);
    $password = $unix->shellEscapeChars($free->groupware_password);
    $WORKING_DIRECTORY_CMDLINE = $unix->shellEscapeChars($WORKING_DIRECTORY);
    $cmd = array();
    $cmd[] = "/usr/share/artica-postfix/bin/wp-cli.phar core install";
    $cmd[] = "--url=\"{$servername}\"";
    $cmd[] = "--title=\"{$servername}\"";
    $cmd[] = "--admin_user={$admin}";
    $cmd[] = "--admin_password={$password}";
    $cmd[] = "--admin_email={$admin}@{$servername}";
    $cmd[] = "--path={$WORKING_DIRECTORY_CMDLINE}";
    $cmd[] = "--allow-root --debug --no-color 2>&1";
    $cmdline = @implode(" ", $cmd);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$cmdline}\n";
    }
    build_progress("{$servername}: {install_wordpress} {please_wait} !...", 51);
    exec($cmdline, $results1);
    while (list($num, $ligne) = each($results1)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$ligne}\n";
        }
    }
    build_progress("{$servername}: {enforce_security}", 52);
    secure_wp($WORKING_DIRECTORY);
    build_progress("{$servername}: {directory_size}", 53);
    $size = $unix->DIRSIZE_BYTES($free->WORKING_DIRECTORY);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$free->WORKING_DIRECTORY} {$size}Bytes\n";
    }
    $q->QUERY_SQL("UPDATE freeweb SET DirectorySize={$size} WHERE servername='{$servername}'", "artica_backup");
    if (!$q->ok) {
        system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "freewebs");
    }
}
Beispiel #21
0
function install()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $pidTimeEx = $unix->file_time_min($pidTime);
    if ($pidTimeEx < 60) {
        return;
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    include_once dirname(__FILE__) . "/ressources/class.ccurl.inc";
    $Masterbin = "/opt/ufdbcat/bin/ufdbcatdd";
    $DebianVersion = _DebianVersion();
    $Arch = _Architecture();
    if ($Arch == 32) {
        return;
    }
    $filename = "ufdbcat-debian{$DebianVersion}-{$Arch}-1.31.tar.gz";
    $url = "http://articatech.net/download/Debian7-squid/{$filename}";
    $curl = new ccurl($url);
    $tmpfile = $unix->TEMP_DIR() . "/{$filename}";
    if (!$curl->GetFile($tmpfile)) {
        squid_admin_mysql(0, "Unable to download {$filename}", @implode("\n", $curl->errors), __FILE__, __LINE__);
        return;
    }
    $tar = $unix->find_program("tar");
    shell_exec("{$tar} xf {$tmpfile} -C /");
    if (is_file($Masterbin)) {
        squid_admin_mysql(0, "Success installing Artica Categorize Daemon", null, __FILE__, __LINE__);
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --ufdbcat");
    if (!$GLOBALS["NOUPDATE"]) {
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.blacklists.php --ufdb --force --" . __FUNCTION__ . "-" . __LINE__ . " >/dev/null 2>&1 &");
    }
}
Beispiel #22
0
function nightly()
{
    @mkdir("/var/log/artica-postfix", 0755, true);
    $GLOBALS["MasterIndexFile"] = "/usr/share/artica-postfix/ressources/index.ini";
    $unix = new unix();
    $sock = new sockets();
    $autoinstall = true;
    $timefile = "/etc/artica-postfix/croned.1/nightly";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = @file_get_contents($pidfile);
    $kill = $unix->find_program("kill");
    $tmpdir = $unix->TEMP_DIR();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " nightly build already executed PID: {$pid} since {$time}Mn\n";
        updater_events("Already executed PID: {$pid} since {$time}Mn");
        if ($time < 120) {
            if (!$GLOBALS["FORCE"]) {
                die;
            }
        }
        unix_system_kill_force($pid);
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    updater_events("Running PID {$mypid}");
    $EnableScheduleUpdates = $sock->GET_INFO("EnableScheduleUpdates");
    $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("EnableScheduleUpdates"));
    if (!is_numeric($EnableScheduleUpdates)) {
        $EnableScheduleUpdates = 0;
    }
    $ArticaAutoUpateOfficial = $sock->GET_INFO("ArticaAutoUpateOfficial");
    $ArticaAutoUpateNightly = intval($sock->GET_INFO("ArticaAutoUpateNightly"));
    $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("ArticaUpdateIntervalAllways"));
    $OfficialArticaUri = $sock->GET_INFO("OfficialArticaUri");
    if (!is_numeric($ArticaAutoUpateOfficial)) {
        $ArticaAutoUpateOfficial = 1;
    }
    if ($OfficialArticaUri == null) {
        $OfficialArticaUri = "http://articatech.net";
    }
    $CheckEveryMinutes = 60;
    $uri = $OfficialArticaUri;
    if ($GLOBALS["FORCE"]) {
        _artica_update_event(1, "Update task pid {$mypid} is forced by an human.", null, __FILE__, __LINE__);
    }
    if ($EnableScheduleUpdates == 1) {
        if (!$GLOBALS["FORCE"]) {
            if (!$GLOBALS["BYCRON"]) {
                updater_events("Operation must be only executed by scheduler");
                _artica_update_event(2, "Operation must be only executed by scheduler ( use --force to by pass)", null, __FILE__, __LINE__);
                @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100);
                return;
            }
        }
    }
    if ($ArticaAutoUpateOfficial == 0) {
        updater_events("Artica Update feature is disabled");
        echo "Starting......: " . date("H:i:s") . " Artica Update feature is disabled (enabled = {$ArticaAutoUpateOfficial}} )\n";
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($EnableScheduleUpdates == 0) {
            if ($unix->file_time_min($timefile) < $CheckEveryMinutes) {
                updater_events("too short time ({$timefile}Mn, require {$CheckEveryMinutes}mn)");
                echo "Starting......: " . date("H:i:s") . " update feature (too short time, require {$CheckEveryMinutes}mn)\n";
                @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 110);
                return;
            }
        }
        if ($ArticaUpdateIntervalAllways == 0) {
            if ($unix->IsProductionTime()) {
                updater_events("Update feature need to be run only during the non-production time");
                echo "Starting......: " . date("H:i:s") . " update feature need to be run only during the non-production time \n";
                @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 110);
            }
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    // ----------------------- LANCEMENT ------------------------------------------------------------------------------
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    if ($EnableArticaMetaClient == 1) {
        updater_events("Nightly builds using Meta console");
        echo "Starting......: " . date("H:i:s") . " Nightly builds using Meta console\n";
        system("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --artica-updates >/dev/null 2>&1 &");
        die;
    }
    echo "Starting......: " . date("H:i:s") . " Nightly builds checking an official release first\n";
    if (update_release()) {
        updater_events("update_release() return true, finish");
        return;
    }
    if ($ArticaAutoUpateNightly == 0) {
        echo "Starting......: " . date("H:i:s") . " Nightly builds feature is disabled\n";
        updater_events("Update to Nightly builds feature is disabled");
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100);
        return;
    }
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 0);
    $array = unserialize(@file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaUpdateRepos"));
    $OFFICIALS = $array["NIGHT"];
    $key = update_find_latest_nightly();
    $MyNextVersion = $key;
    $Lastest = $OFFICIALS[$key]["VERSION"];
    $MAIN_URI = $OFFICIALS[$key]["URL"];
    $MAIN_MD5 = $OFFICIALS[$key]["MD5"];
    $MAIN_FILENAME = $OFFICIALS[$key]["FILENAME"];
    $uri = $MAIN_URI;
    $Lastest = trim(strtolower($Lastest));
    $MyCurrentVersion = GetCurrentVersion();
    echo "Starting......: " . date("H:i:s") . " Current version: {$MyCurrentVersion}\n";
    echo "Starting......: " . date("H:i:s") . " Nightly builds version \"{$Lastest}\" on repository\n";
    echo "Starting......: " . date("H:i:s") . " nightly builds Cur:{$MyCurrentVersion}, Next:{$MyNextVersion}\n";
    if ($MyNextVersion == $MyCurrentVersion) {
        echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Same version\"\n";
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100);
        return;
    }
    if ($MyCurrentVersion > $MyNextVersion) {
        echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Most updated\"\n";
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100);
        return;
    }
    $t1 = time();
    _artica_update_event(2, "nightly builds Downloading new version {$Lastest}", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " nightly builds Downloading new version {$Lastest}, please wait\n";
    events("Downloading new version {$Lastest}");
    $ArticaFileTemp = "{$tmpdir}/{$Lastest}/artica-{$Lastest}.tgz";
    @mkdir("{$tmpdir}/{$Lastest}", 0755, true);
    $curl = new ccurl($uri);
    $curl->Timeout = 2400;
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "nightly_progress";
    $t = time();
    if (!$curl->GetFile($ArticaFileTemp)) {
        _artica_update_event(0, "nightly builds Unable to download latest nightly build {$Lastest} with error {$curl->error}", null, __FILE__, __LINE__);
        events("Unable to download latest nightly build with error {$curl->error}");
        system_admin_events("Unable to download latest nightly build with error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        @unlink($ArticaFileTemp);
        return;
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    _artica_update_event(2, "{$MAIN_FILENAME} download, took {$took}", null, __FILE__, __LINE__);
    $md5_file = md5_file($ArticaFileTemp);
    if ($md5_file != $MAIN_MD5) {
        echo "{$md5_file} <> {$MAIN_MD5}\n";
        _artica_update_event(0, "nightly builds {$MAIN_FILENAME}: corrupted package", null, __FILE__, __LINE__);
        events("nightly builds {$MAIN_FILENAME}: corrupted package");
        system_admin_events("nightly builds {$MAIN_FILENAME}: corrupted package", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        @unlink($ArticaFileTemp);
        return;
    }
    system_admin_events("{$MAIN_FILENAME} download, took {$took}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
    events("artica-{$Lastest}.tgz download, took {$took}");
    $size = @filesize($ArticaFileTemp);
    $size = FormatBytes($size / 1024, true);
    ArticaMeta_nightly($ArticaFileTemp);
    echo "Starting......: " . date("H:i:s") . " nightly builds took {$took}\n";
    events("Now, installing the newest version in {$ArticaFileTemp} package...");
    $size = @filesize($ArticaFileTemp);
    $size = FormatBytes($size / 1024, true);
    if (!install_package($ArticaFileTemp, $Lastest)) {
        events("Install package Failed...");
        return false;
    }
    events("New Artica update v.{$Lastest}");
    _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size})", null, __FILE__, __LINE__);
    system_admin_events("New Artica update v.{$Lastest}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
}
Beispiel #23
0
function compile_ufdbcat()
{
    $unix = new unix();
    $uri = "http://www.articatech.net/download/ufdbGuard-1.31.tar.gz";
    $curl = new ccurl("http://www.articatech.net/download/ufdbGuard-1.31.tar.gz");
    echo "Downloading {$uri}\n";
    $tempdir = $unix->TEMP_DIR() . "/ufdb";
    $tempfile = "{$tempdir}/ufdbGuard-1.31.tar.gz";
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $cp = $unix->find_program("cp");
    if (is_dir($tempdir)) {
        shell_exec("{$rm} -rf {$tempdir}");
    }
    @mkdir($tempdir, 0755, true);
    if (is_file($tempfile)) {
        @unlink($tempfile);
    }
    if (!$curl->GetFile($tempfile)) {
        echo "Fatal, unable to download {$uri}\n";
        meta_admin_mysql(0, "Fatal, unable to download {$uri}", @implode("\n", $curl->errors), __FILE__, __LINE__);
        return;
    }
    if (is_dir("{$tempdir}/ufdbcompile")) {
        shell_exec("{$rm} -rf {$tempdir}/ufdbcompile");
    }
    echo "Uncompressing {$tempdir}/ufdbGuard-1.31.tar.gz to {$tempdir}/\n";
    shell_exec("{$tar} -xf {$tempdir}/ufdbGuard-1.31.tar.gz -C {$tempdir}/");
    $dirs = $unix->dirdir($tempdir);
    while (list($directory, $value) = each($dirs)) {
        echo "Found directory {$directory}\n";
        if (is_file("{$directory}/src/mtserver/ufdbguardd.c")) {
            $WORKDIR = "{$directory}";
            break;
        }
    }
    if (!is_dir($WORKDIR)) {
        echo "Fatal, unable to download {$uri}\n";
        meta_admin_mysql(0, "Fatal, unable to locate working directory", __FILE__, __LINE__);
        if (is_dir($tempdir)) {
            shell_exec("{$rm} -rf {$tempdir}");
        }
        return;
    }
    echo "Patching mtserver/ufdbguardd.c\n";
    $C = explode("\n", @file_get_contents("{$directory}/src/mtserver/ufdbguardd.c"));
    while (list($index, $line) = each($C)) {
        if (strpos($line, "/tmp/ufdbguardd-") > 0) {
            echo "Patching mtserver/ufdbguardd.c line {$index}\n";
            $C[$index] = str_replace("/tmp/ufdbguardd-", "/var/run/ufdbcat-", $line);
        }
    }
    @file_put_contents("{$directory}/src/mtserver/ufdbguardd.c", @implode("\n", $C));
    chdir($WORKDIR);
    if (is_dir("/opt/ufdbcat")) {
        shell_exec("{$rm} -rf /opt/ufdbcat");
    }
    echo "Configure\n";
    $f[] = "./configure";
    $f[] = "--prefix=/opt/ufdbcat";
    $f[] = "--includedir=\"\\\${prefix}/include\"";
    $f[] = "--mandir=\"\\\${prefix}/share/man\"";
    $f[] = "--infodir=\"\\\${prefix}/share/info\"";
    $f[] = "--sysconfdir=/etc/ufdbcat";
    $f[] = "--localstatedir=/opt/ufdbcat";
    $f[] = "--with-ufdb-logdir=/var/log/ufdbcat";
    $f[] = "--with-ufdb-dbhome=/home/ufdbcat";
    $f[] = "--with-ufdb-user=root";
    $f[] = "--with-ufdb-config=/etc/ufdbcat";
    $f[] = "--with-ufdb-logdir=/var/log/ufdbcat";
    $f[] = "--with-ufdb-config=/etc/ufdbcat";
    $f[] = "--with-ufdb-piddir=/var/run/ufdbcat";
    $cmd = @implode(" ", $f);
    system($cmd);
    echo "Make\n";
    system("make");
    echo "Install\n";
    system("make install");
    if (!is_file("/opt/ufdbcat/bin/ufdbguardd")) {
        echo "Fatal, unable to compile ufdbcat\n";
        meta_admin_mysql(0, "Fatal, unable to compile ufdbcat", __FILE__, __LINE__);
        if (is_dir($tempdir)) {
            shell_exec("{$rm} -rf {$tempdir}");
        }
        return;
    }
    @copy("/opt/ufdbcat/bin/ufdbguardd", "/opt/ufdbcat/bin/ufdbcatdd");
    @unlink("/opt/ufdbcat/bin/ufdbguardd");
    @chmod("/opt/ufdbcat/bin/ufdbcatdd", 0755);
    $ufdbcatVersion = ufdbcatVersion();
    $Architecture = Architecture();
    $DebianVersion = DebianVersion();
    $base = "/root/ufdbcat-compile";
    if (is_dir($base)) {
        shell_exec("{$rm} -rf {$base}");
    }
    @mkdir("{$base}/opt/ufdbcat", 0755, true);
    shell_exec("{$cp} -rfp /opt/ufdbcat/* {$base}/opt/ufdbcat/");
    $filename = "ufdbcat-debian{$DebianVersion}-{$Architecture}-{$ufdbcatVersion}.tar.gz";
    chdir($base);
    @unlink("/root/{$filename}");
    shell_exec("/bin/tar -czf /root/{$filename} *");
    echo "/root/{$filename} done\n\n";
}
Beispiel #24
0
function start()
{
    $unix = new unix();
    $tmp_path = $unix->TEMP_DIR();
    _progress("Check repository", 10);
    echo "Downloading index file...\n";
    $curl = new ccurl("http://www.artica.fr/auto.update.php");
    $curl->NoHTTP_POST = true;
    if (!$curl->get()) {
        _progress("Check repository - FAILED", 100);
        echo "{$curl->error}\n";
        return;
    }
    $ini = new Bs_IniHandler();
    $ini->loadString($curl->data);
    $couldversion = $ini->_params["NEXT"]["z-push"];
    echo "Available version = {$couldversion}\n";
    if ($couldversion == null) {
        _progress("Check repository - FAILED", 100);
        echo "Corrupted index file\n";
        return;
    }
    $rm = $unix->find_program("rm");
    $SourceFile = "z-push-{$couldversion}.tar.gz";
    $SourcePath = "{$tmp_path}/{$SourceFile}";
    $SourceTemp = "{$tmp_path}/" . time();
    $InstallDir = $SourceTemp;
    echo "Downloading http://www.artica.fr/download/z-push-{$couldversion}.tar.gz\n";
    _progress("Downloading v.{$couldversion}", 15);
    $curl = new ccurl("http://www.artica.fr/download/z-push-{$couldversion}.tar.gz");
    @unlink($SourcePath);
    if (!$curl->GetFile($SourcePath)) {
        @unlink($SourcePath);
        _progress("Download {$SourceFile} - FAILED", 100);
        echo $curl->error . "\n";
        return;
    }
    _progress("Uncompress {$SourceFile}", 20);
    echo "Create temp dir: {$SourceTemp}\n";
    echo "Uncompress {$SourcePath}\n";
    @mkdir("/usr/share/z-push", 0755, true);
    @mkdir($SourceTemp, 0755, true);
    $tar = $unix->find_program("tar");
    $cp = $unix->find_program("cp");
    $php = $unix->LOCATE_PHP5_BIN();
    shell_exec("{$tar} xf {$SourcePath} -C {$SourceTemp}/");
    @unlink($SourcePath);
    if (!is_file("{$InstallDir}/version.php")) {
        echo "Finding directory\n";
        $DIRS = $unix->dirdir($SourceTemp);
        while (list($num, $ligne) = each($DIRS)) {
            if (is_file("{$num}/version.php")) {
                echo "Found Directory {$num}\n";
                $InstallDir = $num;
                break;
            }
        }
    }
    if (!is_file("{$InstallDir}/version.php")) {
        _progress("Failed Corrupted compressed file", 100);
        shell_exec("{$rm} -rf {$SourceTemp}");
        return;
    }
    _progress("Installing z-Push {$couldversion}", 50);
    shell_exec("{$cp} -rfd {$InstallDir}/* /usr/share/z-push/");
    shell_exec("{$rm} -rf {$SourceTemp}");
    _progress("Reconfiguring FreeWebs ", 80);
    system("{$php} /usr/share/artica-postfix/exec.freeweb.php --reconfigure-zpush");
    _progress("Success", 100);
}
Beispiel #25
0
function HyperCacheScanDownload($urikey, $TargetFile, $ID, $FileType)
{
    if (!isset($GLOBALS["SIZE_DOWNLOADED"])) {
        $GLOBALS["SIZE_DOWNLOADED"] = 0;
    }
    if (!isset($GLOBALS["FAILED_DOWNLOADED"])) {
        $GLOBALS["FAILED_DOWNLOADED"] = 0;
    }
    if (!is_numeric($GLOBALS["SIZE_DOWNLOADED"])) {
        $GLOBALS["SIZE_DOWNLOADED"] = 0;
    }
    if (!is_numeric($GLOBALS["FAILED_DOWNLOADED"])) {
        $GLOBALS["FAILED_DOWNLOADED"] = 0;
    }
    $curl = new ccurl($urikey);
    $FullTarGetPath = $GLOBALS["HyperCacheStoragePath"] . "/" . $TargetFile;
    $GLOBALS["HITS"]++;
    $parse_url = parse_url($urikey);
    $hostname = $parse_url["host"];
    $OriginalFile = basename($parse_url["path"]);
    $t = time();
    events("{downloading} {$OriginalFile} {from} {$hostname}", $ID, 3, __LINE__);
    if (!$curl->GetFile($FullTarGetPath)) {
        events("HyperCacheScanDownload:: Download failed with error {$curl->error}", $ID, 2, __LINE__);
        $GLOBALS["FAILED_DOWNLOADED"]++;
        return false;
    }
    $size = @filesize($FullTarGetPath);
    $MD5File = md5_file($FullTarGetPath);
    $sizeLog = FormatBytes($size / 1024);
    events("{$hostname}: {$OriginalFile} ({$sizeLog}) {took}: " . distanceOfTimeInWords($t, time()), $ID, 2, __LINE__);
    $GLOBALS["SIZE_DOWNLOADED"] = $GLOBALS["SIZE_DOWNLOADED"] + $size;
    $path = HyperCacheMD5File_get($MD5File);
    if ($path != null) {
        if (!HyperCacheRetranslation_set($urikey, $MD5File, $FileType, $path)) {
            $GLOBALS["FAILED_DOWNLOADED"]++;
            return;
        }
        return;
    }
    if (!HyperCacheMD5File_set($MD5File, $TargetFile, $FileType, $size, $OriginalFile)) {
        $GLOBALS["FAILED_DOWNLOADED"]++;
        return;
    }
    if (!HyperCacheRetranslation_set($urikey, $MD5File, $FileType, $TargetFile)) {
        $GLOBALS["FAILED_DOWNLOADED"]++;
        return;
    }
    return true;
}
Beispiel #26
0
function check()
{
    $unix = new unix();
    $oldpid = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    if ($unix->process_exists(@file_get_contents($oldpid))) {
        writelogs("Process " . @file_get_contents($oldpid) . " already exists", __FUNCTION__, __FILE__);
        die;
    }
    @file_put_contents($oldpid, getmypid());
    $sock = new sockets();
    $EnableEmergingThreats = $sock->GET_INFO("EnableEmergingThreats");
    if (!is_numeric($EnableEmergingThreats)) {
        $sock->SET_INFO("EnableEmergingThreats", 0);
        $EnableEmergingThreats = 0;
    }
    if ($EnableEmergingThreats != 1) {
        echo "Starting......: Emerging Threats: Disabled\n";
        @unlink("/usr/share/artica-postfix/ressources/logs/EnableEmergingThreatsBuild.db");
        die;
    }
    $GLOBALS["iptables"] = $unix->find_program("iptables");
    $GLOBALS["ipset"] = $unix->find_program("ipset");
    if (!is_file($GLOBALS["iptables"])) {
        echo "Starting......: Emerging Threats: iptables no such file\n";
        return;
    }
    if (!is_file($GLOBALS["ipset"])) {
        echo "Starting......: Emerging Threats: ipset no such file\n";
        $unix->send_email_events("Could not update Emerging Threats (ipset no such file)", "You have enabled Emerging Threats, but it seems that\nipset binary is not installed on your system.\ntry to install it by using setup-ubuntu stored in /usr/share/artica-postfix/bin\nArtica will disable Emerging Threats to remove this notification");
        $sock->SET_INFO("EnableEmergingThreats", 0);
        return;
    }
    $q = new mysql();
    $sql = "SELECT * FROM postfix_whitelist_con";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "{$q->mysql_error}\n";
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $WHITELISTED[$ligne["ipaddr"]] = true;
        $WHITELISTED[$ligne["hostname"]] = true;
    }
    $pattern_number = @file_get_contents("/etc/artica-postfix/emerging.threats.pattern");
    if (!is_numeric($pattern_number)) {
        $pattern_number = 0;
    }
    $http = new ccurl("http://rules.emergingthreats.net/fwrules/FWrev");
    $tmp = $unix->FILE_TEMP();
    if (!$http->GetFile("{$tmp}")) {
        echo "Starting......: Emerging Threats: http error {$http->error}\n";
        return;
    }
    $pattern_number_internet = trim(@file_get_contents($tmp));
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting......: Emerging Threats: {$tmp}\n";
    }
    if (!is_numeric($pattern_number_internet)) {
        echo "Starting......: Emerging Threats: corrupted pattern\n";
        return;
    }
    if ($pattern_number_internet == $pattern_number) {
        echo "Starting......: Emerging Threats: No new Pattern current is {$pattern_number}\n";
        return;
    }
    echo "Starting......: Emerging Threats: new Pattern {$pattern_number_internet}\n";
    $tmp = $unix->FILE_TEMP();
    $http = new ccurl("http://rules.emergingthreats.net/fwrules/emerging-Block-IPs.txt");
    if (!$http->GetFile("{$tmp}")) {
        echo "Starting......: Emerging Threats: http error {$http->error}\n";
        return;
    }
    $tbl = explode("\n", @file_get_contents("{$tmp}"));
    if (count($tbl) == 0) {
        echo "Starting......: Emerging Threats: corrupted file\n";
        return;
    }
    $iptables_drop_chain = 'ETLOGDROP';
    $iptables_att_chain = 'ATTACKERS';
    $ipset_botcc = 'botcc';
    $ipset_botccnet = 'botccnet';
    $iptables = $GLOBALS["iptables"];
    $ipset = $GLOBALS["ipset"];
    echo "Starting......: Emerging Threats: flush {$iptables_drop_chain}\n";
    shell_exec("{$iptables} -F {$iptables_drop_chain} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: flush {$iptables_att_chain}\n";
    shell_exec("{$iptables} -F {$iptables_att_chain} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: delete {$iptables_att_chain} from FORWARD chain\n";
    shell_exec("{$iptables} -D FORWARD -j {$iptables_att_chain} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: delete {$iptables_att_chain} from INPUT chain\n";
    shell_exec("{$iptables} -D INPUT -j {$iptables_att_chain} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: delete {$ipset_botccnet}\n";
    shell_exec("{$ipset} -X {$ipset_botccnet} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: delete {$ipset_botcc}\n";
    shell_exec("{$ipset} -X {$ipset_botcc} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: Create attacker and drop chains\n";
    shell_exec("{$iptables} -N {$iptables_att_chain} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: insert {$iptables_att_chain} chain into FOWARD chain\n";
    shell_exec("{$iptables} -I FORWARD 1 -j {$iptables_att_chain} 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: insert {$iptables_att_chain} chain into INPUT chain\n";
    shell_exec("{$iptables} -I INPUT 1 -j {$iptables_att_chain} 2>/dev/null 1>/dev/null");
    shell_exec("{$iptables} -N {$iptables_drop_chain} 2>/dev/null 1>/dev/null");
    shell_exec("{$iptables} -A {$iptables_drop_chain} -j LOG --log-level INFO --log-prefix 'ET BLOCK: ' 2>/dev/null 1>/dev/null");
    shell_exec("{$iptables} -A {$iptables_drop_chain} -j DROP 2>/dev/null 1>/dev/null");
    shell_exec("{$ipset} -N {$ipset_botccnet} nethash 2>/dev/null 1>/dev/null");
    shell_exec("{$ipset} -N {$ipset_botcc} iphash 2>/dev/null 1>/dev/null");
    echo "Starting......: Emerging Threats: Starting blocklist " . count($tbl) . " ip(s) in population\n";
    $count = 0;
    while (list($num, $ligne) = each($tbl)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (substr($ligne, 0, 1) == "#") {
            continue;
        }
        if (!$WHITELISTED[$ligne]) {
            echo "adding {$ligne}\n";
            shell_exec("{$ipset} -A {$ipset_botccnet} {$ligne} 2>/dev/null 1>/dev/null");
            shell_exec("{$ipset} -A {$ipset_botcc} {$ligne} 2>/dev/null 1>/dev/null");
            $count++;
        }
    }
    shell_exec("{$iptables} -A {$iptables_att_chain} -p ALL -m set --set {$ipset_botcc} src,src -j {$iptables_drop_chain} 2>/dev/null 1>/dev/null");
    shell_exec("{$iptables} -A {$iptables_att_chain} -p ALL -m set --set {$ipset_botccnet} src,src -j {$iptables_drop_chain} 2>/dev/null 1>/dev/null");
    shell_exec("{$iptables} -A {$iptables_att_chain} -p ALL -m set --set {$ipset_botcc} dst,dst -j {$iptables_drop_chain} 2>/dev/null 1>/dev/null");
    shell_exec("{$iptables} -A {$iptables_att_chain} -p ALL -m set --set {$ipset_botccnet} dst,dst -j {$iptables_drop_chain} 2>/dev/null 1>/dev/null");
    $unix->send_email_events("Emerging Threats update new pattern {$pattern_number_internet} {$count} ip addresses", "", "system");
    @file_put_contents("/etc/artica-postfix/emerging.threats.pattern", $pattern_number_internet);
    shell_exec("{$ipset} -L botccnet >/etc/artica-postfix/botccnet.list");
    $tr = explode("\n", @file_get_contents("/etc/artica-postfix/botccnet.list"));
    $conf = array();
    while (list($num, $ligne) = each($tr)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (preg_match("#(.+?):#", $ligne)) {
            continue;
        }
        $conf["THREADS"][] = $ligne;
    }
    shell_exec("{$ipset} --list botcc >/etc/artica-postfix/ccnet.list");
    $tr = explode("\n", @file_get_contents("/etc/artica-postfix/ccnet.list"));
    $conf = array();
    while (list($num, $ligne) = each($tr)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (preg_match("#(.+?):#", $ligne)) {
            continue;
        }
        $conf["THREADS"][] = $ligne;
    }
    $conf["COUNT"] = count($conf["THREADS"]);
    writelogs_framework("Writing ressources/logs/EnableEmergingThreatsBuild.db done.");
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/EnableEmergingThreatsBuild.db", serialize($conf));
    @chmod("/usr/share/artica-postfix/ressources/logs/EnableEmergingThreatsBuild.db", 0777);
    $conf["COUNT"] = count($conf["THREADS"]);
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/EnableEmergingThreatsBuild.db", serialize($conf));
}
Beispiel #27
0
function backup_webget($ID, $array)
{
    if ($GLOBALS["VERBOSE"]) {
        print_r($array);
    }
    $RemoteArticaServer = $array["RemoteArticaServer"];
    $RemoteArticaPort = $array["RemoteArticaPort"];
    $RemoteArticaUser = $array["RemoteArticaUser"];
    $RemoteArticaPassword = $array["RemoteArticaPassword"];
    $RemoteArticaSite = $array["RemoteArticaSite"];
    $AutoRestore = $array["AutoRestore"];
    $AutoRestoreSqlInstance = $array["AutoRestoreSqlInstance"];
    $AutoRestoreSiteName = $array["AutoRestoreSiteName"];
    if (!is_numeric($AutoRestore)) {
        $AutoRestore = 0;
    }
    if (!is_numeric($AutoRestoreSqlInstance)) {
        $AutoRestoreSqlInstance = 0;
    }
    $array["RemoteArticaPassword"] = md5($array["RemoteArticaPassword"]);
    $unix = new unix();
    $rm = $unix->find_program("rm");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $RESULTS = null;
    if (trim($RemoteArticaServer) == null) {
        backup_events($ID, $RemoteArticaSite, "ERROR, No remote Artica server defined...", __LINE__);
        return;
    }
    if (!is_numeric($RemoteArticaPort)) {
        $RemoteArticaPort = 9000;
    }
    $uri = "https://{$RemoteArticaServer}:{$RemoteArticaPort}";
    backup_events($ID, $RemoteArticaSite, "INFO, Connecting to {$uri} in order to send backup order.", __LINE__);
    include_once dirname(__FILE__) . "/ressources/class.ccurl.inc";
    $params = base64_encode(serialize($array));
    $curl = new ccurl("{$uri}/exec.articaget.php?params={$params}");
    $curl->Timeout = 5600;
    $curl->NoHTTP_POST = true;
    if (!$curl->get()) {
        backup_events($ID, $RemoteArticaSite, "ERROR, Connecting to {$uri} {$curl->error}", __LINE__);
        return;
    }
    $datas = $curl->data;
    if (preg_match("#<LOGS>(.*?)</LOGS>#is", $datas, $re)) {
        $events = $re[1];
    }
    if (preg_match("#<RESULTS>(.*?)</RESULTS>#is", $datas, $re)) {
        $RESULTS = $re[1];
    }
    if ($RESULTS == null) {
        backup_events($ID, $RemoteArticaSite, "ERROR, No answer from {$RemoteArticaServer} ??? {$datas}", __LINE__);
        return;
    }
    if ($RESULTS != "SUCCESS") {
        if ($GLOBALS["VERBOSE"]) {
            echo "\nFAILED\n\n";
        }
        backup_events($ID, $RemoteArticaSite, "ERROR, Failed -> `{$RESULTS}`", __LINE__);
        backup_events($ID, $RemoteArticaSite, "INFO, {$events}", __LINE__);
        return;
    }
    backup_events($ID, $RemoteArticaSite, "INFO,downloading {$RemoteArticaSite}.tar.gz package", __LINE__);
    $curl = new ccurl("{$uri}/ressources/logs/web/{$RemoteArticaSite}.tar.gz");
    $curl->Timeout = 5600;
    $curl->NoHTTP_POST = true;
    @mkdir("/var/tmp/{$RemoteArticaSite}", 0755, true);
    if ($GLOBALS["VERBOSE"]) {
        echo "\nDownloading {$uri}/ressources/logs/web/{$RemoteArticaSite}.tar.gz\n\n";
    }
    $curdate = date("YmdH");
    if (!$curl->GetFile("/var/tmp/{$RemoteArticaSite}/{$RemoteArticaSite}-{$curdate}.tar.gz")) {
        backup_events($ID, $RemoteArticaSite, "ERROR, Failed downloading {$RemoteArticaSite}.tar.gz {$curl->error}", __LINE__);
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "\n\n";
    }
    backup_events($ID, $RemoteArticaSite, "INFO, Connecting to {$uri} in order to cleaning the backup container.", __LINE__);
    $curl = new ccurl("{$uri}/exec.articaget.php?params={$params}&remove=yes");
    $curl->NoHTTP_POST = true;
    if (!$curl->get()) {
        backup_events($ID, $RemoteArticaSite, "ERROR, ordering to cleaning container...{$uri} {$curl->error}", __LINE__);
    }
    //Auto-restore
    if ($AutoRestore == 0) {
        backup_events($ID, $RemoteArticaSite, "INFO the Autorestore feature is disabled...", __LINE__);
    }
    if ($AutoRestore == 1) {
        backup_events($ID, $RemoteArticaSite, "INFO the Autorestore feature is enabled on `{$AutoRestoreSiteName}` local website...", __LINE__);
        if ($AutoRestoreSiteName != null) {
            $tt1 = time();
            backup_events($ID, $RemoteArticaSite, "INFO, auto-restore {$RemoteArticaSite}.tar.gz to {$AutoRestoreSiteName}", __LINE__);
            $cmd = "{$php5} " . dirname(__FILE__) . "/exec.freeweb.php --restore \"{$AutoRestoreSiteName}\" \"/var/tmp/{$RemoteArticaSite}/{$RemoteArticaSite}-{$curdate}.tar.gz\" {$AutoRestoreSqlInstance} --verbose 2>&1";
            exec($cmd, $AutorestoreResults);
            $tt2 = time();
            $took = $unix->distanceOfTimeInWords($tt1, $tt2, true);
            backup_events($ID, $RemoteArticaSite, "INFO, Auto-restore finish took {$took}, see details:\n" . @implode("\n", $AutorestoreResults), __LINE__);
        } else {
            backup_events($ID, $RemoteArticaSite, "ERROR, Autorestore disabled `AutoRestoreSiteName` is null ", __LINE__);
        }
    }
    $DestinationPath = "{$GLOBALS["MOUNTED_PATH_FINAL"]}/freewebs/webget.{$RemoteArticaSite}";
    backup_mkdir($DestinationPath);
    if (!backup_isdir($DestinationPath)) {
        backup_events($ID, $RemoteArticaSite, "ERROR, {$DestinationPath} permission denied or no such file or directory", __LINE__);
        @unlink("/var/tmp/{$RemoteArticaSite}/{$RemoteArticaSite}.tar.gz");
        return false;
    }
    $info = backup_copy("/var/tmp/{$RemoteArticaSite}/", "{$DestinationPath}", $ID);
    backup_events($ID, $RemoteArticaSite, "INFO,/var/tmp/{$RemoteArticaSite}\n{$info}", __LINE__);
    backup_events($ID, $RemoteArticaSite, "INFO,cleaning /var/tmp/{$RemoteArticaSite}", __LINE__);
    if (is_dir("/var/tmp/{$RemoteArticaSite}")) {
        shell_exec("{$rm} -rf /var/tmp/{$RemoteArticaSite}");
    }
}
function update_remote_file($BASE_URI, $filename, $md5, $prc)
{
    if (!isset($GLOBALS["UFDB_SIZE"])) {
        $GLOBALS["UFDB_SIZE"] = 0;
    }
    WriteMyLogs("update_remote_file({$BASE_URI},{$filename},{$md5})", __FUNCTION__, __FILE__, __LINE__);
    $STATUS = unserialize(@file_get_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD"));
    $indexuri = "{$BASE_URI}/{$filename}";
    $unix = new unix();
    $q = new mysql_squid_builder();
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $ln = $unix->find_program("ln");
    $ufdbGenTable = $unix->find_program("ufdbGenTable");
    $Conversion = $q->TLSE_CONVERTION();
    $ufdb = new compile_ufdbguard();
    $curl = new ccurl($indexuri);
    $curl->Timeout = 360;
    echo "Downloading {$indexuri}\n";
    $cache_temp = "/tmp/{$filename}";
    if (!$curl->GetFile($cache_temp)) {
        build_progress("Fatal error downloading {$indexuri} {$curl->error}", $prc);
        echo "Fatal error downloading {$indexuri} {$curl->error}\n";
        $errorDetails = @implode("\n", $GLOBALS["CURLDEBUG"]);
        artica_update_event(0, "Web filtering databases, unable to download {$indexuri}", "Fatal error downloading {$indexuri} {$curl->error}\n{$errorDetails}", __FILE__, __LINE__);
        return;
    }
    $filesize = $unix->file_size($cache_temp);
    $GLOBALS["UFDB_SIZE"] = $GLOBALS["UFDB_SIZE"] + $filesize;
    @mkdir("/var/lib/ftpunivtlse1fr", 755, true);
    $categoryname = str_replace(".tar.gz", "", $filename);
    $categoryDISK = $categoryname;
    if (isset($Conversion[$categoryname])) {
        $categoryDISK = $Conversion[$categoryname];
    }
    $STATUS["LAST_DOWNLOAD"]["TIME"] = time();
    $STATUS["LAST_DOWNLOAD"]["CATEGORY"] = $categoryname;
    $STATUS["LAST_DOWNLOAD"]["SIZE"] = $GLOBALS["CURL_LAST_SIZE_DOWNLOAD"] / 1024;
    @file_put_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD", serialize($STATUS));
    $categoryDISK = str_replace("/", "_", $categoryDISK);
    if (is_link("/var/lib/ftpunivtlse1fr/{$categoryname}")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "/var/lib/ftpunivtlse1fr/{$categoryname} is a link of " . @readlink("/var/lib/ftpunivtlse1fr/{$categoryname}") . "\n";
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Removing  /var/lib/ftpunivtlse1fr/{$categoryname}/\n";
        }
        shell_exec("{$rm} -rf /var/lib/ftpunivtlse1fr/{$categoryname}");
    }
    if (is_dir("/var/lib/ftpunivtlse1fr/{$categoryname}")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Removing  /var/lib/ftpunivtlse1fr/{$categoryname}/\n";
        }
        shell_exec("{$rm} -rf /var/lib/ftpunivtlse1fr/{$categoryname}");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Creating  /var/lib/ftpunivtlse1fr/{$categoryname}/\n";
    }
    @mkdir("/var/lib/ftpunivtlse1fr/{$categoryname}", 0755, true);
    if ($GLOBALS["VERBOSE"]) {
        echo "Extracting {$cache_temp} to  /var/lib/ftpunivtlse1fr/\n";
    }
    shell_exec("{$tar} -xf {$cache_temp} -C /var/lib/ftpunivtlse1fr/");
    if (!is_file("/var/lib/ftpunivtlse1fr/{$categoryname}/domains")) {
        build_progress("Fatal!!: {$categoryname}/domains no such file", $prc);
        ufdbevents("Fatal!!: /var/lib/ftpunivtlse1fr/{$categoryname}/domains no such file", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $CountDeSitesFile = CountDeSitesFile("/var/lib/ftpunivtlse1fr/{$categoryname}/domains");
    if ($GLOBALS["VERBOSE"]) {
        echo "/var/lib/ftpunivtlse1fr/{$categoryname}/domains -> {$CountDeSitesFile} websites\n";
    }
    if ($CountDeSitesFile == 0) {
        build_progress("Fatal!!: {$categoryname}/domains corrupted, no website", $prc);
        ufdbevents("Fatal!!: /var/lib/ftpunivtlse1fr/{$categoryname}/domains corrupted, no website", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB");
        shell_exec("{$rm} -rf /var/lib/ftpunivtlse1fr/{$categoryname}");
        return;
    }
    if (trim(strtolower($categoryDISK)) != trim(strtolower($categoryname))) {
        if (is_dir("/var/lib/ftpunivtlse1fr/{$categoryDISK}")) {
            shell_exec("{$rm} -rf /var/lib/ftpunivtlse1fr/{$categoryDISK}");
        }
        shell_exec("ln -sf /var/lib/ftpunivtlse1fr/{$categoryDISK} /var/lib/ftpunivtlse1fr/{$categoryname}");
    }
    $q->QUERY_SQL("DELETE FROM ftpunivtlse1fr WHERE filename='{$filename}'");
    if (!$q->ok) {
        ufdbevents("Fatal!!: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB");
        return;
    }
    $q->QUERY_SQL("INSERT INTO ftpunivtlse1fr (`filename`,`zmd5`,`websitesnum`) VALUES ('{$filename}','{$md5}','{$CountDeSitesFile}')");
    if (!$q->ok) {
        ufdbevents("Fatal!!: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB");
        return;
    }
    $GLOBALS["UFDB_COUNT_OF_DOWNLOADED"] = $GLOBALS["UFDB_COUNT_OF_DOWNLOADED"] + 1;
    build_progress("{$categoryname} {$CountDeSitesFile} websites", $prc);
    $GLOBALS["squid_admin_mysql"][] = "Success updating category `{$categoryname}` with {$CountDeSitesFile} websites";
    if ($GLOBALS["VERBOSE"]) {
        echo "ufdbGenTable={$ufdbGenTable}\n";
    }
    if (is_file($ufdbGenTable)) {
        $t = time();
        ufdbevents("Compiling /var/lib/ftpunivtlse1fr/{$categoryname}");
        build_progress("{$categoryname} Compiling....", $prc);
        $ufdb->UfdbGenTable("/var/lib/ftpunivtlse1fr/{$categoryname}", $categoryname);
    }
}
Beispiel #29
0
function latests()
{
    $unix = new unix();
    $curl = new ccurl("http://www.squid-cache.org/Versions/v3/3.2/");
    if (!$curl->GetFile("/tmp/index.html")) {
        echo "{$curl->error}\n";
        return 0;
    }
    $f = explode("\n", @file_get_contents("/tmp/index.html"));
    while (list($num, $line) = each($f)) {
        if (preg_match("#<a href=\"squid-(.+?)\\.tar\\.gz#", $line, $re)) {
            $ve = $re[1];
            $STT = explode(".", $ve);
            $CountDeSTT = count($STT);
            if ($CountDeSTT < 4) {
                $ve = "{$ve}.00";
            }
            $veOrg = $ve;
            $ve = str_replace(".", "", $ve);
            $ve = str_replace("-", "", $ve);
            if ($GLOBALS["VERBOSE"]) {
                echo "Add version {$veOrg} -> `{$ve}`\n";
            }
            $file = "squid-{$re[1]}.tar.gz";
            $versions[$ve] = $file;
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ve} -> {$file} {$CountDeSTT} points\n";
            }
        } else {
        }
    }
    krsort($versions);
    while (list($num, $filename) = each($versions)) {
        $vv[] = $filename;
    }
    echo "Found latest file version: `{$vv[0]}`\n";
    return $vv[0];
}
function categorize_delete()
{
    $unix = new unix();
    $URIBASE = $unix->MAIN_URI();
    $tmpdir = $unix->TEMP_DIR();
    if (!is_file("{$tmpdir}/categorize_delete.sql")) {
        $curl = new ccurl("{$URIBASE}/blacklist/categorize_delete.gz");
        if (!$curl->GetFile("{$tmpdir}/categorize_delete.gz")) {
            // ufdbguard_admin_events("Fatal: unable to download categorize_delete.gz file $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
            return;
        }
        if (!extractGZ("{$tmpdir}/categorize_delete.gz", "{$tmpdir}/categorize_delete.sql")) {
            // ufdbguard_admin_events("Fatal: unable to extract $tmpdir/categorize_delete.gz",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
            return;
        }
    }
    $q = new mysql_squid_builder();
    $datas = explode("\n", @file_get_contents("{$tmpdir}/categorize_delete.sql"));
    while (list($index, $row) = each($datas)) {
        if (trim($row) == null) {
            continue;
        }
        $ligne = unserialize($row);
        $category = $ligne["category"];
        $pattern = $ligne["sitename"];
        $tablename = "category_" . $q->category_transform_name($category);
        if (!$q->TABLE_EXISTS($tablename)) {
            $q->CreateCategoryTable($category);
        }
        $q->QUERY_SQL("UPDATE {$tablename} SET enabled=0 WHERE `pattern`='{$pattern}'");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
    // ufdbguard_admin_events("Success updating deleted ". count($datas)." websites from categories",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
    @unlink("{$tmpdir}/categorize_delete.sql");
}