Beispiel #1
0
function databases_items()
{
    include_once "ressources/class.dansguardian.inc";
    $sock = new sockets();
    $dataZ = unserialize(base64_decode($sock->getFrameWork("ufdbguard.php?used-db=yes")));
    if (!is_array($dataZ)) {
        $dataZ = array();
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = count($data);
    $data['rows'] = array();
    $ProductName = "Artica";
    $ProductNamef = dirname(__FILE__) . "/ressources/templates/{$_COOKIE["artica-template"]}/ProducName.conf";
    if (is_file($ProductNamef)) {
        $ProductName = trim(@file_get_contents($ProductNamef));
    }
    $dans = new dansguardian_rules();
    $DBZ["ART"] = "{$ProductName} Database";
    $DBZ["UNIV"] = "Toulouse University";
    $DBZ["PERS"] = "Personal Database";
    if (count($dataZ) == 0) {
        json_error_show("no data", 1);
    }
    $fontsize = "22";
    $q = new mysql_squid_builder();
    while (list($num, $DB) = each($dataZ)) {
        $color = "black";
        $dbname = $DBZ[$DB["DB"]];
        $size = $DB["SIZE"];
        if ($size < 120) {
            $color = "#AFAFAF";
        }
        $size = FormatBytes($size / 1024);
        $category = $q->filaname_tocat($DB["DIR"]);
        $pic = $dans->array_pics[$category];
        if ($pic == null) {
            $pic = "20-categories-personnal.png";
        }
        $data['rows'][] = array('id' => md5(serialize($DB)), 'cell' => array("<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'><img src='img/{$pic}'></span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$category}</span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$dbname}</a></span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$size}</span>"));
    }
    echo json_encode($data);
}
function scan_artica_databases()
{
    $unix = new unix();
    $URIBASE = $unix->MAIN_URI();
    $tmpdir = $unix->TEMP_DIR();
    $curl = new ccurl("{$URIBASE}/catz/index.txt");
    if (!$curl->GetFile("{$tmpdir}/index.txt")) {
        squid_admin_mysql(0, "BLACKLISTS: Failed to retreive {$URIBASE}/catz/index.txt ", $curl->error, __FUNCTION__, __LINE__);
        artica_update_event(0, "BLACKLISTS: Failed to retreive {$URIBASE}/catz/index.txt ", $curl->error, __FUNCTION__, __LINE__);
        echo "BLACKLISTS: Failed to retreive {$URIBASE}/catz/index.txt ({$curl->error})\n";
        return;
    }
    $fIndex = unserialize(base64_decode(@file_get_contents("{$tmpdir}/index.txt")));
    //print_r($fIndex);
    $time = $fIndex["TIME"];
    $q = new mysql_squid_builder();
    //webfilters_databases_disk
    $prefix = "INSERT IGNORE INTO webfilters_databases_disk (`filename`,`size`,`category`,`filtime`) VALUES ";
    $unix = new unix();
    $dirs = $unix->dirdir($GLOBALS["WORKDIR_LOCAL"]);
    if ($GLOBALS["VERBOSE"]) {
        echo "Scanning " . count($dirs) . " files last pattern was " . date("Y-m-d H:i:s", $time) . "\n";
    }
    $sizz = 0;
    while (list($path, $path2) = each($dirs)) {
        $size = $unix->file_size("{$path2}/domains.ufdb");
        $category = basename($path);
        $sizz = $sizz + $size;
        if ($GLOBALS["VERBOSE"]) {
            echo "{$category} `{$path2}/domains.ufdb` = " . $size / 1024 . " Kb\n";
        }
        $category = $q->filaname_tocat("{$path2}/domains.ufdb");
        $filtime = filemtime("{$path2}/domains.ufdb");
        $f[] = "('{$path2}/domains.ufdb','{$size}','{$category}','{$filtime}')";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "scanned " . count($f) . " files\n";
    }
    if (count($f) > 0) {
        $sql = $prefix . @implode(",", $f);
        if (!$q->TABLE_EXISTS("webfilters_databases_disk")) {
            $q->CheckTables();
        }
        $q->QUERY_SQL("TRUNCATE TABLE webfilters_databases_disk");
        $q->CheckTables();
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            squid_admin_mysql(0, "{$q->mysql_error}", null, __FUNCTION__, __LINE__);
            artica_update_event(0, "{$q->mysql_error}", null, __FUNCTION__, __LINE__);
        }
    }
}
Beispiel #3
0
function DisksStatus($aspid = false)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if (!$aspid) {
        $pid = @file_get_contents("{$pidfile}");
        if ($unix->process_exists($pid, basename(__FILE__))) {
            return;
        }
        $pidTime = $unix->file_time_min($pidTime);
        if ($pidTime < 5) {
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, getmypid());
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded()) {
        $php5 = $unix->LOCATE_PHP5_BIN();
        $unix->THREAD_COMMAND_SET("{$php5} " . __FILE__ . " --disks");
        return;
    }
    $q = new mysql_squid_builder();
    if (!$q->TABLE_EXISTS('webfilters_dbstats')) {
        $sql = "CREATE TABLE IF NOT EXISTS `webfilters_dbstats` (\n\t\t\t\t  `category` varchar(128) NOT NULL PRIMARY KEY,\n\t\t\t\t  `articasize` BIGINT UNSIGNED NOT NULL,\n\t\t\t\t  `unitoulouse` BIGINT UNSIGNED NOT NULL,\n\t\t\t\t  `persosize` BIGINT UNSIGNED  NOT NULL,\n\t\t\t\t  KEY `articasize` (`articasize`),KEY `unitoulouse` (`unitoulouse`), KEY `persosize` (`persosize`) )  ENGINE = MYISAM;";
        $q->QUERY_SQL($sql);
    }
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        echo "-> /var/lib/ftpunivtlse1fr\n";
    }
    $dirs = $unix->dirdir("/var/lib/ftpunivtlse1fr");
    while (list($a, $dir) = each($dirs)) {
        if (!is_file("{$dir}/domains.ufdb")) {
            continue;
        }
        $size = filesize("{$dir}/domains.ufdb");
        $category = basename($dir);
        $category = $q->filaname_tocat($category);
        $array[$category]["UNIV"] = $size;
    }
    $dirs = $unix->dirdir("/var/lib/squidguard");
    while (list($a, $dir) = each($dirs)) {
        if (!is_file("{$dir}/domains.ufdb")) {
            continue;
        }
        $size = filesize("{$dir}/domains.ufdb");
        $category = basename($dir);
        $category = $q->filaname_tocat($category);
        $array[$category]["PERSO"] = $size;
    }
    $dirs = $unix->dirdir("/var/lib/ufdbartica");
    while (list($a, $dir) = each($dirs)) {
        if (!is_file("{$dir}/domains.ufdb")) {
            continue;
        }
        $size = filesize("{$dir}/domains.ufdb");
        $category = basename($dir);
        $category = $q->filaname_tocat($category);
        $array[$category]["ARTICA"] = $size;
    }
    while (list($category, $sizes) = each($array)) {
        if (!isset($sizes["UNIV"])) {
            $sizes["UNIV"] = 0;
        }
        if (!isset($sizes["ARTICA"])) {
            $sizes["ARTICA"] = 0;
        }
        if (!isset($sizes["PERSO"])) {
            $sizes["PERSO"] = 0;
        }
        $f[] = "('{$category}','{$sizes["ARTICA"]}','{$sizes["UNIV"]}','{$sizes["PERSO"]}')";
    }
    if (count($f) > 0) {
        $q->QUERY_SQL("TRUNCATE TABLE webfilters_dbstats");
        $q->QUERY_SQL("INSERT IGNORE INTO webfilters_dbstats (category,articasize,unitoulouse,persosize) VALUES " . @implode(",", $f));
    }
}
function xstart()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $timefile = "/etc/artica-postfix/pids/exec.ufdb.parse-categories.php.time";
    $unix = new unix();
    $me = basename(__FILE__);
    $pid = $unix->get_pid_from_file($pidfile);
    if (system_is_overloaded()) {
        die;
    }
    if ($unix->process_exists($pid, $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " {$pid} --> Already executed.. aborting the process\n";
        }
        $time = $unix->PROCCESS_TIME_MIN($pid);
        die;
    }
    @file_put_contents($pidfile, getmypid());
    if ($unix->file_time_min($timefile) < 60) {
        return;
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $q = new mysql_squid_builder();
    $DirsArtica = $unix->dirdir("/var/lib/ufdbartica");
    $sql = "CREATE TABLE IF NOT EXISTS `UPDATE_DBWF_INFOS` ( \n\t`category` varchar(90) NOT NULL, `size_artica` INT UNSIGNED NOT NULL, `date_artica` INT UNSIGNED NOT NULL, `count_artica` INT UNSIGNED NOT NULL, `size_tlse` INT UNSIGNED NOT NULL, `date_tlse` INT UNSIGNED NOT NULL, `count_tlse` INT UNSIGNED NOT NULL, `size_perso` INT UNSIGNED NOT NULL, `date_perso` INT UNSIGNED NOT NULL, `count_perso` INT UNSIGNED NOT NULL, PRIMARY KEY (`category`) \n\t\t\t) ENGINE=MYISAM;";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $MAX = 144;
    $c = 0;
    $UFDB = array();
    $UFDBCOUNT = unserialize(base64_decode(@file_get_contents("/etc/artica-postfix/ufdbcounts.txt")));
    while (list($dir, $line) = each($DirsArtica)) {
        if (is_link($dir)) {
            continue;
        }
        $database_path = "{$dir}/domains.ufdb";
        if (!is_file($database_path)) {
            continue;
        }
        $tablename = basename($dir);
        $size = @filesize("{$dir}/domains.ufdb");
        $time = filemtime("{$dir}/domains.ufdb");
        $cat = $q->tablename_tocat($tablename);
        $MAIN[$cat]["ART"]["SIZE"] = $size;
        $MAIN[$cat]["ART"]["TIME"] = $time;
        $MAIN[$cat]["ART"]["COUNT"] = $UFDBCOUNT[$tablename];
    }
    $DirsArtica = $unix->dirdir("/var/lib/ftpunivtlse1fr");
    while (list($dir, $line) = each($DirsArtica)) {
        $database_path = "{$dir}/domains.ufdb";
        $sourcefile = "{$dir}/domains";
        if (!is_file($database_path)) {
            continue;
        }
        $cat = basename($dir);
        $cat = $q->filaname_tocat($cat);
        $size = @filesize("{$dir}/domains.ufdb");
        $time = filemtime("{$dir}/domains.ufdb");
        $MAIN[$cat]["TLSE"]["SIZE"] = $size;
        $MAIN[$cat]["TLSE"]["TIME"] = $time;
        $MAIN[$cat]["TLSE"]["COUNT"] = $unix->COUNT_LINES_OF_FILE($sourcefile);
        if (system_is_overloaded()) {
            @unlink("{$timefile}");
            die;
        }
    }
    $DirsArtica = $unix->dirdir("/var/lib/squidguard");
    while (list($dir, $line) = each($DirsArtica)) {
        $database_path = "{$dir}/domains.ufdb";
        if (!is_file($database_path)) {
            continue;
        }
        $tablename = "category_" . basename($dir);
        $cat = $q->tablename_tocat($tablename);
        $size = @filesize("{$dir}/domains.ufdb");
        $time = filemtime("{$dir}/domains.ufdb");
        $sourcefile = "{$dir}/domains";
        $MAIN[$cat]["PERSO"]["SIZE"] = $size;
        $MAIN[$cat]["PERSO"]["PATH"] = $dir;
        $MAIN[$cat]["PERSO"]["CATEGORY"] = $cat;
        $MAIN[$cat]["PERSO"]["TIME"] = $time;
        $MAIN[$cat]["PERSO"]["COUNT"] = $unix->COUNT_LINES_OF_FILE($sourcefile);
        if (system_is_overloaded()) {
            @unlink("{$timefile}");
            die;
        }
    }
    $prefix = "INSERT IGNORE INTO `UPDATE_DBWF_INFOS` (`category`,\n\t`size_artica` ,\n\t`date_artica` ,\n\t`count_artica` ,\n\n\t`size_tlse` ,\n\t`date_tlse` ,\n\t`count_tlse` ,\t\t\t\n\t\t\t\n\t`size_perso` ,\n\t`date_perso` ,\n\t`count_perso`) VALUES ";
    while (list($category, $MAINZ) = each($MAIN)) {
        $f[] = "('{$category}','{$MAINZ["ART"]["SIZE"]}','{$MAINZ["ART"]["TIME"]}','{$MAINZ["ART"]["COUNT"]}','{$MAINZ["TLSE"]["SIZE"]}','{$MAINZ["TLSE"]["TIME"]}','{$MAINZ["TLSE"]["COUNT"]}','{$MAINZ["PERSO"]["SIZE"]}','{$MAINZ["PERSO"]["TIME"]}','{$MAINZ["PERSO"]["COUNT"]}')";
    }
    $q->QUERY_SQL("TRUNCATE TABLE `UPDATE_DBWF_INFOS`");
    $sql = $prefix . @implode(",", $f);
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n{$sql}\n";
        return;
    }
}