error("This script tries to match an MD5 of the releases.name or releases.searchname to prehash.md5.\nphp hash_decrypt.php true to limit 1000.\nphp hash_decrypt.php full to run on full database.\n")); echo $c->header ("\nHash Decryption Started at ".date("H:i:s")."\nMatching prehash MD5 to md5(releases.name or releases.searchname)"); preName($argv); function preName($argv) { $db = new DB(); $c = new ColorCLI(); $timestart = TIME(); $limit = ($argv[1] == "full") ? "" : " LIMIT 1000"; $res = $db->queryDirect("SELECT ID, name, searchname, groupID, categoryID FROM releases WHERE hashed = true AND dehashstatus BETWEEN -6 AND 0".$limit); $total = count($res); $counter = 0; $show = ''; if($total > 0) { $precount = $db->queryOneRow('SELECT COUNT(*) AS count FROM prehash'); echo $c->primary ('Comparing '.number_format($total).' releases against '.number_format($precount['count'])." prehash records"); $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) || preg_match('/([0-9a-fA-F]{32})/', $row['name'], $match)) { $pre = $db->queryOneRow(sprintf("SELECT title, source FROM prehash WHERE hash = %s", $db->escapeString($match[1]))); if ($pre !== false) { $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) { $groups = new Groups(); $functions = new Functions(); $groupname = $functions->getByNameByID($row["groupID"]); $oldcatname = $functions->getNameByID($row["categoryID"]); $newcatname = $functions->getNameByID($determinedcat); echo $c->primary($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) { $fail = $db->query(sprintf("UPDATE releases SET dehashstatus = dehashstatus - 1 WHERE ID = %d", $row['ID'])); } } } if ($total > 0) echo $c->header ( "\nRenamed ".$counter." releases in ".$consoletools->convertTime(TIME() - $timestart)."."); else echo $c->info ("\nNothing to do."); }