function startx() { build_progress("{rebuild_ssl_cache}: Removing SSL cache", 10); $unix = new unix(); $rm = $unix->find_program("rm"); $chown = $unix->find_program("chown"); if ($GLOBALS["RESTART"]) { build_progress("{rebuild_ssl_cache}: {stopping_proxy_service}", 30); system("/etc/init.d/squid stop --script=" . basename(__FILE__)); } echo "Remove /var/lib/squid/session/ssl/ssl_db\n"; shell_exec("{$rm} -rf /var/lib/squid/session/ssl/ssl_db"); build_progress("{rebuild_ssl_cache}: Reconstruct SSL cache", 50); $sslcrtd_program = $unix->squid_locate_generic_bin("ssl_crtd"); system("{$sslcrtd_program} -c -s /var/lib/squid/session/ssl/ssl_db"); system("{$chown} -R squid:squid /var/lib/squid/session"); build_progress("{rebuild_ssl_cache}: Reload Proxy service", 60); system("/etc/init.d/cache-tail restart --force"); if ($GLOBALS["RESTART"]) { build_progress("{rebuild_ssl_cache}: {starting_proxy_service}", 30); system("/etc/init.d/squid start --script=" . basename(__FILE__)); build_progress("{rebuild_ssl_cache}: {done}", 100); return; } build_progress("{rebuild_ssl_cache}: Reload Proxy service", 70); system("/etc/init.d/squid reload --force --script=" . basename(__FILE__)); build_progress("{rebuild_ssl_cache}: {done}", 100); }
function disks_scan() { $unix = new unix(); $btrfs = $unix->find_program("btrfs"); $blkid = $unix->find_program("blkid"); $cmd = "{$btrfs} filesystem show 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); while (list($num, $ligne) = each($results)) { if (preg_match("#Label:\\s+'(.*?)'\\s+uuid:\\s+(.+)#i", $ligne, $re)) { $UUID = $re[2]; $array[$UUID]["LABEL"] = $re[1]; $array[$UUID]["DEV"] = exec("{$blkid} -U {$UUID}"); $array[$UUID]["MOUNTED"] = $unix->MOUNTED_PATH($array[$UUID]["DEV"]); $array[$UUID]["DF"] = $unix->BLKID_INFOS($array[$UUID]["DEV"]); continue; } if (preg_match("#Total devices.+?FS bytes used (.+)#", $ligne, $re)) { $array[$UUID]["USED"] = $re[1]; continue; } if (preg_match("#devid\\s+([0-9]+)\\s+size\\s+(.+?)\\s+used\\s+(.+?)\\s+path\\s+(.+)#", $ligne, $re)) { writelogs_framework("{$UUID}: {$ligne}", __FUNCTION__, __FILE__, __LINE__); writelogs_framework("{$UUID}: {$re[4]}: SIZE: {$re[2]}", __FUNCTION__, __FILE__, __LINE__); $array[$UUID]["DEVICES"][$re[1]]["SIZE"] = $re[2]; $array[$UUID]["DEVICES"][$re[1]]["USED"] = $re[3]; $array[$UUID]["DEVICES"][$re[1]]["DEV"] = $re[4]; } } echo "<articadatascgi>" . base64_encode(serialize($array)) . "</articadatascgi>"; }
function ReloadMacHelpers($output = false) { @mkdir("/var/log/squid/reload", 0755, true); $unix = new unix(); $pgrep = $unix->find_program("pgrep"); $rm = $unix->find_program("rm"); shell_exec("{$rm} /var/log/squid/reload/*.ufdbgclient.php"); if (is_file("/var/log/squid/UfdbguardCache.db")) { @unlink("/var/log/squid/UfdbguardCache.db"); } exec("{$pgrep} -l -f \"ufdbgclient.php\" 2>&1", $results); while (list($index, $ligne) = each($results)) { if (preg_match("#pgrep#", $ligne)) { continue; } if (!preg_match("#^([0-9]+)\\s+#", $ligne, $re)) { continue; } $PIDS[] = $re[1]; echo "Starting......: " . date("H:i:s") . " [INIT]: Webfilter client reloading PID {$re[1]}\n"; @touch("/var/log/squid/reload/{$re[1]}.ufdbgclient.php"); @chown("/var/log/squid/reload/{$re[1]}.ufdbgclient.php", "squid"); @chgrp("/var/log/squid/reload/{$re[1]}.ufdbgclient.php", "squid"); } squid_admin_mysql(2, count($PIDS) . " Artica helper(s) was reloaded", null, __FILE__, __LINE__); }
function DropBoxUri() { $sock = new sockets(); $DropBoxUri = $sock->GET_INFO("DropBoxUri"); if (strlen($DropBoxUri) > 10) { echo $DropBoxUri . "\n"; return; } $unix = new unix(); $grep = $unix->find_program("grep"); $tail = $unix->find_program("tail"); exec("{$grep} \"Please visit\" /var/log/dropbox.log|{$tail} -n 2000 2>&1", $results); while (list($dir, $line) = each($results)) { if (preg_match("#Please visit\\s+(.+?)\\s+to link#", $line, $re)) { $uri = trim($re[1]); break; } } if ($uri != null) { $sock = new sockets(); $sock->SET_INFO("DropBoxUri", $uri); echo $uri . "\n"; return; } }
function getlongkey() { $sock = new sockets(); $RacconKey = $sock->GET_INFO("RacconKey"); if ($sock->GET_INFO("RacconKey") != null) { return $RacconKey; } $unix = new unix(); $xxd_bin = $unix->find_program("xxd"); $dd_bin = $unix->find_program("dd"); $cmd = "{$dd_bin} if=/dev/random count=24 bs=1|{$xxd_bin} -ps 2>&1"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } exec($cmd, $results); while (list($num, $ligne) = each($results)) { if (preg_match("#\\s+[a-z]+#", trim($ligne))) { if ($GLOBALS["VERBOSE"]) { echo "skipped \"{$ligne}\" -> \\s+[a-z]+\n"; } continue; } if (strlen(trim($ligne)) < 48) { if ($GLOBALS["VERBOSE"]) { echo "skipped \"" . strlen(trim($ligne)) . "\" length+\n"; } continue; } $key = trim($ligne); } $sock->SET_INFO("RacconKey", $key); return $key; }
function startx() { $unix = new unix(); build_progress(50, "{refresh} CPUS"); @unlink("/etc/artica-postfix/CPU_NUMBER"); build_progress(55, "{refresh} CPUS"); @unlink("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER"); build_progress(60, "{rescan-disk-system}"); $dirs = $unix->dirdir("/sys/class/scsi_host"); $echo = $unix->find_program("echo"); $udevadm = $unix->find_program("udevadm"); $php = $unix->LOCATE_PHP5_BIN(); while (list($dirpath, $line) = each($dirs)) { $basename = basename($dirpath); if (!preg_match("#host[0-9]+#", $basename)) { continue; } $cmd = "{$echo} \"- - -\" >{$dirpath}/scan"; build_progress(65, "{rescan-disk-system}" . dirname($dirpath)); shell_exec($cmd); } build_progress(70, "{rescan-disk-system}"); $cmdline = "{$php} /usr/share/artica-postfix/exec.usb.scan.write.php --verbose"; system($cmd); build_progress(80, "{rescan-network-system}"); system("{$udevadm} control --reload-rules"); system("{$udevadm} trigger --attr-match=subsystem=net"); sleep(3); system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time()); build_progress(100, "{refresh} {done}"); }
function ScanPurgeexc() { $unix = new unix(); $purge = $unix->find_program("purge"); $pidof = $unix->find_program("pidof"); $kill = $unix->find_program("kill"); exec("{$pidof} {$purge} 2>&1", $results); $pp = array(); $pids = explode(" ", @implode("", $results)); while (list($index, $pid) = each($pids)) { if (!is_numeric(trim($pid))) { continue; } $pp[] = $pid; } $count = count($pp); if ($count > 1) { unset($pp[0]); while (list($index, $pid) = each($pp)) { unix_system_kill_force($pid); } } $count = count($pp); return $count; }
function build() { $sock = new sockets(); $unix = new unix(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $HugePages = $sock->GET_INFO("HugePages"); $KernelShmmax = $sock->GET_INFO("KernelShmmax"); $meminfo = MemInfo(); $HUGEPAGESIZE = intval($meminfo["HUGEPAGESIZE"]); $HUGEPAGESIZEBytes = $HUGEPAGESIZE; if (!is_numeric($HugePages)) { $HugePages = 0; } if (!is_numeric($KernelShmmax)) { $KernelShmmax = 0; } if ($HugePages > 0) { $HugePagesB = $HugePages * 1024; $HugePagesB = $HugePagesB * 1024; $HugePagesF = $HugePagesB / $HUGEPAGESIZEBytes; echo "HUGEPAGESIZE = {$HUGEPAGESIZE} ({$HUGEPAGESIZEBytes} bytes) " . FormatBytes($HUGEPAGESIZEBytes / 1024) . "\n"; echo "HugePages = {$HugePages} Mb ({$HugePagesB} bytes)\n"; echo "HugePages Final = {$HugePagesF} " . FormatBytes($HugePagesF / 1024) . " \n"; $unix->sysctl("vm.nr_hugepages", $HugePagesF); shell_exec("{$sysctl} -w vm.nr_hugepages={$HugePagesF}"); for ($i = 0; $i < 10; $i++) { shell_exec("{$echo} {$HugePagesF} > /proc/sys/vm/nr_hugepages"); sleep(1); } } // sysctl }
function BuildDHCP() { $ldap = new clladp(); if ($ldap->ldapFailed) { echo "Starting......: DHCP SERVER ldap connection failed,aborting\n"; return; } if (!$ldap->ExistsDN("dc=organizations,{$ldap->suffix}")) { echo "Starting......: DHCP SERVER dc=organizations,{$ldap->suffix} no such branch, aborting\n"; return; } echo "Starting......: DHCP SERVER ldap connection success\n"; $dhcpd = new dhcpd(); $conf = $dhcpd->BuildConf(); $confpath = dhcp3Config(); $unix = new unix(); @mkdir(dirname($confpath), null, true); @file_put_contents($confpath, $conf); echo "Starting......: DHCP SERVER saving \"{$confpath}\" (" . strlen($conf) . " bytes) done\n"; if (is_dir("/var/lib/dhcp3")) { shell_exec("/bin/chown -R dhcpd:dhcpd /var/lib/dhcp3"); shell_exec("/bin/chmod 755 /var/lib/dhcp3"); } $complain = $unix->find_program("aa-complain"); if (is_file($complain)) { $dhcpd3 = $unix->find_program("dhcpd3"); if (is_file($dhcpd3)) { shell_exec("{$complain} {$dhcpd3} >/dev/null 2>&1"); } } }
function importActivedirectoryusers() { $sock = new sockets(); $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 0) { return; } $unix = new unix(); $user = new settings_inc(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { WriteMyLogs("Process {$pid} already exists", __FUNCTION__, __FILE__, __LINE__); return; } if (system_is_overloaded(basename(__FILE__))) { WriteMyLogs("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__); return; } @file_put_contents($pidfile, getmypid()); $TImeStamp = $unix->file_time_min($pidTime); if (!$GLOBALS["FORCE"]) { if ($TImeStamp < 20) { WriteMyLogs("Need 20mn, current={$TImeStamp}Mn executed by:{$GLOBALS["EXECUTOR"]} Params:{$GLOBALS["PARAMS"]}", __FUNCTION__, __FILE__, __LINE__); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); $netbin = $unix->LOCATE_NET_BIN_PATH(); $usermod = $unix->find_program("usermod"); $chmod = $unix->find_program("chmod"); if (!is_file($netbin)) { WriteMyLogs("net no such binary, aborting", __FUNCTION__, __FILE__, __LINE__); return; } if (is_dir("/var/run/samba/winbindd_privileged")) { shell_exec("{$usermod} -G winbindd_priv squid >/dev/null 2>&1"); shell_exec("{$chmod} 0750 /var/run/samba/winbindd_privileged/ >/dev/null 2>&1"); } $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos"))); $domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]); $domain_lower = strtolower($array["WINDOWS_DNS_SUFFIX"]); $adminpassword = $array["WINDOWS_SERVER_PASS"]; $adminpassword = $unix->shellEscapeChars($adminpassword); $adminname = $array["WINDOWS_SERVER_ADMIN"]; $ad_server = $array["WINDOWS_SERVER_NETBIOSNAME"]; $GLOBALS["AUTHCMD"] = " -U {$adminname}%{$adminpassword}"; getNetInfos(); if (!isset($GLOBALS["LDAP_HOST"])) { WriteMyLogs("Unable to get ldap infos, aborting", __FUNCTION__, __FILE__, __LINE__); return; } GetUsersArray(); }
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 start() { $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { return; } @file_put_contents($pidFile, getmypid()); $time = $unix->file_time_min($pidtime); if ($time < 5) { return; } @file_put_contents($pidtime, time()); $free = $unix->find_program("free"); $echo = $unix->find_program("echo"); $sync = $unix->find_program("sync"); $swapoff = $unix->find_program("swapoff"); $swapon = $unix->find_program("swapon"); exec("{$free} 2>&1", $results); $used = 0; $total = 0; while (list($num, $ligne) = each($results)) { if (preg_match("#Swap:\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)#", $ligne, $re)) { $total = $re[1]; $used = $re[2]; } } if (!is_numeric($total)) { return; } if ($total == 0) { return; } if ($used == 0) { return; } if ($total == $used) { return; } $tot1 = $used / $total; $tot1 = $tot1 * 100; if ($GLOBALS["VERBOSE"]) { echo "Swap:{$used}/{$total} - {$tot1}\n"; } $perc = round($tot1); if ($GLOBALS["VERBOSE"]) { echo "Swap:{$used}/{$total} {$perc}%\n"; } $t = time(); $GLOBALS["ALL_SCORES"]++; shell_exec("{$swapoff} -a && {$swapon} -a"); $usedTXT = FormatBytes($used); $report = $unix->ps_mem_report(); $distance = $unix->distanceOfTimeInWords($t, time(), true); squid_admin_mysql(0, "System swap exceed rule: {$perc}%", "Used {$usedTXT}\nSystem cache was flushed took {$distance}\nThis means you did have enough memory for this computer.\n{$report}", __FILE__, __LINE__); }
function install_key($keyfile) { $path = "/usr/share/artica-postfix/ressources/conf/upload/{$keyfile}"; $license_bin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager"; $time = time(); $unix = new unix(); $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) { progress("{failed} Already running", 110); echo "Already runinng PID {$pid}\n"; return; } } echo "License....: {$path}\n"; echo "Binary File: {$license_bin}\n"; if (!is_file($path)) { echo "{$path} No such file..\n"; progress("{failed} {$keyfile} No such file", 110); die; } if (!is_file($license_bin)) { echo "{$path} No such file..\n"; progress("{failed} " . basename($license_bin) . " No such binary", 110); @unlink($path); die; } $sock = new sockets(); $nohup = $unix->find_program("nohup"); $sock->SET_INFO("kavicapserverEnabled", 1); @unlink("/etc/artica-postfix/kav4proxy-licensemanager"); @unlink("/etc/artica-postfix/kav4proxy-licensemanager-i"); progress("{removing_old_licenses}", 20); system("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -d a"); progress("{installing} {$keyfile}", 30); $cmd = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -c /etc/opt/kaspersky/kav4proxy.conf -a {$path}"; system($cmd); @unlink($path); progress("{analyze_license} {$keyfile}", 50); shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i 2>&1"); progress("{stopping_service}", 60); echo "/etc/init.d/kav4proxy stop\n"; system("/etc/init.d/kav4proxy stop"); progress("{starting_service}", 60); echo "/etc/init.d/kav4proxy start\n"; system("{$nohup} /etc/init.d/kav4proxy start >/dev/null 2>&1 &"); system("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &"); progress("{launch_updates}", 70); $nohup = $unix->find_program("nohup"); $php = $unix - LOCATE_PHP5_BIN(); sleep(2); progress("{launch_updates}", 80); shell_exec("{$nohup} /usr/share/artica-postfix/exec.keepup2date.php --update --force >/dev/null 2>&1 &"); sleep(3); progress("{success}", 100); }
function install($filename) { $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/squid.install.progress"; $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/squid.install.progress.txt"; $unix = new unix(); $LINUX_CODE_NAME = $unix->LINUX_CODE_NAME(); $LINUX_DISTRIBUTION = $unix->LINUX_DISTRIBUTION(); $LINUX_VERS = $unix->LINUX_VERS(); $LINUX_ARCHITECTURE = $unix->LINUX_ARCHITECTURE(); $APACHEUSER = $unix->APACHE_SRC_ACCOUNT(); $DebianVer = "debian{$LINUX_VERS[0]}"; $TMP_DIR = $unix->TEMP_DIR(); $ORGV = @file_get_contents("/usr/share/artica-postfix/VERSION"); $PATCH_VER = null; $tarballs_file = "/usr/share/artica-postfix/ressources/conf/upload/{$filename}"; echo "Package {$tarballs_file}\n"; $size = filesize($tarballs_file); echo "Size....................: " . FormatBytes($size / 1024) . "\n"; build_progress("Analyze...", 10); echo "Current system..........: {$LINUX_CODE_NAME} {$LINUX_DISTRIBUTION} {$LINUX_VERS[0]}/{$LINUX_VERS[1]} {$LINUX_ARCHITECTURE}\n"; echo "Package.................: {$filename}\n"; echo "Temp dir................: {$TMP_DIR}\n"; if (!is_file($tarballs_file)) { echo "{$tarballs_file} no such file...\n"; build_progress("No such file...", 110); return; } echo "Uncompressing {$tarballs_file}...\n"; build_progress("{extracting} {$filename}...", 20); $chown = $unix->find_program("chown"); $chmod = $unix->find_program("chmod"); $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); $squid = $unix->LOCATE_SQUID_BIN(); build_progress("{extracting} {$filename}...", 50); system("{$tar} xf {$tarballs_file} -C /"); echo "Removing {$tarballs_file}...\n"; @unlink($tarballs_file); shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/conf/upload/*"); @unlink(dirname(__FILE__) . "/ressources/logs/squid.compilation.params"); build_progress("{restarting} Squid-cache...", 60); system("/etc/init.d/squid restart --force"); build_progress("{reconfiguring} Squid-cache...", 65); system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); build_progress("{reconfiguring} {APP_UFDBGUARD}...", 70); system("{$php} /usr/share/artica-postfix/exec.squidguard.php --build --force"); build_progress("{restarting} {APP_C_ICAP}...", 80); system("/etc/init.d/c-icap restart"); build_progress("Refresh local versions...", 90); system('/usr/share/artica-postfix/bin/process1 --force --verbose --' . time()); $squid_version = x_squid_version(); build_progress("{success} v.{$squid_version}...", 100); echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n"; }
function ParseMainDir() { $unix = new unix(); $mypid = getmypid(); $kill = $unix->find_program("kill"); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); @mkdir("/etc/artica-postfix/pids", 0755, true); $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pidtime_hour = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".hours.time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($time > 60) { unix_system_kill_force($pid); } else { events("Already executed pid {$pid} since {$time}mn-> DIE"); if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid} since {$time}mn\n"; } die; } } $timeP = $unix->file_time_min($pidtime); if ($timeP < 3) { events("Main::Line: " . __LINE__ . " 3Mn minimal current: {$timeP}mn-> DIE"); die; } @unlink($pidtime); @file_put_contents($pidtime, time()); @file_put_contents($pidfile, $mypid); $dirs = $unix->dirdir("/var/log/artica-postfix/squid/queues"); while (list($directory, $array) = each($dirs)) { $dirs2 = $unix->dirdir($directory); if (count($dirs2) == 0) { events("{$dirs2} 0 elements, remove...", __LINE__); @rmdir($directory); continue; } if (is_dir("{$directory}/SearchWords")) { events("Scanning {$directory}/SearchWords", __LINE__); ParseSubDir("{$directory}/SearchWords"); } } $timeP = $unix->file_time_min($pidtime_hour); if ($timeP > 30) { @unlink($pidtime_hour); @file_put_contents($pidtime_hour, time()); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid-searchwords.php --hour >/dev/null 2>&1"); } }
function install() { $unix = new unix(); $DISTRICODE = $unix->LINUX_CODE_NAME(); $arch = $unix->LINUX_ARCHITECTURE(); $VERS = $unix->LINUX_VERS(); $dpkg = $unix->find_program("dpkg"); echo "DISTRICODE:{$DISTRICODE} \n"; if (!python_verify_modules("MySQLdb")) { $unix->DEBIAN_INSTALL_PACKAGE("python-mysqldb"); } if (!python_verify_modules("ldap")) { echo "Installing python-ldap\n"; if ($DISTRICODE == "DEBIAN") { if ($arch == 64) { if ($VERS[0] == 6) { if (is_file("/usr/share/artica-postfix/bin/install/postfix/python-6-ldap-amd64.deb")) { shell_exec("{$dpkg} -i --force-all /usr/share/artica-postfix/bin/install/postfix/python-6-ldap-amd64.deb"); } } if ($VERS[0] == 7) { if (is_file("/usr/share/artica-postfix/bin/install/postfix/python-7-ldap-amd64.deb")) { shell_exec("{$dpkg} -i --force-all /usr/share/artica-postfix/bin/install/postfix/python-7-ldap-amd64.deb"); } } } } } if (!python_verify_modules("ldap")) { $unix->DEBIAN_INSTALL_PACKAGE("python-ldap"); } if (!python_verify_modules("ldap")) { echo "Warning, ldap/python-ldap not installed...\n"; return; } if (!python_verify_modules("MySQLdb")) { echo "Warning, MySQLdb/python-mysqldb not installed...\n"; return; } echo "MySQLdb / python-mysqldb OK\n"; echo "LDAP / python-ldap OK\n"; $tmpdir = $unix->TEMP_DIR() . "/iredmail"; $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); if (!is_file("/usr/share/artica-postfix/bin/install/postfix/iredapd.tar.gz")) { return; } @mkdir($tmpdir, 0755, true); shell_exec("{$tar} xf /usr/share/artica-postfix/bin/install/postfix/iredapd.tar.gz -C /"); if (!is_file("/opt/iRedAPD/iredapd.py")) { return; } @chmod("/opt/iRedAPD/iredapd.py", 0755); }
function build($uri) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { die; } @file_put_contents($pidfile, getmypid()); $echo = $unix->find_program("echo"); $curl = $unix->find_program("curl"); $squidbin = $unix->LOCATE_SQUID_BIN(); $curl = $unix->find_program("curl"); @unlink("/var/log/squid/request.debug"); $DirFinal = "/usr/share/artica-postfix/ressources/support/" . time(); @mkdir($DirFinal, 0755, true); $SquidMgrListenPort = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidMgrListenPort")); shell_exec("{$echo} \"Proxy address 127.0.0.1:{$SquidMgrListenPort}\" > /var/log/squid/request.debug 2>&1"); shell_exec("{$echo} \"Url to test: {$uri} \" >> /var/log/squid/request.debug 2>&1"); progress("{rotate_logs_files}", 30); shell_exec("{$echo} \"Rotate & turn to debug... \" >> /var/log/squid/request.debug 2>&1"); @copy("/var/log/squid/access.log", "/var/log/squid/access.log." . time()); shell_exec("{$squidbin} -k rotate >> /var/log/squid/request.debug 2>&1"); progress("{turn_to_debug}", 35); shell_exec("{$squidbin} -k debug >/dev/null 2>&1"); sleep(4); progress("{send_query}", 40); $cmd = "{$curl} --head --verbose --trace-time --proxy http://127.0.0.1:{$SquidMgrListenPort} --url {$uri} >> /var/log/squid/request.debug 2>&1"; shell_exec("{$echo} \"{$cmd}\" >> /var/log/squid/request.debug 2>&1"); shell_exec($cmd); sleep(4); progress("{return_back_to_normal}", 40); LogsThisDebug("************************************************************"); squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__); shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " >> /var/log/squid/request.debug 2>&1"); LogsThisDebug("************************************************************"); sleep(1); @copy("/var/log/squid/cache.log", "{$DirFinal}/cache.log"); progress("{compressing_package}", 90); $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); $filename = "request.tar.gz"; @unlink("/usr/share/artica-postfix/ressources/support/{$filename}"); @copy("/var/log/squid/request.debug", "{$DirFinal}/request.debug"); @unlink("/var/log/squid/request.debug"); chdir($DirFinal); $cmd = "{$tar} -cvzf /usr/share/artica-postfix/ressources/support/{$filename} * 2>&1"; exec($cmd, $results); @chmod("/usr/share/artica-postfix/ressources/support/{$filename}", 0755); shell_exec("{$rm} -rf {$DirFinal}"); LogsThisDebug("*********************************************************"); $c = 0; progress("{success}", 100); }
function umountfs() { $unix = new unix(); $mount = $unix->find_program("mount"); $umount = $unix->find_program("umount"); $kav = new Kav4Proxy(); if ($kav->is_tmpfs_mounted()) { echo "Starting......: Kav4proxy unmounting filesystem\n"; shell_exec("{$umount} -f /tmp/Kav4proxy"); shell_exec("/bin/rm -rf /tmp/Kav4proxy"); } }
function xstart() { $unix = new unix(); $CurrentDirectory = "/home/ArticaStatsDB"; if (is_link($CurrentDirectory)) { $CurrentDirectory = @readlink($CurrentDirectory); } $ChangePostGresSQLDir = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/ChangePostGresSQLDir")); echo "Current Directory....: {$CurrentDirectory}\n"; echo "Destination Directory: {$ChangePostGresSQLDir}\n"; if ($ChangePostGresSQLDir == null) { build_progress("{error} Destination Directory = NULL", 110); return; } if ($ChangePostGresSQLDir == $CurrentDirectory) { echo "Same directory....\n"; build_progress("{success}", 100); return; } if (!is_dir($ChangePostGresSQLDir)) { @mkdir($ChangePostGresSQLDir, 0755, true); } if (!is_dir($ChangePostGresSQLDir)) { echo "{$ChangePostGresSQLDir} Permission denied or issue while creating the directory.\n"; build_progress("{error} Destination Directory Permission denied", 110); return; } $mv = $unix->find_program("mv"); $ln = $unix->find_program("ln"); build_progress("{stopping_service}", 10); @file_put_contents("/etc/artica-postfix/settings/Daemons/FreeZePostGres", 1); system("/etc/init.d/artica-postgres stop"); system("/etc/init.d/artica-postgres stop"); build_progress("{moving_data}", 20); system("{$mv} {$CurrentDirectory}/* {$ChangePostGresSQLDir}/"); if (!@rmdir($CurrentDirectory)) { build_progress("{moving_data} {failed}", 30); sleep(3); system("{$mv} {$ChangePostGresSQLDir}/* {$CurrentDirectory}/"); @file_put_contents("/etc/artica-postfix/settings/Daemons/FreeZePostGres", 0); build_progress("{starting_service} {moving_data} {failed}", 90); sleep(3); build_progress("{moving_data} {failed}", 110); return; } shell_exec("{$ln} -sf {$ChangePostGresSQLDir} /home/ArticaStatsDB"); @file_put_contents("/etc/artica-postfix/settings/Daemons/FreeZePostGres", 0); sleep(3); build_progress("{starting_service}", 90); sleep(3); build_progress("{moving_data} {success}", 100); }
function Get_owncloud() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pid = @file_get_contents($pidfile); $unix = new unix(); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid} since {$time}mn\n"; } die; } $uri = download(); if ($uri == null) { return; } $curl = new ccurl($uri); $curl->NoHTTP_POST = true; $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); progress("Downloading Owncloud package...", 25); if (!$curl->GetFile("/root/owncloud.tar.gz")) { progress("Failed download owncloud package", 110); return; } if (is_dir("/usr/share/owncloud")) { shell_exec("{$rm} -rf /usr/share/owncloud"); } @mkdir("/usr/share/owncloud", 0755, true); if (!is_dir("/usr/share/owncloud")) { progress("/usr/share/owncloud permission denied", 110); @unlink("/root/owncloud.tar.gz"); return; } $tar = $unix->find_program("tar"); progress("Extracting package...", 35); shell_exec("{$tar} xf /root/owncloud.tar.gz -C /usr/share/owncloud/"); @unlink("/root/owncloud.tar.gz"); if (is_dir("/usr/share/owncloud/owncloud")) { shell_exec("{$cp} -rf /usr/share/owncloud/owncloud/* /usr/share/owncloud/"); shell_exec("{$rm} -rf /usr/share/owncloud/owncloud"); } if (is_file("/usr/share/owncloud/settings/settings.php")) { progress("Success...", 100); $unix->Process1(true); return; } progress("Failed...", 110); }
function start($database, $table) { $unix = new unix(); if ($database == null) { WriteIsamLogs("Requested myismamchk database:{$database}, table: {$table} -> database is null"); return; } if ($table == null) { WriteIsamLogs("Requested myismamchk database:{$database}, table: {$table} -> table is null"); return; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . md5("{$database}{$table}") . ".pid"; $pid = @file_get_contents("{$database}{$table}"); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); WriteIsamLogs("Already PID {$pid} running since {$timepid}mn, aborting"); return; } @file_put_contents($pidfile, getmypid()); WriteIsamLogs("Requested myismamchk database:{$database}, table: {$table}"); $pgrep = $unix->find_program("pgrep"); $myisamchk = $unix->find_program("myisamchk"); $touch = $unix->find_program("touch"); $myisamchk = $unix->find_program("myisamchk"); $pgrep = $unix->find_program("pgrep"); exec("{$pgrep} -l -f \"{$myisamchk}.*?{$table}\"", $results); while (list($index, $line) = each($results)) { if (preg_match("#pgrep#", $line)) { continue; } if (preg_match("#^[0-9]+\\s+#", $line)) { writelogs("{$line} already executed", @implode("\r\n", $results), __FUNCTION__, __FILE__, __LINE__); return; } } $MYSQL_DATADIR = $unix->MYSQL_DATADIR(); if (!is_file("{$MYSQL_DATADIR}/{$database}/{$table}.MYD")) { WriteIsamLogs("unable to stat {$MYSQL_DATADIR}/{$database}/{$table}.MYD"); return; } if (!is_file("{$MYSQL_DATADIR}/{$database}/{$table}.MYI")) { WriteIsamLogs("{$MYSQL_DATADIR}/{$database}/{$table}.MYI no such file"); return; } $results = array(); WriteIsamLogs("{$myisamchk} --safe-recover --backup {$MYSQL_DATADIR}/{$database}/{$table}.MYI"); exec("{$myisamchk} --safe-recover --backup {$MYSQL_DATADIR}/{$database}/{$table}.MYI 2>&1", $results); while (list($index, $line) = each($results)) { WriteIsamLogs("{$line}"); } }
function restart() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $su = $unix->find_program("su"); $cmd = trim("{$php} /usr/share/artica-postfix/exec.initslapd.php --ftp-proxy --force >/dev/null 2>&1"); shell_exec($cmd); $cmd = trim("{$nohup} /etc/init.d/ftp-proxy restart >/dev/null 2>&1 &"); shell_exec($cmd); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); $cmd = trim("{$nohup} /etc/init.d/artica-status reload >/dev/null 2>&1 &"); shell_exec($cmd); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); }
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 postfix_instances_list() { $unix = new unix(); $search = trim(strtolower($_GET["search"])); if (strlen($search) > 0) { $grep = $unix->find_program("grep"); $search = str_replace(".", "\\.", $search); $search = str_replace("*", ".*?", $search); $searcchmd = "|{$grep} -E '{$search}.*?\\s+'"; } $postmulti = $unix->find_program("postmulti"); $cmd = "{$postmulti} -l{$searcchmd} 2>&1"; exec($cmd, $results); writelogs_framework($cmd . " " . count($results) . " rows", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>" . base64_encode(serialize($results)) . "</articadatascgi>"; }
function parse() { $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time"; $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.pid"; $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogDir"); if ($GLOBALS["LogFileDeamonLogDir"] == null) { $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid/realtime-events"; } $unix = new unix(); $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 ($timepid < 14) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); $TimeExec = $unix->file_time_min($TimeFile); if (!$GLOBALS["FORCE"]) { if ($TimeExec < 20) { return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); parsedb("/var/log/squid"); parsedb($GLOBALS["LogFileDeamonLogDir"]); }
function database_empty() { $hostname = $_GET["hostname"]; if ($hostname == null) { $hostname = "master"; } if ($hostname == "master") { $d[] = "/var/milter-greylist/greylist.db"; $d[] = "/usr/share/artica-postfix/ressources/logs/mgrelist-db.inc"; } if ($hostname != "master") { $d[] = "/var/milter-greylist/{$hostname}/greylist.db"; $d[] = "/usr/share/artica-postfix/ressources/logs/mgrelist-{$_GET["hostname"]}.inc"; } $d[] = "/usr/share/artica-postfix/ressources/logs/greylist-count-{$hostname}.tot"; $d[] = "/usr/share/artica-postfix/ressources/logs/mgrelist-{$hostname}.inc"; while (list($num, $line) = each($d)) { if (is_file($line)) { @unlink($line); } } $unix = new unix(); $nohup = $unix->find_program("nohup"); shell_exec("{$nohup} /etc/init.d/milter-greylist restart >/dev/null 2>&1 &"); }
function MAIN_MENU() { $unix = new unix(); $clear = $unix->find_program("clear"); if (is_file($clear)) { system("{$clear}"); } echo "Credentials Menu\n"; echo "---------------------------------------------\n"; echo "Display SuperAdmin credentials...: [1]\n"; echo "Modify SuperAdmin credentials....: [2]\n"; echo "Exit menu........................: [q]\n"; echo "\n"; $answer = trim(strtolower(fgets(STDIN))); switch ($answer) { case "1": ShowPassword(); break; case "2": ChangePassword(); break; case "q": die; break; default: break; MAIN_MENU(); return; } }
function patchbin() { $unix = new unix(); $sabnzbdplus = $unix->find_program("sabnzbdplus"); if (strlen($sabnzbdplus) < 5) { echo "Starting......: sabnzbdplus sabnzbdplus no such file\n"; return; } echo "Starting......: sabnzbdplus {$sabnzbdplus}\n"; $f = explode("\n", @file_get_contents($sabnzbdplus)); while (list($index, $line) = each($f)) { if (preg_match("#^import sys#", $line)) { $nextline = $f[$index + 1]; echo "Starting......: sabnzbdplus line {$index}\n"; if (preg_match("#sys\\.path.insert\\(0#", $nextline)) { echo "Starting......: sabnzbdplus Patched OK\n"; return; } else { echo "Starting......: sabnzbdplus patching line {$index}\n"; $f[$index] = "import sys\nsys.path.insert(0,'/usr/share/sabnzbdplus')"; @file_put_contents($sabnzbdplus, @implode("\n", $f)); return; } } } }
function startx() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $tar = $unix->find_program("tar"); build_progress("{backup_parameters}....", 5); chdir("/etc/squid3"); system("cd /etc/squid3"); system("{$tar} -czf /root/backup.squid.tar.gz *"); build_progress("{reconfiguring}....", 10); system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); build_progress("{stopping_service}....", 50); system("/etc/init.d/squid stop"); build_progress("{starting_service}....", 80); system("/etc/init.d/squid start"); $cachefile = "/usr/share/artica-postfix/ressources/logs/web/squid.start.progress"; if (is_file($cachefile)) { $textAR = unserialize(@file_get_contents($cachefile)); if ($textAR["POURC"] > 100) { build_progress("{restore_parameters}....", 90); shell_exec("{$tar} -xf /root/backup.squid.tar.gz -C /etc/squid3/"); build_progress("{starting_service}....", 90); system("/etc/init.d/squid start"); } } @unlink("/root/backup.squid.tar.gz"); build_progress("{starting_service} {success}", 100); chdir("/root"); }
function start_hour() { $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $unix = new unix(); $sock = new sockets(); if (system_is_overloaded(basename(__FILE__))) { return; } $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } 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); } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $hostname = $unix->hostname_g(); $today = date("Y-m-d") . " 00:00:00"; $postgres = new postgres_sql(); $results = $postgres->QUERY_SQL("select date_trunc('H',zdate) + (round(extract('minute' from zdate)/15)*15) * '1 minute'::interval as time, sum(rx) as rx, sum(tx) as tx,eth from access_log WHERE proxyname='{$hostname}' AND zdate >'{$today}' group by time,eth"); $c = 0; $f = array(); while ($ligne = @pg_fetch_assoc($results)) { $time = $ligne["time"]; $ETH = $ligne["eth"]; if ($ETH == "lo") { continue; } $RX = $ligne["rx"]; $TX = $ligne["tx"]; $f[] = "('{$time}','{$ETH}','{$RX}','{$TX}')"; } if (count($f) == 0) { return; } $q = new mysql(); if ($q->TABLE_EXISTS("RXTX_HOUR", "artica_events")) { $q->QUERY_SQL("TRUNCATE TABLE `RXTX_HOUR`", "artica_events"); } $sql = "CREATE TABLE IF NOT EXISTS `RXTX_HOUR`\n\t(`ZDATE` DATETIME,\n\t`RX` INT UNSIGNED NOT NULL DEFAULT 1,\n\t`TX` INT UNSIGNED NOT NULL DEFAULT 1,\n\t`ETH` VARCHAR(60),\n\tKEY `ZDATE`(`ZDATE`),\n\tKEY `RX`(`RX`),\n\tKEY `TX`(`TX`),\n\tKEY `ETH`(`ETH`) ) ENGINE = MYISAM;"; $q->QUERY_SQL($sql, "artica_events"); if (!$q->ok) { return; } $q->QUERY_SQL("INSERT IGNORE INTO RXTX_HOUR (ZDATE,ETH,RX,TX) VALUES " . @implode(",", $f), "artica_events"); start_week(); }