4
0

auth.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. $debug = false; //CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  3. require_once("user.php");
  4. $USER = new User("registration_callback");
  5. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  6. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  7. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  8. $currentIP = get_client_ip();
  9. if ($whitelist) {
  10. $skipped = false;
  11. if(in_array($currentIP, getWhitelist($whitelist))) {
  12. !$debug ? exit(http_response_code(200)) : die("$currentIP Whitelist Authorized");
  13. }else{
  14. $skipped = true;
  15. }
  16. }
  17. if ($blacklist) {
  18. if(in_array($currentIP, getWhitelist($blacklist))) {
  19. !$debug ? exit(http_response_code(401)) : die("$currentIP Blacklisted");
  20. }
  21. }
  22. if (isset($_GET['admin'])) {
  23. if($USER->authenticated && $USER->role == "admin" && !in_array(strtoupper($USER->username), getBannedUsers($ban))) {
  24. !$debug ? exit(http_response_code(200)) : die("$USER->username on $currentIP Authorized At Admin Level");
  25. } else {
  26. !$debug ? exit(http_response_code(401)) : die("$USER->username on $currentIP Not Authorized At Admin Level");
  27. }
  28. }
  29. if (isset($_GET['user'])) {
  30. if($USER->authenticated && !in_array(strtoupper($USER->username), getBannedUsers($ban))) {
  31. !$debug ? exit(http_response_code(200)) : die("$USER->username on $currentIP Authorized At User Level");
  32. } else {
  33. !$debug ? exit(http_response_code(401)) : die("$USER->username on $currentIP Not Authorized At User Level");
  34. }
  35. }
  36. if (!isset($_GET['user']) && !isset($_GET['admin']) && !isset($_GET['whitelist'])) {
  37. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  38. }
  39. if ($skipped) {
  40. !$debug ? exit(http_response_code(401)) : die("$USER->username on $currentIP Not Authorized Nor On Whitelist");
  41. }
  42. ?>