Guest User

Untitled

a guest
Jul 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. <?
  2.  
  3.  
  4. // SQL fixing
  5.  
  6.  
  7. // ####################### SET PHP ENVIRONMENT ###########################
  8. error_reporting(E_ALL & ~E_NOTICE & ~8192);
  9.  
  10. // #################### DEFINE IMPORTANT CONSTANTS #######################
  11. define('THIS_SCRIPT', 'sqlfi');
  12.  
  13.  
  14. // ################### PRE-CACHE TEMPLATES AND DATA ######################
  15. // get special phrase groups
  16. $phrasegroups = array();
  17.  
  18. // get special data templates from the datastore
  19. $specialtemplates = array(
  20.  
  21. );
  22.  
  23. // pre-cache templates used by all actions
  24. $globaltemplates = array(
  25.  
  26. );
  27.  
  28. // pre-cache templates used by specific actions
  29. $actiontemplates = array();
  30.  
  31. // ######################### REQUIRE BACK-END ############################
  32. require_once('./global.php');
  33.  
  34.  
  35.  
  36. $tables = $db->list_tables();
  37.  
  38. $start = microtime(true);
  39.  
  40. function check_execution_time() // returns true if CAN continue, else false
  41. {
  42. global $start;
  43. if (intval(microtime(true) - $start) > 99999999999999)
  44. {
  45. return false;
  46. }
  47. else
  48. {
  49. return true;
  50. }
  51. }
  52.  
  53. function strposa($haystack ,$needles=array(),$offset=0) // strpos with array support
  54. {
  55. $chr = array();
  56. foreach($needles as $needle)
  57. {
  58. $strpos = strpos($haystack,$needle,$offset);
  59. if ($strpos !== false)
  60. {
  61. $chr[] = $strpos;
  62. }
  63. }
  64. if(empty($chr)) return false;
  65.  
  66. return min($chr);
  67. }
  68.  
  69.  
  70. // loopers
  71. $table_loop = 1;
  72. $field_loop = 1;
  73. $row_loop = 1;
  74.  
  75. // current values
  76. $current_table = 0;
  77. $current_field = 0;
  78. $current_row = 0;
  79.  
  80. // parsed data
  81. $parsed_tables = array();
  82. $parsed_fields = array();
  83. $parsed_rows = array();
  84.  
  85. $ignore_tables = array( // careful, this is a wildcard ignore
  86. 'admin',
  87. 'album',
  88. 'avatar',
  89. 'bbcode',
  90. 'calendar',
  91. 'cron',
  92. 'cpsession',
  93. 'log',
  94. 'payment',
  95. 'picture',
  96. 'profile',
  97. 'rss',
  98. 'group',
  99. 'subscribe',
  100. 'tachy',
  101. 'temp',
  102. 'hash',
  103. 'forum_announcementread',
  104. 'forum_attachmentviews',
  105. 'forum_covers',
  106. 'forum_discussionread',
  107. 'forum_forumprefixset',
  108. 'forum_forumread',
  109. 'forum_hvquestion',
  110. 'forum_imagecategorypermission',
  111. 'forum_infractiongroup',
  112. 'forum_linking',
  113. 'forum_maillist',
  114. 'forum_moderation',
  115. 'forum_moderatorlog',
  116. 'forum_noticecriteria',
  117. 'forum_noticedismissed',
  118. 'forum_passwordhistory',
  119. 'forum_pmthrottle',
  120. 'forum_postlog',
  121. 'forum_prefixpermission',
  122. 'forum_tagsearch',
  123. 'forum_tagthread',
  124. //'forum_template',
  125. 'forum_templatehistory',
  126. 'forum_threadread',
  127. 'forum_threadviews',
  128. 'forum_upgradelog',
  129. 'forum_useractivation',
  130. 'forum_userchangelog',
  131. 'forum_usergroupleader',
  132. 'forum_usergrouprequest',
  133. 'ow',
  134. 'access',
  135. 'attachment',
  136. 'bookmarksite',
  137. 'cache',
  138. 'faq',
  139. 'permission',
  140. 'holiday',
  141. 'verify',
  142. 'answer',
  143. 'icon',
  144. 'image',
  145. 'infraction',
  146. 'language',
  147. 'queue',
  148. 'plugin',
  149. 'podcast',
  150. 'product',
  151. 'ranks',
  152. 'reminder',
  153. 'session',
  154. 'search',
  155. 'reputation',
  156. 'setting',
  157. 'sig',
  158. 'stats',
  159. 'smili',
  160. 'prefix',
  161. 'event',
  162. 'forum_forum',
  163. 'forum_store',
  164. 'ressources',
  165. 'poll',
  166. 'moderator',
  167. 'post_thanks',
  168. 'phrase',
  169. 'parsed',
  170. );
  171. $ignore_fields = array(
  172. 'id',
  173. 'path',
  174. 'date',
  175. 'time',
  176. 'type',
  177. 'height',
  178. 'width',
  179. 'thumbnail',
  180. 'size',
  181. 'enabled',
  182. 'display',
  183. 'visible',
  184. 'password',
  185. 'list',
  186. 'url',
  187. 'deleted',
  188. 'show',
  189. 'address',
  190. 'hash',
  191. 'regex',
  192. 'point',
  193. 'reason',
  194. 'phrasegroup',
  195. 'code',
  196. 'email',
  197. 'header',
  198. 'condition',
  199. 'array',
  200. 'denied',
  201. 'name',
  202. 'keywords',
  203. 'author',
  204. 'repu',
  205. 'sign',
  206. 'allow',
  207. 'state',
  208. 'folder',
  209. 'field',
  210. 'last',
  211. 'permission',
  212. 'userip',
  213. );
  214.  
  215. $parse = array(
  216. array(
  217. 'è',
  218. 'é',
  219. 'Ã',
  220. 'àŠ',
  221. 'à»',
  222. 'àª',
  223. ),
  224. array(
  225. htmlspecialchars('è'),
  226. htmlspecialchars('é'),
  227. htmlspecialchars('à'),
  228. htmlspecialchars('ê'),
  229. htmlspecialchars('û'),
  230. htmlspecialchars('ê'),
  231. )
  232. );
  233.  
  234. $debug_full = false;
  235.  
  236. // main table loop, excluding
  237. while($table_loop < count($tables))
  238. {
  239.  
  240. if(!check_execution_time())
  241. {
  242. echo "<br><br>Warning: Execution time exeeded 25seconds, loop broken !";
  243. break;
  244. }
  245.  
  246. // resetting loops
  247. $field_loop = 0;
  248. $row_loop = 0;
  249.  
  250.  
  251. $current_table = $tables[$table_loop];
  252. if(strposa($current_table,$ignore_tables) !== FALSE)
  253. {
  254. if ($debug_full)
  255. {
  256. echo "------------------------------<br>Parsing table: $current_table<br><br>";
  257. echo 'This table is in ignore list, table skipped!<br>------------------------------<br>';
  258. }
  259. $parsed_tables[] = $current_table;
  260. ++$table_loop;
  261. continue;
  262. }
  263.  
  264. $fields = $db->list_fields($current_table,$ignore_fields);
  265.  
  266. $data = $db->query_read("SELECT " . implode(',',$fields) . " FROM $current_table LIMIT 0,99999");
  267. $rows = $db->num_rows($data);
  268.  
  269. if($rows == 0 or count($fields) == 0)
  270. {
  271. if($debug_full)
  272. {
  273. echo "------------------------------<br>Parsing table: $current_table<br><br>";
  274. echo "Nothing to parse, table skipped!<br>------------------------------<br>";
  275. }
  276. $parsed_tables[] = $current_table;
  277. ++$table_loop;
  278. continue;
  279. }
  280. else
  281. {
  282. //echo "------------------------------<br>Parsing table: $current_table<br><br>";
  283. //echo "* The table has " . count($fields) . " fields to parse<br>";
  284. //echo "* The table has $rows rows of data to parse<br>";
  285.  
  286.  
  287. // starting parse
  288. while($data_row = $db->fetch_array($data))
  289. {
  290. foreach($data_row as $data_field=>$data_content)
  291. {
  292. if(strposa($data_content,$parse[0]) !== FALSE)
  293. {
  294. print("UPDATE
  295. $current_table
  296. SET $data_field='" . addslashes(str_replace($parse[0],$parse[1],$data_content)) . "'
  297. WHERE $data_field='" . addslashes($data_content) . "';
  298. \n");
  299. }
  300. }
  301. ++$current_row;
  302. }
  303. //echo "Table parsed.";
  304. ++$table_loop;
  305. }
  306. }
  307.  
  308.  
  309. ?>
Add Comment
Please, Sign In to add comment