chetansoni

Oneclick Wordpress Admin User Creator - By CHETAN SONI

Oct 28th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 KB | None | 0 0
  1. <?php
  2.  
  3. /******************************
  4. * Oneclick Wordpress Admin User Creator
  5. * Author - CHETAN SONI
  6. * Twitter - http://twitter.com/iamchetansoni
  7. * ****************************/
  8.  
  9. // configurables
  10. $wpconf = "wp-config.php";
  11. $usrtbl = "users";
  12. $usrmta = "usermeta";
  13.  
  14. // sql data
  15. $sqltbl = "INSERT INTO `%prefix%$usrtbl` (`user_login`,`user_pass`,`user_nicename`,`user_email`,`user_url`,`user_registered`,`user_activation_key`,`user_status`,`display_name`) VALUES ('%usrname%',MD5('%usrpass%'),'%usrnice%','%usrmail%','',NOW(),'','0','%usrnice%')";
  16. $sqlid = "SELECT `id` FROM `%prefix%$usrtbl` WHERE `user_login` = '%usrname%'";
  17. $sqlmta = "INSERT INTO `%prefix%$usrmta` (`user_id`,`meta_key`,`meta_value`) VALUES ('%usrid%','%prefix%capabilities','a:1:{s:13:\"administrator\";s:1:\"1\";}')";
  18. $sqlmta2 = "INSERT INTO `%prefix%$usrmta` (`user_id`,`meta_key`,`meta_value`) VALUES ('%usrid%','%prefix%user_level','10')";
  19.  
  20. // defaults
  21. $prefix = "wp_";
  22. $usrname = "";
  23. $usrpass = "";
  24. $usrnice = "";
  25. $usrmail = "";
  26. $errors = array();
  27.  
  28. // helper functions
  29. function msg($msg,$type=""){
  30. echo "<div class=\"alert $type\">$msg</div>\n";
  31. }
  32.  
  33. function getusrid($query){
  34. $result = @mysql_query ($query);
  35. $row = @mysql_fetch_array ($result, MYSQL_ASSOC);
  36. return $row['id'];
  37. }
  38.  
  39. function box($arr,$classes=""){
  40. if (count($arr)>0):
  41. echo "<div class=\"alert $classes\">\n";
  42. foreach ($arr as $a): echo "$a<br />\n"; endforeach;
  43. echo "</div>\n";
  44. endif;
  45. }
  46.  
  47. function filter($input,$keys=array(),$vals=array()){
  48. $data = str_replace($keys,$vals,$input);
  49. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); }
  50. // if (function_exists('mysql_real_escape_string')) {
  51. // global $dbc; // Need the connection.
  52. // $data = mysql_real_escape_string (trim($data), $dbc);
  53. // } else { $data = mysql_escape_string (trim($data)); } //
  54. return $data;
  55. }
  56.  
  57. ?><!DOCTYPE html>
  58. <html>
  59. <head>
  60. <title>Oneclick Wordpress Admin User Creator</title>
  61.  
  62. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  63. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/css/bootstrap.min.css">
  64. <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/js/bootstrap.min.js"></script>
  65. <script src="//code.jquery.com/jquery.js"></script>
  66.  
  67. <style type="text/css">
  68. body { background: #000000; }
  69. a { color: #bf4c26; }
  70. a:hover { color: #222; }
  71. .wrapper { background: white; border: 1px solid #eee; padding: 10px; width: 800px; margin: 30px auto 0; border-radius: 12px; }
  72. .ver { width: 800px; margin: 5px auto; color: #999; font-size: 11px; }
  73. .theform { display: block; border: 1px solid #efefef; padding: 10px; margin: 10px 0; border-radius: 6px;}
  74. </style>
  75. </head>
  76.  
  77. <body>
  78. <center><img src="http://i.imgur.com/3GqsquD.png"></center>
  79. <div class="wrapper">
  80. <center> <h2> <b>Oneclick Wordpress Admin User Creator</b></h2></center><hr>
  81. <?php
  82. if (file_exists($wpconf)):
  83. // wp config file found
  84. include_once($wpconf);
  85. if (defined('DB_NAME')&&defined('DB_USER')&&defined('DB_PASSWORD')&&defined('DB_HOST')):
  86. // db data found
  87.  
  88. echo "<center>Yippie we got the details, <span style=\"color: green\">Database Name = <b>".DB_USER."</b></span> and <span style=\"color: green\">Database User = <b>".DB_NAME."</b></span></center>";
  89.  
  90. if ($dbc = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD)):
  91. // sql connect successful
  92. if (@mysql_select_db(DB_NAME)):
  93. // sql db select successful
  94. echo "<span style=\"color: green\"><b></b></span>\n<br />";
  95. if (isset($_POST['sub'])):
  96. // form submitted, process and show results
  97. //print_r($_POST);
  98. if (isset($_POST['prefix'])&&(strlen($_POST['prefix'])>0)): $prefix = trim($_POST['prefix']); else: $errors[] = "You did not fill in the table prefix"; endif;
  99. if (isset($_POST['usrname'])&&(strlen($_POST['usrname'])>0)): $usrname = trim($_POST['usrname']); else: $errors[] = "You did not fill in the username"; endif;
  100. if (isset($_POST['usrpass'])&&(strlen($_POST['usrpass'])>0)): $usrpass = trim($_POST['usrpass']); else: $errors[] = "You did not fill in the password"; endif;
  101. if (isset($_POST['usrnice'])&&(strlen($_POST['usrnice'])>0)): $usrnice = trim($_POST['usrnice']); else: $errors[] = "You did not fill in the display username"; endif;
  102. if (isset($_POST['usrmail'])&&(strlen($_POST['usrmail'])>0)): $usrmail = trim($_POST['usrmail']); else: $errors[] = "You did not fill in the email address"; endif;
  103.  
  104. if (count($errors)==0):
  105. // form submitted successfully
  106. $sqltbl = filter($sqltbl,array("%prefix%","%usrname%","%usrpass%","%usrnice%","%usrmail%"),array($prefix,$usrname,$usrpass,$usrnice,$usrmail));
  107. if ($result = @mysql_query ($sqltbl)):
  108. $sqlid = filter($sqlid,array("%prefix%","%usrname%"),array($prefix,$usrname));
  109. $id = getusrid($sqlid);
  110. $sqlmta = filter($sqlmta,array("%prefix%","%usrid%"),array($prefix,$id));
  111. $sqlmta2 = filter($sqlmta2,array("%prefix%","%usrid%"),array($prefix,$id));
  112. if (!@mysql_query ($sqlmta)): $errors[] = "<b>Failed to add user metadata!</b> ".mysql_error(); endif;
  113. if (!@mysql_query ($sqlmta2)): $errors[] = "<b>Failed to add user metadata #2!</b> ".mysql_error(); endif;
  114. else: $errors[] = "<b>Failed to add user!</b> ".mysql_error();
  115. endif;
  116. //echo "$sqltbl<br />$sqlid<br />$sqlmta<br />$sqlmta2";
  117. if (count($errors)==0):
  118. box(array("<b>User added successfully.</b><br />Please login to your dashboard, <a href=\"wp-admin/\">Click Here</a>."),"alert-success");
  119. endif;
  120. endif;
  121. endif;
  122. // display form
  123. box($errors,"alert-danger");
  124. ?>
  125. <form role="form" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="POST" class="theform form-horizontal">
  126. <div class="row">
  127. <fieldset>
  128. <div class="form-group">
  129. <label for="prefix" class="col-lg-2 control-label">Table prefix</label>
  130. <div class="col-lg-3"><input type="text" class="form-control" name="prefix" id="prefix" placeholder="username" value="wp_" value="<?php echo $usrprefix; ?>"></div>
  131. </div>
  132.  
  133. <div class="form-group">
  134. <label for="usrname" class="col-lg-2 control-label">Username</label>
  135. <div class="col-lg-6"><input type="text" class="form-control" name="usrname" id="usrname" placeholder="Enter New Username" value="<?php echo $usrname; ?>"></div>
  136. </div>
  137. <div class="form-group">
  138. <label for="usrpass" class="col-lg-2 control-label">Password</label>
  139. <div class="col-lg-6"><input type="password" class="form-control" id="usrpass" name="usrpass" placeholder="Enter New Password" value="<?php echo $usrpass; ?>"></div>
  140. </div>
  141. <div class="form-group">
  142. <label for="usrnice" class="col-lg-2 control-label">Display Name</label>
  143. <div class="col-lg-6"><input type="text" class="form-control" name="usrnice" id="usrnice" placeholder="Enter Your Display Name" value="<?php echo $usrnice; ?>"></div>
  144. </div>
  145. <div class="form-group">
  146. <label for="usrmail" class="col-lg-2 control-label">E-mail ID</label>
  147. <div class="col-lg-6"><input type="email" class="form-control" name="usrmail" id="usrmail" placeholder="Enter Your E-mail ID" value="<?php echo $usrmail; ?>"></div>
  148. </div>
  149. <div class="form-group">
  150. <div class="col-lg-offset-2 col-lg-6">
  151. <button type="submit" class="btn btn-primary">Add User</button>
  152. </div>
  153. </div>
  154. </fieldset>
  155. </div>
  156. <input type="hidden" name="sub" value="0">
  157. </form>
  158.  
  159. <?
  160. mysql_close($dbc);
  161. else:
  162. // sql select failed
  163. msg("Unable to select the database.","alert-danger");
  164. endif;
  165. else:
  166. // unable to connect to sql
  167. msg("Unable to connect the database.","alert-danger");
  168. endif;
  169. else:
  170. // missing db data
  171. msg("Check your <b>wp-login.php</b> file","");
  172. endif;
  173. else:
  174. // missing wp config file
  175. msg("Unable to locate <b>wp-config.php</b>. Make sure you have uploaded this script to the root of your Wordpress installation.","alert-danger");
  176. endif;
  177. ?>
  178. </div><!--wrapper-->
  179.  
  180. </body>
  181. </html>
Advertisement
Add Comment
Please, Sign In to add comment