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