1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00

Removed authentication feature

This commit is contained in:
Ralf Ramsauer 2015-05-18 22:23:41 +02:00
parent 8b2a0ea4ca
commit 07b6eeed2e

View File

@ -1,17 +1,12 @@
<!DOCTYPE html>
<?php <?php
function tellLock( $pAction, $pUser, $pPass, $pToken, $pIp ){ function tellLock( $pAction, $pUser, $pPass, $pToken, $pIp ){
$pAuthenticated = true;
$json = '{ $json = '{
"user":' . json_encode( $pUser ) . ', "user":' . json_encode( $pUser ) . ',
"password":' . json_encode( $pPass ) . ', "password":' . json_encode( $pPass ) . ',
"action":' . json_encode( $pAction ) . ', "action":' . json_encode( $pAction ) . ',
"token":' . json_encode( $pToken ) . ', "token":' . json_encode( $pToken ) . ',
"ip":' . json_encode( $pIp ) . ', "ip":' . json_encode( $pIp ) . '
"authenticate":' . json_encode( $pAuthenticated ) . '
}'."\n"; }'."\n";
$address = "127.0.0.1"; $address = "127.0.0.1";
@ -80,37 +75,57 @@
$showLoginForm = false; $showLoginForm = false;
$showSuccess = false; $showSuccess = false;
$showFailure = false; $showFailure = false;
$isApi = false;
$pIp = $_SERVER[ 'REMOTE_ADDR' ]; $pIp = $_SERVER[ 'REMOTE_ADDR' ];
if( $_SERVER[ 'REQUEST_METHOD' ] == "POST" ) { if( $_SERVER[ 'REQUEST_METHOD' ] == "POST" ) {
$pUser = $_POST[ 'user' ]; if (array_key_exists("user", $_POST)
$pPass = $_POST[ 'pass' ]; && array_key_exists('pass', $_POST)
$pToken = $_POST[ 'token' ]; && array_key_exists('token', $_POST)
$pAction = $_POST[ 'action' ]; && array_key_exists('action', $_POST)
&& array_key_exists('api', $_POST))
{
$pUser = $_POST[ 'user' ];
$pPass = $_POST[ 'pass' ];
$pToken = $_POST[ 'token' ];
$pAction = $_POST[ 'action' ];
$pApi = $_POST[ 'api' ];
$lSuccess = tellLock( $pAction, $pUser, $pPass, $pToken, $pIp ); if ($pApi == "true")
{
$isApi = true;
}
if ($lSuccess == 0) { $lSuccess = tellLock( $pAction, $pUser, $pPass, $pToken, $pIp );
$showSuccess = true;
if ($lSuccess == 0) {
$showSuccess = true;
} else {
$failureMsg = err2str($lSuccess);
$showFailure = true;
}
} else { } else {
http_response_code( 401 ); $failureMsg = 'Invalid Request';
$failureMsg = err2str($lSuccess);
$showFailure = true; $showFailure = true;
} }
} else { } else {
// This is done by apache mod_rewrite // This is done by apache mod_rewrite
$pToken = $_GET[ 'token' ]; $pToken = $_GET[ 'token' ];
$lToken = preg_replace( '/[^0-9a-f]/i', "", $pToken ); $lToken = preg_replace( '/[^0-9a-fA-F]/i', "", $pToken );
if(strlen($lToken) != 16) {
http_response_code( 404 );
$showFailure = true;
}
$showLoginForm = true;
}
?>
if(strlen($lToken) != 16) {
$showFailure = true;
$failureMsg = "Please provide Token";
} else {
$showLoginForm = true;
}
}
if ($isApi == false) {
?>
<!DOCTYPE html>
<html> <html>
<head> <head>
@ -161,6 +176,7 @@
<input id="pass" type="password" name="pass"> <input id="pass" type="password" name="pass">
<input type="hidden" name="token" value="<?php echo $lToken;?>"> <input type="hidden" name="token" value="<?php echo $lToken;?>">
<input type="hidden" name="api" value="false">
<button name="action" value="unlock">Open</button> <button name="action" value="unlock">Open</button>
<hr/> <hr/>
@ -180,3 +196,8 @@
</body> </body>
</html> </html>
<?php
} else {
echo $lSuccess;
}
?>