From d317753235bb1d4af33245422517d9f17f0630fa Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Sun, 2 Jul 2017 18:39:30 +0200 Subject: [PATCH] Initial tools webui --- tools.php | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 tools.php diff --git a/tools.php b/tools.php new file mode 100644 index 0000000..96f0e99 --- /dev/null +++ b/tools.php @@ -0,0 +1,178 @@ + NOW() - INTERVAL '1 hour'", array($_SERVER['REMOTE_ADDR'])); + $fail_count = pg_fetch_result($res, 0, 0); + + if ($fail_count < 10) + { + // Retrieve password hash and eligibility to unlock door remotely. + $res = @pg_query_params(<< 0 OR active_members.flag != '') AS can_unlock + FROM auth + JOIN active_members USING (account) + JOIN accounts ON accounts.id = account + JOIN user_balances ON user_balances.id = account + WHERE (LOWER(accounts.name) = LOWER($1) OR LOWER(active_members.full_name) = LOWER($1)) + AND auth.realm = 'door' + ORDER BY can_unlock DESC NULLS LAST +SQL + , array($_POST['user'])); + + $row = pg_fetch_assoc($res); + + if ($row) + { + $account = $row['account']; + $balance = $row['balance']; + + if ($row['can_unlock'] != 't') + { + $error = 'User not authorized to unlock door'; + } + else if (!hash_equals(crypt($_POST['pin'], $row['data']), $row['data'])) + { + $error = 'Incorrect password'; + } + else + { + $ok = true; + } + } + else + { + $error = 'User ' . htmlentities($_POST['user'], ENT_QUOTES, 'utf-8') . ' not found'; + } + } + else + { + $error = "Too many login failures"; + $rate_limited = true; + } + } + +if ($ok) +{ + @pg_query_params("INSERT INTO auth_log (host, account, realm) VALUES ($1, $2, 'tool-a001')", array($_SERVER['REMOTE_ADDR'], $account)); + @pg_query_params('INSERT INTO checkins (account) VALUES ($1)', array($account)); +} +else if ($rate_limited) +{ + @pg_query_params("INSERT INTO auth_log (host, realm) VALUES ($1, 'tool-a001')", array($_SERVER['REMOTE_ADDR'])); +} +?> + + + + Bitraf Door + + + + + + + + + +
+ +
+ + +
+

Tool lock is open!

Put it back after use! +

(Current time: )

+ +
+
+

P2K12

Your current balance in P2K12 is . +
+ + +

Error!

+ + +
+
+ +
+
+ Check out tool A001 +
+
+
+
+ + +
'> + + +

Authentication

+
+
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+ +
+ + + + +