add-free.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. if (strlen($id) < 32)
  12. die("Invalid session id");
  13. $row = $db->query("SELECT rowid,* FROM sessions WHERE id='$id'")->fetch();
  14. if ($row == false) {
  15. die("Session not found");
  16. }
  17. $uri = $row['redirect_uri'];
  18. $rowid = $row['rowid'];
  19. $realm = $row['realm'];
  20. $row = $db->query("SELECT value FROM osu_config WHERE realm='$realm' AND field='free_account'")->fetch();
  21. if (!$row || strlen($row['value']) == 0) {
  22. die("Free account disabled");
  23. }
  24. $user = $row['value'];
  25. $row = $db->query("SELECT password FROM users WHERE identity='$user' AND realm='$realm'")->fetch();
  26. if (!$row)
  27. die("Free account not found");
  28. $pw = $row['password'];
  29. if (!$db->exec("UPDATE sessions SET user='$user', password='$pw', realm='$realm', machine_managed='1' WHERE rowid=$rowid")) {
  30. die("Failed to update session database");
  31. }
  32. $db->exec("INSERT INTO eventlog(user,realm,sessionid,timestamp,notes) " .
  33. "VALUES ('$user', '$realm', '$id', " .
  34. "strftime('%Y-%m-%d %H:%M:%f','now'), " .
  35. "'completed user input response for a new PPS MO')");
  36. header("Location: $uri", true, 302);
  37. ?>