Esempio n. 1
0
 /**
  * Constructor. Sets up all necessary properties. Instantiates a \PDO object
  * if needed, otherwise returns the current one.
  */
 public function __construct(array $options = [])
 {
     $this->cli = Utility::isCLI();
     $defaults = ['checkVersion' => false, 'createDb' => false, 'ct' => new \ConsoleTools(), 'dbhost' => defined('DB_HOST') ? DB_HOST : '', 'dbname' => defined('DB_NAME') ? DB_NAME : '', 'dbpass' => defined('DB_PASSWORD') ? DB_PASSWORD : '', 'dbport' => defined('DB_PORT') ? DB_PORT : '', 'dbsock' => defined('DB_SOCKET') ? DB_SOCKET : '', 'dbtype' => defined('DB_TYPE') ? DB_TYPE : '', 'dbuser' => defined('DB_USER') ? DB_USER : '', 'log' => new \ColorCLI(), 'persist' => false];
     $options += $defaults;
     if (!$this->cli) {
         $options['log'] = null;
     }
     $this->opts = $options;
     if (!empty($this->opts['dbtype'])) {
         $this->dbSystem = strtolower($this->opts['dbtype']);
     }
     if (!$this->pdo instanceof \PDO) {
         $this->initialiseDatabase();
     }
     $this->cacheEnabled = defined('NN_CACHE_TYPE') && NN_CACHE_TYPE > 0 ? true : false;
     if ($this->cacheEnabled) {
         try {
             $this->cacheServer = new Cache();
         } catch (CacheException $error) {
             $this->cacheEnabled = false;
             $this->echoError($error->getMessage(), '__construct', 4);
         }
     }
     $this->ct = $this->opts['ct'];
     $this->log = $this->opts['log'];
     $this->_debug = NN_DEBUG || NN_LOGGING;
     if ($this->_debug) {
         try {
             $this->debugging = new \Logger(['ColorCLI' => $this->log]);
         } catch (\LoggerException $error) {
             $this->_debug = false;
         }
     }
     if ($this->opts['checkVersion']) {
         $this->fetchDbVersion();
     }
     if (defined('NN_SQL_DELETE_LOW_PRIORITY') && NN_SQL_DELETE_LOW_PRIORITY) {
         $this->DELETE_LOW_PRIORITY = ' LOW_PRIORITY ';
     }
     if (defined('NN_SQL_DELETE_QUICK') && NN_SQL_DELETE_QUICK) {
         $this->DELETE_QUICK = ' QUICK ';
     }
     return $this->pdo;
 }
Esempio n. 2
0
            case $fields['unrarpath'] != "" && !is_file($fields['unrarpath']):
                $error = Settings::ERR_BADUNRARPATH;
                break;
            case empty($fields['nzbpath']):
                $error = Settings::ERR_BADNZBPATH_UNSET;
                break;
            case !file_exists($fields['nzbpath']) || !is_dir($fields['nzbpath']):
                $error = Settings::ERR_BADNZBPATH;
                break;
            case !is_readable($fields['nzbpath']):
                $error = Settings::ERR_BADNZBPATH_UNREADABLE;
                break;
            case $fields['checkpasswordedrar'] == 1 && !is_file($fields['unrarpath']):
                $error = Settings::ERR_DEEPNOUNRAR;
                break;
            case $fields['tmpunrarpath'] != "" && !file_exists($fields['tmpunrarpath']):
                $error = Settings::ERR_BADTMPUNRARPATH;
                break;
            case $fields['yydecoderpath'] != "" && $fields['yydecoderpath'] !== 'simple_php_yenc_decode' && !file_exists($fields['yydecoderpath']):
                $error = Settings::ERR_BAD_YYDECODER_PATH;
        }
        return $error;
    }
}
/*
 * Putting procedural stuff inside class scripts like this is BAD. Do not use this as an excuse to do more.
 * This is a temporary measure until a proper frontend for cli stuff can be implemented with li3.
 */
if (Utility::isCLI() && isset($argv[1])) {
    echo (new Settings())->getSetting($argv[1]);
}
Esempio n. 3
0
<?php

