function updatev2()
{
    $sock = new sockets();
    $unix = new unix();
    $GLOBALS["TEMP_PATH"] = $unix->TEMP_DIR();
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $ArticaDbReplicate = $sock->GET_INFO("ArticaDbReplicate");
    $CategoriesDatabasesByCron = $sock->GET_INFO("CategoriesDatabaseByCron");
    if (!is_numeric($CategoriesDatabasesByCron)) {
        $CategoriesDatabasesByCron = 1;
    }
    $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics");
    $ArticaDBPath = $sock->GET_INFO("ArticaDBPath");
    if ($ArticaDBPath == null) {
        $ArticaDBPath = "/opt/articatech";
    }
    $ManualArticaDBPath = $sock->GET_INFO("ManualArticaDBPath");
    if ($ManualArticaDBPath == null) {
        $ManualArticaDBPath = "/home/manualupdate/articadb.tar.gz";
    }
    $ManualArticaDBPathNAS = $sock->GET_INFO("ManualArticaDBPathNAS");
    $datas = unserialize(base64_decode($sock->GET_INFO("ufdbguardConfig")));
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    if (!is_numeric($ManualArticaDBPathNAS)) {
        $ManualArticaDBPathNAS = 0;
    }
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    if (!is_numeric($ArticaDbReplicate)) {
        $ArticaDbReplicate = 0;
    }
    $WizardStatsAppliance = unserialize(base64_decode($sock->GET_INFO("WizardStatsAppliance")));
    if (!isset($WizardStatsAppliance["SERVER"])) {
        $WizardStatsAppliance["SERVER"] = null;
    }
    if ($DisableArticaProxyStatistics == 1) {
        updatev2_progress(110, "Error: Artica statistics are disabled");
    }
    if ($datas["UseRemoteUfdbguardService"] == 1) {
        updatev2_progress(110, "Error: - UseRemoteUfdbguardService -  Only used by {$WizardStatsAppliance["SERVER"]}");
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($CategoriesDatabasesByCron == 1) {
            if (!$GLOBALS["BYCRON"]) {
                updatev2_progress(110, "Error: Only executed by schedule...");
                return;
            }
        }
    }
    if ($GLOBALS["FORCE"]) {
        ufdbevents("***** Force enabled ***** ");
        ufdbevents("*****");
        ufdbevents("*****");
        ufdbevents("Executed as {$GLOBALS["CMDLINE"]}");
        ufdbevents("*****");
        ufdbevents("*****");
    }
    if (!$GLOBALS["CHECKTIME"]) {
        ufdbevents("***** CHECKTIME disabled ***** ");
    }
    $CHECKTIME = $unix->file_time_min($timeFile);
    ufdbevents(" **");
    ufdbevents(" **");
    ufdbevents("{$timeFile} = {$CHECKTIME}Mn");
    ufdbevents(" **");
    ufdbevents(" **");
    if (!$GLOBALS["FORCE"]) {
        if ($CHECKTIME < 240) {
            updatev2_progress(110, "STOP: current {$CHECKTIME}Mn, require 240mn");
            return;
        }
    }
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, __FILE__)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time < 10200) {
            updatev2_progress(110, "Error: already running pid {$pid} since {$time}Mn");
            return;
        } else {
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
            if ($GLOBALS["SCHEDULE_ID"] > 0) {
                artica_update_event(1, "Warning: Old task pid {$pid} since {$time}Mn has been killed, (reach 7200mn)", null, __FILE__, __LINE__);
            }
        }
    }
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    ufdbevents("Stamp {$timeFile}");
    @unlink($timeFile);
    $tlse_force_token = null;
    @file_put_contents($timeFile, time());
    @file_put_contents($pidfile, getmypid());
    $tlse_token = null;
    if ($GLOBALS["BYCRON"]) {
        $tlse_token == " --bycron --force";
    }
    if ($GLOBALS["FORCE"]) {
        $tlse_force_token = " --force";
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    ufdbevents("Running  exec.update.squid.tlse.php");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.update.squid.tlse.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}{$tlse_force_token}{$tlse_token} >/dev/null 2>&1 &");
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    updatev2_checkversion();
    updatev2_progress(12, "{runing} [" . __LINE__ . "]");
    ufdbtables(true);
    C_ICAP_TABLES(true);
    schedulemaintenance();
    EXECUTE_BLACK_INSTANCE();
}
function updatev2_adblock()
{
    return;
    if (isset($GLOBALS[__FUNCTION__])) {
        return;
    }
    $GLOBALS[__FUNCTION__] = true;
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $main_artica_path = $GLOBALS["WORKDIR_LOCAL"];
    $unix = new unix();
    $users = new usersMenus();
    if (!$users->CORP_LICENSE) {
        if ($GLOBALS["VERBOSE"]) {
            echo "License error...\n";
        }
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        $TimeMn = $unix->file_time_min($timeFile);
        if ($TimeMn < 60) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$TimeMn}Mn require 60mn minimal (use --force if necessary)\n";
            }
            return;
        }
    }
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    updatev2_checkversion();
    $reload = false;
    $trackergzip = "{$main_artica_path}/category_tracker/tracker_expressions.gz";
    $trackerfinal = "{$main_artica_path}/category_tracker/expressions";
    $malwaregzip = "{$main_artica_path}/category_malware/categoryuris_malware.gz";
    $malwarecsv = "{$main_artica_path}/category_malware/categoryuris_malware.csv";
    $pubgzip = "{$main_artica_path}/category_publicite/publicite_expressions.gz";
    $pubfinal = "{$main_artica_path}/category_publicite/expressions";
    $phishgzip = "{$main_artica_path}/category_phishing/categoryuris_phishing.gz";
    $phishcsv = "{$main_artica_path}/category_phishing/categoryuris_phishing.csv";
    if ($GLOBALS["MIRROR"] == null) {
        return;
    }
    @unlink("{$pubgzip}");
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/publicite_expressions.gz");
    if (!$curl->GetFile($pubgzip)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pubgzip} failed to download {$curl->error}\n";
        }
        // ufdbguard_admin_events("UFDB::Fatal: $pubgzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        @unlink("{$pubgzip}");
    }
    @unlink($trackergzip);
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/tracker_expressions.gz");
    if (!$curl->GetFile($trackergzip)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$trackergzip} failed to download {$curl->error}\n";
        }
        // ufdbguard_admin_events("UFDB::Fatal: $trackergzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        @unlink($trackergzip);
    }
    @unlink($malwaregzip);
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/categoryuris_malware.gz");
    if (!$curl->GetFile($malwaregzip)) {
        // ufdbguard_admin_events("UFDB::Fatal: $malwaregzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        if ($GLOBALS["VERBOSE"]) {
            echo "{$malwaregzip} failed to download {$curl->error}\n";
        }
        @unlink($malwaregzip);
    }
    @unlink($phishgzip);
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/categoryuris_phishing.gz");
    if (!$curl->GetFile($phishgzip)) {
        // ufdbguard_admin_events("UFDB::Fatal: $phishgzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        if ($GLOBALS["VERBOSE"]) {
            echo "{$phishgzip} failed to download {$curl->error}\n";
        }
        @unlink($phishgzip);
    }
    $mdfile1 = md5_file($pubfinal);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pubfinal}({$mdfile1})\n";
    }
    if (is_file($pubgzip)) {
        $unix->uncompress($pubgzip, $pubfinal);
        $mdfile2 = md5_file($pubfinal);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pubfinal}({$mdfile2})\n";
        }
        if ($mdfile2 != $mdfile1) {
            $reload = true;
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pubgzip} no such file\n";
        }
    }
    $mdfile1 = md5_file($trackerfinal);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$trackerfinal} -1- ({$mdfile1})\n";
    }
    if (is_file($trackergzip)) {
        $unix->uncompress($trackergzip, $trackerfinal);
        $mdfile2 = md5_file($trackerfinal);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$trackerfinal} -2- ({$mdfile2})\n";
        }
        if ($mdfile1 != $mdfile2) {
            $reload = true;
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$trackergzip} no such file\n";
        }
    }
    if (is_file($malwaregzip)) {
        $uris = array();
        $q = new mysql_squid_builder();
        $unix->uncompress($malwaregzip, $malwarecsv);
        $handle = @fopen($malwarecsv, "r");
        $q->CreateCategoryUrisTable("malware");
        if ($handle) {
            $line = @fgets($handle);
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            $md5 = md5($line);
            $date = date("Y-m-d H:i:s");
            $url = mysql_escape_string2($line);
            $uris[] = "('{$md5}','{$date}','{$url}',1)";
        }
        if (count($uris) > 0) {
            $sql = "INSERT IGNORE INTO categoryuris_malware\n\t\t\t(zmd5,zDate,pattern,enabled) VALUES " . @implode(",", $uris);
            $q->QUERY_SQL($sql);
        }
    }
    if (is_file($phishgzip)) {
        $uris = array();
        $q = new mysql_squid_builder();
        $unix->uncompress($phishgzip, $phishcsv);
        $handle = @fopen($phishcsv, "r");
        $q->CreateCategoryUrisTable("phishing");
        if ($handle) {
            $line = @fgets($handle);
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            $md5 = md5($line);
            $date = date("Y-m-d H:i:s");
            $url = mysql_escape_string2($line);
            $uris[] = "('{$md5}','{$date}','{$url}',1)";
        }
        if (count($uris) > 0) {
            $sql = "INSERT IGNORE INTO categoryuris_phishing\n\t\t\t(zmd5,zDate,pattern,enabled) VALUES " . @implode(",", $uris);
            $q->QUERY_SQL($sql);
        }
    }
    if ($reload) {
        squid_admin_mysql(2, "Ask to reload the Web filtering service", "");
        shell_exec("/etc/init.d/ufdb reload");
    }
}