Пример #1
0
 /**
  * Send call to API
  *
  * @param string $module string name of url suffix
  * @param array $params array get parameters to send to API
  *
  * @return mixed|array response of API
  * @throws GiantBombException
  */
 private function call($module, $params = array())
 {
     // set api data
     $params['api_key'] = $this->api_key;
     $params['format'] = $this->resp_type;
     // build URL
     $url = $this->endpoint . $module . '?' . http_build_query($params);
     // Set URL
     curl_setopt($this->ch, CURLOPT_URL, $url);
     curl_setopt_array($this->ch, nzedb\utility\Misc::curlSslContextOptions());
     // Send the request & save response to $resp
     $resp["data"] = curl_exec($this->ch);
     if (curl_errno($this->ch)) {
         throw new \GiantBombException('API call failed: ' . curl_error($this->ch));
     }
     // save http response code
     $resp["httpCode"] = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
     if (!$resp || !$resp["data"]) {
         throw new \GiantBombException("Couldn't get information from API");
     }
     return $resp;
 }
Пример #2
0
 /**
  * Makes the call to the API
  *
  * @param string $function			API specific function name for in the URL
  * @param array $params				Unencoded parameters for in the URL
  * @param string $session_id		Session_id for authentication to the API for specific API methods
  * @param const $method				TMDb::GET or TMDb:POST (default TMDb::GET)
  * @return TMDb result array
  */
 private function _makeCall($function, $params = NULL, $session_id = NULL, $method = TMDb::GET)
 {
     $params = !is_array($params) ? array() : $params;
     $auth_array = array('api_key' => $this->_apikey);
     if ($session_id !== NULL) {
         $auth_array['session_id'] = $session_id;
     }
     $url = $this->_apischeme . TMDb::API_URL . '/' . TMDb::API_VERSION . '/' . $function . '?' . http_build_query($auth_array, '', '&');
     if ($method === TMDb::GET) {
         if (isset($params['language']) and $params['language'] === FALSE) {
             unset($params['language']);
         }
         if (isset($params['include_adult'])) {
             $params['include_adult'] = $params['include_adult'] ? 'true' : 'false';
         }
         $url .= !empty($params) ? '&' . http_build_query($params, '', '&') : '';
     }
     $results = '{}';
     if (extension_loaded('curl')) {
         $headers = array('Accept: application/json');
         $ch = curl_init();
         if ($method == TMDB::POST) {
             $json_string = json_encode($params);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string);
             $headers[] = 'Content-Type: application/json';
             $headers[] = 'Content-Length: ' . strlen($json_string);
         } elseif ($method == TMDb::HEAD) {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
             curl_setopt($ch, CURLOPT_NOBODY, 1);
         }
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $this->incRequests();
         curl_setopt_array($ch, nzedb\utility\Misc::curlSslContextOptions());
         $response = curl_exec($ch);
         $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
         $header = substr($response, 0, $header_size);
         $body = substr($response, $header_size);
         $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $error_number = curl_errno($ch);
         $error_message = curl_error($ch);
         // If temp banned, you need to wait for 10 sec
         if ($http_status == 503 or $http_status == 0) {
             if ($this->_retries < 3) {
                 $this->_retries += 1;
                 echo "\nTMDB limits exceeded, sleeping for 10 seconds.";
                 usleep(10 * 1000 * 1000);
                 return $this->_makeCall($function, $params, $session_id, $method);
             }
         }
         $this->_retries = 0;
         if ($error_number > 0) {
             throw new TMDbException('Method failed: ' . $function . ' - HTTP Status ' . $http_status . ' Curl Errno ' . $error_number . ' Curl Error ' . $error_message);
         }
         curl_close($ch);
     } else {
         throw new TMDbException('CURL-extension not loaded');
     }
     $results = json_decode($body, TRUE);
     if (strpos($function, 'authentication/token/new') !== FALSE) {
         $parsed_headers = $this->_http_parse_headers($header);
         $results['Authentication-Callback'] = $parsed_headers['Authentication-Callback'];
     }
     if ($results !== NULL) {
         return $results;
     } elseif ($method == TMDb::HEAD) {
         return $this->_http_parse_headers($header);
     } else {
         throw new TMDbException('Server error on "' . $url . '": ' . $response);
     }
 }
