예제 #1
0
function send_request()
{
    global $Version, $VersionH, $BuildDate;
    @($socket = socket_create(AF_INET, SOCK_STREAM, 0));
    if ($socket < 0) {
        $errno = "socket_create() failed.\n";
        return $errno;
    }
    @($result = socket_connect($socket, '127.0.0.1', 9876));
    if ($result == FALSE) {
        $errno = "socket_connect() failed.\n";
        return $errno;
    }
    /* read one line with welcome string */
    $out = read_line($socket);
    /* send hello query */
    $query = "helo  {$Version}\r\n";
    socket_write($socket, $query, strlen($query));
    /* read one line with helo answer */
    $out = read_line($socket);
    /* send reg check query */
    $query = "execute query\r\n";
    socket_write($socket, $query, strlen($query));
    /* read one line key replay */
    $execute_replay = read_line($socket);
    /* send quit query */
    $quit_query = "bye\r\n";
    socket_write($socket, $quit_query, strlen($quit_query));
    /* read quit answer */
    $quit_replay = read_line($socket);
    /* analyze key replay */
    $answer = $execute_replay;
    /* close socket */
    socket_close($socket);
    /* return function result */
    return $answer;
}
예제 #2
0
             $line = read_line($fp);
             if ($line === false) {
                 print "</blockquote>";
                 $etat = "stop";
             } else {
                 if ($line == "PRET SECOURU" || $line == "RETOUR SECOURU") {
                     print "</blockquote>";
                     $etat = "attente";
                 } else {
                     rec_pret($reader, $line);
                     $etat = "pret";
                 }
             }
             break;
         case "debut_retour":
             $line = read_line($fp);
             if ($line === false) {
                 print "</blockquote>";
                 $etat = "stop";
             } else {
                 if ($line == "PRET SECOURU" || $line == "RETOUR SECOURU") {
                     print "</blockquote>";
                     $etat = "attente";
                 } else {
                     rec_retour($line);
                     $etat = "debut_retour";
                 }
             }
             break;
     }
 }
