function restore($filename) { $unix = new unix(); $sock = new sockets(); $TMP = $unix->FILE_TEMP(); $filenameBase = basename($filename); if (!is_file($filename)) { echo "{$filename} no such file\n"; build_progress("{failed}", 110); } $tmpf = $unix->FILE_TEMP(); build_progress("{uncompress} {$filenameBase}", 10); if (!$unix->uncompress($filename, $tmpf)) { @unlink($filename); build_progress("{uncompress} {$filenameBase} {failed}", 110); return; } @unlink($filename); build_progress("{importing} {$tmpf}", 50); $q = new mysql_squid_builder(); $nice = $unix->EXEC_NICE(); $mysql = $unix->find_program("mysql"); $gzip = $unix->find_program("gzip"); $nohup = $unix->find_program("nohup"); $echo = $unix->find_program("echo"); $rm = $unix->find_program("rm"); $php = $unix->LOCATE_PHP5_BIN(); $sh[] = "#!/bin/sh"; $sh[] = "{$echo} \"{$mysql} -> {$filenameBase}\""; $sh[] = "{$nice} {$mysql} {$q->MYSQL_CMDLINES} -f squidlogs < {$tmpf}"; $sh[] = "{$rm} {$TMP}.sh"; $sh[] = "\n"; @file_put_contents("{$TMP}.sh", @implode("\n", $sh)); @chmod("{$TMP}.sh", 0755); build_progress(10, "Starting restore {$filenameBase} - " . basename("{$TMP}.sh") . " "); system("{$nohup} {$TMP}.sh >{$TMP}.txt 2>&1 &"); sleep(1); $PID = $unix->PIDOF_PATTERN("{$TMP}.sh"); echo "Running PID {$PID}\n"; while ($unix->process_exists($PID)) { build_progress(50, "Starting restoring {$filenameBase}"); sleep(3); $PID = $unix->PIDOF_PATTERN("{$TMP}.sh"); echo "Running PID {$PID}\n"; } echo @file_get_contents("{$TMP}.txt") . "\n"; @unlink("{$TMP}.sh"); @unlink("{$TMP}.txt"); build_progress(50, "{restore} {done} {$filenameBase}"); build_progress(50, "{restore} Analyze Hourly tables"); system("{$php} /usr/share/artica-postfix/exec.squid.stats.hours.php --force --verbose"); build_progress(60, "{restore} Repair Hourly tables"); system("{$php} /usr/share/artica-postfix/exec.squid.stats.hours.php --repair --force --verbose"); build_progress(70, "{restore} Repair Table days"); system("{$php} /usr/share/artica-postfix/exec.squid.stats.repair.php --tables-day --repair --force --verbose"); build_progress(80, "{restore} Repair sums"); system("{$php} /usr/share/artica-postfix/exec.squid.stats.totals.php --repair --force --verbose"); build_progress(100, "{restore} Done"); }
function fstabmount() { $unix = new unix(); $fstabmount = $_GET["fstabmount"]; $dev = $unix->FSTAB_GETDEV($fstabmount); if ($dev != null) { $ext = $unix->DISK_GET_TYPE($dev); } if ($ext == null) { $ext = "auto"; } if (!is_dir($fstabmount)) { @mkdir($fstabmount); } $tmp = $unix->FILE_TEMP(); if ($ext == "ext4") { $kernel = $unix->KERNEL_VERSION_BIN(); error_log("framework::" . __FUNCTION__ . " kernel: {$kernel}"); if ($kernel < 20629) { $ext = "ext4dev"; } } $cmd = "/bin/mount -t {$ext} {$dev} {$fstabmount} >{$tmp} 2>&1"; error_log("framework::" . __FUNCTION__ . " {$cmd}"); shell_exec("/bin/mount -t {$ext} {$dev} {$fstabmount} >{$tmp} 2>&1"); $results = @file_get_contents($tmp); @unlink($tmp); error_log("framework::" . __FUNCTION__ . " mount point is \"{$dev}\" ({$ext})={$results} line " . __LINE__); if (strlen($results) > 0) { echo "<articadatascgi>{$results}</articadatascgi>"; } }
function xstart() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $tar = $unix->find_program("tar"); build_progress("{downloading} roundcubeemail-1.1.2.tar.gz", 20); $tmpfile = $unix->FILE_TEMP(); $curl = new ccurl("http://articatech.net/download/postfix-debian7/roundcubeemail-1.1.2.tar.gz"); if (!$curl->GetFile($tmpfile)) { echo "Failed: " . $curl->error . "\n"; @unlink($tmpfile); build_progress("{failed} roundcubeemail-1.1.2.tar.gz", 110); return; } build_progress("{uncompressing} roundcubeemail-1.1.2.tar.gz", 50); system("{$tar} xf {$tmpfile} -C /"); @unlink($tmpfile); if (!is_file("/usr/share/roundcube/index.php")) { build_progress("{uncompressing} roundcubeemail-1.1.2.tar.gz {failed}", 110); return; } build_progress("{verify_database}", 60); system("{$php} /usr/share/artica-postfix/exec.roundcube.php --database"); build_progress("{restarting_service}", 70); system("{$php} /usr/share/artica-postfix/exec.roundcube.php --restart"); system("/etc/init.d/artica-status restart"); build_progress("{installing} roundcubeemail-1.1.2.tar.gz {success}", 100); }
function iprulesDNS() { $unix = new unix(); $IPCHAIN = "dnsfilter"; $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if ($unix->process_exists(@file_get_contents($pidfile), basename(__FILE__))) { echo "Starting......: " . date("H:i:s") . " iptables configurator already executed PID " . @file_get_contents($pidfile) . "\n"; die; } $pid = getmypid(); file_put_contents($pidfile, $pid); $sock = new sockets(); $EnableIptablesDNS = $sock->GET_INFO("EnableIptablesDNS"); if (!is_numeric($EnableIptablesDNS)) { $EnableIptablesDNS = 1; } if ($EnableIptablesDNS == 0) { $ip = new iptables_exec(); if ($ip->is_chain_exists($IPCHAIN)) { shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}"); shell_exec("{$GLOBALS["iptables"]} -X {$IPCHAIN}"); } return; } $tmpfile = $unix->FILE_TEMP(); $curl = new ccurl("https://raw.github.com/smurfmonitor/dns-iptables-rules/master/domain-blacklist.txt"); $curl->NoHTTP_POST = true; if ($curl->GetFile($tmpfile)) { $size = @filesize($tmpfile); if ($size < 100) { $tmpfile = "/usr/share/artica-postfix/bin/install/iptables_defaults.txt"; } } $ip = new iptables_exec(); if (!$ip->is_chain_exists($IPCHAIN)) { echo "Adding chain {$IPCHAIN}\n"; shell_exec("{$GLOBALS["iptables"]} -N {$IPCHAIN}"); shell_exec("{$GLOBALS["iptables"]} -I INPUT -p udp --dport 53 -j {$IPCHAIN}"); } else { echo "chain {$IPCHAIN} exists...\n"; } shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}"); shell_exec("{$GLOBALS["iptables"]} -A {$IPCHAIN} -j RETURN"); $f = explode("\n", @file_get_contents($tmpfile)); while (list($num, $ligne) = each($f)) { $ligne = trim($ligne); if ($ligne == null) { continue; } $ligne = str_replace("INPUT", $IPCHAIN, $ligne); $ligne = str_replace("iptables", $GLOBALS["iptables"], $ligne); $results = array(); exec($ligne, $results); echo "{$ligne}\n"; while (list($a, $b) = each($results)) { echo "{$b}\n"; } } }
function GetDomains($i) { $unix = new unix(); $tmpfile = $unix->FILE_TEMP(); $curl = new ccurl("http://0675.com.cn/newwebsite_20120101_list._page0.html"); $curl->NoHTTP_POST = true; echo "Get page {$i}\n"; if (!$curl->GetFile($tmpfile)) { echo "http://0675.com.cn/newwebsite_20120101_list._page{$i}.html -> error: \n" . $curl->error . "\n"; return; } $datas = @file($tmpfile); $size = strlen(@implode("", $datas)) / 1024; echo "Page[{$i}]:: {$tmpfile} Size: {$size} Ko\n"; while (list($num, $ligne) = each($datas)) { if (preg_match("#<div class=.*?newdomain.*?>(.*)#", $ligne)) { echo "Sure line {$num}"; $newdata = str_replace("</li>", "", $ligne); $newdata = str_replace("</div>", "", $newdata); $f = explode("<li>", $newdata); } } $q = new mysql_squid_builder(); while (list($num, $www) = each($f)) { if (preg_match("#^\\.(.+)#", $www, $re)) { $www = $re[1]; } if (strpos($www, ",") > 0) { continue; } if (strpos($www, " ") > 0) { continue; } if (strpos($www, ":") > 0) { continue; } if (strpos($www, "%") > 0) { continue; } if (strpos($www, ">") > 0) { continue; } if (strpos($www, "<") > 0) { continue; } if (preg_match("#^www\\.(.+)#", $www, $re)) { $www = $re[1]; } $articacats = trim($q->GET_CATEGORIES($www, true, false)); if ($articacats != null) { echo "\"{$www}\" SUCCESS - {$articacats} -\n"; continue; } echo "\"{$www}\" FAILED\n"; } }
function download() { $unix = new unix(); build_progress("{downloading}", 10); $URI = "http://wordpress.org/latest.tar.gz"; $TMP_FILE = $unix->FILE_TEMP() . ".gz"; $TMP_DIR = $unix->TEMP_DIR(); echo "Downloading {$URI}\n"; $curl = new ccurl($URI); $curl->WriteProgress = true; $curl->ProgressFunction = "download_progress"; if (!$curl->GetFile($TMP_FILE)) { build_progress("{downloading} {failed}", 110); echo $curl->error; return; } echo "Extracting {$TMP_FILE} in {$TMP_DIR}\n"; $tar = $unix->find_program("tar"); $cmd = "{$tar} xf {$TMP_FILE} -C {$TMP_DIR}/"; build_progress("{uncompress}", 50); shell_exec("{$tar} xf {$TMP_FILE} -C {$TMP_DIR}/"); @unlink($TMP_FILE); $dirs = $unix->dirdir($TMP_DIR); $WDP_DIR = null; while (list($num, $ligne) = each($dirs)) { if (!is_file("{$ligne}/wp-admin/install.php")) { continue; } $WDP_DIR = $ligne; break; echo "Find Directory {$ligne}\n"; } if (!is_dir($WDP_DIR)) { build_progress("Find directory failed", 110); echo "Find directory failed\n"; return; } build_progress("{installing}", 80); @mkdir("/usr/share/wordpress-src", 0755, true); $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); shell_exec("cp -rfv {$WDP_DIR}/* /usr/share/wordpress-src/"); if (is_dir($WDP_DIR)) { echo "Removing {$WDP_DIR}\n"; shell_exec("{$rm} -rf {$WDP_DIR}"); } $sock = new sockets(); $sock->SET_INFO("EnableFreeWeb", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/WordPressInstalled", 1); system("/etc/init.d/artica-status restart --force"); build_progress("{success}", 100); $nohup = $unix->find_program("nohup"); $sock = new sockets(); shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 --verbose 654646 >/dev/null 2>&1 &"); }
function certificate_infos() { $unix = new unix(); $openssl = $unix->find_program("openssl"); $l = $unix->FILE_TEMP(); $cmd = "{$openssl} x509 -in /etc/artica-postfix/openvpn/keys/vpn-server.key -text -noout >{$l} 2>&1"; if ($cmd != null) { shell_exec($cmd); $datas = explode("\n", @file_get_contents($l)); writelogs_framework($cmd . " =" . count($datas) . " rows", __FUNCTION__, __FILE__, __LINE__); @unlink($l); } echo "<articadatascgi>" . base64_encode(serialize($datas)) . "</articadatascgi>"; }
function run() { $sock = new sockets(); $PhileSizeCpuLimit = $sock->GET_INFO("PhileSizeCpuLimit"); if ($PhileSizeCpuLimit == null) { $PhileSizeCpuLimit = 0; } if (InMemQUestion()) { writelogs("Already running, aborting", __FUNCTION__, __FILE__, __LINE__); return null; } chdir("/usr/share/artica-postfix/bin"); $unix = new unix(); $tmpfile = $unix->FILE_TEMP(); $cmd = $unix->find_program("nohup") . " /usr/share/artica-postfix/bin/philesight --db /opt/artica/philesight/database.db --index / >{$tmpfile} &"; echo $cmd . "\n"; shell_exec($cmd); sleep(3); $f = explode("\n", @file_get_contents($tmpfile)); @unlink($tmpfile); while (list($num, $ligne) = each($f)) { if (preg_match("#run database recovery#", $ligne)) { $corrupted = true; } } if ($corrupted) { @unlink("/opt/artica/philesight/database.db"); shell_exec($cmd); } if ($PhileSizeCpuLimit == 0) { return; } sleep(3); $pid = getPID(); echo "Pid={$pid}\n"; if ($pid > 2) { $cpulimit = $unix->find_program("cpulimit"); echo "cpulimit={$cpulimit}\n"; if (is_file($cpulimit)) { $cmd_limit = "{$cpulimit} -p {$pid} -l {$PhileSizeCpuLimit} -z >>/var/log/cpulimit 2>&1 &"; sleep(1); echo $cmd_limit . "\n"; shell_exec($cmd_limit); } } }
function xinstall() { $unix = new unix(); $curl = new ccurl(); $tmpfile = $unix->FILE_TEMP(); $tmpdir = $unix->TEMP_DIR(); build_progress("{downloading} v3.1.0-25", 15); $curl = new ccurl("http://articatech.net/download/UpdateUtility/updateutility-3.1.0-25.tar.gz"); if (!$curl->GetFile($tmpfile)) { @unlink($tmpfile); build_progress("{downloading} {failed}", 110); return; } $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); @mkdir("{$tmpdir}/updateutility", 0755); build_progress("{uncompress}", 20); shell_exec("{$tar} -xf {$tmpfile} -C {$tmpdir}/updateutility/"); build_progress("{find_source_directory}", 25); $dirs = $unix->dirdir("{$tmpdir}/updateutility"); $SOURCE_DIRECTORY = null; while (list($num, $ligne) = each($dirs)) { build_progress("{scanning} {$ligne}", 25); if (is_file("{$ligne}/UpdateUtility-Console")) { $SOURCE_DIRECTORY = $ligne; break; } } if ($SOURCE_DIRECTORY == null) { echo "Unable to find source directory\n"; build_progress("{installing} {failed}", 110); shell_exec("{$rm} -rf {$tmpdir}/updateutility"); return; } echo "Using directory {$SOURCE_DIRECTORY}\n"; build_progress("{installing}...", 80); $cp = $unix->find_program("cp"); @mkdir("/etc/UpdateUtility", 0755, true); shell_exec("{$cp} -rfv {$SOURCE_DIRECTORY}/* /etc/UpdateUtility/"); shell_exec("{$rm} -rf {$tmpdir}/updateutility"); if (!is_file("/etc/UpdateUtility/UpdateUtility-Console")) { echo "/etc/UpdateUtility/UpdateUtility-Console no such binary\n"; build_progress("{installing} {failed}", 110); } build_progress("{installing} {success}", 100); }
function export() { $workdir = dirname(__FILE__) . "/ressources/squid-export"; if (!is_dir($workdir)) { @mkdir($workdir, 0777, true); } if (!($handle = opendir("/etc/artica-postfix/settings/Daemons"))) { @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true); die; } while (false !== ($filename = readdir($handle))) { if ($filename == ".") { continue; } if ($filename == "..") { continue; } $targetFile = "/etc/artica-postfix/settings/Daemons/{$filename}"; if ($GLOBALS["VERBOSE"]) { echo "Exporting {$filename}\n"; } $array[$filename] = @file_get_contents($targetFile); } if ($GLOBALS["VERBOSE"]) { echo count($array) . " items....\n"; } $finalitems = base64_encode(serialize($array)); $unix = new unix(); $tmpf = $unix->FILE_TEMP(); @file_put_contents($tmpf, $finalitems); if ($GLOBALS["VERBOSE"]) { echo "compressing in {$workdir}/settingsHD.gz\n"; } if (!$unix->compress($tmpf, "{$workdir}/settingsHD.gz")) { @unlink("{$workdir}/settingsHD.gz"); } @chmod("{$workdir}/settingsHD.gz", 0777); @unlink($tmpf); if ($GLOBALS["VERBOSE"]) { echo "compressing in {$workdir}/settingsHD.gz done\n"; } }
function tests_port($port_id) { $unix = new unix(); $squid = new squidbee(); $q = new mysql_squid_builder(); $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT * FROM proxy_ports WHERE ID={$port_id}")); $ssl_bump_line = $squid->ssl_bump_line($ligne["sslcertificate"]); $randport = rand(63500, 65535); build_progress("{testing_ssl_certificate} ID:{$port_id} {$ligne["sslcertificate"]}", 15); $t = time(); $pid_filename = "/var/run/squid/{$t}.pid"; $cache_log = "/var/log/squid/cache.{$t}.log"; $f[] = "coredump_dir\t/var/squid/cache"; $f[] = "cache_log\t/var/log/squid/cache.log"; $f[] = "pid_filename\t/var/run/squid/squid.pid"; $f[] = "cache_effective_user squid"; $f[] = "http_port 127.0.0.1:{$randport} {$ssl_bump_line}"; echo " ***********************************************************************\n"; echo "Using HTTPS port {$ssl_bump_line} Certificate {$ligne["sslcertificate"]}\n"; echo " ***********************************************************************\n"; $f[] = ""; $tmpfile = $unix->FILE_TEMP(); $squidbin = $unix->LOCATE_SQUID_BIN(); build_progress("{testing_ssl_certificate} {$ligne["sslcertificate"]}", 20); echo "Conf : {$tmpfile}\n"; echo "Binary: {$squidbin}\n"; @file_put_contents($tmpfile, @implode("\n", $f)); exec("{$squidbin} -f {$tmpfile} -k check 2>&1", $results); @unlink($tmpfile); while (list($num, $line) = each($results)) { echo "Check : {$line}\n"; if (preg_match("#FATAL: No valid signing SSL#", $line)) { build_progress("{testing_ssl_certificate_failed} {$ligne["sslcertificate"]}", 110); $sql = "UPDATE proxy_ports SET sslcertificate='' WHERE ID='{$port_id}'"; $q->QUERY_SQL($sql); return; } } build_progress("{testing_ssl_certificate} {success}", 100); // FATAL: No valid signing SSL certificate }
function run() { $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $unix = new unix(); $tmpfile = $unix->FILE_TEMP(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "{$pid} already executed since {$timepid}Mn\n"; } if (!$GLOBALS["FORCE"]) { if ($timepid < 14) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } } @file_put_contents($pidfile, getmypid()); if (!$GLOBALS["FORCE"]) { if (!$GLOBALS["VERBOSE"]) { $time = $unix->file_time_min($TimeFile); if ($time < 14) { echo "Current {$time}Mn, require at least 14mn\n"; return; } } } $tmpfileSource = $unix->FILE_TEMP(); $year = date("Y"); @copy("/var/log/mail.log", $tmpfileSource); $binary = "/usr/share/artica-postfix/bin/pflogsumm.pl"; @chmod("{$binary}", 0755); system("{$binary} -d today {$tmpfileSource} >{$tmpfile}"); @unlink($tmpfileSource); ParseReport($tmpfile); @unlink($tmpfile); stats_total(true); }
function export_openvpn_rsites() { $sock = new sockets(); $meta = new artica_meta(); $unix = new unix(); $q = new mysql(); $gzip = $unix->find_program("gzip"); $addons = array("uuid" => $meta->uuid, "serial" => $meta->serial); $exported = $q->BackupTable("vpnclient", "artica_backup", $addons, true, null); if (!$q->ok) { echo $q->mysql_error; return; } events("export: " . str_replace(" ", " ", FormatBytes(strlen($exported) / 1024)), __FUNCTION__, __FILE__, __LINE__); $tmpf = $unix->FILE_TEMP(); @file_put_contents($tmpf, $exported); $gzipped = "{$tmpf}.gz"; shell_exec("{$gzip} -c {$tmpf} > {$gzipped}"); $taille = str_replace(" ", " ", FormatBytes(filesize($gzipped) / 1024)); events("{$tmpf} compressed: {$taille}", __FUNCTION__, __FILE__, __LINE__); $http = new httpget(); $http->uploads["OPENVPN_SITES"] = $gzipped; $body = $http->send("{$meta->ArticaMetaHostname}/lic.users.import.php", "post", array("DATAS" => base64_encode(serialize($meta->GLOBAL_ARRAY)))); @unlink($tmpf); @unlink($gzipped); if (!preg_match("#<RESULTS>OK</RESULTS>#is", $body)) { events("Exporting remote sites done (error) {$body}...", __FUNCTION__, __FILE__, __LINE__); return; } events("Exporting remote sites done...", __FUNCTION__, __FILE__, __LINE__); export_openvpn_sites_package(); }
function duplicate_wordpress($servername) { $unix = new unix(); $q = new mysql(); $free = new freeweb($servername); $WORKING_DIRECTORY = $free->www_dir; if ($free->groupware_duplicate == null) { build_progress("{$servername}: {duplicate} {$servername} no duplicate set...", 42); sleep(2); return false; } $free2 = new freeweb($free->groupware_duplicate); if ($free2->mysql_database == null) { echo "Fatal: {$free->groupware_duplicate} did not have any such DB set, try to find it..\n"; $free2->mysql_database = $free2->CreateDatabaseName(); echo "Fatal: {$free->groupware_duplicate} = {$free2->mysql_database}\n"; } if (!$q->DATABASE_EXISTS($free2->mysql_database, true)) { build_progress("{$servername}: {duplicate} {$free->groupware_duplicate} did not have any database...", 42); sleep(2); return false; } $srcdir = $free2->www_dir; $Mysqlpassword = null; $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); if (@is_link($WORKING_DIRECTORY)) { $WORKING_DIRECTORY = @readlink($WORKING_DIRECTORY); } if (is_dir($WORKING_DIRECTORY)) { build_progress("{$servername}: {removing} {$WORKING_DIRECTORY}...", 42); sleep(2); shell_exec("{$rm} -rf {$WORKING_DIRECTORY}/*"); } @mkdir($WORKING_DIRECTORY, 0755, true); build_progress("{$servername}: {installing} {from} {$srcdir}...", 42); shell_exec("{$cp} -rf {$srcdir}/* {$WORKING_DIRECTORY}/"); $wordpressDB = $free->mysql_database; if ($wordpressDB == null) { $wordpressDB = $free->CreateDatabaseName(); } if ($q->DATABASE_EXISTS($wordpressDB)) { build_progress("{$servername}: {remove_database} {$wordpressDB}...", 42); sleep(2); if (!$q->DELETE_DATABASE($wordpressDB)) { build_progress("{$servername}: {remove_database} {$wordpressDB} {failed}...", 42); return false; } if (!$q->CREATE_DATABASE($wordpressDB, true)) { build_progress("{$servername}: {create_database} {$wordpressDB} {failed}...", 42); return false; } } if (!$q->DATABASE_EXISTS($wordpressDB)) { if (!$q->CREATE_DATABASE($wordpressDB, true)) { build_progress("{$servername}: {create_database} {$wordpressDB} {failed}...", 42); return false; } } build_progress("{$servername}: {backup_database} {from} {$free2->mysql_database}...", 42); $mysqldump = $unix->find_program("mysqldump"); $q = new mysql(); if ($q->mysql_password != null) { $Mysqlpassword = "******" . $unix->shellEscapeChars($q->mysql_password); } $t = time(); $TMP_FILE = $unix->FILE_TEMP(); $cmdline = trim("{$mysqldump} --add-drop-table --single-transaction --force --insert-ignore -S /var/run/mysqld/mysqld.sock -u {$q->mysql_admin}{$Mysqlpassword} {$free2->mysql_database} >{$TMP_FILE} 2>&1"); if ($GLOBALS["VERBOSE"]) { echo "{$cmdline}\n"; } $results = array(); exec($cmdline, $results); while (list($num, $ligne) = each($results)) { echo "{$ligne}\n"; if (preg_match("#ERROR\\s+([0-9]+)#", $ligne)) { build_progress("{$servername}: {restore_database} {to} {$wordpressDB} {failed}..", 42); sleep(3); return false; } } build_progress("{$servername}: {restore_database} {to} {$wordpressDB}..", 42); $mysqlbin = $unix->find_program("mysql"); $cmd = "{$mysqlbin} --batch --force -S /var/run/mysqld/mysqld.sock -u {$q->mysql_admin}{$Mysqlpassword} --database={$wordpressDB} <{$TMP_FILE} 2>&1"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } exec($cmd, $results); while (list($num, $ligne) = each($results)) { echo "{$ligne}\n"; if (preg_match("#ERROR\\s+([0-9]+)#", $ligne)) { build_progress("{$servername}: {restore_database} {to} {$wordpressDB} {failed}..", 42); sleep(3); return false; } } build_progress("{$servername}: {restore_database} {to} {$wordpressDB}..{done}", 42); @unlink($TMP_FILE); if (!scan($WORKING_DIRECTORY)) { build_progress("{$servername}: {install} {failed}", 42); sleep(3); return false; } $proto = "http"; if ($free->useSSL == 1) { $proto = "https"; } $sql = "UPDATE `wp_options` SET `option_value`='{$proto}://{$servername}' WHERE `option_name`='siteurl'"; $q->QUERY_SQL($sql, $wordpressDB); if (!$q->ok) { echo $q->mysql_error; build_progress("{$servername}: {install} {failed}", 42); sleep(3); return false; } $sql = "UPDATE `wp_options` SET `option_value`='{$proto}://{$servername}' WHERE `option_name`='home'"; $q->QUERY_SQL($sql, $wordpressDB); if (!$q->ok) { echo $q->mysql_error; build_progress("{$servername}: {install} {failed}", 42); sleep(3); return false; } $free->groupware_duplicate = null; $free->CreateSite(true); return true; }
function virtualbox_nat_rebuild() { $unix = new unix(); $filetmp = $unix->FILE_TEMP(); $uuid = $_GET["virtualbox-nats-rebuild"]; shell_exec(LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.virtualbox.php --nat-rebuild {$uuid} >{$filetmp} 2>&1"); echo "<articadatascgi>" . base64_encode(@file_get_contents($filetmp)) . "</articadatascgi>"; @unlink($filetmp); }
function parse($filename) { $unix = new unix(); $LastScannLine = 0; $GLOBALS["MYSQL_CATZ"] = new mysql_catz(); $GLOBALS["SQUID_FAMILY_CLASS"] = new squid_familysite(); if (!isset($GLOBALS["MYHOSTNAME"])) { $unix = new unix(); $GLOBALS["MYHOSTNAME"] = $unix->hostname_g(); } $filesource = dirname(__FILE__) . "/ressources/conf/upload/{$filename}"; if (!is_file($filesource)) { build_progress(110, "{$filename} no such file"); return; } $tmpfile = $unix->FILE_TEMP(); if (!@copy($filesource, $tmpfile)) { @unlink($filesource); build_progress(110, "{$filename} -> {$tmpfile} {failed}"); return; } @unlink($filesource); $SumOflines = $unix->COUNT_LINES_OF_FILE($tmpfile); echo "{$tmpfile} {$SumOflines} lines\n"; $handle = @fopen($tmpfile, "r"); if (!$handle) { echo "Fopen failed on {$tmpfile}\n"; build_progress(110, "{$tmpfile} {failed}"); @unlink($tmpfile); return false; } $c = 0; $d = 0; $e = 0; $prc = 0; $prc_text = 0; $mysql_first_time = 0; $SITES = array(); $NOT_CATEGORIZED = array(); $CATEGORIZED = array(); $RQS = array(); $IPClass = new IP(); $FIRSTTIME = 0; $LASTTIME = 0; $TIME1 = time(); while (!feof($handle)) { $c++; $d++; $e++; $prc = $c / $SumOflines; $prc = round($prc * 100); $buffer = trim(fgets($handle)); if ($buffer == null) { continue; } $stats_sites = count($SITES); $stats_categorized = count($CATEGORIZED); $stats_not_categorized = count($NOT_CATEGORIZED); if (!isset($GLOBALS["LAST_PRC"])) { build_progress($prc, "{$c}/{$SumOflines} {please_wait}"); $GLOBALS["LAST_PRC"] = $prc; } if ($prc > 5) { if ($prc < 95) { if ($GLOBALS["LAST_PRC"] != $prc) { $array_load = sys_getloadavg(); $internal_load = $array_load[0]; $mem = round(memory_get_usage() / 1024 / 1000, 2); echo "Load: {$internal_load}, Memory {$mem}MB\n"; echo "Categorized: " . FormatNumber($stats_categorized) . "\n"; echo "Unknown....: " . FormatNumber($stats_not_categorized) . "\n"; echo "Web sites..: " . FormatNumber($stats_sites) . "\n"; build_progress($prc, FormatNumber($c) . "/" . FormatNumber($SumOflines) . " {please_wait} - {$mem}MB {memory}"); $GLOBALS["LAST_PRC"] = $prc; } } } $array = parseAccessLine($buffer); if (count($array) == 0) { continue; } $TIME = $array["TIME"]; $LASTTIME = $TIME; if ($FIRSTTIME == 0) { $FIRSTTIME = $TIME; } $CATEGORY = $array["CATEGORY"]; $FAMILYSITE = $array["FAMILYSITE"]; $SIZE = intval($array["SIZE"]); if ($IPClass->isIPAddress($FAMILYSITE)) { if (!isset($IPADDRESSES[$FAMILYSITE]["RQS"])) { $IPADDRESSES[$FAMILYSITE]["RQS"] = 1; $IPADDRESSES[$FAMILYSITE]["SIZE"] = 0; $IPADDRESSES[$FAMILYSITE]["CATEGORY"] = $CATEGORY; } else { $IPADDRESSES[$FAMILYSITE]["RQS"] = $IPADDRESSES[$FAMILYSITE]["RQS"] + 1; $IPADDRESSES[$FAMILYSITE]["SIZE"] = $IPADDRESSES[$FAMILYSITE]["SIZE"] + $SIZE; } continue; } if (!isset($SITES[$FAMILYSITE])) { $SITES[$FAMILYSITE] = 0; } if (!isset($RQS[$FAMILYSITE])) { $RQS[$FAMILYSITE] = 0; } $SITES[$FAMILYSITE] = $SITES[$FAMILYSITE] + $SIZE; $RQS[$FAMILYSITE] = $RQS[$FAMILYSITE] + 1; if ($CATEGORY != null) { $CATEGORIZED[$FAMILYSITE] = $CATEGORY; continue; } $NOT_CATEGORIZED[$FAMILYSITE] = true; } fclose($handle); @unlink($tmpfile); build_progress(91, "{building_report}"); $TIME2 = time(); $stats_sites = count($SITES); $stats_categorized = count($CATEGORIZED); $stats_not_categorized = count($NOT_CATEGORIZED); $ARRAY["DURATION"] = $unix->distanceOfTimeInWords($TIME1, $TIME2); $ARRAY["SumOflines"] = $SumOflines; $ARRAY["stats_sites"] = $stats_sites; $ARRAY["stats_ip"] = count($IPADDRESSES); $ARRAY["firsttime"] = $FIRSTTIME; $ARRAY["lasttime"] = $LASTTIME; $ARRAY["stats_categorized"] = $stats_categorized; $ARRAY["stats_not_categorized"] = $stats_not_categorized; build_progress(92, "{building_report}"); $CSV1[] = array("website", "size", "requests"); while (list($familysite, $ligne) = each($NOT_CATEGORIZED)) { $CSV1[] = array($familysite, $SITES[$familysite], $RQS[$familysite]); } build_progress(95, "{building_report}"); $CSV2[] = array("website", "category", "size", "requests"); while (list($familysite, $category) = each($CATEGORIZED)) { $CSV2[] = array($familysite, $category, $SITES[$familysite], $RQS[$familysite]); } build_progress(97, "{building_report}"); $CSV3[] = array("Public IP addresses", "category", "size", "requests"); while (list($ip, $ARRAYIPS) = each($IPADDRESSES)) { $category = $ARRAYIPS["CATEGORY"]; $size = $ARRAYIPS["SIZE"]; $RQS = $ARRAYIPS["RQS"]; $CSV3[] = array($ip, $category, $size, $RQS); } build_progress(99, "{saving_reports}"); outputCSV($CSV1, "/usr/share/artica-postfix/ressources/logs/notcategorized.csv"); outputCSV($CSV2, "/usr/share/artica-postfix/ressources/logs/categorized.csv"); outputCSV($CSV3, "/usr/share/artica-postfix/ressources/logs/ipcategorized.csv"); @file_put_contents("/usr/share/artica-postfix/ressources/logs/categorized.array", serialize($ARRAY)); @chmod("/usr/share/artica-postfix/ressources/logs/notcategorized.csv", 0755); @chmod("/usr/share/artica-postfix/ressources/logs/ipcategorized.csv", 0755); @chmod("/usr/share/artica-postfix/ressources/logs/categorized.csv", 0755); @chmod("/usr/share/artica-postfix/ressources/logs/categorized.array", 0755); build_progress(100, "{done}"); }
function vxvault() { $unix = new unix(); $q = new mysql_squid_builder(); $curl = new ccurl("http://vxvault.net/URL_List.php"); $targetpath = $unix->FILE_TEMP(); if (!$curl->GetFile($targetpath)) { if ($GLOBALS["VERBOSE"]) { echo "DOWNLOAD FAILED {$targetpath}\n"; } @unlink($targetpath); return false; } $lastmd5 = @file_get_contents("/etc/artica-postfix/settings/Daemons/vxvault.md5"); $Currentmd5 = md5_file($targetpath); if (!$GLOBALS["FORCE"]) { if ($lastmd5 == $Currentmd5) { return; } } $fp = @fopen($targetpath, "r"); if (!$fp) { if ($GLOBALS["DEBUG_GREP"]) { echo "{$targetpath} BAD FD\n"; } @unlink($targetpath); return array(); } $c = 0; $t = array(); while (!feof($fp)) { $line = trim(fgets($fp)); $line = str_replace("\r\n", "", $line); $line = str_replace("\n", "", $line); $line = str_replace("\r", "", $line); $line = str_replace("\\", "/", $line); if (!preg_match("#^http#", $line)) { if ($GLOBALS["VERBOSE"]) { echo "SKIP {$line}\n"; } continue; } if (preg_match("#http:\\/\\/(.+?)#", $line, $re)) { $line = $re[1]; } if (preg_match("#https:\\/\\/(.+?)#", $line, $re)) { $line = $re[1]; } $md5 = md5($line); $SQLZ[] = "('{$md5}',NOW(),'{$line}',1)"; if (count($SQLZ) > 500) { $q->QUERY_SQL($GLOBALS["PREFIX"] . @implode(",", $SQLZ)); if (!$q->ok) { echo $q->mysql_error; @fclose($fp); @unlink($targetpath); return; } } } @fclose($fp); @unlink($targetpath); if (count($SQLZ) > 0) { $q->QUERY_SQL($GLOBALS["PREFIX"] . @implode(",", $SQLZ)); if (!$q->ok) { echo $q->mysql_error; return; } } @file_put_contents("/etc/artica-postfix/settings/Daemons/vxvault.md5", $Currentmd5); }
function UPGRADE($noupdate = false) { if (system_is_overloaded(basename(__FILE__))) { system_admin_events("This system is too many overloaded, die()", __FUNCTION__, __FILE__, __LINE__, "system-update"); die; } $called = null; if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}"; } } system_admin_events("Running UPGRADE {$called}", __FUNCTION__, __FILE__, __LINE__, "system-update"); @unlink("/usr/share/artica-postfix/ressources/logs/web/debian.update.html"); $unix = new unix(); $sock = new sockets(); $EnableRebootAfterUpgrade = $sock->GET_INFO("EnableRebootAfterUpgrade"); if (!is_numeric($EnableRebootAfterUpgrade)) { $EnableRebootAfterUpgrade = 0; } $tmpf = $unix->FILE_TEMP(); $txt = "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin\n"; $txt = $txt . "echo \$PATH >{$tmpf} 2>&1\n"; $txt = $txt . "rm -f {$tmpf}\n"; $tmpf = $unix->FILE_TEMP(); @file_put_contents($tmpf, $txt); @chmod($tmpf, '0777'); shell_exec($tmpf); $tmpf = $unix->FILE_TEMP(); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes update >{$tmpf} 2>&1"; system_admin_events($cmd, __FUNCTION__, __FILE__, __LINE__, "system-update"); shell_exec($cmd); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes --yes install -f >{$tmpf} 2>&1"; system_admin_events($cmd, __FUNCTION__, __FILE__, __LINE__, "system-update"); shell_exec($cmd); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes --yes upgrade >>{$tmpf} 2>&1"; system_admin_events($cmd, __FUNCTION__, __FILE__, __LINE__, "system-update"); shell_exec($cmd); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes --yes dist-upgrade >>{$tmpf} 2>&1"; system_admin_events($cmd, __FUNCTION__, __FILE__, __LINE__, "system-update"); shell_exec($cmd); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes --yes autoremove >>{$tmpf} 2>&1"; system_admin_events($cmd, __FUNCTION__, __FILE__, __LINE__, "system-update"); shell_exec($cmd); $datas = @file_get_contents($tmpf); $datassql = addslashes($datas); $q = new mysql(); $sql = "INSERT IGNORE INTO debian_packages_logs(zDate,package_name,events,install_type) VALUES(NOW(),'artica-upgrade','{$datassql}','upgrade');"; $q->QUERY_SQL($sql, "artica_backup"); @unlink('/etc/artica-postfix/apt.upgrade.cache'); if (!$noupdate) { GetUpdates(); } send_email_events("Debian/Ubuntu System upgrade operation", $datas, "update"); INSERT_DEB_PACKAGES(); if ($EnableRebootAfterUpgrade == 1) { send_email_events("Rebooting after upgrade operation", "reboot command has been performed", "update"); shell_exec("reboot"); } }
function restore_tables($filename) { $unix = new unix(); $sock = new sockets(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".restore_tables." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n"; } return; } $filepath = dirname(__FILE__) . "/ressources/conf/upload/{$filename}"; if (!is_file($filename)) { build_progress("{failed} {$filename} no such file", 110); return; } $tmpf = $unix->FILE_TEMP(); build_progress("{uncompress} {$filename}", 10); if (!$unix->uncompress($filename, $tmpf)) { build_progress("{uncompress} {$filename} {failed}", 110); return; } @unlink($filename); build_progress("{importing} {$tmpf}", 50); $mysql = $unix->find_program("mysql"); $q = new mysql_squid_builder(); $cmd = "{$mysql} {$q->MYSQL_CMDLINES} -f squidlogs < {$tmpf}"; system($cmd); build_progress("{done}", 100); @unlink($tmpf); }
function IpCalcRoute($ipsingle){ if(!preg_match("#(.+?)\.([0-9]+)$#",$ipsingle,$re)){ writelogs("Unable to match $ipsingle",__FUNCTION__,__FILE__,__LINE__); return null; } $unix=new unix(); $tmp=$unix->FILE_TEMP(); shell_exec("/usr/share/artica-postfix/bin/ipcalc {$re[1]}.0 >$tmp 2>&1"); $arr=explode("\n",@file_get_contents($tmp)); @unlink($tmp); while (list ($num, $ligne) = each ($arr) ){ if(preg_match("#^Netmask:\s+(.+?)\s+#",$ligne,$ri)){ return "{$re[1]}.0 {$ri[1]}"; } } }
function OCSWEB_PACKAGE_FRAGS() { $sourcefile = base64_decode($_GET["filesource"]); $unix = new unix(); $userwww = $unix->APACHE_GROUPWARE_ACCOUNT(); if (trim($sourcefile) == null) { writelogs_framework("OCS-PACKAGES:: base64_decode({$_GET["filesource"]})=\"NULL\" aborting", __FUNCTION__, __FILE__, __LINE__); return; } $FILEID = $_GET["FILEID"]; if (trim($FILEID) == null) { writelogs_framework("OCS-PACKAGES:: FILEID=\"NULL\" aborting", __FUNCTION__, __FILE__, __LINE__); return; } $nbfrags = $_GET["nbfrags"]; if (trim($nbfrags) == null) { writelogs_framework("OCS-PACKAGES:: nbfrags=\"NULL\" aborting", __FUNCTION__, __FILE__, __LINE__); return; } $TMP = $unix->FILE_TEMP(); shell_exec("/bin/cp {$sourcefile} {$TMP}"); $document_root = "/var/lib/ocsinventory-reports"; writelogs_framework("OCS-PACKAGES:: nbfrags=\"{$nbfrags}\"", __FUNCTION__, __FILE__, __LINE__); writelogs_framework("OCS-PACKAGES:: SOURCE=\"{$sourcefile}\"", __FUNCTION__, __FILE__, __LINE__); writelogs_framework("OCS-PACKAGES:: DEST=\"{$TMP}\"", __FUNCTION__, __FILE__, __LINE__); @mkdir("{$document_root}/download/{$FILEID}", 0755, true); @chmod("{$document_root}/download/{$FILEID}", 0755); @chown("{$document_root}/download/{$FILEID}", $userwww); $fname = $TMP; if ($size = @filesize($fname)) { writelogs_framework("OCS-PACKAGES:: SIZE=\"{$size}\"", __FUNCTION__, __FILE__, __LINE__); $handle = fopen($fname, "rb"); $read = 0; for ($i = 1; $i < $nbfrags; $i++) { $contents = fread($handle, $size / $nbfrags); $read += strlen($contents); writelogs_framework("OCS-PACKAGES:: OPEN=\"{$document_root}/download/{$FILEID}/{$FILEID}-{$i}\"", __FUNCTION__, __FILE__, __LINE__); $handfrag = fopen("{$document_root}/download/{$FILEID}/{$FILEID}-{$i}", "w+b"); fwrite($handfrag, $contents); fclose($handfrag); @chown("{$document_root}/download/{$FILEID}/{$FILEID}-{$i}", $userwww); } $contents = fread($handle, $size - $read); $read += strlen($contents); $handfrag = fopen("{$document_root}/download/{$FILEID}/{$FILEID}-{$i}", "w+b"); fwrite($handfrag, $contents); fclose($handfrag); fclose($handle); @chown("{$document_root}/download/{$FILEID}/{$FILEID}-{$i}", $userwww); unlink($TMP); } exec("/bin/chown -R {$userwww} {$document_root}/download/{$FILEID}", $results); while (list($num, $ligne) = each($results)) { writelogs_framework("OCS-PACKAGES:: chown: {$ligne}", __FUNCTION__, __FILE__, __LINE__); } }
function ParseMailboxDirRsync($pattern) { $backup = new backup_protocols(); $unix = new unix(); $rsync = $unix->find_program("rsync"); $array = $backup->extract_rsync_protocol($pattern); if (!is_array($array)) { writelogs(date('m-d H:i:s') . " " . "rsync protocol error", __FUNCTION__, __FILE__, __LINE__); return false; } if ($array["PASSWORD"] != null) { $tmpstr = $unix->FILE_TEMP(); @file_put_contents($tmpstr, $array["PASSWORD"]); $pwd = " --password-file={$tmpstr}"; } if ($array["USER"] != null) { $user = "******"USER"]}@"; } $pattern_list = "{$rsync} --list-only{$pwd} rsync://{$user}{$array["SERVER"]}/{$array["FOLDER"]}/ --stats --dry-run 2>&1"; if ($GLOBALS["DEBUG"]) { echo "ParseMailboxDirRsync():: Listing files or directories using \"{$pattern_list}\"\n"; } writelogs(date('m-d H:i:s') . " " . "{$pattern_list}", __FUNCTION__, __FILE__, __LINE__); exec($pattern_list, $results); @unlink($tmpstr); unset($array); while (list($num, $line) = each($results)) { if (preg_match("#^d[rwx\\-]+\\s+[0-9]+\\s+[0-9\\/]+\\s+[0-9\\:]+\\s+(.+)#", $line, $re)) { writelogs($re[1], __FUNCTION__, __FILE__, __LINE__); if (trim($re[1]) == '.') { continue; } $array[trim($re[1])] = trim($re[1]); continue; } } return $array; }
function disk_build_unique_partition($dev, $label, $fs_type = null) { $filelogs = "/usr/share/artica-postfix/ressources/logs/web/system.partition.txt"; $GLOBALS["FILELOG"] = $filelogs; $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . md5($dev . $label); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { events("Already PID {$pid} exists, aborting..."); build_progress("Already PID {$pid} exists, aborting", 110); return; } build_progress("{checking}", 5); events("***********************************"); events("Dev.........: {$dev}"); events("Label.......: {$label}"); events("FileSystem..: {$fs_type}"); $mount = $unix->find_program("mount"); $disk_label = str_replace(" ", "_", $label); $targetMountPoint = $unix->isDirInFsTab("/media/{$disk_label}"); events("Target Mount.: {$targetMountPoint}"); build_progress("Target Mount point = {$targetMountPoint}", 10); events("***********************************"); if ($targetMountPoint != null) { events("/media/{$disk_label} already set in fstab!! remove entry in fstab first..."); events("Mounting the new media"); build_progress("Mounting the new media = /media/{$disk_label}", 15); $cmd = "{$mount} /media/{$disk_label} 2>&1"; $results = array(); exec($cmd, $results); while (list($num, $val) = each($results)) { events($val); } build_progress("{success}", 100); return; } $tmpfile = $unix->FILE_TEMP(); build_progress("Creating disk configuration", 20); events("Writing to {$tmpfile}"); @file_put_contents($tmpfile, ",,L\n"); if (!is_file($tmpfile)) { build_progress("Creating disk configuration {$tmpfile} {failed}", 110); return; } events("Cleaning {$dev}..., please wait..."); $dd = $unix->find_program("dd"); $sfdisk = $unix->find_program("sfdisk"); $mkfs = $unix->find_program("mkfs.ext4"); $btrfs = $unix->find_program("mkfs.btrfs"); $xfs = $unix->find_program("mkfs.xfs"); $mount = $unix->find_program("mount"); events("{$dev} filesystem {$fs_type}"); $extV = $fs_type; $e2label = $unix->find_program("e2label"); $e2label_EX = true; $MKFS["ext3"] = "-b 4096 -L \"{$disk_label}\""; $MKFS["ext4"] = "-L \"{$disk_label}\" -i 8096 -I 256 -Tlargefile4"; $MKFS["btrfs"] = "--label \"{$disk_label}\""; $MKFS["xfs"] = "-f -L \"{$disk_label}\""; $MKFS["reiserfs"] = "-q --label \"{$disk_label}\""; if ($fs_type == null) { $fs_type = "ext4"; } $pgr = $unix->find_program("mkfs.{$fs_type}"); events("mkfs.{$fs_type} = {$pgr}"); if (is_file($pgr)) { $mkfs = "{$pgr} {$MKFS[$fs_type]} "; $extV = "{$fs_type}"; $e2label_EX = false; } build_progress("Cleaning {$dev}..., {please_wait}", 30); events("Cleaning {$dev}..., please wait..."); $cmd = "{$sfdisk} -f {$dev} <{$tmpfile} 2>&1"; events($cmd); $results = array(); exec($cmd, $results); while (list($num, $val) = each($results)) { events($val); } $FindFirstPartition = FindFirstPartition($dev); events("First partition = `{$FindFirstPartition}`"); build_progress("First partition {$FindFirstPartition}", 50); if ($FindFirstPartition == null) { build_progress("Find first partition failed", 110); events("First partition = FAILED"); return; } build_progress("Building {$FindFirstPartition}..., {please_wait}", 40); $cmd = "{$dd} if=/dev/zero of={$FindFirstPartition} bs=512 count=1 2>&1"; events($cmd); $results = array(); exec($cmd, $results); while (list($num, $val) = each($results)) { events($val); } build_progress("Formating {$FindFirstPartition}", 60); $cmd = "{$mkfs} {$FindFirstPartition} 2>&1"; events("Formatting {$FindFirstPartition}, please wait...."); events($cmd); $results = array(); exec($cmd, $results); while (list($num, $val) = each($results)) { events($val); } if ($e2label_EX) { build_progress("Set label to {$disk_label}", 70); events("Set label to {$disk_label}"); $cmd = "{$e2label} {$FindFirstPartition} {$disk_label} 2>&1"; events($cmd); $results = array(); exec($cmd, $results); while (list($num, $val) = each($results)) { events($val); } } build_progress("Change fstab {$FindFirstPartition} to /media/{$disk_label}", 80); events("Change fstab to include new media {$FindFirstPartition} to /media/{$disk_label}"); disk_change_fstab($FindFirstPartition, $extV, "/media/{$disk_label}"); build_progress("Mounting the new media", 90); events("Mounting the new media"); $cmd = "{$mount} {$FindFirstPartition} 2>&1"; events($cmd); $results = array(); exec($cmd, $results); while (list($num, $val) = each($results)) { events($val); } $php = $unix->LOCATE_PHP5_BIN(); build_progress("Rebuild caches", 95); shell_exec("{$php} /usr/share/artica-postfix/exec.usb.scan.write.php"); build_progress("{success}", 100); events("done..."); }
function GET_MD5S_REMOTE() { if (!ifMustBeExecuted()) { $GLOBALS["LOGS"][] = "ifMustBeExecuted():: No make sense to execute this script."; WriteMyLogs("ifMustBeExecuted():: No make sense to execute this script...", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "No make sense to execute this script...\n"; } die; } $unix = new unix(); $BASE_URI = "ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib"; $indexuri = "{$BASE_URI}/MD5SUM.LST"; $cache_temp = $unix->FILE_TEMP(); $curl = new ccurl($indexuri); build_progress("Downloading {$indexuri}", 11); WriteMyLogs("Downloading {$indexuri}", __FUNCTION__, __FILE__, __LINE__); $curl->Timeout = 320; if (!$curl->GetFile($cache_temp)) { build_progress("{failed} {$curl->error}", 110); $errorDetails = @implode("\n", $GLOBALS["CURLDEBUG"]); WriteMyLogs("Fatal error downloading {$indexuri} {$curl->error}\n{$errorDetails}", __FUNCTION__, __FILE__, __LINE__); artica_update_event(0, "Web filtering databases, unable to download index file", "Fatal error downloading {$indexuri} {$curl->error}\n{$errorDetails}", __FILE__, __LINE__); die; } $indexuri = "{$BASE_URI}/global_usage"; $curl = new ccurl($indexuri); build_progress("Downloading {$indexuri}", 12); if (!$curl->GetFile("/etc/artica-postfix/univtoulouse-global_usage")) { $errorDetails = @implode("\n", $GLOBALS["CURLDEBUG"]); WriteMyLogs("Fatal error downloading {$indexuri} {$curl->error}\n{$errorDetails}", __FUNCTION__, __FILE__, __LINE__); artica_update_event(0, "Web filtering databases, unable to download global_usage file", "Fatal error downloading {$indexuri} {$curl->error}\n{$errorDetails}", __FILE__, __LINE__); } $f = explode("\n", @file_get_contents($cache_temp)); while (list($index, $line) = each($f)) { if (trim($line) == null) { continue; } if (!preg_match("#^([a-z0-9]+)\\s+([a-z0-9\\.]+)\$#", $line, $re)) { continue; } $md5 = $re[1]; $filename = $re[2]; if ($filename == "blacklists.tar.gz") { continue; } if ($filename == "domains.tar.gz") { continue; } if ($filename == "MD5SUM.LST") { continue; } $ARRAYSUM_REMOTE[$filename] = $md5; } return $ARRAYSUM_REMOTE; }
function top10cpumem() { $unix = new unix(); $ps = $unix->find_program("ps"); $sort = $unix->find_program("sort"); $pr = $unix->find_program("pr"); $head = $unix->find_program("head"); $tmpfile = $unix->FILE_TEMP(); $date = date("Y-m-d H:i:s"); $cmd = "ps aux 2>&1| sort -nrk 3 2>&1| head -10 >{$tmpfile} 2>&1"; $line = null; $index = 0; shell_exec($cmd); $results = array(); $results = explode("\n", @file_get_contents($tmpfile)); while (list($index, $line) = each($results)) { usleep(55000); if (!preg_match("#(.+?)\\s+([0-9]+)\\s+([0-9\\.]+)\\s+([0-9\\.]+)\\s+([0-9]+)\\s+([0-9\\.]+)\\s+.+?\\s+.+?\\s+([0-9\\:]+)\\s+([0-9\\:]+)\\s+(.+?)\$#", $line, $re)) { if (preg_match("#(.+?)\\s+([0-9]+)\\s+([0-9\\.]+)\\s+([0-9\\.]+)\\s+([0-9]+)\\s+([0-9]+)\\s+.+?\\s+.+?\\s+([a-zA-Z0-9]+)\\s+([0-9\\:]+)\\s+(.+?)\$#", $line, $re)) { $user = $re[1]; $pid = $re[2]; $pourcCPU = $re[3]; $purcMEM = $re[4]; $VSZ = $re[5]; $RSS = $re[6]; $START = $re[7]; $TIME = $re[8]; $cmd = $re[9]; $array_cpu[] = array("PID" => $pid, "CPU" => $pourcCPU, "MEM" => $purcMEM, "START" => $START, "TIME" => $TIME, "CMD" => $cmd); continue; } continue; } $user = $re[1]; $pid = $re[2]; $pourcCPU = $re[3]; $purcMEM = $re[4]; $VSZ = $re[5]; $RSS = $re[6]; $START = $re[7]; $TIME = $re[8]; $cmd = $re[9]; $pourcCPU = str_replace("0.0", "0", $pourcCPU); $purcMEM = str_replace("0.0", "0", $purcMEM); if ($pourcCPU == 0) { continue; } $array_cpu[] = array("DATE" => $date, "PID" => $pid, "CPU" => $pourcCPU, "MEM" => $purcMEM, "START" => $START, "TIME" => $TIME, "CMD" => $cmd); } $date = date("Y-m-d H:i:s"); $cmd = "ps aux 2>&1|sort -nrk 4 2>&1|head -10 >{$tmpfile} 2>&1"; shell_exec($cmd); $results = explode("\n", @file_get_contents($tmpfile)); while (list($index, $line) = each($results)) { usleep(55000); if (!preg_match("#(.+?)\\s+([0-9]+)\\s+([0-9\\.]+)\\s+([0-9\\.]+)\\s+([0-9]+)\\s+([0-9\\.]+)\\s+.+?\\s+.+?\\s+([0-9\\:]+)\\s+([0-9\\:]+)\\s+(.+?)\$#", $line, $re)) { if (preg_match("#(.+?)\\s+([0-9]+)\\s+([0-9\\.]+)\\s+([0-9\\.]+)\\s+([0-9]+)\\s+([0-9]+)\\s+.+?\\s+.+?\\s+([a-zA-Z0-9]+)\\s+([0-9\\:]+)\\s+(.+?)\$#", $line, $re)) { $user = $re[1]; $pid = $re[2]; $pourcCPU = $re[3]; $purcMEM = $re[4]; $VSZ = $re[5]; $RSS = $re[6]; $START = $re[7]; $TIME = $re[8]; $cmd = $re[9]; $array_mem[] = array("DATE" => $date, "PID" => $pid, "CPU" => $pourcCPU, "MEM" => $purcMEM, "START" => $START, "TIME" => $TIME, "CMD" => $cmd, "VSZ" => $VSZ, "RSS" => $RSS); continue; } continue; } $user = $re[1]; $pid = $re[2]; $pourcCPU = $re[3]; $purcMEM = $re[4]; $VSZ = $re[5]; $RSS = $re[6]; $START = $re[7]; $TIME = $re[8]; $cmd = $re[9]; $pourcCPU = str_replace("0.0", "0", $pourcCPU); $purcMEM = str_replace("0.0", "0", $purcMEM); if ($purcMEM == 0) { continue; } $array_mem[] = array("PID" => $pid, "CPU" => $pourcCPU, "MEM" => $purcMEM, "START" => $START, "TIME" => $TIME, "CMD" => $cmd, "VSZ" => $VSZ, "RSS" => $RSS); } $array["TOP_CPU"] = $array_cpu; $array["TOP_MEM"] = $array_mem; return base64_encode(serialize($array)); }
function NMAP_SCAN($value) { $value = base64_decode($value); $EXEC_NICE = EXEC_NICE(); $unix = new unix(); $tmpstr = $unix->FILE_TEMP(); @unlink("/usr/share/artica-postfix/ressources/logs/nmap.log"); $cmd = $EXEC_NICE . LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.scan-networks.php >{$tmpstr} 2>&1"; events("running {$cmd}", __FUNCTION__, __FILE__, __LINE__); $t1 = time(); shell_exec($cmd); $t2 = time(); $time_duration = distanceOfTimeInWords($t1, $t2); events("success executing exec.scan-networks.php ", __FUNCTION__, __FILE__, __LINE__); send_email_events("success executing network scanning ({$time_duration})", @file_get_contents("/usr/share/artica-postfix/ressources/logs/nmap.log"), "CLOUD"); @unlink($tmpstr); return true; }
function SingleInstance_start($nopid = false) { $sock = new sockets(); $unix = new unix(); if (!$nopid) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . "pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid)) { echo "{$GLOBALS["deflog_start"]} already Artica Starting process exists {$pid}\n"; return; } @file_put_contents($pidfile, getmypid()); } $miltergreybin = $unix->find_program("milter-greylist"); $MilterGreyListEnabled = $sock->GET_INFO("MilterGreyListEnabled"); if (!is_numeric($MilterGreyListEnabled)) { $MilterGreyListEnabled = 0; } $pid = SingleInstance_pid(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } if ($MilterGreyListEnabled == 0) { echo "{$GLOBALS["deflog_start"]} is not enabled ( see MilterGreyListEnabled)\n"; return; } $dirs[] = "/var/run/milter-greylist"; $dirs[] = "/var/spool/postfix/var/run/milter-greylist"; $dirs[] = "/var/milter-greylist"; $dirs[] = "/var/lib/milter-greylist"; $dirs[] = "/usr/local/var/milter-greylist/"; while (list($num, $directory) = each($dirs)) { @mkdir($directory, 0755, true); @chown($directory, "postfix"); @chgrp($directory, "postfix"); @chmod($directory, 0755); } $FullSocketPath = "/var/run/milter-greylist/milter-greylist.sock"; $pidpath = "/var/run/milter-greylist/milter-greylist.pid"; $dbpath = "/var/milter-greylist/greylist.db"; $confpath = SingleInstanceConfPath(); $files[] = "/var/milter-greylist/greylist.db"; $files[] = "/usr/local/var/milter-greylist/greylist.db"; while (list($num, $filename) = each($files)) { if (!is_file($filename)) { @touch($filename); } @chown($filename, "postfix"); @chgrp($filename, "postfix"); } $MilterGreyListUseTCPPort = $sock->GET_INFO("MilterGreyListUseTCPPort"); $MilterGeryListTCPPort = $sock->GET_INFO("MilterGeryListTCPPort"); if (!is_numeric($MilterGeryListTCPPort)) { $MilterGeryListTCPPort = 0; } if (!is_numeric($MilterGreyListUseTCPPort)) { $MilterGreyListUseTCPPort = 0; } if ($MilterGeryListTCPPort == 0) { $MilterGreyListUseTCPPort = 0; } if (!is_file($confpath)) { SingleInstance(); } if (!is_file($dbpath)) { @touch($dbpath); } @chown($dbpath, "postfix"); @chgrp($dbpath, "postfix"); if ($MilterGreyListUseTCPPort == 1) { $FullSocketPath = "inet:{$MilterGeryListTCPPort}"; } $tmpfile = $unix->FILE_TEMP(); $nohup = $unix->find_program("nohup"); if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} running daemon {$miltergreybin}\n"; } $cmd = "{$nohup} {$miltergreybin} -u postfix -P {$pidpath} -p {$FullSocketPath} -f {$confpath} -d {$dbpath} >{$tmpfile} 2>&1 &"; if ($GLOBALS["VERBOSE"]) { echo "**** \n {$cmd} \n ************\n"; } shell_exec($cmd); $f = explode("\n", @file_get_contents("{$tmpfile}")); while (list($num, $ligne) = each($f)) { $ligne = trim($ligne); if ($ligne == null) { continue; } if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} {$ligne}\n"; } } if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} waiting 5s\n"; } for ($i = 1; $i < 6; $i++) { if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} waiting {$i}/5\n"; } sleep(1); $pid = SingleInstance_pid(); if ($unix->process_exists($pid)) { break; } } $pid = SingleInstance_pid(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} Success PID {$pid}\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "{$GLOBALS["deflog_start"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "{$cmd}\n"; } } }
function WriteDisclaimer($text, $temp_file) { $unix = new unix(); $text = stripslashes($text); $tmp_disclaimer = $unix->FILE_TEMP(); $tmp_disclaimer2 = $unix->FILE_TEMP() . ".txt"; @file_put_contents($tmp_disclaimer, $text); $disctxt = br2nl($text); $disctxt = p2nl($disctxt); $disctxt = strip_tags($disctxt); $disctxt = html_entity_decode($disctxt); @file_put_contents($tmp_disclaimer2, $disctxt); events("{$temp_file} write disclaimer " . strlen($text) . " bytes", __FUNCTION__, __LINE__); $cmd = "/usr/local/bin/altermime --input={$temp_file} --log-syslog --disclaimer={$tmp_disclaimer2} --disclaimer-html={$tmp_disclaimer} --xheader=X-Copyrighted-Material:"; shell_exec($cmd); @unlink($tmp_disclaimer2); @unlink($tmp_disclaimer); }
function SYSLOG_QUERY() { $preprend = $_GET["prepend"]; $pattern = trim(base64_decode($_GET["syslog-query"])); if ($pattern == "yes") { $pattern = null; } $pattern = str_replace(" ", " ", $pattern); $pattern = str_replace(" ", "\\s+", $pattern); $pattern = str_replace(".", "\\.", $pattern); $pattern = str_replace("*", ".+?", $pattern); $pattern = str_replace("/", "\\/", $pattern); $syslogpath = $_GET["syslog-path"]; $maxrows = 0; if ($syslogpath == null) { exec("/usr/share/artica-postfix/bin/artica-install --whereis-syslog", $results); while (list($num, $ligne) = each($results)) { if (preg_match('#SYSLOG:"(.+?)"#', $ligne, $re)) { $syslogpath = $re[1]; break; writelogs_framework("artica-install --whereis-syslog {$syslogpath}", __FUNCTION__, __FILE__, __LINE__); } else { writelogs_framework("{$ligne} no match", __FUNCTION__, __FILE__, __LINE__); } } } $unix = new unix(); $grepbin = $unix->find_program("grep"); $tail = $unix->find_program("tail"); if ($tail == null) { return; } if (isset($_GET["prefix"])) { if (trim($_GET["prefix"]) != null) { if (strpos($_GET["prefix"], ",") > 0) { $_GET["prefix"] = "(" . str_replace(",", "|", $_GET["prefix"]) . ")"; } $_GET["prefix"] = str_replace("*", ".*?", $_GET["prefix"]); $pattern = "{$_GET["prefix"]}.*?\\[[0-9]+\\].*?{$pattern}"; } } if ($preprend != null) { $grep = "{$grepbin} '{$preprend}'"; if (strpos($preprend, ",") > 0) { $grep = "{$grepbin} -E '(" . str_replace(",", "|", $preprend) . ")'"; } } writelogs_framework("Pattern \"{$pattern}\"", __FUNCTION__, __FILE__, __LINE__); if (isset($_GET["rp"])) { $maxrows = $_GET["rp"]; } if ($maxrows == 0) { $maxrows = 500; } if (strlen($pattern) > 1) { if ($preprend != null && strlen($preprend) > 3) { $preprend = "'" . $preprend . "'"; if (strpos($preprend, ",") > 0) { $preprend = " -E '(" . str_replace(",", "|", $preprend) . ")'"; } $grep = "{$grepbin} {$preprend}|{$grepbin} -i -E '{$pattern}'"; } else { $grep = "{$grepbin} -i -E '{$pattern}'"; } } unset($results); $l = $unix->FILE_TEMP(); if ($grep != null) { $cmd = "{$tail} -n 5000 {$syslogpath}|{$grep}|{$tail} -n {$maxrows} 2>&1"; } else { $cmd = "{$tail} -n {$maxrows} {$syslogpath} 2>&1"; } writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); if (count($results) < 3) { $maxrows = $maxrows + 2000; if ($grep != null) { $cmd = "{$tail} -n 5000 {$syslogpath}|{$grep} |{$tail} -n {$maxrows} 2>&1"; } else { $cmd = "{$tail} -n {$maxrows} {$syslogpath} 2>&1"; } writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); } if (count($results) < 3) { $maxrows = $maxrows + 5000; if ($grep != null) { $cmd = "{$grep} {$syslogpath}|{$tail} -n {$maxrows} 2>&1"; } else { $cmd = "{$tail} -n {$maxrows} {$syslogpath} 2>&1"; } writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/syslog.query", @implode("\n", $results)); @chmod("/usr/share/artica-postfix/ressources/logs/web/syslog.query", 0755); }
function start() { $unix = new unix(); $sock = new sockets(); if (!isset($GLOBALS["MYSQL_BIN_PATH"])) { $GLOBALS["MYSQL_BIN_PATH"] = null; } if (!isset($GLOBALS["mysql_install_db"])) { $GLOBALS["mysql_install_db"] = true; } $pidfile = $GLOBALS["MYPID"]; $WORKDIR = $GLOBALS["WORKDIR"]; $SERV_NAME = $GLOBALS["SERV_NAME"]; $mysql_pid_file = $GLOBALS["MYSQL_PID"]; $MYSQL_SOCKET = $GLOBALS["MYSQL_SOCKET"]; $ArticaDBPath = $sock->GET_INFO("ArticaDBPath"); if ($ArticaDBPath == null) { $ArticaDBPath = "/opt/articatech"; } $GLOBALS["WORKDIR"] = $ArticaDBPath; $GLOBALS["MYSQL_BIN_PATH"] = "{$GLOBALS["WORKDIR"]}/bin/articadb"; $OutputBinLog = $unix->FILE_TEMP(); $mysqlserv = new mysql_services(); $mysqlserv->WORKDIR = $GLOBALS["WORKDIR"]; $mysqlserv->MYSQL_PID_FILE = $mysql_pid_file; $mysqlserv->MYSQL_SOCKET = $MYSQL_SOCKET; $mysqlserv->SERV_NAME = $SERV_NAME; $mysqlserv->TokenParams = "MySQLCatzParams"; $mysqlserv->INSTALL_DATABASE = $GLOBALS["mysql_install_db"]; $mysqlserv->MYSQL_BIN_DAEMON_PATH = $GLOBALS["MYSQL_BIN_PATH"]; $mysqlserv->MYSQL_ERRMSG = $GLOBALS["MYSQL_ERRMSG"]; $mysqlserv->InnoDB = false; $mysqlserv->OutputBinLog = $OutputBinLog; $pid = $unix->get_pid_from_file($pidfile); $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance"); $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics"); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); $SquidActHasReverse = $sock->GET_INFO("SquidActHasReverse"); if (!is_numeric($EnableWebProxyStatsAppliance)) { $EnableWebProxyStatsAppliance = 0; } if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if (!is_numeric($SquidActHasReverse)) { $SquidActHasReverse = 0; } if ($unix->isNGnx()) { $SquidActHasReverse = 0; } $EnableArticaDB = 1; if (is_file('/etc/artica-postfix/WEBSTATS_APPLIANCE')) { $EnableWebProxyStatsAppliance = 1; } if (is_file('/etc/artica-postfix/SQUID_REVERSE_APPLIANCE')) { $EnableArticaDB = 0; } if ($DisableArticaProxyStatistics == 1) { $EnableArticaDB = 0; } if ($EnableRemoteStatisticsAppliance == 1) { $EnableArticaDB = 0; } if ($EnableWebProxyStatsAppliance == 1) { $EnableArticaDB = 1; } if ($SquidActHasReverse == 1) { $EnableArticaDB = 0; } if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Starting Task Already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $mysql_install_db = $unix->find_program("mysql_install_db"); if ($EnableArticaDB == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is disabled...\n"; } stop(); die(0); } if ($GLOBALS["MYSQL_BIN_PATH"] != null) { $mysqld = $GLOBALS["MYSQL_BIN_PATH"]; } else { $mysqld = $unix->find_program("mysqld"); } if (!is_file($mysqld)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is not installed...\n"; } return; } if ($GLOBALS["mysql_install_db"]) { if (!is_file($mysql_install_db)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} mysql_install_db no such binary...\n"; } return; } } $pid = DBPID(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL Database Engine already running pid {$pid} since {$time}mn\n"; } return; } if (!is_file("{$GLOBALS["WORKDIR"]}/VERSION")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Corrupted database, launch updates...\n"; } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} writing init.d\n"; } initd(); $TMP = $unix->FILE_TEMP(); $cmdline = $mysqlserv->BuildParams(); $nohup = $unix->find_program("nohup"); if ($GLOBALS["VERBOSE"]) { echo $cmdline . "\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} Starting MySQL daemon ({$SERV_NAME})\n"; } shell_exec("{$nohup} {$cmdline} >{$TMP} 2>&1 &"); sleep(1); for ($i = 0; $i < 5; $i++) { $pid = DBPID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) started pid .{$pid}..\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} MySQL daemon wait {$i}/5\n"; } sleep(1); } sleep(1); $pid = DBPID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) failed to start\n"; } $f = explode("\n", @file_get_contents($TMP)); $repair = false; while (list($num, $ligne) = each($f)) { if (trim($ligne) == null) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} {$ligne}\n"; } } $mysqlserv->CheckOutputErrors($TMP); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) success\n"; } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} {$cmdline}\n"; } } $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize"); }