PageRenderTime 90ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/mailz/lists/admin/stresstest.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 138 lines | 118 code | 17 blank | 3 comment | 22 complexity | 7256ca4ed7caa84ff4398741973287d9 MD5 | raw file
  1. <?php
  2. require_once dirname(__FILE__).'/accesscheck.php';
  3. print "Sorry, stresstest is out of date";
  4. return;
  5. function my_shutdown () {
  6. global $tables;
  7. print "Script status: ".connection_status(); # unfortunately buggy in 4.2.1
  8. $res = Sql_query("select count(*) from $tables[user]");
  9. $row = Sql_fetch_row($res);
  10. print '<script language="Javascript" type="text/javascript"> finish(); </script>';
  11. print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Done. Now there are '.$row[0].' users in the database";</script>'."\n";
  12. # register_shutdown_function("");
  13. exit;
  14. }
  15. register_shutdown_function("my_shutdown");
  16. print '<script language="Javascript" src="js/progressbar.js" type="text/javascript"></script>';
  17. ignore_user_abort(1);
  18. ?>
  19. <h1>Stresstest</h1>
  20. Filling database with stress test information, please wait
  21. <br><b>Warning</b> this is quite demanding for your browser!
  22. <?php
  23. function fill($prefix,$listid) {
  24. global $server_name,$tables,$table_prefix;
  25. # check for not too many
  26. $domain = getConfig("domain");
  27. $res = Sql_query("select count(*) from $tables[user]");
  28. $row = Sql_fetch_row($res);
  29. if ($row[0] > 50000) {
  30. error("Hmm, I think 50 thousand users is quite enough for a test<br>This machine does need to do other things you know.");
  31. print '<script language="Javascript" type="text/javascript">finish();</script>';
  32. print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Done. Now there are '.$row[0].' users in the database";</script>'."\n";
  33. return 0;
  34. }
  35. # fill the database with "users" who have any combination of attribute values
  36. $attributes = array();
  37. $res = Sql_query("select * from $tables[attribute] where type = \"select\" or type = \"checkbox\" or type=\"radio\"");
  38. $num_attributes = Sql_Affected_rows();
  39. $total_attr = 0;
  40. $total_val = 0;
  41. while ($row = Sql_fetch_array($res)) {
  42. array_push($attributes,$row["id"]);
  43. $total_attr++;
  44. $values[$row["id"]] = array();
  45. $res2 = Sql_query("select * from $table_prefix"."listattr_".$row["tablename"]);
  46. while ($row2 = Sql_fetch_array($res2)) {
  47. array_push($values[$row["id"]],$row2["id"]);
  48. $total_val++;
  49. }
  50. }
  51. $total = $total_attr * $total_val;
  52. if (!$total) {
  53. print '<script language="Javascript" type="text/javascript"> finish(); </script>';
  54. Fatal_Error("Can only do stress test when some attributes exist");
  55. return 0;
  56. }
  57. for ($i = 0;$i< $total;$i++) {
  58. $data = array();
  59. reset($attributes);
  60. while (list($key,$val) = each ($attributes)) {
  61. $data[$val] = pos($values[$val]);
  62. if (!$data[$val]) {
  63. reset($values[$val]);
  64. $data[$val] = pos($values[$val]);
  65. }
  66. next($values[$val]);
  67. }
  68. $query = sprintf('insert into %s (email,entered,confirmed) values("testuser%s",now(),1)',
  69. $tables["user"], $prefix . '-' . $i . '@' . $domain);
  70. $result = Sql_query($query,0);
  71. $userid = Sql_insert_id();
  72. if ($userid) {
  73. $result = Sql_query("replace into $tables[listuser] (userid,listid,entered) values($userid,$listid,now())");
  74. reset($data);
  75. while (list($key,$val) = each ($data))
  76. if ($key && $val)
  77. Sql_query("replace into $tables[user_attribute] (attributeid,userid,value) values(".$key.",$userid,".$val.")");
  78. }
  79. }
  80. return 1;
  81. }
  82. print formStart().'<input type="text" name="output" size=45></form>';
  83. print '<p>'.PageLink2("stresstest","Erase Test information","eraseall=yes").' (may take a while)';
  84. print '<script language="Javascript" type="text/javascript"> document.write(progressmeter); start();</script>';
  85. ob_end_flush();
  86. flush();
  87. $testlists = array();
  88. $res = Sql_Query("select id from $tables[list] where name like \"%test%\"");
  89. while ($row = Sql_Fetch_Row($res)) {
  90. array_push($testlists,$row[0]);
  91. }
  92. if (!ini_get("safe_mode")) {
  93. if (!sizeof($testlists)) {
  94. print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Error: cannot find any test lists to use";</script>'."\n";
  95. } elseif (!isset($eraseall)) {
  96. print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Filling ";</script>'."\n";
  97. for ($i=0;$i<=100;$i++) {
  98. set_time_limit(60);
  99. flush();
  100. reset($testlists);
  101. while (list($key,$val) = each ($testlists))
  102. if (!fill(getmypid().$i,$val))
  103. return;
  104. }
  105. } else {
  106. $req = Sql_Query("select id from $tables[user] where email like \"testuser%\"");
  107. $i = 1;
  108. set_time_limit(60);
  109. print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Erasing ";</script>'."\n";flush();
  110. while ($row = Sql_Fetch_row($req)) {
  111. Sql_Query("delete quick from $tables[user_attribute] where userid = $row[0]");
  112. Sql_Query("delete quick from $tables[listuser] where userid = $row[0]");
  113. Sql_Query("delete quick from $tables[usermessage] where userid = $row[0]");
  114. Sql_Query("delete quick from $tables[user] where id = $row[0]");
  115. $i++;
  116. }
  117. }
  118. } else {
  119. print Error("Cannot do stresstest in safe mode");
  120. }
  121. ?>