Example #1
0
 function isTriggered()
 {
     if (!isset($this->data['text'])) {
         $this->printUsage();
         return;
     }
     $HTTP = new HTTP('api.themoviedb.org');
     $html = $HTTP->GET('/2.1/Movie.search/' . $this->getConfig('language') . '/xml/' . $this->api_key . '/' . urlencode($this->data['text']));
     $XML = simplexml_load_string($html);
     if (!$XML) {
         $this->reply('Error on contacting themoviedb.org');
         return;
     }
     $tmp = $XML->xpath('opensearch:totalResults');
     $results = (int) $tmp[0];
     if (!$results) {
         if ($this->getConfig('language') != 'en') {
             $html = $HTTP->GET('/2.1/Movie.search/en/xml/' . $this->api_key . '/' . urlencode($this->data['text']));
             $XML = new SimpleXMLElement($html);
             if (!$XML) {
                 $this->reply('Error on contacting themoviedb.org');
                 return;
             }
             $tmp = $XML->xpath('opensearch:totalResults');
             $results = (int) $tmp[0];
         }
     }
     if (!$results) {
         $this->reply('There is no information available about this movie.');
         return;
     }
     $tmp = $XML->children()->children();
     $Movie = $tmp[0];
     $text = "" . $Movie->name . "";
     if ((string) $Movie->original_name != (string) $Movie->name) {
         $text .= ' (' . $Movie->original_name . ')';
     }
     if (!empty($Movie->released)) {
         $text .= " | Released: " . $Movie->released;
     }
     if ($Movie->rating != '0.0') {
         $text .= " | Press Rating: " . $Movie->rating . '/10';
     }
     if (!empty($Movie->certification)) {
         $text .= " | Rated: " . $Movie->certification;
     }
     $text .= ' (' . $Movie->url . ')';
     $this->reply($text);
     $this->reply($Movie->overview);
 }
Example #2
0
 private static function _execute($url, $method, $post = null)
 {
     $data = parse_url($url);
     if (isset($data['user']) || isset($data['pass'])) {
         // TODO: not yet implemented
         return false;
     }
     if (isset($data['query'])) {
         $data['fullpath'] = $data['path'] . '?' . $data['query'];
     } else {
         $data['fullpath'] = $data['path'];
     }
     switch ($data['scheme']) {
         case 'http':
             $HTTP = new HTTP($data['host'], isset($data['port']) ? $data['port'] : 80);
             break;
         case 'https':
             $HTTP = new HTTP($data['host'], isset($data['port']) ? $data['port'] : 443, true);
             break;
         default:
             return false;
             break;
     }
     switch ($method) {
         case 'GET':
             return $HTTP->GET($data['fullpath']);
             break;
         case 'POST':
             return $HTTP->POST($data['fullpath'], $post);
             break;
         default:
             return false;
             break;
     }
 }
Example #3
0
 private function fetchFunctionDescription($func)
 {
     $HTTP = new HTTP('php.net');
     $html = $HTTP->GET('/' . $this->getConfig('language') . '/' . $func);
     if ($html === false) {
         $this->reply('Timeout on contacting ' . $host);
         return;
     }
     if (preg_match('/<span class=\\"refname\\">(.*?)<\\/span> &mdash; <span class=\\"dc\\-title\\">(.*?)<\\/span>/si', $html, $match)) {
         $match[2] = str_replace(array("\n", "\r"), ' ', strip_tags($match[2]));
         preg_match('/<div class=\\"methodsynopsis dc\\-description\\">(.*?)<\\/div>/si', $html, $descmatch);
         $decl = isset($descmatch[1]) ? strip_tags($descmatch[1]) : $match[1];
         $decl = html_entity_decode(str_replace(array("\n", "\r"), ' ', $decl));
         while (strstr($decl, '  ')) {
             $decl = str_replace('  ', ' ', $decl);
         }
         $decl = str_replace($func, "" . $func . "", $decl);
         $output = $decl . ' - ' . html_entity_decode($match[2]) . ' ( http://php.net/' . $func . ' )';
         $this->reply(libString::isUTF8($output) ? $output : utf8_encode($output));
     } else {
         // if several possibilities
         $output = '';
         if (preg_match_all('/<a href=\\"\\/manual\\/[a-z]+\\/(?:.*?)\\.php\\">(?:<b>)?(.*?)(?:<\\/b>)?<\\/a><br/i', $html, $matches, PREG_SET_ORDER)) {
             if ($this->redirects++ < 2) {
                 $this->fetchFunctionDescription($matches[0][1]);
             } else {
                 $this->reply($this->notfoundtext . ' http://php.net/search.php?show=wholesite&pattern=' . $this->data['text']);
             }
             return;
         } else {
             $output = $this->notfoundtext . ' http://php.net/search.php?show=wholesite&pattern=' . $func;
         }
         $this->reply(libString::isUTF8($output) ? $output : utf8_encode($output));
     }
 }
