function add_node()
{
    $sock = new sockets();
    $ArticaMetaAddNewServ = unserialize($sock->GET_INFO("ArticaMetaAddNewServ"));
    $ArticaMetaHost = $ArticaMetaAddNewServ["ArticaMetaHost"];
    $ArticaMetaPort = $ArticaMetaAddNewServ["ArticaMetaPort"];
    $ArticaMetaUsername = $ArticaMetaAddNewServ["ArticaMetaUsername"];
    $ArticaMetaPassword = $ArticaMetaAddNewServ["ArticaMetaPassword"];
    $change_uuid = $ArticaMetaAddNewServ["change_uuid"];
    echo "ArticaMetaHost.........: {$ArticaMetaHost}\n";
    echo "ArticaMetaPort.........: {$ArticaMetaPort}\n";
    echo "ArticaMetaUsername.....: {$ArticaMetaUsername}\n";
    echo "Testing authentication...\n";
    add_node_progress("Authenticate to {$ArticaMetaHost}:{$ArticaMetaPort}", 10);
    $array["username"] = $ArticaMetaUsername;
    $array["password"] = $ArticaMetaPassword;
    $ident = urlencode(base64_encode(serialize($array)));
    $curl = new ccurl("https://{$ArticaMetaHost}:{$ArticaMetaPort}/artica.meta.listener.php?test-local-ident={$ident}");
    $curl->NoHTTP_POST = true;
    $curl->NoLocalProxy();
    $curl->Timeout = 120;
    if (!$curl->get()) {
        echo @implode("\n", $curl->errors);
        add_node_progress("{$curl->error}", 110);
        die;
    }
    if (!preg_match("#<ARTICA_META>(.+?)</ARTICA_META>#is", $curl->data, $re)) {
        echo "Expected <ARTICA_META>Someting...</ARTICA_META>";
        add_node_progress("Communication: {failed}", 110);
        die;
    }
    if ($re[1] != "SUCCESS") {
        add_node_progress("Authenticate: {failed}", 110);
        die;
    }
    echo "Testing authentication - success -...\n";
    if ($change_uuid == 1) {
        echo "Ask to remote server to change UUID...\n";
        add_node_progress("{change_uuid}", 20);
        $curl = new ccurl("https://{$ArticaMetaHost}:{$ArticaMetaPort}/artica.meta.listener.php?local-ident={$ident}&chuuid=yes");
        $curl->NoHTTP_POST = true;
        $curl->NoLocalProxy();
        $curl->Timeout = 120;
        if (!$curl->get()) {
            echo @implode("\n", $curl->errors);
            add_node_progress("{$curl->error}", 110);
            die;
        }
        if (!preg_match("#<ARTICA_META>(.+?):(.+?)</ARTICA_META>#is", $curl->data, $re)) {
            add_node_progress("{change_uuid}: Communication: {failed}", 110);
            die;
        }
        add_node_progress("{change_uuid}:{$re[2]} {success}", 25);
        echo "Ask to remote server to change UUID - success -...\n";
    }
    echo "Ask UUID to remote server...\n";
    add_node_progress("{uuid}:", 30);
    $curl = new ccurl("https://{$ArticaMetaHost}:{$ArticaMetaPort}/artica.meta.listener.php?local-ident={$ident}&GetYourUUID=yes");
    $curl->NoHTTP_POST = true;
    $curl->NoLocalProxy();
    $curl->Timeout = 120;
    if (!$curl->get()) {
        echo @implode("\n", $curl->errors);
        add_node_progress("{$curl->error}", 110);
        die;
    }
    if (!preg_match("#<ARTICA_META>(.+?):(.+?)</ARTICA_META>#is", $curl->data, $re)) {
        add_node_progress("{uuid}: Communication: {failed}", 110);
        die;
    }
    $RESULT = $re[1];
    $uuid = $re[2];
    echo "UUID results:\n---------------------------------------------\n{$uuid}\n{$RESULT}\n---------------------------------------------\n";
    if ($RESULT == "SUCCESS") {
        add_node_progress("{uuid}: {$uuid} {success}", 35);
    } else {
        add_node_progress("{uuid}: {failed}", 110);
        return;
    }
    echo "Ask to remote server to register to Artica Meta server ...\n";
    add_node_progress("{order}: -> {register}", 50);
    $ArticaMetaServerUsername = $sock->GET_INFO("ArticaMetaServerUsername");
    $ArticaMetaServerPassword = $sock->GET_INFO("ArticaMetaServerPassword");
    $ArticaMetaAddNewServ["ArticaMetaUsername"] = $ArticaMetaServerUsername;
    $ArticaMetaAddNewServ["ArticaMetaPassword"] = $ArticaMetaServerPassword;
    if ($GLOBALS["VERBOSE"]) {
        $verbosed = "&verbose=yes";
    }
    $ArticaMetaAddNewServ_enc = urlencode(base64_encode(serialize($ArticaMetaAddNewServ)));
    $curl = new ccurl("https://{$ArticaMetaHost}:{$ArticaMetaPort}/artica.meta.listener.php?local-ident={$ident}&registerby={$ArticaMetaAddNewServ_enc}{$verbosed}");
    $curl->NoHTTP_POST = true;
    $curl->NoLocalProxy();
    $curl->Timeout = 120;
    if (!$curl->get()) {
        echo @implode("\n", $curl->errors);
        add_node_progress("{$curl->error}", 110);
        die;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "***********************************\n{$curl->data}\n***********************************\n";
    }
    if (!preg_match("#<ARTICA_META>(.+?):(.+?)</ARTICA_META>#is", $curl->data, $re)) {
        add_node_progress("{register}: Communication: {failed}", 110);
        die;
    }
    $RESULT = $re[1];
    $DATA = $re[2];
    echo $DATA;
    echo "Register results:\n---------------------------------------------\n{$DATA}\n{$RESULT}\n---------------------------------------------\n";
    if ($RESULT == "SUCCESS") {
        add_node_progress("{register}: {success}", 99);
    } else {
        add_node_progress("{register}: {failed}", 110);
        return;
    }
    $artica_meta = new mysql_meta();
    add_node_progress("{waiting}: {$ArticaMetaHost} {to_return_back}", 79);
    for ($i = 0; $i < 20; $i++) {
        if ($artica_meta->isExists($uuid)) {
            break;
        }
        echo "Waiting {$ArticaMetaHost} {$uuid} to register to Artica Meta...{$i}/20 second\n";
        $prc = 79 + $i;
        add_node_progress("{waiting}: {$ArticaMetaHost} {to_return_back}", $prc);
        sleep(1);
    }
    if ($artica_meta->isExists($uuid)) {
        $hostname = $artica_meta->uuid_to_host($uuid);
        add_node_progress("{register}: {success} `{$hostname}`", 100);
        return;
    }
    add_node_progress("{register}: {failed}", 110);
}
예제 #2
0
function scan_categories_clean($MAIN_UUID = array())
{
    $sock = new sockets();
    $unix = new unix();
    $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage");
    if ($ArticaMetaStorage == null) {
        $ArticaMetaStorage = "/home/artica-meta";
    }
    $dirs = $unix->dirdir($ArticaMetaStorage);
    $q = new mysql_meta();
    $rm = $unix->find_program("rm");
    while (list($dirname, $FINAL) = each($dirs)) {
        $uuid = basename($dirname);
        if (!preg_match("#^[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+\$#", $uuid)) {
            continue;
        }
        echo "{$uuid} checking if must stay on disk\n";
        if (!$q->isExists($uuid)) {
            echo "{$uuid}: isExists -> FALSE: Remove {$dirname}\n";
            shell_exec("{$rm} -rf {$dirname}");
            continue;
        }
        if (count($MAIN_UUID) > 0) {
            if (!isset($MAIN_UUID[$uuid])) {
                if (is_file("{$dirname}/PERSONAL_CATEGORIES.gz")) {
                    echo "Remove {$dirname}/PERSONAL_CATEGORIES.gz\n";
                    @unlink("{$dirname}/PERSONAL_CATEGORIES.gz");
                }
            }
        }
        if (is_dir("{$dirname}/EVENT_NOTIFY_MASTER")) {
            echo "Remove {$dirname}/EVENT_NOTIFY_MASTER ( directory )\n";
            shell_exec("{$rm} -rf {$dirname}/EVENT_NOTIFY_MASTER");
        }
        if (is_dir("{$dirname}/SMTP_NOTIF")) {
            echo "Remove {$dirname}/SMTP_NOTIF ( directory )\n";
            shell_exec("{$rm} -rf {$dirname}/SMTP_NOTIF");
        }
    }
}