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 save_server_config(){ $unix=new unix(); $php5=$unix->LOCATE_PHP5_BIN(); $nohup=$unix->find_program("nohup"); $cmd=trim("$nohup $php5 /usr/share/artica-postfix/exec.amanda.php --build >/dev/null 2>&1 &"); writelogs_framework("$cmd",__FUNCTION__,__FILE__,__LINE__); shell_exec($cmd); }
function build_conf() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $cmd = trim($nohup . " " . $unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.ejabberd.php >/dev/null 2>&1 &"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function restart() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $cmd = trim("{$nohup} /etc/init.d/artica-postfix restart ftp >/dev/null 2>&1 &"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function db_status() { $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $cmd = trim("{$php5} /usr/share/artica-postfix/exec.squidguard.php --databases-status >/dev/null 2>&1"); shell_exec($cmd); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); }
function execute_debug() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = trim("{$nohup} {$php} /usr/share/artica-postfix/exec.fetchmail.php --single-debug {$_GET["debug"]} >/dev/null 2>&1 &"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); }
function restart() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.vsftpd.php --restart >/dev/null 2>&1 &"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function NOHUP_EXEC($cmdline) { $cmdline = str_replace(">/dev/null 2>&1 &", "", $cmdline); $unix = new unix(); $nohup = $unix->find_program("nohup"); $cmdfinal = "{$nohup} {$cmdline} >/dev/null 2>&1 &"; writelogs_framework("{$cmdfinal}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmdfinal); }
function per_user_mysql() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $cmd = "{$php} /usr/share/artica-postfix/exec.amavis-db.php --init"; writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); shell_exec("/etc/init.d/amavis-db start"); }
function compile_rules() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $cmd = trim("{$nohup} {$php5} /usr/share/artica-postfix/exec.squidguard.php --build >/dev/null 2>&1 &"); shell_exec($cmd); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); }
function save_client_server() { $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = trim("{$nohup} {$php5} /usr/share/artica-postfix/exec.amanda.php --backup-server >/dev/null 2>&1 &"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function smtp_notifs() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = "{$nohup} {$php} /usr/share/artica-postfix/exec.squidguard.smtp.php --smtp --force >/dev/null 2>&1 &"; writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function freeweb_modules(){ $unix=new unix(); $apache2ctl=$unix->find_program("apache2ctl"); if(!is_file($apache2ctl)){echo "<articadatascgi>".base64_encode(serialize(array("apache2ctl no such file")))."</articadatascgi>";return;} $cmd="$apache2ctl -t -D DUMP_MODULES 2>&1"; exec("$cmd",$results); writelogs_framework("$cmd ". count($results)." rows",__FUNCTION__,__FILE__,__LINE__); echo "<articadatascgi>".base64_encode(serialize($results))."</articadatascgi>"; }
function delete_container() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); $cmd = trim("{$php} /usr/share/artica-postfix/exec.containers.php --delete-container {$_GET["delete-container"]}"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); }
function status() { $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $cmd = trim("{$php5} /usr/share/artica-postfix/exec.status.php --ftp-proxy --nowachdog 2>&1"); exec($cmd, $results); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>" . base64_encode(@implode("\n", $results)) . "</articadatascgi>"; }
function backup_test_nas() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $cmd = "{$php} /usr/share/artica-postfix/exec.cyrus.backup.php --test-nas --verbose 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); echo "<articadatascgi>" . base64_encode(serialize($results)) . "</articadatascgi>"; }
function tomysql() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $servername = $_GET["tomysql"]; $cmd = trim("{$php5} /usr/share/artica-postfix/exec.openssl.php --mysql {$servername} 2>&1"); exec($cmd, $results); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>" . base64_encode(trim(@implode("\n", $results))) . "</articadatascgi>"; }
function restart() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = trim("{$nohup} {$php} /usr/share/artica-postfix/exec.mimedefang.php 2>&1"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); $cmds = $_GET["service-cmds"]; $results[] = "Postition: {$cmds}"; exec("/etc/init.d/mimedefang restart 2>&1", $results); echo "<articadatascgi>" . base64_encode(serialize($results)) . "</articadatascgi>"; }
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 database_list() { $db = "/var/milter-greylist/greylist.db"; $inc_file = "/usr/share/artica-postfix/ressources/logs/mgrelist-db.inc"; if (isset($_GET["db_path"])) { $db = base64_decode(trim($_GET["db_path"])); $inc_file = "/usr/share/artica-postfix/ressources/logs/mgrelist-{$_GET["hostname"]}.inc"; } $datas = file_get_contents($db); $tbl = explode("\n", $datas); if (!is_array($tbl)) { return null; } while (list($num, $line) = each($tbl)) { if (trim($line) == null) { continue; } if (preg_match("#greylisted tuples#", $line)) { $KEY = "GREY"; continue; } if (preg_match("#stored tuples#", $line)) { $KEY = "GREY"; continue; } if (preg_match("#Auto-whitelisted tuples#", $line)) { $KEY = "WHITE"; continue; } if (preg_match("#([0-9\\.]+)\\s+<(.+?)>\\s+<(.+?)>#", $line, $re)) { $conf[] = "\$MGREYLIST_DB[\"{$KEY}\"][]=array('{$re[1]}','{$re[2]}','{$re[3]}');"; continue; } writelogs_framework("unable to preg_match {$line}", __FUNCTION__, __FILE__, __LINE__); } writelogs_framework("DB FILE=\"{$db}\"", __FUNCTION__, __FILE__, __LINE__); writelogs_framework("INC FILE={$inc_file}", __FUNCTION__, __FILE__, __LINE__); $file = "<?php\n"; if (is_array($conf)) { $file = $file . implode("\n", $conf); } $file = $file . "\n"; $file = $file . "?>"; @file_put_contents($inc_file, $file); @chmod($inc_file, 0755); }
function smartctl_A() { $unix = new unix(); $smartctl = $unix->find_program("smartctl"); $cmd = "{$smartctl} -A {$_GET["health"]} 2>&1"; exec("{$cmd}", $results); writelogs_framework("{$cmd} " . count($results) . " rows", __FUNCTION__, __FILE__, __LINE__); while (list($num, $line) = each($results)) { if (preg_match("#([0-9]+)\\s+(.+?)\\s+([0-9a-z]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+(.+?)\\s+(.+?)\\s+([0-9\\-]+)\\s+(.+?)\$#", $line, $re)) { $array[$re[1]] = array("ATTRIBUTE" => $re[2], "FLAG" => $re[3], "VALUE" => $re[4], "WORST" => $re[5], "TRESH" => $re[6], "TYPE" => $re[7], "UPDATED" => $re[8], "WHEN_FAILED" => $re[9], "RAW_VALUE" => $re[10]); } else { writelogs_framework("FAILED -> {$line}", __FUNCTION__, __FILE__, __LINE__); } } writelogs_framework("RETURN -> " . count($array) . " rows", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>" . base64_encode(serialize($array)) . "</articadatascgi>"; }
function restart_progress() { $GLOBALS["CACHEFILE"] = "/usr/share/artica-postfix/ressources/logs/web/ss5.progress"; $GLOBALS["LOGSFILES"] = "/usr/share/artica-postfix/ressources/logs/web/ss5.log"; @unlink($GLOBALS["CACHEFILE"]); @unlink($GLOBALS["LOGSFILES"]); @touch($GLOBALS["CACHEFILE"]); @touch($GLOBALS["LOGSFILES"]); @chmod($GLOBALS["CACHEFILE"], 0777); @chmod($GLOBALS["LOGSFILES"], 0777); $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.ss5.php --restart --progress >{$GLOBALS["LOGSFILES"]} 2>&1 &"; writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function access_events() { $filename = "/var/log/squid/haarp.access.log"; $search = $_GET["access-events"]; $unix = new unix(); $search = $unix->StringToGrep($search); $grep = $unix->find_program("grep"); $tail = $unix->find_program("tail"); $refixcmd = "{$tail} -n 2500 {$filename}"; if ($search != null) { $refixcmd = $refixcmd . "|{$grep} -i -E '{$search}'|{$tail} -n 500"; } else { $refixcmd = "{$tail} -n 500 {$filename}"; } exec($refixcmd . " 2>&1", $results); writelogs_framework($refixcmd . " (" . count($results) . ")", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>" . base64_encode(serialize($results)) . "</articadatascgi>"; }
function run_backup_exec() { $unix = new unix(); $md5 = $_GET["md5"]; $pidfile = "/var/run/offlineimap-{$md5}.pid"; if (!is_file($pidfile)) { writelogs_framework("{$pidfile} -> no such file", __FUNCTION__, __FILE__, __LINE__); return; } $pid = @file_get_contents($pidfile); writelogs_framework("{$pidfile} -> {$pid}", __FUNCTION__, __FILE__, __LINE__); if ($unix->process_exists($pid)) { $timemin = $unix->PROCCESS_TIME_MIN($pid); echo "<articadatascgi>{$timemin}</articadatascgi>"; return; } writelogs_framework("{$pidfile} -> FALSE", __FUNCTION__, __FILE__, __LINE__); }
function uncompress() { $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $tar = $unix->find_program("tar"); $filename = $_GET["uncompress"]; $nohup = $unix->find_program("nohup"); $FilePath = "/usr/share/artica-postfix/ressources/conf/upload/{$filename}"; if (!is_file($FilePath)) { echo "<articadatascgi>" . base64_encode(serialize(array("R" => false, "T" => "{failed}: {$FilePath} no such file"))) . "</articadatascgi>"; return; } $cmd = "{$tar} -xf {$FilePath} -C /"; writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $VERSION = snmpd_version(); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php --snmpd >/dev/null 2>&1 &"); echo "<articadatascgi>" . base64_encode(serialize(array("R" => true, "T" => "{success}: v.{$VERSION}"))) . "</articadatascgi>"; }
function access_logs(){ $unix=new unix(); $tail=$unix->find_program("tail"); $grep=$unix->find_program("grep"); $search=$_GET["search"]; if(strlen($search)>1){ $search=str_replace("*", ".*", $search); $cmd="$tail -n 1000 /var/log/squid/access.log|$grep -E \"$search\" 2>&1"; }else{ $cmd="$tail -n 500 /var/log/squid/access.log 2>&1"; } exec($cmd,$results); writelogs_framework($cmd ." ". count($results)." rows",__FUNCTION__,__FILE__,__LINE__); echo "<articadatascgi>". base64_encode(serialize($results))."</articadatascgi>"; }
function transport() { $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/postfix.transport.progress"; $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/postfix.transport.progress.txt"; @unlink($GLOBALS["PROGRESS_FILE"]); @unlink($GLOBALS["LOGSFILES"]); @touch($GLOBALS["PROGRESS_FILE"]); @touch($GLOBALS["LOGSFILES"]); @chmod($GLOBALS["PROGRESS_FILE"], 0777); $array["POURC"] = 2; $array["TEXT"] = "{please_wait}"; @file_put_contents($GLOBALS["CACHEFILE"], serialize($array)); @chmod($GLOBALS["LOGSFILES"], 0777); $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.postfix.transport.php >{$GLOBALS["LOG_FILE"]} 2>&1 &"; writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function vpn_client_running() { $id = $_GET["is-client-running"]; $pid = trim(@file_get_contents("/etc/artica-postfix/openvpn/clients/{$id}/pid")); $unix = new unix(); writelogs_framework("/etc/artica-postfix/openvpn/clients/{$id}/pid -> {$pid}", __FUNCTION__, __FILE__, __LINE__); if ($unix->process_exists($pid)) { echo "<articadatascgi>TRUE</articadatascgi>"; return; } writelogs_framework("{$id}: pid {$pid}", __FUNCTION__, __FILE__, __LINE__); exec($unix->find_program("pgrep") . " -l -f \"openvpn.+?clients\\/2\\/settings.ovpn\" 1>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^([0-9]+)\\s+.*openvpn#", $ligne)) { writelogs_framework("pid= preg_match= {$re[1]}", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>TRUE</articadatascgi>"; return; } } writelogs_framework("{$pid} NOT RUNNING", __FUNCTION__, __FILE__, __LINE__); }
function test_auth() { $unix = new unix(); $username = base64_decode($_GET["username"]); $password = base64_decode($_GET["password"]); $radtest = $unix->find_program("radtest"); $username = $unix->shellEscapeChars($username); $password = $unix->shellEscapeChars($password); $resultsA = "\t\t*********************************\n\t\t*********** FAILED *******************\n\t\t*********************************\n"; $mainpassword = @file_get_contents("/etc/artica-postfix/ldap_settings/password"); $mainpassword = $unix->shellEscapeChars($mainpassword); $cmdline = "{$radtest} {$username} {$password} localhost 0 {$mainpassword} 2>&1"; writelogs_framework("{$cmdline}", __FUNCTION__, __FILE__, __LINE__); exec($cmdline, $results); while (list($num, $ligne) = each($results)) { if (preg_match("#User-Password#", $ligne, $re)) { } if (preg_match("#Access-Accept#", $ligne)) { $resultsA = "\t\t*********************************\n\t\t*********** SUCCESS ******************\n\t\t*********************************\n"; } } $resultsA = str_replace("*", " * ", $resultsA); echo "<articadatascgi>" . base64_encode($resultsA . @implode("\n", $results)) . "</articadatascgi>"; }
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); }