Example #4
0
 function getStats($username, $html)
 {
     $HTTP = new HTTP('www.hacker.org');
     if (false === ($top = $this->getCache())) {
         $top = $HTTP->GET('/challenge/top.php');
         if ($top === false) {
             return 'timeout';
         }
         $this->putCache($top);
     }
     if (!preg_match('#a href="/forum/profile\\.php\\?mode=viewprofile&u=([0-9]+)">' . $username . '</a></td> <td>(.*?)</td><td>(.*?)</td>#i', $top, $arr)) {
         return false;
     }
     $score = $arr[2];
     $solved = $arr[3];
     $extra = array();
     $html = $HTTP->GET('/forum/profile.php?mode=viewprofile&u=' . $arr[1]);
     if ($html === false) {
         return 'timeout';
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/coil/">#', $html, $arr)) {
         $extra[] = 'Mortal Coil: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/modulo/">#', $html, $arr)) {
         $extra[] = 'Modulo: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/runaway/">#', $html, $arr)) {
         $extra[] = 'Runaway: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/brick/">#', $html, $arr)) {
         $extra[] = 'Bricolage: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/oneofus/">#', $html, $arr)) {
         $extra[] = 'OneOfUs: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/push/">#', $html, $arr)) {
         $extra[] = 'Pusherboy: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/tapeworm/">#', $html, $arr)) {
         $extra[] = 'Tapeworm: ' . $arr[1];
     }
     if (preg_match('#<td>([0-9]+)</td><td><a href="/cross/">#', $html, $arr)) {
         $extra[] = 'Crossflip: ' . $arr[1];
     }
     $data = array('username' => $username, 'challs' => $solved, 'score' => $score, 'extra' => count($extra) ? ' - ' . $username . "'s puzzle scores: " . implode(', ', $extra) : '');
     return $data;
 }
Example #5
0
 function getStats($username, $html)
 {
     $HTTP = new HTTP('www.wechall.net');
     $html = $HTTP->GET('/wechallchalls.php?username='******'timeout';
     }
     if (libString::startsWith('The user', $html)) {
         return false;
     }
     preg_match('/^(.+?) solved (\\d+?) of (\\d+?) Challenges with (\\d+?) of (\\d+?) possible points \\(([\\d\\.]+?)%\\). Rank for the site WeChall: (\\d+)$/', $html, $arr);
     $html = $HTTP->GET('/wechall.php?username=noother');
     if ($html === false) {
         return 'timeout';
     }
     preg_match('/is ranked \\d+? from (\\d+),/', $html, $arr2);
     $data = array('username' => $arr[1], 'challs_solved' => $arr[2], 'challs_total' => $arr[3], 'points' => $arr[4], 'points_total' => $arr[5], 'points_percent' => $arr[6], 'rank' => $arr[7], 'users_total' => $arr2[1]);
     return $data;
 }
Example #6
0
 static function tinyURLDecode($tinyurl)
 {
     $parts = parse_url($tinyurl);
     $HTTP = new HTTP('tinyurl.com');
     $HTTP->set('auto-follow', false);
     $HTTP->GET($parts['path']);
     $header = $HTTP->getHeader();
     if (!isset($header['Location'])) {
         return false;
     }
     return $header['Location'];
 }
