function iscsi_search() { $unix = new unix(); $uuid = $unix->GetUniqueID(); $hostname = $unix->hostname_g(); $hostnameR = explode(".", $hostname); krsort($hostnameR); $hostname = @implode(".", $hostnameR); @file_put_contents("/etc/iscsi/initiatorname.iscsi", "GenerateName=yes\n"); $ip = $_GET["iscsi-search"]; $unix = new unix(); $iscsiadm = $unix->find_program("iscsiadm"); $cmd = "{$iscsiadm} --mode discovery --type sendtargets --portal {$ip} 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); writelogs_framework("{$cmd} = " . count($results) . " rows", __FUNCTION__, __FILE__, __LINE__); $array = array(); while (list($index, $line) = each($results)) { if (preg_match("#Invalid Initiatorname#", $line)) { shell_exec("/etc/init.d/open-iscsi restart"); return; } if (!preg_match("#([0-9\\.]+):([0-9]+),([0-9]+)\\s+(.+?):(.+)#", $line, $re)) { continue; } $array[$re[1]][] = array("PORT" => $re[2], "ID" => $re[3], "ISCSI" => $re[4], "FOLDER" => $re[5], "IP" => $re[1]); } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/iscsi-search.array", serialize($array)); @chmod("/usr/share/artica-postfix/ressources/logs/web/iscsi-search.array", 0755); }
function RefreshIndex() { $unix = new unix(); $nice = EXEC_NICE(); $sock = new sockets(); $users = new usersMenus(); $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); $wget = $unix->find_program("wget"); $SYSTEMID = $unix->GetUniqueID(); if ($SYSTEMID == null) { build_progress("System ID is Null !!!", 5); return; } build_progress_index("Register server...", 10); build_progress("Register server...", 10); shell_exec("{$nohup} {$nice} {$php} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"); if ($SYSTEMID == null) { build_progress_index("No system ID, force...", 15); build_progress("No system ID, force", 15); shell_exec("{$nice} /usr/share/artica-postfix/bin/artica-update -refresh-index --force >/dev/null 2>&1"); return; } $xMEM_TOTAL_INSTALLEE = $users->MEM_TOTAL_INSTALLEE; $CPU_NUMBER = $users->CPU_NUMBER; $LinuxDistributionFullName = $users->LinuxDistriFullName; if ($LinuxDistributionFullName == null) { $LinuxDistributionFullName = "Linux Default"; } $ARTICA_VERSION = GetCurrentVersion(); $hostname = $unix->hostname_g(); $CheckUserCount = CheckUserCount(); $RebootAfterArticaUpgrade = $sock->GET_INFO("RebootAfterArticaUpgrade"); if (!is_numeric($RebootAfterArticaUpgrade)) { $RebootAfterArticaUpgrade = 0; } $EnableScheduleUpdates = $sock->GET_INFO("EnableScheduleUpdates"); $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("EnableScheduleUpdates")); if (!is_numeric($EnableScheduleUpdates)) { $EnableScheduleUpdates = 0; } $ArticaAutoUpateOfficial = $sock->GET_INFO("ArticaAutoUpateOfficial"); $ArticaAutoUpateNightly = intval($sock->GET_INFO("ArticaAutoUpateNightly")); $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("ArticaUpdateIntervalAllways")); $OfficialArticaUri = $sock->GET_INFO("OfficialArticaUri"); if (!is_numeric($ArticaAutoUpateOfficial)) { $ArticaAutoUpateOfficial = 1; } if ($OfficialArticaUri == null) { $OfficialArticaUri = "http://articatech.net/artica.update.php"; } $uri = $OfficialArticaUri; $dmidecode = @file_get_contents("/etc/artica-postfix/dmidecode.cache.url"); @unlink($GLOBALS["MasterIndexFile"]); $tarballs_file = "/usr/share/artica-postfix/ressources/logs/web/tarballs.cache"; echo "Starting......: " . date("H:i:s") . " CPU NUMBER: {$CPU_NUMBER}\n"; echo "Starting......: " . date("H:i:s") . " Hostname..: {$hostname}\n"; echo "Starting......: " . date("H:i:s") . " Artica ver: {$ARTICA_VERSION}\n"; echo "Starting......: " . date("H:i:s") . " Users.....: {$CheckUserCount}\n"; build_progress_index("Configuration done...", 15); build_progress("Configuration done", 15); $DATA["UUID"] = $SYSTEMID; $DATA["MEM"] = $xMEM_TOTAL_INSTALLEE; $DATA["CPU"] = $CPU_NUMBER; $DATA["LINUX"] = $LinuxDistributionFullName; $DATA["VERSION"] = $ARTICA_VERSION; $DATA["HOSTNAME"] = $hostname; $DATA["USERS"] = $CheckUserCount; $DATA["DMICODE"] = $dmidecode; build_progress_index("Check repositories...", 20); build_progress("Check repositories", 20); $MAIN_URI = $unix->MAIN_URI(); echo "Starting......: " . date("H:i:s") . " Main URI..: {$MAIN_URI}\n"; $md5string = @md5_file($GLOBALS["MasterIndexFile"]); build_progress_index("Get Index...", 25); build_progress("Get Index...", 25); echo "Starting......: " . date("H:i:s") . " Update index file..\n"; $curl = new ccurl($OfficialArticaUri); $curl->parms["datas"] = base64_encode(serialize($DATA)); if (!$curl->get()) { echo "Last detected error: {$curl->error}\n"; build_progress_index("Get Index...{failed}", 110); build_progress("Get Index file !! FAILED !!", 110); _artica_update_event(0, "Unable to download index file with error {$curl->error_num}, {$curl->error}", null, __FILE__, __LINE__); return false; } @unlink("/etc/artica-postfix/settings/Daemons/ArticaUpdateRepos"); build_progress_index("Parse Index from repository", 40); build_progress("Parse Index from repository", 40); if (preg_match("#<ERROR>(.+?)</ERROR>#is", $curl->data, $re)) { echo "{$re[1]} !! FAILED !!\n"; build_progress_index("Corrupted index from repository !! FAILED !!", 110); build_progress("Corrupted index from repository !! FAILED !!", 110); return; } if (!preg_match("#<CONTENT>(.+?)</CONTENT>#is", $curl->data, $re)) { echo "Corrupted index from repository !! FAILED !!\n"; build_progress_index("Corrupted index from repository !! FAILED !!", 110); build_progress("Corrupted index from repository !! FAILED !!", 110); return; } $MAIN = unserialize(base64_decode($re[1])); if (!is_array($MAIN)) { echo "It is not an array...\n"; build_progress_index("Corrupted index from repository !! FAILED !!", 110); build_progress("Corrupted index from repository !! FAILED !!", 110); } build_progress_index("Retreive index from repository success", 100); @file_put_contents("/etc/artica-postfix/settings/Daemons/ArticaUpdateRepos", serialize($MAIN)); return true; }
function quicklinks_main_menu() { $sock = new sockets(); $users = new usersMenus(); if ($GLOBALS["AS_ROOT"]) { $users->AsSystemAdministrator = true; } $CachePage = "/usr/share/artica-postfix/ressources/logs/web/" . __FUNCTION__ . ".html"; if (!$GLOBALS["AS_ROOT"]) { if ($users->AsSystemAdministrator) { if (is_file($CachePage)) { $tpl = new templates(); echo $tpl->_ENGINE_parse_body(@file_get_contents($CachePage)); return; } } $uuid = $sock->getFrameWork("services.php?GetMyHostId=yes"); $debian_version = $sock->getFrameWork("system.php?debian_version=yes"); } else { $debian_version = debian_version_asroot(); $unix = new unix(); $uuid = $unix->GetUniqueID(); } $tpl = new templates(); $version = @file_get_contents(dirname(__FILE__) . "/VERSION"); $WizardSavedSettings = unserialize(base64_decode($sock->GET_INFO("WizardSavedSettings"))); $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos"))); if ($LicenseInfos["COMPANY"] == null) { $LicenseInfos["COMPANY"] = $WizardSavedSettings["company_name"]; } $productName = "Artica"; if (is_file(dirname(__FILE__) . "/ressources/templates/{$_COOKIE["artica-template"]}/ProducName.conf")) { $productName = @file_get_contents(dirname(__FILE__) . "/ressources/templates/{$_COOKIE["artica-template"]}/ProducName.conf"); } $tr[] = paragrapheWin("license-white-64.png", "{artica_license}", "GoToArticaLicense()"); $tr[] = paragrapheWin("update-64.png", "{update2}", "GotToArticaUpdate()"); $tr[] = paragrapheWin("64-settings-white.png", "{web_interface_settings}", "GotoArticaSettings()"); $tr[] = paragrapheWin("backup-64-white.png", "{backup_restore}", "GotoArticaBackup()"); $license_type = "Community Edition"; if ($users->CORP_LICENSE) { $license_type = "Entreprise Edition"; } $company = $tpl->javascript_parse_text("{company}"); $companytext = $LicenseInfos["COMPANY"]; $len = strlen($companytext); if ($len > 22) { $companytext = substr($companytext, 0, 19) . "..."; } $back = "x86-256-opac20.png"; if ($users->ArchStruct == 64) { $back = "x64-256-opac20.png"; } $html = "\n\t<div style='background-image:url(img/{$back});background-repeat:no-repeat;background-position:43% 20%;'>\n\t\t<div style='font-size:64px;color:white;width:767px'>{$productName} v.{$version}\n\t\t\t<div style='font-size:15px;text-align:right;border-top:1px solid #FFFFFF;padding-top:5px'>{$company}: {$companytext} | uuid: {$uuid} | {$license_type}</div>\n\t\t\t<div style='font-size:32px;text-align:right;'>{$users->LinuxDistriFullName} {$users->ArchStruct}bits</div>\n\t\t</div>\n\t\n\t\n\t" . CompileTr5_win($tr); $html = $html . "</div>"; if ($GLOBALS['AS_ROOT']) { @file_put_contents($CachePage, $html); } echo $html; }
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"; $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; } $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 include_tpl_file($path, $category) { $sock = new sockets(); $unix = new unix(); $uuid = $unix->GetUniqueID(); if ($uuid == null) { echo "UUID=NULL; Aborting"; return; } if ($category == null) { echo "CATEGORY=NULL; Aborting"; return; } if (!is_file($path)) { echo "{$path} no such file\n"; return; } $q = new mysql_squid_builder(); $q->CreateCategoryTable($category); $TableDest = "category_" . $q->category_transform_name($category); $array = array(); $f = @explode("\n", @file_get_contents($path)); $count_websites = count($f); $i = 0; $d = 0; $group = 0; $prefix = "INSERT IGNORE INTO {$TableDest} (zmd5,zDate,category,pattern,uuid) VALUES"; while (list($index, $website) = each($f)) { $i++; $d++; if ($d > 1000) { $group = $group + $d; events_tail("include_tpl_file({$category}):: importing {$group} sites..."); $d = 0; } if ($website == null) { return; } $www = trim(strtolower($website)); if (preg_match("#www\\.(.+?)\$#i", $www, $re)) { $www = $re[1]; } $md5 = md5($www . $category); if ($array[$md5]) { echo "{$www} already exists\n"; continue; } $enabled = 1; $sql_add[] = "('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $array[$md5] = true; if ($GLOBALS["SIMULATE"]) { echo "{$i}/{$count_websites}: {$sql_add}\n"; continue; } if (count($sql_add) > 500) { $sql = $prefix . @implode(",", $sql_add); $q->QUERY_SQL($sql); if (!$q->ok) { echo "{$i}/{$count_websites} Failed: {$www}\n"; } else { echo "{$i}/{$count_websites} Success: {$www}\n"; } $sql_add = array(); } } if (count($sql_add) > 0) { $sql = $prefix . @implode(",", $sql_add); $q->QUERY_SQL($sql); if (!$q->ok) { echo "{$i}/{$count_websites} Failed: {$www}\n"; } else { echo "{$i}/{$count_websites} Success: {$www}\n"; } $sql_add = array(); } echo " -------------------------------------------------\n"; echo count($array) . " websites done\n"; echo " -------------------------------------------------\n"; }
function xrun() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { echo "Starting......: " . date("H:i:s") . " [META]: Already executed {$pid}\n"; return; } if ($unix->SQUID_ENABLED() == 0) { echo "Starting......: " . date("H:i:s") . " [META]: Squid Not installed or disabled\n"; return; } $myuuid = $unix->GetUniqueID(); echo "Starting......: " . date("H:i:s") . " [META]: My UUID = {$myuuid}\n"; $md5_org = md5_file("/etc/squid3/acls_center_meta.conf"); $q = new mysql(); $results = $q->QUERY_SQL("SELECT gpid FROM metagroups_link WHERE uuid='{$myuuid}'", "metaclient"); $acls = new squid_acls(); $acls->Build_Acls(false, true); if (count($acls->acls_array) == 0) { @file_put_contents("/etc/squid3/acls_center_meta.conf", "\n"); @chown("/etc/squid3/acls_center_meta.conf", "squid"); @chgrp("/etc/squid3/acls_center_meta.conf", "squid"); $md5_new = md5_file("/etc/squid3/acls_center_meta.conf"); if ($md5_new != $md5_org) { $squidbin = $unix->LOCATE_SQUID_BIN(); squid_admin_mysql(1, "Reload proxy service for Meta acls", null, __FILE__, __LINE__); shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure"); } return; } $all_acls = @implode("\n", $acls->acls_array); $php = $unix->LOCATE_PHP5_BIN(); $ACLS = array(); while ($ligne = mysql_fetch_assoc($results)) { echo "{$myuuid} is a member of group id {$ligne["gpid"]}\n"; $ACLS = buildacls_fromgroup($ligne["gpid"], $ACLS); } $q = new mysql(); $results = $q->QUERY_SQL("SELECT * FROM meta_webfilters_acls WHERE metauuid='{$myuuid}'", "metaclient"); $aclsGroups = new squid_acls_groups(); $aclsGroups->AsMeta = true; while ($ligne = mysql_fetch_assoc($results)) { $aclname = $ligne["aclname"]; $httpaccess = $ligne["httpaccess"]; $httpaccess_data = $ligne["httpaccess_data"]; $reverse = false; $ID = $ligne["ID"]; $valueToAdd = null; if ($httpaccess == "deny_access_except") { $reverse = true; } echo "Starting......: " . date("H:i:s") . " [META]: aclname[{$ID}]: {$aclname}/{$httpaccess}\n"; if (isset($GLOBALS["ACLRULEXEC"][$ID])) { echo "Starting......: " . date("H:i:s") . " [META]: aclname[{$ID}]: Already executed, skip\n"; continue; } $Groups = $aclsGroups->buildacls_bytype_items($ID, $reverse); if (count($Groups) == 0) { echo "Starting......: " . date("H:i:s") . " [META]: aclname[{$ID}]: no group, skip...\n"; continue; } $GLOBALS["ACLRULEXEC"][$ID] = true; $firstToken = getFirstToken($httpaccess, $httpaccess_data, $ID); $ACLS[] = "{$firstToken} {$valueToAdd}" . @implode(" ", $Groups); } @file_put_contents("/etc/squid3/acls_center_meta.conf", "{$all_acls}\n" . @implode("\n", $ACLS) . "\n"); @chown("/etc/squid3/acls_center_meta.conf", "squid"); @chgrp("/etc/squid3/acls_center_meta.conf", "squid"); if (count($ACLS) == 0) { $md5_new = md5_file("/etc/squid3/acls_center_meta.conf"); if ($md5_new != $md5_org) { $squidbin = $unix->LOCATE_SQUID_BIN(); squid_admin_mysql(1, "Reload proxy service for Meta acls", null, __FILE__, __LINE__); shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure"); } return; } if (!$GLOBALS["NOCHECK"]) { if (!isInSquidConf()) { squid_admin_mysql(1, "Reconfigure proxy service for Meta acls", null, __FILE__, __LINE__); system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force --for-meta"); return; } } $md5_new = md5_file("/etc/squid3/acls_center_meta.conf"); if ($md5_new != $md5_org) { $squidbin = $unix->LOCATE_SQUID_BIN(); squid_admin_mysql(1, "Reload proxy service for Meta acls", null, __FILE__, __LINE__); shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure"); } }
function export_push() { $sock = new sockets(); $unix = new unix(); $export_stamp = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".EXPORT.time"; $export_time = $unix->file_time_min($export_stamp); if ($export_time < 60) { return; } $ArticaProxyStatisticsBackupFolder = $sock->GET_INFO("ArticaProxyStatisticsBackupFolder"); if ($ArticaProxyStatisticsBackupFolder == null) { $ArticaProxyStatisticsBackupFolder = "/home/artica/squid/backup-statistics"; } $ArticaProxyStatisticsBackupFolder = $ArticaProxyStatisticsBackupFolder . "/export"; $WizardStatsAppliance = unserialize(base64_decode($sock->GET_INFO("WizardStatsAppliance"))); $proto = "http"; if ($WizardStatsAppliance["SSL"] == 1) { $proto = "https"; } $uri = "{$proto}://{$WizardStatsAppliance["SERVER"]}:{$WizardStatsAppliance["PORT"]}/nodes.listener.php"; if ($GLOBALS["VERBOSE"]) { echo "{$uri}\n"; } $credentials["MANAGER"] = $WizardStatsAppliance["MANAGER"]; $credentials["PASSWORD"] = $WizardStatsAppliance["MANAGER-PASSWORD"]; $files = $unix->DirFiles($ArticaProxyStatisticsBackupFolder); Export_logs("PUSH Scanning {$ArticaProxyStatisticsBackupFolder}"); while (list($filename, $none) = each($files)) { $size = @filesize("{$ArticaProxyStatisticsBackupFolder}/{$filename}"); Export_logs("PUSH Scanning {$ArticaProxyStatisticsBackupFolder}/{$filename} ( {$size} bytes )"); $array = array("UUID" => $unix->GetUniqueID(), "HOSTNAME" => $unix->hostname_g(), "SIZE" => $size, "FILENAME" => $filename, "creds" => base64_encode(serialize($credentials))); if ($GLOBALS["VERBOSE"]) { echo "PUSH {$ArticaProxyStatisticsBackupFolder}/{$filename}\n"; } $curl = new ccurl($uri, false, null, true); if (!$curl->postFile("SQUID_STATS_CONTAINER", "{$ArticaProxyStatisticsBackupFolder}/{$filename}", $array)) { if ($GLOBALS["VERBOSE"]) { echo "Posting informations Failed {$curl->error}...\n"; } Export_logs("Failed {$curl->error}"); continue; } if (!preg_match("#<RESULTS>(.*?)</RESULTS>#is", $curl->data, $re)) { Export_logs("{$WizardStatsAppliance["SERVER"]} did not report something"); stats_admin_events(0, "{$WizardStatsAppliance["SERVER"]} did not report something", $curl->data, __FILE__, __LINE__); continue; } $RESULT = $re[1]; Export_logs("RESULT = {$RESULT}"); if ($RESULT != "SUCCESS") { Export_logs("Failed, {$WizardStatsAppliance["SERVER"]} report {$RESULT} "); stats_admin_events(0, "{$WizardStatsAppliance["SERVER"]} report {$RESULT}", $curl->data, __FILE__, __LINE__); continue; } Export_logs("Success, removing {$ArticaProxyStatisticsBackupFolder}/{$filename}"); @unlink("{$ArticaProxyStatisticsBackupFolder}/{$filename}"); stats_admin_events(0, "Success uploading {$filename} to {$WizardStatsAppliance["SERVER"]} report {$RESULT}", $curl->data, __FILE__, __LINE__); } }
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 WizardExecute($aspid = false) { $unix = new unix(); $sock = new sockets(); @chmod("/usr/share/artica-postfix/bin/process1", 0755); @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { die; } $pid = $unix->PIDOF_PATTERN(basename(__FILE__)); if ($pid != getmypid()) { return; } } @file_put_contents($pidfile, getmypid()); $unix->CREATE_NEW_UUID(); $uuid = $unix->GetUniqueID(); $php5 = $unix->LOCATE_PHP5_BIN(); $php = $php5; $nohup = $unix->find_program("nohup"); $squidbin = $unix->LOCATE_SQUID_BIN(); $DEBUG_LOG = "/var/log/artica-wizard.log"; @mkdir("/etc/artica-postfix/ldap_settings", 0755, true); @mkdir("/var/lib/ldap", 0755, true); $rmbin = $unix->find_program("rm"); writeprogress(5, "{set_permissions}..."); shell_exec("{$php} /usr/share/artica-postfix/exec.checkfolder-permissions.php --force --wizard"); writeprogress(10, "{uuid}: {$uuid}"); sleep(2); $savedsettings = unserialize(base64_decode(file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings"))); if (!is_array($savedsettings)) { writeprogress(110, "No saved settings Corrupted Array..."); die; } if (count($savedsettings) < 4) { writeprogress(110, "No saved settings no enough element..."); die; } $smtp_domainname = trim($savedsettings["smtp_domainname"]); if ($smtp_domainname == null) { if (isset($savedsettings["domain"])) { $smtp_domainname = $savedsettings["domain"]; } } if (strlen($smtp_domainname) < 3) { $smtp_domainname = "my-domain.com"; } if ($smtp_domainname == ".") { $smtp_domainname = "my-domain.com"; } if ($smtp_domainname == null) { $smtp_domainname = "my-domain.com"; } if (strpos($smtp_domainname, ".") == 0) { $smtp_domainname = "my-domain.com"; } writeprogress(12, "Using `{$smtp_domainname}` as LDAP suffix"); if (strpos($smtp_domainname, ".") > 0) { $smtp_domainname_exploded = explode(".", $smtp_domainname); writeprogress(12, "{$smtp_domainname} " . count($smtp_domainname_exploded) . " items"); $suffix = "dc=" . @implode(",dc=", $smtp_domainname_exploded); } else { $suffix = "dc={$smtp_domainname}"; } $SQUIDEnable = 1; $AsCategoriesAppliance = intval($savedsettings["AsCategoriesAppliance"]); $AsTransparentProxy = intval($savedsettings["AsTransparentProxy"]); $AsReverseProxyAppliance = intval($savedsettings["AsReverseProxyAppliance"]); $AsMetaServer = intval($savedsettings["AsMetaServer"]); $WizardWebFilteringLevel = $sock->GET_INFO("WizardWebFilteringLevel"); if (is_numeric($WizardWebFilteringLevel)) { $WizardSavedSettings["EnableWebFiltering"] = 1; } @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidDatabasesUtlseEnable", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/AsMetaServer", $AsMetaServer); @file_put_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance", $AsCategoriesAppliance); if ($AsCategoriesAppliance == 1) { $savedsettings["EnableWebFiltering"] = 0; @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0); $SQUIDEnable = 0; } if ($AsMetaServer == 1) { $savedsettings["EnableWebFiltering"] = 0; @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0); $SQUIDEnable = 0; } if ($AsReverseProxyAppliance == 1) { $AsCategoriesAppliance = 0; $AsTransparentProxy = 0; $savedsettings["EnableWebFiltering"] = 0; $savedsettings["adminwebserver"] = null; $savedsettings["second_webadmin"] = null; $SQUIDEnable = 0; @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableNginx", 1); } if ($savedsettings["administrator"] != null) { writeprogress(13, "{creating_accounts} {artica_manager}: {$savedsettings["administrator"]}"); sleep(2); @mkdir("/etc/artica-postfix/ldap_settings", 0755, true); @file_put_contents("/etc/artica-postfix/ldap_settings/admin", $savedsettings["administrator"]); @file_put_contents("/etc/artica-postfix/ldap_settings/password", $savedsettings["administratorpass"]); sleep(1); @unlink("/etc/artica-postfix/no-ldap-change"); @chmod("/usr/share/artica-postfix/bin/artica-install", 0755); writeprogress(14, "{building_openldap_configuration_file}"); system("/usr/share/artica-postfix/bin/artica-install --slapdconf >>{$DEBUG_LOG} 2>&1"); } else { writeprogress(13, "{creating_accounts} {artica_manager}: {default} Manager"); sleep(2); } writeprogress(15, "{creating_domain} LDAP {suffix}:{$suffix} "); @file_put_contents("/etc/artica-postfix/ldap_settings/suffix", $suffix); sleep(3); shell_exec("{$rmbin} -rf /var/lib/ldap/*"); @file_put_contents("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED", time()); writeprogress(16, "{reconfigure}: {openldap_server}"); @unlink("/etc/artica-postfix/no-ldap-change"); @chmod("/usr/share/artica-postfix/bin/artica-install", 0755); @chmod("/usr/share/artica-postfix/bin/process1", 0755); writeprogress(17, "{building_openldap_configuration_file}"); system("/usr/share/artica-postfix/bin/artica-install --slapdconf >>{$DEBUG_LOG} 2>&1"); writeprogress(18, "{restarting_service} {openldap_server} [{$suffix}] (1/3)"); shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --ldapd-conf --verbose >>{$DEBUG_LOG} 2>&1"); system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1"); usleep(800); writeprogress(19, "{restarting_service} {openldap_server} [{$suffix}] (2/3)"); system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1"); usleep(800); writeprogress(20, "{restarting_service} {openldap_server} [{$suffix}] (3/3)"); system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1"); sleep(2); writeprogress(22, "{refresh_global_settings}"); system('/usr/share/artica-postfix/bin/process1 --checkout --force --verbose ' . time()); writeprogress(23, "{scanning_hardware_software}"); system('/usr/share/artica-postfix/bin/process1 --force --verbose ' . time()); $SUBNIC = null; FINAL___(); @file_get_contents($pidfile, getmypid()); writeprogress(24, "{restarting_service}: {mysql_server}"); system('/etc/init.d/mysql restart --force'); sleep(1); $users = new usersMenus(); $q = new mysql(); writeprogress(25, "{creating_databases}"); sleep(1); $q->BuildTables(); $sock = new sockets(); $CPU_NUMBERS = $unix->CPU_NUMBER(); if ($CPU_NUMBERS == 0) { $CPU_NUMBERS = 4; } $MEMORY = $unix->MEM_TOTAL_INSTALLEE(); $MEMORY_TEXT = FormatBytes($MEMORY); $INTEL_CELERON = FALSE; writeprogress(25, "CPUs {$CPU_NUMBERS} - {memory}: {$MEMORY_TEXT}"); sleep(2); if ($MEMORY > 1) { if ($unix->MEM_TOTAL_INSTALLEE() < 624288) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 3); writeprogress(25, "{$MEMORY_TEXT} = Enable Intel Celeron mode...."); shell_exec("{$php5} /usr/share/artica-postfix/exec.intel.celeron.php"); $INTEL_CELERON = true; } } if (!$INTEL_CELERON) { if ($CPU_NUMBERS < 2) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 3); writeprogress(25, "CPUs:{$CPU_NUMBERS} = Intel Celeron mode...."); shell_exec("{$php5} /usr/share/artica-postfix/exec.intel.celeron.php"); $INTEL_CELERON = true; } } if (!$INTEL_CELERON) { if ($CPU_NUMBERS < 3) { @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 2); writeprogress(25, "CPUs:{$CPU_NUMBERS} = {features}: {no_statistics}"); sleep(1); } } writeprogress(26, "{creating_services}"); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php --force >/dev/null 2>&1 &"); if (is_file($squidbin)) { writeprogress(27, "{RestartingProxyStatisticsDatabase}"); shell_exec("/etc/init.d/squid-db restart >>{$DEBUG_LOG} 2>&1"); } $cyrus = $unix->LOCATE_CYRUS_DAEMON(); if (is_file($cyrus)) { writeprogress(28, "{restarting_service} SaslAuthd Daemon"); shell_exec("/etc/init.d/saslauthd restart"); writeprogress(29, "{restarting_service} Cyrus IMAP Daemon"); shell_exec("/etc/init.d/cyrus-imapd restart"); writeprogress(30, "{restarting_service} Postfix Daemon"); shell_exec("/etc/init.d/postfix restart"); } if (isset($savedsettings["GoldKey"])) { if (!$sock->IsGoldKey($savedsettings["GoldKey"])) { unset($savedsettings["GoldKey"]); } } if (isset($savedsettings["GoldKey"])) { if ($sock->IsGoldKey($savedsettings["GoldKey"])) { $WORKDIR = base64_decode("L3Vzci9sb2NhbC9zaGFyZS9hcnRpY2E="); $WORKFILE = base64_decode('LmxpYw=='); $WORKPATH = "{$WORKDIR}/{$WORKFILE}"; @file_put_contents($WORKPATH, "TRUE"); $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos"))); $LicenseInfos["UUID"] = $savedsettings["UUID_FIRST"]; $LicenseInfos["TIME"] = time(); $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos"); writeprogress(31, "{register_license}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register >/dev/null 2>&1"); writeprogress(32, "{saving_license}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1"); } } $ldap = new clladp(); writeprogress(40, "{building_organization} {$savedsettings["organization"]}"); if (!$ldap->AddOrganization($savedsettings["organization"])) { debug_logs("Building organization failed {$ldap->ldap_last_error}"); sleep(2); if (!$ldap->AddOrganization($savedsettings["organization"])) { debug_logs("Building organization failed 2/2 {$ldap->ldap_last_error}"); } } sleep(2); writeprogress(40, "{creating_domain} {$savedsettings["smtp_domainname"]}"); if (!$ldap->AddDomainEntity($savedsettings["organization"], $savedsettings["smtp_domainname"])) { debug_logs("AddDomainEntity failed {$ldap->ldap_last_error}"); } sleep(2); $timezone = $savedsettings["timezones"]; $sourcefile = "/usr/share/zoneinfo/{$timezone}"; if (is_file($sourcefile)) { writeprogress(60, "{timezone} {$timezone}"); @unlink("/etc/localtime"); @copy($sourcefile, "/etc/localtime"); @file_put_contents("/etc/timezone", $timezone); } else { writeprogress(60, "{$sourcefile} no such file"); } sleep(2); BUILD_NETWORK(); shell_exec("{$nohup} /etc/init.d/artica-status restart >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --reconfigure"); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --reconfigure-cyrus"); $FreeWebAdded = false; sleep(3); if (!is_file("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED")) { if (!$GLOBALS["NOREBOOT"]) { $reboot = true; } $rebootWarn = null; } if (is_file($squidbin)) { include_once dirname(__FILE__) . "/ressources/class.squid.inc"; if ($SQUIDEnable == 1) { $squid = new squidbee(); if ($AsTransparentProxy == 1) { $squid->hasProxyTransparent = 1; } @file_put_contents("/etc/artica-postfix/settings/Daemons/HyperCacheStoreID", 1); $q = new mysql(); if ($q->COUNT_ROWS("squid_caches_center", "artica_backup") == 0) { $cachename = basename($squid->CACHE_PATH); $q->QUERY_SQL("INSERT IGNORE INTO `squid_caches_center` (cachename,cpu,cache_dir,cache_type,cache_size,cache_dir_level1,cache_dir_level2,enabled,percentcache,usedcache,remove)\n\t\t\t\tVALUES('{$cachename}',1,'{$squid->CACHE_PATH}','{$squid->CACHE_TYPE}','2000','128','256',1,0,0,0)", "artica_backup"); } $zipfile = "/usr/share/artica-postfix/ressources/conf/upload/squid-zip-import.zip"; if (is_file($zipfile)) { writeprogress(63, "Analyze old squid.conf"); system("{$php5} /usr/share/artica-postfix/exec.squid.import.conf.php --zip"); } $squid->SaveToLdap(true); writeprogress(65, "{ReconfiguringProxy} {please_wait} 1/2"); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force"); } else { writeprogress(63, "{stopping} {proxy_service}"); shell_exec("/etc/init.d/squid stop"); } } if ($AsCategoriesAppliance == 1) { writeprogress(65, "{starting} Categories service"); shell_exec("/etc/init.d/ufdbcat start"); } if ($AsReverseProxyAppliance == 1) { writeprogress(65, "{starting} Reverse Proxy service..."); system("{$php5} /usr/share/artica-postfix/exec.nginx.php --build"); shell_exec("/etc/init.d/nginx restart"); } if (isset($savedsettings["EnablePDNS"])) { $sock->SET_INFO("EnablePDNS", $savedsettings["EnablePDNS"]); } if (isset($savedsettings["EnableDHCPServer"])) { $sock->SET_INFO("EnableDHCPServer", $savedsettings["EnableDHCPServer"]); } if (isset($savedsettings["EnableFreeRadius"])) { $sock->SET_INFO("EnableFreeRadius", $savedsettings["EnableFreeRadius"]); $sock->getFrameWork("freeradius.php?restart=yes"); } $restart_artica_status = false; if ($savedsettings["adminwebserver"] != null) { writeprogress(67, "{creating_webservices}{$rebootWarn}"); $sock->SET_INFO("EnableFreeWeb", 1); writeprogress(60, "{restarting_artica_status}"); $restart_artica_status = true; restart_artica_status(); writeprogress(68, "{restarting_webservices}"); restart_apache_src(); writeprogress(69, "{creating_default_website} {$savedsettings["adminwebserver"]}"); include_once dirname(__FILE__) . "/ressources/class.freeweb.inc"; $free = new freeweb($savedsettings["adminwebserver"]); $free->servername = $savedsettings["adminwebserver"]; $free->groupware = "ARTICA_MINIADM"; $free->CreateSite(); writeprogress(69, "{creating_default_website} {$savedsettings["adminwebserver"]}"); rebuild_vhost($savedsettings["adminwebserver"]); } if ($savedsettings["second_webadmin"] != null) { $sock->SET_INFO("EnableFreeWeb", 1); if (!$restart_artica_status) { writeprogress(70, "{creating_webservices}{$rebootWarn}"); restart_artica_status(); restart_apache_src(); } include_once dirname(__FILE__) . "/ressources/class.freeweb.inc"; $free = new freeweb($savedsettings["second_webadmin"]); $free->servername = $savedsettings["second_webadmin"]; $free->groupware = "ARTICA_ADM"; $free->CreateSite(); rebuild_vhost($savedsettings["second_webadmin"]); } if ($savedsettings["statsadministrator"] != null) { $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT id FROM radgroupcheck WHERE groupname='WebStatsAdm' LIMIT 0,1", "artica_backup")); $gpid = $ligne["id"]; if (!is_numeric($gpid)) { $gpid = 0; } if ($gpid == 0) { $sql = "INSERT IGNORE INTO radgroupcheck (`groupname`, `attribute`,`op`, `value`) VALUES ('WebStatsAdm', 'Auth-Type',':=', 'Accept');"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { $gpid = 0; } else { $gpid = $q->last_id; } if ($gpid > 0) { $savedsettings["statsadministrator"] = mysql_escape_string2($savedsettings["statsadministrator"]); $administratorpass = mysql_escape_string2(url_decode_special_tool($savedsettings["statsadministratorpass"])); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT value FROM radcheck WHERE username='******' LIMIT 0,1", "artica_backup")); if (trim($ligne["value"]) == null) { $sql = "INSERT IGNORE INTO radcheck (`username`, `attribute`, `value`) VALUES ('{$savedsettings["statsadministrator"]}', 'Cleartext-Password', '{$savedsettings["statsadministratorpass"]}');"; $q->QUERY_SQL($sql, "artica_backup"); } else { $sql = "UPDATE radcheck SET `value`='{$savedsettings["statsadministratorpass"]}' WHERE username='******'"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error; } } $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT username FROM radcheck WHERE username='******' AND groupname='WebStatsAdm' LIMIT 0,1", "artica_backup")); if (trim($ligne["username"]) == null) { $sql = "insert into radusergroup (username, groupname, priority,gpid) VALUES ('{$savedsettings["statsadministrator"]}', 'WebStatsAdm', 1,{$gpid});"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error; } } } } } $reboot = false; writeprogress(80, "{checking_parameters}{$rebootWarn}"); if (!is_file("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED")) { @file_put_contents("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED", time()); } $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.initslapd.php"); $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 1) { writeprogress(82, "{LaunchActiveDirectoryConnection}..."); system("{$php5} /usr/share/artica-postfix/exec.kerbauth.php --build --force --verbose >>{$DEBUG_LOG} 2>&1"); } $WizardWebFilteringLevel = $sock->GET_INFO("WizardWebFilteringLevel"); if (is_numeric($WizardWebFilteringLevel)) { $savedsettings["EnableWebFiltering"] = 1; } if ($savedsettings["EnableWebFiltering"] == 1) { writeprogress(82, "{activate_webfiltering_service}..."); sleep(2); EnableWebFiltering(); } else { writeprogress(82, "{no_web_filtering}"); sleep(2); } if ($users->POSTFIX_INSTALLED) { $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --build --force >>{$DEBUG_LOG} 2>&1"); } writeprogress(83, "{RestartingArticaStatus}"); system("/etc/init.d/artica-status restart --force"); $serverbin = $unix->find_program("zarafa-server"); if (is_file($serverbin)) { writeprogress(85, "{restarting_zarafa_services}{$rebootWarn}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.initdzarafa.php"); shell_exec("{$php5} /usr/share/artica-postfix/exec.zarafa-db.php --init"); shell_exec("/etc/init.d/zarafa-db restart"); shell_exec("/etc/init.d/zarafa-server restart"); shell_exec("/etc/init.d/zarafa-web restart"); } writeprogress(90, "{restarting_services}{$rebootWarn}"); shell_exec("{$nohup} /etc/init.d/artica-status reload >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.monit.php --build >/dev/null 2>&1"); shell_exec("{$nohup} /usr/share/artica-postfix/exec.web-community-filter.php --register >/dev/null 2>&1 &"); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); if ($EnableArticaMetaClient == 1) { shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &"); } if (is_file($squidbin)) { if ($SQUIDEnable == 1) { $q = new mysql_squid_builder(); if ($q->COUNT_ROWS("proxy_ports") == 0) { $WizardSqlWait = unserialize(@file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSqlWait")); while (list($none, $sql) = each($WizardSqlWait)) { $q->QUERY_SQL($sql); } } writeprogress(95, "{ReconfiguringProxy} {please_wait} 2/2"); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force"); writeprogress(97, "{checking_hypercache_feature} {please_wait}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.hypercache-dedup.php --wizard"); } } writeprogress(98, "{empty_watchdog_events} {please_wait}"); $q = new mysql(); $q->QUERY_SQL("TRUNCATE TABLE squid_admin_mysql", "artica_events"); $time = $unix->file_time_min("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED"); if (!$reboot) { writeprogress(100, "{done}"); FINAL___(); return; } writeprogress(100, "Rebooting"); FINAL___(); sleep(10); shell_exec($unix->find_program("reboot")); }
function build() { $sock = new sockets(); $emailprefix = null; $unix = new unix(); $ini = new Bs_IniHandler(); $IPADDRSSL = array(); $IPADDRSSL2 = array(); $users = new usersMenus(); $uuid = $unix->GetUniqueID(); if ($uuid == null) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} no UUID !!, return\n"; } return; } $ArticaSquidParameters = $sock->GET_INFO('ArticaSquidParameters'); $visible_hostname = $ini->_params["NETWORK"]["visible_hostname"]; if ($visible_hostname == null) { $visible_hostname = $unix->hostname_g(); } $SquidBinIpaddr = $sock->GET_INFO("SquidBinIpaddr"); $AllowAllNetworksInSquid = $sock->GET_INFO("AllowAllNetworksInSquid"); if (!is_numeric($AllowAllNetworksInSquid)) { $AllowAllNetworksInSquid = 1; } $ini->loadString($ArticaSquidParameters); NETWORK_ALL_INTERFACES(); $LISTEN_PORT = intval($ini->_params["NETWORK"]["LISTEN_PORT"]); $ICP_PORT = intval(trim($ini->_params["NETWORK"]["ICP_PORT"])); $certificate_center = $ini->_params["NETWORK"]["certificate_center"]; $SSL_BUMP = intval($ini->_params["NETWORK"]["SSL_BUMP"]); $ssl = false; if ($ICP_PORT == 0) { $ICP_PORT = 3130; } if ($LISTEN_PORT == 0) { $LISTEN_PORT = 3128; } $squid = new squidbee(); $q = new mysql_squid_builder(); $LogsWarninStop = intval($sock->GET_INFO("LogsWarninStop")); $chown = $unix->find_program("chown"); $python = $unix->find_program("python"); $StreamCachePort = intval($sock->GET_INFO("StreamCachePort")); $StreamCacheSize = intval($sock->GET_INFO("StreamCacheSize")); $StreamCacheSSLPort = intval($sock->GET_INFO("StreamCacheSSLPort")); $StreamCacheICPPort = intval($sock->GET_INFO("StreamCacheICPPort")); $StreamCacheLocalPort = intval($sock->GET_INFO("StreamCacheLocalPort")); $StreamCacheUrlRewiteNumber = intval($sock->GET_INFO("StreamCacheUrlRewiteNumber")); if ($StreamCacheSize == 0) { $StreamCacheSize = 1500; } if ($StreamCachePort == 0) { $StreamCachePort = 5559; } if ($StreamCacheLocalPort == 0) { $StreamCacheLocalPort = 5563; } if ($StreamCacheSSLPort == 0) { $StreamCacheSSLPort = 5560; } if ($StreamCacheICPPort == 0) { $StreamCacheICPPort = 5562; } if ($StreamCacheUrlRewiteNumber == 0) { $StreamCacheUrlRewiteNumber = 15; } $StreamCacheBindProxy = $squid->VerifStreamProxyBindIP(); $StreamCacheOutProxy = $sock->GET_INFO("StreamCacheOutProxy"); if (!isset($GLOBALS["NETWORK_ALL_INTERFACES"][$StreamCacheOutProxy])) { $StreamCacheOutProxy = null; } $f[] = ""; $f[] = "# ************** REDIRECTOR ********************"; $f[] = "url_rewrite_program {$python} /usr/share/videocache/videocache.py"; $f[] = "url_rewrite_children {$StreamCacheUrlRewiteNumber}"; $f[] = "url_rewrite_concurrency {$StreamCacheUrlRewiteNumber}"; $f[] = ""; $f[] = "# ***********************************************"; $f[] = ""; $f[] = "acl vc_deny_myport myport {$StreamCacheLocalPort}"; $f[] = ""; $f[] = "acl vc_deny_url url_regex -i \\.blip\\.tv\\/(.*)filename \\.hardsextube\\.com\\/videothumbs \\.xtube\\.com\\/(.*)(Thumb|videowall) www\\.youtube\\.com\\/"; $f[] = "acl vc_deny_url url_regex -i \\.(youtube|googlevideo)\\.com\\/.*\\/manifest"; $f[] = "acl vc_deny_url url_regex -i \\.(youtube|googlevideo)\\.com\\/videoplayback?.*playerretry=[0-9]"; $f[] = "acl vc_deny_dom dstdomain .manifest.youtube.com .manifest.googlevideo.com"; $f[] = "acl vc_deny_dom dstdomain .redirector.googlevideo.com .redirector.youtube.com"; $f[] = ""; $f[] = "acl vc_url url_regex -i \\/youku\\/[0-9A-Z]+\\/[0-9A-Z\\-]+\\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)"; $f[] = "acl vc_url url_regex -i \\/(.*)key=[a-z0-9]+(.*)\\.flv"; $f[] = "acl vc_url url_regex -i \\-xh\\.clients\\.cdn[0-9a-zA-Z]?[0-9a-zA-Z]?[0-9a-zA-Z]?\\.com\\/data\\/(.*)\\.flv"; $f[] = "acl vc_url url_regex -i \\.(youtube|youtube-nocookie|googlevideo)\\.com\\/feeds\\/api\\/videos\\/[0-9a-zA-Z_-]{11}\\/"; $f[] = "acl vc_url url_regex -i \\.(youtube|youtube-nocookie|googlevideo)\\.com\\/(videoplayback|get_video|watch_popup|user_watch|stream_204|get_ad_tags|get_video_info|player_204|ptracking|set_awesome)\\?"; $f[] = "acl vc_url url_regex -i \\.(youtube|youtube-nocookie|googlevideo)\\.com\\/(v|e|embed)\\/[0-9a-zA-Z_-]{11}"; $f[] = "acl vc_url url_regex -i \\.youtube\\.com\\/s\\? \\.youtube\\.com\\/api\\/stats\\/(atr|delayplay|playback|watchtime)\\?"; $f[] = "acl vc_url url_regex -i \\.(youtube|youtube-nocookie|googlevideo)\\.com\\/videoplayback\\/id\\/[0-9a-zA-Z_-]+\\/"; $f[] = "acl vc_url url_regex -i \\.android\\.clients\\.google\\.com\\/market\\/GetBinary\\/"; $f[] = "acl vc_url url_regex -i cs(.*)\\.vk\\.me\\/(.*)/([a-zA-Z0-9.]+)\\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)"; $f[] = "acl vc_url url_regex -i video(.*)\\.rutube\\.ru\\/(.*)/([a-zA-Z0-9.]+)\\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)Seg[0-9]+-Frag[0-9]+"; $f[] = ""; $f[] = "acl vc_dom_r dstdom_regex -i msn\\..*\\.(com|net)"; $f[] = "acl vc_dom_r dstdom_regex -i msnbc\\..*\\.(com|net)"; $f[] = "acl vc_dom_r dstdom_regex -i video\\..*\\.fbcdn\\.net"; $f[] = "acl vc_dom_r dstdom_regex -i myspacecdn\\..*\\.footprint\\.net"; $f[] = ""; $f[] = "acl vc_dom dstdomain .stream.aol.com .5min.com .msn.com .blip.tv .dmcdn.net .break.com .vimeo.com .vimeocdn.com video.thestaticvube.com"; $f[] = "acl vc_dom dstdomain .dailymotion.com .c.wrzuta.pl .v.imwx.com .mccont.com .myspacecdn.com video-http.media-imdb.com fcache.veoh.com"; $f[] = "acl vc_dom dstdomain .hardsextube.com .public.extremetube.phncdn.com .redtubefiles.com .video.pornhub.phncdn.com .videos.videobash.com"; $f[] = "acl vc_dom dstdomain .public.keezmovies.com .public.keezmovies.phncdn.com .slutload-media.com .public.spankwire.com .xtube.com"; $f[] = "acl vc_dom dstdomain .public.youporn.phncdn.com .xvideos.com .tube8.com .public.spankwire.phncdn.com .pornhub.com"; $f[] = ""; $f[] = ""; $f[] = "acl vc_deny_url url_regex -i crossdomain.xml"; $f[] = "acl vc_method method GET"; $f[] = "acl vc_header req_header X-Requested-With -i videocache"; $f[] = "url_rewrite_access deny vc_deny_myport"; $f[] = "url_rewrite_access deny !vc_method"; $f[] = "url_rewrite_access deny vc_header"; $f[] = "url_rewrite_access deny vc_deny_dom"; $f[] = "url_rewrite_access deny vc_deny_url"; $f[] = "url_rewrite_access allow vc_dom"; $f[] = "url_rewrite_access allow vc_url"; $f[] = "url_rewrite_access allow vc_dom_r"; CheckFilesAndSecurity(); $f = array(); $f[] = "[main]"; $StreamCacheBindHTTP = VerifHTTPIP(); $FreeWebListenPort = $sock->GET_INFO("FreeWebListenPort"); $FreeWebListenSSLPort = $sock->GET_INFO("FreeWebListenSSLPort"); if (!is_numeric($FreeWebListenSSLPort)) { $FreeWebListenSSLPort = 443; } if (!is_numeric($FreeWebListenPort)) { $FreeWebListenPort = 80; } if ($FreeWebListenPort != 80) { $StreamCacheBindHTTP = "{$StreamCacheBindHTTP}:{$FreeWebListenPort}"; } $SquidMgrListenPort = intval($sock->GET_INFO("SquidMgrListenPort")); $SquidDebugPortInterface = intval($sock->GET_INFO("SquidDebugPortInterface")); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache IP...............: {$StreamCacheBindHTTP}:{$FreeWebListenPort}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Proxy Port..............: {$SquidMgrListenPort}\n"; } if (!$users->CORP_LICENSE) { $emailprefix = "trial_"; } $f[] = "client_email = {$emailprefix}{$uuid}@articatech.com"; $f[] = "scheduler_pidfile = /var/run/squid/videocache.pid"; $f[] = "cache_host = {$StreamCacheBindHTTP}"; $f[] = "source_ip = 127.0.0.1"; $f[] = "videocache_user = squid"; $f[] = ""; $f[] = "# # # Proxy specifications # # #"; $f[] = "squid_access_log=/var/log/squid/access.log"; $f[] = "enable_access_log_monitoring = 1"; $f[] = "squid_access_log_format_combined = 0"; $f[] = ""; $f[] = "base_dir = /home/squid/videocache/"; $f[] = "logdir = /var/log/squid/"; $f[] = "pidfile = pidfile.txt"; $f[] = "this_proxy=127.0.0.1:{$SquidMgrListenPort}"; $f[] = "cache_swap_low = 90"; $f[] = "cache_swap_high = 93"; $f[] = "disk_cleanup_strategy = 1"; $f[] = "enable_videocache = 1"; $f[] = "offline_mode = 0"; $f[] = "base_dir_selection = 2"; $f[] = "# # # MySQL setup # # #"; $f[] = "db_hostname = /var/run/mysqld/squid-db.sock"; $f[] = "db_username = root"; $f[] = "db_password ="******"db_database = videocache"; $f[] = "max_cache_processes = 4"; $f[] = "max_cache_speed = 0"; $f[] = ""; $f[] = "# # # Remote Proxy # # #"; $f[] = "proxy =127.0.0.1:{$SquidMgrListenPort}"; $f[] = "max_video_size = 0"; $f[] = "min_video_size = 0"; $f[] = "force_video_size = 1"; $f[] = "logformat = %tl %p %s %i %w %c %v %m %d"; $f[] = "scheduler_logformat = %tl %p %s %i %w %c %v %m %d"; $f[] = "cleaner_logformat = %tl %p %s %w %c %v %m %d"; $f[] = "db_query_logformat = %tl %m"; $f[] = "timeformat = %d/%b/%Y:%H:%M:%S"; $f[] = "enable_videocache_log = 1"; $f[] = "enable_scheduler_log = 1"; $f[] = "enable_cleaner_log = 1"; $f[] = "enable_trace_log = 1"; $f[] = "enable_db_query_log = 0"; $f[] = "logfile = videocache.log"; $f[] = "scheduler_logfile = videocache-scheduler.log"; $f[] = "cleaner_logfile = videocache-cleaner.log"; $f[] = "tracefile = videocache-trace.log"; $f[] = "db_query_logfile = videocache-database.log"; $f[] = "max_logfile_size = 90"; $f[] = "max_scheduler_logfile_size = 90"; $f[] = "max_cleaner_logfile_size = 5"; $f[] = "max_tracefile_size = 5"; $f[] = "max_db_query_logfile_size = 5"; $f[] = "#------------------------------------------------------------------------------"; $f[] = "# Website Specific Options |"; $f[] = "#------------------------------------------------------------------------------"; $f[] = ""; $f[] = "# This option enables the caching of Android apps across various devices."; $f[] = "# This option's value can be either 0 or 1."; $f[] = "enable_android_cache = 1"; $f[] = ""; $f[] = "# These options set minimum and maximum size (in KB) for android apps. An app with"; $f[] = "# size smaller than min_android_app_size or larger than max_android_app_size will"; $f[] = "# not be cached. Set to zero (0) to disable."; $f[] = "# Default:"; $f[] = "# min_android_app_size = 1024"; $f[] = "# max_android_app_size = 0"; $f[] = "min_android_app_size = 1024"; $f[] = "max_android_app_size = 0"; $f[] = ""; $f[] = "# This option enables the caching of youtube videos."; $f[] = "# This option's value can be either 0 or 1."; $f[] = "#----------------------------------------------------------------------------"; $f[] = "# | IMPORTANT : Each supported website have an option to enable or disable |"; $f[] = "# | caching of its videos in the form enable_website_cache. You can opt to |"; $f[] = "# | cache the websites you want by disabling the caching for other websites |"; $f[] = "#----------------------------------------------------------------------------"; $f[] = "# Default : 1"; $f[] = "enable_youtube_cache = 1"; $f[] = ""; $f[] = "# This options determines if Videocache will cache different YouTube video"; $f[] = "# formats separately. Please select an appropriate algorithm from the listed below."; $f[] = "# Available strategies:"; $f[] = "# 1 : (disabled) Don't check for YouTube video formats. Cache one of the formats"; $f[] = "# and serve it for requests for all kinds of formats."; $f[] = "# 2 : (strict) Strictly check for YouTube formats and cache all formats separately."; $f[] = "# Consumes maximum bandwidth."; $f[] = "# 3 : (approximate) Check YouTube formats but with approximation. For example,"; $f[] = "# if a client asked for a video in 480p format and we already have 360p"; $f[] = "# format of the same video in cache, then serve 360p format and vice-versa."; $f[] = "# Default : 3"; $f[] = "enable_youtube_format_support = 3"; $f[] = ""; $f[] = "# This option enables the caching of HTML5 videos from YouTube."; $f[] = "# This option's value can be 0 or 1."; $f[] = "# Default : 1"; $f[] = "enable_youtube_html5_videos = 1"; $f[] = ""; $f[] = "# This option enables the caching of 3D videos from YouTube."; $f[] = "# This option's value can either be 0 or 1."; $f[] = "# Default : 1"; $f[] = "enable_youtube_3d_videos = 1"; $f[] = ""; $f[] = "# This option enables the caching of several video segments used by YouTube"; $f[] = "# to serve a single video. This option works only when enable_store_log_monitoring"; $f[] = "# option is enabled. This option's value can either be 0 or 1."; $f[] = "# Default : 1"; $f[] = "enable_youtube_partial_caching = 1"; $f[] = ""; $f[] = "# This option enforces the maximum video quality from Youtube. If a user browses"; $f[] = "# a video in higher quality format, Videocache will still cache and serve the video"; $f[] = "# in the format specified below or a lower quality format depending on the availability."; $f[] = "# Valid values : 480p, 720p, 1080p, 2304p (Please don't append p)"; $f[] = "# Default : 720"; $f[] = "max_youtube_video_quality = 720"; $f[] = ""; $f[] = "# This option will help in enhancing the performance of Videocache."; $f[] = "# If min_youtube_views is set to 1000, then Videocache will cache a video only"; $f[] = "# if it has received at least 1000 views on Youtube. Otherwise, video will not"; $f[] = "# be cached. Set this to 0 to disable this option."; $f[] = "# Default : 100"; $f[] = "min_youtube_views = 100"; $f[] = ""; $f[] = "# www.aol.com"; $f[] = "enable_aol_cache = 1"; $f[] = ""; $f[] = "# www.bing.com"; $f[] = "enable_bing_cache = 1"; $f[] = ""; $f[] = "# www.blip.tv"; $f[] = "enable_bliptv_cache = 1"; $f[] = ""; $f[] = "# www.break.com"; $f[] = "enable_breakcom_cache = 1"; $f[] = ""; $f[] = "# www.dailymotion.com"; $f[] = "enable_dailymotion_cache = 1"; $f[] = ""; $f[] = "# www.facebook.com"; $f[] = "enable_facebook_cache = 1"; $f[] = ""; $f[] = "# www.imdb.com"; $f[] = "enable_imdb_cache = 1"; $f[] = ""; $f[] = "# www.metacafe.com"; $f[] = "enable_metacafe_cache = 1"; $f[] = ""; $f[] = "# www.myspace.com"; $f[] = "enable_myspace_cache = 1"; $f[] = ""; $f[] = "# www.veoh.com"; $f[] = "enable_veoh_cache = 1"; $f[] = ""; $f[] = "# www.videobash.com"; $f[] = "enable_videobash_cache = 1"; $f[] = ""; $f[] = "# www.vimeo.com"; $f[] = "enable_vimeo_cache = 1"; $f[] = ""; $f[] = "# www.vube.com"; $f[] = "enable_vube_cache = 1"; $f[] = ""; $f[] = "# www.weather.com"; $f[] = "enable_weather_cache = 1"; $f[] = ""; $f[] = "# www.wrzuta.pl"; $f[] = "enable_wrzuta_cache = 1"; $f[] = ""; $f[] = "# www.youku.com"; $f[] = "enable_youku_cache = 1"; $f[] = ""; $f[] = "# Pr0n sites"; $f[] = "# www.extremetube.com"; $f[] = "enable_extremetube_cache = 1"; $f[] = ""; $f[] = "# www.hardsextube.com"; $f[] = "enable_hardsextube_cache = 1"; $f[] = ""; $f[] = "# www.keezmovies.com"; $f[] = "enable_keezmovies_cache = 1"; $f[] = ""; $f[] = "# www.pornhub.com"; $f[] = "enable_pornhub_cache = 1"; $f[] = ""; $f[] = "# www.redute.com"; $f[] = "enable_redtube_cache = 1"; $f[] = ""; $f[] = "# www.slutload.com"; $f[] = "enable_slutload_cache = 1"; $f[] = ""; $f[] = "# www.spankwire.com"; $f[] = "enable_spankwire_cache = 1"; $f[] = ""; $f[] = "# www.tube8.com"; $f[] = "enable_tube8_cache = 1"; $f[] = ""; $f[] = "# www.xhamster.com"; $f[] = "enable_xhamster_cache = 1"; $f[] = ""; $f[] = "# www.xtube.com"; $f[] = "enable_xtube_cache = 1"; $f[] = ""; $f[] = "# www.xvideos.com"; $f[] = "enable_xvideos_cache = 1"; $f[] = ""; $f[] = "# www.youporn.com"; $f[] = "enable_youporn_cache = 1"; $f[] = ""; $f[] = ""; $f[] = "#------------------------------------------------------------------------------"; $f[] = "# Apache Configuration Options |"; $f[] = "#------------------------------------------------------------------------------"; $f[] = ""; $f[] = "# Use this option if you don't want Videocache to generate Apache specific"; $f[] = "# configuration on your system. This can be used when you are using other"; $f[] = "# web server than Apache. Like lighttpd etc."; $f[] = "# Default : 0"; $f[] = "skip_apache_conf = 0"; $f[] = ""; $f[] = "# This option specifies the absolute path to your Apache's conf.d or extra"; $f[] = "# directory. Videocache will generate and save Videocache spcecific "; $f[] = "# configuration for Apache in this directory."; $f[] = "# Example : /etc/httpd/conf.d/ or /etc/apache2/conf.d/ or /etc/httpd/extra/"; $f[] = "# Default : NOT SET"; $httpdconf = $unix->LOCATE_APACHE_CONF_PATH(); $python = $unix->find_program("python"); $DAEMON_PATH = $unix->getmodpathfromconf($httpdconf); $sock->SET_INFO("EnableFreeWeb", 1); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache..................: {$DAEMON_PATH}\n"; } $f[] = "apache_conf_dir = {$DAEMON_PATH}"; $f[] = ""; $f[] = "# This option can be used to hide cache directories from your clients. Your"; $f[] = "# clients will not be able to browse the contents cache directories via HTTP"; $f[] = "# if this option is enabled. Browsing videos will not be affected."; $f[] = "# Default : 1"; $f[] = "hide_cache_dirs = 1"; $f[] = ""; @file_put_contents("/etc/videocache.conf", @implode("\n", $f)); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/videocache.conf done\n"; } shell_exec("{$python} /usr/share/videocache/vc-update >/dev/null 2>&1"); $f[] = array(); $StreamCacheCache = $sock->GET_INFO("StreamCacheCache"); $StreamCacheMainCache = $sock->GET_INFO("StreamCacheMainCache"); if ($StreamCacheCache == null) { $StreamCacheCache = "/home/squid/videocache"; } if ($StreamCacheMainCache == null) { $StreamCacheMainCache = "/home/squid/streamcache"; } $f[] = "##############################################################################"; $f[] = "# #"; $f[] = "# file : {$DAEMON_PATH}/videocache.conf #"; $f[] = "# #"; $f[] = "# Videocache is a squid url rewriter to cache videos from various websites. #"; $f[] = "# Check http://cachevideos.com/ for more details. #"; $f[] = "# #"; $f[] = "# ----------------------------- Note This ---------------------------------- #"; $f[] = "# Don't change this file under any circumstances. #"; $f[] = "# Use /etc/videocache.conf to configure Videocache. #"; $f[] = "# #"; $f[] = "##############################################################################"; $f[] = ""; $f[] = ""; $f[] = "Alias /crossdomain.xml /home/squid/videocache/youtube_crossdomain.xml"; $f[] = "Alias /videocache {$StreamCacheCache}/"; $f[] = "<Directory {$StreamCacheCache}/>"; $f[] = " Options -Indexes"; $f[] = " Order Allow,Deny"; $f[] = " Allow from all"; $f[] = " <IfModule mod_headers.c>"; $f[] = " Header add Videocache \"2.0.0\""; $f[] = " Header add X-Cache \"HIT from 192.168.1.210\""; $f[] = " </IfModule>"; $f[] = " <IfModule mod_mime.c>"; $f[] = " AddType video/webm .webm"; $f[] = " AddType application/vnd.android.package-archive .android"; $f[] = " </IfModule>"; $f[] = "</Directory>"; $f[] = ""; if (!is_file("{$DAEMON_PATH}/videocache.conf")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$DAEMON_PATH}/videocache.conf done\n"; } @file_put_contents("{$DAEMON_PATH}/videocache.conf", @implode("\n", $f)); } $f = array(); $LOCATE_APACHE_CONF_PATH = $unix->LOCATE_APACHE_CONF_PATH(); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache config: {$LOCATE_APACHE_CONF_PATH}\n"; } $APACHECONF = FALSE; $exp = explode("\n", @file_get_contents($LOCATE_APACHE_CONF_PATH)); while (list($index, $line) = each($exp)) { if (!preg_match("#Include.*?videocache\\.conf#", $line)) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache {$line} Done\n"; } $APACHECONF = true; } $php = $unix->LOCATE_PHP5_BIN(); if (!$APACHECONF) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Reconfigure Apache\n"; } shell_exec("{$php} /usr/share/artica-postfix/exec.freeweb.php --httpd"); } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Configuration done..\n"; } }
function meta_admin_mysql_check($nopid = false) { $f = array(); $unix = new unix(); $sock = new sockets(); $users = new usersMenus(); $hostname = $unix->hostname_g(); $BaseWorkDir = "{$GLOBALS["ARTICALOGDIR"]}/meta_admin_mysql"; $uuid = $unix->GetUniqueID(); if (!($handle = opendir($BaseWorkDir))) { echo "Failed open {$BaseWorkDir}\n"; return; } $hostname = "master"; $EnableArticaMetaServer = intval($sock->GET_INFO("EnableArticaMetaServer")); if ($EnableArticaMetaServer == 0) { $hostname = $unix->hostname_g(); } $q = new mysql(); if (!$q->test_mysql_connection()) { return; } if (!$q->TABLE_EXISTS("meta_admin_mysql", "artica_events")) { return; } if (!$q->ok) { meta_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__); return; } while (false !== ($filename = readdir($handle))) { if ($filename == ".") { continue; } if ($filename == "..") { continue; } $targetFile = "{$BaseWorkDir}/{$filename}"; if ($unix->file_time_min($targetFile) > 240) { @unlink($targetFile); continue; } $array = unserialize(@file_get_contents($targetFile)); if (!is_array($array)) { @unlink($targetFile); continue; } if (!is_numeric($array["TASKID"])) { $array["TASKID"] = 0; } $content = mysql_escape_string2($array["text"]); $subject = mysql_escape_string2($array["subject"]); $zdate = $array["zdate"]; $function = $array["function"]; $file = $array["file"]; $line = $array["line"]; $TASKID = $array["TASKID"]; $severity = $array["severity"]; $zm5 = md5("{$zdate}{$subject}{$function}{$file}{$line}{$uuid}"); meta_events("[meta_admin_mysql]:: {$subject} ", __FUNCTION__, __FILE__, __LINE__); $q->QUERY_SQL("INSERT IGNORE INTO `meta_admin_mysql`\n\t\t\t\t(`zmd5`,`uuid`,`zDate`,`content`,`subject`,`function`,`filename`,`line`,`severity`,`hostname`) VALUES\n\t\t\t\t('{$zm5}','{$uuid}','{$zdate}','{$content}','{$subject}','{$function}','{$file}','{$line}','{$severity}','{$hostname}')", "artica_events"); $q->QUERY_SQL("INSERT IGNORE INTO `meta_admin_mysql`\n\t\t\t\t(`zDate`,`content`,`subject`,`function`,`filename`,`line`,`severity`,`hostname`) VALUES\n\t\t\t\t('{$zdate}','{$content}','{$subject}','{$function}','{$file}','{$line}','{$severity}','{$hostname}')", "artica_events"); if (!$q->ok) { meta_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__); return; } @unlink($targetFile); } }
function caches_infos($aspid = false) { $cacheFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $cachePID = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if ($GLOBALS["FORCE"]) { ToSyslog("caches_infos(): Executed in force mode"); } $unix = new unix(); $sock = new sockets(); if (!$GLOBALS["VERBOSE"]) { if (system_is_overloaded(basename(__FILE__))) { EventsWatchdog("Overloaded system, aborting task..."); ToSyslog("caches_infos(): Overloaded system, aborting task"); writelogs("Overloaded system, aborting task...", __FUNCTION__, __FILE__, __LINE__); return; } if ($aspid) { $pid = @file_get_contents($cachePID); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($timepid < 15) { ToSyslog("caches_infos(): Already task PID: {$pid} running since {$timepid}Mn"); } $kill = $unix->find_program("{$kill}"); unix_system_kill_force($pid); } } } if ($GLOBALS["VERBOSE"]) { echo "init...\n"; } $q = new mysql_squid_builder(); if (!$GLOBALS["FORCE"]) { $CacheTime = $unix->file_time_min($cacheFile); if ($CacheTime < 15) { EventsWatchdog("Max 15Mn, current={$CacheTime} ({$cacheFile})..."); if ($GLOBALS["VERBOSE"]) { echo "Max 15Mn, current={$CacheTime}\n"; } return; } } $squid_pid = SQUID_PID(); if (!$unix->process_exists($squid_pid)) { $nohup = $unix->find_program("nohup"); squid_admin_mysql(0, "Squid-Cache is not running..., start it", null, __FILE__, __LINE__); ToSyslog("caches_infos(): Squid-Cache is not running..., start it"); shell_exec("{$nohup} /etc/init.d/squid start >/dev/null 2>&1 &"); return; } @unlink($cacheFile); @file_put_contents($cacheFile, time()); $ttl = $unix->PROCCESS_TIME_MIN($squid_pid); if ($unix->PROCCESS_TIME_MIN($squid_pid) < 5) { ToSyslog("caches_infos(): squid-cache running only since {$ttl}mn, aborting"); return; } ToSyslog("caches_infos(): Starting get Squid-cache informations."); $array = $unix->squid_get_cache_infos(); for ($i = 0; $i < 10; $i++) { $check = true; if (!is_array($array)) { if ($GLOBALS["VERBOSE"]) { echo "unix->squid_get_cache_infos() Not an array...\n"; } $check = false; sleep(1); $array = $unix->squid_get_cache_infos(); continue; } if (count($array) == 0) { if ($GLOBALS["VERBOSE"]) { echo "unix->squid_get_cache_infos() O items !!\n"; } $check = false; sleep(1); $array = $unix->squid_get_cache_infos(); continue; } if ($check) { break; } } if (!is_array($array)) { if ($GLOBALS["VERBOSE"]) { echo "unix->squid_get_cache_infos() Not an array...\n"; } return; } if (count($array) == 0) { if ($GLOBALS["VERBOSE"]) { echo basename(__FILE__) . "[" . __LINE__ . "] unix->squid_get_cache_infos() O items !!...\n"; } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array)); @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755); return; } @unlink("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db"); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array)); @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755); $uuid = $unix->GetUniqueID(); $profix = "INSERT IGNORE INTO cachestatus(uuid,cachedir,maxsize,currentsize,pourc) VALUES "; while (list($directory, $arrayDir) = each($array)) { $directory = trim($directory); if ($directory == null) { continue; } if ($GLOBALS["VERBOSE"]) { echo "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')\n"; } $f[] = "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')"; } if (count($f) > 0) { $q->QUERY_SQL("DELETE FROM cachestatus WHERE uuid='{$uuid}'"); $q->QUERY_SQL("{$profix}" . @implode(",", $f)); if (!$q->ok) { echo $q->mysql_error . "\n"; } } }
function HyperCache_create_license() { $sock = new sockets(); $unix = new unix(); $uuid = $unix->GetUniqueID(); if ($uuid == null) { if ($GLOBALS["VERBOSE"]) { echo "No system ID !\n"; } return; } $HyperCacheStoreID = intval($sock->GET_INFO("HyperCacheStoreID")); if ($HyperCacheStoreID == 0) { return; } $HyperCacheStoreIDLicense = $sock->GET_INFO("HyperCacheStoreIDLicense"); if ($HyperCacheStoreIDLicense == null) { echo "No license set..., continue in evalution mode\n"; return; } $uri = "https://svb.unveiltech.com/svblicenseaction.php?ma=86&license={$HyperCacheStoreIDLicense}"; $curl = new ccurl($uri); $curl->parms["ma"] = 86; $curl->parms["license"] = $HyperCacheStoreIDLicense; $curl->parms["artid"] = $uuid; if (!$curl->get()) { echo "HyperCache:: Check license failed\n"; return false; } echo $curl->data . "\n"; if (intval(trim($curl->data)) == 1) { return true; } if (stripos($curl->data, "The Activation Code is not valid") > 0) { return false; } if (stripos($curl->data, "The Activation Code is already activated") > 0) { return true; } if (stripos($curl->data, "The Activation Code is already activated with another server") > 0) { return false; } }
function Export($asPid = false) { return; $unix = new unix(); $restartProcess = false; $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if ($GLOBALS["VERBOSE"]) { echo "CacheTime: {$cachetime}\n"; } $restart_cmd = trim("{$nohup} {$php5} " . __FILE__ . " --export >/dev/null 2>&1 &"); $sock = new sockets(); shell_exec(trim("{$nohup} {$php5} " . __FILE__ . " --export-not-categorized >/dev/null 2>&1 &")); if ($asPid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } @file_put_contents($pidfile, getmypid()); } $uuid = $unix->GetUniqueID(); if ($uuid == null) { if ($GLOBALS["VERBOSE"]) { echo "No system ID !\n"; } return; } $q = new mysql_squid_builder(); $tables = $q->LIST_TABLES_CATEGORIES(); $c = 0; while (list($table, $www) = each($tables)) { $limit = null; $limitupate = null; if (!preg_match("#category_(.+?)\$#", $table)) { continue; } if (!$q->TABLE_EXISTS($table)) { continue; } $sql = "SELECT COUNT(zmd5) as tcount FROM {$table} WHERE sended=0 and enabled=1"; $q->CreateCategoryTable(null, $table); $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); if (!$q->ok) { writelogs("{$table} {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__); return; } $prefix = "INSERT IGNORE INTO categorize (zmd5 ,pattern,zDate,uuid,category) VALUES"; if ($ligne["tcount"] > 0) { writelogs("{$table} {$ligne["tcount"]} items to export", __FUNCTION__, __FILE__, __LINE__); if ($ligne["tcount"] > 5000) { $limit = "LIMIT 0,5000"; $limitupate = "LIMIT 5000"; } $results = $q->QUERY_SQL("SELECT * FROM {$table} WHERE sended=0 AND enabled=1 {$limit}"); while ($ligne2 = mysql_fetch_array($results, MYSQL_ASSOC)) { $md5 = md5("{$ligne2["category"]}{$ligne2["pattern"]}"); $f[] = "('{$md5}','{$ligne2["pattern"]}','{$ligne2["zDate"]}','{$uuid}','{$ligne2["category"]}')"; $c++; if (count($f) > 1000) { $q->QUERY_SQL($prefix . @implode(",", $f)); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } $f = array(); } } $q->QUERY_SQL("UPDATE {$table} SET sended=1 WHERE sended=0 {$limitupate}"); } } if (count($f) > 0) { $q->QUERY_SQL($prefix . @implode(",", $f)); $f = array(); } $ALLCOUNT = $q->COUNT_ROWS("categorize"); if ($GLOBALS["VERBOSE"]) { echo "Total row in categorize table: {$ALLCOUNT}\n"; } if ($ALLCOUNT > 2000) { $restartProcess = true; } $sql = "SELECT * FROM categorize ORDER BY zDate DESC LIMIT 0,2000"; if ($GLOBALS["VERBOSE"]) { echo "Execute query\n"; } $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error . "\n{$sql}\n"; return; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["category"] == null) { continue; } if ($ligne["pattern"] == null) { continue; } if ($ligne["zmd5"] == null) { continue; } $logsExp[] = "{$ligne["pattern"]}:{$ligne["category"]}"; $array[$ligne["zmd5"]] = array("category" => $ligne["category"], "pattern" => $ligne["pattern"], "uuid" => $ligne["uuid"]); } if (!isset($array)) { WriteMyLogs("Nothing to export", __FUNCTION__, __FILE__, __LINE__); return; } if (!is_array($array)) { WriteMyLogs("Nothing to export", __FUNCTION__, __FILE__, __LINE__); return; } if (count($array) == 0) { WriteMyLogs("Nothing to export", __FUNCTION__, __FILE__, __LINE__); return; } $WHITELISTED["1636b7346f2e261c5b21abfcaef45a69"] = true; $WHITELISTED["8cdd119c-2dc1-452d-b9d0-451c6046464f"] = true; if (!isset($WHITELISTED[$uuid])) { if (count($array) > 500) { $q->QUERY_SQL("TRUNCATE TABLE categorize_delete"); WriteMyLogs("Too much categories to export " . count($array) . ">500, aborting", __FUNCTION__, __FILE__, __LINE__, "export"); } } WriteMyLogs("Exporting " . count($array) . " websites", __FUNCTION__, __FILE__, __LINE__); $f = base64_encode(serialize($array)); $unix = new unix(); $URIBASE = $unix->MAIN_URI(); if ($GLOBALS["VERBOSE"]) { echo "Sending " . strlen($f) . " bytes to repository server\n"; } $curl = new ccurl("{$URIBASE}/shalla-orders.php", false); $curl->parms["COMMUNITY_POST"] = $f; if (!$curl->get()) { writelogs("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers", __FUNCTION__, __FILE__, __LINE__); squid_admin_mysql("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers \"{$curl->error}\"", null, __FILE__, __LINE__, "export"); return null; } if (preg_match("#<ANSWER>OK</ANSWER>#is", $curl->data)) { squid_admin_mysql(2, "Exporting success " . count($array) . " websites", null, __FILE__, __LINE__); if (count($logsExp) < 10) { $textadd = @implode(",", $logsExp); } $curl = new ccurl("{$URIBASE}/webfilters-instant.php?checks=yes", false); $curl->NoHTTP_POST = true; if (!$curl->get()) { squid_admin_mysql(1, "Failed to order to build webfilter instant with HTTP ERROR: `{$curl->error}`", null, __FILE__, __LINE__, "export"); } if (preg_match("#<ANSWER>OK</ANSWER>#is", $curl->data)) { writelogs_squid("Success to order to build webfilter instant", __FUNCTION__, __FILE__, __LINE__, "export"); } else { writelogs_squid("Failed to order to build webfilter instant ANSWER NOT OK in server response.", __FUNCTION__, __FILE__, __LINE__, "export"); if ($GLOBALS["VERBOSE"]) { echo $curl->data; } } writelogs("Deleting websites...", __FUNCTION__, __FILE__, __LINE__); while (list($md5, $datas) = each($array)) { $sql = "DELETE FROM categorize WHERE zmd5='{$md5}'"; $q->QUERY_SQL($sql, "artica_backup"); } if ($restartProcess) { writelogs("{$restart_cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($restart_cmd); } else { $q->QUERY_SQL("OPTIMIZE TABLE categorize", "artica_backup"); } } else { WriteMyLogs("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers \"{$curl->data}\"", __FUNCTION__, __FILE__, __LINE__, "export"); } }
function caches_infos() { $unix = new unix(); $squid_pid = SQUID_PID(); if (!$unix->process_exists($squid_pid)) { $nohup = $unix->find_program("nohup"); squid_admin_mysql(0, "Squid-Cache is not running...", null, __FILE__, __LINE__); return; } $ttl = $unix->PROCCESS_TIME_MIN($squid_pid); if ($unix->PROCCESS_TIME_MIN($squid_pid) < 5) { ToSyslog("caches_infos(): squid-cache running only since {$ttl}mn, aborting"); return; } ToSyslog("caches_infos(): Starting get Squid-cache informations."); $array = $unix->squid_get_cache_infos(); for ($i = 0; $i < 10; $i++) { $check = true; if (!is_array($array)) { if ($GLOBALS["VERBOSE"]) { echo "unix->squid_get_cache_infos() Not an array...\n"; } $check = false; sleep(1); $array = $unix->squid_get_cache_infos(); continue; } if (count($array) == 0) { if ($GLOBALS["VERBOSE"]) { echo "unix->squid_get_cache_infos() O items !!\n"; } $check = false; sleep(1); $array = $unix->squid_get_cache_infos(); continue; } if ($check) { break; } } if (!is_array($array)) { if ($GLOBALS["VERBOSE"]) { echo "unix->squid_get_cache_infos() Not an array...\n"; } return; } if (count($array) == 0) { if ($GLOBALS["VERBOSE"]) { echo basename(__FILE__) . "[" . __LINE__ . "] unix->squid_get_cache_infos() O items !!...\n"; } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array)); @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755); return; } @unlink("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db"); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array)); @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755); $q = new mysql_squid_builder(); $uuid = $unix->GetUniqueID(); $profix = "INSERT IGNORE INTO cachestatus(uuid,cachedir,maxsize,currentsize,pourc) VALUES "; while (list($directory, $arrayDir) = each($array)) { $directory = trim($directory); if ($directory == null) { continue; } if ($GLOBALS["VERBOSE"]) { echo "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')\n"; } $f[] = "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')"; } if (count($f) > 0) { $q->QUERY_SQL("TRUNCATE TABLE cachestatus"); $q->QUERY_SQL("{$profix}" . @implode(",", $f)); if (!$q->ok) { echo $q->mysql_error . "\n"; } } }
function caches_delete() { $unix = new unix(); $uuid = $unix->GetUniqueID(); events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] uuid=`{$uuid}`", __FUNCTION__, __LINE__); $q = new mysql(); $results = $q->QUERY_SQL("SELECT * FROM squid_caches32 WHERE enabled=0 AND uuid='{$uuid}' AND ToDelete=1", "artica_backup"); if (mysql_num_rows($results) == 0) { events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] No cache to delete for `{$uuid}`...aborting task...", __FUNCTION__, __LINE__); return; } events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] Reconfiguring squid-cache in order to disconnect caches...", __FUNCTION__, __LINE__); $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] reconfiguring the proxy cache", __FUNCTION__, __LINE__); $results = array(); exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force 2>&1", $results); while (list($a, $b) = each($results)) { events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$b}", __FUNCTION__, __LINE__); } events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] restarting the proxy cache", __FUNCTION__, __LINE__); $results = array(); exec("{$php5} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force --script=" . basename(__FILE__) . " 2>&1", $results); while (list($a, $b) = each($results)) { events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$b}", __FUNCTION__, __LINE__); } $rm = $unix->find_program("rm"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $cache_directory = $ligne["cache_directory"]; $cacheid = $ligne["cacheid"]; if (!is_dir($cache_directory)) { events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$cache_directory} no such directory, removing the cache", __FUNCTION__, __LINE__); $q->QUERY_SQL("DELETE FROM squid_caches32 WHERE cacheid='{$cacheid}'", "artica_backup"); continue; } events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] Stamp cache {$cacheid} to be build", __FUNCTION__, __LINE__); $cacheid_array[$cacheid] = $cache_directory; $q->QUERY_SQL("UPDATE squid_caches32 SET Building=1 WHERE cacheid='{$cacheid}'", "artica_backup"); events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] removing {$cache_directory}", __FUNCTION__, __LINE__); $cmd = "{$nohup} {$rm} -rf {$cache_directory} >/dev/null 2>&1 &"; } $c = 0; while (count($cacheid_array) > 0) { sleep(2); $c++; reset($cacheid_array); while (list($cacheid, $cache_directory) = each($cacheid_array)) { if (!is_dir($cache_directory)) { events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$cache_directory} deleted, removing the cache", __FUNCTION__, __LINE__); $q->QUERY_SQL("DELETE FROM squid_caches32 WHERE cacheid='{$cacheid}'", "artica_backup"); unset($cacheid_array[$cacheid]); continue; } events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$cache_directory} still exists, waiting " . count($cacheid_array) . " cache(s)...", __FUNCTION__, __LINE__); } if ($c > 900) { events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] timeout...", __FUNCTION__, __LINE__); break; } } }
function GetUniqueID() { $unix = new unix(); $uuid = $unix->GetUniqueID(); echo "<articadatascgi>" . base64_encode($uuid) . "</articadatascgi>"; }
function PUSH_STATS_FILE($filepath) { $sock = new sockets(); $unix = new unix(); $q = new mysql_squid_builder(); $EnableSquidRemoteMySQL = intval($sock->GET_INFO("EnableSquidRemoteMySQL")); events("PUSH_STATS_FILE: EnableSquidRemoteMySQL = {$EnableSquidRemoteMySQL}"); $WizardStatsAppliance = unserialize(base64_decode($sock->GET_INFO("WizardStatsAppliance"))); if (isset($WizardStatsAppliance["SERVER"])) { if ($WizardStatsAppliance["SERVER"] != null) { $EnableSquidRemoteMySQL = 1; } } $proto = "http"; if ($WizardStatsAppliance["SSL"] == 1) { $proto = "https"; } $uri = "{$proto}://{$WizardStatsAppliance["SERVER"]}:{$WizardStatsAppliance["PORT"]}/nodes.listener.php"; if ($EnableSquidRemoteMySQL == 0) { return false; } $size = @filesize($filepath); $filename = basename($filepath); $array = array("SQUID_BEREKLEY" => true, "UUID" => $unix->GetUniqueID(), "HOSTNAME" => $unix->hostname_g(), "SIZE" => $size, "FILENAME" => $filename); $curl = new ccurl($uri, false, null, true); $curl->x_www_form_urlencoded = false; if (!$curl->postFile(basename($filepath), $filepath, $array)) { events("PUSH_STATS_FILE: Failed " . $curl->error); return false; } return true; }
function RefreshIndex() { $unix = new unix(); $nice = EXEC_NICE(); $sock = new sockets(); $users = new usersMenus(); $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); $wget = $unix->find_program("wget"); $SYSTEMID = $unix->GetUniqueID(); if ($SYSTEMID == null) { build_progress("System ID is Null !!!", 5); return; } build_progress("Register server...", 10); shell_exec("{$nohup} {$nice} {$php} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"); if ($SYSTEMID == null) { build_progress("No system ID, force", 15); shell_exec("{$nice} /usr/share/artica-postfix/bin/artica-update -refresh-index --force >/dev/null 2>&1"); return; } $xMEM_TOTAL_INSTALLEE = $users->MEM_TOTAL_INSTALLEE; $CPU_NUMBER = $users->CPU_NUMBER; $LinuxDistributionFullName = $users->LinuxDistriFullName; if ($LinuxDistributionFullName == null) { $LinuxDistributionFullName = "Linux Default"; } $ARTICA_VERSION = GetCurrentVersion(); $hostname = $unix->hostname_g(); $CheckUserCount = CheckUserCount(); $dmidecode = @file_get_contents("/etc/artica-postfix/dmidecode.cache.url"); $uriplus = "{$SYSTEMID};{$xMEM_TOTAL_INSTALLEE};{$CPU_NUMBER};{$LinuxDistributionFullName};{$ARTICA_VERSION};{$hostname};{$CheckUserCount};{$dmidecode}"; $uriplus = urlencode($uriplus); @unlink($GLOBALS["MasterIndexFile"]); $tarballs_file = "/usr/share/artica-postfix/ressources/logs/web/tarballs.cache"; echo "Starting......: " . date("H:i:s") . " CPU NUMBER: {$CPU_NUMBER}\n"; echo "Starting......: " . date("H:i:s") . " Hostname..: {$hostname}\n"; echo "Starting......: " . date("H:i:s") . " Artica ver: {$ARTICA_VERSION}\n"; echo "Starting......: " . date("H:i:s") . " Users.....: {$CheckUserCount}\n"; build_progress("Configuration done", 15); $ini = new iniFrameWork(); $ini->loadFile('/etc/artica-postfix/artica-update.conf'); if (trim($ini->_params["AUTOUPDATE"]["uri"]) == null) { $ini->_params["AUTOUPDATE"]["uri"] = "http://www.articatech.net/auto.update.php"; } if (!isset($ini->_params["AUTOUPDATE"]["enabled"])) { $ini->_params["AUTOUPDATE"]["enabled"] = "yes"; } if ($ini->_params["AUTOUPDATE"]["enabled"] == null) { $ini->_params["AUTOUPDATE"]["enabled"] = "yes"; } if (!is_numeric(trim($ini->_params["AUTOUPDATE"]["CheckEveryMinutes"]))) { $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"] = 60; } $uri = $ini->_params["AUTOUPDATE"]["uri"]; $arrayURI = parse_url($uri); build_progress("Check repositories", 20); $MAIN_URI = $unix->MAIN_URI(); echo "Starting......: " . date("H:i:s") . " Main URI..: {$MAIN_URI}\n"; $md5string = @md5_file($GLOBALS["MasterIndexFile"]); build_progress("Get TarBalls...", 25); echo "Starting......: " . date("H:i:s") . " Update tarballs..\n"; $curl = new ccurl("{$MAIN_URI}/tarballs.php?time=" . time()); @unlink($tarballs_file); $curl->NoHTTP_POST = true; if (!$curl->GetFile($tarballs_file)) { build_progress("Get TarBalls !! FAILED !!", 30); _artica_update_event(0, "Unable to download tarballs file with error {$curl->error_num}, {$curl->error}", null, __FILE__, __LINE__); @unlink($tarballs_file); } build_progress("Ping repositories...", 35); @chmod($tarballs_file, 0755); echo "Starting......: " . date("H:i:s") . " dmidecode = " . strlen($dmidecode) . " bytes\n"; echo "Starting......: " . date("H:i:s") . " Updating repository information..\n"; $curl = new ccurl("{$MAIN_URI}/routers.inject.php?time=" . time()); $curl->NoHTTP_POST = true; $curl->get(); build_progress("Retreive index from repository", 40); $curl = new ccurl("{$uri}?time=" . time() . "&datas={$uriplus}"); $curl->NoHTTP_POST = true; $curl->forceCache = true; echo "Starting......: " . date("H:i:s") . " Downloading collection using Interface: `{$curl->interface}`\n"; echo "Starting......: " . date("H:i:s") . " Using \"{$GLOBALS["MasterIndexFile"]}\"\n"; echo "Starting......: " . date("H:i:s") . " Timeout set to \"{$curl->Timeout}s\"\n"; if (!$curl->GetFile($GLOBALS["MasterIndexFile"])) { build_progress("Retreive index from repository !! FAILED !!", 100); if (!$GLOBALS["NOT_FORCE_PROXY"]) { echo "Starting......: " . date("H:i:s") . " FATAL: Unable to download index file, try in direct mode\n"; $GLOBALS["NOT_FORCE_PROXY"] = true; return RefreshIndex(); } echo "Starting......: " . date("H:i:s") . " FATAL: {$GLOBALS["MasterIndexFile"]} " . @filesize($GLOBALS["MasterIndexFile"]) . " bytes\n"; echo "Starting......: " . date("H:i:s") . " FATAL: Unable to download index file with error {$curl->error_num}, {$curl->error}\n"; _artica_update_event(0, "Unable to download index file with error {$curl->error_num}, {$curl->error}", null, __FILE__, __LINE__); exec("{$nice} /usr/share/artica-postfix/bin/artica-update -refresh-index 2>&1", $results); while (list($num, $ligne) = each($dirs)) { echo "Starting......: " . date("H:i:s") . " {$ligne}\n"; } return; } build_progress("Retreive index from repository !! Success !!", 100); $md5string2 = md5_file($GLOBALS["MasterIndexFile"]); echo "Starting......: " . date("H:i:s") . " source: `{$md5string}` new: `{$md5string2}`\n"; echo "Starting......: " . date("H:i:s") . " Success...\n"; return true; }
include_once dirname(__FILE__) . "/ressources/class.squidguard.inc"; include_once dirname(__FILE__) . "/ressources/class.mysql.inc"; include_once dirname(__FILE__) . "/ressources/class.compile.ufdbguard.inc"; include_once dirname(__FILE__) . "/ressources/class.compile.dansguardian.inc"; include_once dirname(__FILE__) . '/framework/class.unix.inc'; include_once dirname(__FILE__) . "/framework/frame.class.inc"; include_once dirname(__FILE__) . '/ressources/class.ufdbguard-tools.inc'; include_once dirname(__FILE__) . "/ressources/class.os.system.inc"; $file = $argv[1]; if (!is_file($file)) { echo "{$file}, no such file\n"; die; } $unix = new unix(); $sock = new sockets(); $uuid = $unix->GetUniqueID(); if ($uuid == null) { die; } $handle = @fopen($file, "r"); if (!$handle) { echo "Failed to open file\n"; return; } $q = new mysql_squid_builder(); $category = "categoryuris_malware"; $countstart = $q->COUNT_ROWS("categoryuris_malware"); $prefix = "INSERT IGNORE INTO categoryuris_malware (zmd5,zDate,pattern,enabled) VALUES "; echo "{$prefix}\n"; $c = 0; $CBAD = 0;