add-mo.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. require('config.php');
  3. $db = new PDO($osu_db);
  4. if (!$db) {
  5. die($sqliteerror);
  6. }
  7. if (isset($_POST["id"]))
  8. $id = preg_replace("/[^a-fA-F0-9]/", "", $_POST["id"]);
  9. else
  10. die("Missing session id");
  11. $user = $_POST["user"];
  12. $pw = $_POST["password"];
  13. if (strlen($id) < 32 || !isset($user) || !isset($pw)) {
  14. die("Invalid POST data");
  15. }
  16. if (strlen($user) < 1 || strncasecmp($user, "cert-", 5) == 0) {
  17. echo "<html><body><p><red>Invalid username</red></p>\n";
  18. echo "<a href=\"signup.php?session_id=$id\">Try again</a>\n";
  19. echo "</body></html>\n";
  20. exit;
  21. }
  22. $row = $db->query("SELECT rowid,* FROM sessions WHERE id='$id'")->fetch();
  23. if ($row == false) {
  24. die("Session not found");
  25. }
  26. $realm = $row['realm'];
  27. $userrow = $db->query("SELECT identity FROM users WHERE identity='$user' AND realm='$realm'")->fetch();
  28. if ($userrow) {
  29. echo "<html><body><p><red>Selected username is not available</red></p>\n";
  30. echo "<a href=\"signup.php?session_id=$id\">Try again</a>\n";
  31. echo "</body></html>\n";
  32. exit;
  33. }
  34. $uri = $row['redirect_uri'];
  35. $rowid = $row['rowid'];
  36. if (!$db->exec("UPDATE sessions SET user='$user', password='$pw', realm='$realm', type='password' WHERE rowid=$rowid")) {
  37. die("Failed to update session database");
  38. }
  39. $db->exec("INSERT INTO eventlog(user,realm,sessionid,timestamp,notes) " .
  40. "VALUES ('$user', '$realm', '$id', " .
  41. "strftime('%Y-%m-%d %H:%M:%f','now'), " .
  42. "'completed user input response for a new PPS MO')");
  43. header("Location: $uri", true, 302);
  44. ?>