Example #7
0
 function getStats($username, $html)
 {
     $HTTP = new HTTP('www.thisislegal.com');
     $html = $HTTP->GET('/userscore.php?username='******'timeout';
     }
     if ($html === '0') {
         return false;
     }
     list($rank, $score, $score_total, $users_total) = explode(':', $html);
     $html = $HTTP->GET('/user/' . urlencode($username));
     if ($html === false) {
         return 'timeout';
     }
     preg_match('#Username: <font class="cf">\\s+(.+?)</font>#', $html, $arr);
     list($full, $username) = $arr;
     preg_match('#<b>% Completed&nbsp;\\((\\d+?)/(\\d+?)\\):&nbsp;</b>#', $html, $arr);
     list($full, $challs_solved, $challs_total) = $arr;
     $data = array('username' => $username, 'rank' => $rank, 'users_total' => $users_total, 'challs_solved' => $challs_solved, 'challs_total' => $challs_total, 'score' => $score, 'score_total' => $score_total);
     return $data;
 }
Example #8
0
 function getRfc($data)
 {
     $this->cachefile = $data['cachefile'];
     $HTTP = new HTTP('www.ietf.org');
     if (($index = $this->getCache()) === false) {
         echo "fetching new data\n";
         $index = $HTTP->GET('/rfc/rfc-index.xml');
         $index = preg_replace('/<rfc-index.*?>/is', '<rfc-index>', $index);
         // remove namespaces (they break simplexml xpath...)
         if ($index === false) {
             return 'timeout';
         }
         $this->putCache($index);
     }
     // pad docnum to 4 nums with zeroes
     $data['docNum'] = str_pad($data['docNum'], 4, '0', STR_PAD_LEFT);
     $xml = simplexml_load_string($index);
     $query = $data['docType'] . '-entry[doc-id[.="' . strtoupper($data['docType']) . $data['docNum'] . '"]]';
     $docs = $xml->xpath($query);
     if (!$docs) {
         return 'doc does not exist';
     }
     $doc = $docs[0];
     $link = 'http://www.ietf.org/rfc/';
     if ($data['docType'] != 'rfc') {
         // others use subfolders
         $link .= $data['docType'] . '/';
         // others dont use number padding... (but in rfc-index.xml, they do)
         $data['docNum'] = (int) $data['docNum'];
     }
     $link .= $data['docType'] . $data['docNum'] . '.txt';
     $reply = "[" . $data['docType'] . "] " . (string) $doc->{'doc-id'};
     $title = (string) $doc->title;
     if (!empty($title)) {
         $reply .= ' - ' . $title;
     }
     $reply .= ' - ' . $link;
     return $reply;
 }
Example #9
0
 private function getW3Challs($count)
 {
     $HTTP = new HTTP('w3challs.com');
     $html = $HTTP->GET('/');
     if (!$html) {
         return false;
     }
     if (!preg_match('#<input type="hidden" name="member_token" value="(.+?)" />#', $html, $arr)) {
         return false;
     }
     $token = $arr[1];
     $html = $HTTP->POST('/profile/awe', array('changeLanguage' => 'fr', 'member_token' => $token));
     if (!$html) {
         return false;
     }
     preg_match_all('#<a href="/challenges/challenge(\\d+?)".+?title="(.+?), by (.+?) \\(Points: (\\d+?);#', $html, $arr);
     $challs = array();
     for ($i = 0; $i < sizeof($arr[1]); $i++) {
         $challs[] = array('id' => $arr[1][$i], 'name' => $arr[2][$i], 'author' => $arr[3][$i], 'points' => $arr[4][$i]);
     }
     usort($challs, array('self', 'sortByID'));
     $texts = array();
     for ($i = 0; $i < $count; $i++) {
         $texts[] = sprintf("%s by %s worth %d points ( %s )", $challs[$i]['name'], $challs[$i]['author'], $challs[$i]['points'], 'http://w3challs.com/challenges/challenge' . $challs[$i]['id']);
     }
     return $texts;
 }
