Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
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.

setup.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /*
  6. * This script will create a local administrator account.
  7. */
  8. require __DIR__ . '/required.php';
  9. if ($database->has('accounts', ["[>]assigned_permissions" => ["uid" => "uid"]], ['permid' => 1])) {
  10. die("An admin account already exists, exiting.");
  11. }
  12. if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['realname'])) {
  13. ?>
  14. <!DOCTYPE html>
  15. <title>Admin Account Creation</title>
  16. <h1>Admin Account Creation tool</h1>
  17. <form action="setup.php" method="POST">
  18. Username: <input type="text" name="username" placeholder="Username" required="required" /><br />
  19. Password: <input type="text" name="password" placeholder="Password" required="required" /><br />
  20. Name: <input type="text" name="realname" placeholder="Real Name" required="required" /><br />
  21. Email: <input type="email" name="email" placeholder="Email Address" /><br />
  22. <button type="submit">
  23. Create account
  24. </button>
  25. </form>
  26. <?php
  27. } else {
  28. header("Content-Type: text/plain");
  29. $user = User::byUsername($_POST['username']);
  30. if ($user->exists()) {
  31. $userid = $user->getID();
  32. echo "User already exists, skipping creation.\n";
  33. } else {
  34. $userid = User::add($_POST['username'], $_POST['password'], $_POST['realname'], (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : null), "", "", 1);
  35. echo "User account #$userid created.\n";
  36. }
  37. $database->insert('assigned_permissions', ['uid' => $userid, 'permid' => 1]);
  38. die("ADMIN permission assigned.");
  39. }