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.

reports.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. // Detect if loaded by the user or by PHP
  6. if (count(get_included_files()) == 1) {
  7. define("LOADED", true);
  8. } else {
  9. define("LOADED", false);
  10. }
  11. require_once __DIR__ . "/../required.php";
  12. dieifnotloggedin();
  13. if (LOADED) {
  14. if (isset($VARS['type']) && isset($VARS['format'])) {
  15. generateReport($VARS['type'], $VARS['format']);
  16. die();
  17. } else {
  18. $Strings->get("invalid parameters");
  19. die();
  20. }
  21. }
  22. function getUserReport(): Report {
  23. global $database, $Strings;
  24. $users = $database->select(
  25. "accounts", [
  26. "[>]acctstatus" => ["acctstatus" => "statusid"],
  27. "[>]accttypes" => ["accttype" => "typeid"]
  28. ], [
  29. "uid", "username", "realname", "email", "statuscode", "typecode", "authsecret"
  30. ]
  31. );
  32. $report = new Report($Strings->get("Users", false));
  33. $report->setHeader([
  34. $Strings->get("uid", false),
  35. $Strings->get("username", false),
  36. $Strings->get("name", false),
  37. $Strings->get("email", false),
  38. $Strings->get("status", false),
  39. $Strings->get("type", false),
  40. $Strings->get("2fa", false)
  41. ]);
  42. for ($i = 0; $i < count($users); $i++) {
  43. $report->addDataRow([
  44. $users[$i]["uid"],
  45. $users[$i]["username"],
  46. $users[$i]["realname"],
  47. $users[$i]["email"],
  48. $users[$i]["statuscode"],
  49. $users[$i]["typecode"],
  50. is_null($users[$i]["authsecret"]) ? "0" : "1"
  51. ]);
  52. }
  53. return $report;
  54. }
  55. function getGroupReport() {
  56. global $database, $Strings;
  57. $groups = $database->select('assigned_groups', [
  58. "[>]groups" => ['groupid'],
  59. "[>]accounts" => ['uid']
  60. ], [
  61. 'username',
  62. 'realname',
  63. 'accounts.uid',
  64. 'groupname',
  65. 'groupid'
  66. ]);
  67. $header = [$Strings->get("group id", false), $Strings->get("group name", false), $Strings->get("uid", false), $Strings->get("username", false), $Strings->get("name", false)];
  68. $data = [];
  69. for ($i = 0; $i < count($groups); $i++) {
  70. $data[] = [
  71. $groups[$i]["groupid"],
  72. $groups[$i]["groupname"],
  73. $groups[$i]["uid"],
  74. $groups[$i]["username"],
  75. $groups[$i]["realname"]
  76. ];
  77. }
  78. return new Report($Strings->get("Groups", false), $header, $data);
  79. }
  80. function getManagerReport() {
  81. global $database, $Strings;
  82. $managers = $database->select('managers', [
  83. "[>]accounts (manager)" => ['managerid' => 'uid'],
  84. "[>]accounts (employee)" => ['employeeid' => 'uid']
  85. ], [
  86. 'managerid',
  87. 'employeeid',
  88. 'manager.username (manageruser)',
  89. 'employee.username (employeeuser)',
  90. 'manager.realname (managername)',
  91. 'employee.realname (employeename)',
  92. ]);
  93. $header = [$Strings->get("manager name", false), $Strings->get("manager username", false), $Strings->get("employee name", false), $Strings->get("employee username", false)];
  94. $data = [];
  95. for ($i = 0; $i < count($managers); $i++) {
  96. $data[] = [
  97. $managers[$i]["managername"],
  98. $managers[$i]["manageruser"],
  99. $managers[$i]["employeename"],
  100. $managers[$i]["employeeuser"]
  101. ];
  102. }
  103. return new Report($Strings->get("Managers", false), $header, $data);
  104. }
  105. function getPermissionReport() {
  106. global $database, $Strings;
  107. $permissions = $database->select('assigned_permissions', [
  108. "[>]accounts" => ['uid' => 'uid'],
  109. "[>]permissions" => ['permid' => 'permid']
  110. ], [
  111. 'username',
  112. 'realname',
  113. 'assigned_permissions.uid',
  114. 'permissions.permid',
  115. 'permcode'
  116. ]);
  117. $header = [$Strings->get("uid", false), $Strings->get("username", false), $Strings->get("name", false), $Strings->get("permission", false), $Strings->get("permission id", false)];
  118. $data = [];
  119. for ($i = 0; $i < count($permissions); $i++) {
  120. $data[] = [
  121. $permissions[$i]["uid"],
  122. $permissions[$i]["username"],
  123. $permissions[$i]["realname"],
  124. $permissions[$i]["permcode"],
  125. $permissions[$i]["permid"],
  126. ];
  127. }
  128. return new Report($Strings->get("Permissions", false), $header, $data);
  129. }
  130. function getSecurityReport() {
  131. global $database, $Strings;
  132. $log = $database->select('authlog', [
  133. "[>]logtypes" => ['logtype'],
  134. "[>]accounts" => ['uid']
  135. ], [
  136. 'logtime',
  137. 'typename',
  138. 'uid',
  139. 'username',
  140. 'realname',
  141. 'ip',
  142. 'otherdata'
  143. ]);
  144. $header = [$Strings->get("logtime", false), $Strings->get("logtype", false), $Strings->get("ip address", false), $Strings->get("uid", false), $Strings->get("username", false), $Strings->get("name", false), $Strings->get("other data", false)];
  145. $data = [];
  146. for ($i = 0; $i < count($log); $i++) {
  147. $data[] = [
  148. $log[$i]["logtime"],
  149. $log[$i]["typename"],
  150. $log[$i]["ip"],
  151. $log[$i]["uid"],
  152. $log[$i]["username"],
  153. $log[$i]["realname"],
  154. $log[$i]["otherdata"]
  155. ];
  156. }
  157. return new Report($Strings->get("Security", false), $header, $data);
  158. }
  159. function getReport($type): Report {
  160. switch ($type) {
  161. case "users":
  162. return getUserReport();
  163. break;
  164. case "groups":
  165. return getGroupReport();
  166. break;
  167. case "managers":
  168. return getManagerReport();
  169. break;
  170. case "permissions":
  171. return getPermissionReport();
  172. break;
  173. case "security":
  174. return getSecurityReport();
  175. break;
  176. default:
  177. return new Report("error", ["ERROR"], ["Invalid report type."]);
  178. }
  179. }
  180. function generateReport($type, $format) {
  181. $report = getReport($type);
  182. $report->output($format);
  183. }