function ArticaMeta_release($source_package) { $sock = new sockets(); $EnableArticaMetaServer = intval($sock->GET_INFO("EnableArticaMetaServer")); if ($EnableArticaMetaServer == 0) { echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository - DISABLED -\n"; return; } echo "Starting......: " . date("H:i:s") . " Checking META repository - ENABLED -\n"; $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage"); if ($ArticaMetaStorage == null) { $ArticaMetaStorage = "/home/artica-meta"; } @mkdir("{$ArticaMetaStorage}/nightlys", 0755, true); @mkdir("{$ArticaMetaStorage}/releases", 0755, true); $basename = basename($source_package); if (!preg_match("#artica-[0-9\\.]+\\.tgz#", $basename)) { echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository - FAILED ( not an artica package) -\n"; return; } if (is_file("{$ArticaMetaStorage}/releases/{$basename}")) { @unlink("{$ArticaMetaStorage}/releases/{$basename}"); } @copy($source_package, "{$ArticaMetaStorage}/releases/{$basename}"); meta_admin_mysql(2, "Added {$basename} into official repository", null, __FILE__, __LINE__); $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); echo "Starting......: " . date("H:i:s") . " Prepare New META package for clients...\n"; shell_exec("{$php} " . dirname(__FILE__) . "/exec.artica-meta-server.php --force"); echo "Starting......: " . date("H:i:s") . " Prepare New META package for clients done...\n"; }
function Replicate_policy_to_group($gpid, $content) { $q = new mysql_meta(); $sql = "SELECT uuid FROM metagroups_link WHERE gpid='{$gpid}'"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { meta_admin_mysql(0, "Fatal error: Mysql Error", $q->mysql_error . "\n{$sql}", __FILE__, __LINE__); return; } $md5Content = md5($content); $content = mysql_escape_string2($content); if (mysql_num_rows($results) == 0) { return; } while ($ligne = mysql_fetch_assoc($results)) { $uuid = $ligne["uuid"]; $md5 = md5("{$md5Content}{$uuid}"); $q->QUERY_SQL("DELETE FROM `policies_storage` WHERE `zmd5`='{$md5}'"); $sql = "INSERT IGNORE INTO `policies_storage` (zmd5,uuid,policy_content) VALUES ('{$md5}','{$uuid}','{$content}')"; $q->QUERY_SQL($sql); if (!$q->ok) { meta_admin_mysql(0, "Fatal error: Mysql Error", $q->mysql_error . "\n{$sql}", __FILE__, __LINE__); continue; } $q->CreateOrder($uuid, "POLICY", array("VALUE" => $md5)); } }
function compile_ufdbcat() { $unix = new unix(); $uri = "http://www.articatech.net/download/ufdbGuard-1.31.tar.gz"; $curl = new ccurl("http://www.articatech.net/download/ufdbGuard-1.31.tar.gz"); echo "Downloading {$uri}\n"; $tempdir = $unix->TEMP_DIR() . "/ufdb"; $tempfile = "{$tempdir}/ufdbGuard-1.31.tar.gz"; $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); $cp = $unix->find_program("cp"); if (is_dir($tempdir)) { shell_exec("{$rm} -rf {$tempdir}"); } @mkdir($tempdir, 0755, true); if (is_file($tempfile)) { @unlink($tempfile); } if (!$curl->GetFile($tempfile)) { echo "Fatal, unable to download {$uri}\n"; meta_admin_mysql(0, "Fatal, unable to download {$uri}", @implode("\n", $curl->errors), __FILE__, __LINE__); return; } if (is_dir("{$tempdir}/ufdbcompile")) { shell_exec("{$rm} -rf {$tempdir}/ufdbcompile"); } echo "Uncompressing {$tempdir}/ufdbGuard-1.31.tar.gz to {$tempdir}/\n"; shell_exec("{$tar} -xf {$tempdir}/ufdbGuard-1.31.tar.gz -C {$tempdir}/"); $dirs = $unix->dirdir($tempdir); while (list($directory, $value) = each($dirs)) { echo "Found directory {$directory}\n"; if (is_file("{$directory}/src/mtserver/ufdbguardd.c")) { $WORKDIR = "{$directory}"; break; } } if (!is_dir($WORKDIR)) { echo "Fatal, unable to download {$uri}\n"; meta_admin_mysql(0, "Fatal, unable to locate working directory", __FILE__, __LINE__); if (is_dir($tempdir)) { shell_exec("{$rm} -rf {$tempdir}"); } return; } echo "Patching mtserver/ufdbguardd.c\n"; $C = explode("\n", @file_get_contents("{$directory}/src/mtserver/ufdbguardd.c")); while (list($index, $line) = each($C)) { if (strpos($line, "/tmp/ufdbguardd-") > 0) { echo "Patching mtserver/ufdbguardd.c line {$index}\n"; $C[$index] = str_replace("/tmp/ufdbguardd-", "/var/run/ufdbcat-", $line); } } @file_put_contents("{$directory}/src/mtserver/ufdbguardd.c", @implode("\n", $C)); chdir($WORKDIR); if (is_dir("/opt/ufdbcat")) { shell_exec("{$rm} -rf /opt/ufdbcat"); } echo "Configure\n"; $f[] = "./configure"; $f[] = "--prefix=/opt/ufdbcat"; $f[] = "--includedir=\"\\\${prefix}/include\""; $f[] = "--mandir=\"\\\${prefix}/share/man\""; $f[] = "--infodir=\"\\\${prefix}/share/info\""; $f[] = "--sysconfdir=/etc/ufdbcat"; $f[] = "--localstatedir=/opt/ufdbcat"; $f[] = "--with-ufdb-logdir=/var/log/ufdbcat"; $f[] = "--with-ufdb-dbhome=/home/ufdbcat"; $f[] = "--with-ufdb-user=root"; $f[] = "--with-ufdb-config=/etc/ufdbcat"; $f[] = "--with-ufdb-logdir=/var/log/ufdbcat"; $f[] = "--with-ufdb-config=/etc/ufdbcat"; $f[] = "--with-ufdb-piddir=/var/run/ufdbcat"; $cmd = @implode(" ", $f); system($cmd); echo "Make\n"; system("make"); echo "Install\n"; system("make install"); if (!is_file("/opt/ufdbcat/bin/ufdbguardd")) { echo "Fatal, unable to compile ufdbcat\n"; meta_admin_mysql(0, "Fatal, unable to compile ufdbcat", __FILE__, __LINE__); if (is_dir($tempdir)) { shell_exec("{$rm} -rf {$tempdir}"); } return; } @copy("/opt/ufdbcat/bin/ufdbguardd", "/opt/ufdbcat/bin/ufdbcatdd"); @unlink("/opt/ufdbcat/bin/ufdbguardd"); @chmod("/opt/ufdbcat/bin/ufdbcatdd", 0755); $ufdbcatVersion = ufdbcatVersion(); $Architecture = Architecture(); $DebianVersion = DebianVersion(); $base = "/root/ufdbcat-compile"; if (is_dir($base)) { shell_exec("{$rm} -rf {$base}"); } @mkdir("{$base}/opt/ufdbcat", 0755, true); shell_exec("{$cp} -rfp /opt/ufdbcat/* {$base}/opt/ufdbcat/"); $filename = "ufdbcat-debian{$DebianVersion}-{$Architecture}-{$ufdbcatVersion}.tar.gz"; chdir($base); @unlink("/root/{$filename}"); shell_exec("/bin/tar -czf /root/{$filename} *"); echo "/root/{$filename} done\n\n"; }
function artica_meta_server($force = false) { $WORKDIR = "/var/lib/ftpunivtlse1fr"; $sock = new sockets(); $unix = new unix(); $EnableArticaMetaServer = intval($sock->GET_INFO("EnableArticaMetaServer")); if ($EnableArticaMetaServer == 0) { return; } $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage"); if ($ArticaMetaStorage == null) { $ArticaMetaStorage = "/home/artica-meta"; } @mkdir("{$ArticaMetaStorage}/nightlys", 0755, true); @mkdir("{$ArticaMetaStorage}/releases", 0755, true); @mkdir("{$ArticaMetaStorage}/webfiltering", 0755, true); $srcdir = $WORKDIR; $destfile = "{$ArticaMetaStorage}/webfiltering/ftpunivtlse1fr.tgz"; if (is_file($destfile)) { if (!$force) { return; } } $tar = $unix->find_program("tar"); @unlink($destfile); chdir($srcdir); shell_exec("{$tar} czf {$destfile} *"); @unlink("{$ArticaMetaStorage}/webfiltering/ftpunivtlse1fr.txt"); @file_put_contents("{$ArticaMetaStorage}/webfiltering/ftpunivtlse1fr.txt", time()); artica_update_event(2, "Toulouse University categories: Success update Artica Meta webfiltering repository", @implode("\n", $GLOBALS["EVENTS"]), __FILE__, __LINE__); meta_admin_mysql(2, "Success update Toulouse University categories webfiltering repository", null, __FILE__, __LINE__); }
function META_MASTER_UFDBTABLES($force = false) { $sock = new sockets(); $unix = new unix(); $EnableArticaMetaServer = intval($sock->GET_INFO("EnableArticaMetaServer")); if ($EnableArticaMetaServer == 0) { return; } $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage"); if ($ArticaMetaStorage == null) { $ArticaMetaStorage = "/home/artica-meta"; } @mkdir("{$ArticaMetaStorage}/nightlys", 0755, true); @mkdir("{$ArticaMetaStorage}/releases", 0755, true); @mkdir("{$ArticaMetaStorage}/webfiltering", 0755, true); $srcdir = $GLOBALS["WORKDIR_LOCAL"]; $destfile = "{$ArticaMetaStorage}/webfiltering/ufdbartica.tgz"; $destdir = "{$ArticaMetaStorage}/webfiltering/ufdbartica"; META_MASTER_UFDBTABLES_ufdbartica_txt(); $rm = $unix->find_program("rm"); if (is_file($destfile)) { $timeFile = "/etc/artica-postfix/pids/exec.artica-meta-server.php.checkufdb.time"; $time = $unix->file_time_min($timeFile); if ($time < 1440) { return; } } $tar = $unix->find_program("tar"); $split = $unix->find_program("split"); @unlink($destfile); chdir($srcdir); shell_exec("{$tar} czf {$destfile} *"); if (is_dir($destdir)) { shell_exec("{$rm} -rf {$destdir}"); } @mkdir("{$destdir}", 0755, true); chdir("{$destdir}"); system("cd {$destdir}"); @copy($destfile, "{$destdir}/ufdbartica.tgz"); echo "Split...ufdbartica.tgz\n"; shell_exec("{$split} -b 1m -d ufdbartica.tgz ufdbartica.tgz."); @unlink("{$destdir}/ufdbartica.tgz"); $files = $unix->DirFiles("{$destdir}"); while (list($num, $ligne) = each($files)) { $Splited_md5 = md5_file("{$destdir}/{$num}"); $ARRAY["{$num}"] = $Splited_md5; } @file_put_contents("{$destdir}/ufdbartica.txt", serialize($ARRAY)); @unlink("{$ArticaMetaStorage}/webfiltering/ufdbartica.txt"); @unlink("{$ArticaMetaStorage}/webfiltering/ARTICAUFDB_LAST_DOWNLOAD"); @copy("/etc/artica-postfix/ARTICAUFDB_LAST_DOWNLOAD", "{$ArticaMetaStorage}/webfiltering/ARTICAUFDB_LAST_DOWNLOAD"); @file_get_contents("{$ArticaMetaStorage}/webfiltering/ufdbartica.txt", time()); if (is_file("/etc/artica-postfix/artica-webfilter-db-index.txt")) { @unlink("{$ArticaMetaStorage}/webfiltering/index.txt"); @copy("/etc/artica-postfix/artica-webfilter-db-index.txt", "{$ArticaMetaStorage}/webfiltering/index.txt"); } if (is_file("/etc/artica-postfix/ufdbcounts.txt")) { @unlink("{$ArticaMetaStorage}/webfiltering/ufdbcounts.txt"); @copy("/etc/artica-postfix/ufdbcounts.txt", "{$ArticaMetaStorage}/webfiltering/ufdbcounts.txt"); } calculate_categorized_websites(true); artica_update_event(2, "Artica Webfiltering databases: Success update Artica Meta webfiltering repository", @implode("\n", $GLOBALS["EVENTS"]), __FILE__, __LINE__); meta_admin_mysql(2, "Success update webfiltering repository with Webfiltering databases", null, __FILE__, __LINE__); }
function parse_userauthdb($path, $uuid = null, $asmeta = false) { $unix = new unix(); $f = array(); if ($GLOBALS["VERBOSE"]) { echo "Parsing {$path}\n"; } if (!is_file($path)) { if ($GLOBALS["VERBOSE"]) { echo "{$path} no such file\n"; } return; } $db_con = dba_open($path, "r", "db4"); if (!$db_con) { if ($asmeta) { meta_admin_mysql(1, "DB open failed {$path}", null, __FILE__, __LINE__); } echo "DB open failed\n"; die; } $mainkey = dba_firstkey($db_con); while ($mainkey != false) { $val = 0; $array = unserialize(dba_fetch($mainkey, $db_con)); $mac = $array["MAC"]; if (strlen($mac) > 17) { $mac = clean_mac($mac); } $ipaddr = $array["IPADDR"]; $uid = $array["uid"]; $hostname = $array["hostname"]; $UserAgent = $array["UserAgent"]; $UserAgent = mysql_escape_string2($UserAgent); $uid = mysql_escape_string2($uid); $ipaddr = mysql_escape_string2($ipaddr); $mac = mysql_escape_string2($mac); $f[] = "('{$mainkey}','{$mac}','{$ipaddr}','{$uid}','{$hostname}','{$UserAgent}')"; $mainkey = dba_nextkey($db_con); } dba_close($db_con); if (count($f) > 0) { if ($GLOBALS["VERBOSE"]) { echo "UserAutDB: INSERTING " . count($f) . " elements\n"; } $q = new mysql_squid_builder(); if ($uuid != null) { $q = new mysql_stats($uuid); } $sql = "INSERT IGNORE INTO UserAutDB (zmd5,MAC,ipaddr,uid,hostname,UserAgent) VALUES " . @implode(",", $f); $q->QUERY_SQL("TRUNCATE TABLE `UserAutDB`"); $q->QUERY_SQL($sql); } }
function snapshot_restore($tarball) { backupevents("Restoring {$tarball}"); ini_set('html_errors', 0); ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); $unix = new unix(); $sock = new sockets(); $rm = $unix->find_program("rm"); $BaseWorkDir = "/usr/share/artica-postfix/snapshots/" . time(); $tar = $unix->find_program("tar"); $squidbin = $unix->LOCATE_SQUID_BIN(); $php = $unix->LOCATE_PHP5_BIN(); if ($GLOBALS["SEND_META"]) { $GLOBALS["NOT_RESTORE_NETWORK"] = true; } progress(10, "{restoring} {$tarball}"); echo $tarball . "\n"; if (!is_file($tarball)) { progress(110, "{failed}"); echo $tarball . " no such file\n"; return; } @mkdir($BaseWorkDir, 0755, true); progress(15, "{extracting}"); echo $tarball . " -> {$BaseWorkDir}\n"; system("{$tar} xf {$tarball} -C {$BaseWorkDir}/"); @unlink($tarball); if (is_file("{$BaseWorkDir}/TRUNCATE_TABLES")) { $TRUNCATE_TABLES = unserialize(@file_get_contents("{$BaseWorkDir}/TRUNCATE_TABLES")); @unlink("{$BaseWorkDir}/TRUNCATE_TABLES"); while (list($database, $tables) = each($TRUNCATE_TABLES)) { progress(20, "{cleaning} {$database}"); while (list($tablename, $none) = each($tables)) { if ($database == "artica_backup") { echo "Cleaning {$tablename}\n"; $q = new mysql(); $q->QUERY_SQL("TRUNCATE TABLE `{$tablename}`", "artica_backup"); continue; } if ($database == "squidlogs") { echo "Cleaning {$tablename}\n"; $q = new mysql_squid_builder(); $q->QUERY_SQL("TRUNCATE TABLE `{$tablename}`"); continue; } } } } else { echo "{$BaseWorkDir}/TRUNCATE_TABLES no such file\n"; } progress(30, "{restoring} squidlogs"); restore_squidlogs($BaseWorkDir); progress(40, "{restoring} artica_backup"); restore_artica_backup($BaseWorkDir); progress(50, "{restoring} Artica settings"); restore_artica_settings($BaseWorkDir); progress(60, "{restoring} Open LDAP"); Restore_ldap($BaseWorkDir); progress(70, "{restoring} Reverse Proxy"); restore_nginx($BaseWorkDir); progress(75, "{restoring} PowerDNS"); restore_powerdns($BaseWorkDir); progress(80, "{cleaning}..."); shell_exec("{$rm} -rf {$BaseWorkDir}"); progress(90, "{reconfigure_server}, {please_wait}..."); if (is_file($squidbin)) { system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); } progress(100, "{success}..."); if ($GLOBALS["SEND_META"]) { meta_admin_mysql(2, "Success restoring snapshot", null, __FILE__, __LINE__); } }
function extract_tgz($uuid) { $unix = new unix(); $workingdir = "/usr/share/artica-postfix/ressources/conf/meta/hosts/uploaded/{$uuid}"; if (is_file("{$workingdir}/status.tgz")) { $tar = $unix->find_program("tar"); shell_exec("{$tar} -xf {$workingdir}/status.tgz -C {$workingdir}/"); @unlink("{$workingdir}/status.tgz"); } $unix->chown_func($unix->APACHE_SRC_ACCOUNT(), $unix->APACHE_SRC_GROUP(), "{$workingdir}/*"); if (is_file("{$workingdir}/squid_admin_mysql.db")) { $q = new mysql_meta(); if (!$q->TABLE_EXISTS("squid_admin_mysql")) { $q->CheckTables(); } $data = trim(@file_get_contents("{$workingdir}/squid_admin_mysql.db")); if ($data != null) { $q->QUERY_SQL(@file_get_contents("{$workingdir}/squid_admin_mysql.db")); if (!$q->ok) { meta_admin_mysql(0, "Failed to import {$workingdir}/squid_admin_mysql.db", $q->mysql_error, __FILE__, __LINE__); } else { @unlink("{$workingdir}/squid_admin_mysql.db"); } } else { @unlink("{$workingdir}/squid_admin_mysql.db"); } } else { if ($GLOBALS["VERBOSE"]) { echo "{$workingdir}/squid_admin_mysql.db ( no such file )\n"; } } if (is_file("{$workingdir}/network_hosts.db")) { __network_hosts($uuid, "{$workingdir}/network_hosts.db"); } else { if ($GLOBALS["VERBOSE"]) { echo "{$workingdir}/network_hosts.db ( no such file )\n"; } } global_status_ini($uuid); }
function artica_updates_scheduled($aspid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if (!$aspid) { $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Starting......: " . date("H:i:s") . " artica_updates_scheduled already executed PID: {$pid} since {$time}Mn\n"; if ($time < 120) { if (!$GLOBALS["FORCE"]) { die; } } unix_system_kill_force($pid); } } else { $pidTimeEx = $unix->file_time_min($pidTime); if ($pidTimeEx < 61) { events("Skip Artica updates, current {$pidTimeEx}Mn, require 60mn ", __FUNCTION__, __FILE__, __LINE__); return; } } @chdir("/root"); @file_put_contents($pidfile, getmypid()); @unlink($pidTime); @file_put_contents($pidTime, time()); $tmpdir = $unix->TEMP_DIR(); $meta = new artica_meta(); $ARRAY = array(); $sock = new sockets(); $MetaClientAutoUpdate = intval($sock->GET_INFO("MetaClientAutoUpdate")); $ini = new iniFrameWork(); $ini->loadFile('/etc/artica-postfix/artica-update.conf'); $nightly = trim(strtolower($ini->_params["AUTOUPDATE"]["nightlybuild"])); if ($nightly == 1) { $nightly = "yes"; } if ($GLOBALS["VERBOSE"]) { echo "Update nightly ? `{$nightly}`\n"; } $curl = $meta->buildCurl("/meta-updates/releases/"); if (!$curl->GetFile("{$tmpdir}/releases.txt")) { events("Fatal: /meta-updates/releases/releases.txt {$curl->errors}", __FUNCTION__, __FILE__, __LINE__); artica_update_event(0, "Failed Downloading /meta-updates/releases/", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading /meta-updates/releases/", @implode("\n", $curl->errors), __FILE__, __LINE__); return false; } $data = @file_get_contents("{$tmpdir}/releases.txt"); $f = explode("\n", $data); @unlink("{$tmpdir}/releases.txt"); while (list($index, $ligne) = each($f)) { if (!preg_match("#href.*?artica-([0-9\\.]+)\\.tgz#", $ligne, $re)) { if ($GLOBALS["VERBOSE"]) { echo "Not Found {$ligne}\n"; } continue; } $verbin = intval(str_replace(".", "", $re[1])); events("Found : v{$verbin} /meta-updates/releases/artica-{$re[1]}.tgz", __FUNCTION__, __FILE__, __LINE__); $ARRAY[$verbin] = "/meta-updates/releases/artica-{$re[1]}.tgz"; } if ($MetaClientAutoUpdate == 1) { $nightly = "yes"; } if ($nightly == "yes") { $curl = $meta->buildCurl("/meta-updates/nightlys/"); if (!$curl->GetFile("{$tmpdir}/nightlys.txt")) { artica_update_event(0, "Failed Downloading /meta-updates/nightlys/", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading /meta-updates/nightlys/", @implode("\n", $curl->errors), __FILE__, __LINE__); } else { $data = @file_get_contents("{$tmpdir}/nightlys.txt"); $f = explode("\n", $data); @unlink("{$tmpdir}/nightlys.txt"); while (list($index, $ligne) = each($f)) { if (!preg_match("#href.*?artica-([0-9\\.]+)\\.tgz#", $ligne, $re)) { if ($GLOBALS["VERBOSE"]) { echo "Not Found {$ligne}\n"; } continue; } $verbin = intval(str_replace(".", "", $re[1])); events("Found : v{$verbin} /meta-updates/nightlys/artica-{$re[1]}.tgz", __FUNCTION__, __FILE__, __LINE__); $ARRAY[$verbin] = "/meta-updates/nightlys/artica-{$re[1]}.tgz"; } } } krsort($ARRAY); while (list($index, $ligne) = each($ARRAY)) { if ($GLOBALS["VERBOSE"]) { echo "Found v.{$index} / {$ligne}\n"; } $TA[] = $index; $TZ[] = $ligne; } $LASTVER = $TA[0]; $LASTFILE = $TZ[0]; $MYVERSION_TEXT = trim(@file_get_contents("/usr/share/artica-postfix/VERSION")); $MYVERSION = intval(str_replace(".", "", $MYVERSION_TEXT)); events("Last version: {$LASTVER} -> {$LASTFILE} against {$MYVERSION}", __FUNCTION__, __FILE__, __LINE__); if ($MYVERSION > $LASTVER) { events("Most updated, aborting", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "Most updated, aborting\n"; } return; } if ($MYVERSION == $LASTVER) { events("Most updated, aborting", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "Most updated, aborting\n"; } return; } $curl = $meta->buildCurl($LASTFILE); $tmpfile = "{$tmpdir}/" . basename($LASTFILE); if (!$curl->GetFile($tmpfile)) { events("Failed Downloading {$LASTFILE} {$curl->errors}", __FUNCTION__, __FILE__, __LINE__); artica_update_event(0, "Failed Downloading {$LASTFILE}", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading {$LASTFILE}", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink($tmpfile); return; } if (!$unix->TARGZ_TEST_CONTAINER($tmpfile)) { artica_update_event(0, "Failed {$tmpfile} corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed {$tmpfile} corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink($tmpfile); return false; } if ($GLOBALS["VERBOSE"]) { echo "Extracting {$tmpfile}\n"; } $tar = $unix->find_program("tar"); shell_exec("{$tar} xf {$tmpfile} -C /usr/share/"); @unlink($tmpfile); $MYVERSION_TEXT = trim(@file_get_contents("/usr/share/artica-postfix/VERSION")); $php = $unix->LOCATE_PHP5_BIN(); shell_exec("{$php} /usr/share/artica-postfix/exec.nightly.php --restart-services >/dev/null 2>&1"); artica_update_event(2, "Success update Artica to {$MYVERSION_TEXT}", null, __FILE__, __LINE__); meta_admin_mysql(2, "Success update Artica to {$MYVERSION_TEXT}", null, __FILE__, __LINE__); }
function ArticaMeta_nightly($source_package) { $sock = new sockets(); $EnableArticaMetaServer = intval($sock->GET_INFO("EnableArticaMetaServer")); if ($EnableArticaMetaServer == 0) { echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository - DISABLED -\n"; _artica_update_event(2, "Checking Artica-meta repository - DISABLED -", null, __FILE__, __LINE__); return; } build_progress_manu("Checking Meta repository", 32); echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository - ENABLED -\n"; $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage"); if ($ArticaMetaStorage == null) { $ArticaMetaStorage = "/home/artica-meta"; } @mkdir("{$ArticaMetaStorage}/nightlys", 0755, true); @mkdir("{$ArticaMetaStorage}/releases", 0755, true); $basename = basename($source_package); if (!preg_match("#artica-[0-9\\.]+\\.tgz#", $basename)) { _artica_update_event(1, "Checking Artica-meta repository - FAILED ( {$basename} not an artica package)", null, __FILE__, __LINE__); echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository - FAILED ( not an artica package) -\n"; return; } build_progress_manu("Checking Meta repository", 33); if (is_file("{$ArticaMetaStorage}/nightlys/{$basename}")) { @unlink("{$ArticaMetaStorage}/nightlys/{$basename}"); } @copy($source_package, "{$ArticaMetaStorage}/nightlys/{$basename}"); _artica_update_event(2, "Added {$basename} into nightly repository", null, __FILE__, __LINE__); meta_admin_mysql(2, "Added {$basename} into nightly repository", null, __FILE__, __LINE__); $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); build_progress_manu("Checking Meta repository", 34); shell_exec("{$php} " . dirname(__FILE__) . "/exec.artica-meta-server.php --force"); }
function ParseDB_FILE($path, $uuid = null, $asmeta = false) { $unix = new unix(); if (!is_file($path)) { return; } echo "Open {$path}\n"; $db_con = dba_open($path, "r", "db4"); if (!$db_con) { if ($asmeta) { meta_admin_mysql(1, "DB open failed {$path}", null, __FILE__, __LINE__); } echo "DB open failed\n"; die; } $mainkey = dba_firstkey($db_con); while ($mainkey != false) { $val = 0; $data = unserialize(dba_fetch($mainkey, $db_con)); $mainkey = dba_nextkey($db_con); if (!is_array($data)) { continue; } $q = new mysql_squid_builder(); $qCommon = new mysql_squid_builder(); if ($uuid != null) { $q = new mysql_stats($uuid); } if ($asmeta) { $q = new mysql_meta(); } if (!isset($data["HOURLY"])) { continue; } if (!isset($data["WWW"])) { continue; } $category = null; $ipaddr = mysql_escape_string2($data["IPADDR"]); if (isset($data["MAC"])) { $mac = mysql_escape_string2($data["MAC"]); } $uid = mysql_escape_string2($data["UID"]); $familysite = mysql_escape_string2($data["WWW"]); if (isset($data["category"])) { $category = mysql_escape_string2($data["category"]); } if ($uid == null) { $uid = $qCommon->UID_FROM_MAC($data["MAC"]); } if ($uid == null) { $uid = $qCommon->UID_FROM_IP($data["IPADDR"]); } $uid = mysql_escape_string2($uid); $length = strlen($ipaddr) + strlen($mac) + strlen($uid) + strlen($familysite); if ($length == 0) { continue; } while (list($day, $array) = each($data["HOURLY"])) { while (list($hour, $size) = each($array)) { $md5 = md5("'{$ipaddr}','{$mac}','{$uid}','{$familysite}','{$day}','{$hour}','{$size}','{$category}'"); $wwwUH[] = "('{$md5}','{$ipaddr}','{$mac}','{$uid}','{$familysite}','{$day}','{$hour}','{$size}','{$category}')"; if ($GLOBALS["VERBOSE"]) { echo "('{$md5}','{$ipaddr}','{$mac}','{$uid}','{$familysite}','{$day}','{$hour}','{$size}','{$category}')\n"; } } } } dba_close($db_con); $TABLE_WEEK_RTTH = "WEEK_RTTH"; $ENGINE = "MEMORY"; if ($asmeta) { $TABLE_WEEK_RTTH = "{$uuid}_WEEK_RTTH"; $ENGINE = "MYISAM"; } if ($asmeta) { xmeta_events("DROP TABLE `{$TABLE_WEEK_RTTH}`", __FUNCTION__, __FILE__, __LINE__); } $q->QUERY_SQL("DROP TABLE `{$TABLE_WEEK_RTTH}`"); if ($asmeta) { xmeta_events("CREATE TABLE `{$TABLE_WEEK_RTTH}`", __FUNCTION__, __FILE__, __LINE__); } $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `{$TABLE_WEEK_RTTH}` (\n\t\t `zmd5` varchar(90) NOT NULL,\n\t\t `familysite` varchar(128) NOT NULL,\n\t\t `ipaddr` varchar(50) NOT NULL DEFAULT '',\n\t\t `day` smallint(2) NOT NULL,\n\t\t `hour` smallint(2) NOT NULL,\n\t\t `uid` varchar(128) NOT NULL,\n\t\t `MAC` varchar(20) NOT NULL,\n\t\t `size` BIGINT UNSIGNED NOT NULL,\n\t\t `category` varchar(90) NOT NULL,\n\t\t PRIMARY KEY `zmd5` (`zmd5`),\n\t\t KEY `familysite` (`familysite`),\n\t\t KEY `ipaddr` (`ipaddr`),\n\t\t KEY `uid` (`uid`),\n\t\t KEY `category` (`category`),\n\t\t KEY `hour` (`hour`),\n\t\t KEY `day` (`day`),\n\t\t KEY `MAC` (`MAC`)\n\t\t) ENGINE={$ENGINE};"); if (!$q->ok) { if ($asmeta) { meta_admin_mysql(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__); } echo $q->mysql_error; return; } $q->QUERY_SQL("INSERT IGNORE INTO `{$TABLE_WEEK_RTTH}` ( `zmd5`,`ipaddr`,`MAC`,`uid`,familysite,`day`,`hour`,`size`,`category`) VALUES " . @implode(",", $wwwUH)); if (!$q->ok) { if ($asmeta) { meta_admin_mysql(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__); } echo $q->mysql_error; return; } if ($asmeta) { xmeta_events("Success parsing {$path} adding " . count($wwwUH) . " elements", __FUNCTION__, __FILE__, __LINE__); return; } $sock = new sockets(); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); $EnableSquidRemoteMySQL = intval($sock->GET_INFO("EnableSquidRemoteMySQL")); if ($EnableSquidRemoteMySQL == 1) { return; } if ($EnableArticaMetaClient == 0) { return; } $DIR_TEMP = $unix->TEMP_DIR(); if (!$unix->compress($path, "{$DIR_TEMP}/SQUID_QUOTASIZE.gz")) { meta_admin_mysql(1, "Unable to compress {$path}", null, __FILE__, __LINE__); @unlink("{$DIR_TEMP}/SQUID_QUOTASIZE.gz"); return; } $artica_meta = new artica_meta(); if (!$artica_meta->SendFile("{$DIR_TEMP}/SQUID_QUOTASIZE.gz", "SQUID_QUOTASIZE")) { meta_admin_mysql(1, "Unable to updload {$DIR_TEMP}/SQUID_QUOTASIZE.gz", null, __FILE__, __LINE__); } @unlink("{$DIR_TEMP}/SQUID_QUOTASIZE.gz"); }
function build_progress($text, $pourc) { echo "[{$pourc}%] {$text}\n"; $array["POURC"] = $pourc; $array["TEXT"] = $text; @file_put_contents($GLOBALS["PROGRESS_FILE"], serialize($array)); @chmod($GLOBALS["PROGRESS_FILE"], 0755); $info = 2; if ($pourc > 100) { $info = 0; } $sock = new sockets(); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); if ($EnableArticaMetaClient == 0) { return; } meta_admin_mysql($info, "{$pourc}%: {$text}", null, __FILE__, __LINE__); if ($pourc == 100) { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); system("{$php} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &"); } }