admin.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Blacklister Admin</title>
  5. </head>
  6. <body>
  7. <div>
  8. <?php
  9. error_reporting(E_ALL);
  10. require_once 'action.php';
  11. require_once 'db.php';
  12. require_once 'token.php';
  13. require_once 'stats.php';
  14. if(!isset($_GET['token'])){
  15. echo "<form action='admin.php'><input type='text' size='35' id='token' name='token'><input type='submit' value='send token'></form></div></body></html>";
  16. exit;
  17. }
  18. if(isset($_GET['ip'])) {
  19. $ip = ip2long(substr(trim($_GET['ip']),0,15));
  20. }
  21. if(isset($_GET['token'])) {
  22. $token = substr(trim($_GET['token']),0,32);
  23. }
  24. if(isset($_GET['action'])) {
  25. $action = substr(trim($_GET['action']),0,12);
  26. }
  27. if(isset($_GET['userid'])) {
  28. $userid = substr(trim($_GET['userid']),0,32);
  29. }
  30. if(isset($_GET['role'])) {
  31. $role = substr(trim($_GET['role']),0,8);
  32. }
  33. if(isset($_GET['description'])) {
  34. $description = substr(trim($_GET['description']),0,40);
  35. }
  36. $stats = true;
  37. $tok = new token;
  38. if (!$tok->isAdmin($token)) {
  39. echo "admin access denied</div></body></html>";
  40. exit;
  41. }
  42. if($stats == true) {
  43. (new stats)->log($ip,$action,$token);
  44. }
  45. switch($action) {
  46. case 'deluser':
  47. if((new action)->delUser($userid)){
  48. echo " user removed " . $userid ."\n";
  49. } else {
  50. echo " fehler\n";
  51. };
  52. break;
  53. case 'adduser':
  54. if((new action)->addUser($userid,$role,$description)){
  55. echo " user added, token:" . $userid . " role:" .$role . " description: " . $description . "\n";
  56. } else {
  57. echo " fehler\n";
  58. };
  59. break;
  60. case 'blacklist':
  61. if((new action)->blackList($ip)){
  62. echo " blacklisted " . long2ip($ip) ."\n";
  63. } else {
  64. echo " fehler\n";
  65. };
  66. break;
  67. case 'deblacklist':
  68. if((new action)->deBlackList($ip)){
  69. echo " deblacklisted " . long2ip($ip) ."\n";
  70. } else {
  71. echo " fehler\n";
  72. };
  73. break;
  74. case 'whitelist':
  75. if((new action)->whiteList($ip)){
  76. echo " whitelisted " . long2ip($ip) ."\n";
  77. } else {
  78. echo " fehler\n";
  79. };
  80. break;
  81. case 'dewhitelist':
  82. if((new action)->deWhiteList($ip)){
  83. echo " dewhitelisted " . long2ip($ip) ."\n";
  84. } else {
  85. echo " fehler\n";
  86. };
  87. break;
  88. case 'list':
  89. if((new action)->list($ip)){
  90. echo " listed " . long2ip($ip) ."\n";
  91. } else {
  92. echo " fehler\n";
  93. };
  94. break;
  95. case 'delist':
  96. if((new action)->adminDeList($ip)){
  97. echo " delisted " . long2ip($ip) ."\n";
  98. } else {
  99. echo " fehler\n";
  100. };
  101. break;
  102. }
  103. ?>
  104. </div>
  105. <h3>Clients</h3>
  106. <table>
  107. <tr><th>Token</th><th>Role</th><th>Description</th><th></th></tr>
  108. <?php
  109. $userlist = (new action)->getUser();
  110. foreach($userlist as $user) {
  111. echo "<tr><td>" . $user[0] . "</td><td>" . $user[1] . "</td><td>" . $user[2] . "</td><td><input type='button' id='deluser' value='remove' onclick='window.location.href=\"admin.php?token=" . $token . "&action=deluser&userid=" . $user[0] . "\"'></td></tr>";
  112. }
  113. ?>
  114. <tr>
  115. <form action="admin.php">
  116. <input type="hidden" id="token" name="token" value="<?php echo $token; ?>">
  117. <input type="hidden" id="action" name="action" value="adduser">
  118. <td>
  119. <input type='text' id='userid' name='userid' size='35' readonly value='<?php echo bin2hex(random_bytes(16)) ?>'>
  120. <input type='button' id='createtoken' value='refresh' onclick='window.location.href="admin.php?token=<?php echo $token; ?>"'>
  121. </td><td>
  122. <input type='radio' id='reporter' name='role' value='reporter'>Reporter
  123. <input type='radio' id='consumer' name='role' value='consumer'>Consumer
  124. <input type='radio' id='admin' name='role' value='admin'>Admin
  125. </td><td>
  126. <input type='text' id='description' name='description'>
  127. </td><td>
  128. <input type='submit' value='add user'>
  129. </td></form>
  130. </tr>
  131. </table>
  132. <h3>Blacklist</h3>
  133. <table>
  134. <?php
  135. $blacklist = (new action)->getBlackList();
  136. foreach($blacklist as $blip) {
  137. echo "<tr><td>" . long2ip($blip) . "</td><td><input type='button' id='deblacklist' value='remove' onclick='window.location.href=\"admin.php?token=" . $token . "&action=deblacklist&ip=" . long2ip($blip) . "\"'></td></tr>";
  138. }
  139. ?>
  140. <tr>
  141. <form action="admin.php">
  142. <input type="hidden" id="token" name="token" value="<?php echo $token; ?>">
  143. <input type="hidden" id="action" name="action" value="blacklist">
  144. <td>
  145. <input type='text' id='ip' name='ip'>
  146. </td><td>
  147. <input type='submit' value='add to blacklist'>
  148. </form>
  149. </td></tr>
  150. </table>
  151. <h3>Whitelist</h3>
  152. <table border="0">
  153. <?php
  154. $whitelist = (new action)->getWhiteList();
  155. foreach($whitelist as $wlip) {
  156. echo "<tr><td>" . long2ip($wlip) . "</td><td><input type='button' id='dewhitelist' value='remove' onclick='window.location.href=\"admin.php?token=" . $token . "&action=dewhitelist&ip=" . long2ip($wlip) . "\"'></td></tr>";
  157. }
  158. ?>
  159. <tr>
  160. <form action="admin.php">
  161. <input type="hidden" id="token" name="token" value="<?php echo $token; ?>">
  162. <input type="hidden" id="action" name="action" value="whitelist">
  163. <td>
  164. <input type='text' id='ip' name='ip'>
  165. </td><td>
  166. <input type='submit' value='add to whitelist'>
  167. </form>
  168. </td></tr>
  169. </table>
  170. <h3>List</h3>
  171. <table border="0">
  172. <?php
  173. $list = (new action)->getList();
  174. foreach($list as $lip) {
  175. echo "<tr><td>" . long2ip($lip) . "</td>";
  176. echo "<td><input type='button' id='delist' value='remove' onclick='window.location.href=\"admin.php?token=" . $token . "&action=delist&ip=" . long2ip($lip) . "\"'></td>";
  177. echo "<td><input type='button' id='blacklist' value='blacklist' onclick='window.location.href=\"admin.php?token=" . $token . "&action=blacklist&ip=" . long2ip($lip) . "\"'></td>";
  178. echo "<td><input type='button' id='whitelist' value='whitelist' onclick='window.location.href=\"admin.php?token=" . $token . "&action=whitelist&ip=" . long2ip($lip) . "\"'></td></tr>";
  179. }
  180. ?>
  181. <tr>
  182. <form action="admin.php">
  183. <input type="hidden" id="token" name="token" value="<?php echo $token; ?>">
  184. <input type="hidden" id="action" name="action" value="list">
  185. <td>
  186. <input type='text' id='ip' name='ip'>
  187. </td><td>
  188. <input type='submit' value='add to list'>
  189. </form>
  190. </td></tr>
  191. </table>
  192. </body>
  193. </html>