function install_key($keyfile)
{
    $path = "/usr/share/artica-postfix/ressources/conf/upload/{$keyfile}";
    $license_bin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager";
    $time = time();
    $unix = new unix();
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) {
            progress("{failed} Already running", 110);
            echo "Already runinng PID {$pid}\n";
            return;
        }
    }
    echo "License....: {$path}\n";
    echo "Binary File: {$license_bin}\n";
    if (!is_file($path)) {
        echo "{$path} No such file..\n";
        progress("{failed} {$keyfile} No such file", 110);
        die;
    }
    if (!is_file($license_bin)) {
        echo "{$path} No such file..\n";
        progress("{failed} " . basename($license_bin) . " No such binary", 110);
        @unlink($path);
        die;
    }
    $sock = new sockets();
    $nohup = $unix->find_program("nohup");
    $sock->SET_INFO("kavicapserverEnabled", 1);
    @unlink("/etc/artica-postfix/kav4proxy-licensemanager");
    @unlink("/etc/artica-postfix/kav4proxy-licensemanager-i");
    progress("{removing_old_licenses}", 20);
    system("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -d a");
    progress("{installing} {$keyfile}", 30);
    $cmd = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -c /etc/opt/kaspersky/kav4proxy.conf -a {$path}";
    system($cmd);
    @unlink($path);
    progress("{analyze_license} {$keyfile}", 50);
    shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i 2>&1");
    progress("{stopping_service}", 60);
    echo "/etc/init.d/kav4proxy stop\n";
    system("/etc/init.d/kav4proxy stop");
    progress("{starting_service}", 60);
    echo "/etc/init.d/kav4proxy start\n";
    system("{$nohup} /etc/init.d/kav4proxy start >/dev/null 2>&1 &");
    system("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    progress("{launch_updates}", 70);
    $nohup = $unix->find_program("nohup");
    $php = $unix - LOCATE_PHP5_BIN();
    sleep(2);
    progress("{launch_updates}", 80);
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.keepup2date.php --update --force >/dev/null 2>&1 &");
    sleep(3);
    progress("{success}", 100);
}
function disconnect()
{
    $unix = new unix();
    $sock = new sockets();
    progress("Unmout Stastistics Appliance", 20);
    $php = $unix->LOCATE_PHP5_BIN();
    $sock->SET_INFO("EnableSquidRemoteMySQL", 0);
    $sock->SET_INFO("EnableRemoteSyslogStatsAppliance", 0);
    $sock->SET_INFO("RemoteStatisticsApplianceSettings", base64_encode(serialize(array())));
    $sock->SET_INFO("WizardStatsAppliance", base64_encode(serialize(array())));
    $sock->SET_INFO("UseRemoteUfdbguardService", 0);
    progress("{reconfiguring} Proxy service", 30);
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    progress("{reconfiguring} Web filtering service", 40);
    system("{$php} /usr/share/artica-postfix/exec.squidguard.php --build --force");
    progress("{restarting} Service status", 50);
    system("/etc/init.d/artica-status restart --force");
    progress("{reconfiguring} {tasks}", 60);
    system("{$php} /usr/share/artica-postfix/exec.schedules.php");
    progress("{done}", 100);
}
Пример #3
0
function install()
{
    $filename = "kav4proxy_5.5-88.tar.gz";
    $uri = "http://articatech.net/download/kaspersky/{$filename}";
    $time = time();
    $unix = new unix();
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) {
            return;
        }
    }
    $cacheFile = "/usr/share/artica-postfix/ressources/logs/web/KAV4PROXYINST.status";
    @unlink($cacheFile);
    $rm = $unix->find_program("rm");
    $cp = $unix->find_program("cp");
    $TMPDIR = $unix->TEMP_DIR() . "/{$time}";
    $FINAL_TARGET_DIR = null;
    $TARGET_PATH = "{$TMPDIR}/{$filename}";
    progress("{downloading} 5.5.88 version", "Downloading {$filename}", 30);
    progress("{downloading} 5.5.88 version", "Temporary directory = {$TMPDIR}", 30);
    $curl = new ccurl("{$uri}");
    $debianbin = $unix->find_program("update-rc.d");
    $redhatbin = $unix->find_program("chkconfig");
    @mkdir($TMPDIR);
    if (!$curl->GetFile($TARGET_PATH)) {
        progress("{failed}", $curl->error, 100);
        shell_exec("{$rm} -rf {$TMPDIR}");
        return;
    }
    progress("{downloading} 5.5.88 version {success}", "success saving {$TARGET_PATH} ", 50);
    progress("{extracting} 5.5.88 version", "Extracting {$TARGET_PATH} ", 55);
    $tar = $unix->find_program("tar");
    exec("{$tar} xvf {$TARGET_PATH} -C /{$TMPDIR}/ 2>&1", $results);
    while (list($index, $line) = each($results)) {
        progress("{extracting} 5.5.88 version", $line, 60);
    }
    $dir = $unix->dirdir($TMPDIR);
    while (list($index, $line) = each($dir)) {
        progress("{search} {directory}", $line, 65);
        if (preg_match("#kav4proxy#", $line)) {
            progress("{search} {directory}", "Found directory {$line}", 65);
            $FINAL_TARGET_DIR = $line;
            break;
        }
    }
    if ($FINAL_TARGET_DIR == null) {
        progress("{extracting} 5.5.88 version {failed}", "Unable to find a suitable directory", 100);
        shell_exec("{$rm} -rf {$TMPDIR}");
        return;
    }
    progress("{installing} 5.5.88 version", "Copy the content of {$FINAL_TARGET_DIR}", 70);
    exec("{$cp} -rfdv  {$FINAL_TARGET_DIR}/* / 2>&1", $resultsA);
    while (list($index, $line) = each($resultsA)) {
        progress("{installing} 5.5.88 version", $line, 70);
    }
    progress("{installing} 5.5.88 version", "Removing the {$TMPDIR} directory", 71);
    shell_exec("{$rm} -rf {$TMPDIR}");
    if (!is_file("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager")) {
        progress("{installing} 5.5.88 version {failed}", "install from {$FINAL_TARGET_DIR} failed ", 100);
        return;
    }
    $ln = $unix->find_program("ln");
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    progress("{installing} 5.5.88 version", "linking /etc/init.d/kav4proxy", 75);
    shell_exec("ln -s --force /opt/kaspersky/kav4proxy/lib/bin/kav4proxy /etc/init.d/kav4proxy");
    if (is_file($debianbin)) {
        shell_exec("{$debianbin} -f kav4proxy defaults >/dev/null 2>&1");
    }
    if (is_file($redhatbin)) {
        shell_exec("{$redhatbin} --add kav4proxy >/dev/null 2>&1");
    }
    progress("{installing} 5.5.88 version", "executing preinstall", 78);
    exec('/usr/share/artica-postfix/bin/install/kavgroup/kav4prox_predoinst.sh 2>&1', $results2);
    while (list($index, $line) = each($results2)) {
        progress("{installing} 5.5.88 version", $line, 78);
    }
    progress("{installing} 5.5.88 version", "Creating kluser user", 80);
    $unix->CreateUnixUser("kluser", "klusers");
    progress("{installing} 5.5.88 version", "Apply permissions", 85);
    @mkdir("/var/log/kaspersky/kav4proxy", 0755, true);
    @mkdir("/var/run/kav4proxy", 0755, true);
    shell_exec("{$chown} -R kluser:klusers /var/log/kaspersky/kav4proxy");
    shell_exec("{$chown} -R kluser:klusers /var/opt/kaspersky/kav4proxy");
    shell_exec("{$chown} -R kluser:klusers /var/run/kav4proxy");
    shell_exec("{$chown} -R kluser:klusers /var/opt/kaspersky/kav4proxy");
    shell_exec("{$chmod} 0755 /var/opt/kaspersky/kav4proxy");
    $f[] = "EULA_AGREED=yes";
    $f[] = "";
    @file_put_contents("/var/opt/kaspersky/kav4proxy/installer.dat", @implode("\n", $f));
    $f = array();
    $f[] = "CONFIGURE_ENTER_KEY_PATH=";
    $f[] = "KAVMS_SETUP_LICENSE_DOMAINS=*";
    $f[] = "CONFIGURE_KEEPUP2DATE_ASKPROXY=no";
    $f[] = "CONFIGURE_RUN_KEEPUP2DATE=no";
    $f[] = "CONFIGURE_WEBMIN_ASKCFGPATH=";
    $f[] = "KAV4PROXY_SETUP_TYPE=3";
    $f[] = "KAV4PROXY_SETUP_LISTENADDRESS=127.0.0.1:1344";
    $f[] = "KAV4PROXY_SETUP_CONFPATH=/etc/squid3/squid.conf";
    $f[] = "KAV4PROXY_SETUP_BINPATH=" . $unix->LOCATE_SQUID_BIN();
    $f[] = "KAV4PROXY_CONFIRM_FOUND=Y";
    $f[] = "KAVICAP_SETUP_NONICAPCFG=Y";
    @file_put_contents("/opt/kaspersky/kav4proxy/lib/bin/setup/autoanswers.conf", @implode("\n", $f));
    chdir('/opt/kaspersky/kav4proxy/lib/bin/setup');
    exec('./postinstall.pl 2>&1', $results3);
    while (list($index, $line) = each($results3)) {
        progress("{installing} 5.5.88 version", $line, 90);
    }
    shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time() . " >/dev/null 2>&1");
    shell_exec("/etc/init.d/artica-status restart --force >/dev/null 2>&1");
    progress("{installed}", "Done", 100);
}
Пример #4
0
             }
             $itemid += 1;
         } else {
             $itemid = $fid + $num;
         }
     } else {
         if ($update) {
             $all ? msg('', '?moduleid=' . $moduleid . '&file=' . $file . '&action=index&all=1&one=' . $one) : dmsg('更新成功', $this_forward);
         } else {
             if ($one) {
                 dheader('?file=html&action=back&mid=' . $moduleid);
             }
             $all ? msg($MOD['name'] . '生成成功', $this_forward) : dmsg($MOD['name'] . '生成成功', $this_forward);
         }
     }
     msg('ID从' . $fid . '至' . ($itemid - 1) . $MOD['name'] . ($update ? '更新' : '生成') . '成功' . progress($sid, $fid, $tid), "?moduleid={$moduleid}&file={$file}&action={$action}&sid={$sid}&fid={$itemid}&tid={$tid}&num={$num}&update={$update}&all={$all}&one={$one}");
     break;
 case 'cate':
     $catid or msg('请选择分类');
     isset($num) or $num = 50;
     isset($fid) or $fid = 1;
     $total = max(ceil($CAT['item'] / $MOD['pagesize']), 1);
     if ($fpage && $tpage) {
         $fid = $fpage;
         $num = $tpage - $fpage + 1;
         tohtml('list', $module);
         dmsg('生成成功', $this_forward);
     }
     if ($fid <= $total) {
         tohtml('list', $module);
         msg('第' . $fid . '页至第' . ($fid + $num - 1) . '页生成成功', '?moduleid=' . $moduleid . '&file=' . $file . '&action=' . $action . '&catid=' . $catid . '&fid=' . ($fid + $num) . '&num=' . $num . '&fpage=' . $fpage . '&tpage=' . $tpage);
Пример #5
0
function Compile_rules($NoPersoRules = false)
{
    progress(5, "Cleaning rules");
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    iptables_delete_all();
    $sock = new sockets();
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    $PostFixLimitToNets = $sock->GET_INFO("PostFixLimitToNets");
    if (!is_numeric($PostFixLimitToNets)) {
        $PostFixLimitToNets = 0;
    }
    $EnablePostfixAutoBlockWhiteListed = $sock->GET_INFO("EnablePostfixAutoBlockWhiteListed");
    if (!is_numeric($EnablePostfixAutoBlockWhiteListed)) {
        $EnablePostfixAutoBlockWhiteListed = 0;
    }
    $GlobalIptablesEnabled = $sock->GET_INFO("GlobalIptablesEnabled");
    if (!is_numeric($GlobalIptablesEnabled)) {
        $GlobalIptablesEnabled = 1;
    }
    if ($GlobalIptablesEnabled != 1) {
        if ($GLOBALS["VERBOSE"]) {
            echo "GlobalIptablesEnabled <> 1, aborting...\n";
        }
        return;
    }
    if (!$NoPersoRules) {
        perso(true);
    }
    FW_PERSO_RULES();
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    if ($EnablePostfixAutoBlockWhiteListed == 1) {
        Compile_rules_whitelist();
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "FW_NGINX_RULES\n\n";
    }
    FW_NGINX_RULES(true);
    FW_SPAMHAUS_RULES(true);
    if ($PostFixLimitToNets == 1) {
        Compile_rules_postfix_limitToNets();
        return;
    }
    $unix = new unix();
    $iptables = $unix->find_program("iptables");
    $sock = new sockets();
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    $iptablesClass = new iptables_chains();
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    $InstantIptablesEventAll = $sock->GET_INFO("InstantIptablesEventAll");
    if (!is_numeric($InstantIptablesEventAll)) {
        $InstantIptablesEventAll = 1;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "InstantIptablesEventAll={$InstantIptablesEventAll}\n";
    }
    if ($GLOBALS["EnablePostfixAutoBlock"] != 1) {
        progress(100, "Building rules done...");
        return;
    }
    events("Query iptables rules from mysql");
    progress(10, "Query rules");
    progress(25, "Building logging rules");
    $sql = "SELECT * FROM iptables WHERE disable=0 AND flux='INPUT' and log=1 AND allow=0 AND local_port=25";
    if ($GLOBALS["VERBOSE"]) {
        echo $sql . "\n";
    }
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $GLOBALS["IPTABLES_WHITELISTED"] = $iptablesClass->LoadWhiteLists();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ip = $ligne["serverip"];
        if ($iptablesClass->isWhiteListed($ip)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ip} is whitelisted\n";
            }
            continue;
        }
        events("LOG {$ligne["serverip"]} REJECT INBOUND PORT 25");
        progress(35, "Building logging rules for {$ip}");
        $cmd = "{$iptables} -A INPUT -s {$ip} -p tcp --destination-port 25 -j LOG --log-prefix \"SMTP DROP: \" -m comment --comment \"ArticaInstantPostfix\"";
        $commands[] = $cmd;
    }
    progress(40, "Building rules...");
    $c = 0;
    $sql = "SELECT * FROM iptables WHERE disable=0 AND flux='INPUT' AND allow=0 AND local_port=25";
    if ($GLOBALS["VERBOSE"]) {
        echo $sql . "\n";
    }
    $results = $q->QUERY_SQL($sql, "artica_backup");
    progress(55, "Building rules...");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ip = $ligne["serverip"];
        if ($iptablesClass->isWhiteListed($ip)) {
            continue;
        }
        $c++;
        events("ADD REJECT {$ligne["serverip"]} INBOUND PORT 25");
        progress(60, "Building rules for {$ip}...");
        if ($InstantIptablesEventAll == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ip} -> LOG\n";
            }
            $cmd = "{$iptables} -A INPUT -s {$ip} -p tcp --destination-port 25 -j LOG --log-prefix \"SMTP DROP: \" -m comment --comment \"ArticaInstantPostfix\"";
            $commands[] = $cmd;
        }
        $cmd = "{$iptables} -A INPUT -s {$ip} -p tcp --destination-port 25 -j DROP -m comment --comment \"ArticaInstantPostfix\"";
        $commands[] = $cmd;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo count($commands) . " should be performed\n";
        return;
    }
    if (is_array($commands)) {
        while (list($index, $line) = each($commands)) {
            shell_exec($line);
        }
    }
    $unix->send_email_events("{$c} banned addresses compiled in the SMTP Firewall", "{$c} items has been banned from 25,587,465 ports", "postfix");
    progress(90, "Building rules done...");
    progress(100, "Building rules done...");
    $nohup = $unix->find_program("nohup");
    $cachefile = "/etc/artica-postfix/IPTABLES_INPUT";
    shell_exec("{$nohup} {$iptables} -L --line-numbers -n >{$cachefile} 2>&1 &");
}
Пример #6
0
     isset($sid) or $sid = $fid;
     if ($fid <= $tid) {
         $result = $db->query("SELECT itemid FROM {$DT_PRE}news WHERE itemid>={$fid} ORDER BY itemid LIMIT 0,{$num}");
         if ($db->affected_rows($result)) {
             while ($r = $db->fetch_array($result)) {
                 $itemid = $r['itemid'];
                 $do->update($itemid);
             }
             $itemid += 1;
         } else {
             $itemid = $fid + $num;
         }
     } else {
         dmsg('更新成功', "?moduleid={$moduleid}&file={$file}");
     }
     msg('ID从' . $fid . '至' . ($itemid - 1) . '更新成功' . progress($sid, $fid, $tid), "?moduleid={$moduleid}&file={$file}&action={$action}&sid={$sid}&fid={$itemid}&tid={$tid}&num={$num}");
     break;
 case 'recycle':
     $lists = $do->get_list('status=0' . $condition, $dorder[$order]);
     include tpl('news_recycle', $module);
     break;
 case 'check':
     if ($itemid && !$psize) {
         $do->check($itemid);
         dmsg('审核成功', $forward);
     } else {
         $lists = $do->get_list('status=2' . $condition, $dorder[$order]);
         include tpl('news_check', $module);
     }
     break;
 case 'reject':
