Пример #1
0
function get_time($location)
{
    $location = trim($location);
    term_echo("*** TIME: http://www.google.com/search?gbv=1&q=time+" . urlencode($location));
    $html = wget_ssl("www.google.com.au", "/search?gbv=1&q=time+" . urlencode($location), ICEWEASEL_UA, "", 60);
    $html = strip_headers($html);
    $result = "";
    $delim1 = "<div id=\"ires\">";
    $delim2 = "</li>";
    $i = strpos($html, $delim1);
    if ($i !== False) {
        $html = substr($html, $i);
        $i = strpos($html, $delim2);
        if ($i !== False) {
            $html = trim(substr($html, 0, $i));
            $html = strip_tags($html);
            while (strpos($html, "  ") !== False) {
                $html = str_replace("  ", " ", $html);
            }
            if ($html != "" and strpos($html, "Time in") !== False) {
                $result = substr($html, 0, 300);
            }
        } else {
            term_echo("*** TIME: delim2 not found");
        }
    } else {
        term_echo("*** TIME: delim1 not found");
    }
    return $result;
}
Пример #2
0
function load_translations()
{
    if (file_exists(TRANSLATIONS_FILE) == False) {
        term_echo("*** TRANSLATIONS FILE NOT FOUND: " . TRANSLATIONS_FILE);
        return False;
    }
    $data = file_get_contents(TRANSLATIONS_FILE);
    if ($data === False) {
        term_echo("*** ERROR LOADING TRANSLATIONS FILE: " . TRANSLATIONS_FILE);
        return False;
    }
    $data = explode(PHP_EOL, trim($data));
    $translations = array();
    if (count($data) % 2 != 0) {
        term_echo("*** TRANSLATIONS FILE CONTAINS INVALID NUMBER OF LINES: " . TRANSLATIONS_FILE);
        return False;
    }
    for ($i = 0; $i < count($data); $i = $i + 2) {
        $key = trim($data[$i]);
        $value = trim($data[$i + 1]);
        if ($key == "" or $value == "") {
            term_echo("*** TRANSLATION NO. " . ($i + 1) . " CONTAINS EMPTY KEY OR VALUE: " . TRANSLATIONS_FILE);
            return False;
        }
        $translations[$key] = trim($value);
    }
    return $translations;
}
Пример #3
0
function sn_login()
{
    $agent = ICEWEASEL_UA;
    $host = "soylentnews.org";
    $uri = "/my/login";
    $port = 443;
    $params = array();
    $params["returnto"] = "";
    $params["op"] = "userlogin";
    $params["login_temp"] = "yes";
    #$params["unickname"]="exec";
    $params["unickname"] = "crutchy";
    #$params["upasswd"]=trim(file_get_contents("../pwd/exec"));
    $params["upasswd"] = trim(file_get_contents("../pwd/crutchy_sn"));
    $params["userlogin"] = "******";
    $response = wpost($host, $uri, $port, $agent, $params);
    $cookies = exec_get_cookies($response);
    # user=4468::4pVxvvp70xtWLTfclHBpBp; path=/; expires=Fri, 20-Jun-2014 10:28:58 GMT
    $login_cookie = "";
    $delim = "user="******"") {
        privmsg("error: login failure");
        sn_logout();
    }
    $parts = explode(";", $login_cookie);
    $cookie_user = trim($parts[0]);
    term_echo("*** SN USER COOKIE = \"{$cookie_user}\"");
    # << THERE SEEMS TO BE ABOUT A 30 MINUTE CYCLE TIME FOR COOKIE VALUES
    return $cookie_user;
}
Пример #4
0
function chart(&$log_data, $chan, $filename)
{
    $w = 1800;
    $h = 800;
    $nick_data = array();
    for ($i = 0; $i < count($log_data); $i++) {
        if ($log_data[$i]["dest"] != $chan) {
            continue;
        }
        $nick = $log_data[$i]["nick"];
        $nick_data[$nick][] = $log_data[$i];
    }
    $left_margin = 50;
    # pixels
    $min_y = -1;
    $max_y = count($nick_data) - 1;
    $min_x = $log_data[0]["timestamp"];
    $max_x = $log_data[count($log_data) - 1]["timestamp"];
    $dx = $max_x - $min_x;
    term_echo("*** dx = {$dx}");
    $dt = 1 / chart__ppu($w - $left_margin, $min_x, $max_x);
    # number of seconds per pixel
    term_echo("*** dt = {$dt}");
    $m = $dx / $dt;
    term_echo("*** m = {$m}");
    $chart_data = array();
    $y = 0;
    $max_lines_per_pixel = 0;
    foreach ($nick_data as $nick => $records) {
        for ($i = 0; $i < count($nick_data[$nick]); $i++) {
            $x = chart__r2p_x($w, $min_x, $max_x, $log_data[$i]["timestamp"]) + $left_margin;
            if (isset($chart_data[$nick][$x]) == True) {
                $chart_data[$nick][$x] = $chart_data[$nick][$x] + 1;
            } else {
                $chart_data[$nick][$x] = 1;
            }
            $max_lines_per_pixel = max($max_lines_per_pixel, $chart_data[$nick][$x]);
        }
    }
    $dl = $max_lines_per_pixel / 255;
    # number of lines per color gradient (decimal)
    # paint chart
    $buffer = imagecreatetruecolor($w, $h);
    $color_bg = imagecolorallocate($buffer, 255, 255, 255);
    imagefill($buffer, 0, 0, $color_bg);
    $y = 0;
    foreach ($chart_data as $nick => $data) {
        $y++;
        $py1 = chart__r2p_y($h, $min_y, $max_y, $y) + round(0.3 * chart__ppu($h, $min_y, $max_y));
        $py2 = chart__r2p_y($h, $min_y, $max_y, $y) - round(0.3 * chart__ppu($h, $min_y, $max_y));
        foreach ($chart_data[$nick] as $px => $intensity) {
            $color_x = imagecolorallocate($buffer, 0, 0, round($dl * $intensity));
            imageline($buffer, $px, $py1, $px, $py2, $color_x);
        }
    }
    #scale_img($buffer,0.5,$w,$h);
    imagepng($buffer, $filename . ".png");
    imagedestroy($buffer);
}
Пример #5
0
function chromas_log($alias, $trailing, $dest)
{
    $params = parse_parameters($trailing, "=", " ");
    if ($params !== False) {
        foreach ($params as $key => $value) {
            if (strpos($key, " ") !== False) {
                $params = False;
                break;
            }
        }
    }
    if ($params === False) {
        term_echo("chromas_log failed: invalid parameters");
        return False;
    }
    # chromas, 23 march 2015
    if (isset($params["until"]) == False) {
        date_default_timezone_set("UTC");
        $params["until"] = strftime("%F %T", time() - 5);
    }
    $paramstr = "";
    foreach ($params as $key => $value) {
        if ($paramstr != "") {
            $paramstr = $paramstr . "&";
        }
        $paramstr = $paramstr . urlencode($key) . "=" . urlencode($value);
    }
    if (isset($params["channel"]) == False) {
        $paramstr = $paramstr . "&channel=" . urlencode($dest);
    }
    if (isset($params["out"]) == False) {
        $paramstr = $paramstr . "&out=irc-full";
    }
    if ($alias == "~log") {
        $uri = "/s/soylent_log.php?" . $paramstr;
    } else {
        $uri = "/s/soylent_log.php?op=" . $alias . "&" . $paramstr;
    }
    if (get_bucket("chromas_irc_log_debug") == "on") {
        pm("chromas", "http://chromas.0x.no" . $uri);
        pm("crutchy", "http://chromas.0x.no" . $uri);
    }
    $response = wget("chromas.0x.no", $uri, 80, ICEWEASEL_UA, "", 10, "", 1024, False);
    $html = trim(strip_headers($response));
    if ($html == "") {
        pm("#", "chromas_log failed: no response");
        return False;
    }
    $lines = explode("\n", trim($html));
    return $lines;
}
Пример #6
0
function handle_privmsg($parts, &$channel_data)
{
    if (count($parts) < 3) {
        return;
    }
    # trailing = <nick> <channel> <trailing>
    $nick = strtolower($parts[0]);
    $channel = strtolower($parts[1]);
    array_shift($parts);
    array_shift($parts);
    $trailing = trim(implode(" ", $parts));
    term_echo("*** activity: nick={$nick}, channel={$channel}, trailing={$trailing}");
    nick_follow($nick, $channel, $trailing);
    minion_talk($nick, $channel, $trailing);
}
Пример #7
0
function scale_img(&$buffer, $scale, $w, $h)
{
    $final_w = round($w * $scale);
    $final_h = round($h * $scale);
    $buffer_resized = imagecreatetruecolor($final_w, $final_h);
    if (imagecopyresampled($buffer_resized, $buffer, 0, 0, 0, 0, $final_w, $final_h, $w, $h) == False) {
        term_echo("imagecopyresampled error");
        return False;
    }
    imagedestroy($buffer);
    $buffer = imagecreate($final_w, $final_h);
    if (imagecopy($buffer, $buffer_resized, 0, 0, 0, 0, $final_w, $final_h) == False) {
        term_echo("imagecopy error");
        return False;
    }
    imagedestroy($buffer_resized);
}
Пример #8
0
function load_directory($dir, &$lines, $directive)
{
    if (file_exists($dir) == True and is_dir($dir) == True) {
        term_echo("load_directory: \"{$dir}\" found");
        $handle = opendir($dir);
        while (($file = readdir($handle)) !== False) {
            if ($file == "." or $file == "..") {
                continue;
            }
            $fullname = $dir . "/" . $file;
            if (is_dir($fullname) == True) {
                load_directory($fullname, $lines, $directive);
            } else {
                load_include($fullname, $lines, $directive);
            }
        }
        closedir($handle);
    } else {
        term_echo("load_directory: \"{$dir}\" not found");
    }
}
Пример #9
0
function shell_sed($trailing, $nick, $dest)
{
    # [nick[:|,|>|.] ]sed_cmd
    global $delims;
    $trailing = trim($trailing);
    if (trim($trailing) == "") {
        return False;
    }
    if (strtolower(substr($trailing, strlen($trailing) - 2)) == "/e") {
        die;
    }
    $parts = explode(" ", $trailing);
    $sed_nick = "";
    if (count($parts) > 1) {
        $break = False;
        for ($i = 0; $i < count($delims); $i++) {
            if (strpos($parts[0], $delims[$i]) == True) {
                $break = True;
                break;
            }
        }
        if ($break == False) {
            $sed_nick = $parts[0];
            if (strpos(":,>.", substr($sed_nick, strlen($sed_nick) - 1)) !== False) {
                $sed_nick = substr($sed_nick, 0, strlen($sed_nick) - 1);
            }
            array_shift($parts);
        }
    }
    if ($sed_nick == "") {
        $sed_nick = $nick;
    }
    $sed_cmd = implode(" ", $parts);
    if (strlen($sed_cmd) < 5) {
        return False;
    }
    if (strtolower($sed_cmd[0]) != "s") {
        return False;
    }
    if (in_array($sed_cmd[1], $delims) == False) {
        return False;
    }
    $index = "last_" . strtolower($sed_nick) . "_" . strtolower($dest);
    $last = get_bucket($index);
    if ($last == "") {
        return False;
    }
    $action_delim = chr(1) . "ACTION ";
    if (strtoupper(substr($last, 0, strlen($action_delim))) == $action_delim) {
        $last = trim(substr($last, strlen($action_delim)), chr(1));
    }
    #$command="echo ".escapeshellarg($last)." | sed -e --posix ".escapeshellarg($sed_cmd);
    $command = "echo " . escapeshellarg($last) . " | sed -e " . escapeshellarg($sed_cmd);
    var_dump($command);
    $cwd = NULL;
    $env = NULL;
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $process = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
    $result = trim(stream_get_contents($pipes[1]));
    $result_lines = explode("\n", $result);
    var_dump($result_lines);
    if (count($result_lines) > 1) {
        return False;
    }
    fclose($pipes[1]);
    $stderr = trim(stream_get_contents($pipes[2]));
    fclose($pipes[2]);
    proc_close($process);
    if ($stderr != "") {
        term_echo($stderr);
        return True;
    }
    if ($result == $last or $result == $sed_cmd) {
        $result = "";
    }
    if ($result != "") {
        if ($nick == $sed_nick) {
            privmsg("<{$sed_nick}> {$result}");
        } else {
            privmsg("<{$nick}> <{$sed_nick}> {$result}");
        }
    }
    return True;
}
Пример #10
0
function set_array_bucket($array, $bucket, $unset = True)
{
    $bucket_data = serialize($array);
    if ($bucket_data === False) {
        term_echo("error serializing \"{$bucket}\" bucket");
    } else {
        if ($unset == True) {
            unset_bucket($bucket);
        }
        set_bucket($bucket, $bucket_data);
    }
}
Пример #11
0
<?php