Example #10
0
function _xRegister()
{
    global $t, $C;
    require_once 'validator.php';
    $_REQUEST = string_strip_tags($_REQUEST);
    $v =& Validator::Get();
    $v->Register($_REQUEST['return_url'], VT_VALID_HTTP_URL, "The 'URL to Send Traffic' field must be a valid HTTP URL");
    if (!string_is_empty($_REQUEST['return_url'])) {
        require_once 'http.php';
        $http = new HTTP();
        $v->Register($http->GET($_REQUEST['return_url'], null, true), VT_NOT_FALSE, "The 'URL to Send Traffic' does not seem to be working: " . $http->error);
        $_REQUEST['header'] = $http->response_headers;
        $_REQUEST['content'] = $http->body;
    }
    if ($C['flag_req_email'] || !empty($_REQUEST['email'])) {
        $v->Register($_REQUEST['email'], VT_VALID_EMAIL, "The 'E-mail Address' field must be a valid email");
    }
    if ($C['flag_req_site_name'] || !empty($_REQUEST['site_name'])) {
        $v->Register($_REQUEST['site_name'], VT_LENGTH_BETWEEN, "The 'Site Name' field must have between {$C['site_name_min']} and {$C['site_name_max']} characters", array($C['site_name_min'], $C['site_name_max']));
    }
    if ($C['flag_req_site_description'] || !empty($_REQUEST['site_description'])) {
        $v->Register($_REQUEST['site_description'], VT_LENGTH_BETWEEN, "The 'Site Description' field must have between {$C['site_description_min']} and {$C['site_description_max']} characters", array($C['site_description_min'], $C['site_description_max']));
    }
    if ($C['flag_req_icq'] || !empty($_REQUEST['icq'])) {
        $v->Register($_REQUEST['icq'], VT_IS_NUMERIC, "The 'ICQ Number' field must be numeric");
    }
    if ($C['flag_req_nickname'] || !empty($_REQUEST['nickname'])) {
        $v->Register($_REQUEST['nickname'], VT_NOT_EMPTY, "The 'Nickname' field is required");
    }
    if ($C['flag_req_banner'] || !empty($_REQUEST['banner'])) {
        $v->Register($_REQUEST['banner'], VT_VALID_HTTP_URL, "The 'Banner URL' field must be a valid HTTP URL");
        if (!string_is_empty($_REQUEST['banner'])) {
            require_once 'http.php';
            $http = new HTTP();
            $v->Register($http->GET($_REQUEST['banner'], null, true), VT_NOT_FALSE, "The 'Banner URL' does not seem to be working: " . $http->error);
        }
    }
    if ($C['flag_captcha_register']) {
        require_once 'captcha.php';
        $captcha = new Captcha();
        $captcha->Verify();
    }
    $_REQUEST['domain'] = domain_from_url($_REQUEST['return_url']);
    require_once 'dirdb.php';
    $db = new TradeDB();
    $v->Register($db->Exists($_REQUEST['domain']), VT_IS_FALSE, "The site you are trying to register already exists in our database");
    // Check blacklist
    $_REQUEST['server_ip'] = gethostbyname($domain);
    $_REQUEST['dns'] = gethostbyname($domain);
    if (($blacklisted = check_blacklist($_REQUEST)) !== false) {
        $v->SetError("You have matched one or more of our blacklist items and cannot register new trade accounts" . (!empty($blacklisted[1]) ? ": " . $blacklisted[1] : ''));
    }
    // Check category
    $categories = array_map('trim', file(FILE_CATEGORIES));
    if ($C['flag_allow_select_category'] && count($categories)) {
        $v->Register(in_array($_REQUEST['category'], $categories), VT_IS_TRUE, "You have selected an invalid category");
        $_REQUEST['categories'] = array($_REQUEST['category']);
    }
    if (!$v->Validate()) {
        $t->Assign('g_errors', $v->GetErrors());
        return _xRegisterShow();
    }
    $_REQUEST = array_merge($_REQUEST, unserialize(file_get_contents(FILE_NEW_TRADE_DEFAULTS)));
    $password = $_REQUEST['password'] = get_random_password();
    $t->AssignByRef('g_trade', $_REQUEST);
    trade_add($_REQUEST, true);
    $_REQUEST['password'] = $password;
    $t->Display('register-complete.tpl');
}
Example #11
0
 private function checkMD5Decrypt($hash)
 {
     $HTTP = new HTTP('www.md5decrypt.org');
     $html = $HTTP->GET('/');
     if ($html === false) {
         return false;
     }
     if (!preg_match('/<script>document.cookie=\'(.+?)=(.+?)\';/', $html, $arr)) {
         return false;
     }
     $HTTP->setCookie($arr[1], $arr[2]);
     $res = $HTTP->POST('/index/process', array('value' => base64_encode($hash), 'operation' => 'MD5D'));
     if ($res === false) {
         return false;
     }
     $json = json_decode($res);
     if (!$json) {
         return false;
     }
     if (!empty($json->error)) {
         return false;
     }
     return $json->body;
 }
