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; }
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); } } }