Exemplo n.º 1
0
<?php

// Shitty script to check time/date in php mysql and system...
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\db\Settings;
use nzedb\utility\Misc;
$n = PHP_EOL;
// TODO change this to be able to use GnuWin
if (!nzedb\utility\Misc::isWin()) {
    echo 'These are the settings in your php.ini files:' . $n;
    echo 'CLI PHP timezone : ' . exec('cat /etc/php5/cli/php.ini | grep \'date.timezone =\' | cut -d \\  -f 3') . $n;
    echo 'apache2 timezone : ' . exec('cat /etc/php5/apache2/php.ini| grep \'date.timezone =\' | cut -d \\  -f 3') . $n;
}
$system = ' not supported on windows.';
$pdo = new Settings();
$MySQL = $pdo->queryOneRow('SELECT NOW() AS time, @@system_time_zone AS tz');
if (!Misc::isWin()) {
    $system = exec('date');
}
$php = date('D M d H:i:s T o');
$MySQL = date('D M d H:i:s T o', strtotime($MySQL['time'] . ' ' . $MySQL['tz']));
echo 'The various dates/times:' . $n;
echo 'System time      : ' . $system . $n;
echo 'MYSQL time       : ' . $MySQL . $n;
echo 'PHP time         : ' . $php . $n;
if ($MySQL === $system && $system === $php) {
    exit('Looks like all your dates/times are good.' . $n);
} else {
    exit('Looks like you have 1 or more dates/times set wrong.' . $n);
}
Exemplo n.º 2
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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 realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\db\PreDb;
use nzedb\utility\Misc;
if (!Misc::isWin()) {
    $canExeRead = Misc::canExecuteRead(nZEDb_RES);
    if (is_string($canExeRead)) {
        exit($canExeRead);
    }
    unset($canExeRead);
}
if (!isset($argv[1])) {
    $message = <<<HELP
This script can export a predb dump file. You may use the full path, or a relative path.
For exporting, the path must be writeable by mysql, any existing file [predb_dump.csv] will be overwritten.

php {$argv[0]} /path/to/write/to                     ...: To export.

HELP;
    exit($message);
Exemplo n.º 3
0
 public function loadTables(array $options = [])
 {
     $defaults = ['ext' => 'tsv', 'files' => [], 'path' => nZEDb_RES . 'db' . DS . 'schema' . DS . 'data', 'regex' => '#^' . Misc::PATH_REGEX . '(?P<order>\\d+)-(?P<table>\\w+)\\.tsv$#'];
     $options += $defaults;
     $show = Misc::isCLI() || nZEDb_DEBUG;
     $files = empty($options['files']) ? Misc::getDirFiles($options) : $options['files'];
     natsort($files);
     $local = $this->pdo->isLocalDb() ? '' : 'LOCAL ';
     $sql = 'LOAD DATA ' . $local . 'INFILE "%s" IGNORE INTO TABLE `%s` FIELDS TERMINATED BY "\\t" OPTIONALLY ENCLOSED BY "\\"" IGNORE 1 LINES (%s)';
     foreach ($files as $file) {
         if ($show === true) {
             echo "File: {$file}\n";
         }
         if (is_readable($file)) {
             if (preg_match($options['regex'], $file, $matches)) {
                 $table = $matches['table'];
                 // Get the first line of the file which holds the columns used.
                 $handle = @fopen($file, "r");
                 if (is_resource($handle)) {
                     $line = fgets($handle);
                     fclose($handle);
                     if ($line === false) {
                         echo "FAILED reading first line of '{$file}'\n";
                         continue;
                     }
                     $fields = trim($line);
                     if ($show === true) {
                         echo "Inserting data into table: '{$table}'\n";
                     }
                     if (Misc::isWin()) {
                         $file = str_replace("\\", '\\/', $file);
                     }
                     $this->pdo->exec(sprintf($sql, $file, $table, $fields));
                 } else {
                     exit("Failed to open file: '{$file}'\n");
                 }
             } else {
                 echo "Incorrectly formatted filename '{$file}' (should match " . str_replace('#', '', $options['regex']) . "\n";
             }
         } else {
             echo $this->log->error("  Unable to read file: '{$file}'");
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Check the Admin settings for yEnc and process them accordingly.
  *
  * @void
  *
  * @access protected
  */
 protected function _initiateYEncSettings()
 {
     // Check if the user wants to use yyDecode or the simple_php_yenc_decode extension.
     $this->_yyDecoderPath = $this->pdo->getSetting('yydecoderpath') != '' ? (string) $this->pdo->getSetting('yydecoderpath') : false;
     if (strpos((string) $this->_yyDecoderPath, 'simple_php_yenc_decode') !== false) {
         if (extension_loaded('simple_php_yenc_decode')) {
             $this->_yEncExtension = true;
         } else {
             $this->_yyDecoderPath = false;
         }
     } else {
         if ($this->_yyDecoderPath !== false) {
             $this->_yEncSilence = Misc::isWin() ? '' : ' > /dev/null 2>&1';
             $this->_yEncTempInput = nZEDb_TMP . 'yEnc' . DS;
             $this->_yEncTempOutput = $this->_yEncTempInput . 'output';
             $this->_yEncTempInput .= 'input';
             // Test if the user can read/write to the yEnc path.
             if (!is_file($this->_yEncTempInput)) {
                 @file_put_contents($this->_yEncTempInput, 'x');
             }
             if (!is_file($this->_yEncTempInput) || !is_readable($this->_yEncTempInput) || !is_writable($this->_yEncTempInput)) {
                 $this->_yyDecoderPath = false;
             }
             if (is_file($this->_yEncTempInput)) {
                 @unlink($this->_yEncTempInput);
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Constructor.
  *
  * @param array $options (Optional) Class instances.
  *                       (Optional) Folder to store log files in.
  *                       (Optional) Filename of log, must be alphanumeric (a-z 0-9) and contain no file extensions.
  *
  * @access public
  * @throws LoggerException
  */
 public function __construct(array $options = [])
 {
     if (!nZEDb_LOGGING && !nZEDb_DEBUG) {
         return;
     }
     $defaults = ['ColorCLI' => null, 'LogFolder' => '', 'LogFileName' => ''];
     $options += $defaults;
     $this->colorCLI = $options['ColorCLI'] instanceof ColorCLI ? $options['ColorCLI'] : new ColorCLI();
     $this->getSettings();
     $this->currentLogFolder = !empty($options['LogFolder']) ? $options['LogFolder'] : $this->currentLogFolder;
     $this->currentLogName = (!empty($options['LogFileName']) ? $options['LogFileName'] : $this->currentLogName) . '.log';
     $this->setLogFile();
     $this->outputCLI = strtolower(PHP_SAPI) === 'cli';
     $this->isWindows = Misc::isWin();
     $this->timeStart = time();
 }