Account and permission manager and security log viewer. https://netsyms.biz/apps/managepanel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Log.lib.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. class Log {
  8. /**
  9. *
  10. * @global $database
  11. * @param int/LogType $type Either an integer (as defined by the constants in class LogType) or a LogType object.
  12. * @param int/User $user Either a UID number or a User object.
  13. * @param string $data Extra data to include in the log, in addition to the timestamp, log type, user, and IP address.
  14. */
  15. public static function insert($type, $user, string $data = "") {
  16. global $database;
  17. // find IP address
  18. $ip = IPUtils::getClientIP();
  19. if (gettype($type) == "object" && is_a($type, "LogType")) {
  20. $type = $type->getType();
  21. }
  22. if (is_a($user, "User")) {
  23. $uid = $user->getUID();
  24. } else if (gettype($user) == "integer") {
  25. $uid = $user;
  26. } else {
  27. $uid = null;
  28. }
  29. $database->insert("authlog", ['logtime' => date("Y-m-d H:i:s"), 'logtype' => $type, 'uid' => $uid, 'ip' => $ip, 'otherdata' => $data]);
  30. }
  31. }
  32. class LogType {
  33. const LOGIN_OK = 1;
  34. const LOGIN_FAILED = 2;
  35. const PASSWORD_CHANGED = 3;
  36. const API_LOGIN_OK = 4;
  37. const API_LOGIN_FAILED = 5;
  38. const BAD_2FA = 6;
  39. const API_BAD_2FA = 7;
  40. const BAD_CAPTCHA = 8;
  41. const ADDED_2FA = 9;
  42. const REMOVED_2FA = 10;
  43. const LOGOUT = 11;
  44. const API_AUTH_OK = 12;
  45. const API_AUTH_FAILED = 13;
  46. const API_BAD_KEY = 14;
  47. const LOG_CLEARED = 15;
  48. const USER_REMOVED = 16;
  49. const USER_ADDED = 17;
  50. const USER_EDITED = 18;
  51. const MOBILE_LOGIN_OK = 19;
  52. const MOBILE_LOGIN_FAILED = 20;
  53. const MOBILE_BAD_KEY = 21;
  54. private $type;
  55. function __construct(int $type) {
  56. $this->type = $type;
  57. }
  58. public function getType(): int {
  59. return $type;
  60. }
  61. }