Пример #3
0
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\NZB;
use nzedb\db\Settings;
$pdo = new Settings();
if (isset($argv[1]) && $argv[1] == "true") {
    $timestart = time();
    $nzbcount = $brokencount = 0;
    $guids = $pdo->queryDirect("SELECT guid FROM releases WHERE nzbstatus = 1 ORDER BY postdate DESC");
    echo $pdo->log->primary("Be patient, this WILL take a very long time, make sure to kill all nZEDb scripts first. There are " . number_format($guids->rowCount()) . " NZB files to scan.");
    $nzb = new NZB($pdo);
    if ($guids instanceof \Traversable) {
        foreach ($guids as $guid) {
            $nzbpath = $nzb->NZBPath($guid["guid"]);
            if ($nzbpath !== false) {
                $nzbcount++;
                $nzbfile = nzedb\utility\Misc::unzipGzipFile($nzbpath);
                if ($nzbfile && preg_match('/^[\\r\\n]+<\\?xml/', $nzbfile)) {
                    $brokencount++;
                    $nzbfile = preg_replace('/^[\\r\\n]+<\\?xml/i', '<?xml', $nzbfile);
                    $nzb = preg_replace('/<\\/nzb>.+/i', '</nzb>', $nzbfile);
                    unlink($nzbpath);
                    $fp = gzopen($nzbpath, 'w6');
                    if ($fp) {
                        gzwrite($fp, $nzb, strlen($nzb));
                        gzclose($fp);
                        chmod($nzbpath, 0777);
                    }
                }
                if ($nzbcount % 5000 == 0) {
                    echo $nzbcount . " NZBs scanned. " . $brokencount . " NZBs fixed. " . (TIME() - $timestart) . " seconds.\n";
                } else {
Пример #4
0
 private static function check_bin($binPath = '')
 {
     $binPath = $binPath ?: '/usr/bin/git';
     $resource = proc_open('which git', [1 => ['pipe', 'w']], $pipes);
     $stdout = stream_get_contents($pipes[1]);
     foreach ($pipes as $pipe) {
         fclose($pipe);
     }
     $status = trim(proc_close($resource));
     if (!$status) {
         $binPath = trim($stdout);
     }
     if (strpos($binPath, ' ') !== false) {
         $binPath = nzedb\utility\Misc::isWin() ? '"' . $binPath . '"' : str_replace(' ', '\\ ', $binPath);
     }
     self::set_bin($binPath);
     return $binPath;
 }
Пример #5
0
    foreach ($check as $type) {
        switch ($type) {
            case R:
                readable($folder);
                break;
            case W:
                writable($folder);
                break;
            case E:
                executable($folder);
                break;
        }
    }
}
echo 'Your permissions seem right for this user. Note, this script does not verify all paths, only the most important ones.' . PHP_EOL;
if (!nzedb\utility\Misc::isWin()) {
    $user = posix_getpwuid(posix_geteuid());
    if ($user['name'] !== 'www-data') {
        echo 'If you have not already done so, please rerun this script using the www-data user: sudo -u www-data php verify_permissions.php yes' . PHP_EOL;
    }
}
function readable($folder)
{
    if (!is_readable($folder)) {
        exit('Error: This path is not readable: (' . $folder . ') resolve this and rerun the script.' . PHP_EOL);
    }
}
function writable($folder)
{
    if (!is_writable($folder)) {
        exit('Error: This path is not writable: (' . $folder . ') resolve this and rerun the script.' . PHP_EOL);
Пример #6
0
 /**
  * Connect to a NNTP server
  *
  * @param string $host          (optional) The address of the NNTP-server to connect to, defaults to 'localhost'.
  * @param mixed  $encryption    (optional) Use TLS/SSL on the connection?
  *                              (string) 'tcp'                 => Use no encryption.
  *                                       'ssl', 'sslv3', 'tls' => Use encryption.
  *                              (null)|(false) Use no encryption.
  * @param int    $port          (optional) The port number to connect to, defaults to 119.
  * @param int    $timeout       (optional) How many seconds to wait before giving up when connecting.
  * @param int    $socketTimeout (optional) How many seconds to wait before timing out the (blocked) socket.
  *
  * @return mixed (bool)   On success: True when posting allowed, otherwise false.
  *               (object) On failure: pear_error
  * @access protected
  */
 protected function connect($host = null, $encryption = null, $port = null, $timeout = 15, $socketTimeout = 120)
 {
     if ($this->_isConnected()) {
         return $this->throwError('Already connected, disconnect first!', null);
     }
     // v1.0.x API
     if (is_int($encryption)) {
         trigger_error('You are using deprecated API v1.0 in Net_NNTP_Protocol_Client: connect() !', E_USER_NOTICE);
         $port = $encryption;
         $encryption = false;
     }
     if (is_null($host)) {
         $host = 'localhost';
     }
     // Choose transport based on encryption, and if no port is given, use default for that encryption.
     switch ($encryption) {
         case null:
         case 'tcp':
         case false:
             $transport = 'tcp';
             $port = is_null($port) ? 119 : $port;
             break;
         case 'ssl':
         case 'tls':
             $transport = $encryption;
             $port = is_null($port) ? 563 : $port;
             break;
         default:
             $message = '$encryption parameter must be either tcp, tls, ssl.';
             trigger_error($message, E_USER_ERROR);
             return $this->throwError($message);
     }
     // Attempt to connect to usenet.
     $socket = stream_socket_client($transport . '://' . $host . ':' . $port, $errorNumber, $errorString, $timeout, STREAM_CLIENT_CONNECT, stream_context_create(nzedb\utility\Misc::streamSslContextOptions()));
     if ($socket === false) {
         $message = "Connection to {$transport}://{$host}:{$port} failed.";
         if (preg_match('/tls|ssl/', $transport)) {
             $message .= ' Try disabling SSL/TLS, and/or try a different port.';
         }
         $message .= ' [ERROR ' . $errorNumber . ': ' . $errorString . ']';
         if ($this->_logger) {
             $this->_logger->notice($message);
         }
         return $this->throwError($message);
     }
     // Store the socket resource as property.
     $this->_socket = $socket;
     $this->_socketTimeout = is_numeric($socketTimeout) ? $socketTimeout : $this->_socketTimeout;
     // Set the socket timeout.
     stream_set_timeout($this->_socket, $this->_socketTimeout);
     if ($this->_logger) {
         $this->_logger->info("Connection to {$transport}://{$host}:{$port} has been established.");
     }
     // Retrieve the server's initial response.
     $response = $this->_getStatusResponse();
     if ($this->isError($response)) {
         return $response;
     }
     switch ($response) {
         // 200, Posting allowed
         case NET_NNTP_PROTOCOL_RESPONSECODE_READY_POSTING_ALLOWED:
             // TODO: Set some variable before return
             return true;
             // 201, Posting NOT allowed
         // 201, Posting NOT allowed
         case NET_NNTP_PROTOCOL_RESPONSECODE_READY_POSTING_PROHIBITED:
             if ($this->_logger) {
                 $this->_logger->info('Posting not allowed!');
             }
             // TODO: Set some variable before return
             return false;
         default:
             return $this->_handleErrorResponse($response);
     }
 }
Пример #7
0
         $rage = ['releasetitle' => array_shift($seriesnames), 'description' => array_shift($seriesdescription), 'country' => array_shift($seriescountry), 'genre' => array_shift($seriesgenre), 'imgdata' => array_shift($seriesimg), 'id' => array_shift($seriesid)];
     }
 }
 if ($data['anidbid'] > 0) {
     $AniDB = new AniDB(['Settings' => $releases->pdo]);
     $ani = $AniDB->getAnimeInfo($data['anidbid']);
 }
 if ($data['imdbid'] != '' && $data['imdbid'] != 00) {
     $movie = new Movie(['Settings' => $page->settings]);
     $mov = $movie->getMovieInfo($data['imdbid']);
     $trakt = new TraktTv(['Settings' => $page->settings]);
     $traktSummary = $trakt->movieSummary('tt' . $data['imdbid'], 'full');
     if ($traktSummary !== false && isset($traktSummary['trailer']) && $traktSummary['trailer'] !== '' && preg_match('/[\\/?]v[\\/\\=](\\w+)$/i', $traktSummary['trailer'], $youtubeM)) {
         $mov['trailer'] = '<embed width="480" height="345" src="' . 'https://www.youtube.com/v/' . $youtubeM[1] . '" type="application/x-shockwave-flash"></embed>';
     } else {
         $mov['trailer'] = nzedb\utility\Misc::imdb_trailers($data['imdbid']);
     }
     if ($mov && isset($mov['title'])) {
         $mov['title'] = str_replace(['/', '\\'], '', $mov['title']);
         $mov['actors'] = $movie->makeFieldLinks($mov, 'actors');
         $mov['genre'] = $movie->makeFieldLinks($mov, 'genre');
         $mov['director'] = $movie->makeFieldLinks($mov, 'director');
     } else {
         if ($traktSummary !== false) {
             $mov['title'] = str_replace(['/', '\\'], '', $traktSummary['title']);
         } else {
             $mov = false;
         }
     }
 }
 if ($data['xxxinfo_id'] != '' && $data['xxxinfo_id'] != 0) {
Пример #8
0
 /**
  * @param        $region
  * @param        $params
  * @param        $public_key
  * @param        $private_key
  * @param string $associate_tag
  *
  * @return bool|SimpleXMLElement|string
  */
 private function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = "")
 {
     if ($public_key !== "" && $private_key !== "" && $associate_tag !== "") {
         $method = "GET";
         // Must be in small case.
         $host = "ecs.amazonaws." . $region;
         $uri = "/onca/xml";
         $params["Service"] = "AWSECommerceService";
         $params["AWSAccessKeyId"] = $public_key;
         $params["AssociateTag"] = $associate_tag;
         $params["Timestamp"] = gmdate("Y-m-d\\TH:i:s\\Z");
         $params["Version"] = "2009-03-31";
         /* The params need to be sorted by the key, as Amazon does this at
         			their end and then generates the hash of the same. If the params
         			are not in order then the generated hash will be different thus
         			failing the authetication process.
         			*/
         ksort($params);
         $canonicalized_query = array();
         foreach ($params as $param => $value) {
             $param = str_replace("%7E", "~", rawurlencode($param));
             $value = str_replace("%7E", "~", rawurlencode($value));
             $canonicalized_query[] = $param . "=" . $value;
         }
         $canonicalized_query = implode("&", $canonicalized_query);
         $string_to_sign = $method . "\n" . $host . "\n" . $uri . "\n" . $canonicalized_query;
         /* Calculate the signature using HMAC with SHA256 and base64-encoding.
          * The 'hash_hmac' function is only available from PHP 5 >= 5.1.2.
          */
         $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
         // Encode the signature for the request.
         $signature = str_replace("%7E", "~", rawurlencode($signature));
         // Create request.
         $request = "http://" . $host . $uri . "?" . $canonicalized_query . "&Signature=" . $signature;
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $request);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt_array($ch, nzedb\utility\Misc::curlSslContextOptions());
         $xml_response = curl_exec($ch);
         if ($xml_response === False) {
             return False;
         } else {
             // Parse XML.
             $parsed_xml = @simplexml_load_string($xml_response);
             return $parsed_xml === False ? False : $parsed_xml;
         }
     } else {
         return "missingkey";
     }
 }