From 6312216882a0704408c41dfd93b61ee70bc1e8b5 Mon Sep 17 00:00:00 2001 From: Darko Date: Tue, 8 Oct 2013 12:33:20 +0200 Subject: [PATCH] Updates to db, added back hash_decrypt script to loop. --- bin/monitor.php | 4 +- nnscripts/remove_parts_without_releases.php | 1 + test/db_updates/db.sql | 11 +++ test/hash_decrypt.php | 76 ++++++++++++++------- 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/bin/monitor.php b/bin/monitor.php index 3bf3da2..ea04ac6 100644 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -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__); @@ -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(); diff --git a/nnscripts/remove_parts_without_releases.php b/nnscripts/remove_parts_without_releases.php index 8f0eed0..4732737 100644 --- a/nnscripts/remove_parts_without_releases.php +++ b/nnscripts/remove_parts_without_releases.php @@ -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"); diff --git a/test/db_updates/db.sql b/test/db_updates/db.sql index 3fb0e07..8bcd30a 100644 --- a/test/db_updates/db.sql +++ b/test/db_updates/db.sql @@ -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; + diff --git a/test/hash_decrypt.php b/test/hash_decrypt.php index bb370a4..eef0d55 100755 --- a/test/hash_decrypt.php +++ b/test/hash_decrypt.php @@ -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"; +}