Esempio n. 1
0
        $connection->close();
        p("A client timeout logging in. ( IP = {$connection->IP} )");
    });
    p("A new client has joined. ( IP = {$connection->IP} )");
};
$worker_tasker->onMessage = function ($connection, $data) {
    $data = json_decode($data, True);
    if ($connection->IP == '127.0.0.1' && isset($data['pass'], $data['task']) && $data['pass'] == sha1(DB_PASS)) {
        if (!isset($data['task']['action'])) {
            $solution = new Solution($data['task']);
            $solution->push();
            return;
        } else {
            switch ($data['task']['action']) {
                case 'kill':
                    kill_client($data['task']['cid']);
                    break;
            }
        }
    }
    if ($data == NULL || !isset($data['action'])) {
        p("Json decoding failed or in bad format. ( cid = {$connection->cid}, IP = {$connection->IP} )");
        return;
    }
    switch ($data['action']) {
        case 'heartbeat':
            // 评测端信息更新
            heartbeat($connection, $data);
            break;
        case 'update_state':
            // 评测中更新状态
Esempio n. 2
0
<?php

/*        Copyright (C) 2013-2014 Electric Sheep Fencing, LP */
$nocsrf = true;
require_once "guiconfig.inc";
require_once "openvpn.inc";
/* Handle AJAX */
if ($_GET['action']) {
    if ($_GET['action'] == "kill") {
        $port = $_GET['port'];
        $remipp = $_GET['remipp'];
        if (!empty($port) and !empty($remipp)) {
            $retval = kill_client($port, $remipp);
            echo htmlentities("|{$port}|{$remipp}|{$retval}|");
        } else {
            echo gettext("invalid input");
        }
        exit;
    }
}
function kill_client($port, $remipp)
{
    global $g;
    //$tcpsrv = "tcp://127.0.0.1:{$port}";
    $tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
    $errval;
    $errstr;
    /* open a tcp connection to the management port of each server */
    $fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
    $killed = -1;
    if ($fp) {
Esempio n. 3
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;
    }
}