/** * Returns article number based on # of days. * * @param int $days How many days back we want to go. * @param array $data Group data from usenet. * * @return string */ public function daytopost($days, $data) { $goalTime = time() - 86400 * $days; // The time we want = current unix time (ex. 1395699114) - minus 86400 (seconds in a day) // times days wanted. (ie 1395699114 - 2592000 (30days)) = 1393107114 // The servers oldest date. $firstDate = $this->postdate($data['first'], $data); if ($goalTime < $firstDate) { // If the date we want is older than the oldest date in the group return the groups oldest article. return $data['first']; } // The servers newest date. $lastDate = $this->postdate($data['last'], $data); if ($goalTime > $lastDate) { // If the date we want is newer than the groups newest date, return the groups newest article. return $data['last']; } if ($this->_echoCLI) { $this->_colorCLI->doEcho($this->_colorCLI->primary('Searching for an approximate article number for group ' . $data['group'] . ' ' . $days . ' days back.')); } // Pick the middle to start with $wantedArticle = round(($data['last'] + $data['first']) / 2); $aMax = $data['last']; $aMin = $data['first']; $reallyOldArticle = $oldArticle = $articleTime = null; while (true) { // Article exists outside of available range, this shouldn't happen if ($wantedArticle <= $data['first'] || $wantedArticle >= $data['last']) { break; } // Keep a note of the last articles we checked $reallyOldArticle = $oldArticle; $oldArticle = $wantedArticle; // Get the date of this article $articleTime = $this->postdate($wantedArticle, $data); // Article doesn't exist, start again with something random if (!$articleTime) { $wantedArticle = mt_rand($aMin, $aMax); $articleTime = $this->postdate($wantedArticle, $data); } if ($articleTime < $goalTime) { // Article is older than we want $aMin = $oldArticle; $wantedArticle = round(($aMax + $oldArticle) / 2); if ($this->_echoCLI) { echo '-'; } } else { if ($articleTime > $goalTime) { // Article is newer than we want $aMax = $oldArticle; $wantedArticle = round(($aMin + $oldArticle) / 2); if ($this->_echoCLI) { echo '+'; } } else { if ($articleTime == $goalTime) { // Exact match. We did it! (this will likely never happen though) break; } } } // We seem to be flip-flopping between 2 articles, assume we're out of articles to check. // End on an article more recent than our oldest so that we don't miss any releases. if ($reallyOldArticle == $wantedArticle && $goalTime - $articleTime <= 0) { break; } } $wantedArticle = (int) $wantedArticle; if ($this->_echoCLI) { $this->_colorCLI->doEcho($this->_colorCLI->primary(PHP_EOL . 'Found article #' . $wantedArticle . ' which has a date of ' . date('r', $articleTime) . ', vs wanted date of ' . date('r', $goalTime) . '. Difference from goal is ' . round(($goalTime - $articleTime) / 60 / 60 / 24, 1) . ' days.')); } return $wantedArticle; }
<?php // To troubleshoot what's actually on usenet. require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php'); use nzedb\Binaries; use nzedb\ColorCLI; use nzedb\NNTP; $cli = new ColorCLI(); if (!isset($argv[2]) || !is_numeric($argv[2])) { exit($cli->error("\nTest your nntp connection, get group information and postdate for specific article.\n\n" . "php {$argv['0']} alt.binaries.teevee 595751142 ...: To test nntp on alt.binaries.teevee with artivle 595751142.\n")); } $nntp = new NNTP(); if ($nntp->doConnect() !== true) { exit; } $first = $argv[2]; $group = $argv[1]; // Select a group. $groupArr = $nntp->selectGroup($group); print_r($groupArr); // Insert actual local part numbers here. $msg = $nntp->getXOVER($first . '-' . $first); // Print out the array of headers. print_r($msg); // get postdate for an article $binaries = new Binaries(['NNTP' => $nntp]); $newdate = $binaries->postdate($first, $groupArr); echo $cli->primary("The posted date for " . $group . ", article " . $first . " is " . date('Y-m-d H:i:s', $newdate));
exit($colorCLI->error("\nWrong number of parameters{$usage}")); } else { if ($argv[1] !== 1 && $argv[1] != '<IUnderStandTheRisks>' && $argv[1] != 'IUnderStandTheRisks' && $argv[1] != 'true') { exit($colorCLI->error("\nInvalid parameter(s){$usage}")); } } $pdo = new Settings(); $users = $pdo->query("SELECT id, username, email, password FROM users"); $update = $pdo->Prepare('UPDATE users SET password = :password WHERE id = :id'); $Users = new Users(['Settings' => $pdo]); foreach ($users as $user) { if (needUpdate($user)) { $hash = $Users->hashPassword($user['email']); if ($hash !== false) { $update->execute([':password' => $hash, ':id' => $user['id']]); echo $colorCLI->primary('Updating hash for user:'******'username']; } else { echo $colorCLI->error('Error updating hash for user:'******'username']; } } } function needUpdate($user) { global $colorCLI; $status = true; if (empty($user['email'])) { $status = false; echo $colorCLI->error('Cannot update password hash - Email is not set for user: '******'username']); } else { if (preg_match('#^\\$.+$#', $user['password'])) { $status = false;
<?php require_once dirname(dirname(dirname(__DIR__))) . '/www/config.php'; use nzedb\ColorCLI; $output = new ColorCLI(); echo $output->primary("Checking for files in the renamed directories."); $status = 0; $dirs = [['old' => 'misc/testing/DB_scripts', 'newpath' => 'misc/testing/DB'], ['old' => 'misc/testing/Dev_testing/Subject_testing', 'newpath' => 'misc/testing/Developers/Subject'], ['old' => 'misc/testing/Dev_testing', 'newpath' => 'misc/testing/Developers'], ['old' => 'misc/testing/PostProc_testing', 'newpath' => 'misc/testing/PostProc'], ['old' => 'misc/testing/Regex_testing', 'newpath' => 'misc/testing/Regex'], ['old' => 'misc/testing/Release_scripts', 'newpath' => 'misc/testing/Release'], ['old' => 'misc/update_scripts/nix_scripts/tmux/powerline/themes', 'newpath' => 'misc/update/nix/tmux/powerline/themes'], ['old' => 'misc/update_scripts/nix_scripts/tmux/powerline', 'newpath' => 'misc/update/nix/tmux/powerline'], ['old' => 'misc/update_scripts/nix_scripts/screen/sequential', 'newpath' => 'misc/update/nix/screen/sequential'], ['old' => 'misc/update_scripts/nix_scripts/tmux/', 'newpath' => 'misc/update/nix/tmux'], ['old' => 'misc/update_scripts/nix_scripts', 'newpath' => 'misc/update/nix'], ['old' => 'misc/update_scripts/python_scripts/lib', 'newpath' => 'misc/update/python/lib'], ['old' => 'misc/update_scripts/python_scripts', 'newpath' => 'misc/update/python'], ['old' => 'misc/update_scripts/win_scripts', 'newpath' => 'misc/update/win'], ['old' => 'misc/update_scripts', 'newpath' => 'misc/update']]; $tatus = 0; foreach ($dirs as $dir) { if (isset($dir['old'])) { $pathOld = nZEDb_ROOT . $dir['old']; if (file_exists($pathOld)) { $pathNew = nZEDb_ROOT . $dir['newpath']; echo $output->info("Moving contents of '{$pathOld}' to '{$pathNew}'"); $dirIt = new \DirectoryIterator($pathOld); foreach ($dirIt as $item) { if ($item->isDot()) { continue; } echo $output->info(" Moving {$item->getPathname()}"); if (rename($item->getPathname(), $pathNew . DIRECTORY_SEPARATOR . $item->getFilename()) === false) { echo $output->error(" FAILED!"); $status = 1; } } $d = dir($pathOld); if ($d->read() === false) { @unlink($pathOld); } else { echo $output->error("Could not move all files. Check your permissions!");
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php'); use nzedb\ColorCLI; use nzedb\db\Settings; $pdo = new Settings(); $count = $groups = 0; $cli = new ColorCLI(); echo $cli->header("This script will show all Backfill Groups.\n" . "An optional first argument of ASC/DESC is used to sort the display by first_record_postdate in ascending/descending order.\n" . "An optional second argument will limit the return to that number of groups.\n\n" . "php {$argv['0']} true 20 ...: To sort the backfill groups by first_record_postdate and display only 20 groups.\n"); $limit = ""; if (isset($argv[2]) && is_numeric($argv[2])) { $limit = "limit " . $argv[2]; } else { if (isset($argv[1]) && is_numeric($argv[1])) { $limit = "limit " . $argv[1]; } } $mask = $cli->primary("%-50.50s %22.22s %22.22s %22.22s %22.22s"); $mask1 = $cli->header("%-50.50s %22.22s %22.22s %22.22s %22.22s"); $groups = $pdo->queryOneRow("SELECT COUNT(*) AS count FROM groups WHERE backfill = 1 AND first_record IS NOT NULL"); if ($rels = $pdo->query("SELECT last_updated, last_updated, CAST(last_record AS SIGNED)-CAST(first_record AS SIGNED) AS headers_downloaded FROM groups")) { foreach ($rels as $rel) { $count += $rel['headers_downloaded']; } } printf($mask1, "Group Name => " . $groups['count'] . "(" . number_format($count) . " downloaded)", "Backfilled Days", "Oldest Post", "Last Updated", "Headers Downloaded"); printf($mask1, "==================================================", "======================", "======================", "======================", "======================"); if (isset($argv[1]) && ($argv[1] === "desc" || $argv[1] === "DESC")) { if ($rels = $pdo->query(sprintf("SELECT name, backfill_target, first_record_postdate, last_updated, last_updated, " . "CAST(last_record AS SIGNED)-CAST(first_record AS SIGNED) AS headers_downloaded, " . "TIMESTAMPDIFF(DAY,first_record_postdate,NOW()) AS days FROM groups " . "WHERE backfill = 1 AND first_record_postdate IS NOT NULL AND last_updated IS NOT NULL " . "AND last_updated IS NOT NULL ORDER BY first_record_postdate DESC %s", $limit))) { foreach ($rels as $rel) { $headers = number_format($rel['headers_downloaded']); printf($mask, $rel['name'], $rel['backfill_target'] . "(" . $rel['days'] . ")", $rel['first_record_postdate'], $rel['last_updated'], $headers); }
} $out = new ColorCLI(); $versions = new \nzedb\utility\Versions(); $version = $versions->getGitHookPrecommit(); if ($version > $current) { copy($source, $target); echo $out->info("Updated pre-commit hook to version {$version}"); $file = file($target, FILE_IGNORE_NEW_LINES); } chmod($target, 0774); $count = count($file); $index = 0; while ($index < $count) { if (preg_match('/^#nZEDb hook\\s*-\\s*(.+)$/', $file[$index], $match)) { if (VERBOSE) { echo $out->primary("Matched: " . $file[$index]); } $index++; $file[$index] = trim($file[$index]); switch ($match[1]) { case 'update version info': case 'run hooks': $hook = '/usr/bin/php ' . nZEDb_LIB . 'build/git-hooks/runHooks.php'; if ($hook != $file[$index]) { if (VERBOSE) { echo $out->primary('Replace: "' . $file[$index] . '" with "' . $hook . '"'); } $file[$index] = $hook; $changed = true; } else { echo $out->primary("Skipped: " . $file[$index]);