예제 #3
0
        break;
    default:
        throw new Exception('Unsupported mapper: ' . $config_database['mapper']);
        break;
}
if (empty($config['gearman'])) {
    /* 
    Add a Shard-Query managed gearmand
    */
    write_line("A gearman server was not seen in your config.  Enter a host to use: [127.0.0.1]");
    $gearman_host = read_line();
    if (!trim($gearman_host)) {
        $gearman_host = '127.0.0.1';
    }
    write_line("A gearman port was not seen in your config.  Enter a port number to use: [7001]");
    $gearman_port = read_line();
    if (!trim($gearman_port)) {
        $gearman_port = 7001;
    }
    $gearman = array(array('hostname' => $gearman_host, 'port' => $gearman_port, 'is_local' => true));
} else {
    /*
    Use externally managed gearmand
    */
    $gearman = $config['gearman'];
    unset($config['gearman']);
    $gearmen = explode(',', $gearman);
    if (!is_array($gearmen)) {
        $gearmen = array($gearman);
    }
    $gearman = array();
예제 #4
0
function check_data($xml, $data)
{
    global $element, $dict, $check_tags, $current_file, $word_count;
    if (!in_array($element, $check_tags)) {
        return;
    }
    if (trim($data) == '') {
        return;
    }
    $words = preg_split('/\\W+/', trim($data));
    if (is_array($words)) {
        foreach ($words as $word) {
            if (trim($word) == '' || is_numeric($word) || preg_match('/[^a-z]/', $word)) {
                continue;
            }
            $word_count++;
            $word = strtolower($word);
            if (!pspell_check($dict, $word)) {
                /* known bug: due to trim()ing and whitespace removal, the
                 * line number shown here might not match the actual line
                 * number in the file, but it's usually pretty close
                 */
                $note = "{$current_file}:" . xml_get_current_line_number($xml) . ": {$word}   (in element {$element})\n";
                echo $note;
                echo "================\nContext:\n{$data}\n================\n";
                do {
                    $response = read_line("Add this word to personal wordlist? (yes/no/save/later): ");
                    if ($response[0] == 's') {
                        pspell_save_wordlist($dict);
                        echo "Wordlist saved.\n";
                    }
                } while ($response[0] != 'y' && $response[0] != 'n' && $response[0] != 'l');
                if ($response[0] == 'y') {
                    pspell_add_to_personal($dict, $word);
                    echo "Added '{$word}' to personal wordlist.\n";
                }
                if ($response[0] == 'l') {
                    file_put_contents('/tmp/fix-me-later.txt', $note, FILE_APPEND);
                    echo "You will deal with '{$word}' later.\n";
                }
            }
        }
    }
    return;
}
//connect [PDO included in doo framework]
$dbh = null;
try {
    $dbh = new PDO("mysql:host={$sq_host};port={$sq_port};", $username, $password);
} catch (PDOException $e) {
    write_line('Connection failed: ' . $e->getMessage());
    return;
}
//Check for shard_query account
$sql = "SELECT \n\t\tCOUNT(*) as count\n\tFROM\n\t\tmysql.user\n\tWHERE\n\t\tuser = '******' ";
$stmt = $dbh->query($sql);
$res = $stmt->fetch(PDO::FETCH_ASSOC);
$create_user = true;
if ((int) $res['count'] != 0) {
    write_line("A {$sq_username} user was already found.  Do you want to drop it and recreate it?\nHIT CTRL-C TO ABORT NOW WITHOUT MAKING ANY CHANGES, otherwise (y/n): [n]");
    $drop_user = read_line();
    if (strtolower($drop_user[0]) == 'y') {
        write_line("Dropping current user!");
        $sql = "DROP USER {$sq_username}@'%'";
        $dbh->query($sql);
        $sql = "DROP USER {$sq_username}@'localhost'";
        $dbh->query($sql);
        write_line("Done!");
        $create_user = true;
    } else {
        $create_user = false;
    }
}
if ($create_user === true) {
    //add acount
    write_line("Creating user...");
}
echo "Enter the password [shard_query] >";
$repo_pass = read_line();
if (!trim($repo_pass)) {
    $repo_pass = "******";
}
echo "Enter the mapper type (hash|directory|none) [directory] >";
$mapper_type = read_line();
if (!trim($mapper_type)) {
    $mapper_type = "directory";
}
echo "Enter the default virtual schema [default] >";
$virtual_schema = read_line();
if (!trim($virtual_schema)) {
    $virtual_schema = "default";
}
$config = array('rdbms-type' => 'pdo-mysql', 'db' => $repo_db, 'host' => $repo_host, 'port' => $repo_port, 'user' => $repo_user, 'password' => $repo_pass, 'mapper_type' => $mapper_type, 'default_virtual_schema' => $virtual_schema);
echo "";
echo "* Persisting config database pointer to include/\n";
if (file_exists('include/config.inc')) {
    echo "WARNING: An existing configuration exists.  Do you want to overwrite the existing configuration? [y] >";
    $yesno = read_line();
    if (substr(strtolower($yesno), 0, 1) != "y") {
        echo "\nABORTED!\n";
        exit;
    }
}
if (file_put_contents('include/config.inc', serialize($config)) === false) {
    echo "Failure Saving config.inc!";
}
echo "Completed!\n";
예제 #7
0
        $left = is_numeric($parts[0]) ? (int) $parts[0] : '#ref/' . $parts[0];
        $right = is_numeric($parts[2]) ? (int) $parts[2] : '#ref/' . $parts[2];
    } elseif ($cnt == 2) {
        $op = 'NOT';
        $left = 0;
        $right = is_numeric($parts[1]) ? (int) $parts[1] : '#ref/' . $parts[1];
    } else {
        // assign
        if (is_numeric($parts[0])) {
            $wires[$key] = $parts[0];
            return;
        }
        $op = 'Assign';
        $left = 0;
        $right = '#ref/' . $parts[0];
    }
    $className = 'Op_' . $op;
    $wires[$key] = new $className($left, $right);
}
foreach ($lines as $line) {
    read_line($line, $wires);
}
$result = $wires['a']->calculate($wires);
echo "1: ";
var_Dump($result);
$wires = ['b' => $result];
foreach ($lines as $line) {
    read_line($line, $wires);
}
echo "2: ";
var_Dump($wires['a']->calculate($wires));
예제 #8
0
/**
 * SMTP server state machine. Use read_line() to get input from the buffer, add_response() to queue things
 * to the output buffer, kill_client() to stop talking to the client. $save_email_function() to store the email.
 *
 * @param $client_id int
 */
