function stop($aspid = false) { $unix = new unix(); 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 "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { build_progress_rs("{stopping_service}", 30); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } return true; } $pid = PID_NUM(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); build_progress_rs("{stopping_service}", 15); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } system("/etc/init.d/unifi stop >/dev/null 2>&1 &"); for ($i = 0; $i < 5; $i++) { build_progress_rs("{stopping_service}", 15 + $i); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { build_progress_rs("{stopping_service}", 30); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return true; } build_progress_rs("{stopping_service}", 30); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { build_progress_rs("{stopping_service}", 30 + $i); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { build_progress_rs("{stopping_service} {failed}", 110); squid_admin_mysql(0, "Failed to stop Unifi Controller Engine", __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } return; } return true; }
function Checks() { $GLOBALS["NORELOAD"] = true; $unix = new unix(); if (!is_file("/usr/lib/x86_64-linux-gnu/autofs/lookup_ldap.so")) { build_progress_rs("{install} autofs-ldap", 15); $unix->DEBIAN_INSTALL_PACKAGE("autofs-ldap"); } if (!is_file("/usr/lib/x86_64-linux-gnu/autofs/lookup_ldap.so")) { build_progress_rs("{install} autofs-ldap {failed}", 110); return; } if (!$unix->is_socket("/var/run/slapd/slapd.sock")) { build_progress_rs("{restarting_service} OpenLDAP", 15); system("/etc/init.d/slapd restart"); } else { if ($GLOBALS["PROGRESS"]) { build_progress_rs("{restarting_service} OpenLDAP", 15); system("/etc/init.d/slapd restart"); } } $curlftpfs = $unix->find_program("curlftpfs"); $fusermount = $unix->find_program("fusermount"); if (is_file($curlftpfs)) { if (!is_file("/sbin/mount.curl")) { build_progress_rs("/sbin/mount.curl", 15); $curlftpfsZ[] = "#! /bin/sh"; $curlftpfsZ[] = "{$curlftpfs} \$1 \$2 -o \$5,disable_eprt"; $curlftpfsZ[] = ""; @file_put_contents("/sbin/mount.curl", @implode("\n", $curlftpfsZ)); @chmod("/sbin/mount.curl", 0755); } if (!is_file("/sbin/umount.curl")) { build_progress_rs("/sbin/umount.curl", 15); $curlftpfsZ = array(); $curlftpfsZ[] = "#! /bin/sh"; $curlftpfsZ[] = "{$fusermount} -u \$1"; $curlftpfsZ[] = ""; @file_put_contents("/sbin/umount.curl", @implode("\n", $curlftpfsZ)); @chmod("/sbin/umount.curl", 0755); } } $ldap = new clladp(); $data = "<?xml version=\"1.0\" ?>\n <autofs_ldap_sasl_conf\n usetls=\"no\"\n tlsrequired=\"no\"\n authrequired=\"yes\"\n authtype=\"PLAIN\"\n user=\"{$ldap->ldap_admin}\"\n secret=\"{$ldap->ldap_password}\"\n />"; @file_put_contents("/etc/autofs_ldap_auth.conf", $data); if (is_file("/etc/autofs_ldap_auth.conf")) { @chmod("/etc/autofs_ldap_auth.conf", 0600); @chown("/etc/autofs_ldap_auth.conf", "root"); @chgrp("/etc/autofs_ldap_auth.conf", "root"); } build_progress_rs("{checking_configuration}", 15); $auto = new autofs(); build_progress_rs("{checking_configuration}", 20); autofs_default(); build_progress_rs("{checking_configuration}", 25); Autocount(); build_progress_rs("{checking_configuration}", 30); davfs(); }
function remote_progress() { $sock = new sockets(); $POST = unserialize($sock->GET_INFO("InfluxRemoteProgress")); $unix = new unix(); $InfluxUseRemote = intval($POST["InfluxUseRemote"]); $InfluxUseRemoteIpaddr = $POST["InfluxUseRemoteIpaddr"]; $InfluxUseRemotePort = intval($POST["InfluxUseRemotePort"]); if ($InfluxUseRemotePort == 0) { $InfluxUseRemotePort = 8086; } $InfluxUseRemoteArticaPort = intval($POST["InfluxUseRemoteArticaPort"]); if ($InfluxUseRemoteArticaPort == 0) { $InfluxUseRemoteArticaPort = 9000; } $ArticaInfluxUsername = $POST["ArticaInfluxUsername"]; $ArticaInfluxPassword = $POST["ArticaInfluxPassword"]; $php = $unix->LOCATE_PHP5_BIN(); $array["username"] = $ArticaInfluxUsername; $array["password"] = $ArticaInfluxPassword; $sock->SET_INFO("InfluxUseRemoteIpaddr", $InfluxUseRemoteIpaddr); $sock->SET_INFO("InfluxUseRemotePort", $InfluxUseRemotePort); echo "Use: {$ArticaInfluxUsername} as SuperAdmin/{$ArticaInfluxPassword}\n"; build_progress_rs("{checking} {enabled}: {$InfluxUseRemote}", 20); sleep(2); build_progress_rs("{checking} Syslog: {$POST["InfluxSyslogRemote"]}", 22); sleep(2); $auth = urlencode(base64_encode(serialize($array))); if ($InfluxUseRemote == 1) { build_progress_rs("{checking} {$InfluxUseRemoteIpaddr}:{$InfluxUseRemoteArticaPort}", 30); if (!$unix->network_test_port($InfluxUseRemoteIpaddr, $InfluxUseRemoteArticaPort)) { build_progress_rs("{checking} {$InfluxUseRemoteIpaddr}:{$InfluxUseRemoteArticaPort} {failed}", 110); return; } build_progress_rs("{notify_statistics_server}", 50); $myhostname = $unix->hostname_g(); $curl = new ccurl("https://{$InfluxUseRemoteIpaddr}:{$InfluxUseRemoteArticaPort}/artica.meta.listener.php?influx-client=yes&hostname={$myhostname}&auth={$auth}", false); $curl->NoHTTP_POST = true; if (!$curl->get()) { echo $curl->error; build_progress_rs("{notify_statistics_server} {failed}", 110); return; } if (strpos($curl->data, "<OK>OK</OK>") == 0) { if (preg_match("#<ERROR>(.+?)<\\/#is", $curl->data, $re)) { echo $re[1] . "\n"; } build_progress_rs("{protocol_error} {failed2}", 110); return; } sleep(3); build_progress_rs("{checking} {$InfluxUseRemoteIpaddr}:{$InfluxUseRemotePort}", 55); if (!$unix->network_test_port($InfluxUseRemoteIpaddr, $InfluxUseRemotePort)) { build_progress_rs("{checking} {$InfluxUseRemoteIpaddr}:{$InfluxUseRemotePort} {failed}", 110); return; } build_progress_rs("{saving_settings}", 60); $sock->SET_INFO("InfluxUseRemote", 1); $sock->SET_INFO("InfluxSyslogRemote", $POST["InfluxSyslogRemote"]); } else { build_progress_rs("{saving_settings}", 60); $sock->SET_INFO("InfluxUseRemote", 0); } build_progress_rs("{reconfiguring_proxy_service}", 70); system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); build_progress_rs("{restarting_services} 1/6", 74); system("/etc/init.d/rsyslog restart"); build_progress_rs("{restarting_services} 2/6", 75); system("/etc/init.d/squid-tail restart"); build_progress_rs("{restarting_services} 3/6", 80); system("/etc/init.d/ufdb-tail restart"); build_progress_rs("{restarting_services} 4/6", 85); system("/etc/init.d/artica-syslog"); build_progress_rs("{restarting_services} 5/6", 90); system("/etc/init.d/artica-status"); build_progress_rs("{restarting_services} 6/6", 95); system("/etc/init.d/influx-db restart"); build_progress_rs("{done}", 100); }