Advertisement
MeIiodas

Untitled

May 12th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. <?php
  2. define('DATABASE_NAME', 'ripple');
  3. define('DATABASE_USER', 'meliodas');
  4. define('DATABASE_PASS', 'planken');
  5. define('DATABASE_HOST', 'localhost');
  6. define('DATABASE_WHAT', 'host');
  7.  
  8. define('CREATE_ADMIN', 'true');
  9. define('ADMIN_USERNAME', 'Meliodas');
  10. define('ADMIN_EMAIL', 'admin@ripple.moe');
  11.  
  12. $db = new DBPDO();
  13.  
  14. function randomString($l) {
  15. $c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  16. $res = '';
  17. srand((float) microtime() * 1000000);
  18. for ($i = 0; $i < $l; $i++) {
  19. $res .= $c[rand() % strlen($c)];
  20. }
  21.  
  22. return $res;
  23. }
  24.  
  25. echo "Fokabot doesn't exist. Creating account...\n";
  26. $plainPassword = randomString(8);
  27. $options = ['cost' => 9, 'salt' => base64_decode(base64_encode(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)))];
  28. $md5Password = crypt(md5($plainPassword), '$2y$'.$options['salt']);
  29. $db->execute("INSERT INTO `users`(`id`, `username`, `username_safe`, `password_md5`, `salt`, `email`, `register_datetime`, `rank`, `allowed`, `latest_activity`, `silence_end`, `silence_reason`, `password_version`, `privileges`, `flags`) VALUES ('999', 'FokaBot', 'fokabot', ?, ?, 'fo@kab.ot', '1452544880', '4', '1', '0', '0', '', 1, 3063295, 0);", [$md5Password, base64_encode($options['salt'])]);
  30. $db->execute("INSERT INTO `users_stats`(`id`, `username`, `username_aka`, `user_color`, `user_style`, `ranked_score_std`, `playcount_std`, `total_score_std`, `replays_watched_std`, `ranked_score_taiko`, `playcount_taiko`, `total_score_taiko`, `replays_watched_taiko`, `ranked_score_ctb`, `playcount_ctb`, `total_score_ctb`, `replays_watched_ctb`, `ranked_score_mania`, `playcount_mania`, `total_score_mania`, `replays_watched_mania`, `total_hits_std`, `total_hits_taiko`, `total_hits_ctb`, `total_hits_mania`, `country`, `show_country`, `level_std`, `level_taiko`, `level_ctb`, `level_mania`, `avg_accuracy_std`, `avg_accuracy_taiko`, `avg_accuracy_ctb`, `avg_accuracy_mania`, `pp_std`, `pp_taiko`, `pp_ctb`, `pp_mania`, `badges_shown`, `safe_title`, `userpage_content`, `play_style`, `favourite_mode`) VALUES ('999', 'FokaBot', '', 'black', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'XX', '1', '0', '0', '0', '0', '0.000000000000', '0.000000000000', '0.000000000000', '0.000000000000', '0', '0', '0', '0', '3,4,11,0,0,0', '0', '', 0, 0);");
  31. echo 'Fokabot account created! Password is: '.$plainPassword."\n";
  32. echo 'Yepp... thats all we got for now. Some stuff might be missing as not everything is tested and set up correctly.';
  33.  
  34. if(ADMIN_USERNAME == "true") {
  35. echo "Creating account...\n";
  36. $plainPassword = randomString(8);
  37. $options = ['cost' => 9, 'salt' => base64_decode(base64_encode(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)))];
  38. $md5Password = crypt(md5($plainPassword), '$2y$'.$options['salt']);
  39. $db->execute("INSERT INTO `users`(`id`, `username`, `username_safe`, `password_md5`, `salt`, `email`, `register_datetime`, `rank`, `allowed`, `latest_activity`, `silence_end`, `silence_reason`, `password_version`, `privileges`, `flags`) VALUES ('1000', ?, ?, ?, ?, ?, '1452544880', '4', '1', '0', '0', '', 1, 3145727, 0);", [ADMIN_USERNAME,strtolower(ADMIN_USERNAME),ADMIN_EMAIL,$md5Password, base64_encode($options['salt'])]);
  40. $db->execute("INSERT INTO `users_stats`(`id`, `username`, `username_aka`, `user_color`, `user_style`, `ranked_score_std`, `playcount_std`, `total_score_std`, `replays_watched_std`, `ranked_score_taiko`, `playcount_taiko`, `total_score_taiko`, `replays_watched_taiko`, `ranked_score_ctb`, `playcount_ctb`, `total_score_ctb`, `replays_watched_ctb`, `ranked_score_mania`, `playcount_mania`, `total_score_mania`, `replays_watched_mania`, `total_hits_std`, `total_hits_taiko`, `total_hits_ctb`, `total_hits_mania`, `country`, `show_country`, `level_std`, `level_taiko`, `level_ctb`, `level_mania`, `avg_accuracy_std`, `avg_accuracy_taiko`, `avg_accuracy_ctb`, `avg_accuracy_mania`, `pp_std`, `pp_taiko`, `pp_ctb`, `pp_mania`, `badges_shown`, `safe_title`, `userpage_content`, `play_style`, `favourite_mode`) VALUES ('1000', ?, '', 'black', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'XX', '1', '1', '1', '1', '1', '0.000000000000', '0.000000000000', '0.000000000000', '0.000000000000', '0', '0', '0', '0', '1,0,0,0,0,0', '0', '', 0, 0);", [ADMIN_USERNAME]);
  41. echo 'New account created! Password is: '.$plainPassword."\n";
  42. }
  43.  
  44. class DBPDO {
  45. public $pdo;
  46. private $error;
  47.  
  48. public function __construct() {
  49. $this->connect();
  50. }
  51.  
  52. public function prep_query($query) {
  53. return $this->pdo->prepare($query);
  54. }
  55.  
  56. public function connect() {
  57. if (!$this->pdo) {
  58. $dsn = 'mysql:dbname='.DATABASE_NAME.';'.DATABASE_WHAT.'='.DATABASE_HOST;
  59. $user = DATABASE_USER;
  60. $password = DATABASE_PASS;
  61. try {
  62. $this->pdo = new PDO($dsn, $user, $password, [PDO::ATTR_PERSISTENT => true]);
  63.  
  64. return true;
  65. }
  66. catch(PDOException $e) {
  67. $this->error = $e->getMessage();
  68. die($this->error);
  69.  
  70. return false;
  71. }
  72. } else {
  73. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  74.  
  75. return true;
  76. }
  77. }
  78.  
  79. public function table_exists($table_name) {
  80. $stmt = $this->prep_query('SHOW TABLES LIKE ?');
  81. $stmt->execute([$this->add_table_prefix($table_name)]);
  82.  
  83. return $stmt->rowCount() > 0;
  84. }
  85.  
  86. public function execute($query, $values = null) {
  87. if ($values === null) {
  88. $values = [];
  89. } elseif (!is_array($values)) {
  90. $values = [$values];
  91. }
  92. $stmt = $this->prep_query($query);
  93. $stmt->execute($values);
  94.  
  95. return $stmt;
  96. }
  97.  
  98. public function fetch($query, $values = null) {
  99. if ($values === null) {
  100. $values = [];
  101. } elseif (!is_array($values)) {
  102. $values = [$values];
  103. }
  104. $stmt = $this->execute($query, $values);
  105.  
  106. return $stmt->fetch(PDO::FETCH_ASSOC);
  107. }
  108.  
  109. public function fetchAll($query, $values = null, $key = null) {
  110. if ($values === null) {
  111. $values = [];
  112. } elseif (!is_array($values)) {
  113. $values = [$values];
  114. }
  115. $stmt = $this->execute($query, $values);
  116. $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  117. // Allows the user to retrieve results using a
  118. // column from the results as a key for the array
  119. if ($key != null && $results[0][$key]) {
  120. $keyed_results = [];
  121. foreach ($results as $result) {
  122. $keyed_results[$result[$key]] = $result;
  123. }
  124. $results = $keyed_results;
  125. }
  126.  
  127. return $results;
  128. }
  129.  
  130. public function lastInsertId() {
  131. return $this->pdo->lastInsertId();
  132. }
  133. }
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement