PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/web/install/template/page.5.php

https://gitlab.com/Rushaway/sourcebanspp
PHP | 220 lines | 205 code | 13 blank | 2 comment | 27 complexity | da0d7403cd11c025b9e67aadff9635dd MD5 | raw file
  1. <?php
  2. $web_cfg = "<?php
  3. define('DB_HOST', '{server}'); // The host/ip to your SQL server
  4. define('DB_USER', '{user}'); // The username to connect with
  5. define('DB_PASS', '{pass}'); // The password
  6. define('DB_NAME', '{db}'); // Database name
  7. define('DB_PREFIX', '{prefix}'); // The table prefix for SourceBans
  8. define('DB_PORT', '{port}'); // The SQL port (Default: 3306)
  9. define('DB_CHARSET', '{charset}'); // The Database charset (Default: utf8)
  10. define('STEAMAPIKEY', '{steamapikey}'); // Steam API Key for Shizz
  11. define('SB_EMAIL', '{sbwpemail}');
  12. ";
  13. $srv_cfg = '"driver_default" "mysql"
  14. "sourcebans"
  15. {
  16. "driver" "default"
  17. "host" "{server}"
  18. "database" "{db}"
  19. "user" "{user}"
  20. "pass" "{pass}"
  21. //"timeout" "0"
  22. "port" "{port}"
  23. }
  24. ';
  25. $web_cfg = str_replace("{server}", $_POST['server'], $web_cfg);
  26. $web_cfg = str_replace("{user}", $_POST['username'], $web_cfg);
  27. $web_cfg = str_replace("{pass}", $_POST['password'], $web_cfg);
  28. $web_cfg = str_replace("{db}", $_POST['database'], $web_cfg);
  29. $web_cfg = str_replace("{prefix}", $_POST['prefix'], $web_cfg);
  30. $web_cfg = str_replace("{port}", $_POST['port'], $web_cfg);
  31. $web_cfg = str_replace("{charset}", $_POST['charset'], $web_cfg);
  32. $web_cfg = str_replace("{steamapikey}", $_POST['apikey'], $web_cfg);
  33. $web_cfg = str_replace("{sbwpemail}", $_POST['sb-email'], $web_cfg);
  34. $srv_cfg = str_replace("{server}", $_POST['server'], $srv_cfg);
  35. $srv_cfg = str_replace("{user}", $_POST['username'], $srv_cfg);
  36. $srv_cfg = str_replace("{pass}", $_POST['password'], $srv_cfg);
  37. $srv_cfg = str_replace("{db}", $_POST['database'], $srv_cfg);
  38. $srv_cfg = str_replace("{port}", $_POST['port'], $srv_cfg);
  39. if (is_writable("../config.php")) {
  40. $config = fopen(ROOT . "../config.php", "w");
  41. fwrite($config, $web_cfg);
  42. fclose($config);
  43. }
  44. if (isset($_POST['postd']) && $_POST['postd']) {
  45. if (empty($_POST['uname']) ||empty($_POST['pass1']) ||empty($_POST['pass2'])||empty($_POST['steam'])||empty($_POST['email'])) {
  46. echo "<script>ShowBox('Error', 'There is some missing data. All fields are required.', 'red', '', true);</script>";
  47. } else {
  48. require_once(ROOT.'../includes/Database.php');
  49. $db = new Database($_POST['server'], $_POST['port'], $_POST['database'], $_POST['username'], $_POST['password'], $_POST['prefix']);
  50. if (!$db) {
  51. echo "<script>ShowBox('Error', 'There was an error connecting to your database. <br />Recheck the details to make sure they are correct', 'red', '', true);</script>";
  52. } else {
  53. // Setup Admin
  54. $db->query('INSERT INTO `:prefix_admins` (user, authid, password, gid, email, extraflags, immunity) VALUES (:user, :authid, :password, :gid, :email, :extraflags, :immunity)');
  55. $db->bind(':user', $_POST['uname']);
  56. $db->bind(':authid', str_replace('STEAM_1', 'STEAM_0', $_POST['steam']));
  57. $db->bind(':password', password_hash($_POST['pass1'], PASSWORD_BCRYPT));
  58. $db->bind(':gid', -1);
  59. $db->bind(':email', $_POST['email']);
  60. $db->bind(':extraflags', (1<<24));
  61. $db->bind(':immunity', 100);
  62. $db->execute();
  63. // Setup Settings
  64. $file = file_get_contents(INCLUDES_PATH . "/sql/data.sql");
  65. $file = str_replace("{prefix}", $_POST['prefix'], $file);
  66. $querys = explode(";", $file);
  67. foreach ($querys as $query) {
  68. if (strlen($query) > 2) {
  69. $db->query(stripslashes($query));
  70. if (!$db->execute()) {
  71. $errors++;
  72. }
  73. }
  74. }
  75. ?>
  76. <table style="width: 101%; margin: 0 0 -2px -2px;">
  77. <tr>
  78. <td colspan="3" class="listtable_top"><b>Final Steps</b></td>
  79. </tr>
  80. </table>
  81. <div id="submit-main">
  82. <div align="center">
  83. The final step is to add this to your databases.cfg on your gameserver (/[MOD]/addons/sourcemod/configs/databases.cfg)<br />
  84. This code must be added <b>INSIDE</b> the `"Databases" { [insert here] }` part of the file.<br />
  85. <textarea cols="105" rows="14" readonly><?php echo $srv_cfg;?></textarea>
  86. <?php
  87. if (strtolower($_POST['server']) == "localhost") {
  88. echo '<script>ShowBox("Local server warning", "You have said your MySQL server is running on the same box as the webserver, this is fine, but you may need to alter the following config to set the remote domain/ip of your MySQL server. Unless your gameserver is on the same box as your webserver." , "blue", "", true);</script>';
  89. }
  90. if (!is_writable("../config.php")) {
  91. ?>
  92. <br /><br />
  93. As your config.php wasnt writeable by the server, you will need to add the following into the (./config.php) file.
  94. <textarea cols="105" rows="15" readonly><?php echo $web_cfg;?></textarea><br />
  95. <?php
  96. }
  97. ?>
  98. </div>
  99. </div>
  100. <table style="width: 101%; margin: 0 0 -2px -2px;">
  101. <tr>
  102. <td colspan="3" class="listtable_top"><b>Finish Up</b></td>
  103. </tr>
  104. </table>
  105. <div id="submit-main">
  106. <div align="center">
  107. The setup of SourceBans is finished. Delete this folder to complete the install. <br />
  108. <i>If you need to import bans from AMXBans, then click the import button below</i><br/><br/>
  109. <form name="import" method="POST" action="index.php?step=6">
  110. <div align="center">
  111. <input type="submit" TABINDEX=2 onclick="" name="button" class="btn cancel" id="button" value="Import AMXBans" /></div>
  112. <input type="hidden" name="username" value="<?php echo $_POST['username']?>">
  113. <input type="hidden" name="password" value="<?php echo $_POST['password']?>">
  114. <input type="hidden" name="server" value="<?php echo $_POST['server']?>">
  115. <input type="hidden" name="database" value="<?php echo $_POST['database']?>">
  116. <input type="hidden" name="port" value="<?php echo $_POST['port']?>">
  117. <input type="hidden" name="prefix" value="<?php echo $_POST['prefix']?>">
  118. </div>
  119. </form>
  120. </div>
  121. <?php
  122. }
  123. }
  124. include TEMPLATES_PATH.'/footer.php';
  125. die();
  126. }
  127. ?>
  128. <b>Hover your mouse over the '?' buttons to see an explanation of the field.</b><br /><br />
  129. <table style="width: 101%; margin: 0 0 -2px -2px;">
  130. <tr>
  131. <td colspan="3" class="listtable_top"><b>Setup</b></td>
  132. </tr>
  133. </table>
  134. <form action="" name="mfrm" id="mfrm" method="post">
  135. <div id="submit-main">
  136. <div align="center">
  137. <table width="60%" style="border-collapse:collapse;" id="group.details" cellpadding="3">
  138. <tr>
  139. <td valign="top" width="35%"><div class="rowdesc"><?php echo HelpIcon("Main Admin", "Type the username for the main SourceBans admin");?>Admin Username</div></td>
  140. <td><div align="center">
  141. <input type="text" TABINDEX=1 class="textbox" id="uname" name="uname" value="" />
  142. </div><div id="server.msg" style="color:#CC0000;"></div></td>
  143. </tr>
  144. <tr>
  145. <td valign="top" width="35%"><div class="rowdesc"><?php echo HelpIcon("Password", "Type a password for the main admin");?>Admin Password</div></td>
  146. <td><div align="center">
  147. <input type="password" TABINDEX=1 class="textbox" id="pass1" name="pass1" value="" />
  148. </div><div id="port.msg" style="color:#CC0000;"></div></td>
  149. </tr>
  150. <tr>
  151. <td valign="top" width="35%"><div class="rowdesc"><?php echo HelpIcon("Confirm", "Type the password again");?>Confirm Password</div></td>
  152. <td><div align="center">
  153. <input type="password" TABINDEX=1 class="textbox" id="pass2" name="pass2" value="" />
  154. </div><div id="user.msg" style="color:#CC0000;"></div></td>
  155. </tr>
  156. <tr>
  157. <td valign="top" width="35%"><div class="rowdesc"><?php echo HelpIcon("STEAM", "Type your STEAM id");?>Steam ID</div></td>
  158. <td><div align="center">
  159. <input type="text" TABINDEX=1 class="textbox" id="steam" name="steam" value="" />
  160. </div><div id="user.msg" style="color:#CC0000;"></div></td>
  161. </tr>
  162. <tr>
  163. <td valign="top" width="35%"><div class="rowdesc"><?php echo HelpIcon("Email", "Type your email");?>Email</div></td>
  164. <td><div align="center">
  165. <input type="text" TABINDEX=1 class="textbox" id="email" name="email" value="" />
  166. </div><div id="user.msg" style="color:#CC0000;"></div></td>
  167. </tr>
  168. </table>
  169. <br/><br/>
  170. <input type="button" onclick="CheckInput();" TABINDEX=2 onclick="" name="button" class="btn ok" id="button" value="Ok" /></div>
  171. <input type="hidden" name="postd" value="1">
  172. <input type="hidden" name="username" value="<?php echo $_POST['username']?>">
  173. <input type="hidden" name="password" value="<?php echo $_POST['password']?>">
  174. <input type="hidden" name="server" value="<?php echo $_POST['server']?>">
  175. <input type="hidden" name="database" value="<?php echo $_POST['database']?>">
  176. <input type="hidden" name="port" value="<?php echo $_POST['port']?>">
  177. <input type="hidden" name="prefix" value="<?php echo $_POST['prefix']?>">
  178. <input type="hidden" name="apikey" value="<?php echo $_POST['apikey']?>">
  179. <input type="hidden" name="sb-email" value="<?php echo $_POST['sb-email']?>">
  180. <input type="hidden" name="charset" value="<?php echo $_POST['charset']?>">
  181. </div>
  182. </form>
  183. <script type="text/javascript">
  184. $E('html').onkeydown = function(event){
  185. var event = new Event(event);
  186. if (event.key == 'enter' ) CheckInput();
  187. };
  188. function CheckInput()
  189. {
  190. var error = 0;
  191. if($('uname').value == "")
  192. error++;
  193. if($('pass1').value == "")
  194. error++;
  195. if($('pass2').value == "")
  196. error++;
  197. if($('steam').value == "")
  198. error++;
  199. if($('email').value == "")
  200. error++;
  201. if(error > 0)
  202. ShowBox('Error', 'You must fill all fields on this page.', 'red', '', true);
  203. else
  204. $('mfrm').submit();
  205. }
  206. </script>