Fix command now fully working with json

This commit is contained in:
osaajani 2020-01-08 16:17:12 +01:00
parent 31d2739ccb
commit 929ea695e1
5 changed files with 18 additions and 16 deletions

View File

@ -83,7 +83,7 @@ namespace controllers\internals;
* @param string $message : Text of the message to analyse * @param string $message : Text of the message to analyse
* @return mixed : false on error, array with new text and command to execute ['updated_text' => string, 'command' => string] * @return mixed : false on error, array with new text and command to execute ['updated_text' => string, 'command' => string]
*/ */
public function check_for_command (int $id_user, string $message) : bool public function check_for_command (int $id_user, string $message)
{ {
$extracted_command = []; $extracted_command = [];
@ -94,14 +94,14 @@ namespace controllers\internals;
} }
if (!isset($decode_message['login'], $decode_message['password'])) if (!isset($decode_message['login'], $decode_message['password'], $decode_message['command']))
{ {
return false; return false;
} }
//Check for user //Check for user
$internal_user = \controllers\internals\User($this->bdd); $internal_user = new \controllers\internals\User($this->bdd);
$user = $internal_user->check_credentials($decode_message['login'], $decode_message['password']); $user = $internal_user->check_credentials($decode_message['login'], $decode_message['password']);
if (!$user || $user['id'] != $id_user) if (!$user || $user['id'] != $id_user)
{ {
@ -109,37 +109,38 @@ namespace controllers\internals;
} }
//Check for admin rights
if ($command['admin'] && !$user['admin'])
{
return false;
}
//Find command //Find command
$commands = $this->gets_for_user($user['id']); $commands = $this->gets_for_user($user['id']);
$find_command = false; $find_command = false;
foreach ($commands as $command) foreach ($commands as $command)
{ {
$command_name = $command['name']; if ($decode_message['command'] === $command['name'])
if (isset($decode_message[$command_name]))
{ {
$find_command = true; $find_command = $command;
break; break;
} }
} }
if (!$find_command) if (false === $find_command)
{ {
return false; return false;
} }
//Check for admin rights
if ($find_command['admin'] && !$user['admin'])
{
return false;
}
//Forge command and return //Forge command and return
$decode_message['password'] = '******'; $decode_message['password'] = '******';
$updated_text = json_encode($decode_message); $updated_text = json_encode($decode_message);
$generated_command = PWD_SCRIPTS . '/' . $command['script']; $generated_command = PWD_SCRIPTS . '/' . $find_command['script'];
$args = $decode_message['args'] ?? ''; $args = $decode_message['args'] ?? '';
$generated_command .= ' ' . escapeshellcmd($args); $generated_command .= ' ' . escapeshellcmd($args);

View File

@ -202,7 +202,7 @@ namespace controllers\internals;
$controller->render($settings['template'], $datas); $controller->render($settings['template'], $datas);
$content = ob_get_clean(); $content = ob_get_clean();
return mail($to, $settings['subject'], $content); return @mail($to, $settings['subject'], $content);
} }
/** /**

View File

@ -146,6 +146,7 @@ class Phone extends AbstractDaemon
$this->logger->info('Receive message : ' . json_encode($sms)); $this->logger->info('Receive message : ' . json_encode($sms));
$command_result = $this->process_for_command($sms); $command_result = $this->process_for_command($sms);
$this->logger->info('after command');
$sms['text'] = $command_result['text']; $sms['text'] = $command_result['text'];
$is_command = $command_result['is_command']; $is_command = $command_result['is_command'];

0
datas/.tokeep Normal file
View File

0
scripts/.tokeep Normal file
View File