/install.php

https://github.com/keeganmann/FRC-Stats · PHP · 181 lines · 177 code · 0 blank · 4 comment · 6 complexity · a1be2e89bbd3b53108b6ca4aa4671658 MD5 · raw file

  1. <html>
  2. <head>
  3. <title>FRC STATS - <?php echo $title ?></title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <link rel="stylesheet" type="text/css" href="styles.css" />
  6. <link rel="shortcut icon" href="favicon.ico" />
  7. <style type="text/css">
  8. table{
  9. margin-left: auto;
  10. margin-right: auto;
  11. width:auto;
  12. background: #b9b9b9;
  13. color: #555555;
  14. }
  15. h2, h1{
  16. color: #ffffff;
  17. }
  18. body {
  19. font-family: Helvetica, sans-serif;
  20. font-size: 14px;
  21. text-align:center;
  22. background-color: #b6b6b6;
  23. background-color: #000000;
  24. background-image: url('graphics/tilestars.jpg');
  25. background-repeat:repeat;
  26. color: #b6b6b6;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <?php
  32. include('config.php');
  33. if(frcgetinstalled()){
  34. ?>
  35. <h1 style="color: #ff0000;">ERROR: SYSTEM ALREADY INSTALLED</h1>
  36. <A href="index.php">Click here to continue</a>
  37. <?php
  38. }
  39. else if ($_POST['username'] != "") {
  40. echo "installing...";
  41. //set database login info in config.php
  42. $file = fopen("config.php", "a");
  43. fwrite($file, "<?php\n");
  44. fwrite($file, "\$frcmysqlusername = " . $_POST[username] . ";\n");
  45. fwrite($file, "\$frcmysqlpassword = " . $_POST[password] . ";\n");
  46. fwrite($file, "\$frcmysqldatabase = " . $_POST[database] . ";\n");
  47. fwrite($file, "\$frcmysqlserverurl =" . $_POST[serverurl] . ";\n");
  48. fwrite($file, "\$frcinstalled = TRUE;\n");
  49. fwrite($file, "?>\n");
  50. fclose($file);
  51. echo "connecting...";
  52. $con = mysql_connect($_POST[serverurl], $_POST[username], $_POST[password]);
  53. if (!$con)
  54. die("ERROR: COULD NOT CONNECT TO DATABASE");
  55. //create the database
  56. echo "create database...";
  57. mysql_query("CREATE DATABASE " . $_POST[database]);
  58. mysql_select_db($_POST[database], $con);
  59. //create the tables
  60. echo "create tables...";
  61. mysql_query("
  62. CREATE TABLE Accounts
  63. (
  64. username varchar(50),
  65. password varchar(50),
  66. firstname varchar(50),
  67. lastname varchar(50),
  68. email varchar(100),
  69. permissions varchar(50)
  70. )");
  71. mysql_query("
  72. CREATE TABLE Matches
  73. (
  74. matchnumber int(11),
  75. team1 int(11),
  76. team2 int(11),
  77. team3 int(11),
  78. team4 int(11),
  79. team5 int(11),
  80. team6 int(11),
  81. redscore int(11),
  82. bluescore int(11)
  83. )");
  84. mysql_query("
  85. CREATE TABLE Performance
  86. (
  87. matchnumber int(11),
  88. teamnumber int(5)
  89. )");
  90. mysql_query("
  91. CREATE TABLE Robopics
  92. (
  93. teamnumber int(11),
  94. path varchar(50)
  95. )");
  96. mysql_query("
  97. CREATE TABLE SurveyResponses
  98. (
  99. teamnumber int(5)
  100. )");
  101. mysql_query("
  102. CREATE TABLE TeamData
  103. (
  104. teamnumber int(5),
  105. teamname varchar(50),
  106. city varchar(50),
  107. state varchar(50),
  108. country varchar(50),
  109. rookieyear int(4)
  110. )");
  111. //create root account
  112. echo "adding root user...";
  113. mysql_query("
  114. INSERT INTO Accounts
  115. VALUES ('root', '" . md5($_POST['rootpass']) . "', NULL, NULL, NULL, 'admin')");
  116. mysql_close()
  117. ?>
  118. <h1>INSTALLATION SUCCESSFUL</h1>
  119. <A href="index.php">Click here to continue</a>
  120. <?php
  121. } else {
  122. ?>
  123. <h1>Install</h1>
  124. <form action="install.php" method="post">
  125. <h2>Database</h2>
  126. <table>
  127. <tr>
  128. <td>
  129. Username:
  130. </td>
  131. <td>
  132. <input type="text" name="username" value="root" /><br/>
  133. </td>
  134. </tr>
  135. <tr>
  136. <td>
  137. Password:
  138. </td>
  139. <td>
  140. <input type="password" name="password" value="nageek5tree" /><br/>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td>
  145. Database Name:
  146. </td>
  147. <td>
  148. <input type="text" name="database" value="frc_stats_2011" /><br/>
  149. </td>
  150. </tr>
  151. <tr>
  152. <td>
  153. Server URL:
  154. </td>
  155. <td>
  156. <input type="text" name="serverurl" value="localhost" /><br/>
  157. </td>
  158. </tr>
  159. </table>
  160. <br/>
  161. <h2>Account</h2>
  162. <table>
  163. <tr>
  164. <td>
  165. root password:
  166. </td>
  167. <td>
  168. <input type="password" name="rootpass" value="cobalt60" /><br/>
  169. </td>
  170. </tr>
  171. </table>
  172. <br/>
  173. <p>
  174. <input type="submit" value="Install" />
  175. </p>
  176. </form>
  177. <?php
  178. }
  179. ?>
  180. </body>
  181. </html>