function restart($nopid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if (!$nopid) { $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]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); stop(true); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Reconfigure...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Path: /etc/zarafa/httpd.conf...\n"; } build(); start(true); }
function restart() { $unix = new unix(); $shorewall = $unix->find_program("shorewall"); if (!is_file($shorewall)) { return; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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 "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Already task running PID {$pid} since {$time}mn\n"; } return; } stop(true); start(true); if (is_file("/etc/init.d/ssh")) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, restarting SSH service.\n"; } system("/etc/init.d/ssh restart"); } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ACTION DONE.\n"; } }
function movementLogic() { global $posx, $posy, $serial, $curDirection, $curMove, $direction, $DIYdistance_LEFT, $DIYdistance, $DIYdistance_RIGHT, $carIsRunning; echo "left " . $DIYdistance_LEFT . "\n"; echo "center" . $DIYdistance . "\n"; echo "right" . $DIYdistance_RIGHT . "\n"; echo "Current" . $curDirection . "\n"; if ($carIsRunning) { //echo " forward "; if ($DIYdistance_RIGHT >= OBSTACLE && $DIYdistance_LEFT >= OBSTACLE && $DIYdistance >= OBSTACLE && ($curDirection != 's' && $curDirection != 'a' && $curDirection != 'd')) { forward(); // $carIsRunning = TRUE; } else { if ($DIYdistance_RIGHT < OBSTACLE && $DIYdistance_LEFT < OBSTACLE && $DIYdistance <= OBSTACLE) { backward(); $carIsRunning = TRUE; } else { stop(); $carIsRunning = TRUE; //FALSE; } } } }
function restart($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("haproxy"); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "ReStarting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, haproxy not installed\n"; } return; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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 "ReStarting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } stop(true); build(); start(true); }
function restart() { $unix = new unix(); $sock = new sockets(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); stop(true); build(); sleep(1); start(true); $cicap = $unix->find_program("c-icap"); if (is_file($cicap)) { $CicapEnabled = intval($sock->GET_INFO("CicapEnabled")); if ($CicapEnabled == 1) { system("/etc/init.d/c-icap reload"); } } }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); build_progress("{stopping_service}", 10); stop(true); build_progress("{reconfiguring}", 40); build(); sleep(1); build_progress("{starting_service}", 45); if (!start(true)) { build_progress("{starting_service} {failed}", 110); return; } system("/etc/init.d/monit restart"); build_progress("{starting_service} {success}", 100); }
function restart() { $pid = stop(); // wait for main process to shut down while ($pid && count(explode("\n", shell_exec("ps --pid " . $pid))) > 2) { usleep(50000); } start(); }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: Memcached Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); stop(true); start(true); }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); vsftpd_admin_mysql(1, "Restarting VSFTPD service...", null, __FILE__, __LINE__); stop(true); sleep(1); start(true); }
function movementLogic() { global $posx, $posy, $curMove, $direction, $DIYdistance_LEFT, $DIYdistance, $DIYdistance_RIGHT, $carIsRunning; echo "logic"; echo $carIsRunning; if ($carIsRunning) { echo " forward "; forward(); /*if ( ( !($DIYdistance_RIGHT < OBSTACLE) || !($DIYdistance_LEFT < OBSTACLE) || !($DIYdistance < OBSTACLE) ) && ( ($curMove != 's') || ($curMove != 'a') || ($curMove != 'd') ) ){ forward(); echo "empros\n"; $carIsRunning = TRUE; }elseif (($curMove != 'a') && ($DIYdistance_LEFT > $DIYdistance_RIGHT)){ left(); echo "aristera\n"; $carIsRunning = TRUE; }elseif (($curMove != 'd') && ($DIYdistance_LEFT < $DIYdistance_RIGHT)){ right(); echo "dexia\n"; $carIsRunning = TRUE; }elseif ( ($DIYdistance_RIGHT < OBSTACLE) && ($DIYdistance_LEFT < OBSTACLE) && ($DIYdistance < OBSTACLE) ) { stop(); echo "stop\n"; $carIsRunning = false; } else{ forward(); echo "piso\n"; $carIsRunning = TRUE; }*/ } else { stop(); echo "Stops from position.php"; $carIsRunning = TRUE; } }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); squid_admin_mysql(1, "HAARP: Restart operation ordered", "{$GLOBALS["RGVS"]}"); stop(true); sleep(1); start(true); $squidbin = $unix->LOCATE_SQUID_BIN(); squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__); }
function upcoming_attendees_html($event, $types = array('attend')) { $yql = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20%22http%3A%2F%2Fupcoming.yahoo.com%2Fajax%2Fevent_page_all_attendees.php%3Fevent_id%3D{$event}%22%3B&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback="; $json = file_get_contents($yql); $json = json_decode($json); if (!$json || !is_object($json)) { stop('Bad YQL response', 500); } $results = $json->query->results; if (!$results) { stop('Event not found', 404); } $html = ''; foreach ($types as $type) { $html .= $results->rsp->{$type} . "\n"; } if (!$html) { stop('Bad YQL data structure', 500); } return html_entity_decode($html); }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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 "Restarting....: [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $pid = PID_NUM(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Restarting....: [INIT]: {$GLOBALS["TITLENAME"]} PID {$pid} running since {$time}mn\n"; } } stop(true); sleep(1); start(true); }
function getDataJSON($user = null) { global $username, $conn, $ustabl; if ($user == null) { $user = $username; } $login = loginstatus(); if ($login['username'] != $user && $login['isAdmin'] != "true") { stop('E0.0.1', "You're not logged in like that!"); } $sql = "SELECT data FROM {$ustabl} WHERE username='******'"; $result = $conn->query($sql); if ($result->num_rows == 0) { stop('E0.1', "Username not known. [{$user}]"); // E1* } if ($result->num_rows > 1) { stop('E0.2', "Internal error!"); // E2* } $data = $result->fetch_assoc()['data']; // We're sure to get 1 line return $data; }
function error($string){ makelog('<<ERROR>>: '.$string); stop(); DIE(); }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("pdns_server"); $PowerDNSLogLevel = $sock->GET_INFO("PowerDNSLogLevel"); $PowerDNSDNSSEC = $sock->GET_INFO("PowerDNSDNSSEC"); $PowerDNSLogsQueries = $sock->GET_INFO("PowerDNSLogsQueries"); if (!is_numeric($PowerDNSLogLevel)) { $PowerDNSLogLevel = 0; } if (!is_numeric($PowerDNSDNSSEC)) { $PowerDNSDNSSEC = 0; } if (!is_numeric($PowerDNSLogsQueries)) { $PowerDNSLogsQueries = 0; } if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, not installed\n"; } return; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); $EnablePDNS = $sock->GET_INFO("EnablePDNS"); if (!is_numeric($EnablePDNS)) { $EnablePDNS = 0; } if ($EnablePDNS == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnablePDNS)\n"; } stop(true); return; } if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } if (!is_file("/usr/lib/libboost_serialization.so.1.49.0")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}: Please wait, installing libboost-serialization1.49.0\n"; } $unix->DEBIAN_INSTALL_PACKAGE("libboost-serialization1.49.0"); } $php5 = $unix->LOCATE_PHP5_BIN(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $nohup = $unix->find_program("nohup"); $dnsmasq_bin = $unix->find_program("dnsmasq"); $kill = $unix->find_program("kill"); if (is_file($dnsmasq_bin)) { $dnsmasq_pid = $unix->PIDOF($dnsmasq_bin); if ($unix->process_exists($dnsmasq_pid)) { unix_system_kill_force($dnsmasq_pid); } } @mkdir("/var/run/pdns", 0755, true); $t = explode("\n", @file_get_contents("/etc/powerdns/pdns.conf")); while (list($index, $ligne) = each($t)) { if (preg_match("#^recursor=(.+)\$#", $ligne, $re)) { $recursor = trim($re[1]); break; } } $PowerDNSPerfs = unserialize(base64_encode($sock->GET_INFO("PowerDNSPerfs"))); if (!isset($PowerDNSPerfs["cache-ttl"])) { $PowerDNSPerfs["cache-ttl"] = 3600; } if (!isset($PowerDNSPerfs["negquery-cache-ttl"])) { $PowerDNSPerfs["negquery-cache-ttl"] = 7200; } if (!isset($PowerDNSPerfs["query-cache-ttl"])) { $PowerDNSPerfs["query-cache-ttl"] = 300; } if (!isset($PowerDNSPerfs["recursive-cache-ttl"])) { $PowerDNSPerfs["recursive-cache-ttl"] = 7200; } if (!is_numeric($PowerDNSPerfs["negquery-cache-ttl"])) { $PowerDNSPerfs["negquery-cache-ttl"] = 7200; } if (!is_numeric($PowerDNSPerfs["query-cache-ttl"])) { $PowerDNSPerfs["query-cache-ttl"] = 300; } if (!is_numeric($PowerDNSPerfs["recursive-cache-ttl"])) { $PowerDNSPerfs["recursive-cache-ttl"] = 7200; } if (!is_numeric($PowerDNSPerfs["cache-ttl"])) { $PowerDNSPerfs["cache-ttl"] = 3600; } $cmds[] = $Masterbin; $cmds[] = "--daemon --guardian=yes"; $cmds[] = "--recursor={$recursor}"; $cmds[] = "--config-dir=/etc/powerdns"; $cmds[] = "--cache-ttl={$PowerDNSPerfs["cache-ttl"]}"; $cmds[] = "--negquery-cache-ttl={$PowerDNSPerfs["negquery-cache-ttl"]}"; $cmds[] = "--query-cache-ttl={$PowerDNSPerfs["query-cache-ttl"]}"; $cmds[] = "--recursive-cache-ttl={$PowerDNSPerfs["recursive-cache-ttl"]}"; if ($PowerDNSLogLevel > 8) { $cmds[] = "--log-dns-details --loglevel={$PowerDNSLogLevel}"; } else { if ($PowerDNSLogsQueries == 1) { $cmds[] = "--log-dns-details"; } if ($PowerDNSLogLevel > 0) { $cmds[] = "--loglevel={$PowerDNSLogLevel}"; } } $cmd = @implode(" ", $cmds); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n"; } shell_exec($cmd); for ($i = 1; $i < 11; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } if ($PowerDNSDNSSEC == 1) { shell_exec("{$php5} /usr/share/artica-postfix/exec.pdns.php --dnssec"); } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } }
} } break; case 'wipe': // Removing temporary files if (isset($node_id)) { // Node ID is set, stop and wipe the node stop($lab->getNodes()[$node_id]); $cmd = 'rm -rf "/opt/unetlab/tmp/' . $tenant . '/' . $lab->getId() . '/' . $node_id . '/"'; exec($cmd, $o, $rc); if ($rc !== 0) { error_log(date('M d H:i:s ') . date('M d H:i:s ') . 'ERROR: ' . $GLOBALS['messages'][13]); error_log(date('M d H:i:s ') . date('M d H:i:s ') . implode("\n", $o)); exit(13); } } else { // Node ID is not set, stop and wipe all nodes foreach ($lab->getNodes() as $node_id => $node) { stop($node); } $cmd = 'rm -rf "/opt/unetlab/tmp/' . $tenant . '/' . $lab->getId() . '/"'; exec($cmd, $o, $rc); if ($rc !== 0) { error_log(date('M d H:i:s ') . date('M d H:i:s ') . 'ERROR: ' . $GLOBALS['messages'][13]); error_log(date('M d H:i:s ') . date('M d H:i:s ') . implode("\n", $o)); exit(13); } } break; } exit(0);
function clean($aspid = false) { $unix = new unix(); $sock = new sockets(); $pidfile = "/etc/artica-postfix/pids/zarafa-search-starter.pid"; if (!$aspid) { $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]: {$GLOBALS["SERVICE_NAME"]} Engine Artica Task Already running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath"); if ($ZarafaIndexPath == null) { $ZarafaIndexPath = "/var/lib/zarafa/index"; } $rm = $unix->find_program("rm"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} directory {$ZarafaIndexPath}\n"; } stop(true); recursive_remove_directory($ZarafaIndexPath, true); start(true); }
function restart() { stop(); echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, build_index_page();\n"; build_index_page(); start(); }
function shutdown() { // This is our shutdown function, in // here we can do any last operations // before the script is complete. stop(); exec("echo q > /dev/ttymotor"); echo "Script executed with success"; }
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"); }
if (preg_match("#--force#", implode(" ", $argv), $re)) { $GLOBALS["FORCE"] = true; } if (preg_match("#--reconfigure#", implode(" ", $argv), $re)) { $GLOBALS["RECONFIGURE"] = true; } $GLOBALS["AS_ROOT"] = true; include_once dirname(__FILE__) . '/framework/class.unix.inc'; include_once dirname(__FILE__) . '/framework/frame.class.inc'; include_once dirname(__FILE__) . '/framework/class.settings.inc'; include_once dirname(__FILE__) . '/ressources/class.squid.inc'; include_once dirname(__FILE__) . '/ressources/class.system.network.inc'; $GLOBALS["ARGVS"] = implode(" ", $argv); if ($argv[1] == "--stop") { $GLOBALS["OUTPUT"] = true; stop(); die; } if ($argv[1] == "--start") { $GLOBALS["OUTPUT"] = true; start(); die; } if ($argv[1] == "--restart") { $GLOBALS["OUTPUT"] = true; restart(); die; } if ($argv[1] == "--reload") { $GLOBALS["OUTPUT"] = true; reload();
function ban($userid) { global $allplayers, $bot; if (isset($allplayers[$userid])) { global $banlist; $banlist[$userid] = 1; stop($userid); file_put_contents('banlist', serialize($banlist)); $bot->send(30406413, 'Игрок ' . $userid . ' заблокирован, счет аннулирован.'); // "Player ... banned, score nulled." $top[$userid] = 0; $bot->send($userid, 'Вы заблокированы администратором, ваши очки сборшены.'); // "You was blocked by administrator, your score nulled." } else { $bot->send(30406413, 'Игрок ' . $userid . ' не найден в списке игроков.'); // "Player ... was not found in players list." } }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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 "ReStarting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); stop(true); if ($GLOBALS["OUTPUT"]) { echo "Restarting....: [INIT]: {$GLOBALS["TITLENAME"]} Removing sessions\n"; } remove_sessions(); if ($GLOBALS["OUTPUT"]) { echo "Restarting....: [INIT]: {$GLOBALS["TITLENAME"]} Building rules\n"; } build(); start(true); if ($GLOBALS["OUTPUT"]) { echo "Restarting....: [INIT]: {$GLOBALS["TITLENAME"]} Success starting PID 0\n"; } }
function restart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); build_progress(10, "{stopping} {APP_FRESHCLAM}"); stop(true); build_progress(50, "{building_configuration}"); build(); sleep(1); build_progress(70, "{starting} {APP_FRESHCLAM}"); if (start(true)) { if ($GLOBALS["PROGRESS"]) { build_progress(95, "{restarting} {watchdog}"); system("/etc/init.d/artica-status restart"); } build_progress(100, "{done} {APP_FRESHCLAM}"); } }
include_once dirname(__FILE__) . '/ressources/class.mysql.squid.builder.php'; include_once dirname(__FILE__) . '/framework/class.unix.inc'; include_once dirname(__FILE__) . '/framework/frame.class.inc'; if ($argv[1] == "--build-squid") { $GLOBALS["OUTPUT"] = true; build_squid(); die; } if ($argv[1] == "--build") { $GLOBALS["OUTPUT"] = true; build(); die; } if ($argv[1] == "--stop") { $GLOBALS["OUTPUT"] = true; stop($argv[2]); die; } if ($argv[1] == "--start") { $GLOBALS["OUTPUT"] = true; start($argv[2]); die; } function start($ID) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/sockd.pid"; $SERV_NAME = $GLOBALS["SERV_NAME"]; $pid = $unix->get_pid_from_file($pidfile); $sock = new sockets(); if ($unix->process_exists($pid, basename(__FILE__))) {
function parse_memory() { $unix = new unix(); $nginx = $unix->find_program("nginx"); $sock = new sockets(); $nginx = $unix->find_program("nginx"); if (!is_file($nginx)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, not installed\n"; } return; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidStampReload = $GLOBALS["pidStampReload"]; if (!$GLOBALS["VERBOSE"]) { echo "{$pidtime}\n"; $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; } $TimExec = $unix->file_time_min($pidtime); if ($TimExec < 5) { return; } } @file_put_contents($pidfile, getmypid()); @unlink($pidtime); @file_put_contents($pidtime, time()); $python = $unix->find_program("python"); $nice = $unix->EXEC_NICE(); exec("{$nice}{$python} /usr/share/artica-postfix/bin/ps_mem.py 2>&1", $results); $FOUND = false; while (list($index, $line) = each($results)) { $line = trim($line); if ($line == null) { continue; } if (!preg_match("#^[0-9\\.]+.*?=\\s+([0-9\\.]+)\\s+(.+?)\\s+nginx#", $line, $re)) { if ($GLOBALS["VERBOSE"]) { echo "Not found \"{$line}\"\n"; } continue; } $memoryValue = $re[1]; $unit = trim(strtolower($re[2])); echo "Found {$memoryValue} {$unit}\n"; if ($unit == "kib") { $memoryValue = $memoryValue / 1048.576; } if ($unit == "mib") { $memoryValue = $memoryValue * 1.048576; } if ($unit == "gib") { $memoryValue = $memoryValue * 1048.576; } $FOUND = true; break; } if (!$FOUND) { if ($GLOBALS["VERBOSE"]) { echo "Not found...\n"; } return; } $memoryValue = round($memoryValue, 2); $MaxMemory = max_memory(); $MaxMemoryReload = $MaxMemory / 2; $memoryValueInt = intval($memoryValue); echo "Nginx = {$memoryValue} MB INT({$memoryValueInt}) Reload on:{$MaxMemoryReload}MB; Restart on:{$MaxMemory}MB\n"; $ACTION_DONE = false; if ($MaxMemory > 0) { if ($memoryValueInt > 0) { if ($memoryValueInt > $MaxMemoryReload) { $StampTime = $unix->file_time_min($pidStampReload); if ($StampTime > 20) { squid_admin_mysql(1, "Reverse proxy reach medium memory {$memoryValueInt}MB Reload:{$MaxMemoryReload}MB [action=reload]", "The service will be restarted"); reload(true); @unlink($pidStampReload); @file_put_contents($pidStampReload, time()); $ACTION_DONE = true; } } if (!$ACTION_DONE) { if ($memoryValueInt > $MaxMemory) { squid_admin_mysql(0, "Reverse proxy reach max memory allowed {$memoryValueInt}MB MAX:{$MaxMemory}MB [action=restart]", "The service will be restarted"); stop(true); start(true); @unlink($pidStampReload); } } } } add_memory_value($memoryValue); }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("ufdbguardd"); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ufdbguardd not installed\n"; } return; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); $EnableUfdbGuard = $sock->EnableUfdbGuard(); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } $UseRemoteUfdbguardService = $sock->GET_INFO("UseRemoteUfdbguardService"); if (!is_numeric($UseRemoteUfdbguardService)) { $UseRemoteUfdbguardService = 0; } if ($EnableRemoteStatisticsAppliance == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableRemoteStatisticsAppliance)\n"; } if ($unix->process_exists($pid)) { stop(true); } return; } if ($UseRemoteUfdbguardService == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see UseRemoteUfdbguardService)\n"; } if ($unix->process_exists($pid)) { stop(true); } return; } if ($EnableUfdbGuard == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableUfdbGuard)\n"; } if ($unix->process_exists($pid)) { stop(true); } return; } if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } $php5 = $unix->LOCATE_PHP5_BIN(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $nohup = $unix->find_program("nohup"); $tail = $unix->find_program("tail"); if (!is_file("/var/log/squid/ufdbguardd.log")) { for ($i = 1; $i < 5; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting for ufdbguardd.log {$i}/5\n"; } sleep(1); if (is_file("/var/log/squid/ufdbguardd.log")) { break; } } } STOP_TAIL_INSTANCES(); $cmd = "{$tail} -f -n 0 /var/log/squid/ufdbguardd.log|{$php5} /usr/share/artica-postfix/exec.ufdbguard-tail.php >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n"; } shell_exec($cmd); for ($i = 1; $i < 11; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } }
echo "Fatal, could not configure apache2 to use fossology\n"; } */ /* if(!stop('httpd')) { echo "Erorr! Could not restart httpd, please restart by hand\n"; exit(1); } if(!start('httpd')) { echo "Erorr! Could not restart httpd, please restart by hand\n"; exit(1); } */ if (!stop('iptables')) { echo "Erorr! Could not stop Firewall, please stop by hand\n"; exit(1); } /* echo "*** Starting fossology ***\n"; if(!start('fossology')) { echo "Erorr! Could not start fossology, please restart by hand\n"; exit(1); } */ break; case 'Fedora': $fedora = 'Fedora'; $fedVersion = $distros[2];
function restart() { $unix = new unix(); $sock = new sockets(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } build_progress_restart("{failed}", 110); return; } @file_put_contents($pidfile, getmypid()); build_progress_restart("{stopping_service}", 15); if (!stop(true)) { build_progress_restart("{failed}", 110); return; } build_progress_restart("{reconfiguring}", 30); build(); sleep(1); build_progress_restart("{starting_service}", 30); if (!start(true)) { build_progress_restart("{failed}", 110); } build_progress_restart("{reloading} Postfix", 90); system("/etc/init.d/postfix reload"); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.freshclam.php --execute >/dev/null 2>&1 &"); build_progress_restart("{success}", 100); }