#####################################################################################################
/*
exec:~wget|20|0|0|1|||||php scripts/wget.php %%trailing%%
*/
#####################################################################################################
require_once "lib.php";
require_once "wget_lib.php";
$trailing = trim($argv[1]);
term_echo("wget: {$trailing}");
if ($trailing == "") {
    privmsg("syntax: ~wget url delim 1 <> delim 2");
    return;
}
$result = quick_wget($trailing);
if ($result == False) {
    privmsg("syntax: ~wget url delim 1 <> delim 2");
    return;
}
if (strlen($result) > 300) {
    $result = trim(substr($result, 0, 300)) . "...";
}
privmsg(chr(3) . "07" . $result);
#####################################################################################################
Пример #12
0
function wiki_privmsg($return, $msg)
{
    if ($return == False) {
        privmsg(chr(3) . "13" . $msg);
    } else {
        term_echo(chr(3) . "13" . $msg);
    }
}
Пример #13
0
function run_event_registration_test()
{
    global $passed;
    unset_bucket(TEST_BUCKET);
    $bucket_index = "<<EXEC_EVENT_HANDLERS>>";
    $test_cmd = "PRIVMSG";
    $test_data = ":%%nick%% INTERNAL %%dest%% :~event-test %%trailing%%";
    $data1 = get_bucket($bucket_index);
    if (check_handler($bucket_index, $test_cmd, $test_data) == True) {
        term_echo("run_event_registration_test failed! (1)");
        $passed = False;
    }
    register_event_handler($test_cmd, $test_data);
    if (check_handler($bucket_index, $test_cmd, $test_data) == False) {
        term_echo("run_event_registration_test failed! (2)");
        $passed = False;
    }
    set_bucket("<<SELF_TRIGGER_EVENTS_FLAG>>", "1");
    privmsg("event test message");
    sleep(2);
    $test = get_bucket(TEST_BUCKET);
    term_echo("*** TEST BUCKET => {$test}");
    if ($test != TEST_VALUE) {
        term_echo("run_event_registration_test failed! (3)");
        $passed = False;
    }
    unset_bucket(TEST_BUCKET);
    unset_bucket("<<SELF_TRIGGER_EVENTS_FLAG>>");
    delete_event_handler($test_cmd, $test_data);
    sleep(2);
    if (check_handler($bucket_index, $test_cmd, $test_data) == True) {
        term_echo("run_event_registration_test failed! (4)");
        $passed = False;
    }
    $data2 = get_bucket($bucket_index);
    if ($data1 != $data2) {
        term_echo("run_event_registration_test failed! (5)");
        $passed = False;
    }
}
Пример #14
0
function load_translations()
{
    if (file_exists(TRANSLATIONS_FILE) == False) {
        term_echo("*** TRANSLATIONS FILE NOT FOUND: " . TRANSLATIONS_FILE);
        return False;
    }
    $data = file_get_contents(TRANSLATIONS_FILE);
    if ($data === False) {
        term_echo("*** ERROR LOADING TRANSLATIONS FILE: " . TRANSLATIONS_FILE);
        return False;
    }
    $data = explode("\n", $data);
    $translations = "";
    for ($i = 0; $i < count($data); $i++) {
        $line = trim($data[$i]);
        if ($line == "") {
            continue;
        }
        $parts = explode(">>", $line);
        if (count($parts) < 2) {
            term_echo("*** INVALID TRANSLATION: " . $line);
            return False;
        }
        $translations[trim($parts[0])] = trim($parts[1]);
    }
    return $translations;
}
Пример #15
0
$url = get_redirected_url($trailing);
if ($url === False) {
    privmsg("error: unable to download source (get_redirected_url)");
    return;
}
$host = "";
$uri = "";
$port = 80;
if (get_host_and_uri($url, $host, $uri, $port) == False) {
    privmsg("error: unable to download source (get_host_and_uri)");
    return;
}
$response = wget($host, $uri, $port);
$source_html = strip_headers($response);
$source_title = extract_raw_tag($source_html, "title");
term_echo($source_title);
$i = strpos($source_title, "--");
if ($i !== False) {
    $source_title = trim(substr($source_title, 0, $i));
}
$i = strpos($source_title, "|");
if ($i !== False) {
    $source_title = trim(substr($source_title, 0, $i));
}
$i = strpos($source_title, " - ");
if ($i !== False) {
    $source_title = trim(substr($source_title, 0, $i));
}
$i = strpos($source_title, " : ");
if ($i !== False) {
    $source_title = trim(substr($source_title, 0, $i));
Пример #16
0
function source_define($host, $term, $params)
{
    global $debug;
    $sterm = $term;
    if ($params["space_delim"] != "") {
        $sterm = str_replace(" ", $params["space_delim"], $sterm);
    }
    $uri = str_replace($params["template"], urlencode($sterm), $params["uri"]);
    term_echo("*** DEFINE: trying {$host}{$uri} on port " . $params["port"]);
    $response = wget($host, $uri, $params["port"], ICEWEASEL_UA, "", 20);
    $html = strip_headers($response);
    $html = replace_ctrl_chars($html, " ");
    strip_all_tag($html, "head");
    strip_all_tag($html, "script");
    if ($debug == "ON") {
        privmsg("debug [{$host}]: uri = \"{$uri}\"");
        $L = strlen($html);
        privmsg("debug [{$host}]: html length = \"{$L}\"");
        unset($L);
        privmsg("debug [{$host}]: delim_start = \"" . $params["delim_start"] . "\"");
        privmsg("debug [{$host}]: delim_end = " . $params["delim_end"] . "\"");
    }
    $i = strpos($html, $params["delim_start"]);
    $def = "";
    if ($i !== False) {
        if ($debug == "ON") {
            privmsg("debug [{$host}]: delim_start pos = \"{$i}\"");
        }
        $html = substr($html, $i + strlen($params["delim_start"]));
        $i = strpos($html, $params["delim_end"]);
        if ($i !== False) {
            if ($debug == "ON") {
                privmsg("debug [{$host}]: delim_end pos = \"{$i}\"");
            }
            $def = trim(strip_tags(substr($html, 0, $i)));
            $def = str_replace(array("\n", "\r"), " ", $def);
            $def = str_replace("  ", " ", $def);
            if (strlen($def) > MAX_DEF_LENGTH) {
                $def = trim(substr($def, 0, MAX_DEF_LENGTH)) . "...";
            }
        }
    }
    if ($def == "") {
        $location = exec_get_header($response, "location");
        if ($location == "") {
            return False;
        } else {
            $new_term = extract_text($location, $params["get_param"], "&", True);
            if ($new_term != $term) {
                term_echo("redirecting to \"{$location}\"");
                if ($debug == "ON") {
                    privmsg("debug [{$host}]: redirecting to \"{$location}\"");
                }
                return source_define($host, $new_term, $params);
            } else {
                return False;
            }
        }
    } else {
        if ($params["ignore"] != "" and strpos($def, $params["ignore"]) !== False) {
            return False;
        }
        if (strpos($def, "There aren't any definitions") !== False) {
            return False;
        }
        privmsg("[" . $params["name"] . "] " . chr(3) . "03{$term}" . chr(3) . ": " . html_decode($def));
        return True;
    }
}
Пример #17
0
$count_new = 0;
$count_top = 0;
for ($i = 0; $i < $item_count; $i++) {
    if (isset($items[$i]) == False) {
        continue;
    }
    sleep(5);
    $story_url = $items[$i]["url"] . "&threshold=-1&highlightthresh=-1&mode=flat&commentsort=0";
    $title = $items[$i]["title"];
    $title_output = chr(3) . "06" . $title . chr(3);
    $host = "";
    $uri = "";
    $port = "";
    if (get_host_and_uri($story_url, $host, $uri, $port) == True) {
        $k = $i + 1;
        term_echo("[{$k}/{$item_count}] {$story_url}");
        $response = wget($host, $uri, $port, ICEWEASEL_UA, "", 60);
        $html = strip_headers($response);
        $sid = extract_text($html, "<input type=\"hidden\" name=\"sid\" value=\"", "\">");
        if ($sid === False) {
            continue;
        }
        $parts = explode("<div id=\"comment_top_", $html);
        array_shift($parts);
        for ($j = 0; $j < count($parts); $j++) {
            sleep(1);
            $n = strpos($parts[$j], "\"");
            if ($n === False) {
                continue;
            }
            $cid = substr($parts[$j], 0, $n);
Пример #18
0
    output("error: journal list not found");
    return;
}
$rows = explode("<tr>", $html);
array_shift($rows);
array_shift($rows);
$item_count = 20;
for ($i = 0; $i < max($item_count, count($rows)); $i++) {
    $cells = explode("<td valign=\"top\">", $rows[$i]);
    if (count($cells) != 4) {
        term_echo("*** SN JOURNAL FEED: invalid number of cells for row {$i}");
        continue;
    }
    # TODO: DEBUG HERE
    $id = substr($cells[2], 0, strpos($cells[2], "<"));
    term_echo("*** SN JOURNAL FEED: row {$i} id = {$id} => " . $cells[2]);
}
/*$ids=array();

term_echo("*** comment_feed: $item_count feed stories to check");

$count_new=0;

for ($i=0;$i<$item_count;$i++)
{
  if (isset($items[$i])==False)
  {
    continue;
  }
  sleep(5);
  $url=$items[$i]["url"]."&threshold=-1&highlightthresh=-1&mode=flat&commentsort=0";
Пример #19
0
function meeting_privmsg()
{
    global $parts;
    global $meeting_data;
    global $board_member_accounts;
    global $options_yes;
    global $options_no;
    if (count($parts) < 3) {
        term_echo("meeting: invalid number of trailing parts");
        return;
    }
    # trailing = <nick> <channel> <trailing>
    $nick = strtolower($parts[0]);
    $channel = strtolower($parts[1]);
    array_shift($parts);
    array_shift($parts);
    $trailing = trim(implode(" ", $parts));
    term_echo("meeting_privmsg: nick={$nick}, channel={$channel}, trailing={$trailing}");
    $meeting_data = get_array_bucket("MEETING_DATA_" . $channel);
    if (isset($meeting_data["description"]) == False) {
        term_echo("meeting: no meeting open");
        return;
    }
    $data = array();
    $data["nick"] = $nick;
    $data["timestamp"] = microtime(True);
    $data["trailing"] = $trailing;
    $meeting_data["messages"][] = $data;
    $test = strtolower($trailing);
    if (in_array($test, $options_yes) == True or in_array($test, $options_no) == True) {
        $account = users_get_account($nick);
        if (in_array($account, $board_member_accounts) == False) {
            meeting_event_msg($channel, "{$nick} is not an authenticated board member. vote not counted");
        }
        $n = count($meeting_data["motions"]);
        if ($n == 0) {
            meeting_event_msg($channel, "no motions registered. vote not counted");
        } else {
            $motion =& $meeting_data["motions"][$n - 1];
            $vote_yes = array_search($account, $motion["votes"]["yes"]);
            $vote_no = array_search($account, $motion["votes"]["no"]);
            if ($vote_yes !== False) {
                unset($motion["votes"]["yes"][$vote_yes]);
                $motion["votes"]["yes"] = array_values($motion["votes"]["yes"]);
            }
            if ($vote_no !== False) {
                unset($motion["votes"]["no"][$vote_no]);
                $motion["votes"]["no"] = array_values($motion["votes"]["no"]);
            }
            if ($vote_yes !== False or $vote_no !== False) {
                meeting_event_msg($channel, "vote by {$nick} [{$account}] for current motion already registered. previous vote deleted");
            }
            if (in_array($test, $options_yes) == True) {
                $motion["votes"]["yes"][] = $account;
                meeting_event_msg($channel, "'aye' vote registered for {$nick} [{$account}] for current motion");
            } else {
                $motion["votes"]["no"][] = $account;
                meeting_event_msg($channel, "'nay' vote registered for {$nick} [{$account}] for current motion");
            }
        }
    }
}
Пример #20
0
function fetch_prepare($sql, $params)
{
    global $pdo;
    $statement = $pdo->prepare($sql);
    if ($statement === False) {
        term_echo("SQL PREPARE ERROR\n\n{$sql}\n");
        return False;
    }
    foreach ($params as $key => $value) {
        if (ctype_digit(strval($value)) == True) {
            $err = $statement->bindParam(":{$key}", $params[$key], PDO::PARAM_INT);
        } else {
            $err = $statement->bindParam(":{$key}", $params[$key], PDO::PARAM_STR);
        }
        if ($err == False) {
            $err = $statement->errorInfo();
            if ($err[0] != Null) {
                echo $err[2] . "\n";
            }
            term_echo("SQL BINDVALUE ERROR\n\n{$sql}\n");
            return False;
        }
    }
    if ($statement->execute() === False) {
        $err = $statement->errorInfo();
        if ($err[0] != Null) {
            echo $err[2] . "\n";
        }
        term_echo("SQL EXECUTE ERROR\n\n{$sql}\n");
        return False;
    }
    return $statement->fetchAll(PDO::FETCH_ASSOC);
}
Пример #21
0
#exec:~nethack|15|20|0|1|||||php scripts/nethack.php %%trailing%% %%dest%% %%nick%%
#startup:~join #nethack
*/
#####################################################################################################
require_once "lib.php";
$trailing = $argv[1];
$dest = $argv[2];
$nick = $argv[3];
$fn = DATA_PATH . "nethack_ncommander";
$old = "";
if (file_exists($fn) == True) {
    $old = trim(file_get_contents($fn));
}
$host = "alt.org";
$port = 80;
$uri = "/nethack/player-endings.php?player=NCommander";
$response = wget($host, $uri, $port);
$html = strip_headers($response);
$cells = explode("<TR", $html);
$last = array_shift(explode("</TR>", array_pop($cells)));
$last = str_replace("</TD>", " ", $last);
$last = strip_tags($last);
$last = array_pop(explode(">", $last));
$last = clean_text($last);
if ($last != $old) {
    pm("#Soylent", "NCommander was killed: " . $last);
    file_put_contents($fn, $last);
} else {
    term_echo("NETHACK >>> {$last}");
}
#####################################################################################################
Пример #22
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)");
    }
}
Пример #23
0
     if ($amount !== False) {
         $data = exec_file_read("previous_sn_funding");
         $previous = "";
         if (count($data) > 0) {
             $previous = trim($data[0]);
         } else {
             term_echo("funding: count(data) = 0");
         }
         if ($previous != $amount) {
             pm("#soylent", chr(3) . "05" . "*** SN funding has changed from \${$previous} to \${$amount}");
             exec_file_write("previous_sn_funding", array($amount));
         } else {
             term_echo("funding: previous = amount ({$amount})");
         }
     } else {
         term_echo("funding: amount not found in http response");
     }
     sn_logout();
     return;
 case "~verifier-nick-change":
     $parts = explode(" ", $trailing);
     if (count($parts) == 2) {
         $old_nick = trim(strtolower($parts[0]));
         $new_nick = trim(strtolower($parts[1]));
         $registered_nick = get_bucket(BUCKET_VERIFIER_NICK);
         if ($old_nick == $registered_nick) {
             set_bucket(BUCKET_VERIFIER_NICK, $new_nick);
             pm("#", "SN status verifier nick updated from \"{$registered_nick}\" to \"{$new_nick}\"");
         }
     }
     return;