Example #12
0
 public function request_result($data)
 {
     if ($data["url"][0] != "/") {
         return false;
     }
     if ($_SERVER["HTTPS"] == "on") {
         $http = new HTTPS($_SERVER["HTTP_HOST"]);
     } else {
         $http = new HTTP($_SERVER["HTTP_HOST"]);
     }
     /* Determine URL path
      */
     $url = $data["url"];
     if (strpos($url, "?") === false) {
         $url .= "?";
     } else {
         $url .= "&";
     }
     $url .= "output=";
     switch ($data["type"]) {
         case "ajax":
             $url .= "ajax";
             break;
         case "xml":
             $url .= "restxml";
             break;
         case "json":
             $url .= "restjson";
             break;
         default:
             return false;
     }
     /* Restore cookies
      */
     if (isset($_SESSION["apitest_cookies"])) {
         if (($cookies = json_decode($_SESSION["apitest_cookies"], true)) !== null) {
             foreach ($cookies as $key => $value) {
                 $http->add_cookie($key, $value);
             }
         }
     }
     /* Authentication
      */
     if ($data["username"] != "" && $data["password"] != "") {
         $auth_str = sprintf("%s:%s", $data["username"], $data["password"]);
         $http->add_header("Authorization", "Basic " . base64_encode($auth_str));
     }
     /* Send request
      */
     switch ($data["method"]) {
         case "GET":
             $result = $http->GET($url);
             break;
         case "POST":
             $result = $http->POST($url, $data["postdata"]);
             break;
         case "PUT":
             $result = $http->PUT($url, $data["postdata"]);
             break;
         case "DELETE":
             $result = $http->DELETE($url);
             break;
         default:
             return false;
     }
     /* Decode JSON result
      */
     if ($result["headers"]["content-type"] == "application/json") {
         $result["body"] = $this->indent_json($result["body"]);
     }
     /* Store cookies
      */
     $_SESSION["apitest_cookies"] = json_encode($http->cookies);
     return $result;
 }