function process_smtp($client_id)
{
    global $clients;
    global $GM_ERROR;
    global $save_email_function;
    switch ($clients[$client_id]['state']) {
        case 0:
            add_response($client_id, '220 ' . GSMTP_HOST_NAME . ' SMTP Guerrilla-SMTPd #' . $client_id . ' (' . sizeof($clients) . ') ' . gmdate('r'));
            $clients[$client_id]['state'] = 1;
            break;
        case 1:
            $input = read_line($clients, $client_id);
            if ($input) {
                log_line('[' . $client_id . '] cmd:' . $input);
            }
            if ($input) {
                if (stripos($input, 'HELO') !== false) {
                    $temp = explode(' ', $input);
                    $clients[$client_id]['helo'] = trim($temp[1]);
                    add_response($client_id, '250 ' . GSMTP_HOST_NAME . ' Hello ' . trim($temp[1]) . ' [' . $clients[$client_id]['address'] . '], got some spam for me?');
                } elseif (stripos($input, 'EHLO') !== false) {
                    $temp = explode(' ', $input);
                    $clients[$client_id]['helo'] = trim($temp[1]);
                    add_response($client_id, '250-' . GSMTP_HOST_NAME . ' Hello ' . trim($temp[1]) . '[' . $clients[$client_id]['address'] . ']' . "\r\n" . "250-SIZE " . GSMTP_MAX_SIZE . "\r\n" . "250 HELP");
                } elseif (stripos($input, 'XCLIENT') === 0) {
                    $clients[$client_id]['address'] = substr($input, 13);
                    if ($pos = strpos($clients[$client_id]['address'], ' ')) {
                        $clients[$client_id]['address'] = substr($clients[$client_id]['address'], 0, $pos);
                    }
                    add_response($client_id, '250 Ok');
                } elseif (stripos($input, 'MAIL FROM:') === 0) {
                    $clients[$client_id]['mail_from'] = substr($input, 10);
                    add_response($client_id, '250 Ok');
                } elseif (stripos($input, 'RCPT TO:') !== false) {
                    $email = extract_rcpt_email(substr($input, 8));
                    // do not allow CC, RCPT TO is allowed only once
                    if (empty($clients[$client_id]['rcpt_to']) && $email) {
                        $clients[$client_id]['rcpt_to'] = $email;
                        add_response($client_id, '250 Accepted');
                    } else {
                        log_line('mailbox unavailable[' . $input . '] input:' . $input, 1);
                        // do not let CC.
                        kill_client($client_id, '550 Requested action not taken: mailbox unavailable');
                    }
                } elseif (stripos($input, 'DATA') !== false) {
                    add_response($client_id, '354 Enter message, ending with "." on a line by itself');
                    $clients[$client_id]['state'] = 2;
                    $clients[$client_id]['read_buffer'] = '';
                } elseif (stripos($input, 'QUIT') !== false) {
                    log_line("client asked to quit", 1);
                    kill_client($client_id, '221 Bye');
                    continue;
                } elseif (stripos($input, 'NOOP') !== false) {
                    log_line("client NOOP from client", 1);
                    add_response($client_id, '250 OK');
                } elseif (stripos($input, 'RSET') !== false) {
                    $clients[$client_id]['read_buffer'] = '';
                    $clients[$client_id]['rcpt_to'] = '';
                    $clients[$client_id]['mail_from'] = '';
                    add_response($client_id, '250 OK');
                } else {
                    log_line('[' . $client_id . ']unrecoginized cmd:' . $input, 1);
                    add_response($client_id, '500 unrecognized command');
                    $clients[$client_id]['error_c']++;
                    if ($clients[$client_id]['error_c'] > 3) {
                        kill_client($client_id, '500 Too many unrecognized commands');
                        continue;
                    }
                }
            }
            break;
        case 2:
            $input = read_line($clients, $client_id);
            if ($input) {
                list($id, $to) = $save_email_function($input, $clients[$client_id]['rcpt_to'], $clients[$client_id]['helo'], $clients[$client_id]['address'], $clients[$client_id]['mail_from']);
                if ($id) {
                    add_response($client_id, '250 OK : queued as ' . $id);
                    // put client back to state 1
                    $clients[$client_id]['state'] = 1;
                    $clients[$client_id]['read_buffer'] = '';
                    $clients[$client_id]['error_c'] = 0;
                } else {
                    // The email didn't save properly, usualy because it was in
                    // an incorrect mime format or bad recipient
                    kill_client($client_id, "554 Transaction failed (" . strlen($input) . ") " . $clients[$client_id]['rcpt_to'] . " !{$id}! \\{{$GM_ERROR}\\} ");
                    log_line("Message for client: [{$client_id}] failed to [{$to}] {" . $clients[$client_id]['rcpt_to'] . "}, told client to exit.", 1);
                }
                continue;
            }
            break;
    }
}
}
echo "";
$create_user = true;
if (empty($params['user'])) {
    write_line("Please enter admin credentials for a user with GRANT option (to set up each shard): ");
    write_line("Please enter mysql a administrator username: [root]");
    $username = read_line();
} else {
    $username = $params['user'];
}
if (trim($username) == "") {
    $username = "******";
}
if (empty($params['password'])) {
    write_line("Enter admin password: [default no password]");
    $password = read_line();
} else {
    $password = $params['password'];
}
echo "* Populating/Updating shard list\n";
$mapper->conn->my_query('DELETE IGNORE shards.* from shards join schemata on shards.schema_id = schemata.id where schema_name = "' . $config['schema_name'] . '"') or die($mapper->conn->my_error());
foreach ($shards as $shard_name => $shard) {
    if (!isset($coord_shard_name) || isset($coord_shard_name) && $shard_name == $coord_shard_name) {
        $coord_shard = 1;
    } else {
        $coord_shard = 0;
    }
    $mapper->add_shard($shard_name, $shard, $coord_shard, $accepts_new_rows = true, null, $config['schema_name']);
    if ($create_user) {
        $shard_admin = $shard;
        $shard_admin['user'] = $username;