function get_raw_title($redirect_data) { $rd_url = $redirect_data["url"]; $rd_cookies = $redirect_data["cookies"]; $rd_extra_headers = $redirect_data["extra_headers"]; $host = ""; $uri = ""; $port = 80; if (get_host_and_uri($rd_url, $host, $uri, $port) == False) { term_echo("get_host_and_uri=false"); return False; } $breakcode = "return ((strpos(strtolower(\$response),\"</title>\")!==False) or (strlen(\$response)>=10000));"; #$breakcode=""; $response = wget($host, $uri, $port, ICEWEASEL_UA, $rd_extra_headers, 20, $breakcode, 256); #var_dump($response); $html = strip_headers($response); $title = extract_raw_tag($html, "title"); $title = html_decode($title); $title = trim(html_decode($title)); if ($title == "") { term_echo(" get_raw_title: title is empty"); return False; } return $title; }
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; }
function translate($lang_from, $lang_to, $msg) { $html = wget_ssl("translate.google.com", "/?sl=" . urlencode($lang_from) . "&tl=" . urlencode($lang_to) . "&js=n&ie=UTF-8&text=" . urlencode($msg)); $html = strip_headers($html); if ($html === False) { return ""; } strip_all_tag($html, "head"); strip_all_tag($html, "style"); strip_all_tag($html, "a"); $html = strip_tags($html, "<div>"); $delim1 = "TRANSLATED_TEXT='"; $delim2 = "';"; $i = strpos($html, $delim1) + strlen($delim1); if ($i === False) { return ""; } $html = substr($html, $i); $i = strpos($html, $delim2); if ($i === False) { return ""; } $result = trim(substr($html, 0, $i)); $result = str_replace("\\x26", "&", $result); $result = html_decode($result); $result = html_decode($result); return $result; }
function get_api_data($uri) { $host = "bitbucket.org"; $port = 443; $headers = ""; $response = wget($host, $uri, $port, ICEWEASEL_UA, $headers, 60); $content = strip_headers($response); return json_decode($content, True); }
function copyright_check_url($html, $anchor_url) { $host = ""; $uri = ""; $port = ""; if (get_host_and_uri($anchor_url, $host, $uri, $port) == True) { $response = wget($host, $uri, $port, ICEWEASEL_UA, "", 60); $anchor_html = strip_headers($response); #<crutchy> cull spaces and special chars, lowercase all, strip tags, css etc and compare #<crutchy> have some kind of arbitrary string length (or maybe %) that causes trigger } return True; }
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; }
function google_search($query) { $response = wget_ssl("www.google.com.au", "/search?source=hp&q=" . urlencode($query)); $html = strip_headers($response); strip_all_tag($html, "head"); strip_all_tag($html, "script"); strip_all_tag($html, "style"); $results = explode("<cite class=\"_Rm\">", $html); array_shift($results); if (count($results) == 0) { return False; } for ($i = 0; $i < count($results); $i++) { $results[$i] = explode("</cite>", $results[$i])[0]; $results[$i] = strip_tags($results[$i]); } return $results; }
function shorten_url($url, $mode = "title") { if ($url == "") { return False; } $params = array(); $params["url"] = $url; if ($mode != "") { $params["mode"] = $mode; # optional } $response = wpost("o.my.to", "/", "80", ICEWEASEL_UA, $params, "", 30); $short_url = trim(strip_headers($response)); if ($short_url != "") { return $short_url; } else { return False; } }
function youtube_search($query) { $agent = ICEWEASEL_UA; $host = "www.youtube.com"; $uri = "/results"; $port = 443; $params = array(); $params["search_query"] = $query; $response = wpost($host, $uri, $port, $agent, $params); $html = strip_headers($response); strip_all_tag($html, "head"); strip_all_tag($html, "script"); strip_all_tag($html, "style"); $delim1 = "class=\"item-section\">"; $delim2 = "</ol>"; $html = extract_text_nofalse($html, $delim1, $delim2); $results = explode("<li><div class=\"yt-lockup yt-lockup-tile yt-lockup-video vve-check clearfix yt-uix-tile\"", $html); array_shift($results); if (count($results) == 0) { return False; } for ($i = 0; $i < count($results); $i++) { $parts = explode(">", $results[$i]); array_shift($parts); $results[$i] = implode(">", $parts); $delim1 = "<h3 class=\"yt-lockup-title \">"; $delim2 = "</h3>"; $results[$i] = extract_text_nofalse($results[$i], $delim1, $delim2); $delim1 = "<a href=\""; $delim2 = "\" "; $url = "https://www.youtube.com" . extract_text_nofalse($results[$i], $delim1, $delim2); $delim1 = "dir=\"ltr\">"; $delim2 = "</a>"; $title = extract_text_nofalse($results[$i], $delim1, $delim2); $title = html_decode($title); $title = html_decode($title); $delim1 = "> - Duration: "; $delim2 = ".</span>"; $time = extract_text_nofalse($results[$i], $delim1, $delim2); $results[$i] = $url . " - " . $title . " - " . $time; } return $results; }
function process_weather(&$location, $nick, $getdata = False) { $loc = get_location($location, $nick); term_echo("*** WEATHER LOCATION LOOKUP: {$loc}"); if ($loc === False) { if ($location == "") { return False; } $loc = $location; } $location = $loc; $loc_query = filter($loc, VALID_UPPERCASE . VALID_LOWERCASE . VALID_NUMERIC . " "); $prefs = get_prefs($nick); $fheit = "1"; $use_unit_pref = False; if (isset($prefs["unit"]) == True and $getdata == False) { if ($prefs["unit"] == "metric") { $use_unit_pref = True; $fheit = "0"; } if ($prefs["unit"] == "imperial") { $use_unit_pref = True; } } # https://www.google.com/search?gbv=1&q=weather+traralgon $url = "http://www.google.com.au/search?gbv=1&fheit={$fheit}&q=weather+" . urlencode($loc_query); term_echo($url); $response = wget("www.google.com.au", "/search?gbv=1&fheit={$fheit}&q=weather+" . urlencode($loc_query), 80, ICEWEASEL_UA, "", 60); $html = strip_headers($response); $delim1 = "<div class=\"e\">"; $delim2 = "</table>"; $html = extract_text($html, $delim1, $delim2); if ($html === False) { return False; } $html = replace_ctrl_chars($html, " "); $html = str_replace(" ", " ", $html); $html = html_decode($html); $html = html_decode($html); $location = trim(strip_tags(extract_raw_tag($html, "h3"))); if (substr($location, 0, 12) == "Weather for ") { $location = substr($location, 12); } $wind = trim(strip_tags(extract_text_nofalse($html, "style=\"white-space:nowrap;padding-right:15px;color:#666\">Wind: ", "</span>"))); $humidity = extract_text($html, "style=\"white-space:nowrap;padding-right:0px;vertical-align:top;color:#666\">Humidity: ", "</td>"); $parts = explode("<td", $html); $temps = array(); $tempsC = array(); $conds = array(); $days = array(); for ($i = 1; $i < count($parts); $i++) { $cond = extract_text($parts[$i], "alt=\"", "\""); $temp = extract_text($parts[$i], "<span class=\"wob_t\" style=\"display:inline\">", "</span>"); $day = extract_text($parts[$i], "colspan=\"2\" style=\"vertical-align:top;text-align:center\">", "</td>"); if ($cond !== False) { $conds[] = strtolower($cond); } if ($temp !== False) { $temps[] = $temp; $tempsC[] = sprintf("%.0f", (substr($temp, 0, strlen($temp) - 2) - 32) * 5 / 9) . "°C"; } if ($day !== False) { $days[] = $day; } } $offset = 0; $wind_caption = ", wind " . $wind; if ($wind == "") { $offset = 1; $wind_caption = ""; } if (count($conds) != 5 or count($temps) != 10 - $offset or count($tempsC) != 10 - $offset or count($days) != 4) { return False; } if ($use_unit_pref == False) { $result = $location . " - currently " . $temps[0] . " / " . $tempsC[0] . ", " . $conds[0] . $wind_caption . ", humidity " . $humidity . " - "; } else { $result = $location . " - currently " . $temps[0] . ", " . $conds[0] . $wind_caption . ", humidity " . $humidity . " - "; } $fulldays = array("Sun." => "Sunday", "Mon." => "Monday", "Tue." => "Tuesday", "Wed." => "Wednesday", "Thu." => "Thursday", "Fri." => "Friday", "Sat." => "Saturday"); for ($i = 1; $i <= 4; $i++) { $day = $days[$i - 1]; $day = $fulldays[$day]; if ($use_unit_pref == False) { $result = $result . $day . " " . $conds[$i] . " (" . $temps[$i * 2 + 1 - $offset] . ":" . $temps[$i * 2 - $offset] . " / " . $tempsC[$i * 2 + 1 - $offset] . ":" . $tempsC[$i * 2 - $offset] . ")"; } else { $result = $result . $day . " " . $conds[$i] . " (" . $temps[$i * 2 + 1 - $offset] . ":" . $temps[$i * 2 - $offset] . ")"; } if ($i < 4) { $result = $result . ", "; } } $color = "10"; if (isset($prefs["color"]) == True) { $color = $prefs["color"]; } $result = chr(3) . $color . $result; if ($getdata != False) { $data = array(); $data["tempF"] = $temps[0]; $data["tempC"] = $tempsC[0]; $data["cond"] = $conds[0]; $data["wind"] = $wind_caption; $data["humidity"] = $humidity; $data["location"] = $location; return $data; } return $result; }
function wiki_unspamctl($nick, $trailing) { $account = users_get_account($nick); $allowed = array("crutchy", "chromas", "mrcoolbp", "paulej72", "juggs", "martyb"); if (in_array($account, $allowed) == False) { privmsg(" error: not authorized"); return; } $title = trim(substr($trailing, strlen(".unspamctl"))); if ($title == "") { privmsg(" syntax: .unspamctl <page title>"); return; } if (login($nick, True) == False) { return; } $cookieprefix = get_bucket("wiki_login_cookieprefix"); $sessionid = get_bucket("wiki_login_sessionid"); if ($cookieprefix == "" or $sessionid == "") { privmsg(" not logged in"); return; } $headers = array("Cookie" => login_cookie($cookieprefix, $sessionid)); $uri = "/w/api.php?action=query&format=php&meta=tokens&type=rollback"; $response = wget(WIKI_HOST, $uri, 80, WIKI_USER_AGENT, $headers); $data = unserialize(strip_headers($response)); if (isset($data["query"]["tokens"]["rollbacktoken"]) == False) { privmsg(" error getting rollbacktoken"); logout(True); return; } $token = $data["query"]["tokens"]["rollbacktoken"]; /*$uri="/w/api.php?action=edit"; $params=array( "format"=>"php", "title"=>$title, "text"=>$text, "contentformat"=>"text/x-wiki", "contentmodel"=>"wikitext", "bot"=>"", "token"=>$token); $response=wpost(WIKI_HOST,$uri,80,WIKI_USER_AGENT,$params,$headers); $data=unserialize(strip_headers($response)); if (isset($data["error"])==True) { privmsg(" error: ".$data["error"]["code"]); } else { $msg=$data["edit"]["result"]; if ($data["edit"]["result"]=="Success") { if ((isset($data["edit"]["oldrevid"])==True) and (isset($data["edit"]["newrevid"])==True)) { $msg=$msg.", oldrevid=".$data["edit"]["oldrevid"].", newrevid=".$data["edit"]["newrevid"]; } } privmsg(" $msg"); $title=str_replace(" ","_",$title); privmsg(" http://wiki.soylentnews.org/wiki/".urlencode($title)); }*/ logout(True); }
ini_set("display_errors", "on"); require_once "lib.php"; $trailing = trim($argv[1]); $dest = $argv[2]; $nick = $argv[3]; $alias = $argv[4]; if ($trailing == "") { privmsg("syntax: .jisho <word>"); privmsg("looks up jisho.org"); return; } $max_items = 2; $host = "jisho.org"; $uri = "/search/" . urlencode($trailing); $response = wget($host, $uri); $html = strip_headers($response); if ($html === False) { privmsg("error downloading"); return; } $items = explode("<div class=\"concept_light clearfix\">", $html); array_shift($items); $results = array(); for ($i = 0; $i < count($items); $i++) { $result = array(); # hiragana $delim1 = "<span class=\"kanji-2-up kanji\">"; $delim2 = "</span>"; $result_hiragana_2 = extract_text($items[$i], $delim1, $delim2); $delim1 = "<span class=\"kanji-3-up kanji\">"; $delim2 = "</span>";
<?php /* exec:~jisho|20|0|0|1|||||php scripts/jisho2.php %%trailing%% help:~jisho|syntax: ~jisho <word> help:~jisho|looks up jisho.org */ require_once "lib.php"; $trailing = trim($argv[1]); if ($trailing == "") { privmsg("syntax: ~jisho <word>"); privmsg("looks up jisho.org"); return; } $response = wget("jisho.org", "/api/v1/search/words?keyword=" . urlencode($trailing)); $content = strip_headers($response); if ($content === False) { privmsg("error downloading"); return; } $results = json_decode($content, True); if (isset($results["data"]) == False) { privmsg("invalid result"); return; } for ($i = 0; $i < min(2, count($results["data"])); $i++) { $out = ""; for ($j = 0; $j < count($results["data"][$i]["japanese"]); $j++) { if ($out != "") { $out = $out . ", "; }
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; } }
$dest = $argv[2]; $nick = $argv[3]; $alias = substr($argv[4], 1); if ($trailing == "debug on") { set_bucket("chromas_irc_log_debug", "on"); privmsg(" enabled debug pm"); return; } elseif ($trailing == "debug off") { unset_bucket("chromas_irc_log_debug"); privmsg(" disabled debug pm"); return; } $lines = chromas_log($alias, $trailing, $dest); if ($lines === False) { $response = wget("chromas.0x.no", "/s/soylent_log.php", 80); $html = trim(strip_headers($response)); $html = str_replace("\n", " ", $html); privmsg(chr(3) . "03" . $html); privmsg(chr(3) . " http://chromas.0x.no/s/soylent_log.php"); return; } $cutoff_index = 4; for ($i = 0; $i < count($lines); $i++) { if ($i > $cutoff_index) { $n = count($lines) - $cutoff_index - 1; privmsg(chr(3) . "03{$n} records not shown - refer to http://chromas.0x.no{$uri}"); break; } $msg = trim($lines[$i]); if ($msg != "") { privmsg(chr(3) . "03" . $msg);
function get_name($uid) { global $host; global $port; $uri = "/api.pl?m=user&op=get_nick&uid={$uid}"; $response = wget($host, $uri, $port); $content = strip_headers($response); $data = json_decode($content, True); if (isset($data["nick"]) == True) { return $data["nick"]; } else { return False; } }
function sn_submit($url) { if ($url == "") { return False; } $url = get_redirected_url($url); if ($url === False) { privmsg("error: unable to download source (get_redirected_url)"); return False; } $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 False; } $response = wget($host, $uri, $port); if (get_host_and_uri($url, $host, $uri, $port) == False) { privmsg("error: unable to download source (wget)"); return False; } $source_html = strip_headers($response); $source_title = extract_raw_tag($source_html, "title"); $delimiters = array("--", "|", " - ", " : ", " — ", " • "); for ($i = 0; $i < count($delimiters); $i++) { $j = strpos($source_title, $delimiters[$i]); if ($j !== False) { $source_title = trim(substr($source_title, 0, $j)); } } if ($source_title === False or $source_title == "") { privmsg("error: title not found or empty"); return False; } $source_title = html_decode($source_title); $source_title = html_decode($source_title); $source_body = extract_meta_content($source_html, "description"); if ($source_body === False or $source_body == "") { $source_body = extract_meta_content($source_html, "og:description", "property"); if ($source_body === False or $source_body == "") { privmsg("error: description meta content not found or empty"); return False; } } $html = $source_html; $article = extract_raw_tag($html, "article"); if ($article !== False) { $html = $article; } strip_all_tag($html, "head"); strip_all_tag($html, "script"); strip_all_tag($html, "style"); #strip_all_tag($html,"a"); strip_all_tag($html, "strong"); $html = strip_tags($html, "<p>"); $html = lowercase_tags($html); $html = explode("<p", $html); $source_body = array(); for ($i = 0; $i < count($html); $i++) { $parts = explode(">", $html[$i]); if (count($parts) >= 2) { array_shift($parts); $html[$i] = implode(">", $parts); } $html[$i] = strip_tags($html[$i]); $html[$i] = clean_text($html[$i]); $host_parts = explode(".", $host); for ($j = 0; $j < count($host_parts); $j++) { if (strlen($host_parts[$j]) > 3) { if (strpos(strtolower($html[$i]), strtolower($host_parts[$j])) !== False) { continue 2; } } } if (filter($html[$i], "0123456789") != "") { continue; } if (strlen($html[$i]) > 1) { if ($html[$i][strlen($html[$i]) - 1] != ".") { continue; } while (True) { $j = strlen($html[$i]) - 1; if ($j < 0) { break; } $c = $html[$i][$j]; if ($c == ".") { break; } $html[$i] = substr($html[$i], 0, $j); } } if (strlen($html[$i]) > 100) { $source_body[] = $html[$i]; } } $source_body = implode("\n\n", $source_body); $source_body = html_decode($source_body); $source_body = html_decode($source_body); $host = "dev.soylentnews.org"; $port = 443; $uri = "/submit.pl"; $response = wget($host, $uri, $port, ICEWEASEL_UA); $html = strip_headers($response); $reskey = extract_text($html, "<input type=\"hidden\" id=\"reskey\" name=\"reskey\" value=\"", "\">"); if ($reskey === False) { privmsg("error: unable to extract reskey"); return False; } sleep(25); $params = array(); $params["reskey"] = $reskey; #$params["name"]=trim(substr($nick,0,50)); $params["name"] = get_bot_nick(); $params["email"] = ""; $params["subj"] = trim(substr($source_title, 0, 100)); $params["primaryskid"] = "1"; $params["tid"] = "6"; $params["sub_type"] = "plain"; $params["story"] = $source_body . "\n\n" . $url . "\n\n-- submitted from IRC"; $params["op"] = "SubmitStory"; $response = wpost($host, $uri, $port, ICEWEASEL_UA, $params); $html = strip_headers($response); strip_all_tag($html, "head"); strip_all_tag($html, "script"); strip_all_tag($html, "style"); strip_all_tag($html, "a"); $html = strip_tags($html); $html = clean_text($html); if (strpos($html, "Perhaps you would like to enter an email address or a URL next time. Thanks for the submission.") !== False) { privmsg("submission successful - https://{$host}/submit.pl?op=list"); return True; } else { privmsg("error: something went wrong with your submission"); return False; } }
for ($i = 0; $i < count($request_ids); $i++) { $id = $request_ids[$i]; $request_params = array(); $request_params["exec_key"] = $key; $response = wpost("irciv.us.to", "/?exec&request_id={$id}", 80, "", $request_params); $content = trim(strip_headers($response)); var_dump($content); if (strpos(strtoupper($content), "ERROR") !== False) { output_message($content); } elseif ($content != "") { $content = unserialize($content); output_message($content["request_uri"]); $data = get_bucket($content["data"]); $response_params = array(); $response_params["exec_key"] = $key; $response_params["request_id"] = $id; $response_params["data"] = $data; $response = wpost("irciv.us.to", "/?exec", 80, "", $response_params); $content = trim(strip_headers($response)); output_message($content); } } } sleep(10); } ##################################################################################################### function output_message($msg) { privmsg($msg); } #####################################################################################################
function get_api_data($uri) { $host = "api.github.com"; $port = 443; $tok = trim(file_get_contents("../pwd/gh_tok")); $headers = array(); $headers["Authorization"] = "token {$tok}"; $headers["Accept"] = "application/vnd.github.v3+json"; $response = wget($host, $uri, $port, ICEWEASEL_UA, $headers, 60); $content = strip_headers($response); return json_decode($content, True); }