functions.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. // MTSM - Minetest Server Manager
  3. // (C) Chris Dorman, 2021
  4. // License: CC-BY-SA version 3.0
  5. // http://github.com/Pentium44/MTSM
  6. include("config.php");
  7. function recurse_copy($src,$dst) {
  8. $dir = opendir($src);
  9. @mkdir($dst);
  10. while(false !== ( $file = readdir($dir)) ) {
  11. if (( $file != '.' ) && ( $file != '..' )) {
  12. if ( is_dir($src . '/' . $file) ) {
  13. recurse_copy($src . '/' . $file,$dst . '/' . $file);
  14. }
  15. else {
  16. copy($src . '/' . $file,$dst . '/' . $file);
  17. }
  18. }
  19. }
  20. closedir($dir);
  21. }
  22. function generateToken() {
  23. $length = 12;
  24. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  25. $charactersLength = strlen($characters);
  26. $randomToken = '';
  27. for ($i = 0; $i < $length; $i++) {
  28. $randomToken .= $characters[rand(0, $charactersLength - 1)];
  29. }
  30. file_put_contents("mtm_db/token.php", "<?php \$reg_token = \"$randomToken\"; ?>");
  31. }
  32. function loginForm() {
  33. ?>
  34. <br />
  35. <div class="login">
  36. Don't have an account? No problem, <a href="<?php echo $_SERVER['PHP_SELF']; ?>?forms=register">register here</a>!<br /><br />
  37. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
  38. <table><tr><td>
  39. Username:</td><td> <input class="text" type="text" name="username"></td></tr><tr><td>
  40. Password:</td><td> <input class="text" type="password" name="password"></td></tr></table>
  41. <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login">
  42. </form>
  43. </div>
  44. <?php
  45. }
  46. function changePassForm() {
  47. ?>
  48. <br />
  49. <div class="chgpass">
  50. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=changepass" method="post">
  51. <table><tr><td>
  52. Old password:</td><td> <input class="text" type="password" name="oldpass"></td></tr><tr><td>
  53. Password:</td><td> <input class="text" type="password" name="password"></td></tr><tr><td>
  54. Password Again:</td><td> <input class="text" type="password" name="password_again"></td></tr>
  55. </table>
  56. <input class="text" type="submit" name="submitBtn" value="Change">
  57. </form>
  58. </div>
  59. <?php
  60. }
  61. /*function uploadForm() {
  62. print <<<EOD
  63. Upload
  64. <table style="margin:auto;">
  65. <form action="upload.php" method="post" enctype="multipart/form-data">
  66. <tr>
  67. <td>
  68. <input type="file" name="file[]" id="file" multiple><br>
  69. </td>
  70. <td>
  71. <input type="submit" name="submit" value="Upload">
  72. </td>
  73. </tr>
  74. </form>
  75. </table>
  76. EOD;
  77. }*/
  78. function modUploadForm() {
  79. ?>
  80. <p>
  81. Warning: Mod uploads MUST be in ZIP archive format and MUST have the mod contents WITHIN a parent directory
  82. within the archive. Failure to do so would cause for non-working mod installations into your user mods menu.
  83. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=upload-modzip" method="POST" enctype="multipart/form-data">
  84. <input type="file" name="file"></input>
  85. <input style="padding: 2px;" class="text" type="submit" name="upload-btn" value="Upload">
  86. </form>
  87. </p>
  88. <?php
  89. }
  90. function modsForm() {
  91. ?>
  92. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=configure-mods" method="post">
  93. <table><tr>
  94. <?php
  95. chdir("mods");
  96. $docount = 0;
  97. foreach(glob("*") as $filename) {
  98. echo "<td><input class='text' type='checkbox' name='$filename'> $filename</td>\n";
  99. $docount++;
  100. if($docount == 3) {
  101. echo "</tr><tr>";
  102. $docount = 0;
  103. }
  104. }
  105. chdir("..");
  106. ?>
  107. </tr></table>
  108. <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Set mods">
  109. </form>
  110. <?php
  111. }
  112. function userModsForm($username) {
  113. if(count(glob("mtm_db/usermods/$username/*")) !== 0) {
  114. ?>
  115. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=configure-user-mods" method="post">
  116. <?php
  117. chdir("mtm_db/usermods/$username/");
  118. foreach(glob("*") as $filename) {
  119. echo "<input class='text' type='checkbox' name='$filename'> $filename<br />\n";
  120. }
  121. chdir("../../../");
  122. ?>
  123. <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Set mods">
  124. </form>
  125. <?php
  126. } else {
  127. echo "No user mods available!";
  128. }
  129. }
  130. function settingsForm() {
  131. ?>
  132. <div class="login">
  133. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=configure-server" method="post">
  134. <input class="text" type="checkbox" name="enablepvp"> Enable PVP<br />
  135. <input class="text" type="checkbox" name="creative"> Creative Mode<br />
  136. <input class="text" type="checkbox" name="enabledamage"> Enable Damage<br />
  137. <input class="text" type="checkbox" name="serverannounce"> Server Announcement<br />
  138. Server Name: <input class="text" type="text" name="servername"><br />
  139. Server Desc: <input class="text" type="text" name="serverdesc"><br />
  140. Server Website: <input class="text" type="text" name="serverurl"><br />
  141. Server MOTD: <input class="text" type="text" name="motd"><br />
  142. Map Generation: <select name="mgname">
  143. <option value="v7">v7</option>
  144. <option value="v6">v6</option>
  145. <option value="v5">v5</option>
  146. <option value="valleys">valleys</option>
  147. <option value="carpathian">carpathian</option>
  148. <option value="flat">flat</option>
  149. <option value="fractal">fractal</option>
  150. </select><br />
  151. Default Privs: <input class="text" type="text" name="defaultprivs" value="shout, interact, home"><br />
  152. Spawnpoint (Format example: '32, 20, -140')<br /> <input class="text" type="text" name="staticspawnpoint"><br />
  153. Player Transfer Distance (Value in chunks, 0 = unlimited)<br />
  154. <input class="text" type="text" style="width: 50px;" name="playertransferdistance"><br />
  155. <input class="text" type="submit" name="submitBtn" value="Set">
  156. </form>
  157. </div>
  158. <?php
  159. }
  160. function registerForm() {
  161. ?>
  162. <br />
  163. <div class="login">
  164. Don't have a registration code? Reach out! cddo [at] riseup [dot] net<br />
  165. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=register" method="post">
  166. <table><tr><td>
  167. Username:</td><td> <input class="text" type="text" name="username"></td></tr><tr><td>
  168. Full name:</td><td> <input class="text" type="text" name="fullname"></td></tr><tr><td>
  169. Email:</td><td><input class="text" type="text" name="email"></td></tr><tr><td>
  170. Password:</td><td> <input class="text" type="password" name="password"></td></tr><tr><td>
  171. Password again:</td><td> <input class="text" type="password" name="password-again"></td></tr><tr><td>
  172. <?php if($GLOBALS['reg_token_required'] == "true") { echo 'Registration token (required):</td><td> <input class="text" type="text" name="codeword"></td></tr><tr><td>'; } ?>
  173. Go:</td><td> <input class="text" type="submit" name="submitBtn" value="Register">
  174. </td></tr></table>
  175. </form>
  176. </div>
  177. <?php
  178. }
  179. ?>