require './plugins/' . $name . '/setup.php';
 try {
     #Setup transaction
     $db->beginTransaction();
     #Delete addon
     if (isset($setup[$name])) {
         unset($setup[$name]);
         Uninstall();
         if (isset($data['link'])) {
             $db->exec('DELETE FROM ' . PRE . 'mitems WHERE url="' . $name . '"');
             include './lib/mcache.php';
             RenderMenu();
         }
     } else {
         $setup[$name] = (double) $data['version'];
         Install();
         if (isset($_POST['m'])) {
             $q = $db->prepare('INSERT INTO ' . PRE . 'mitems (menu,text,url,seq) VALUES (?,?,?,?)');
             for ($i = 0, $num = count($_POST['mt']); $i < $num; ++$i) {
                 if (!empty($_POST['mt'][$i])) {
                     $q->execute(array($_POST['mid'][$i], $_POST['mt'][$i], $name, $_POST['mp'][$i]));
                 }
             }
             include './lib/mcache.php';
             RenderMenu();
         }
     }
     $o = new Config('plug');
     $o->add('setup', $setup);
     $o->save();
     $db->commit();
Exemple #2
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/opt/influxdb/influxd";
    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());
    }
    build_progress_rs("{starting_service}", 30);
    if (!is_file($Masterbin)) {
        Install();
        if (!is_file($Masterbin)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, influxdb not installed\n";
            }
            build_progress_rs("{failed_to_start_service} ({not_installed})", 110);
            return;
        }
    }
    $pid = PID_NUM();
    $EnableUnifiController = intval($sock->GET_INFO("EnableUnifiController"));
    $UnifiHTTPPort = intval($sock->GET_INFO("UnifiHTTPPort"));
    if ($UnifiHTTPPort == 0) {
        $UnifiHTTPPort = 8088;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($EnableUnifiController == 0) {
            stop(true);
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        build_progress_rs("{already_running}", 100);
        return true;
    }
    if ($EnableUnifiController == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Disabled\n";
        }
        build_progress_rs("{starting_service} {failed} ({disabled})", 110);
        return false;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $date = $unix->find_program("date");
    build_progress_rs("{starting_service}!", 35);
    build_progress_rs("{starting_service}", 45);
    $cmd = "/etc/init.d/unifi start >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress_rs("{starting_service}", 45 + $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)) {
        build_progress_rs("{starting_service}", 50);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        build_progress_rs("{starting_service} {success}", 100);
        return true;
    } else {
        build_progress_rs("{failed_to_start_service}", 110);
        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";
        }
        return false;
    }
}
Exemple #3
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/opt/influxdb/influxd";
    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());
    }
    if (!is_file($Masterbin)) {
        Install();
        if (!is_file($Masterbin)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, influxdb not installed\n";
            }
            return;
        }
    }
    $pid = PID_NUM();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    @mkdir("/home/artica/squid/InfluxDB", 0755, true);
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($SquidPerformance > 2) {
            stop(true);
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    if ($SquidPerformance > 2) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Perfomance is set to no statistics\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    if (!is_dir("/var/log/influxdb")) {
        @mkdir("/var/log/influxdb", 0755, true);
    }
    $influxdb_version = influxdb_version();
    Config($influxdb_version);
    if (preg_match("#^0\\.9#", $influxdb_version)) {
        $f[] = "{$Masterbin} run -config=/etc/opt/influxdb/influxdb.conf";
        $f[] = "-pidfile=/var/run/influxdb.pid";
    }
    if (preg_match("#^0\\.8#", $influxdb_version)) {
        $f[] = "{$Masterbin} -config=/etc/opt/influxdb/influxdb.conf";
        $f[] = "-pidfile=/var/run/influxdb.pid";
    }
    $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} v{$influxdb_version} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $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 v{$influxdb_version} 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";
        }
    }
}
Exemple #4
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/opt/influxdb/influxd";
    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());
    }
    build_progress_rs("{starting_service}", 30);
    if (!is_file($Masterbin)) {
        Install();
        if (!is_file($Masterbin)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, influxdb not installed\n";
            }
            build_progress_rs("{failed_to_start_service} ({not_installed})", 110);
            return;
        }
    }
    if (!is_file("/etc/artica-postfix/settings/Daemons/EnableInfluxDB")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableInfluxDB", 1);
    }
    $pid = PID_NUM();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    $EnableInfluxDB = intval($sock->GET_INFO("EnableInfluxDB"));
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    if ($InfluxUseRemote == 1) {
        $EnableInfluxDB = 0;
    }
    $EnableIntelCeleron = intval(file_get_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron"));
    if ($EnableIntelCeleron == 1) {
        $EnableInflux = 0;
    }
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $EnableInflux = 1;
        $SquidPerformance = 0;
        $EnableIntelCeleron = 0;
    }
    @mkdir("/home/artica/squid/InfluxDB", 0755, true);
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($SquidPerformance > 2) {
            stop(true);
            build_progress_rs("{starting_service} {failed} ({disabled})", 110);
            return;
        }
        if ($EnableInfluxDB == 0) {
            stop(true);
            build_progress_rs("{starting_service} {failed} ({disabled})", 110);
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        build_progress_rs("{already_running}", 100);
        return true;
    }
    if ($EnableInfluxDB == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} InfluxDB engine is disabled\n";
        }
        build_progress_rs("{starting_service} {failed} ({disabled})", 110);
        return false;
    }
    if ($SquidPerformance > 2) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Perfomance is set to no statistics\n";
        }
        build_progress_rs("{starting_service} {failed} ({disabled})", 110);
        return false;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $date = $unix->find_program("date");
    if (!is_dir("/var/log/influxdb")) {
        @mkdir("/var/log/influxdb", 0755, true);
    }
    $influxdb_version = influxdb_version();
    build_progress_rs("{starting_service} v{$influxdb_version}", 35);
    Config($influxdb_version);
    build_progress_rs("{starting_service}", 45);
    $unix->KILL_PROCESSES_BY_PORT(8086);
    if (!ifInitScript()) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} patching init script\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --influx");
    }
    $cmd = "/etc/init.d/influx-db start";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} v{$influxdb_version} service\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress_rs("{starting_service}", 45 + $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)) {
        build_progress_rs("{starting_service}", 50);
        for ($i = 1; $i < 5; $i++) {
            build_progress_rs("{starting_service} {waiting_listen_port}", 50 + $i);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting 8086 port... {$i}/5\n";
            }
            sleep(1);
            $pid = PID_NUM();
            if (test_listen_port()) {
                break;
            }
        }
        if (!test_listen_port()) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
            }
            build_progress_rs("{failed_to_start_service}", 110);
            return false;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success v{$influxdb_version} PID {$pid}\n";
        }
        build_progress_rs("{starting_service} {success}", 100);
        return true;
    } else {
        build_progress_rs("{failed_to_start_service}", 110);
        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";
        }
        return false;
    }
}