コード例 #1
0
ファイル: TMDb.php プロジェクト: sebst3r/nZEDb
 /**
  * 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\Utility::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);
     }
 }
コード例 #2
0
ファイル: GiantBombAPI.php プロジェクト: sebst3r/nZEDb
 /**
  * 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\Utility::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;
 }
コード例 #3
0
ファイル: clean_nzbs.php プロジェクト: Jay204/nZEDb
use nzedb\db\Settings;
$pdo = new Settings();
if (isset($argv[1]) && ($argv[1] === "true" || $argv[1] === "delete")) {
    $releases = new Releases(['Settings' => $pdo]);
    $nzb = new NZB($pdo);
    $releaseImage = new ReleaseImage($pdo);
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $timestart = time();
    $checked = $deleted = 0;
    $couldbe = $argv[1] === "true" ? $couldbe = "could be " : "were ";
    echo $pdo->log->header('Getting List of nzbs to check against db.');
    $dirItr = new RecursiveDirectoryIterator($pdo->getSetting('nzbpath'));
    $itr = new RecursiveIteratorIterator($dirItr, RecursiveIteratorIterator::LEAVES_ONLY);
    foreach ($itr as $filePath) {
        if (is_file($filePath) && preg_match('/([a-f-0-9]+)\\.nzb\\.gz/', $filePath, $guid)) {
            $nzbfile = nzedb\utility\Utility::unzipGzipFile($filePath);
            if ($nzbfile) {
                $nzbfile = @simplexml_load_string($nzbfile);
            }
            if ($nzbfile) {
                $res = $pdo->queryOneRow(sprintf("SELECT id, guid FROM releases WHERE guid = %s", $pdo->escapeString(stristr($filePath->getFilename(), '.nzb.gz', true))));
                if ($res === false) {
                    if ($argv[1] === "delete") {
                        @copy($filePath, nZEDb_ROOT . "pooped/" . $guid[1] . ".nzb.gz");
                        $releases->deleteSingle(['g' => $guid[1], 'i' => false], $nzb, $releaseImage);
                        $deleted++;
                    }
                } else {
                    if (isset($res)) {
                        $pdo->queryExec(sprintf("UPDATE releases SET nzbstatus = 1 WHERE id = %s", $res['id']));
                    }
コード例 #4
0
ファイル: automated.config.php プロジェクト: sebst3r/nZEDb
    define('nZEDb_LOGAUTOLOADER', false);
    define('nZEDb_QUERY_STRIP_WHITESPACE', false);
    define('nZEDb_RENAME_PAR2', true);
    define('nZEDb_RENAME_MUSIC_MEDIAINFO', true);
    define('nZEDb_CACHE_EXPIRY_SHORT', 300);
    define('nZEDb_CACHE_EXPIRY_MEDIUM', 600);
    define('nZEDb_CACHE_EXPIRY_LONG', 900);
    define('nZEDb_PREINFO_OPEN', false);
    define('nZEDb_FLOOD_CHECK', false);
    define('nZEDb_FLOOD_WAIT_TIME', 5);
    define('nZEDb_FLOOD_MAX_REQUESTS_PER_SECOND', 5);
    define('nZEDb_USE_SQL_TRANSACTIONS', true);
    define('nZEDb_RELEASE_SEARCH_TYPE', 0);
    define('nZEDb_MAX_PAGER_RESULTS', '125000');
}
unset($settings_file);
require_once nZEDb_CORE . 'autoloader.php';
require_once nZEDb_LIBS . 'autoloader.php';
require_once SMARTY_DIR . 'autoloader.php';
define('HAS_WHICH', nzedb\utility\Utility::hasWhich() ? true : false);
if (file_exists(__DIR__ . DS . 'config.php')) {
    require_once __DIR__ . DS . 'config.php';
}
// Check if they updated config.php for the openssl changes. Only check 1 to save speed.
if (!defined('nZEDb_SSL_VERIFY_PEER')) {
    define('nZEDb_SSL_CAFILE', '');
    define('nZEDb_SSL_CAPATH', '');
    define('nZEDb_SSL_VERIFY_PEER', '0');
    define('nZEDb_SSL_VERIFY_HOST', '0');
    define('nZEDb_SSL_ALLOW_SELF_SIGNED', '1');
}
コード例 #5
0
ファイル: verify_permissions.php プロジェクト: Jay204/nZEDb
    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\Utility::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
ファイル: Client.php プロジェクト: sebst3r/nZEDb
 /**
  * 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\Utility::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
ファイル: AmazonProductAPI.php プロジェクト: sebst3r/nZEDb
 /**
  * @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\Utility::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";
     }
 }
コード例 #8
0
ファイル: export_settings.php プロジェクト: Jay204/nZEDb
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\db\Settings;
// TODO make this platform agnostic
passthru("clear");
$pdo = new Settings();
if (!isset($argv[1]) || isset($argv[1]) && $argv[1] != "site" && $argv[1] != "tmux") {
    exit($pdo->log->error("\nThis script will output the setting of your site-edit or tmux-edit page to share with others. This will ouptut directly to web using pastebinit. This does not post any private information.\nTo run:\nphp export_settings.php [site, tmux] [tabbed, html, csv]\n"));
}
if (!nzedb\utility\Utility::hasCommand('pastebinit')) {
    exit($pdo->log->error("This script requires pastebinit, but it's not installed. Aborting.\n"));
}
switch (strtolower($argv[1])) {
    case 'site':
        $sql = "SELECT * FROM settings WHERE setting NOT LIKE '%key%' AND setting NOT LIKE '%google%' AND setting NOT LIKE '%seed%' AND setting NOT LIKE '%amazon%' AND setting != 'saburl' AND setting != 'adheader' AND setting != 'adbrowse' AND setting != 'addetail' AND setting != 'request_url'";
        break;
    case 'tmux':
        $sql = 'SELECT * FROM tmux';
        break;
    default:
        $sql = '';
}
if ($sql != '') {
    $output = '';
    $style = isset($argv[2]) ? strtolower($argv[2]) : '';
    switch ($style) {
        case 'html':
            $mask = "\t\t<tr><td>%s</td><td>%s</td></tr>\n";
            $output = "<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<th>Setting</th>\n\t\t\t<th>Value</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n";
            break;
コード例 #9
0
ファイル: Nfo.php プロジェクト: Jay204/nZEDb
 /**
  * Confirm this is an NFO file.
  *
  * @param string $possibleNFO The nfo.
  * @param string $guid        The guid of the release.
  *
  * @return bool               True on success, False on failure.
  *
  * @access public
  */
 public function isNFO(&$possibleNFO, $guid)
 {
     if ($possibleNFO === false) {
         return false;
     }
     // Make sure it's not too big or small, size needs to be at least 12 bytes for header checking. Ignore common file types.
     $size = strlen($possibleNFO);
     if ($size < 65535 && $size > 11 && !preg_match('/\\A(\\s*<\\?xml|=newz\\[NZB\\]=|RIFF|\\s*[RP]AR|.{0,10}(JFIF|matroska|ftyp|ID3))|;\\s*Generated\\s*by.*SF\\w/i', $possibleNFO)) {
         // File/GetId3 work with files, so save to disk.
         $tmpPath = $this->tmpPath . $guid . '.nfo';
         file_put_contents($tmpPath, $possibleNFO);
         // Linux boxes have 'file' (so should Macs), Windows *can* have it too: see GNUWIN.txt in docs.
         if (nzedb\utility\Utility::hasCommand('file')) {
             exec('file -b "' . $tmpPath . '"', $result);
             if (is_array($result)) {
                 if (count($result) > 1) {
                     $result = implode(',', $result[0]);
                 } else {
                     $result = $result[0];
                 }
             }
             // Check if it's text.
             if (preg_match('/(ASCII|ISO-8859|UTF-(8|16|32).*?)\\s*text/', $result)) {
                 @unlink($tmpPath);
                 return true;
                 // Or binary.
             } else {
                 if (preg_match('/^(JPE?G|Parity|PNG|RAR|XML|(7-)?[Zz]ip)/', $result) || preg_match('/[\\x00-\\x08\\x12-\\x1F\\x0B\\x0E\\x0F]/', $possibleNFO)) {
                     @unlink($tmpPath);
                     return false;
                 }
             }
         }
         // If above checks couldn't  make a categorical identification, Use GetId3 to check if it's an image/video/rar/zip etc..
         $getid3 = new getid3();
         $check = $getid3->analyze($tmpPath);
         @unlink($tmpPath);
         if (isset($check['error'])) {
             // Check if it's a par2.
             $par2info = new Par2Info();
             $par2info->setData($possibleNFO);
             if ($par2info->error) {
                 // Check if it's an SFV.
                 $sfv = new SfvInfo();
                 $sfv->setData($possibleNFO);
                 if ($sfv->error) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
コード例 #10
0
ファイル: NZBImport.php プロジェクト: Jay204/nZEDb
 /**
  * @param array $filesToProcess List of NZB files to import.
  * @param bool|string $useNzbName Use the NZB file name as release name?
  * @param bool $delete Delete the NZB when done?
  * @param bool $deleteFailed Delete the NZB if failed importing?
  *
  * @return string|bool
  *
  * @access public
  */
 public function beginImport($filesToProcess, $useNzbName = false, $delete = true, $deleteFailed = true)
 {
     // Get all the groups in the DB.
     if (!$this->getAllGroups()) {
         if ($this->browser) {
             return $this->retVal;
         } else {
             return false;
         }
     }
     $start = date('Y-m-d H:i:s');
     $nzbsImported = $nzbsSkipped = 0;
     // Loop over the file names.
     foreach ($filesToProcess as $nzbFile) {
         // Check if the file is really there.
         if (is_file($nzbFile)) {
             // Get the contents of the NZB file as a string.
             if (strtolower(substr($nzbFile, -7)) === '.nzb.gz') {
                 $nzbString = nzedb\utility\Utility::unzipGzipFile($nzbFile);
             } else {
                 $nzbString = file_get_contents($nzbFile);
             }
             if ($nzbString === false) {
                 $this->echoOut('ERROR: Unable to read: ' . $nzbFile);
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
             // Load it as a XML object.
             $nzbXML = @simplexml_load_string($nzbString);
             if ($nzbXML === false || strtolower($nzbXML->getName()) != 'nzb') {
                 $this->echoOut('ERROR: Unable to load NZB XML data: ' . $nzbFile);
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
             // Try to insert the NZB details into the DB.
             $inserted = $this->scanNZBFile($nzbXML, $useNzbName ? str_ireplace('.nzb', '', basename($nzbFile)) : false);
             if ($inserted) {
                 // Try to copy the NZB to the NZB folder.
                 $path = $this->nzb->getNZBPath($this->relGuid, 0, true);
                 // Try to compress the NZB file in the NZB folder.
                 $fp = gzopen($path, 'w5');
                 gzwrite($fp, $nzbString);
                 gzclose($fp);
                 if (!is_file($path)) {
                     $this->echoOut('ERROR: Problem compressing NZB file to: ' . $path);
                     // Remove the release.
                     $this->pdo->queryExec(sprintf("DELETE FROM releases WHERE guid = %s", $this->pdo->escapeString($this->relGuid)));
                     if ($deleteFailed) {
                         @unlink($nzbFile);
                     }
                     $nzbsSkipped++;
                     continue;
                 } else {
                     if ($delete) {
                         // Remove the nzb file.
                         @unlink($nzbFile);
                     }
                     $nzbsImported++;
                     continue;
                 }
             } else {
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
         } else {
             $this->echoOut('ERROR: Unable to fetch: ' . $nzbFile);
             $nzbsSkipped++;
             continue;
         }
     }
     $this->echoOut('Proccessed ' . $nzbsImported . ' NZBs in ' . (strtotime(date('Y-m-d H:i:s')) - strtotime($start)) . ' seconds, ' . $nzbsSkipped . ' NZBs were skipped.');
     if ($this->browser) {
         return $this->retVal;
     } else {
         return true;
     }
 }
コード例 #11
0
ファイル: details.php プロジェクト: sebst3r/nZEDb
         $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->traktMoviesummary('tt' . $data['imdbid'], true);
     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\Utility::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) {
コード例 #12
0
ファイル: release-files.php プロジェクト: Jay204/nZEDb
<?php

require_once './config.php';
$page = new AdminPage();
if (!$page->users->isLoggedIn()) {
    $page->show403();
}
if (isset($_GET['id'])) {
    $releases = new Releases(['Settings' => $page->settings]);
    $release = $releases->getByGuid($_GET['id']);
    if ($release === false) {
        $page->show404();
    }
    $nzb = new NZB($page->settings);
    $nzbPath = $nzb->getNZBPath($_GET['id']);
    if (!file_exists($nzbPath)) {
        $page->show404();
    }
    $nzbFile = nzedb\utility\Utility::unzipGzipFile($nzbPath);
    $files = $nzb->nzbFileList($nzbFile);
    $page->smarty->assign('release', $release);
    $page->smarty->assign('files', $files);
    $page->title = "File List";
    $page->meta_title = "View Nzb file list";
    $page->meta_keywords = "view,nzb,file,list,description,details";
    $page->meta_description = "View Nzb File List";
    $page->content = $page->smarty->fetch('release-files.tpl');
    $page->render();
}
コード例 #13
0
ファイル: Git.php プロジェクト: sebst3r/nZEDb
 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\Utility::isWin() ? '"' . $binPath . '"' : str_replace(' ', '\\ ', $binPath);
     }
     self::set_bin($binPath);
     return $binPath;
 }
コード例 #14
0
ファイル: NZBContents.php プロジェクト: Jay204/nZEDb
 /**
  * Decompress a NZB, load it into simplexml and return.
  *
  * @param string $guid Release guid.
  *
  * @return bool|SimpleXMLElement
  *
  * @access public
  */
 public function LoadNZB(&$guid)
 {
     // Fetch the NZB location using the GUID.
     $nzbPath = $this->nzb->NZBPath($guid);
     if ($nzbPath === false) {
         if ($this->echooutput) {
             echo PHP_EOL . $guid . ' appears to be missing the nzb file, skipping.' . PHP_EOL;
         }
         return false;
     }
     $nzbContents = nzedb\utility\Utility::unzipGzipFile($nzbPath);
     if (!$nzbContents) {
         if ($this->echooutput) {
             echo PHP_EOL . 'Unable to decompress: ' . $nzbPath . ' - ' . fileperms($nzbPath) . ' - may have bad file permissions, skipping.' . PHP_EOL;
         }
         return false;
     }
     $nzbFile = @simplexml_load_string($nzbContents);
     if (!$nzbFile) {
         if ($this->echooutput) {
             echo PHP_EOL . "Unable to load NZB: {$guid} appears to be an invalid NZB, skipping." . PHP_EOL;
         }
         return false;
     }
     return $nzbFile;
 }
コード例 #15
0
ファイル: NZBGet.php プロジェクト: Jay204/nZEDb
    /**
     * Send a NZB to NZBGet.
     *
     * @param string $guid Release identifier.
     *
     * @return bool|mixed
     *
     * @access public
     */
    public function sendNZBToNZBGet($guid)
    {
        $relData = $this->Releases->getByGuid($guid);
        $string = nzedb\utility\Utility::unzipGzipFile($this->NZB->getNZBPath($guid));
        $string = $string === false ? '' : $string;
        $header = '<?xml version="1.0"?>
			<methodCall>
				<methodName>append</methodName>
				<params>
					<param>
						<value><string>' . $relData['searchname'] . '</string></value>
					</param>
					<param>
						<value><string>' . $relData['category_name'] . '</string></value>
					</param>
					<param>
						<value><i4>0</i4></value>
					</param>
					<param>
						<value><boolean>>False</boolean></value>
					</param>
					<param>
						<value>
							<string>' . base64_encode($string) . '</string>
						</value>
					</param>
				</params>
			</methodCall>';
        nzedb\utility\getUrl($this->fullURL . 'append', 'post', $header);
    }
コード例 #16
0
ファイル: Releases.php プロジェクト: Jay204/nZEDb
 /**
  * @param $guids
  *
  * @return string
  */
 public function getZipped($guids)
 {
     $nzb = new NZB($this->pdo);
     $zipFile = new ZipFile();
     foreach ($guids as $guid) {
         $nzbPath = $nzb->NZBPath($guid);
         if ($nzbPath) {
             $nzbContents = nzedb\utility\Utility::unzipGzipFile($nzbPath);
             if ($nzbContents) {
                 $filename = $guid;
                 $r = $this->getByGuid($guid);
                 if ($r) {
                     $filename = $r['searchname'];
                 }
                 $zipFile->addFile($nzbContents, $filename . '.nzb');
             }
         }
     }
     return $zipFile->file();
 }
コード例 #17
0
ファイル: populate_nzb_guid.php プロジェクト: Jay204/nZEDb
function create_guids($live, $delete = false)
{
    $pdo = new Settings();
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $timestart = TIME();
    $relcount = $deleted = $total = 0;
    $relrecs = false;
    if ($live == "true") {
        $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC"));
    } else {
        if ($live == "limited") {
            $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000"));
        }
    }
    if ($relrecs) {
        $total = $relrecs->rowCount();
    }
    if ($total > 0) {
        echo $pdo->log->header("Creating nzb_guids for " . number_format($total) . " releases.");
        $releases = new Releases(['Settings' => $pdo]);
        $nzb = new NZB($pdo);
        $releaseImage = new ReleaseImage($pdo);
        $reccnt = 0;
        if ($relrecs instanceof Traversable) {
            foreach ($relrecs as $relrec) {
                $reccnt++;
                $nzbpath = $nzb->NZBPath($relrec['guid']);
                if ($nzbpath !== false) {
                    $nzbfile = nzedb\utility\Utility::unzipGzipFile($nzbpath);
                    if ($nzbfile) {
                        $nzbfile = @simplexml_load_string($nzbfile);
                    }
                    if (!$nzbfile) {
                        if (isset($delete) && $delete == 'delete') {
                            //echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n";
                            $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                            $deleted++;
                        }
                        continue;
                    }
                    $binary_names = array();
                    foreach ($nzbfile->file as $file) {
                        $binary_names[] = $file["subject"];
                    }
                    if (count($binary_names) == 0) {
                        if (isset($delete) && $delete == 'delete') {
                            //echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n";
                            $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                            $deleted++;
                        }
                        continue;
                    }
                    asort($binary_names);
                    foreach ($nzbfile->file as $file) {
                        if ($file["subject"] == $binary_names[0]) {
                            $segment = $file->segments->segment;
                            $nzb_guid = md5($segment);
                            $pdo->queryExec("UPDATE releases set nzb_guid = " . $pdo->escapestring($nzb_guid) . " WHERE id = " . $relrec["id"]);
                            $relcount++;
                            $consoletools->overWritePrimary("Created: [" . $deleted . "] " . $consoletools->percentString($reccnt, $total) . " Time:" . $consoletools->convertTimer(TIME() - $timestart));
                            break;
                        }
                    }
                } else {
                    if (isset($delete) && $delete == 'delete') {
                        //echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting.");
                        $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                    }
                }
            }
        }
        if ($relcount > 0) {
            echo "\n";
        }
        echo $pdo->log->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart));
    } else {
        echo $pdo->log->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart));
        exit($pdo->log->info("No releases are missing the guid."));
    }
}
コード例 #18
0
ファイル: NZBExport.php プロジェクト: Jay204/nZEDb
 /**
  * Export to user specified folder.
  *
  * @param array $params
  *
  * @return bool
  *
  * @access public
  */
 public function beginExport($params)
 {
     $gzip = false;
     if ($params[4] === true) {
         $gzip = true;
     }
     $fromDate = $toDate = '';
     $path = $params[0];
     // Check if the path ends with dir separator.
     if (substr($path, -1) !== DS) {
         $path .= DS;
     }
     // Check if it's a directory.
     if (!is_dir($path)) {
         $this->echoOut('Folder does not exist: ' . $path);
         return $this->returnValue();
     }
     // Check if we can write to it.
     if (!is_writable($path)) {
         $this->echoOut('Folder is not writable: ' . $path);
         return $this->returnValue();
     }
     // Check if the from date is the proper format.
     if (isset($params[1]) && $params[1] !== '') {
         if (!$this->checkDate($params[1])) {
             return $this->returnValue();
         }
         $fromDate = $params[1];
     }
     // Check if the to date is the proper format.
     if (isset($params[2]) && $params[2] !== '') {
         if (!$this->checkDate($params[2])) {
             return $this->returnValue();
         }
         $toDate = $params[2];
     }
     // Check if the group_id exists.
     if (isset($params[3]) && $params[3] !== 0) {
         if (!is_numeric($params[3])) {
             $this->echoOut('The group ID is not a number: ' . $params[3]);
             return $this->returnValue();
         }
         $groups = $this->pdo->query('SELECT id, name FROM groups WHERE id = ' . $params[3]);
         if (count($groups) === 0) {
             $this->echoOut('The group ID is not in the DB: ' . $params[3]);
             return $this->returnValue();
         }
     } else {
         $groups = $this->pdo->query('SELECT id, name FROM groups');
     }
     $exported = 0;
     // Loop over groups to take less RAM.
     foreach ($groups as $group) {
         $currentExport = 0;
         // Get all the releases based on the parameters.
         $releases = $this->releases->getForExport($fromDate, $toDate, $group['id']);
         $totalFound = count($releases);
         if ($totalFound === 0) {
             if ($this->echoCLI) {
                 echo 'No releases found to export for group: ' . $group['name'] . PHP_EOL;
             }
             continue;
         }
         if ($this->echoCLI) {
             echo 'Found ' . $totalFound . ' releases to export for group: ' . $group['name'] . PHP_EOL;
         }
         // Create a path to store the new NZB files.
         $currentPath = $path . $this->safeFilename($group['name']) . DS;
         if (!is_dir($currentPath)) {
             mkdir($currentPath);
         }
         foreach ($releases as $release) {
             // Get path to the NZB file.
             $nzbFile = $this->nzb->NZBPath($release["guid"]);
             // Check if it exists.
             if ($nzbFile === false) {
                 if ($this->echoCLI) {
                     echo 'Unable to find NZB for release with GUID: ' . $release['guid'];
                 }
                 continue;
             }
             // Create path to current file.
             $currentFile = $currentPath . $this->safeFilename($release['searchname']);
             // Check if the user wants them in gzip, copy it if so.
             if ($gzip) {
                 if (!copy($nzbFile, $currentFile . '.nzb.gz')) {
                     if ($this->echoCLI) {
                         echo 'Unable to export NZB with GUID: ' . $release['guid'];
                     }
                     continue;
                 }
                 // If not, decompress it and create a file to store it in.
             } else {
                 $nzbContents = nzedb\utility\Utility::unzipGzipFile($nzbFile);
                 if (!$nzbContents) {
                     if ($this->echoCLI) {
                         echo 'Unable to export NZB with GUID: ' . $release['guid'];
                     }
                     continue;
                 }
                 $fh = fopen($currentFile . '.nzb', 'w');
                 fwrite($fh, $nzbContents);
                 fclose($fh);
             }
             $currentExport++;
             if ($this->echoCLI && $currentExport % 10 === 0) {
                 echo 'Exported ' . $currentExport . ' of ' . $totalFound . ' nzbs for group: ' . $group['name'] . "\r";
             }
         }
         if ($this->echoCLI && $currentExport > 0) {
             echo 'Exported ' . $currentExport . ' of ' . $totalFound . ' nzbs for group: ' . $group['name'] . PHP_EOL;
         }
         $exported += $currentExport;
     }
     if ($exported > 0) {
         $this->echoOut('Exported total of ' . $exported . ' NZB files to ' . $path);
     }
     return $this->returnValue();
 }