示例#1
0
function get_header_login($host, $uri, $port, $header, $url)
{
    $extra_headers = array();
    $extra_headers["Cookie"] = sn_login();
    $response = whead($host, $uri, $port, ICEWEASEL_UA, $extra_headers);
    sn_logout();
    $header_value = exec_get_header($response, $header, False);
    if ($header_value != "") {
        privmsg("  {$header} header for {$url} = {$header_value}");
    }
}
示例#2
0
 if (strtolower($dest) != "#soylent") {
     privmsg("Comments may only be posted from the #Soylent channel.");
     return;
 }
 # [SoylentNews] - What a Warp-Speed Spaceship Might Look Like - http://sylnt.us/yvt2q - its-nice-to-dream
 $host = "sylnt.us";
 $i = strpos($bender_msg, $host);
 if ($i === False) {
     privmsg("http://sylnt.us/ not found in Bender's last feed message.");
     return;
 }
 $bender_msg = substr($bender_msg, $i + strlen($host));
 $parts = explode(" ", $bender_msg);
 $uri = $parts[0];
 $response = wget($host, $uri, 80, ICEWEASEL_UA);
 $redirect_url = exec_get_header($response, "Location");
 if ($redirect_url == "") {
     privmsg("Location header not found @ http://" . $host . $uri);
     return;
 }
 term_echo($redirect_url);
 # http://soylentnews.org/article.pl?sid=14/06/20/0834246&from=rss
 $delim = "sid=";
 $i = strpos($redirect_url, $delim);
 if ($i === False) {
     privmsg("\"sid\" parameter not found in Location header URL");
     return;
 }
 $sid = substr($redirect_url, $i + strlen($delim));
 $parts = explode("&", $sid);
 $sid = $parts[0];
示例#3
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;
    }
}
示例#4
0
function get_redirected_url($from_url, $url_list = "", $last_loc = "", $cookies = "")
{
    $url = trim($from_url);
    if ($url == "") {
        term_echo("get_redirected_url: empty url");
        return False;
    }
    #term_echo("  get_redirected_url: $url");
    $comp = parse_url($url);
    $host = "";
    if (isset($comp["host"]) == False) {
        if (is_array($url_list) == True) {
            if (count($url_list) > 0) {
                $host = parse_url($url_list[count($url_list) - 1], PHP_URL_HOST);
                $scheme = parse_url($url_list[count($url_list) - 1], PHP_URL_SCHEME);
                $url = $scheme . "://" . $host . $url;
            }
        }
    } else {
        $host = $comp["host"];
    }
    if ($host == "") {
        term_echo("get_redirected_url: redirect without host: " . $url);
        return False;
    }
    $uri = "/";
    if (isset($comp["path"]) == True) {
        $uri = $comp["path"];
    }
    if (isset($comp["query"]) == True) {
        if ($comp["query"] != "") {
            $uri = $uri . "?" . $comp["query"];
        }
    }
    if (isset($comp["fragment"]) == True) {
        if ($comp["fragment"] != "") {
            $uri = $uri . "#" . $comp["fragment"];
        }
    }
    $port = 80;
    if (isset($comp["scheme"]) == True) {
        if ($comp["scheme"] == "https") {
            $port = 443;
        }
    }
    if ($host == "" or $uri == "") {
        term_echo("get_redirected_url: empty host or uri");
        return False;
    }
    $extra_headers = "";
    if (isset($cookies[$host]) == True) {
        $cookie_strings = array();
        foreach ($cookies[$host] as $key => $value) {
            $cookie_strings[] = $key . "=" . $value;
        }
        $extra_headers = array();
        $extra_headers["Cookie"] = implode("; ", $cookie_strings);
    }
    #$breakcode="return (substr(\$response,strlen(\$response)-4)==\"\r\n\r\n\");";
    $breakcode = "return ((strlen(\$response)>10000) or (substr(\$response,strlen(\$response)-7)==\"</head>\"));";
    $response = wget($host, $uri, $port, ICEWEASEL_UA, $extra_headers, 10, $breakcode);
    if (is_array($cookies) == True) {
        $new_cookies = exec_get_cookies($response);
        if (count($new_cookies) > 0) {
            for ($i = 0; $i < count($new_cookies); $i++) {
                $parts = explode("; ", $new_cookies[$i]);
                $keyval = explode("=", $parts[0]);
                if (count($keyval) >= 2) {
                    $key = $keyval[0];
                    array_shift($keyval);
                    $value = implode("=", $keyval);
                    $cookies[$host][$key] = $value;
                }
            }
        }
    }
    #var_dump($response);
    $loc_header = trim(exec_get_header($response, "location", False));
    $location = $loc_header;
    # <META http-equiv="refresh" content="0;URL='http://www.goodgearguide.com.au/article/577990/how-encryption-keys-could-stolen-by-your-lunch/'">
    if ($location == "" or $location == $last_loc) {
        if (is_array($cookies) == False) {
            return $url;
        } else {
            return array("url" => $url, "cookies" => $cookies, "extra_headers" => $extra_headers);
        }
    } else {
        if ($location[0] == "/") {
            $location = $url . $location;
        }
        if (is_array($url_list) == True) {
            $n = 0;
            for ($i = 0; $i < count($url_list); $i++) {
                if ($url_list[$i] == $url_list) {
                    $n++;
                }
            }
            if ($n > 1) {
                term_echo("get_redirected_url: redirected url already been visited twice");
                return False;
            } else {
                $list = $url_list;
                $list[] = $url;
                if (count($list) < 10) {
                    return get_redirected_url($location, $list, $loc_header, $cookies);
                } else {
                    if (is_array($cookies) == False) {
                        return $url;
                    } else {
                        return array("url" => $url, "cookies" => $cookies, "extra_headers" => $extra_headers);
                    }
                }
            }
        } else {
            $list = array($url);
            return get_redirected_url($location, $list, $loc_header, $cookies);
        }
    }
}
示例#5
0
 if ($redirect_data === False) {
     term_echo("get_redirected_url=false");
     return;
 }
 $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;
 }
 $headers = whead($host, $uri, $port);
 $content_length = exec_get_header($headers, "content-length", False);
 if ($content_length != "") {
     if ($content_length > 1024 * 1024) {
         privmsg(chr(3) . "13" . round($content_length / 1024 / 1024, 3) . " Mb (header)");
     } elseif ($content_length > 1024) {
         privmsg(chr(3) . "13" . round($content_length / 1024, 3) . " kb (header)");
     } else {
         privmsg(chr(3) . "13" . $content_length . " bytes (header)");
     }
     return;
 }
 $breakcode = "return (strlen(\$response)>=2000000);";
 $response = wget($host, $uri, $port, ICEWEASEL_UA, $rd_extra_headers, 20, $breakcode, 256);
 $html = strip_headers($response);
 $content_length = strlen($html);
 if ($content_length > 1024 * 1024) {