mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
Refactored action to command
This commit is contained in:
parent
0e55a86404
commit
211127f9d3
@ -58,10 +58,10 @@ Response Logic::parseRequest(const Json::Value &root)
|
|||||||
|
|
||||||
_logger(LogLevel::info, "Incoming request...");
|
_logger(LogLevel::info, "Incoming request...");
|
||||||
Response response;
|
Response response;
|
||||||
string action, user, password, ip, token;
|
string command, user, password, ip, token;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
action = getJsonOrFail<string>(root, "action");
|
command = getJsonOrFail<string>(root, "command");
|
||||||
ip = getJsonOrFail<string>(root, "ip");
|
ip = getJsonOrFail<string>(root, "ip");
|
||||||
user = getJsonOrFail<string>(root, "user");
|
user = getJsonOrFail<string>(root, "user");
|
||||||
password = getJsonOrFail<string>(root, "password");
|
password = getJsonOrFail<string>(root, "password");
|
||||||
@ -75,10 +75,10 @@ Response Logic::parseRequest(const Json::Value &root)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger(" Action: " + action, LogLevel::notice);
|
_logger(" Command: " + command, LogLevel::notice);
|
||||||
_logger(" User : " + user, LogLevel::notice);
|
_logger(" User : " + user, LogLevel::notice);
|
||||||
_logger(" IP : " + ip, LogLevel::notice);
|
_logger(" IP : " + ip, LogLevel::notice);
|
||||||
_logger(" Token : " + token, LogLevel::notice);
|
_logger(" Token : " + token, LogLevel::notice);
|
||||||
|
|
||||||
if (_checkToken(token) == false)
|
if (_checkToken(token) == false)
|
||||||
{
|
{
|
||||||
@ -95,14 +95,14 @@ Response Logic::parseRequest(const Json::Value &root)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "lock")
|
if (command == "lock")
|
||||||
{
|
{
|
||||||
response = _lock();
|
response = _lock();
|
||||||
} else if (action == "unlock") {
|
} else if (command == "unlock") {
|
||||||
response = _unlock();
|
response = _unlock();
|
||||||
} else {
|
} else {
|
||||||
response.code = Response::Code::UnknownAction;
|
response.code = Response::Code::UnknownCommand;
|
||||||
response.message = "Unknown Action: " + action;
|
response.message = "Unknown Command: " + command;
|
||||||
_logger(response.message, LogLevel::error);
|
_logger(response.message, LogLevel::error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ struct Response
|
|||||||
InvalidToken, // Request contains invalid token
|
InvalidToken, // Request contains invalid token
|
||||||
InvalidCredentials, // Invalid LDAP credentials
|
InvalidCredentials, // Invalid LDAP credentials
|
||||||
InvalidIP, // IP check failure
|
InvalidIP, // IP check failure
|
||||||
UnknownAction, // Unknown action
|
UnknownCommand, // Unknown action
|
||||||
LDAPInit, // Ldap initialization failed
|
LDAPInit, // Ldap initialization failed
|
||||||
} code;
|
} code;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
function tellLock( $pAction, $pUser, $pPass, $pToken, $pIp ){
|
function tellLock( $pCommand, $pUser, $pPass, $pToken, $pIp ){
|
||||||
|
|
||||||
$json = '{
|
$json = '{
|
||||||
"user":' . json_encode( $pUser ) . ',
|
"user":' . json_encode( $pUser ) . ',
|
||||||
"password":' . json_encode( $pPass ) . ',
|
"password":' . json_encode( $pPass ) . ',
|
||||||
"action":' . json_encode( $pAction ) . ',
|
"command":' . json_encode( $pCommand ) . ',
|
||||||
"token":' . json_encode( $pToken ) . ',
|
"token":' . json_encode( $pToken ) . ',
|
||||||
"ip":' . json_encode( $pIp ) . '
|
"ip":' . json_encode( $pIp ) . '
|
||||||
}'."\n";
|
}'."\n";
|
||||||
@ -61,7 +61,7 @@
|
|||||||
return "Invalid IP";
|
return "Invalid IP";
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
return "Unknown Action"; // Unknown action
|
return "Unknown Command"; // Unknown command
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
return "LDAP Init error"; // Ldap initialization failed
|
return "LDAP Init error"; // Ldap initialization failed
|
||||||
@ -84,13 +84,13 @@
|
|||||||
if (array_key_exists("user", $_POST)
|
if (array_key_exists("user", $_POST)
|
||||||
&& array_key_exists('pass', $_POST)
|
&& array_key_exists('pass', $_POST)
|
||||||
&& array_key_exists('token', $_POST)
|
&& array_key_exists('token', $_POST)
|
||||||
&& array_key_exists('action', $_POST)
|
&& array_key_exists('command', $_POST)
|
||||||
&& array_key_exists('api', $_POST))
|
&& array_key_exists('api', $_POST))
|
||||||
{
|
{
|
||||||
$pUser = $_POST[ 'user' ];
|
$pUser = $_POST[ 'user' ];
|
||||||
$pPass = $_POST[ 'pass' ];
|
$pPass = $_POST[ 'pass' ];
|
||||||
$pToken = $_POST[ 'token' ];
|
$pToken = $_POST[ 'token' ];
|
||||||
$pAction = $_POST[ 'action' ];
|
$pCommand = $_POST[ 'command' ];
|
||||||
$pApi = $_POST[ 'api' ];
|
$pApi = $_POST[ 'api' ];
|
||||||
|
|
||||||
if ($pApi == "true")
|
if ($pApi == "true")
|
||||||
@ -98,7 +98,7 @@
|
|||||||
$isApi = true;
|
$isApi = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lSuccess = tellLock( $pAction, $pUser, $pPass, $pToken, $pIp );
|
$lSuccess = tellLock($pCommand, $pUser, $pPass, $pToken, $pIp);
|
||||||
|
|
||||||
if ($lSuccess == 0) {
|
if ($lSuccess == 0) {
|
||||||
$showSuccess = true;
|
$showSuccess = true;
|
||||||
@ -178,9 +178,9 @@ if ($isApi == false) {
|
|||||||
<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">
|
<input type="hidden" name="api" value="false">
|
||||||
|
|
||||||
<button name="action" value="unlock">Open</button>
|
<button name="command" value="unlock">Open</button>
|
||||||
<hr/>
|
<hr/>
|
||||||
<button name="action" value="lock">Lock</button>
|
<button name="command" value="lock">Lock</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php elseif( $showSuccess ): ?>
|
<?php elseif( $showSuccess ): ?>
|
||||||
|
Loading…
Reference in New Issue
Block a user