Skip to content

Commit

Permalink
Updates to db, added back hash_decrypt script to loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Oct 8, 2013
1 parent d771d29 commit 6312216
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 27 deletions.
4 changes: 2 additions & 2 deletions bin/monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require(dirname(__FILE__)."/config.php");
require(WWW_DIR.'/lib/postprocess.php');
$version="0.1r842";
$version="0.1r843";

$db = new DB();
$DIR = dirname (__FILE__);
Expand Down Expand Up @@ -1686,7 +1686,7 @@ function writelog( $pane )
if (( $array['MAX_LOAD'] >= get_load()) && (( TIME() - $time27 ) >= $array['FIXRELEASES_TIMER'] ) && ( $array['FIXRELEASES'] == "true" ) && ( $optimize_safe_to_run != "true" )) {
$color = get_color();
$log = writelog($panes6[2]);
shell_exec("$_tmux respawnp -t {$array['TMUX_SESSION']}:6.2 'echo \"\033[38;5;\"$color\"m\" && $ds1 $panes6[2] $ds2 && cd $_test && $_php postprocess_pre.php 2>&1 $log && $_php fixReleaseNames.php 1 true all yes 2>&1 $log && $_php fixReleaseNames.php 3 true other yes 2>&1 $log && $_php fixReleaseNames.php 5 true other yes 2>&1 $log && $_php fixReleaseNames.php 7 true other yes 2>&1 $log && echo \" \033[1;0;33m\" && $ds1 $panes6[2] $ds3' 2>&1 1> /dev/null");
shell_exec("$_tmux respawnp -t {$array['TMUX_SESSION']}:6.2 'echo \"\033[38;5;\"$color\"m\" && $ds1 $panes6[2] $ds2 && cd $_test && $_php postprocess_pre.php 2>&1 $log && $_php fixReleaseNames.php 1 true all yes 2>&1 $log && $_php fixReleaseNames.php 3 true other yes 2>&1 $log && $_php fixReleaseNames.php 5 true other yes 2>&1 $log && $_php fixReleaseNames.php 7 true other yes 2>&1 $log && $_php hash_decrypt.php true 2>&1 $log && echo \" \033[1;0;33m\" && $ds1 $panes6[2] $ds3' 2>&1 1> /dev/null");
$time27 = TIME();}
elseif (( $array['FIXRELEASES'] != "true" ) && ( $optimize_safe_to_run != "true" )) {
$color = get_color();
Expand Down
1 change: 1 addition & 0 deletions nnscripts/remove_parts_without_releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//----------------------------------------------------------------------
// Load the application
require_once(dirname(__FILE__)."/../bin/config.php");
require_once(WWW_DIR. "lib/framework/db.php");

// nnscripts includes
require_once("lib/nnscripts.php");
Expand Down
11 changes: 11 additions & 0 deletions test/db_updates/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ ALTER TABLE `releases` ADD `dehashstatus` TINYINT( 1 ) NOT NULL DEFAULT '0' A
ALTER TABLE `releases` ADD `nfostatus` TINYINT NOT NULL DEFAULT 0 after `dehashstatus`;
ALTER TABLE `releases` ADD `relnamestatus` TINYINT NOT NULL DEFAULT 1 after `nfostatus`;
ALTER TABLE `releases` ADD `relstatus` TINYINT(4) NOT NULL DEFAULT 0 after `relnamestatus`;
ALTER TABLE `releases` ADD `hashed` BOOL DEFAULT FALSE after `relstatus`;
CREATE INDEX ix_releases_hashed on releases(hashed);
CREATE INDEX ix_releases_mergedreleases on releases(dehashstatus, relnamestatus, passwordstatus);
UPDATE releases SET hashed = true WHERE searchname REGEXP '[a-fA-F0-9]{32}' OR name REGEXP '[a-fA-F0-9]{32}';
delimiter //
CREATE TRIGGER check_insert BEFORE INSERT ON releases FOR EACH ROW BEGIN IF NEW.searchname REGEXP '[a-fA-F0-9]{32}' OR NEW.name REGEXP '[a-fA-F0-9]{32}' THEN SET NEW.hashed = true; END IF; END;//
delimiter ;
delimiter //
CREATE TRIGGER check_update BEFORE UPDATE ON releases FOR EACH ROW BEGIN IF NEW.searchname REGEXP '[a-fA-F0-9]{32}' OR NEW.name REGEXP '[a-fA-F0-9]{32}' THEN SET NEW.hashed = true; END IF; END;//
delimiter;




Expand Down
76 changes: 51 additions & 25 deletions test/hash_decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,73 @@
require_once(WWW_DIR."lib/site.php");
require_once ("consoletools.php");
require_once ("namecleaner.php");
require_once ("functions.php");

//this scripts is adapted from nZEDb decrypt_hashes.php
//this script is adapted from nZEDb decrypt_hashes.php

preName();
if (!isset($argv[1]))
exit ("This script tries to match an MD5 of the releases.name or releases.searchname to prehash.md5.\nphp decrypt_hashes.php true to limit 1000.\nphp decrypt_hashes.php full to run on full database.\n");

function preName()
{

$db = new DB();
$consoletools = new ConsoleTools();
$counter = 0;
$loops = 1;
$reset = 0;
echo "\nDecrypt Hashes Started at ".date("g:i:s")."\nMatching prehash MD5 to md5(releases.name or releases.searchname)\n";
preName($argv);

function preName($argv)
{
$db = new DB();
$timestart = TIME();
$limit = ($argv[1] == "full") ? "" : " LIMIT 1000";

$db->query("update releases set dehashstatus = -1 where dehashstatus = 0 and searchname REGEXP '[a-fA-F0-9]{32}'");
if($res = $db->queryDirect("select ID, searchname from releases where dehashstatus between -6 and -1 and searchname REGEXP '[a-fA-F0-9]{32}'"))
$res = $db->queryDirect("SELECT ID, name, searchname, groupID, categoryID FROM releases WHERE dehashstatus BETWEEN -5 AND 0 AND hashed = true".$limit);
$total = count($res);
$counter = 0;
$show = '';
if($total > 0)
{
$consoletools = new ConsoleTools();
$category = new Category();
$functions = new Functions();
$reset = 0;
$loops = 1;
$n = "\n";
foreach ($res as $row)
{
$success = false;
if (preg_match('/([0-9a-fA-F]{32})/', $row['searchname'], $match))
if (preg_match('/([0-9a-fA-F]{32})/', $row['searchname'], $match) || preg_match('/([0-9a-fA-F]{32})/', $row['name'], $match))
{
if($res1 = $db->queryOneRow(sprintf("select title from prehash where hash = %s", $db->escapeString($match[1]))))
$pre = $db->queryOneRow(sprintf("SELECT title, source FROM prehash WHERE hash = %s", $db->escapeString($match[1])));
if ($pre !== false)
{
$db->query(sprintf("update releases set dehashstatus = 1, relnamestatus = 6, searchname = %s where ID = %d", $db->escapeString($res1['title']), $row['ID']));
if ($db->getAffectedRows() >= 1)
$determinedcat = $category->determineCategory($row["groupID"], $pre['title']);
$result = $db->query(sprintf("UPDATE releases SET dehashstatus = 1, relnamestatus = 5, searchname = %s, categoryID = %d WHERE ID = %d", $db->escapeString($pre['title']), $determinedcat, $row['ID']));
if (count($result) > 0)
{
echo "Renamed hashed release: ".$res1['title']."\n";
$success = true;
$groups = new Groups();
$functions = new Functions();
$groupname = $functions->getByNameByID($row["groupID"]);
$oldcatname = $functions->getNameByID($row["categoryID"]);
$newcatname = $functions->getNameByID($determinedcat);

echo $n."New name: ".$pre['title'].$n.
"Old name: ".$row["searchname"].$n.
"New cat: ".$newcatname.$n.
"Old cat: ".$oldcatname.$n.
"Group: ".$groupname.$n.
"Method: "."prehash md5 release name: ".$pre["source"].$n.
"ReleaseID: ". $row["ID"].$n;

$success = true;
$counter++;
}
}
}
if ($success == false)
$consoletools->overWrite("Renaming hashed releases:".$consoletools->percentString($loops++,mysqli_num_rows($res)));
{
$fail = $db->query(sprintf("UPDATE releases SET dehashstatus = dehashstatus - 1 WHERE ID = %d", $row['ID']));
}
}
}
echo "\n".$counter. " release(s) names changed.\n";

}


?>
if ($total > 0)
echo "\nRenamed ".$counter." releases in ".$consoletools->convertTime(TIME() - $timestart)."\n";
else
echo "\nNothing to do.\n";
}

0 comments on commit 6312216

Please sign in to comment.