Exemple #1
0
function SplitSQL($file, $delimiter = ';')
{
    set_time_limit(0);
    if (is_file($file) === true) {
        $file = fopen($file, 'r');
        if (is_resource($file) === true) {
            $query = [];
            $db = new DB();
            $dbsys = DB_TYPE;
            $c = new ColorCLI();
            while (feof($file) === false) {
                $query[] = fgets($file);
                if (preg_match('~' . preg_quote($delimiter, '~') . '\\s*$~iS', end($query)) === 1) {
                    $query = trim(implode('', $query));
                    if ($dbsys == "pgsql") {
                        $query = str_replace(array("`", chr(96)), '', $query);
                    }
                    try {
                        $qry = $db->prepare($query);
                        $qry->execute();
                        echo $c->alternateOver('SUCCESS: ') . $c->primary($query);
                    } catch (PDOException $e) {
                        if ($e->errorInfo[1] == 1091 || $e->errorInfo[1] == 1060 || $e->errorInfo[1] == 1054 || $e->errorInfo[1] == 1061 || $e->errorInfo[1] == 1062 || $e->errorInfo[1] == 1071 || $e->errorInfo[1] == 1072 || $e->errorInfo[1] == 1146 || $e->errorInfo[0] == 23505 || $e->errorInfo[0] == 42701 || $e->errorInfo[0] == 42703 || $e->errorInfo[0] == '42P07' || $e->errorInfo[0] == '42P16') {
                            if ($e->errorInfo[1] == 1060) {
                                echo $c->error($query . " The column already exists - Not Fatal {" . $e->errorInfo[1] . "}.\n");
                            } else {
                                echo $c->error($query . " Skipped - Not Fatal {" . $e->errorInfo[1] . "}.\n");
                            }
                        } else {
                            if (preg_match('/ALTER IGNORE/i', $query)) {
                                $db->queryExec("SET SESSION old_alter_table = 1");
                                try {
                                    $qry = $db->prepare($query);
                                    $qry->execute();
                                    echo $c->alternateOver('SUCCESS: ') . $c->primary($query);
                                } catch (PDOException $e) {
                                    exit($c->error($query . " Failed {" . $e->errorInfo[1] . "}\n\t" . $e->errorInfo[2]));
                                }
                            } else {
                                exit($c->error($query . " Failed {" . $e->errorInfo[1] . "}\n\t" . $e->errorInfo[2]));
                            }
                        }
                    }
                    while (ob_get_level() > 0) {
                        ob_end_flush();
                    }
                    flush();
                }
                if (is_string($query) === true) {
                    $query = [];
                }
            }
            return fclose($file);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
function categorizeRelease($update = true, $where, $echooutput = false)
{
    $pdo = new Settings();
    $cat = new Categorize();
    $consoletools = new consoleTools();
    $relcount = $chgcount = 0;
    $c = new ColorCLI();
    echo $c->primary("SELECT id, searchname, groupid, categoryid FROM releases " . $where);
    $resrel = $pdo->queryDirect("SELECT id, searchname, groupid, categoryid FROM releases " . $where);
    $total = $resrel->rowCount();
    if ($total > 0) {
        foreach ($resrel as $rowrel) {
            $catId = $cat->determineCategory($rowrel['groupid'], $rowrel['searchname']);
            if ($rowrel['categoryid'] != $catId) {
                if ($update === true) {
                    $pdo->queryExec(sprintf("\n\t\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\t\tSET iscategorized = 1,\n\t\t\t\t\t\t\t\trageid = -1,\n\t\t\t\t\t\t\t\tseriesfull = NULL,\n\t\t\t\t\t\t\t\tseason = NULL,\n\t\t\t\t\t\t\t\tepisode = NULL,\n\t\t\t\t\t\t\t\ttvtitle = NULL,\n\t\t\t\t\t\t\t\ttvairdate = NULL,\n\t\t\t\t\t\t\t\timdbid = NULL,\n\t\t\t\t\t\t\t\tmusicinfoid = NULL,\n\t\t\t\t\t\t\t\tconsoleinfoid = NULL,\n\t\t\t\t\t\t\t\tgamesinfo_id = 0,\n\t\t\t\t\t\t\t\txxxinfo_id = 0,\n\t\t\t\t\t\t\t\tbookinfoid = NULL,\n\t\t\t\t\t\t\t\tanidbid = NULL,\n\t\t\t\t\t\t\t\tcategoryid = %d\n\t\t\t\t\t\t\tWHERE id = %d", $catId, $rowrel['id']));
                }
                $chgcount++;
            }
            $relcount++;
            if ($echooutput) {
                $consoletools->overWritePrimary("Re-Categorized: [" . number_format($chgcount) . "] " . $consoletools->percentString($relcount, $total));
            }
        }
    }
    if ($echooutput !== false && $relcount > 0) {
        echo "\n";
    }
    return $chgcount;
}
Exemple #3
0
function print_str($type, $str, $argv)
{
    if ($argv[1] != 'file') {
        $cli = new ColorCLI();
        if ($type == "primary") {
            echo $cli->primary($str);
        } else {
            if ($type == "alternate") {
                echo $cli->alternate($str);
            } else {
                echo $cli->header($str);
            }
        }
    } else {
        echo $str . "\n";
    }
}
Exemple #4
0
 /**
  * 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

require_once dirname(__FILE__) . '/../www/config.php';
$output = new \ColorCLI();
echo $output->primary("Checking for files in the renamed directories.");
$status = 0;
$dirs = array(['old' => 'misc/testing/DB_scripts', 'newpath' => 'misc/testing/DB'], ['old' => 'misc/testing/Dev_testing/Subject_testing', 'newpath' => 'misc/testing/Dev/Subject'], ['old' => 'misc/testing/Dev_testing', 'newpath' => 'misc/testing/Dev'], ['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!");
            }
    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;
Exemple #7
0
<?php

// To troubleshoot what's actually on usenet.
require_once dirname(__FILE__) . '/../../../www/config.php';
$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));
Exemple #8
0
}
$out = new ColorCLI();
$versions = new \newznab\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('/^#newznab 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 ' . NN_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]);
Exemple #9
0
<?php

//This script will update all records in the xxxinfo table where there is no cover
require_once dirname(__FILE__) . '/../../../www/config.php';
use newznab\db\Settings;
$pdo = new Settings();
$movie = new XXX();
$c = new ColorCLI();
$movies = $pdo->queryDirect("SELECT title FROM xxxinfo WHERE cover = 0");
if ($movies instanceof Traversable) {
    echo $c->primary("Updating " . number_format($movies->rowCount()) . " XXX movie covers.");
    foreach ($movies as $mov) {
        $starttime = microtime(true);
        $mov = $movie->updateXXXInfo($mov['title']);
        // sleep so that it's not ddos' the site
        $diff = floor((microtime(true) - $starttime) * 1000000);
        if (333333 - $diff > 0) {
            echo "\nsleeping\n";
            usleep(333333 - $diff);
        }
    }
    echo "\n";
}
Exemple #10
0
require dirname(__FILE__) . '/../../../www/config.php';
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);
        }
Exemple #11
0
 /**
  * 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;
     // 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'];
     }
     $totalArticles = (int) ($lastDate - $firstDate);
     if ($this->_echoCLI) {
         $this->_colorCLI->doEcho($this->_colorCLI->primary('Searching for an approximate article number for group ' . $data['group'] . ' ' . $days . ' days back.'));
     }
     switch (true) {
         case $totalArticles < 1000000:
             $matchPercentage = 1.01;
             break;
         case $totalArticles < 10000000:
             $matchPercentage = 1.007;
             break;
         case $totalArticles < 100000000:
             $matchPercentage = 1.003;
             break;
         case $totalArticles < 500000000:
             $matchPercentage = 1.001;
             break;
         case $totalArticles < 1000000000:
             $matchPercentage = 1.0008;
             break;
         default:
             $matchPercentage = 1.0005;
             break;
     }
     $wantedArticle = $data['last'] * (($goalTime - $firstDate) / $totalArticles);
     $articleTime = 0;
     $percent = 1.01;
     for ($i = 0; $i < 100; $i++) {
         $wantedArticle = (int) $wantedArticle;
         if ($wantedArticle <= $data['first'] || $wantedArticle >= $data['last']) {
             break;
         }
         $articleTime = $this->postdate($wantedArticle, $data);
         if ($articleTime >= $goalTime / $matchPercentage && $articleTime <= $goalTime * $matchPercentage) {
             break;
         }
         if ($articleTime > $goalTime) {
             $wantedArticle /= $percent;
         } else {
             if ($articleTime < $goalTime) {
                 $wantedArticle *= $percent;
             }
         }
         $percent -= 0.001;
     }
     $wantedArticle = (int) $wantedArticle;
     if ($this->_echoCLI) {
         $this->_colorCLI->doEcho($this->_colorCLI->primary('Found article #' . $wantedArticle . ' which has a date of ' . date('r', $articleTime) . ', vs wanted date of ' . date('r', $goalTime) . '.'));
     }
     return $wantedArticle;
 }