Пример #7
0
function restore()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["VERBOSE"]) {
        echo "PID: {$pidfile}\n";
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        $TTL = $unix->PROCESS_TTL($pid);
        if ($TTL < 240) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    $hostname = $unix->hostname_g();
    progress(10, "{mounting}");
    if (!restore_TestNas()) {
        system_admin_events("Mounting NAS filesystem report false", __FUNCTION__, __FILE__, __LINE__);
        progress(100, "{failed}");
        return;
    }
    $BackupArticaRestoreNASIpaddr = $sock->GET_INFO("BackupArticaRestoreNASIpaddr");
    $BackupArticaRestoreNASFolder = $sock->GET_INFO("BackupArticaRestoreNASFolder");
    $BackupArticaRestoreNASUser = $sock->GET_INFO("BackupArticaRestoreNASUser");
    $BackupArticaRestoreNASPassword = $sock->GET_INFO("BackupArticaRestoreNASPassword");
    $BackupArticaRestoreNASFolderSource = $sock->GET_INFO("BackupArticaRestoreNASFolderSource");
    $BackupArticaRestoreNetwork = $sock->GET_INFO("BackupArticaRestoreNetwork");
    $mountPoint = "/mnt/BackupArticaRestoreNAS";
    $BackupArticaRestoreNASFolderSource = str_replace("\\", "/", $BackupArticaRestoreNASFolderSource);
    $sourceDir = "{$mountPoint}/{$BackupArticaRestoreNASFolderSource}";
    $sourceDir = str_replace("//", "/", $sourceDir);
    if (!is_file("{$sourceDir}/BKVERSION.txt")) {
        progress(100, "{failed} BKVERSION.txt no such file");
        $mount = new mount("/var/log/artica-postfix/backup.debug");
        if ($mount->ismounted($mountPoint)) {
            $mount->umount($mountPoint);
        }
        return;
    }
    $time = trim(@file_get_contents("{$sourceDir}/BKVERSION.txt"));
    progress(15, "{backup} " . date("Y-m-d H:i:s"));
    progress(20, "{restoring_ldap_database}, {please_wait}...");
    Restore_ldap($sourceDir);
    progress(40, "{restoring_artica_settings}, {please_wait}...");
    restore_artica_settings($sourceDir);
    progress(50, "{restoring_artica_databases}, {please_wait}...");
    restore_artica_backup($sourceDir);
    progress(60, "{restoring_artica_databases}, {please_wait}...");
    restore_ocsweb($sourceDir);
    progress(80, "{restoring_artica_databases}, {please_wait}...");
    restore_squidlogs($sourceDir);
    progress(82, "{restoring} PowerDNS, {please_wait}...");
    restore_powerdns($sourceDir);
    progress(90, "{reconfigure_server}, {please_wait}...");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $php = $unix->LOCATE_PHP5_BIN();
    if (is_file($squidbin)) {
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    }
    progress(100, "{success}");
    $mount = new mount("/var/log/artica-postfix/backup.debug");
    if ($mount->ismounted($mountPoint)) {
        $mount->umount($mountPoint);
    }
    if ($BackupArticaRestoreNetwork == 1) {
        $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php --build");
    }
    return;
}
Пример #8
0
/** Prints "Language selection" screen*/
function print_select_language()
{
    progress(10);
    echo "<br><center>\n\t<font class=\"pn-title\">" . _VERSION_WARNING . "</font><br><br>\n<font class=\"pn-title\">" . _SELECT_LANGUAGE_1 . "</font></center>\n<form action=\"install.php\" method=\"post\"><center><table width=\"50%\" align=center><tr>\n<td align=center><font class=\"pn-normal\">" . _SELECT_LANGUAGE_2;
    lang_dropdown();
    echo "<input type=\"hidden\" name=\"op\" value=\"Set Language\">\n<input type=\"submit\" value=\"" . _BTN_SET_LANGUAGE . "\"></font></td></tr>\n</table></center></form>";
}
Пример #9
0
function restore($filename, $storeid)
{
    $filename = trim($filename);
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".{$filename}.pid";
    $pid = @file_get_contents("{$pidfile}");
    if ($unix->process_exists($pid, basename(__FILE__))) {
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $EnableSyslogDB = @file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    @mkdir("/var/log/artica-postfix/squid-brut", 0777, true);
    @mkdir("/var/log/artica-postfix/squid-reverse", 0777, true);
    $GLOBALS["filename"] = $filename;
    $sock = new sockets();
    $TempDir = "/home/artica-extract-temp";
    @mkdir($TempDir, 0777);
    @chown($TempDir, "mysql");
    @chdir($TempDir, "mysql");
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    $bzip2 = $unix->find_program("bzip2");
    $gunzip = $unix->find_program("gunzip");
    progress("Extract {$filename} from MySQL database into {$TempDir}", 4);
    if ($EnableSyslogDB == 1) {
        $q = new mysql_storelogs();
        $sql = "SELECT filecontent INTO DUMPFILE '{$TempDir}/{$filename}' FROM files_store WHERE ID = '{$storeid}'";
        $q->QUERY_SQL($sql);
    } else {
        $q = new mysql_syslog();
        $sql = "SELECT filedata INTO DUMPFILE '{$TempDir}/{$filename}' FROM store WHERE filename = '{$filename}'";
        $q->QUERY_SQL($sql);
    }
    if (!$q->ok) {
        progress("Failed!!! {$q->mysql_error}", 100);
        return;
    }
    $file_extension = file_extension($filename);
    progress("Extract {$filename} extension: {$file_extension}", 5);
    $newtFile = $filename . ".log";
    if ($file_extension == "bz2") {
        $cmdline = "bzip2 -d \"{$TempDir}/{$filename}\" -c >\"{$TempDir}/{$newtFile}.log\" 2>&1";
        exec($cmdline, $results);
    }
    if ($file_extension == "gz") {
        $cmdline = "gunzip -d \"{$TempDir}/{$filename}\" -c >\"{$TempDir}/{$newtFile}.log\" 2>&1";
    }
    if ($cmdline != null) {
        exec($cmdline, $results);
        progress("Extract done " . @implode(" ", $results), 7);
    } else {
        if (!@copy("{$TempDir}/{$filename}", "{$TempDir}/{$newtFile}.log")) {
            progress("Failed!!! Copy error", 100);
            return;
        }
    }
    @unlink("{$TempDir}/{$filename}");
    if (!is_file("{$TempDir}/{$newtFile}.log")) {
        progress("Failed!!! {$TempDir}/{$newtFile}.log error no such file", 100);
        return;
    }
    $linesNumber = $unix->COUNT_LINES_OF_FILE("{$TempDir}/{$newtFile}.log");
    progress("Open {$TempDir}/{$newtFile}.log {$linesNumber}", 10);
    $handle = @fopen("{$TempDir}/{$newtFile}.log", "r");
    if (!$handle) {
        progress("Failed!!! {$TempDir}/{$newtFile}.log open failed", 100);
        return;
    }
    $c = 0;
    $d = 0;
    $TTEV = 0;
    while (!feof($handle)) {
        $c++;
        $buffer = trim(fgets($handle, 4096));
        if (!preg_match("#MAC:.*?\\[([0-9]+)\\/(.*?)\\/([0-9]+).*?:([0-9]+):([0-9]+):([0-9]+)\\s+(.*?)\\]\\s+\"#", $buffer, $re)) {
            continue;
        }
        $dteStr = "{$re[1]}/{$re[2]}/{$re[3]}:{$re[4]}:{$re[5]}:{$re[6]} {$re[7]}";
        $ttime = strtotime($dteStr);
        $newDate = date("Y-m-d H", $ttime) . "h";
        $datelog = date("Y-m-d-h", $ttime);
        $MD5Buffer = md5($buffer);
        $TTEV++;
        @mkdir("/var/log/artica-postfix/squid-brut/{$datelog}", 0777, true);
        @file_put_contents("/var/log/artica-postfix/squid-brut/{$datelog}/{$MD5Buffer}", $buffer);
        if ($c > 10) {
            $d = $d + $c;
            $pp = $d / $linesNumber;
            $pp = $pp * 100;
            $pp = round($pp, 1);
            if ($pp > 10) {
                if ($pp > 100) {
                    $pp = 99;
                }
                progress("Processing {$d}/{$linesNumber} - {$newDate} ", $pp);
                $c = 0;
            }
        }
    }
    progress("Success, {$TTEV} events sent to MySQL injector ", 100);
    @unlink("{$TempDir}/{$newtFile}.log");
}
function visited_sites()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/squid.visited_sites_rescan.pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    $t = time();
    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;
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    stats_admin_events(2, "Starting table visited_sites", "", __FILE__, __LINE__);
    progress("Starting table visited_sites", 5);
    $q = new mysql_squid_builder();
    $sql = "SELECT sitename FROM visited_sites WHERE LENGTH(category)=0";
    $results = $q->QUERY_SQL($sql);
    $num_rows = mysql_num_rows($results);
    $took = $unix->distanceOfTimeInWords($t, time());
    stats_admin_events(2, "Query done {$num_rows} websites to scan", "took:{$took}", __FILE__, __LINE__);
    if ($num_rows == 0) {
        progress(null, 100);
        return;
    }
    progress("Query done {$num_rows} websites to scan", 10);
    $c = 0;
    $t = 0;
    $d = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $sitenameOrg = $ligne["sitename"];
        $sitename = strtolower(trim($sitenameOrg));
        if (badCharacters($sitename)) {
            $q->categorize_reaffected($sitename);
            $sitenameOrg = mysql_escape_string2($sitenameOrg);
            $q->QUERY_SQL("UPDATE visited_sites SET category='reaffected' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
            $d++;
            $c++;
            continue;
        }
        if (strpos($sitename, ".") == 0) {
            $q->categorize_reaffected($sitename);
            $sitenameOrg = mysql_escape_string2($sitenameOrg);
            $q->QUERY_SQL("UPDATE visited_sites SET category='reaffected' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
            $d++;
            $c++;
            continue;
        }
        if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $sitename)) {
            $sitename = gethostbyaddr($sitename);
            if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $sitename)) {
                $c++;
                continue;
            }
        }
        $ipaddr = gethostbyname($sitename);
        if (!preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $ipaddr)) {
            $q->categorize_reaffected($sitenameOrg);
            $q->QUERY_SQL("UPDATE visited_sites SET category='reaffected' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
            $d++;
            $c++;
            continue;
        }
        $cat = $q->GET_CATEGORIES($sitename);
        if ($cat != null) {
            $d++;
            $q->QUERY_SQL("UPDATE visited_sites SET category='{$cat}' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
        }
        $c++;
        if ($c > 50) {
            $t = $t + $c;
            $purc = $t / $num_rows;
            $purc = round($purc, 2) * 100;
            $c = 0;
            if ($purc > 10) {
                progress("{$sitename} {$t}/{$num_rows}", $purc);
            }
        }
    }
    progress($sitename, 100);
    $took = $unix->distanceOfTimeInWords($t, time());
    if ($d > 0) {
        stats_admin_events(2, "{$d} New categorized websites...", "took:{$took}", __FILE__, __LINE__);
    }
}
Пример #11
0
	include_once('ressources/class.artica.inc');
	include_once('ressources/class.ini.inc');
	include_once('ressources/class.squid.inc');
	include_once('ressources/class.system.network.inc');
	
	
	$user=new usersMenus();
	if($user->AsWebStatisticsAdministrator==false){
		$tpl=new templates();
		echo "alert('". $tpl->javascript_parse_text("{ERROR_NO_PRIVS}")."');";
		die();exit();
	}	
	
	if(isset($_GET["popup"])){popup();exit;}
	if(isset($_GET["summarize"])){summarize();exit;}
	if(isset($_GET["progress"])){progress();exit;}