Example #13
0
function stats_minute_update($now, $last, $n_date, $l_date)
{
    global $C, $g_stats_hourly, $g_stats_daily, $g_stats_minute;
    $g_stats_minute = true;
    // Number of seconds since the last update
    $since = $now - $last;
    // The minutes that should be reset back to zero
    // Should end up as an array containing the minutes of the day to reset (from 0 to 1439)
    $reset_minutes = null;
    // 24 hours or more since the last update
    if ($since >= SECONDS_PER_DAY) {
        $reset_minutes = range(0, MINUTES_PER_DAY - 1);
    } else {
        if ($since >= SECONDS_PER_MINUTE * 2) {
            $minutes_since = floor($since / SECONDS_PER_MINUTE) - 1;
            $this_minute = $n_date['hours'] * MINUTES_PER_HOUR + $n_date['minutes'];
            $reset_minutes = array();
            for ($i = $this_minute; $i >= $this_minute - $minutes_since; $i--) {
                $reset_minutes[] = $i >= 0 ? $i : MINUTES_PER_DAY + $i;
            }
            $reset_minutes = array_reverse($reset_minutes);
        } else {
            $reset_minutes = array($n_date['hours'] * MINUTES_PER_HOUR + $n_date['minutes']);
        }
    }
    // Starting offset of minute stats
    $minutes_start = HOURS_PER_DAY * RECORD_SIZE_STATS;
    // Zeroed packed record
    $packed_record = trade_packed_record();
    // Record stats for generation of outlists
    $stats = array('total' => array('24h' => array_fill(1, STATS_PER_RECORD, 0), '60m' => array_fill(1, STATS_PER_RECORD, 0)));
    list($hour, $minute) = explode('-', date('H-i', $now - SECONDS_PER_HOUR));
    $minute_offset = ($hour * MINUTES_PER_HOUR + $minute) * RECORD_SIZE_STATS + $minutes_start;
    $end_of_file = (HOURS_PER_DAY + MINUTES_PER_DAY) * RECORD_SIZE_STATS;
    // Reset trades
    foreach (stats_get_all_files() as $stats_file) {
        $trade = basename($stats_file);
        $system_trade = strpos($stats_file, DIR_TRADE_STATS) === false;
        $fp = fopen($stats_file, 'r+');
        flock($fp, LOCK_EX);
        // Get 24 hour stats
        if (!$system_trade) {
            $stats[$trade] = array();
            $stats[$trade]['24h'] = array_fill(1, STATS_PER_RECORD, 0);
            for ($i = 0; $i < HOURS_PER_DAY; $i++) {
                $r = unpack('L' . STATS_PER_RECORD, fread($fp, RECORD_SIZE_STATS));
                foreach ($r as $j => $k) {
                    $stats[$trade]['24h'][$j] += $k;
                    $stats['total']['24h'][$j] += $k;
                }
            }
            // Seek to minute of last update to get stats
            fseek($fp, $reset_minutes[0] == 0 ? $minutes_start + (MINUTES_PER_DAY - 1) * RECORD_SIZE_STATS : $minutes_start + ($reset_minutes[0] - 1) * RECORD_SIZE_STATS, SEEK_SET);
            $stats[$trade]['1m'] = unpack('L' . STATS_PER_RECORD, fread($fp, RECORD_SIZE_STATS));
        }
        // Seek to first minute to be zeroed
        fseek($fp, $minutes_start + $reset_minutes[0] * RECORD_SIZE_STATS, SEEK_SET);
        // Reset to 0
        foreach ($reset_minutes as $minute) {
            fwrite($fp, $packed_record);
            // Seek to minute 0 if we just zeroed minute 1439
            if ($minute == MINUTES_PER_DAY - 1) {
                fseek($fp, $minutes_start, SEEK_SET);
            }
        }
        // Get 60 minute stats
        if (!$system_trade) {
            $stats[$trade]['60m'] = array_fill(1, STATS_PER_RECORD, 0);
            fseek($fp, $minute_offset, SEEK_SET);
            for ($i = 0; $i < MINUTES_PER_HOUR; $i++) {
                $r = unpack('L' . STATS_PER_RECORD, fread($fp, RECORD_SIZE_STATS));
                foreach ($r as $j => $k) {
                    $stats[$trade]['60m'][$j] += $k;
                    $stats['total']['24h'][$j] += $k;
                }
                // Wrap around midnight with a seek
                if (ftell($fp) == $end_of_file) {
                    fseek($fp, HOURS_PER_DAY * RECORD_SIZE_STATS, SEEK_SET);
                }
            }
        }
        flock($fp, LOCK_UN);
        fclose($fp);
    }
    // Generate the outlists
    generate_outlists($stats);
    // Determine if toplists should be built
    if (!file_exists(FILE_TIME_TOPLISTS)) {
        file_create(FILE_TIME_TOPLISTS);
    }
    // Rebuild toplists, only if not using cron (indicated by rebuild interval set to -1)
    if ($C['toplist_rebuild_interval'] > 0) {
        $toplists_last = filemtime(FILE_TIME_TOPLISTS);
        if (isset($C['base_url']) && $now - $toplists_last > $C['toplist_rebuild_interval'] * SECONDS_PER_MINUTE) {
            require_once 'http.php';
            $http = new HTTP();
            $http->GET("{$C['base_url']}/cp/index.php?r=btl");
        }
    }
}