PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/install/index.php

https://gitlab.com/Etern4l/BitcoinDice
PHP | 312 lines | 296 code | 10 blank | 6 comment | 26 complexity | caf3b319eb35f323490eea76aad8770f MD5 | raw file
  1. <?php
  2. /*
  3. * © BitcoinDice
  4. */
  5. if (isset($_GET['checkCons'])) {
  6. if (@!mysql_connect($_POST['db_host'],$_POST['db_user'],$_POST['db_pass']) || @!mysql_select_db($_POST['db_name'])) {
  7. header('Location: ./?step=3&db');
  8. exit();
  9. }
  10. $included_=true;
  11. include 'db_data.php';
  12. $db_file=fopen('../inc/db-conf.php','wb');
  13. fwrite($db_file,"<?php \n");
  14. fwrite($db_file,'$conf_c=true;'."\n");
  15. fwrite($db_file,'mysql_connect(\''.$_POST['db_host'].'\',\''.$_POST['db_user'].'\',\''.$_POST['db_pass'].'\');'."\n");
  16. fwrite($db_file,'mysql_select_db(\''.$_POST['db_name'].'\');'."\n");
  17. fwrite($db_file,'mysql_query("SET NAMES utf8");'."\n");
  18. fwrite($db_file,"?>"); ?><?php
  19. fclose($db_file);
  20. $w_file=fopen('../inc/driver-conf.php','wb');
  21. fwrite($w_file,"<?php \n");
  22. fwrite($w_file,'$driver_login=\'http://'.$_POST['w_user'].':'.$_POST['w_pass'].'@'.$_POST['w_host'].':'.$_POST['w_port'].'/\';'."\n");
  23. fwrite($w_file,"?>"); ?><?php
  24. fclose($w_file);
  25. header('Location: ./?step=4');
  26. exit();
  27. }
  28. if (isset($_GET['saveB'])) {
  29. include '../inc/db-conf.php';
  30. mysql_query("UPDATE `system` SET `title`='$_POST[s_title]',`url`='$_POST[s_url]',`currency`='$_POST[s_cur]',`currency_sign`='$_POST[s_cur_sign]',`description`='$_POST[s_desc]' WHERE `id`=1");
  31. header('Location: ./?step=5');
  32. exit();
  33. }
  34. if (empty($_GET['step']) || ($_GET['step']!=1 && $_GET['step']!=2 && $_GET['step']!=3 && $_GET['step']!=4 && $_GET['step']!=5 && $_GET['step']!=6)) {
  35. header('Location: ./?step=1');
  36. exit();
  37. }
  38. else $step=$_GET['step'];
  39. if ($step==3 && (!is_writable('../inc/db-conf.php') || !is_writable('../inc/driver-conf.php'))) {
  40. header('Location: ./?step=2');
  41. exit();
  42. }
  43. ?>
  44. <!DOCTYPE html>
  45. <html>
  46. <head>
  47. <title>BitcoinDice 1.0 - Installation</title>
  48. <meta charset="utf-8">
  49. <link rel="stylesheet" type="text/css" href="./install_page.css">
  50. <link rel="shortcut icon" href="./favicon.ico">
  51. <script type="text/javascript" src="jquery.js"></script>
  52. </head>
  53. <body>
  54. <div class="allbody">
  55. <div class="alls" style="text-align: center;">
  56. <h1>BitcoinDice 1.0 Installation</h1>
  57. </div>
  58. </div>
  59. <?php
  60. switch ($step) {
  61. case 1:
  62. ?>
  63. <script type="text/javascript">
  64. function next() {
  65. window.location.href='./?step=2';
  66. }
  67. </script>
  68. <div class="allbody">
  69. <div class="alls">
  70. <h3>Welcome!</h3>
  71. This is an automatic installation script. Please, follow the instructions on the following screens.
  72. </div>
  73. </div>
  74. <?php
  75. break;
  76. case 2:
  77. ?>
  78. <script type="text/javascript">
  79. function next() {
  80. window.location.href='./?step=3';
  81. }
  82. </script>
  83. <div class="allbody">
  84. <div class="alls">
  85. <h3>File Permissions</h3>
  86. Please make sure that following files are writable (chmod 777):
  87. <br>
  88. <table>
  89. <tr>
  90. <td><i>inc/db-conf.php</i></td>
  91. <td>&nbsp;&nbsp;</td>
  92. <td><?php if (is_writable('../inc/db-conf.php')) { echo '<span style="color: green;"><b>Yes</b></span>'; } else { echo '<span style="color: red;"><b>No</b></span>'; } ?></td>
  93. </tr>
  94. <tr>
  95. <td><i>inc/driver-conf.php</i></td>
  96. <td>&nbsp;&nbsp;</td>
  97. <td><?php if (is_writable('../inc/driver-conf.php')) { echo '<span style="color: green;"><b>Yes</b></span>'; } else { echo '<span style="color: red;"><b>No</b></span>'; } ?></td>
  98. </tr>
  99. </table>
  100. <br>
  101. The above files should be writable, otherwise the installation will not continue!
  102. </div>
  103. </div>
  104. <?php
  105. break;
  106. case 3:
  107. ?>
  108. <script type="text/javascript">
  109. function next() {
  110. $.ajax({
  111. 'url': './db_test_call.php?db_user='+$("input#db_user").val()+'&db_pass='+$("input#db_pass").val()+'&db_host='+$("input#db_host").val()+'&db_db='+$("input#db_db").val(),
  112. 'dataType': "json",
  113. 'success': function(data) {
  114. if (data['error']=='no') checkWallet();
  115. else alert('Database error! Can\'t connect to database! Please check if provided informations are correct and try again.');
  116. }
  117. });
  118. }
  119. function checkWallet() {
  120. $.ajax({
  121. 'url': './driver_test_call.php?w_user='+$("input#w_user").val()+'&w_pass='+$("input#w_pass").val()+'&w_host='+$("input#w_host").val()+'&w_port='+$("input#w_port").val(),
  122. 'dataType': "json",
  123. 'success': function(data) {
  124. document.getElementById('mform').submit();
  125. },
  126. 'error': function() {
  127. alert('Wallet error! Can\'t connect to wallet! Please check if provided informations are correct and try again.');
  128. }
  129. });
  130. }
  131. </script>
  132. <div class="allbody">
  133. <div class="alls">
  134. <form id="mform" method="post" action="./?checkCons">
  135. <h3>Database Info</h3>
  136. <i>Please fill in correct database info:</i>
  137. <br>
  138. <table>
  139. <tr>
  140. <td>Host:</td>
  141. <td><input type="text" name="db_host" id="db_host" value="localhost"></td>
  142. </tr>
  143. <tr>
  144. <td>Username:</td>
  145. <td><input type="text" name="db_user" id="db_user" placeholder="DB user"></td>
  146. </tr>
  147. <tr>
  148. <td>Password:</td>
  149. <td><input type="text" name="db_pass" id="db_pass" placeholder="DB pass"></td>
  150. </tr>
  151. <tr>
  152. <td>Database:</td>
  153. <td><input type="text" name="db_name" id="db_db" placeholder="DB name"></td>
  154. </tr>
  155. </table>
  156. <h3>Wallet Info</h3>
  157. <i>Please fill in correct wallet info:</i>
  158. <br>
  159. <table>
  160. <tr>
  161. <td>Host:</td>
  162. <td><input type="text" name="w_host" id="w_host" value="localhost"></td>
  163. </tr>
  164. <tr>
  165. <td>Login:</td>
  166. <td><input type="text" name="w_user" id="w_user" placeholder="Wallet user"></td>
  167. </tr>
  168. <tr>
  169. <td>Password:</td>
  170. <td><input type="text" name="w_pass" id="w_pass" placeholder="Wallet password"></td>
  171. </tr>
  172. <tr>
  173. <td>Port:</td>
  174. <td><input type="text" name="w_port" id="w_port" placeholder="Wallet port"></td>
  175. </tr>
  176. </table>
  177. </form>
  178. </div>
  179. </div>
  180. <?php
  181. break;
  182. case 4:
  183. ?>
  184. <script type="text/javascript">
  185. function next() {
  186. document.getElementById('mform').submit();
  187. }
  188. </script>
  189. <div class="allbody">
  190. <div class="alls">
  191. <h3>Basic Settings</h3>
  192. <br>
  193. <form id="mform" action="./?saveB" method="post">
  194. <table>
  195. <tr>
  196. <td>Site title:</td>
  197. <td><input type="text" name="s_title"></td>
  198. </tr>
  199. <tr>
  200. <td>Site description:</td>
  201. <td><input type="text" name="s_desc"></td>
  202. </tr>
  203. <tr>
  204. <td>URL:</td>
  205. <td><input type="text" name="s_url"></td>
  206. <td>(<b>without <i>http://</i></b>)</td>
  207. </tr>
  208. <tr>
  209. <td>Currency:</td>
  210. <td><input type="text" name="s_cur" value="Bitcoin" disabled></td>
  211. </tr>
  212. <tr>
  213. <td>Currency sign:</td>
  214. <td><input type="text" name="s_cur_sign" value="BTC" disabled></td>
  215. </tr>
  216. </table>
  217. </form>
  218. </div>
  219. </div>
  220. <?php
  221. break;
  222. case 5:
  223. ?>
  224. <script type="text/javascript">
  225. function next() {
  226. window.location.href='./?step=6';
  227. }
  228. </script>
  229. <div class="allbody">
  230. <div class="alls">
  231. <h3>CRON setup</h3>
  232. In order to BitcoinDice work properly, you must have the CRON set this way:
  233. <br><br>
  234. <b>Every 1 minute</b>: <i>content/cron/check_deposits.php</i>
  235. <br><br><hr>
  236. <b>Example (Linux):</b>
  237. <br><br>
  238. 1) <i>Open CRON table:</i>
  239. <br>
  240. $ crontab -e
  241. <br><br>
  242. 2) <i>Add the following line:</i>
  243. <br>
  244. * * * * * cd /var/www/content/cron; php check_deposits.php;
  245. <br><br>
  246. 3) Save CRON table by pressing <b>CTRL</b>+<b>X</b>, than confirm (<b>Y</b>) and press <b>enter</b>.
  247. <br><br>
  248. 4) Restart CRON service:
  249. <br>
  250. $ service cron restart
  251. <br><br>
  252. That's all.
  253. </div>
  254. </div>
  255. <?php
  256. break;
  257. case 6:
  258. ?>
  259. <div class="allbody">
  260. <div class="alls">
  261. <h3>Thank You!</h3>
  262. <br>
  263. Your installation is done! You can login to administration or try your luck at your own gambling site :-)
  264. <br>
  265. <br>
  266. Admin details:<br>
  267. &nbsp;Username: <b>admin</b><br>
  268. &nbsp;Password: <b>admin</b>
  269. <br>
  270. <br>
  271. <i>Don't forget to change this info after first login!</i>
  272. <br>
  273. <br>
  274. <b>Warning!</b> Please remove the <i>/install</i> directory now, otherwise there is a security risk.
  275. </div>
  276. </div>
  277. <?php
  278. break;
  279. }
  280. ?>
  281. <div class="allbody">
  282. <div class="alls" style="padding: 5px; height: 30px;">
  283. <div style="float: left; font-style: italic;">
  284. <h2>Step: <?php echo $step; ?></h2>
  285. </div>
  286. <div style="float: right;">
  287. <?php
  288. if ($step==6) echo '<input id="next" type="button" onclick="javascript:window.location.href=\'../admin/\';" value="Go to Admin!" style="padding: 5px;">';
  289. else echo '<input id="next" type="button" onclick="javascript:next();" value="Next ->" style="padding: 5px;">';
  290. ?>
  291. </div>
  292. </div>
  293. </div>
  294. <?php
  295. if ($step==3 && isset($_GET['db'])) echo '<script type="text/javascript">alert("Can\'t connect to database! Please check if provided informations are correct and try again.");</script>';
  296. ?>
  297. </body>
  298. </html>