示例#1
0
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;
}
示例#2
0
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;
}
示例#3
0
function quick_wget($trailing)
{
    $parts = explode(" ", $trailing);
    delete_empty_elements($parts);
    if (count($parts) < 2) {
        return False;
    }
    $url = $parts[0];
    array_shift($parts);
    $trailing = implode(" ", $parts);
    $parts = explode("<>", $trailing);
    delete_empty_elements($parts);
    if (count($parts) < 2) {
        return False;
    }
    $delim1 = trim($parts[0]);
    $delim2 = trim($parts[1]);
    $host = "";
    $uri = "";
    $port = "";
    if (get_host_and_uri($url, $host, $uri, $port) == False) {
        return False;
    }
    $response = wget_ssl($host, $uri, $port);
    $result = extract_text($response, $delim1, $delim2);
    if ($result === False) {
        return False;
    }
    $result = strip_tags($result);
    $result = html_decode($result);
    $result = html_decode($result);
    $result = trim($result);
    if ($result == "") {
        return False;
    }
    return $result;
}
示例#4
0
*/
#####################################################################################################
require_once "lib.php";
require_once "sn_lib.php";
$trailing = trim($argv[1]);
$alias = strtolower(trim($argv[2]));
$parts = explode(" ", $trailing);
if (count($parts) != 2) {
    return;
}
$header = $parts[0];
$url = $parts[1];
$host = "";
$uri = "";
$port = 80;
if (get_host_and_uri($url, $host, $uri, $port) == False) {
    return;
}
switch ($alias) {
    case "~header":
        get_header($host, $uri, $port, $header, $url);
        break;
    case "~header-login":
        if (strtolower($host) == "soylentnews.org") {
            get_header_login($host, $uri, $port, $header, $url);
        }
        break;
}
#####################################################################################################
function get_header($host, $uri, $port, $header, $url)
{
示例#5
0
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;
    }
}
示例#6
0
term_echo("*** comment_feed: {$item_count} feed stories to check");
$top_score_pub = 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;
示例#7
0
function check_push_events($repo)
{
    $data = get_api_data("/repos/{$repo}/events");
    $n = count($data) - 1;
    for ($i = $n; $i >= 0; $i--) {
        if (isset($data[$i]["created_at"]) == False) {
            continue;
        }
        if ($data[$i]["type"] != "PushEvent") {
            continue;
        }
        $timestamp = $data[$i]["created_at"];
        $t = convert_timestamp($timestamp, CREATE_TIME_FORMAT);
        $dt = microtime(True) - $t;
        if ($dt > TIME_LIMIT_SEC) {
            continue;
        }
        github_msg($repo, chr(3) . "13" . "push to https://github.com/{$repo} @ " . date("H:i:s", $t) . " by " . $data[$i]["actor"]["login"]);
        github_msg($repo, "  " . chr(3) . "03" . $data[$i]["payload"]["ref"]);
        for ($j = 0; $j < count($data[$i]["payload"]["commits"]); $j++) {
            $commit = $data[$i]["payload"]["commits"][$j];
            github_msg($repo, chr(3) . "11" . "  " . $commit["author"]["name"] . ": " . chr(2) . chr(3) . "03" . $commit["message"]);
            $commit_url = $commit["url"];
            $commit_host = "";
            $commit_uri = "";
            $commit_port = "";
            if (get_host_and_uri($commit_url, $commit_host, $commit_uri, $commit_port) == True) {
                $commit_data = get_api_data($commit_uri);
                $ref_parts = explode("/", $data[$i]["payload"]["ref"]);
                if (isset($commit_data["files"]) == True and isset($ref_parts[2]) == True) {
                    $branch = $ref_parts[2];
                    $html_url = $commit_data["html_url"];
                    github_msg($repo, chr(3) . "11" . "  " . $html_url);
                    $n1 = count($commit_data["files"]);
                    for ($k = 0; $k < $n1; $k++) {
                        if ($k > 4) {
                            $rem = $n1 - $k;
                            github_msg($repo, "  " . chr(3) . "08" . "└─" . chr(3) . "({$rem} files skipped)");
                            break;
                        }
                        $commit_filename = str_replace(" ", "%20", $commit_data["files"][$k]["filename"]);
                        $commit_status = $commit_data["files"][$k]["status"];
                        $tree_symbol = "├─";
                        if ($k == $n1 - 1) {
                            $tree_symbol = "└─";
                        }
                        if ($commit_status == "removed") {
                            github_msg($repo, "  " . chr(3) . "08" . $tree_symbol . "removed:" . chr(3) . " /{$repo}/blob/{$branch}/{$commit_filename}");
                        } else {
                            $commit_changes = "";
                            if (isset($commit_data["files"][$k]["additions"]) == True and isset($commit_data["files"][$k]["deletions"]) == True) {
                                $additions = $commit_data["files"][$k]["additions"];
                                $deletions = $commit_data["files"][$k]["deletions"];
                                $commit_changes = " [+{$additions},-{$deletions}]";
                            }
                            github_msg($repo, "  " . chr(3) . "08" . $tree_symbol . $commit_status . $commit_changes . ":" . chr(3) . " https://github.com/{$repo}/blob/{$branch}/{$commit_filename}");
                        }
                    }
                }
            }
        }
    }
}