js();

function js(){
	$t=time();
	$tpl=new templates();
	$title=$tpl->_ENGINE_parse_body("{category_database_update}");
	$page=CurrentPageName();
	
	$html="
		function start$t(){
			YahooWinS('550','$page?popup=yes&t=$t','$title');
		
		}
		
		
Пример #12
0
}
.progress-0 {background-image: none;}
.progress-10 {background-position: -675px 0;}
.progress-20 {background-position: -600px 0;}
.progress-30 {background-position: -525px 0;}
.progress-40 {background-position: -450px 0;}
.progress-50 {background-position: -375px 0;}
.progress-60 {background-position: -300px 0;}
.progress-70 {background-position: -225px 0;}
.progress-80 {background-position: -150px 0;}
.progress-90 {background-position: -75px 0;}
.progress-100 {background-position: 0 0;}
</style>
<?php 
creatureGrid($creature_results);
?>
<br>
<?php 
// Detailed view
$i = 0;
foreach ($creature_results as $r) {
    $underscore = str_replace(' ', '_', $r['name']);
    echo "<div class='div center' id='{$underscore}'>";
    cards($r);
    echo '<br>';
    progress($r['progress'], $r);
    echo '</div>';
    $i++;
}
disqus('Ancient Beast - Bestiary');
include '../footer.php';
Пример #13
0
                 $db->query("UPDATE {$DT_PRE}know_expert SET passport='{$passport}' WHERE username='******'");
                 $db->query("UPDATE {$DT_PRE}know_vote SET passport='{$passport}' WHERE username='******'");
                 $db->query("UPDATE {$DT_PRE}club SET passport='{$passport}' WHERE username='******'");
                 $db->query("UPDATE {$DT_PRE}club_fans SET passport='{$passport}' WHERE username='******'");
                 $db->query("UPDATE {$DT_PRE}club_group SET passport='{$passport}' WHERE username='******'");
                 $db->query("UPDATE {$DT_PRE}club_reply SET passport='{$passport}' WHERE username='******'");
                 $db->query("UPDATE {$DT_PRE}club SET replyer='{$passport}' WHERE replyuser='******'");
             }
             $userid += 1;
         } else {
             $userid = $fid + $num;
         }
     } else {
         dmsg('更新成功', $this_forward);
     }
     msg('ID从' . $fid . '至' . ($userid - 1) . '昵称更新成功' . progress($sid, $fid, $tid), "?moduleid={$moduleid}&file={$file}&action={$action}&sid={$sid}&fid={$userid}&tid={$tid}&num={$num}&all={$all}&one={$one}");
     break;
 case 'cate':
     $catid or msg('请选择分类');
     isset($num) or $num = 50;
     isset($fid) or $fid = 1;
     $total = max(ceil($CAT['item'] / $MOD['pagesize']), 1);
     if ($fpage && $tpage) {
         $fid = $fpage;
         $num = $tpage - $fpage + 1;
         tohtml('list', $module);
         dmsg('生成成功', $this_forward);
     }
     if ($fid <= $total) {
         tohtml('list', $module);
         msg('第' . $fid . '页至第' . ($fid + $num - 1) . '页生成成功', '?moduleid=' . $moduleid . '&file=' . $file . '&action=' . $action . '&catid=' . $catid . '&fid=' . ($fid + $num) . '&num=' . $num . '&fpage=' . $fpage . '&tpage=' . $tpage);
Пример #14
0
function download()
{
    progress("Downloading index file", 10);
    $curl = new ccurl("http://www.articatech.net/auto.update.php");
    $curl->NoHTTP_POST = true;
    if (!$curl->get()) {
        progress("Failed download index file", 110);
        return null;
    }
    $ini = new Bs_IniHandler();
    $ini->loadString($curl->data);
    $owncloudversion = $ini->_params["NEXT"]["owncloud"];
    if ($owncloudversion == null) {
        progress("Failed corrupted index file", 110);
        return null;
    }
    progress("Owncloud version {$owncloudversion}", 15);
    return "http://www.articatech.net/download/owncloud-{$owncloudversion}.tar.gz";
}
Пример #15
0
     }
     isset($num) or $num = 2;
     isset($sid) or $sid = $fid;
     isset($itemid) or $itemid = 1;
     if ($fid <= $tid) {
         $result = $db->query("SELECT * FROM {$table} WHERE pid>={$fid} AND username='******' ORDER BY pid LIMIT 0,{$num} ");
         if ($db->affected_rows($result)) {
             while ($r = $db->fetch_array($result)) {
                 $itemid = $r['pid'];
                 delete_upload($r['fileurl'], 0);
             }
             $itemid += 1;
         } else {
             $itemid = $fid + $num;
         }
         msg('ID从' . $fid . '至' . ($itemid - 1) . '删除成功' . progress($sid, $fid, $tid), "?file={$file}&action={$action}&username={$username}&id={$id}&sid={$sid}&fid={$itemid}&tid={$tid}&num={$num}");
     } else {
         dmsg('删除成功', "?file={$file}");
     }
 } else {
     if ($u) {
         $id = $u['userid'] % 10;
     } else {
         for ($i = 0; $i < 10; $i++) {
             $t = $db->get_one("SELECT itemid FROM {$DT_PRE}upload_{$i} WHERE username='******'");
             if ($t) {
                 $id = $i;
                 break;
             }
         }
         if ($id == -1) {
Пример #16
0
function build($uri)
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $echo = $unix->find_program("echo");
    $curl = $unix->find_program("curl");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $curl = $unix->find_program("curl");
    @unlink("/var/log/squid/request.debug");
    $DirFinal = "/usr/share/artica-postfix/ressources/support/" . time();
    @mkdir($DirFinal, 0755, true);
    $SquidMgrListenPort = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidMgrListenPort"));
    shell_exec("{$echo} \"Proxy address 127.0.0.1:{$SquidMgrListenPort}\" > /var/log/squid/request.debug 2>&1");
    shell_exec("{$echo} \"Url to test: {$uri} \" >> /var/log/squid/request.debug 2>&1");
    progress("{rotate_logs_files}", 30);
    shell_exec("{$echo} \"Rotate & turn to debug... \" >> /var/log/squid/request.debug 2>&1");
    shell_exec("{$squidbin} -k rotate >> /var/log/squid/request.debug 2>&1");
    progress("{turn_to_debug}", 35);
    shell_exec("{$squidbin} -k debug >/dev/null 2>&1");
    sleep(4);
    progress("{send_query}", 40);
    $cmd = "{$curl} --head --verbose --trace-time --proxy http://127.0.0.1:{$SquidMgrListenPort} --url {$uri} >> /var/log/squid/request.debug 2>&1";
    shell_exec("{$echo} \"{$cmd}\" >> /var/log/squid/request.debug 2>&1");
    shell_exec($cmd);
    sleep(4);
    progress("{return_back_to_normal}", 40);
    LogsThisDebug("************************************************************");
    squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__);
    shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . "  >> /var/log/squid/request.debug 2>&1");
    LogsThisDebug("************************************************************");
    sleep(1);
    @copy("/var/log/squid/cache.log", "{$DirFinal}/cache.log");
    progress("{compressing_package}", 90);
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $filename = "request.tar.gz";
    @unlink("/usr/share/artica-postfix/ressources/support/{$filename}");
    @copy("/var/log/squid/request.debug", "{$DirFinal}/request.debug");
    @unlink("/var/log/squid/request.debug");
    chdir($DirFinal);
    $cmd = "{$tar} -cvzf /usr/share/artica-postfix/ressources/support/{$filename} * 2>&1";
    exec($cmd, $results);
    @chmod("/usr/share/artica-postfix/ressources/support/{$filename}", 0755);
    shell_exec("{$rm} -rf {$DirFinal}");
    LogsThisDebug("*********************************************************");
    $c = 0;
    progress("{success}", 100);
}
Пример #17
0
                 $i = 0;
                 foreach ($files as $f) {
                     file_del($f);
                     $cf++;
                     $i++;
                     if ($i > 500) {
                         msg('已删除 ' . $cd . ' 个目录,' . $cf . ' 个文件' . progress(0, $cd, $tt), '?action=' . $action . '&dir=' . $dir . '&cd=' . $cd . '&cf=' . $cf . '&job=' . $job . '&tt=' . $tt, 0);
                     }
                 }
                 dir_delete($sub);
                 $cd++;
                 msg('已删除 ' . $cd . ' 个目录,' . $cf . ' 个文件' . progress(0, $cd, $tt), '?action=' . $action . '&dir=' . $dir . '&cd=' . $cd . '&cf=' . $cf . '&job=' . $job . '&tt=' . $tt, 0);
             } else {
                 dir_delete($sub);
                 $cd++;
                 msg('已删除 ' . $cd . ' 个目录,' . $cf . ' 个文件' . progress(0, $cd, $tt), '?action=' . $action . '&dir=' . $dir . '&cd=' . $cd . '&cf=' . $cf . '&job=' . $job . '&tt=' . $tt, 0);
             }
         } else {
             dir_delete(DT_CACHE . '/' . $dir);
             msg('缓存更新成功');
         }
     } else {
         msg('目录名错误');
     }
 } else {
     $dir = $job . timetodate($DT_TIME, 'YmdHis');
     if (rename(DT_CACHE . '/' . $job, DT_CACHE . '/' . $dir)) {
         dir_create(DT_CACHE . '/' . $job);
         file_del(DT_CACHE . '/' . $dir . '/index.html');
         $dirs = glob(DT_CACHE . '/' . $dir . '/*');
         $tt = count($dirs);
Пример #18
0
     }
     $sqldump = '';
     $tableid = isset($tableid) ? $tableid - 1 : 0;
     $startfrom = isset($startfrom) ? intval($startfrom) : 0;
     $tablenumber = count($tables);
     for ($i = $tableid; $i < $tablenumber && strlen($sqldump) < $sizelimit * 1000; $i++) {
         $sqldump .= sql_dumptable($tables[$i], $startfrom, strlen($sqldump));
         $startfrom = 0;
     }
     if (trim($sqldump)) {
         $sqldump = "# Destoon V" . DT_VERSION . " R" . DT_RELEASE . " http://www.destoon.com\n# " . timetodate($DT_TIME, 6) . "\n# --------------------------------------------------------\n\n\n" . $sqldump;
         $tableid = $i;
         $filename = $random . '/' . $fileid . '.sql';
         file_put($D . $filename, $sqldump);
         $fid = $fileid;
         msg('分卷 <strong>#' . $fileid++ . '</strong> 备份成功.. 程序将自动继续...' . progress(0, $fid, $tid), '?file=' . $file . '&sizelimit=' . $sizelimit . '&sqlcompat=' . $sqlcompat . '&sqlcharset=' . $sqlcharset . '&tableid=' . $tableid . '&fileid=' . $fileid . '&fileid=' . $fileid . '&tid=' . $tid . '&startfrom=' . $startrow . '&random=' . $random . '&backup=1');
     } else {
         cache_delete($_username . '_backup.php');
         $db->query("DELETE FROM {$DT_PRE}setting WHERE item='destoon' AND item_key='backtime'");
         $db->query("INSERT INTO {$DT_PRE}setting (item,item_key,item_value) VALUES('destoon','backtime','{$DT_TIME}')");
         msg('数据库备份成功', '?file=' . $file . '&action=import');
     }
 } else {
     $dtables = $tables = $C = $T = array();
     $i = $j = $dtotalsize = $totalsize = 0;
     $result = $db->query("SHOW TABLES FROM `" . $CFG['db_name'] . "`");
     while ($rr = $db->fetch_row($result)) {
         if (!$rr[0]) {
             continue;
         }
         $T[$rr[0]] = $rr[0];
Пример #19
0
function Compile_rules()
{
    progress(5, "Cleaning rules");
    iptables_delete_all();
    if ($GLOBALS["EnablePostfixAutoBlock"] != 1) {
        progress(100, "Building rules done...");
        return;
    }
    events("Query iptables rules from mysql");
    progress(10, "Query rules");
    progress(25, "Building logging rules");
    $sql = "SELECT * FROM iptables WHERE disable=0 AND flux='INPUT' and log=1";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ip = $ligne["serverip"];
        events("LOG {$ligne["serverip"]} REJECT INBOUND PORT 25");
        progress(35, "Building logging rules for {$ip}");
        $cmd = "/sbin/iptables -A INPUT -s {$ip} -p tcp --destination-port 25 -j LOG --log-prefix \"SMTP DROP: \" -m comment --comment \"ArticaInstantPostfix\"";
        system("{$cmd}");
    }
    progress(40, "Building rules...");
    $sql = "SELECT * FROM iptables WHERE disable=0 AND flux='INPUT'";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    progress(55, "Building rules...");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ip = $ligne["serverip"];
        events("ADD REJECT {$ligne["serverip"]} INBOUND PORT 25");
        progress(60, "Building rules for {$ip}...");
        $cmd = "/sbin/iptables -A INPUT -s {$ip} -p tcp --destination-port 25 -j DROP -m comment --comment \"ArticaInstantPostfix\"";
        system("{$cmd}");
    }
    progress(90, "Building rules done...");
    progress(100, "Building rules done...");
}
function sqlQuery($sql, $colname = NULL, $bindvar = NULL)
{
    global $i;
    $conn = new Connection();
    $Query = $conn->connect()->prepare($sql);
    if (!empty($bindvar)) {
        $Query->bindValue(":id", $bindvar, PDO::PARAM_STR);
    }
    $Query->execute();
    $returnrow = array();
    if (is_null($colname)) {
        $returnrow = array(array());
    }
    array_pop($returnrow);
    while ($row = $Query->fetch(\PDO::FETCH_ASSOC)) {
        if (is_null($colname)) {
            array_push($returnrow, $row);
        } else {
            array_push($returnrow, $row[$colname]);
        }
    }
    // Calculate the percent progress
    $percent = intval($i);
    progress($percent, $i);
    $i++;
    return $returnrow;
}
Пример #21
0
if ($user->AsWebStatisticsAdministrator == false) {
    $tpl = new templates();
    echo "alert('" . $tpl->javascript_parse_text("{ERROR_NO_PRIVS}") . "');";
    die;
    exit;
}
if (isset($_GET["popup"])) {
    popup();
    exit;
}
if (isset($_GET["summarize"])) {
    summarize();
    exit;
}
if (isset($_GET["progress"])) {
    progress();
    exit;
}
js();
function js()
{
    $t = time();
    $tpl = new templates();
    $title = $tpl->_ENGINE_parse_body("{category_database_update}");
    $page = CurrentPageName();
    $html = "\n\t\tfunction start{$t}(){\n\t\t\tYahooWinS('550','{$page}?popup=yes&t={$t}','{$title}');\n\t\t\n\t\t}\n\t\t\n\t\t\n\tstart{$t}();";
    echo $html;
}
function popup()
{
    $tt = time();
Пример #22
0
function enable_icap()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        echo basename(__FILE__) . ":Already executed pid {$pid}.. aborting the process\n";
        progress("{failed}", 110);
        return;
    }
    $sock = new sockets();
    $sock->SET_INFO("kavicapserverEnabled", 1);
    $MEM = $unix->MEM_TOTAL_INSTALLEE();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $sock->SET_INFO("kavicapserverEnabled", 0);
        if ($GLOBALS["OUTPUT"]) {
            echo "Not enough memory - {$MEM}\n";
        }
        progress("{failed}", 110);
        return;
    }
    $q = new mysql_squid_builder();
    progress("{verify_icap_center}", 10);
    $q->CheckTablesICAP();
    if ($q->COUNT_ROWS("c_icap_services") == 0) {
        progress("{verify_icap_center} {failed}", 110);
    }
    progress("{hooking_local_service}", 10);
    $q->QUERY_SQL("UPDATE c_icap_services SET `enabled`=1 WHERE ID=6");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        progress("{hooking_local_service} {failed}", 110);
    }
    $q->QUERY_SQL("UPDATE c_icap_services SET `enabled`=1 WHERE ID=5");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        progress("{hooking_local_service} {failed}", 110);
    }
    progress("{reloading} {APP_KAV4PROXY}", 20);
    build();
    system("/etc/init.d/kav4proxy reload");
    progress("{configuring} {APP_SQUID}", 50);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force --noverifcaches");
    progress("{restarting} {APP_SQUID}", 70);
    system("/etc/init.d/squid restart --force {$GLOBALS["SCRIPT_SUFFIX"]}");
    progress("{restarting} Artica-status", 80);
    system("/etc/init.d/artica-status restart --force");
    progress("{refresh} License", 90);
    $GLOBALS["FORCE"] = true;
    license_infos(true);
    progress("{success} {hooking_local_service}", 100);
}
Пример #23
0
                    $PHORUM['DB']->interact(DB_RETURN_RES, "UPDATE {$PHORUM['pm_messages_table']}\n                         SET    datestamp = {$pm['timestamp']}\n                         WHERE  pm_message_id = {$pm_id}", NULL, DB_MASTERQUERY);
                }
                $done++;
                progress($done, count($data->privatemessage));
            }
            echo "\n\n";
            break;
    }
}
echo "Updating Forum Stats...\n";
$done = 0;
foreach ($map["forums"] as $fid) {
    $PHORUM["forum_id"] = $fid;
    $PHORUM['DB']->update_forum_stats(true);
    $done++;
    progress($done, count($map["forums"]));
}
echo "\n\n";
if (!empty($errors)) {
    echo "There were some errors.\n";
    echo implode("\n", $errors);
    echo "\n\n";
}
/*************************************/
function makeArray($obj)
{
    $arr = (array) $obj;
    if (empty($arr)) {
        $arr = "";
    } else {
        foreach ($arr as $key => $value) {
Пример #24
0
         if ($db->affected_rows($result)) {
             while ($r = $db->fetch_array($result)) {
                 $itemid = $r['itemid'];
                 tohtml('webpage', $module);
             }
             $itemid += 1;
         } else {
             $itemid = $fid + $num;
         }
     } else {
         if ($all) {
             dheader("?moduleid=3&file=vote&action=html&all=1&item={$item}&one={$one}");
         }
         dmsg('生成成功', "?moduleid={$moduleid}&file={$file}&item={$item}");
     }
     msg('ID从' . $fid . '至' . ($itemid - 1) . '[单页]生成成功' . progress($sid, $fid, $tid), "?moduleid={$moduleid}&file={$file}&action={$action}&sid={$sid}&fid={$itemid}&tid={$tid}&num={$num}&item={$item}&all={$all}&one={$one}");
     break;
 case 'delete':
     $itemid or msg('请选择单页');
     $do->delete($itemid);
     dmsg('删除成功', $forward);
     break;
 case 'level':
     $itemid or msg('请选择单页');
     $level = intval($level);
     $do->level($itemid, $level);
     dmsg('级别设置成功', $forward);
     break;
 default:
     $sfields = array('按条件', '标题', '链接地址', '内容', '绑定域名');
     $dfields = array('title', 'title', 'linkurl', 'content', 'domain');
Пример #25
0
function Compile_rules()
{
    progress(5, "Cleaning rules");
    iptables_delete_all();
    $sock = new sockets();
    $EnablePostfixAutoBlockWhiteListed = $sock->GET_INFO("EnablePostfixAutoBlockWhiteListed");
    if (!is_numeric($EnablePostfixAutoBlockWhiteListed)) {
        $EnablePostfixAutoBlockWhiteListed = 0;
    }
    if ($EnablePostfixAutoBlockWhiteListed == 1) {
        Compile_rules_whitelist();
        return;
    }
    $unix = new unix();
    $iptables = $unix->find_program("iptables");
    $sock = new sockets();
    $iptablesClass = new iptables_chains();
    $InstantIptablesEventAll = $sock->GET_INFO("InstantIptablesEventAll");
    if (!is_numeric($InstantIptablesEventAll)) {
        $InstantIptablesEventAll = 1;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "InstantIptablesEventAll={$InstantIptablesEventAll}\n";
    }
    if ($GLOBALS["EnablePostfixAutoBlock"] != 1) {
        progress(100, "Building rules done...");
        return;
    }
    events("Query iptables rules from mysql");
    progress(10, "Query rules");
    progress(25, "Building logging rules");
    $sql = "SELECT * FROM iptables WHERE disable=0 AND flux='INPUT' and log=1 AND local_port=25";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $GLOBALS["IPTABLES_WHITELISTED"] = $iptablesClass->LoadWhiteLists();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ip = $ligne["serverip"];
        if ($iptablesClass->isWhiteListed($ip)) {
            continue;
        }
        events("LOG {$ligne["serverip"]} REJECT INBOUND PORT 25");
        progress(35, "Building logging rules for {$ip}");
        $cmd = "{$iptables} -A INPUT -s {$ip} -p tcp --destination-port 25 -j LOG --log-prefix \"SMTP DROP: \" -m comment --comment \"ArticaInstantPostfix\"";
        $commands[] = $cmd;
    }
    progress(40, "Building rules...");
    $c = 0;
    $sql = "SELECT * FROM iptables WHERE disable=0 AND flux='INPUT' AND local_port=25";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    progress(55, "Building rules...");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ip = $ligne["serverip"];
        if ($iptablesClass->isWhiteListed($ip)) {
            continue;
        }
        $c++;
        events("ADD REJECT {$ligne["serverip"]} INBOUND PORT 25");
        progress(60, "Building rules for {$ip}...");
        if ($InstantIptablesEventAll == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ip} -> LOG\n";
            }
            $cmd = "{$iptables} -A INPUT -s {$ip} -p tcp --destination-port 25 -j LOG --log-prefix \"SMTP DROP: \" -m comment --comment \"ArticaInstantPostfix\"";
            $commands[] = $cmd;
        }
        $cmd = "{$iptables} -A INPUT -s {$ip} -p tcp --destination-port 25 -j DROP -m comment --comment \"ArticaInstantPostfix\"";
        $commands[] = $cmd;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo count($commands) . " should be performed\n";
        return;
    }
    if (is_array($commands)) {
        while (list($index, $line) = each($commands)) {
            shell_exec($line);
        }
    }
    $unix->send_email_events("{$c} banned addresses compiled in the SMTP Firewall", "{$c} items has been banned from 25,587,465 ports", "postfix");
    progress(90, "Building rules done...");
    progress(100, "Building rules done...");
}
Пример #26
0
function restore_id($storeid)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$storeid}.pid";
    $pid = @file_get_contents("{$pidfile}");
    if ($unix->process_exists($pid, basename(__FILE__))) {
        events("Process {$pid} already exists...aborting");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    include_once dirname(__FILE__) . "/ressources/class.mysql.syslogs.inc";
    $sock = new sockets();
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $sarg_bin = $unix->find_program("sarg");
    if (!is_file($sarg_bin)) {
        sarg_admin_events("Fatal, unable to locate sarg binary, aborting...", __FUNCTION__, __FILE__, __LINE__, "sarg");
        return;
    }
    $bzip2 = $unix->find_program("bzip2");
    $gunzip = $unix->find_program("gunzip");
    $TempDir = "/home/artica-extract-temp";
    @mkdir($TempDir, 0777);
    @chown($TempDir, "mysql");
    @chdir($TempDir, "mysql");
    if (!is_file("/etc/squid3/sarg.conf")) {
        buildconf();
    }
    $q = new mysql_storelogs();
    $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT filename FROM files_info WHERE storeid='{$storeid}'"));
    $filename = $ligne["filename"];
    events("Extracting infos from {$filename}");
    $EnableSyslogDB = @file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    if ($EnableSyslogDB == 0) {
        events("Extracting infos from {$filename} failed, SyslogDB is not enabled");
        return;
    }
    $q = new mysql_storelogs();
    $sql = "SELECT filecontent INTO DUMPFILE '{$TempDir}/{$filename}' FROM files_store WHERE ID = '{$storeid}'";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        events("Failed!!! {$q->mysql_error}", 100);
        return;
    }
    $file_extension = file_extension($filename);
    progress("Extract {$filename} extension: {$file_extension}", 5);
    $newtFile = $filename . ".log";
    if ($file_extension == "bz2") {
        $cmdline = "{$bzip2} -d \"{$TempDir}/{$filename}\" -c >\"{$TempDir}/{$newtFile}.log\" 2>&1";
        exec($cmdline, $results);
    }
    if ($file_extension == "gz") {
        $cmdline = "{$gunzip} -d \"{$TempDir}/{$filename}\" -c >\"{$TempDir}/{$newtFile}.log\" 2>&1";
    }
    if ($cmdline != null) {
        exec($cmdline, $results);
        progress("Extract done " . @implode(" ", $results), 7);
    } else {
        if (!@copy("{$TempDir}/{$filename}", "{$TempDir}/{$newtFile}.log")) {
            progress("Failed!!! Copy error", 100);
            return;
        }
    }
    @unlink("{$TempDir}/{$filename}");
    if (!is_file("{$TempDir}/{$newtFile}.log")) {
        progress("Failed!!! {$TempDir}/{$newtFile}.log error no such file", 100);
        return;
    }
    $t = time();
    sargToFile("{$TempDir}/{$newtFile}.log");
    progress("{$filename} ({$storeid}) done " . $unix->distanceOfTimeInWords($t, time()));
    backup();
}
function install()
{
    $filename = "phpldapadmin-1.2.3.tgz";
    $version_down = "1.2.3";
    $uri = "http://articatech.net/download/phpldapadmin-1.2.3.tgz";
    $INSTALL_DIR = "/usr/share/phpldapadmin";
    $time = time();
    $unix = new unix();
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) {
            return;
        }
    }
    $cacheFile = "/usr/share/artica-postfix/ressources/logs/web/phpldapadmin.status";
    @unlink($cacheFile);
    $rm = $unix->find_program("rm");
    $cp = $unix->find_program("cp");
    $TMPDIR = $unix->TEMP_DIR() . "/{$time}";
    $FINAL_TARGET_DIR = null;
    $TARGET_PATH = "{$TMPDIR}/{$filename}";
    progress("{downloading} 1.2.3 version", "Downloading {$filename}", 30);
    progress("{downloading} 1.2.3 version", "Temporary directory = {$TMPDIR}", 30);
    $curl = new ccurl("{$uri}");
    $php = $unix->LOCATE_PHP5_BIN();
    $debianbin = $unix->find_program("update-rc.d");
    $redhatbin = $unix->find_program("chkconfig");
    @mkdir($TMPDIR);
    if (!$curl->GetFile($TARGET_PATH)) {
        progress("{failed}", $curl->error, 100);
        shell_exec("{$rm} -rf {$TMPDIR}");
        return;
    }
    @mkdir("/usr/share/phpldapadmin", 0755, true);
    progress("{downloading} {$version_down} version {success}", "success saving {$TARGET_PATH} ", 50);
    progress("{extracting} {$version_down} version", "Extracting {$TARGET_PATH} ", 55);
    $tar = $unix->find_program("tar");
    exec("{$tar} xvf {$TARGET_PATH} -C /{$TMPDIR}/ 2>&1", $results);
    while (list($index, $line) = each($results)) {
        progress("{extracting} {$version_down} version", $line, 60);
    }
    $dir = $unix->dirdir($TMPDIR);
    while (list($index, $line) = each($dir)) {
        progress("{search} {directory}", $line, 65);
        if (preg_match("#phpldapadmin#", $line)) {
            progress("{search} {directory}", "Found directory {$line}", 65);
            $FINAL_TARGET_DIR = $line;
            break;
        }
    }
    if ($FINAL_TARGET_DIR == null) {
        progress("{extracting} {$version_down} version {failed}", "Unable to find a suitable directory", 100);
        shell_exec("{$rm} -rf {$TMPDIR}");
        return;
    }
    progress("{installing} {$version_down} version", "Copy the content of {$FINAL_TARGET_DIR}", 70);
    exec("{$cp} -rfdv  {$FINAL_TARGET_DIR}/* {$INSTALL_DIR}/ 2>&1", $resultsA);
    while (list($index, $line) = each($resultsA)) {
        progress("{installing} 5.5.88 version", $line, 70);
    }
    progress("{installing} {$version_down} version", "Removing the {$TMPDIR} directory", 71);
    shell_exec("{$rm} -rf {$TMPDIR}");
    if (!is_file("{$INSTALL_DIR}/index.php")) {
        progress("{installing} {$version_down} version {failed}", "install from {$FINAL_TARGET_DIR} failed ", 100);
        return;
    }
    $ln = $unix->find_program("ln");
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time() . " >/dev/null 2>&1");
    shell_exec("/etc/init.d/artica-status restart --force >/dev/null 2>&1");
    progress("{installed}", "Done", 100);
    shell_exec("{$php} /usr/share/artica-postfix/exec.phpldapadmin.php --build");
    sleep(2);
    shell_exec("/etc/init.d/artica-webconsole restart --force");
}
Пример #28
0
function support_step2()
{
    $files[] = "/var/log/squid/cache.log";
    $files[] = "/var/log/syslog";
    $files[] = "/var/log/messages";
    $files[] = "/var/log/auth.log";
    $files[] = "/var/log/squid/access.log";
    $files[] = "/var/log/squid/external-acl.log";
    $files[] = "/var/log/squid/logfile_daemon.debug";
    $files[] = "/var/log/php.log";
    $files[] = "/var/log/mail.log";
    $files[] = "/var/log/squid.watchdog.log";
    $files[] = "/var/log/squid/ufdbguardd.log";
    $files[] = "/var/log/samba/log.winbindd";
    $files[] = "/etc/samba/smb.conf";
    $files[] = "/var/log/samba/log.nmbd";
    $files[] = "/var/log/samba/log.smbd";
    $files[] = "/var/run/mysqld/mysqld.err";
    $files[] = "/etc/init.d/artica-ifup";
    $files[] = "/var/log/net-start.log";
    $files[] = "/var/log/artica-ufdb.log";
    $files[] = "/var/log/artica-meta.log";
    $files[] = "/var/log/webfiltering-update.log";
    $files[] = "{$GLOBALS["ARTICALOGDIR"]}/ufdbguard-tail.debug";
    $unix = new unix();
    $cp = $unix->find_program("cp");
    $dmesg = $unix->find_program("dmesg");
    @mkdir("/usr/share/artica-postfix/ressources/support", 0755, true);
    shell_exec("{$dmesg} >/usr/share/artica-postfix/ressources/support/dmesg.txt");
    progress("{get_all_logs}", 45);
    if (is_dir("/etc/squid3")) {
        @mkdir("/usr/share/artica-postfix/ressources/support/etc-squid3", 0755, true);
        $cmd = "/bin/cp -rf /etc/squid3/* /usr/share/artica-postfix/ressources/support/etc-squid3/";
        shell_exec("{$cmd}");
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    progress("{get_all_logs}", 46);
    if (is_file("/tmp/squid.conf")) {
        if (is_file($squidbin)) {
            shell_exec("{$squidbin} -f /tmp/squid.conf -k parse >/etc-squid3/tmp.squid.conf.log 2>&1");
        }
        @copy("/tmp/squid.conf", "/usr/share/artica-postfix/ressources/support/etc-squid3/tmp.squid.conf");
    }
    progress("{get_all_logs}", 47);
    if (is_dir("/etc/postfix")) {
        @mkdir("/usr/share/artica-postfix/ressources/support/etc-postfix", 0755, true);
        $cmd = "/bin/cp -rf /etc/postfix/* /usr/share/artica-postfix/ressources/support/etc-postfix/";
        shell_exec("{$cmd}");
    }
    progress("{get_all_logs}", 48);
    while (list($a, $b) = each($files)) {
        if (is_file($b)) {
            progress("{get_all_logs}:" . basename($b), 48);
            $destfile = basename("{$b}.gz");
            $unix->compress($b, "/usr/share/artica-postfix/ressources/support/{$destfile}");
        }
    }
    progress("{get_all_logs} lshw", 49);
    $lshw = $unix->find_program("lshw");
    exec("{$lshw} -class network 2>&1", $results);
    progress("{get_all_logs} ifconfig", 50);
    $ifconfig = $unix->find_program("ifconfig");
    exec("{$ifconfig} -a 2>&1", $results);
    $results[] = "\n\t***************\n";
    progress("{get_all_logs} IP", 50);
    $ip = $unix->find_program("ip");
    exec("{$ip} link show 2>&1", $results);
    $results[] = "\n\t***************\n";
    progress("{get_all_logs} Route", 50);
    exec("{$ip} route 2>&1", $results);
    $results[] = "\n\t***************\n";
    $f = explode("\n", @file_get_contents("/etc/iproute2/rt_tables"));
    while (list($a, $line) = each($f)) {
        if (!preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) {
            continue;
        }
        $table_num = $re[1];
        $tablename = $re[2];
        if ($table_num == 0) {
            continue;
        }
        if ($table_num > 252) {
            continue;
        }
        $results[] = "\n\t***** Table route {$table_num} named {$tablename} *****\n";
        exec("{$ip} route show table {$table_num} 2>&1", $results);
        $results[] = "\n\t***************\n";
    }
    progress("{get_all_logs} uname", 51);
    $unix = new unix();
    $uname = $unix->find_program("uname");
    $results[] = "{$uname} -a:";
    exec("{$uname} -a 2>&1", $results);
    $results[] = "\n";
    $results[] = "/bin/bash --version:";
    exec("/bin/bash --version 2>&1", $results);
    $results[] = "\n";
    progress("{get_all_logs} gdb", 52);
    $gdb = $unix->find_program("gdb");
    if (is_file($gdb)) {
        $results[] = "{$gdb} --version:";
        exec("{$gdb} --version 2>&1", $results);
    } else {
        $results[] = "gdb no such binary....";
    }
    $results[] = "\n";
    $smbd = $unix->find_program("smbd");
    if (is_file($smbd)) {
        $results[] = "{$smbd} -V:";
        exec("{$smbd} -V 2>&1", $results);
    } else {
        $results[] = "smbd no such binary....";
    }
    $results[] = "\n";
    progress("{get_all_logs} {$squidbin}", 53);
    if (is_file($squidbin)) {
        $results[] = "{$squidbin} -v:";
        exec("{$squidbin} -v 2>&1", $results);
        squid_watchdog_events("Reconfiguring Proxy parameters...");
        exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results);
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results));
    } else {
        $results[] = "squid no such binary....";
    }
    $results[] = "\n";
    progress("{get_all_logs}", 54);
    if (is_file($squidbin)) {
        $results[] = "{$squidbin} -v:";
        exec("{$squidbin} -v 2>&1", $results);
        squid_watchdog_events("Reconfiguring Proxy parameters...");
        exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results);
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results));
        shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-conf-check.txt");
        if (is_file("/tmp/squid.conf")) {
            shell_exec("{$squidbin} -f /tmp/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-temp-check.txt");
        }
    } else {
        $results[] = "squid3 no such binary....";
    }
    progress("{get_all_logs} DF", 55);
    $results[] = "\n";
    $df = $unix->find_program("df");
    if (is_file($df)) {
        $results[] = "{$df} -h:";
        exec("{$df} -h 2>&1", $results);
    } else {
        $results[] = "{$df} no such binary....";
    }
    progress("{get_all_logs}", 56);
    @file_put_contents("/usr/share/artica-postfix/ressources/support/generated.versions.txt", @implode("\n", $results));
}
Пример #29
0
function build_report($ID, $nopid = false)
{
    if (!is_numeric($ID)) {
        ufdbguard_admin_events("Not a numeric ID", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    $t = time();
    $unix = new unix();
    $tablename = "WebTrackMem{$ID}";
    $tableBlock = "WebTrackMeB{$ID}";
    if (!$nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$ID}.pid";
        $pid = @file_get_contents($pidfile);
        if ($pid < 100) {
            $pid = null;
        }
        if ($unix->process_exists($pid, basename(__FILE__))) {
            ufdbguard_admin_events("Already executed pid {$pid}", __FUNCTION__, __FILE__, __LINE__, "reports");
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Building report {$ID}\n";
    }
    $q = new mysql_squid_builder();
    if ($q->TABLE_EXISTS($tablename)) {
        $q->DELETE_TABLE($tablename);
    }
    if ($q->TABLE_EXISTS($tableBlock)) {
        $q->DELETE_TABLE($tableBlock);
    }
    if (!$q->CreateMemberReportTable($tablename)) {
        ufdbguard_admin_events("could not create table {$tablename}", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    if (!$q->CreateMemberReportBlockTable($tableBlock)) {
        ufdbguard_admin_events("could not create table {$tablename}", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    $rp = new squid_report($ID);
    $LIST_TABLES_dansguardian_events = $q->LIST_TABLES_dansguardian_events();
    progress(10, $ID);
    $counttables = count($LIST_TABLES_dansguardian_events);
    $prefix = "INSERT IGNORE INTO {$tablename} (`zMD5`,`sitename`,`familysite`,`{$rp->userfield}`,`zDate`,`size`,`hits`,`category`) VALUES ";
    while (list($sourcetable, $ligne) = each($LIST_TABLES_dansguardian_events)) {
        $c++;
        $sql = $rp->BuildQuery($sourcetable);
        $results = $q->QUERY_SQL($sql);
        if (!$q->ok) {
            ufdbguard_admin_events("{$q->mysql_error}\n{$sql}", __FUNCTION__, __FILE__, __LINE__, "reports");
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Parsing {$sourcetable} \n{$sql}\n-> `" . mysql_num_rows($results) . "` rows\n";
        }
        if (mysql_num_rows($results) == 0) {
            continue;
        }
        $purc = round($c / $counttables, 2) * 100;
        progress($purc, $ID);
        $f = array();
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $md5 = md5(serialize($ligne));
            $sitename = $ligne["sitename"];
            $familysite = $q->GetFamilySites($sitename);
            if (!isset($GLOBALS["CATEGORY"][$sitename])) {
                $GLOBALS["CATEGORY"][$sitename] = $q->GET_CATEGORIES($sitename);
            }
            $category = $GLOBALS["CATEGORY"][$sitename];
            $source = addslashes($ligne["source"]);
            $zDate = $ligne["zDate"];
            $size = $ligne["size"];
            $hits = $ligne["hits"];
            $category = addslashes($category);
            $f[] = "('{$md5}','{$sitename}','{$familysite}','{$source}','{$zDate}','{$size}','{$hits}','{$category}')";
        }
        if (count($f) == 0) {
            continue;
        }
        $q->QUERY_SQL($prefix . @implode(",", $f));
        if (!$q->ok) {
            ufdbguard_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "reports");
            return;
        }
        if (system_is_overloaded(__FILE__)) {
            sleep(5);
        }
    }
    if ($rp->csv == 1) {
        SaveCSV($ID);
    }
    $LIST_TABLES_BLOCKED = $q->LIST_TABLES_BLOCKED();
    $prefix = "INSERT IGNORE INTO {$tableBlock} (`zMD5`,`zDate`,`hits`,`website`,`category`,`rulename`,`event`,`why`,`explain`,`blocktype`,`{$rp->userfield}`) VALUES ";
    while (list($sourcetable, $ligne) = each($LIST_TABLES_BLOCKED)) {
        $c++;
        if ($GLOBALS["VERBOSE"]) {
            echo "Parsing {$sourcetable}\n";
        }
        $sql = $rp->BuildQueryBlock($sourcetable);
        if (!$q->FIELD_EXISTS("{$sourcetable}", "uid")) {
            $q->QUERY_SQL("ALTER TABLE `{$sourcetable}` ADD `uid` VARCHAR( 128 ) NOT NULL ,ADD INDEX ( `uid` )");
        }
        $results = $q->QUERY_SQL($sql);
        if (!$q->ok) {
            ufdbguard_admin_events("{$q->mysql_error}\n{$sql}", __FUNCTION__, __FILE__, __LINE__, "reports");
            return;
        }
        if (mysql_num_rows($results) == 0) {
            continue;
        }
        $purc = round($c / $counttables, 2) * 100;
        progress($purc, $ID);
        $f = array();
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $zMD5 = md5(serialize($ligne));
            $sitename = $ligne["sitename"];
            $category = $ligne["category"];
            if ($category == null) {
                if (!isset($GLOBALS["CATEGORY"][$sitename])) {
                    $GLOBALS["CATEGORY"][$sitename] = $q->GET_CATEGORIES($sitename);
                }
                $category = $GLOBALS["CATEGORY"][$sitename];
            }
            $source = addslashes($ligne["source"]);
            $zDate = $ligne["zDate"];
            $hits = $ligne["hits"];
            $rulename = $ligne["rulename"];
            $event = $ligne["event"];
            $why = $ligne["why"];
            $explain = $ligne["explain"];
            $blocktype = $ligne["blocktype"];
            $category = addslashes($category);
            $f[] = "('{$zMD5}','{$zDate}','{$hits}','{$sitename}','{$category}','{$rulename}','{$event}','{$why}','{$explain}','{$blocktype}','{$source}')";
        }
        if (system_is_overloaded(__FILE__)) {
            sleep(5);
        }
    }
    $myisamchk = $unix->find_program("myisamchk");
    $myisampack = $unix->find_program("myisampack");
    $mysql_data = $unix->MYSQL_DATA_DIR();
    echo "OPTIMIZE TABLE {$tableBlock}\n";
    $q->QUERY_SQL("OPTIMIZE TABLE {$tableBlock}");
    echo "OPTIMIZE TABLE {$tablename}\n";
    $q->QUERY_SQL("OPTIMIZE TABLE {$tablename}");
    echo "LOCK TABLE {$tablename}\n";
    $q->QUERY_SQL("LOCK TABLE {$tablename} WRITE");
    echo "LOCK TABLE {$tableBlock}\n";
    $q->QUERY_SQL("LOCK TABLE {$tableBlock} WRITE");
    $q->QUERY_SQL("FLUSH TABLE {$tableBlock}");
    $q->QUERY_SQL("FLUSH TABLE {$tablename}");
    echo "myisamchk {$tablename}\n";
    shell_exec("{$myisamchk} -cFU {$mysql_data}/squidlogs/{$tablename}.MYI");
    echo "myisamchk {$tableBlock}\n";
    shell_exec("{$myisamchk} -cFU {$mysql_data}/squidlogs/{$tableBlock}.MYI");
    echo "myisampack {$tablename}\n";
    shell_exec("{$myisampack} -f {$mysql_data}/squidlogs/{$tablename}.MYI");
    echo "myisampack {$tableBlock}\n";
    shell_exec("{$myisampack} -f {$mysql_data}/squidlogs/{$tableBlock}.MYI");
    $q->QUERY_SQL("FLUSH TABLE {$tablename}");
    $q->QUERY_SQL("FLUSH TABLE {$tableBlock}");
    $rp->set_duration($unix->distanceOfTimeInWords($t, time(), true));
    progress(100, $ID);
}