QwikClock is an employee time tracking app.
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.

api.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * Simple JSON API to allow other apps to access data from this app.
  4. *
  5. * Requests can be sent via either GET or POST requests. POST is recommended
  6. * as it has a lower chance of being logged on the server, exposing unencrypted
  7. * user passwords.
  8. */
  9. require __DIR__ . '/required.php';
  10. require_once __DIR__ . '/lib/login.php';
  11. require_once __DIR__ . '/lib/userinfo.php';
  12. header("Content-Type: application/json");
  13. $username = $VARS['username'];
  14. $password = $VARS['password'];
  15. if (user_exists($username) !== true || authenticate_user($username, $password, $errmsg) !== true) {
  16. header("HTTP/1.1 403 Unauthorized");
  17. die("\"403 Unauthorized\"");
  18. }
  19. $userinfo = getUserByUsername($username);
  20. // query max results
  21. $max = 20;
  22. if (preg_match("/^[0-9]+$/", $VARS['max']) === 1 && $VARS['max'] <= 1000) {
  23. $max = (int) $VARS['max'];
  24. }
  25. switch ($VARS['action']) {
  26. case "ping":
  27. $out = ["status" => "OK", "maxresults" => $max, "pong" => true];
  28. exit(json_encode($out));
  29. default:
  30. header("HTTP/1.1 400 Bad Request");
  31. die("\"400 Bad Request\"");
  32. }