require_once "config.php";
if (\newznab\utility\Utility::isCLI()) {
    exit('This script is only for exporting from the web, use the script in misc/testing' . PHP_EOL);
}
$page = new AdminPage();
$rel = new Releases(['Settings' => $page->settings]);
if ($page->isPostBack()) {
    $retVal = $path = '';
    $path = $_POST["folder"];
    $postFrom = isset($_POST["postfrom"]) ? $_POST["postfrom"] : '';
    $postTo = isset($_POST["postto"]) ? $_POST["postto"] : '';
    $group = $_POST["group"] === '-1' ? 0 : (int) $_POST["group"];
    $gzip = $_POST["gzip"] === '1' ? true : false;
    if ($path !== "") {
        $NE = new NZBExport(['Browser' => true, 'Settings' => $page->settings, 'Releases' => $rel]);
        $retVal = $NE->beginExport([$path, $postFrom, $postTo, $group, $gzip]);
    } else {
        $retVal = 'Error, a path is required!';
    }
    $page->smarty->assign(['folder' => $path, 'output' => $retVal, 'fromdate' => $postFrom, 'todate' => $postTo, 'group' => $_POST["group"], 'gzip' => $_POST["gzip"]]);
} else {
    $page->smarty->assign(['fromdate' => $rel->getEarliestUsenetPostDate(), 'todate' => $rel->getLatestUsenetPostDate()]);
}
$page->title = "Export Nzbs";
$page->smarty->assign(['gziplist' => [1 => 'True', 0 => 'False'], 'grouplist' => $rel->getReleasedGroupsForSelect(true)]);
$page->content = $page->smarty->fetch('nzb-export.tpl');
$page->render();
Esempio n. 4
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (see LICENSE.txt in the base directory.  If
 * not, see:
 *
 * @link <http://www.gnu.org/licenses/>.
 * @author niel
 * @copyright 2014 nZEDb
 */
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php';
require_once SMARTY_DIR . 'Smarty.class.php';
use newznab\db\DbUpdate;
use newznab\utility\Utility;
if (!Utility::isCLI()) {
    exit;
}
if (isset($argc) && $argc > 1 && isset($argv[1]) && $argv[1] == true) {
    $backup = isset($argv[2]) && $argv[2] == 'safe' ? true : false;
    $updater = new DbUpdate(['backup' => $backup]);
    echo $updater->log->header("Db updater starting ...");
    $patched = $updater->processPatches(['safe' => $backup]);
    if ($patched > 0) {
        echo $updater->log->info("{$patched} patch(es) applied.");
        $smarty = new Smarty();
        $cleared = $smarty->clearCompiledTemplate();
        if ($cleared) {
            $msg = "The smarty template cache has been cleaned for you\n";
        } else {
            $msg = "You should clear your smarty template cache at: " . SMARTY_DIR . "templates_c\n";
Esempio n. 5
0
 public function getValidVersionsFile($filepath = null)
 {
     $filepath = empty($filepath) ? $this->_filespec : $filepath;
     $temp = libxml_use_internal_errors(true);
     $this->_xml = simplexml_load_file($filepath);
     libxml_use_internal_errors($temp);
     if ($this->_xml === false) {
         if (Utility::isCLI()) {
             $this->out->error("Your versions XML file ({$filepath}) is broken, try updating from git.");
         }
         throw new \Exception("Failed to open versions XML file '{$filepath}'");
     }
     if ($this->_xml->count() > 0) {
         $vers = $this->_xml->xpath('/newznab/versions');
         if ($vers[0]->count() == 0) {
             $this->out->error("Your versions XML file ({NN_VERSIONS}) does not contain version info, try updating from git.");
             throw new \Exception("Failed to find versions node in XML file '{$filepath}'");
         } else {
             $this->out->primary("Your versions XML file ({NN_VERSIONS}) looks okay, continuing.");
             $this->_vers =& $this->_xml->versions;
         }
     } else {
         throw new \RuntimeException("No elements in file!\n");
     }
     return $this->_xml;
 }