From 74ee1b02b08e6c517d533be74ec6b491cf4e5d00 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 31 Jul 2019 10:06:53 +0200 Subject: httpdocs/index.php: password-protection --- httpdocs/index.php | 76 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/httpdocs/index.php b/httpdocs/index.php index 0513515..f3a8df2 100644 --- a/httpdocs/index.php +++ b/httpdocs/index.php @@ -1,6 +1,6 @@ \n"; -print "\n"; +if (array_key_exists('HTTPS', $_SERVER) +&& ($_SERVER['HTTPS'] == 'on')) + $https = true; +else + $https = false; + +function push_it() { + if (!array_key_exists('password', $_POST)) + return; + $f = fopen('../password', 'r'); + if ($f === false) { + print 'Cannot read password file
' . "\n"; + return; + } + $saved_hash = trim(fgets($f)); + fclose($f); + $entered_hash = hash('sha512', $_POST['password']); + if ($saved_hash != $entered_hash) { + print 'Wrong password: ' . $entered_hash . '
' . "\n"; + return; + } + foreach ($_POST as $key => $dummy) + if (preg_match('/^push_([0-9]+)$/', $key, $duration)) + break; + if (count($duration) != 2) + return; + $duration = $duration[1]; + if (($duration > 0) + && ($duration < 300)) { + print 'pushing for ' . ($duration * 0.1) . ' seconds ...
' . "\n"; + shell_exec('/usr/bin/gpio write 28 1'); + flush(); + usleep(100000 * $duration); + shell_exec('/usr/bin/gpio write 28 0'); + print '... done
' . "\n"; + } +} + +print '' . "\n"; +print '' . "\n"; print 'fileserver lights-out' . "\n"; -if (array_key_exists('push', $_GET)) +if (array_key_exists('password', $_POST)) print '' . "\n"; -print "\n"; -print "\n"; +print '' . "\n"; +print '' . "\n"; print 'Fileserver is currently '; if ($l == '1') print 'off'; else print 'on'; -print "
\n"; -if (array_key_exists('push', $_GET) -&& ($_GET['push'] > 0) -&& ($_GET['push'] < 300)) { - print 'pushing for ' . ($_GET['push'] * 0.1) . ' seconds ...
' . "\n"; - shell_exec('/usr/bin/gpio write 28 1'); - flush(); - usleep(100000 * $_GET['push']); - shell_exec('/usr/bin/gpio write 28 0'); - print '... done
' . "\n"; +print '
' . "\n"; +if ($https) { + push_it(); + print '
' . "\n"; + print 'Passwort:
' . "\n"; + print '
' . "\n"; + print '
' . "\n"; + print '
' . "\n"; } -print 'short power button push'; -print "
\n"; -print 'long power button push'; -print "
\n"; -print "\n"; -print "\n"; +print '' . "\n"; +print '' . "\n"; -- cgit v1.2.3-54-g00ecf