Exemplo n.º 1
0
function inject($category, $table = null, $file = null)
{
    include_once dirname(__FILE__) . "/ressources/class.dansguardian.inc";
    $unix = new unix();
    $q = new mysql_squid_builder();
    if (is_file($category)) {
        $file = $category;
        $category_name = basename($file);
        echo "{$file} -> {$category_name}\n";
        if (preg_match("#(.+?)\\.gz\$#", $category_name)) {
            echo "{$category_name} -> gunzip\n";
            $new_category_name = str_replace(".gz", "", $category_name);
            $gunzip = $unix->find_program("gunzip");
            $target_file = dirname($file) . "/{$new_category_name}";
            $cmd = "/bin/gunzip -d -c \"{$file}\" >{$target_file} 2>&1";
            echo "{$cmd}\n";
            shell_exec($cmd);
            if (!is_file($target_file)) {
                echo "Uncompress failed\n";
                return;
            }
            $file = $target_file;
            $table = $new_category_name;
            $category = $q->tablename_tocat($table);
            echo "{$new_category_name} -> {$table}\n";
        } else {
            $table = $category_name;
            echo "{$new_category_name} -> {$table}\n";
            $category = $q->tablename_tocat($table);
        }
        echo "Table: {$table}\nSource File:{$file}\nCategory: {$category}\n";
    }
    if (!is_file($file)) {
        if (!is_file($table)) {
            echo "`{$table}` No such file\n";
        }
        if (is_file($table)) {
            $file = $table;
            $table = null;
        }
    }
    if ($table == null) {
        $table = "category_" . $q->category_transform_name($category);
        echo "Table will be {$table}\n";
    }
    if (!$q->TABLE_EXISTS($table)) {
        echo "{$table} does not exists, check if it is an official one\n";
        $dans = new dansguardian_rules();
        if (isset($dans->array_blacksites[$category])) {
            $q->CreateCategoryTable($category);
        }
    }
    if (!$q->TABLE_EXISTS($table)) {
        echo "`{$category}` -> no such table \"{$table}\"\n";
        return;
    }
    $sql = "SELECT COUNT(*) AS TCOUNT FROM {$table}";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        if (preg_match("#is marked as crashed and last#", $q->mysql_error)) {
            echo "`{$table}` -> crashed, remove \"{$table}\"\n";
            $q->QUERY_SQL("DROP TABLE {$table}");
            $q->QUERY_SQL("flush tables");
            $q = new mysql_squid_builder();
            echo "`{$table}` -> Create category \"{$category}\"\n";
            $q->CreateCategoryTable($category);
            $q->CreateCategoryTable($category);
            $q = new mysql_squid_builder();
        }
        if (!$q->TABLE_EXISTS($table)) {
            echo "`{$category}` -> no such table \"{$table}\"\n";
            return;
        }
    }
    if ($file == null) {
        $dir = "/var/lib/squidguard";
        if ($GLOBALS["SHALLA"]) {
            $dir = "/root/shalla/BL";
        }
        if (!is_file("{$dir}/{$category}/domains")) {
            echo "{$dir}/{$category}/domains no such file";
            return;
        }
        $file = "{$dir}/{$category}/domains";
    }
    if (!is_file($file)) {
        echo "{$file} no such file";
        return;
    }
    $sock = new sockets();
    $unix = new unix();
    $uuid = $unix->GetUniqueID();
    if ($uuid == null) {
        echo "No uuid\n";
        return;
    }
    echo "open {$file}\n";
    $handle = @fopen($file, "r");
    if (!$handle) {
        echo "Failed to open file\n";
        return;
    }
    $q = new mysql_squid_builder();
    if ($GLOBALS["CATTO"] != null) {
        $category = $GLOBALS["CATTO"];
    }
    $countstart = $q->COUNT_ROWS($table);
    $prefix = "INSERT IGNORE INTO {$table} (zmd5,zDate,category,pattern,uuid) VALUES ";
    echo "{$prefix}\n";
    $catz = new mysql_catz();
    $c = 0;
    $CBAD = 0;
    $CBADIP = 0;
    $CBADNULL = 0;
    while (!feof($handle)) {
        $c++;
        $www = trim(fgets($handle, 4096));
        if ($www == null) {
            $CBADNULL++;
            continue;
        }
        $www = str_replace('"', "", $www);
        if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $www)) {
            $CBADIP++;
            continue;
        }
        $www = trim(strtolower($www));
        if ($www == "thisisarandomentrythatdoesnotexist.com") {
            $CBAD++;
            continue;
        }
        if ($www == null) {
            $CBADNULL++;
            continue;
        }
        if (preg_match("#(.+?)\\s+(.+)#", $www, $re)) {
            $www = $re[1];
        }
        if (preg_match("#^\\.(.*)\$#", $www, $re)) {
            $www = $re[1];
        }
        if (strpos($www, "#") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "'") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "{") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "(") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, ")") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "%") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        $category2 = $catz->GET_CATEGORIES($www);
        if ($category2 != null) {
            if ($category2 == $category) {
                continue;
            }
            $md5 = md5($category . $www);
            if ($category == "p**n") {
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "hobby/arts") {
                    echo date("H:i:s") . " Remove {$www} from hobby/arts and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_hobby_arts WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "society") {
                    echo date("H:i:s") . " Remove {$www} from society and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_society WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "finance/realestate") {
                    echo date("H:i:s") . " Remove {$www} from finance/realestate and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_finance_realestate WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "science/computing") {
                    echo date("H:i:s") . " Remove {$www} from science/computing and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_science_computing WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "industry") {
                    echo date("H:i:s") . " Remove {$www} from industry and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_industry WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "proxy") {
                    echo date("H:i:s") . " Remove {$www} from proxy and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_proxy WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "searchengines") {
                    echo date("H:i:s") . " Remove {$www} from searchengines and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_searchengines WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "blog") {
                    echo date("H:i:s") . " Remove {$www} from blog and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_blog WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "forums") {
                    echo date("H:i:s") . " Remove {$www} from blog and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_blog WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/sports") {
                    echo date("H:i:s") . " Remove {$www} from recreation/sports and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_sports WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "hacking") {
                    echo date("H:i:s") . " Remove {$www} from hacking and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_hacking WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "malware") {
                    echo date("H:i:s") . " Remove {$www} from malware and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_malware WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "drugs") {
                    echo date("H:i:s") . " Remove {$www} from drugs and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_drugs WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "health") {
                    echo date("H:i:s") . " Remove {$www} from health and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_health WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "news") {
                    echo date("H:i:s") . " Remove {$www} from news and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_news WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "audio-video") {
                    echo date("H:i:s") . " Remove {$www} from audio-video and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_audio_video WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/schools") {
                    echo date("H:i:s") . " Remove {$www} from recreation/schools and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_schools WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "reaffected") {
                    echo date("H:i:s") . " Remove {$www} from reaffected and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_reaffected WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "warez") {
                    echo date("H:i:s") . " Remove {$www} from warez and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_warez WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "suspicious") {
                    echo date("H:i:s") . " Remove {$www} from suspicious and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_suspicious WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
            }
            if ($category == "gamble") {
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
            }
            if ($category == "proxy") {
                if ($category2 == "society") {
                    echo date("H:i:s") . " Remove {$www} from society and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_society WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "p**n") {
                    echo date("H:i:s") . " Remove {$www} from p**n and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_porn WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "science/computing") {
                    echo date("H:i:s") . " Remove {$www} from science/computing and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_science_computing WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "industry") {
                    echo date("H:i:s") . " Remove {$www} from industry and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_industry WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "filehosting") {
                    echo date("H:i:s") . " Remove {$www} from filehosting and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_filehosting WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "hacking") {
                    echo date("H:i:s") . " Remove {$www} from hacking and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_hacking WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "governments") {
                    echo date("H:i:s") . " Remove {$www} from governments and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_governments WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
            }
            if ($category == "spyware") {
                if ($category2 == "society") {
                    echo date("H:i:s") . " Remove {$www} from society and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_society WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "industry") {
                    echo date("H:i:s") . " Remove {$www} from industry and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_industry WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/sports") {
                    echo date("H:i:s") . " Remove {$www} from recreation/sports and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_sports WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/schools") {
                    echo date("H:i:s") . " Remove {$www} from recreation/schools and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_schools WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "searchengines") {
                    echo date("H:i:s") . " Remove {$www} from searchengines and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_searchengines WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "audio-video") {
                    echo date("H:i:s") . " Remove {$www} from audio-video and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_audio_video WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "suspicious") {
                    $q->QUERY_SQL("DELETE FROM category_suspicious WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "health") {
                    echo date("H:i:s") . " Remove {$www} from health and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_health WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "jobsearch") {
                    echo date("H:i:s") . " Remove {$www} from jobsearch and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_jobsearch WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "hobby/arts") {
                    $q->QUERY_SQL("DELETE FROM category_hobby_arts WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "science/computing") {
                    echo date("H:i:s") . " Remove {$www} from science_computing and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_science_computing WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/travel") {
                    echo date("H:i:s") . " Remove {$www} from recreation_travel and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_travel WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "dynamic") {
                    echo date("H:i:s") . " Remove {$www} from dynamic and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_dynamic WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "finance/realestate") {
                    echo date("H:i:s") . " Remove {$www} from finance_realestate and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_finance_realestate WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "isp") {
                    echo date("H:i:s") . " Remove {$www} from isp and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_isp WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "housing/accessories") {
                    echo date("H:i:s") . " Remove {$www} from housing/accessories and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_housing_accessories WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "malware") {
                    continue;
                }
                if ($category2 == "phishing") {
                    continue;
                }
            }
            echo date("H:i:s") . " {$www} {$category2} SKIP\n";
            continue;
        }
        $md5 = md5($www . $category);
        $n[] = "('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')";
        if (count($n) > 6000) {
            $sql = $prefix . @implode(",", $n);
            $q->QUERY_SQL($sql, "artica_backup");
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
                $n = array();
                continue;
            }
            $countend = $q->COUNT_ROWS($table);
            $final = $countend - $countstart;
            echo "" . numberFormat($c, 0, "", " ") . " items, " . numberFormat($final, 0, "", " ") . " new entries added - {$CBADNULL} bad entries for null value,{$CBADIP} entries for IP addresses\n";
            $n = array();
        }
    }
    fclose($handle);
    if (count($f) > 0) {
        if ($c > 0) {
            $countend = $q->COUNT_ROWS($table);
            $final = $countend - $countstart;
            echo "{$c} items, {$final} new entries added - {$CBAD} bad entries\n";
            $sql = $prefix . @implode(",", $n);
            $q->QUERY_SQL($sql, "artica_backup");
            if (!$q->ok) {
                echo $q->mysql_error . "\n{$sql}";
                continue;
            }
            $n = array();
        }
    }
    $countend = $q->COUNT_ROWS($table);
    $final = $countend - $countstart;
    echo "" . numberFormat($final, 0, "", " ") . " new entries added\n";
    @unlink($file);
}
function websites_uid_not_categorised($uid = null, $tablename = null, $aspid = false)
{
    if (isset($GLOBALS["websites_uid_not_categorised_{$uid}"])) {
        return;
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$uid}.pid";
    if ($aspid) {
        $pid = @file_get_contents($pidfile);
        $myfile = basename(__FILE__);
        if ($unix->process_exists($pid, $myfile)) {
            ufdbguard_admin_events("Task already running PID: {$pid}, aborting current task", __FUNCTION__, __FILE__, __LINE__, "stats");
            return;
        }
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $q = new mysql_squid_builder();
    if ($uid != null) {
        $uidtable = $q->uid_to_tablename($uid);
        $tablename = "www_{$uidtable}";
    }
    if (!$q->FIELD_EXISTS($tablename, "category")) {
        $q->QUERY_SQL("ALTER TABLE `{$tablename}` ADD `category` varchar(255), ADD INDEX (`category`)");
    }
    $sql = "SELECT familysite,`category` FROM `{$tablename}` GROUP BY familysite,`category` HAVING `category` IS NULL ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            echo "############# ERROR #########\n{$q->mysql_error}\\Line:" . __LINE__ . "\n#############\n";
        }
        return false;
    }
    $c = 0;
    $mysql_num_rows = mysql_num_rows($results);
    if ($mysql_num_rows == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$sql} (No rows)\n";
        }
        return true;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $sitename = $ligne["familysite"];
        $IpClass = new IP();
        if ($IpClass->isValid($sitename)) {
            if (isset($GLOBALS["IPCACHE"][$sitename])) {
                $t = time();
                $sitename = gethostbyaddr($sitename);
                events("{$tablename}: {$ligne["familysite"]} -> {$sitename} " . $unix->distanceOfTimeInWords($t, time()) . " gethostbyaddr() LINE:" . __LINE__);
                $GLOBALS["IPCACHE"][$sitename] = $sitename;
            }
        }
        $category = $q->GET_CATEGORIES($sitename);
        if ($IpClass->isValid($sitename)) {
            if ($category == null) {
                $category = "ipaddr";
            }
            $q->categorize($sitename, $category);
        }
        events("{$tablename}: {$ligne["familysite"]} -> {$sitename} [{$category}] LINE:" . __LINE__);
        if (strlen($category) > 0) {
            $category = mysql_escape_string2($category);
            $ligne["familysite"] = mysql_escape_string2($ligne["familysite"]);
            $sql = "UPDATE `{$tablename}` SET `category`='{$category}' WHERE familysite='{$ligne["familysite"]}'";
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                ufdbguard_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "stats");
                return;
            }
        }
    }
}
Exemplo n.º 3
0
function move_domain(){
	$q=new mysql_squid_builder();
	$domain=$_POST["move-domain"];
	$table=$q->cat_totablename($_POST["from_cat"]);
	$q->QUERY_SQL("DELETE FROM `$table` WHERE `pattern`='$domain'");
	$q->categorize($domain, $_POST["to_cat"],true);
	
}
function add_to_cat()
{
    $q = new mysql_squid_builder();
    $q->categorize($_POST["add-to-cat"], $_POST["category"], true);
}
Exemplo n.º 5
0
function save_category()
{
    if ($_GET["website"] == null) {
        return;
    }
    $www = trim(strtolower(base64_decode($_GET["website"])));
    if (preg_match("#^www\\.(.+?)\$#i", $www, $re)) {
        $www = $re[1];
    }
    $category = $_GET["category"];
    $q = new mysql_squid_builder();
    $q->categorize($www, $category);
}
Exemplo n.º 6
0
function elephantlist_Redirected($data)
{
    $CACHE = unserialize(@file_get_contents("/root/p**n-cache.db"));
    $q = new mysql_squid_builder();
    if (preg_match_all("#elephantlist\\.com\\/tp\\/out\\.php\\?to=(.+?)&#is", $data, $re)) {
        while (list($num, $ligne) = each($re[1])) {
            $sitename = $ligne;
            $familysite = $q->GetFamilySites($ligne);
            if (!isset($CACHE[$sitename])) {
                $q->categorize($sitename, "p**n");
                $CACHE[$sitename] = true;
            }
            if (!isset($CACHE[$familysite])) {
                $q->categorize($familysite, "p**n");
                $CACHE[$familysite] = true;
            }
            $f[] = "http://{$sitename}";
        }
    } else {
        echo "elephantlist_Redirected - nothing found\n";
        return array();
    }
    @file_put_contents("/root/p**n-cache.db", serialize($CACHE));
    return $f;
}
Exemplo n.º 7
0
function import_translated()
{
    $q = new mysql_squid_builder();
    $MAINZ = unserialize(@file_get_contents("/root/translated"));
    $translated_done = unserialize(@file_get_contents("/root/translated_done"));
    $max = count($MAINZ);
    $gg = new generic_categorize();
    $i = 1;
    while (list($www, $category) = each($MAINZ)) {
        echo "{$i}/{$max} {$www} ";
        $i++;
        if (isset($translated_done[$www])) {
            echo "\n";
            continue;
        }
        $category_artica = $gg->GetCategories($www);
        if ($category_artica != null) {
            echo "-> ARTICA {$category_artica}\n";
            $q->categorize($www, $category_artica);
            $translated_done[$www] = true;
            @file_put_contents("/root/translated_done", serialize($translated_done));
            continue;
        }
        $category_artica = $q->GET_CATEGORIES($www, true, true, true, true);
        if ($category_artica != null) {
            echo "-> ARTICA {$category}<>{$category_artica}\n";
            $translated_done[$www] = true;
            @file_put_contents("/root/translated_done", serialize($translated_done));
            continue;
        }
        echo "{$category}\n";
        $q->categorize($www, $category);
        $translated_done[$www] = true;
        @file_put_contents("/root/translated_done", serialize($translated_done));
    }
}
function CATEGORIZE()
{
    $category = $_POST["CATEGORIZE"];
    $www = $_POST["WWW"];
    $q = new mysql_squid_builder();
    $q->categorize($www, $category);
    $q->QUERY_SQL("DELETE FROM notcategorized WHERE sitename='{$www}'");
    if (!$q->ok) {
        echo $q->mysql_error;
    }
}
Exemplo n.º 9
0
    if ($sitename == null) {
        continue;
    }
    $category = UBoxGoogleSafeBrowsingGetCurl($sitename);
    if ($category == null) {
        echo "{$i}] {$sitename} -> NONE\n";
        usleep(500);
        $q->QUERY_SQL("UPDATE webtests SET SafeBrws=1 WHERE sitename='{$sitename}'");
        continue;
    }
    if (strpos($category, "We're sorry")) {
        echo "STOP!\n";
        return;
    }
    echo "{$i}] {$sitename} -> {$category}\n";
    $q->categorize($sitename, $category);
    $q->QUERY_SQL("DELETE FROM webtests WHERE sitename='{$sitename}'");
}
function UBoxGoogleSafeBrowsingGetCurl($szUrl)
{
    $f = new external_categorize(null);
    return $f->UBoxGoogleSafeBrowsingPhpGsbLookup($szUrl);
    $API_KEY = $GLOBALS["GoogleApiKey"];
    $client = "artica";
    $appver = "1.5.2";
    $pver = "3.0";
    $szPath = "https://sb-ssl.google.com/safebrowsing/api/lookup?client=" . $client . "&apikey=" . $API_KEY . "&appver=" . $appver . "&pver=" . $pver . "&url=" . $szUrl;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $szPath);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla");
 if ($familysite == $ligne["sitename"]) {
     $familysite = null;
 }
 if ($GLOBALS["OUTPUT"]) {
     echo "{$www} -> STAMP\n";
 }
 $q->QUERY_SQL("UPDATE webtests SET checked=1 WHERE sitename='{$ligne["sitename"]}'");
 if ($GLOBALS["OUTPUT"]) {
     echo "{$www} -> GET_CATEGORIES\n";
 }
 $articacats = trim($q->GET_CATEGORIES($ligne["sitename"], true, false));
 if ($GLOBALS["OUTPUT"]) {
     echo "{$ligne["sitename"]} -> \"{$articacats}\"\n";
 }
 if ($articacats != null) {
     $q->categorize($ligne["sitename"], $articacats);
     $unix->_syslog("{$percent}) {$ligne["sitename"]} = {$articacats}", __FILE__);
     continue;
 }
 if ($familysite != null) {
     $articacats = trim($q->GET_CATEGORIES($familysite, true, false));
     if ($GLOBALS["OUTPUT"]) {
         echo "{$ligne["sitename"]} {$familysite} -> {$articacats}\n";
     }
     if ($articacats != null) {
         $q->categorize($ligne["sitename"], $articacats);
         $unix->_syslog("{$percent}) {$ligne["sitename"]} = {$articacats}", __FILE__);
         continue;
     }
 }
 $ipaddr = gethostbyname($ligne["sitename"]);