function handle_get_request($data)
{
    global $allow_get;
    if (!$allow_get) {
        print 'Get off my lawn, you getter!';
        exit;
    }
    handle_data($data);
}
Example #2
0
/**
 *  Generate colorized (by clients CSS) table rows like popular file-merge programms. 
 *  @var: $old (string) after htmlspecialchars() function. Old version to compare
 *  @var: $new (string) after htmlspecialchars() function. New version to compare
 *
 *  @return: array[old_info, new_info], where old_info and new_info is array of lines array [line_number, action_code, text]
 */
function php_diff($old, $new)
{
    $diff = diff(explode(PHP_EOL, $old), explode(PHP_EOL, $new));
    $x = 0;
    $y = 0;
    // line counters
    $out_left = array();
    // array for left table column
    $out_right = array();
    // array for right table column
    foreach ($diff as $k) {
        if (is_array($k)) {
            // have difference
            $action = 0;
            if (!empty($k['d'])) {
                $action |= DELETED;
            }
            if (!empty($k['i'])) {
                $action |= ADDED;
            }
            if (!empty($k['d'])) {
                foreach ($k['d'] as $str) {
                    $out_left[] = handle_data($x++, $action, $str);
                }
            }
            if (!empty($k['i'])) {
                foreach ($k['i'] as $str) {
                    $out_right[] = handle_data($y++, $action, $str);
                }
            }
            // equalize arrays length
            while (count($out_left) < count($out_right)) {
                $out_left[] = handle_data(-1, EMPTIED, "");
            }
            while (count($out_right) < count($out_left)) {
                $out_right[] = handle_data(-1, EMPTIED, "");
            }
        } else {
            // no difference
            $out_left[] = handle_data($x++, EQUAL, $k);
            $out_right[] = handle_data($y++, EQUAL, $k);
        }
    }
    $out = array();
    $out[] = $out_left;
    $out[] = $out_right;
    return $out;
}
Example #3
0
function authenticate($items)
{
    global $exec_list;
    global $admin_data;
    global $admin_is_sock;
    global $admin_accounts;
    global $admin_aliases;
    global $operator_aliases;
    term_echo("detected cmd 330: {$admin_data}");
    $parts = explode(" ", $items["params"]);
    if ($admin_data != "") {
        if (count($parts) == 3 and $parts[0] == get_bot_nick()) {
            $nick = $parts[1];
            $account = $parts[2];
            $admin_items = parse_data($admin_data);
            $args = explode(" ", $admin_items["trailing"]);
            $alias = $args[0];
            if ($admin_items["nick"] == $nick) {
                if (is_operator_alias($alias) == True) {
                    if ($account != OPERATOR_ACCOUNT) {
                        term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized");
                    } else {
                        $tmp_data = $admin_data;
                        $tmp_is_sock = $admin_is_sock;
                        $admin_data = "";
                        $admin_is_sock = "";
                        handle_data($tmp_data, $tmp_is_sock, True);
                        return;
                    }
                } elseif (in_array($alias, $admin_aliases) == True) {
                    if ($account != OPERATOR_ACCOUNT and in_array($account, $admin_accounts) == False) {
                        term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized");
                    } else {
                        $tmp_data = $admin_data;
                        $tmp_is_sock = $admin_is_sock;
                        $admin_data = "";
                        $admin_is_sock = "";
                        handle_data($tmp_data, $tmp_is_sock, True);
                        return;
                    }
                } elseif (has_account_list($alias) == True) {
                    if ($account != OPERATOR_ACCOUNT and in_array($account, $exec_list[$alias]["accounts"]) == False and $exec_list[$alias]["accounts_wildcard"] != "*" and in_array($account, $admin_accounts) == False) {
                        term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized");
                    } else {
                        $tmp_data = $admin_data;
                        $tmp_is_sock = $admin_is_sock;
                        $admin_data = "";
                        $admin_is_sock = "";
                        handle_data($tmp_data, $tmp_is_sock, True);
                        return;
                    }
                }
            }
        }
    }
    $admin_data = "";
    $admin_is_sock = "";
}
Example #4
0
function rawmsg($msg, $obfuscate = False)
{
    global $socket;
    global $throttle_time;
    global $rawmsg_times;
    if ($throttle_time !== False) {
        $delta = microtime(True) - $throttle_time;
        if ($delta > THROTTLE_LOCKOUT_TIME) {
            $throttle_time = False;
        } else {
            term_echo("*** REFUSED OUTGOING MESSAGE DUE TO SERVER THROTTLING: {$msg}");
            return;
        }
    }
    $n = count($rawmsg_times);
    if ($n > 0) {
        $last = $rawmsg_times[$n - 1];
        $dt = microtime(True) - $last;
        if ($dt > THROTTLE_LOCKOUT_TIME) {
            $rawmsg_times = array();
        } else {
            if ($n >= RAWMSG_TIME_COUNT) {
                usleep(ANTI_FLOOD_DELAY * 1000000.0);
            }
        }
    }
    fputs($socket, $msg . "\n");
    $rawmsg_times[] = microtime(True);
    while (count($rawmsg_times) > RAWMSG_TIME_COUNT) {
        array_shift($rawmsg_times);
    }
    if ($obfuscate == False) {
        handle_data($msg . "\n", True, False, True);
    } else {
        term_echo("RAWMSG: (obfuscated)");
    }
}
Example #5
0
function get_charts($uid, $index, $index2, $actnum, $type, $userNum)
{
    //刻度
    $xscale = floor($actnum / 10);
    $filenames = array();
    $imgs = array();
    $x = get_act($uid, $index, $index2, $userNum);
    $datas = handle_data($type, $uid, $index, $xscale, $actnum, $x, $userNum);
    foreach ($index2 as $i2) {
        $ydata = $datas[$i2];
        $xdata = $datas['x'];
        //y轴自适应
        $yMax = max($ydata);
        $y = $yMax + 0.05;
        // 创建 Graph 类,350 为宽度,250 长度,auto:表示生成的缓存文件名是该文件的文件名+扩展名(.jpg .png .gif ……)
        $graph = new Graph(500, 250, "auto");
        // 设置刻度类型,x轴直线刻度,y轴为直线刻度
        $graph->SetScale("textlin", 0, $y);
        //设置x轴最小刻度
        $graph->xaxis->scale->ticks->Set($xscale);
        $graph->xaxis->SetTickLabels($xdata);
        //设置y轴最小刻度
        $graph->yaxis->scale->ticks->Set(0.05);
        //设置x轴文字
        $graph->xaxis->title->Set('top actid');
        // 创建坐标类,将y轴数据注入
        $lineplot = new BarPlot($ydata);
        // y 轴连线设定为蓝色
        $lineplot->SetColor("blue");
        // 坐标类注入图标类
        $graph->Add($lineplot);
        if (!is_array($uid)) {
            $filename = $index . '-' . $i2 . '-' . $uid;
        } else {
            $filename = $index . '-' . $i2;
        }
        $graph->title->Set($filename);
        $img = IMG_PATH . $filename . IMG_TYPE;
        $filenames[] = $filename;
        $imgs[] = $img;
        // 显示图
        $graph->Stroke($img);
    }
    return array('name' => $filenames);
}