/** * Class constructor initialises the SimpleXML object and sets a few properties. * @param string $filepath Optional filespec for the XML file to use. Will use default otherwise. * @throws \Exception If the XML is invalid. */ public function __construct($filepath = null) { if (empty($filepath)) { if (defined('nZEDb_VERSIONS')) { $filepath = nZEDb_VERSIONS; } } if (!file_exists($filepath)) { throw new \RuntimeException("Versions file '{$filepath}' does not exist!'"); } $this->_filespec = $filepath; $this->out = new \ColorCLI(); $this->git = new Git(); $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 ({nZEDb_VERSIONS}) 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('/nzedb/versions'); if ($vers[0]->count() == 0) { $this->out->error("Your versions XML file ({nZEDb_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 ({nZEDb_VERSIONS}) looks okay, continuing."); $this->_vers =& $this->_xml->versions; } } else { throw new \RuntimeException("No elements in file!\n"); } }
/** * 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_SYSTEM') ? DB_SYSTEM : '', '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('nZEDb_CACHE_TYPE') && nZEDb_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 = nZEDb_DEBUG || nZEDb_LOGGING; if ($this->_debug) { try { $this->debugging = new \Logger(['ColorCLI' => $this->log]); } catch (\LoggerException $error) { $this->_debug = false; } } if ($this->opts['checkVersion']) { $this->fetchDbVersion(); } return $this->pdo; }
* 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 2015 nZEDb */ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php'; use nzedb\db\DbUpdate; use nzedb\utility\Git; use nzedb\utility\Utility; if (!Utility::isCLI()) { exit; } $error = false; $git = new Git(); $branch = $git->active_branch(); if (in_array($branch, $git->mainBranches())) { // Only update patches, etc. on specific branches to lessen conflicts try { // Run DbUpdates to make sure we're up to date. $DbUpdater = new DbUpdate(['git' => $git]); $DbUpdater->newPatches(['safe' => false]); } catch (\Exception $e) { $error = 1; echo "Error while checking patches!\n"; echo $e->getMessage() . "\n";
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]); }
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('/nzedb/versions'); if ($vers[0]->count() == 0) { $this->out->error("Your versions XML file ({nZEDb_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 ({nZEDb_VERSIONS}) looks okay, continuing."); $this->_vers =& $this->_xml->versions; } } else { throw new \RuntimeException("No elements in file!\n"); } return $this->_xml; }
<?php require_once './config.php'; use nzedb\NZBExport; use nzedb\Releases; use nzedb\utility\Utility; if (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');
<?php require_once './config.php'; require_once nZEDb_LIB . 'utility' . DS . 'Utility.php'; if (\nzedb\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(array($path, $postFrom, $postTo, $group, $gzip)); } else { $retVal = 'Error, a path is required!'; } $page->smarty->assign(array('folder' => $path, 'output' => $retVal, 'fromdate' => $postFrom, 'todate' => $postTo, 'group' => $_POST["group"], 'gzip' => $_POST["gzip"])); } else { $page->smarty->assign(array('fromdate' => $rel->getEarliestUsenetPostDate(), 'todate' => $rel->getLatestUsenetPostDate())); } $page->title = "Export Nzbs"; $page->smarty->assign(array('gziplist' => array(1 => 'True', 0 => 'False'), 'grouplist' => $rel->getReleasedGroupsForSelect(true))); $page->content = $page->smarty->fetch('nzb-export.tpl'); $page->render();