users.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. require('config.php');
  3. $db = new PDO($osu_db);
  4. if (!$db) {
  5. die($sqliteerror);
  6. }
  7. if (isset($_GET["id"])) {
  8. $id = $_GET["id"];
  9. if (!is_numeric($id))
  10. $id = 0;
  11. } else
  12. $id = 0;
  13. if (isset($_GET["cmd"]))
  14. $cmd = $_GET["cmd"];
  15. else
  16. $cmd = '';
  17. if ($cmd == 'eventlog' && $id > 0) {
  18. $row = $db->query("SELECT dump FROM eventlog WHERE rowid=$id")->fetch();
  19. $dump = $row['dump'];
  20. if ($dump[0] == '<') {
  21. header("Content-type: text/xml");
  22. echo "<?xml version=\"1.0\"?>\n";
  23. echo $dump;
  24. } else {
  25. header("Content-type: text/plain");
  26. echo $dump;
  27. }
  28. exit;
  29. }
  30. if ($cmd == 'mo' && $id > 0) {
  31. $mo = $_GET["mo"];
  32. if (!isset($mo))
  33. exit;
  34. if ($mo != "devinfo" && $mo != "devdetail" && $mo != "pps")
  35. exit;
  36. $row = $db->query("SELECT $mo FROM users WHERE rowid=$id")->fetch();
  37. header("Content-type: text/xml");
  38. echo "<?xml version=\"1.0\"?>\n";
  39. echo $row[$mo];
  40. exit;
  41. }
  42. if ($cmd == 'cert' && $id > 0) {
  43. $row = $db->query("SELECT cert_pem FROM users WHERE rowid=$id")->fetch();
  44. header("Content-type: text/plain");
  45. echo $row['cert_pem'];
  46. exit;
  47. }
  48. ?>
  49. <html>
  50. <head><title>HS 2.0 users</title></head>
  51. <body>
  52. <?php
  53. if ($cmd == 'subrem-clear' && $id > 0) {
  54. $db->exec("UPDATE users SET remediation='' WHERE rowid=$id");
  55. }
  56. if ($cmd == 'subrem-add-user' && $id > 0) {
  57. $db->exec("UPDATE users SET remediation='user' WHERE rowid=$id");
  58. }
  59. if ($cmd == 'subrem-add-machine' && $id > 0) {
  60. $db->exec("UPDATE users SET remediation='machine' WHERE rowid=$id");
  61. }
  62. if ($cmd == 'subrem-add-policy' && $id > 0) {
  63. $db->exec("UPDATE users SET remediation='policy' WHERE rowid=$id");
  64. }
  65. if ($cmd == 'subrem-add-free' && $id > 0) {
  66. $db->exec("UPDATE users SET remediation='free' WHERE rowid=$id");
  67. }
  68. if ($cmd == 'fetch-pps-on' && $id > 0) {
  69. $db->exec("UPDATE users SET fetch_pps=1 WHERE rowid=$id");
  70. }
  71. if ($cmd == 'fetch-pps-off' && $id > 0) {
  72. $db->exec("UPDATE users SET fetch_pps=0 WHERE rowid=$id");
  73. }
  74. if ($cmd == 'reset-pw' && $id > 0) {
  75. $db->exec("UPDATE users SET password='ChangeMe' WHERE rowid=$id");
  76. }
  77. if ($cmd == "policy" && $id > 0 && isset($_GET["policy"])) {
  78. $policy = $_GET["policy"];
  79. if ($policy == "no-policy" ||
  80. is_readable("$osu_root/spp/policy/$policy.xml")) {
  81. $db->exec("UPDATE users SET policy='$policy' WHERE rowid=$id");
  82. }
  83. }
  84. if ($cmd == "account-type" && $id > 0 && isset($_GET["type"])) {
  85. $type = $_GET["type"];
  86. if ($type == "shared")
  87. $db->exec("UPDATE users SET shared=1 WHERE rowid=$id");
  88. if ($type == "default")
  89. $db->exec("UPDATE users SET shared=0 WHERE rowid=$id");
  90. }
  91. if ($cmd == "set-osu-cred" && $id > 0) {
  92. $osu_user = $_POST["osu_user"];
  93. $osu_password = $_POST["osu_password"];
  94. if (strlen($osu_user) == 0)
  95. $osu_password = "";
  96. $db->exec("UPDATE users SET osu_user='$osu_user', osu_password='$osu_password' WHERE rowid=$id");
  97. }
  98. $dump = 0;
  99. if ($id > 0) {
  100. if (isset($_GET["dump"])) {
  101. $dump = $_GET["dump"];
  102. if (!is_numeric($dump))
  103. $dump = 0;
  104. } else
  105. $dump = 0;
  106. echo "[<a href=\"users.php\">All users</a>] ";
  107. if ($dump == 0)
  108. echo "[<a href=\"users.php?id=$id&dump=1\">Include debug dump</a>] ";
  109. else
  110. echo "[<a href=\"users.php?id=$id\">Without debug dump</a>] ";
  111. echo "<br>\n";
  112. $row = $db->query("SELECT rowid,* FROM users WHERE rowid=$id")->fetch();
  113. echo "<H3>" . $row['identity'] . "@" . $row['realm'] . "</H3>\n";
  114. echo "MO: ";
  115. if (strlen($row['devinfo']) > 0) {
  116. echo "[<a href=\"users.php?cmd=mo&id=$id&mo=devinfo\">DevInfo</a>]\n";
  117. }
  118. if (strlen($row['devdetail']) > 0) {
  119. echo "[<a href=\"users.php?cmd=mo&id=$id&mo=devdetail\">DevDetail</a>]\n";
  120. }
  121. if (strlen($row['pps']) > 0) {
  122. echo "[<a href=\"users.php?cmd=mo&id=$id&mo=pps\">PPS</a>]\n";
  123. }
  124. if (strlen($row['cert_pem']) > 0) {
  125. echo "[<a href=\"users.php?cmd=cert&id=$id\">Certificate</a>]\n";
  126. }
  127. echo "<BR>\n";
  128. echo "Fetch PPS MO: ";
  129. if ($row['fetch_pps'] == "1") {
  130. echo "On next connection " .
  131. "[<a href=\"users.php?cmd=fetch-pps-off&id=$id\">" .
  132. "do not fetch</a>]<br>\n";
  133. } else {
  134. echo "Do not fetch " .
  135. "[<a href=\"users.php?cmd=fetch-pps-on&id=$id\">" .
  136. "request fetch</a>]<br>\n";
  137. }
  138. $cert = $row['cert'];
  139. if (strlen($cert) > 0) {
  140. echo "Certificate fingerprint: $cert<br>\n";
  141. }
  142. echo "Remediation: ";
  143. $rem = $row['remediation'];
  144. if ($rem == "") {
  145. echo "Not required";
  146. echo " [<a href=\"users.php?cmd=subrem-add-user&id=" .
  147. $row['rowid'] . "\">add:user</a>]";
  148. echo " [<a href=\"users.php?cmd=subrem-add-machine&id=" .
  149. $row['rowid'] . "\">add:machine</a>]";
  150. echo " [<a href=\"users.php?cmd=subrem-add-policy&id=" .
  151. $row['rowid'] . "\">add:policy</a>]";
  152. echo " [<a href=\"users.php?cmd=subrem-add-free&id=" .
  153. $row['rowid'] . "\">add:free</a>]";
  154. } else if ($rem == "user") {
  155. echo "User [<a href=\"users.php?cmd=subrem-clear&id=" .
  156. $row['rowid'] . "\">clear</a>]";
  157. } else if ($rem == "policy") {
  158. echo "Policy [<a href=\"users.php?cmd=subrem-clear&id=" .
  159. $row['rowid'] . "\">clear</a>]";
  160. } else if ($rem == "free") {
  161. echo "Free [<a href=\"users.php?cmd=subrem-clear&id=" .
  162. $row['rowid'] . "\">clear</a>]";
  163. } else {
  164. echo "Machine [<a href=\"users.php?cmd=subrem-clear&id=" .
  165. $row['rowid'] . "\">clear</a>]";
  166. }
  167. echo "<br>\n";
  168. echo "<form>Policy: <select name=\"policy\" " .
  169. "onChange=\"window.location='users.php?cmd=policy&id=" .
  170. $row['rowid'] . "&policy=' + this.value;\">\n";
  171. echo "<option value=\"" . $row['policy'] . "\" selected>" . $row['policy'] .
  172. "</option>\n";
  173. $files = scandir("$osu_root/spp/policy");
  174. foreach ($files as $file) {
  175. if (!preg_match("/.xml$/", $file))
  176. continue;
  177. if ($file == $row['policy'] . ".xml")
  178. continue;
  179. $p = substr($file, 0, -4);
  180. echo "<option value=\"$p\">$p</option>\n";
  181. }
  182. echo "<option value=\"no-policy\">no policy</option>\n";
  183. echo "</select></form>\n";
  184. echo "<form>Account type: <select name=\"type\" " .
  185. "onChange=\"window.location='users.php?cmd=account-type&id=" .
  186. $row['rowid'] . "&type=' + this.value;\">\n";
  187. if ($row['shared'] > 0) {
  188. $default_sel = "";
  189. $shared_sel = " selected";
  190. } else {
  191. $default_sel = " selected";
  192. $shared_sel = "";
  193. }
  194. echo "<option value=\"default\"$default_sel>default</option>\n";
  195. echo "<option value=\"shared\"$shared_sel>shared</option>\n";
  196. echo "</select></form>\n";
  197. echo "Phase 2 method(s): " . $row['methods'] . "<br>\n";
  198. echo "<br>\n";
  199. echo "<a href=\"users.php?cmd=reset-pw&id=" .
  200. $row['rowid'] . "\">Reset AAA password</a><br>\n";
  201. echo "<br>\n";
  202. echo "<form action=\"users.php?cmd=set-osu-cred&id=" . $row['rowid'] .
  203. "\" method=\"POST\">\n";
  204. echo "OSU credentials (if username empty, AAA credentials are used):<br>\n";
  205. echo "username: <input type=\"text\" name=\"osu_user\" value=\"" .
  206. $row['osu_user'] . "\">\n";
  207. echo "password: <input type=\"password\" name=\"osu_password\">\n";
  208. echo "<input type=\"submit\" value=\"Set OSU credentials\">\n";
  209. echo "</form>\n";
  210. echo "<hr>\n";
  211. $user = $row['identity'];
  212. $osu_user = $row['osu_user'];
  213. $realm = $row['realm'];
  214. }
  215. if ($id > 0 || ($id == 0 && $cmd == 'eventlog')) {
  216. if ($id == 0) {
  217. echo "[<a href=\"users.php\">All users</a>] ";
  218. echo "<br>\n";
  219. }
  220. echo "<table border=1>\n";
  221. echo "<tr>";
  222. if ($id == 0) {
  223. echo "<th>user<th>realm";
  224. }
  225. echo "<th>time<th>address<th>sessionID<th>notes";
  226. if ($dump > 0)
  227. echo "<th>dump";
  228. echo "\n";
  229. if (isset($_GET["limit"])) {
  230. $limit = $_GET["limit"];
  231. if (!is_numeric($limit))
  232. $limit = 20;
  233. } else
  234. $limit = 20;
  235. if ($id == 0)
  236. $res = $db->query("SELECT rowid,* FROM eventlog ORDER BY timestamp DESC LIMIT $limit");
  237. else if (strlen($osu_user) > 0)
  238. $res = $db->query("SELECT rowid,* FROM eventlog WHERE (user='$user' OR user='$osu_user') AND realm='$realm' ORDER BY timestamp DESC LIMIT $limit");
  239. else
  240. $res = $db->query("SELECT rowid,* FROM eventlog WHERE user='$user' AND realm='$realm' ORDER BY timestamp DESC LIMIT $limit");
  241. foreach ($res as $row) {
  242. echo "<tr>";
  243. if ($id == 0) {
  244. echo "<td>" . $row['user'] . "\n";
  245. echo "<td>" . $row['realm'] . "\n";
  246. }
  247. echo "<td>" . $row['timestamp'] . "\n";
  248. echo "<td>" . $row['addr'] . "\n";
  249. echo "<td>" . $row['sessionid'] . "\n";
  250. echo "<td>" . $row['notes'] . "\n";
  251. $d = $row['dump'];
  252. if (strlen($d) > 0) {
  253. echo "[<a href=\"users.php?cmd=eventlog&id=" . $row['rowid'] .
  254. "\">";
  255. if ($d[0] == '<')
  256. echo "XML";
  257. else
  258. echo "txt";
  259. echo "</a>]\n";
  260. if ($dump > 0)
  261. echo "<td>" . htmlspecialchars($d) . "\n";
  262. }
  263. }
  264. echo "</table>\n";
  265. }
  266. if ($id == 0 && $cmd != 'eventlog') {
  267. echo "[<a href=\"users.php?cmd=eventlog&limit=50\">Eventlog</a>] ";
  268. echo "<br>\n";
  269. echo "<table border=1>\n";
  270. echo "<tr><th>User<th>Realm<th>Remediation<th>Policy<th>Account type<th>Phase 2 method(s)<th>DevId\n";
  271. $res = $db->query('SELECT rowid,* FROM users WHERE phase2=1');
  272. foreach ($res as $row) {
  273. echo "<tr><td><a href=\"users.php?id=" . $row['rowid'] . "\"> " .
  274. $row['identity'] . " </a>";
  275. echo "<td>" . $row['realm'];
  276. $rem = $row['remediation'];
  277. echo "<td>";
  278. if ($rem == "") {
  279. echo "Not required";
  280. } else if ($rem == "user") {
  281. echo "User";
  282. } else if ($rem == "policy") {
  283. echo "Policy";
  284. } else if ($rem == "free") {
  285. echo "Free";
  286. } else {
  287. echo "Machine";
  288. }
  289. echo "<td>" . $row['policy'];
  290. if ($row['shared'] > 0)
  291. echo "<td>shared";
  292. else
  293. echo "<td>default";
  294. echo "<td>" . $row['methods'];
  295. echo "<td>";
  296. $xml = xml_parser_create();
  297. xml_parse_into_struct($xml, $row['devinfo'], $devinfo);
  298. foreach($devinfo as $k) {
  299. if ($k['tag'] == 'DEVID') {
  300. echo $k['value'];
  301. break;
  302. }
  303. }
  304. echo "\n";
  305. }
  306. echo "</table>\n";
  307. }
  308. ?>
  309. </html>