Пример #24
0
function handle_bot_data($data, $bot_nick)
{
    $items = parse_data($data);
    if ($items !== False) {
        term_echo("MINION_CMD_{$bot_nick} bucket set");
        set_bucket("MINION_CMD_{$bot_nick}", $data);
    } else {
        term_echo("invalid command \"{$data}\"");
    }
}
Пример #25
0
switch ($trailing) {
    case "meeting":
        $response = wget("soylentnews.org", "/");
        $delim1 = "<!-- begin site_news block -->";
        $delim2 = "<!-- end site_news block -->";
        $max_len = 300;
        $text = extract_text($response, $delim1, $delim2);
        $parts = explode("<hr>", $text);
        $result = "";
        for ($i = 0; $i < count($parts); $i++) {
            if (strpos(strtolower($parts[$i]), "meeting") !== False) {
                $result = $parts[$i];
            }
        }
        if ($result != "") {
            term_echo($result);
            $result = strip_tags($result);
            $result = replace_ctrl_chars($result, " ");
            $result = str_replace("  ", " ", $result);
            if (strlen($result) > $max_len) {
                $result = trim(substr($result, 0, $max_len)) . "...";
            }
        } else {
            require_once "wiki_lib.php";
            $title = "Issues to Be Raised at the Next Board Meeting";
            $section = "Next meeting";
            $result = get_text($title, $section, True);
            var_dump($result);
            if (is_array($result) == True) {
                $result = trim(implode(" ", $text));
            }
Пример #26
0
require_once "lib.php";
date_default_timezone_set("UTC");
$trailing = $argv[1];
$dest = $argv[2];
$nick = $argv[3];
if ($dest != "#sylnt" or $nick != "crutchy") {
    return;
}
#$password=trim(file_get_contents("../pwd/server"));
$password = "******";
$SID = "44X";
$server_name = "192.168.1.22";
$server_description = "jared's lappy";
$socket = fsockopen("192.168.1.55", 6667);
if ($socket === False) {
    term_echo("SERVER: ERROR OPENING SOCKET CONNECTION");
    return;
} else {
    stream_set_blocking($socket, 0);
    fputs($socket, "PASS {$password} TS 6 :{$SID}\n");
    # https://github.com/atheme/charybdis/blob/master/doc/technical/capab.txt
    #fputs($socket,"CAPAB :QS ENCAP EX CHW IE KNOCK SAVE EUID SERVICES RSFNC KLN UNKLN TB EOPMOD MLOCK\n");
    fputs($socket, "CAPAB :TB\n");
    fputs($socket, "SERVER {$server_name} 1 :{$server_description}\n");
    fputs($socket, "SVINFO 6 6 0 " . time() . "\n");
}
while (True) {
    $data = fgets($socket);
    echo $data;
    usleep(10000.0);
    # 0.01 second to prevent cpu flogging
Пример #27
0
            privmsg("location \"{$trailing}\" deleted");
        } else {
            if (trim($trailing) != "") {
                privmsg("location for \"{$trailing}\" not found");
            } else {
                privmsg("syntax: ~time-del <name>");
            }
        }
        break;
    case "~time":
        $loc = get_location($trailing, $nick);
        if ($loc === False) {
            if ($trailing == "") {
                privmsg("syntax: ~time location");
                privmsg("time data courtesy of Google");
                return;
            }
            $loc = $trailing;
        }
        term_echo("*** TIME LOCATION: {$loc}");
        $result = get_time($loc);
        if ($result != "") {
            $arr = convert_google_location_time($result);
            #privmsg($result);
            privmsg(date("l, j F Y @ g:i a", $arr["timestamp"]) . " " . $arr["timezone"] . " - " . $arr["location"]);
        } else {
            privmsg("location not found - UTC timestamp: " . date("l, j F Y, g:i a"));
        }
        break;
}
#####################################################################################################
Пример #28
0
function wpost($host, $uri, $port, $agent = ICEWEASEL_UA, $params, $extra_headers = "", $timeout = 20, $params_str = False, $dump_request = False)
{
    if (check_url($host . $uri) == False) {
        return "";
    }
    $errno = 0;
    $errstr = "";
    if ($port == 443) {
        $fp = @fsockopen("ssl://{$host}", 443, $errno, $errstr, $timeout);
    } else {
        $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
    }
    if ($fp === False) {
        term_echo("Error connecting to \"{$host}\".");
        return;
    }
    if ($params_str == False) {
        $content = "";
        foreach ($params as $key => $value) {
            if ($content != "") {
                $content = $content . "&";
            }
            $content = $content . $key . "=" . rawurlencode($value);
        }
    } else {
        $content = $params;
    }
    $headers = "POST {$uri} HTTP/1.0\r\n";
    $headers = $headers . "Host: {$host}\r\n";
    $headers = $headers . "User-Agent: {$agent}\r\n";
    $headers = $headers . "Content-Type: application/x-www-form-urlencoded\r\n";
    $headers = $headers . "Content-Length: " . strlen($content) . "\r\n";
    if ($extra_headers != "") {
        foreach ($extra_headers as $key => $value) {
            $headers = $headers . $key . ": " . $value . "\r\n";
        }
    }
    $headers = $headers . "Connection: Close\r\n\r\n";
    $request = $headers . $content;
    if ($dump_request == True) {
        var_dump($request);
    }
    fwrite($fp, $request);
    $response = "";
    while (!feof($fp)) {
        $response = $response . fgets($fp, 1024);
    }
    fclose($fp);
    return $response;
}
Пример #29
0
function parse_xml($html)
{
    $parts = explode("<story", $html);
    array_shift($parts);
    $items = array();
    for ($i = 0; $i < count($parts); $i++) {
        $item = array();
        $item["type"] = "xml_story";
        $item["title"] = extract_raw_tag($parts[$i], "title");
        $item["title"] = html_decode($item["title"]);
        $item["title"] = html_decode($item["title"]);
        $item["title"] = replace_ctrl_chars($item["title"], " ");
        $item["title"] = str_replace("  ", " ", $item["title"]);
        $url = str_replace("&amp;", "&", strip_ctrl_chars(extract_raw_tag($parts[$i], "url")));
        term_echo("*** raw story url: " . $url);
        $item["url"] = get_redirected_url($url);
        $item["timestamp"] = time();
        if ($item["title"] === False or $item["url"] === False) {
            continue;
        }
        $items[] = $item;
    }
    return $items;
}
Пример #30
0
 case "export":
     break;
 case "global":
     if ($trailing == "on" or $trailing == "off") {
         if ($trailing == "on") {
             set_bucket("LIVE_SCRIPT_GLOBAL_EXECUTE", "enabled");
             privmsg("live script global exec flag set");
         } else {
             unset_bucket("LIVE_SCRIPT_GLOBAL_EXECUTE");
             privmsg("live script global exec flag cleared");
         }
     }
     break;
 case "kill":
     unset_bucket("LIVE_SCRIPT_GLOBAL_EXECUTE");
     term_echo("*** LIVE SCRIPTING KILLED: live script global exec flag cleared with kill command");
     break;
 case "enable":
     if ($trailing == "") {
         privmsg("error: script name not specified");
         break;
     }
     if (isset($scripts[$trailing]) == False) {
         privmsg("error: script named \"{$trailing}\" not found");
         break;
     }
     $scripts[$trailing]["enabled"] = True;
     $data_changed = True;
     privmsg("script \"{$trailing}\" enabled");
     break;
 case "disable":