Exemple #1
0
function build()
{
    $unix = new unix();
    $q = new mysql();
    $sql = "SELECT COUNT(*) as tcount FROM httrack_sites WHERE enabled=1";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        build_progress_build("MySQL {failed}!", 110);
        return;
    }
    $Tcount = intval($ligne["tcount"]);
    $HTTrackInSquid = 0;
    if ($Tcount > 0) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/HTTrackInSquid", 1);
        $HTTrackInSquid = 1;
    } else {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/HTTrackInSquid", 0);
        $HTTrackInSquid = 0;
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        if ($HTTrackInSquid == 1) {
            build_progress("{enabled}", 10);
            if (!build_IsInSquid()) {
                build_ufdb();
            }
            if (!build_IsInSquid()) {
                build_progress_build("{building} {failed} build_IsInSquid!", 110);
                return;
            }
        } else {
            build_progress("{disabled}", 10);
        }
    }
    $MAIN = array();
    build_apache_OFF();
    $sql = "SELECT * FROM httrack_sites WHERE enabled=1";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = mysql_fetch_assoc($results)) {
        $ID = $ligne["ID"];
        $path = null;
        $dir = $ligne["workingdir"];
        build_apache_ON($ID, $dir);
        $sitename = $ligne["sitename"];
        build_progress("{building} {$sitename}", 22);
        $uri = parse_url($sitename);
        $host = $uri["host"];
        $srhost = $host;
        if (isset($uri["path"])) {
            $path = $uri["path"];
            $path = str_replace("/", "\\/", $path);
            $path = str_replace(".", "\\.", $path);
        }
        $host = str_replace(".", "\\.", $host);
        $MAIN["{$host}{$path}"] = "HTTrack{$ID}/{$srhost}";
    }
    @file_put_contents("/etc/squid3/HTTrack.db", serialize($MAIN));
    @chown("/etc/squid3/HTTrack.db", "squid");
    @chmod("/etc/artica-postfix/settings/Daemons/HTTrackInSquid", 0755);
    build_progress("{building} {restarting} {webservice}", 50);
    system("/etc/init.d/apache2 restart");
    if (is_file($squidbin)) {
        system("{$squidbin} -k reconfigure");
    }
    if ($HTTrackInSquid == 0) {
        build_progress("{building} {restarting} {webservice} {done} - DISABLED - {$Tcount} {websites}", 110);
        return;
    }
    build_progress("{building} {restarting} {webservice} {done}", 100);
}
function build_apache_OFF()
{
    if (!is_file("/etc/apache2/conf.d/WindowsUpdate")) {
        return;
    }
    @unlink("/etc/apache2/conf.d/WindowsUpdate");
    build_progress_build("{building} {restarting} {webservice}", 22);
    system("/etc/init.d/apache2 restart");
    build_progress_build("{building} {restarting} {webservice} {done}", 24);
}