fix codestyle

This commit is contained in:
osaajani 2020-06-23 21:06:13 +02:00
parent 350dbb5b59
commit adef27f862
37 changed files with 556 additions and 488 deletions

View File

@ -23,7 +23,7 @@ namespace adapters;
/** /**
* Adapter constructor, called when instanciated by RaspiSMS. * Adapter constructor, called when instanciated by RaspiSMS.
* *
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service * @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/ */
public function __construct(string $datas); public function __construct(string $datas);
@ -34,9 +34,9 @@ namespace adapters;
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string; public static function meta_uid(): string;
/** /**
* Name of the adapter. * Name of the adapter.
@ -72,7 +72,6 @@ namespace adapters;
*/ */
public static function meta_support_reception(): bool; public static function meta_support_reception(): bool;
/** /**
* Does the implemented service support status change callback. * Does the implemented service support status change callback.
*/ */
@ -86,10 +85,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success * ?string 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false); public function send(string $destination, string $text, bool $flash = false);
@ -97,18 +96,18 @@ namespace adapters;
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'smss' => Array of the sms reads * array 'smss' => Array of the sms reads
* [ * [
* [ * [
* string 'at' => sms reception date, * string 'at' => sms reception date,
* string 'text' => sms text, * string 'text' => sms text,
* string 'origin' => phone number who sent the sms * string 'origin' => phone number who sent the sms
* ], * ],
* ... * ...
* ] * ]
* ] * ]
*/ */
public function read(): array; public function read(): array;
@ -131,15 +130,15 @@ namespace adapters;
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array; public static function reception_callback(): array;
} }

View File

@ -28,7 +28,7 @@ namespace adapters;
/** /**
* Adapter constructor, called when instanciated by RaspiSMS. * Adapter constructor, called when instanciated by RaspiSMS.
* *
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service * @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/ */
public function __construct(string $datas) public function __construct(string $datas)
{ {
@ -45,9 +45,9 @@ namespace adapters;
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'gammu_adapter'; return 'gammu_adapter';
} }
@ -125,7 +125,6 @@ namespace adapters;
return false; return false;
} }
/** /**
* Method called to send a SMS to a number. * Method called to send a SMS to a number.
* *
@ -134,10 +133,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success, null on error * ?string 'uid' => Uid of the sms created on success, null on error
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -151,6 +150,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot unlock SIM.'; $response['error_message'] = 'Cannot unlock SIM.';
return $response; return $response;
} }
@ -179,6 +179,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Gammu command failed.'; $response['error_message'] = 'Gammu command failed.';
return $response; return $response;
} }
@ -187,6 +188,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot find output OK.'; $response['error_message'] = 'Cannot find output OK.';
return $response; return $response;
} }
@ -208,10 +210,12 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot retrieve sms uid.'; $response['error_message'] = 'Cannot retrieve sms uid.';
return $response; return $response;
} }
$response['uid'] = $uid; $response['uid'] = $uid;
return $response; return $response;
} }
@ -219,10 +223,10 @@ namespace adapters;
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -236,6 +240,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot unlock sim.'; $response['error_message'] = 'Cannot unlock sim.';
return $response; return $response;
} }
@ -249,6 +254,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Gammu command return failed.'; $response['error_message'] = 'Gammu command return failed.';
return $response; return $response;
} }
@ -292,6 +298,25 @@ namespace adapters;
return false; return false;
} }
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback(): array
{
return [];
}
/** /**
* Function to unlock pin. * Function to unlock pin.
* *
@ -376,24 +401,4 @@ namespace adapters;
return (bool) $find; return (bool) $find;
} }
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
{
return [];
}
} }

View File

@ -12,7 +12,7 @@
namespace adapters; namespace adapters;
/** /**
* Octopush SMS service with a shortcode adapter * Octopush SMS service with a shortcode adapter.
*/ */
class OctopushShortcodeAdapter implements AdapterInterface class OctopushShortcodeAdapter implements AdapterInterface
{ {
@ -27,22 +27,22 @@ class OctopushShortcodeAdapter implements AdapterInterface
private $datas; private $datas;
/** /**
* Octopush login * Octopush login.
*/ */
private $login; private $login;
/** /**
* Octopush api key * Octopush api key.
*/ */
private $api_key; private $api_key;
/** /**
* Sender name to use instead of shortcode * Sender name to use instead of shortcode.
*/ */
private $sender; private $sender;
/** /**
* Octopush api baseurl * Octopush api baseurl.
*/ */
private $api_url = 'https://www.octopush-dm.com/api'; private $api_url = 'https://www.octopush-dm.com/api';
@ -69,12 +69,11 @@ class OctopushShortcodeAdapter implements AdapterInterface
return __CLASS__; return __CLASS__;
} }
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'octopush_shortcode_adapter'; return 'octopush_shortcode_adapter';
} }
@ -95,6 +94,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
public static function meta_description(): string public static function meta_description(): string
{ {
$credentials_url = 'https://www.octopush-dm.com/api-logins'; $credentials_url = 'https://www.octopush-dm.com/api-logins';
return ' return '
Envoi de SMS avec un shortcode en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a> Envoi de SMS avec un shortcode en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a>
'; ';
@ -128,7 +128,6 @@ class OctopushShortcodeAdapter implements AdapterInterface
<b>Si vous utilisez un expéditeur nommé, le destinataire ne pourra pas répondre.</b>', <b>Si vous utilisez un expéditeur nommé, le destinataire ne pourra pas répondre.</b>',
'required' => false, 'required' => false,
], ],
]; ];
} }
@ -172,10 +171,10 @@ class OctopushShortcodeAdapter implements AdapterInterface
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success * array 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -196,7 +195,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
'sms_type' => self::SMS_TYPE_LOWCOST, 'sms_type' => self::SMS_TYPE_LOWCOST,
]; ];
if ($this->sender !== null) if (null !== $this->sender)
{ {
$datas['sms_sender'] = $this->sender; $datas['sms_sender'] = $this->sender;
} }
@ -212,25 +211,28 @@ class OctopushShortcodeAdapter implements AdapterInterface
$response = curl_exec($curl); $response = curl_exec($curl);
curl_close($curl); curl_close($curl);
if ($response === false) if (false === $response)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'HTTP query failed.'; $response['error_message'] = 'HTTP query failed.';
return $response; return $response;
} }
$response_decode = json_decode($response, true); $response_decode = json_decode($response, true);
if ($response_decode === null) if (null === $response_decode)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Invalid JSON for response.'; $response['error_message'] = 'Invalid JSON for response.';
return $response; return $response;
} }
if ($response_decode['error_code'] != self::ERROR_CODE_OK) if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code']; $response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
return $response; return $response;
} }
@ -239,16 +241,19 @@ class OctopushShortcodeAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot extract SMS uid'; $response['error_message'] = 'Cannot extract SMS uid';
return $response; return $response;
} }
$response['uid'] = $uid; $response['uid'] = $uid;
return $response; return $response;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -257,10 +262,10 @@ class OctopushShortcodeAdapter implements AdapterInterface
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -300,18 +305,18 @@ class OctopushShortcodeAdapter implements AdapterInterface
$response = curl_exec($curl); $response = curl_exec($curl);
curl_close($curl); curl_close($curl);
if ($response === false) if (false === $response)
{ {
return false; return false;
} }
$response_decode = json_decode($response, true); $response_decode = json_decode($response, true);
if ($response_decode === null) if (null === $response_decode)
{ {
return false; return false;
} }
if ($response_decode['error_code'] != self::ERROR_CODE_OK) if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{ {
return false; return false;
} }
@ -338,7 +343,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
$uid = $_POST['message_id'] ?? false; $uid = $_POST['message_id'] ?? false;
$status = $_POST['status'] ?? false; $status = $_POST['status'] ?? false;
if ($uid === false || $status === false) if (false === $uid || false === $status)
{ {
return false; return false;
} }
@ -347,40 +352,40 @@ class OctopushShortcodeAdapter implements AdapterInterface
{ {
case 'DELIVERED': case 'DELIVERED':
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break;
break;
case 'NOT_ALLOWED': case 'NOT_ALLOWED':
case 'INVALID_DESTINATION_ADDRESS': case 'INVALID_DESTINATION_ADDRESS':
case 'OUT_OF_DATE': case 'OUT_OF_DATE':
case 'EXPIRED': case 'EXPIRED':
case 'BLACKLISTED_NUMBER': case 'BLACKLISTED_NUMBER':
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break;
default : break;
default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;
break; break;
} }
return ['uid' => $uid, 'status' => $status]; return ['uid' => $uid, 'status' => $status];
} }
/** /**
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array public static function reception_callback(): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,
@ -400,6 +405,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'One required data of the callback is missing.'; $response['error_message'] = 'One required data of the callback is missing.';
return $response; return $response;
} }
@ -408,6 +414,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2); $response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
return $response; return $response;
} }
@ -416,6 +423,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
'text' => $text, 'text' => $text,
'origin' => $origin, 'origin' => $origin,
]; ];
return $response; return $response;
} }
} }

View File

@ -12,7 +12,7 @@
namespace adapters; namespace adapters;
/** /**
* Octopush SMS service with a shortcode adapter * Octopush SMS service with a shortcode adapter.
*/ */
class OctopushVirtualNumberAdapter implements AdapterInterface class OctopushVirtualNumberAdapter implements AdapterInterface
{ {
@ -27,27 +27,27 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
private $datas; private $datas;
/** /**
* Octopush login * Octopush login.
*/ */
private $login; private $login;
/** /**
* Octopush api key * Octopush api key.
*/ */
private $api_key; private $api_key;
/** /**
* Number phone to use * Number phone to use.
*/ */
private $number; private $number;
/** /**
* Number phone to use formated for octopush compatibility * Number phone to use formated for octopush compatibility.
*/ */
private $formatted_number; private $formatted_number;
/** /**
* Octopush api baseurl * Octopush api baseurl.
*/ */
private $api_url = 'https://www.octopush-dm.com/api'; private $api_url = 'https://www.octopush-dm.com/api';
@ -75,12 +75,11 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
return __CLASS__; return __CLASS__;
} }
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'octopush_virtual_number_adapter'; return 'octopush_virtual_number_adapter';
} }
@ -101,6 +100,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
public static function meta_description(): string public static function meta_description(): string
{ {
$credentials_url = 'https://www.octopush-dm.com/api-logins'; $credentials_url = 'https://www.octopush-dm.com/api-logins';
return ' return '
Envoi de SMS avec un numéro virtuel en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a> Envoi de SMS avec un numéro virtuel en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a>
'; ';
@ -133,7 +133,6 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
'required' => true, 'required' => true,
'number' => true, 'number' => true,
], ],
]; ];
} }
@ -177,10 +176,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success * array 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -212,25 +211,28 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$response = curl_exec($curl); $response = curl_exec($curl);
curl_close($curl); curl_close($curl);
if ($response === false) if (false === $response)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'HTTP query failed.'; $response['error_message'] = 'HTTP query failed.';
return $response; return $response;
} }
$response_decode = json_decode($response, true); $response_decode = json_decode($response, true);
if ($response_decode === null) if (null === $response_decode)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Invalid JSON for response.'; $response['error_message'] = 'Invalid JSON for response.';
return $response; return $response;
} }
if ($response_decode['error_code'] != self::ERROR_CODE_OK) if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code']; $response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
return $response; return $response;
} }
@ -239,16 +241,19 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot extract SMS uid'; $response['error_message'] = 'Cannot extract SMS uid';
return $response; return $response;
} }
$response['uid'] = $uid; $response['uid'] = $uid;
return $response; return $response;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -257,10 +262,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -300,18 +305,18 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$response = curl_exec($curl); $response = curl_exec($curl);
curl_close($curl); curl_close($curl);
if ($response === false) if (false === $response)
{ {
return false; return false;
} }
$response_decode = json_decode($response, true); $response_decode = json_decode($response, true);
if ($response_decode === null) if (null === $response_decode)
{ {
return false; return false;
} }
if ($response_decode['error_code'] != self::ERROR_CODE_OK) if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{ {
return false; return false;
} }
@ -338,7 +343,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$uid = $_POST['message_id'] ?? false; $uid = $_POST['message_id'] ?? false;
$status = $_POST['status'] ?? false; $status = $_POST['status'] ?? false;
if ($uid === false || $status === false) if (false === $uid || false === $status)
{ {
return false; return false;
} }
@ -347,40 +352,40 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{ {
case 'DELIVERED': case 'DELIVERED':
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break;
break;
case 'NOT_ALLOWED': case 'NOT_ALLOWED':
case 'INVALID_DESTINATION_ADDRESS': case 'INVALID_DESTINATION_ADDRESS':
case 'OUT_OF_DATE': case 'OUT_OF_DATE':
case 'EXPIRED': case 'EXPIRED':
case 'BLACKLISTED_NUMBER': case 'BLACKLISTED_NUMBER':
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break;
default : break;
default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;
break; break;
} }
return ['uid' => $uid, 'status' => $status]; return ['uid' => $uid, 'status' => $status];
} }
/** /**
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array public static function reception_callback(): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,
@ -400,6 +405,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'One required data of the callback is missing.'; $response['error_message'] = 'One required data of the callback is missing.';
return $response; return $response;
} }
@ -408,6 +414,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2); $response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
return $response; return $response;
} }
@ -416,6 +423,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
'text' => $text, 'text' => $text,
'origin' => $origin, 'origin' => $origin,
]; ];
return $response; return $response;
} }
} }

View File

@ -14,7 +14,7 @@ namespace adapters;
use Ovh\Api; use Ovh\Api;
/** /**
* OVH SMS service with a shortcode allowing responses * OVH SMS service with a shortcode allowing responses.
*/ */
class OvhSmsShortcodeAdapter implements AdapterInterface class OvhSmsShortcodeAdapter implements AdapterInterface
{ {
@ -56,9 +56,9 @@ namespace adapters;
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'ovh_sms_shortcode_adapter'; return 'ovh_sms_shortcode_adapter';
} }
@ -160,7 +160,6 @@ namespace adapters;
return false; return false;
} }
/** /**
* Method called to send a SMS to a number. * Method called to send a SMS to a number.
* *
@ -169,10 +168,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success * ?string 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -206,6 +205,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Invalid receiver'; $response['error_message'] = 'Invalid receiver';
return $response; return $response;
} }
@ -214,16 +214,19 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot retrieve uid.'; $response['error_message'] = 'Cannot retrieve uid.';
return $response; return $response;
} }
$response['uid'] = $uid; $response['uid'] = $uid;
return $response; return $response;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -232,10 +235,10 @@ namespace adapters;
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -288,6 +291,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -312,9 +316,8 @@ namespace adapters;
//Check service name //Check service name
$endpoint = '/sms/' . $this->datas['service_name']; $endpoint = '/sms/' . $this->datas['service_name'];
$response = $this->api->get($endpoint); $response = $this->api->get($endpoint);
$success = $success && (bool) $response;
return $success; return $success && (bool) $response;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
@ -357,22 +360,21 @@ namespace adapters;
return ['uid' => $uid, 'status' => $status]; return ['uid' => $uid, 'status' => $status];
} }
/** /**
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array public static function reception_callback(): array
{ {
return []; return [];
} }

View File

@ -14,7 +14,7 @@ namespace adapters;
use Ovh\Api; use Ovh\Api;
/** /**
* OVH SMS service with a virtual number adapter * OVH SMS service with a virtual number adapter.
*/ */
class OvhSmsVirtualNumberAdapter implements AdapterInterface class OvhSmsVirtualNumberAdapter implements AdapterInterface
{ {
@ -29,7 +29,7 @@ namespace adapters;
private $api; private $api;
/** /**
* Number used * Number used.
*/ */
private $number; private $number;
@ -41,7 +41,7 @@ namespace adapters;
/** /**
* Adapter constructor, called when instanciated by RaspiSMS. * Adapter constructor, called when instanciated by RaspiSMS.
* *
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service * @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/ */
public function __construct(string $datas) public function __construct(string $datas)
{ {
@ -66,12 +66,11 @@ namespace adapters;
return __CLASS__; return __CLASS__;
} }
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'ovh_sms_virtual_number_adapter'; return 'ovh_sms_virtual_number_adapter';
} }
@ -180,10 +179,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success * array 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -210,6 +209,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Invalid receiver'; $response['error_message'] = 'Invalid receiver';
return $response; return $response;
} }
@ -218,16 +218,19 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot retrieve uid'; $response['error_message'] = 'Cannot retrieve uid';
return $response; return $response;
} }
$response['uid'] = $uid; $response['uid'] = $uid;
return $response; return $response;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -236,10 +239,10 @@ namespace adapters;
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -254,7 +257,7 @@ namespace adapters;
$endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/incoming'; $endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/incoming';
$uids = $this->api->get($endpoint); $uids = $this->api->get($endpoint);
if (!is_array($uids) || !$uids) if (!\is_array($uids) || !$uids)
{ {
return $response; return $response;
} }
@ -286,6 +289,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -359,17 +363,17 @@ namespace adapters;
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array public static function reception_callback(): array
{ {
return []; return [];
} }

View File

@ -38,7 +38,7 @@ namespace adapters;
/** /**
* Adapter constructor, called when instanciated by RaspiSMS. * Adapter constructor, called when instanciated by RaspiSMS.
* *
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service * @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/ */
public function __construct(string $datas) public function __construct(string $datas)
{ {
@ -55,9 +55,9 @@ namespace adapters;
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'test_adapter'; return 'test_adapter';
} }
@ -90,7 +90,6 @@ namespace adapters;
return []; return [];
} }
/** /**
* Does the implemented service support reading smss. * Does the implemented service support reading smss.
*/ */
@ -131,10 +130,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success * array 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -148,15 +147,16 @@ namespace adapters;
$at = (new \DateTime())->format('Y-m-d H:i:s'); $at = (new \DateTime())->format('Y-m-d H:i:s');
$success = file_put_contents($this->test_file_write, json_encode(['uid' => $uid, 'at' => $at, 'destination' => $destination, 'text' => $text, 'flash' => $flash]) . "\n", FILE_APPEND); $success = file_put_contents($this->test_file_write, json_encode(['uid' => $uid, 'at' => $at, 'destination' => $destination, 'text' => $text, 'flash' => $flash]) . "\n", FILE_APPEND);
if ($success === false) if (false === $success)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot write in file : ' . $this->test_file_write; $response['error_message'] = 'Cannot write in file : ' . $this->test_file_write;
return $response; return $response;
} }
$response['uid'] = $uid; $response['uid'] = $uid;
return $response; return $response;
} }
@ -164,10 +164,10 @@ namespace adapters;
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -180,19 +180,21 @@ namespace adapters;
try try
{ {
$file_contents = file_get_contents($this->test_file_read); $file_contents = file_get_contents($this->test_file_read);
if ($file_contents === false) if (false === $file_contents)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot read file : ' . $this->test_file_read; $response['error_message'] = 'Cannot read file : ' . $this->test_file_read;
return $response; return $response;
} }
//Empty file to avoid dual read //Empty file to avoid dual read
$success = file_put_contents($this->test_file_read, ''); $success = file_put_contents($this->test_file_read, '');
if ($success === false) if (false === $success)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = 'Cannot write in file : ' . $this->test_file_read; $response['error_message'] = 'Cannot write in file : ' . $this->test_file_read;
return $response; return $response;
} }
@ -215,6 +217,7 @@ namespace adapters;
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -232,7 +235,6 @@ namespace adapters;
/** /**
* Method called on reception of a status update notification for a SMS. * Method called on reception of a status update notification for a SMS.
*
*/ */
public static function status_change_callback() public static function status_change_callback()
{ {
@ -268,22 +270,21 @@ namespace adapters;
return $return; return $return;
} }
/** /**
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array public static function reception_callback(): array
{ {
return []; return [];
} }

View File

@ -14,7 +14,7 @@ namespace adapters;
use Twilio\Rest\Client; use Twilio\Rest\Client;
/** /**
* Twilio SMS service with a virtual number adapter * Twilio SMS service with a virtual number adapter.
*/ */
class TwilioVirtualNumberAdapter implements AdapterInterface class TwilioVirtualNumberAdapter implements AdapterInterface
{ {
@ -24,17 +24,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
private $datas; private $datas;
/** /**
* Twilio Api client * Twilio Api client.
*/ */
private $client; private $client;
/** /**
* Twilio virtual number to use * Twilio virtual number to use.
*/ */
private $number; private $number;
/** /**
* Callback address Twilio must call on SMS status change * Callback address Twilio must call on SMS status change.
*/ */
private $status_change_callback; private $status_change_callback;
@ -65,12 +65,11 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
return __CLASS__; return __CLASS__;
} }
/** /**
* Uniq name of the adapter * Uniq name of the adapter
* It should be the classname of the adapter un snakecase * It should be the classname of the adapter un snakecase.
*/ */
public static function meta_uid() : string public static function meta_uid(): string
{ {
return 'twilio_virtual_number_adapter'; return 'twilio_virtual_number_adapter';
} }
@ -174,10 +173,10 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
* @param bool $flash : Is the SMS a Flash SMS * @param bool $flash : Is the SMS a Flash SMS
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success * array 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false) public function send(string $destination, string $text, bool $flash = false)
{ {
@ -198,20 +197,23 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
] ]
); );
if ($message->errorCode !== null) if (null !== $message->errorCode)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $message->errorMessage; $response['error_message'] = $message->errorMessage;
return $response; return $response;
} }
$response['uid'] = $message->sid; $response['uid'] = $message->sid;
return $response; return $response;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -220,10 +222,10 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads * array 'sms' => Array of the sms reads
* ] * ]
*/ */
public function read(): array public function read(): array
{ {
@ -241,7 +243,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
foreach ($messages as $record) foreach ($messages as $record)
{ {
if ($record->direction != 'inbound') if ('inbound' !== $record->direction)
{ {
continue; continue;
} }
@ -265,6 +267,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
{ {
$response['error'] = true; $response['error'] = true;
$response['error_message'] = $t->getMessage(); $response['error_message'] = $t->getMessage();
return $response; return $response;
} }
} }
@ -284,7 +287,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
foreach ($phone_numbers as $record) foreach ($phone_numbers as $record)
{ {
//If not the same number, return false //If not the same number, return false
if ($record->phoneNumber != $this->number) if ($record->phoneNumber !== $this->number)
{ {
continue; continue;
} }
@ -317,16 +320,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
switch ($status) switch ($status)
{ {
case 'delivered' : case 'delivered':
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break;
case 'failed' : break;
case 'failed':
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break;
default : break;
default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;
break; break;
} }
@ -337,17 +341,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* ] * ]
* *
* ] * ]
*/ */
public static function reception_callback() : array public static function reception_callback(): array
{ {
return []; return [];
} }

View File

@ -69,14 +69,14 @@ namespace controllers\internals;
} }
/** /**
* Analyse a message to check if it's a command so execute it * Analyse a message to check if it's a command so execute it.
* *
* @param int $id_user : User id to search a command for * @param int $id_user : User id to search a command for
* @param string $message : Message to analyse * @param string $message : Message to analyse
* *
* @return mixed bool|string : false if not a valid command, anonymized message if valid command * @return mixed bool|string : false if not a valid command, anonymized message if valid command
*/ */
public function analyze_and_process (int $id_user, string $message) public function analyze_and_process(int $id_user, string $message)
{ {
if (!ENABLE_COMMAND) if (!ENABLE_COMMAND)
{ {

View File

@ -98,13 +98,12 @@ namespace controllers\internals;
} }
/** /**
* Update a user status.
* *
* Update a user status * @param string $email : User email
*
* @param string $email : User email
* @param string $status : User status, default \models\User::STATUS_ACTIVE * @param string $status : User status, default \models\User::STATUS_ACTIVE
*/ */
public function update_user_status (string $email, string $status) public function update_user_status(string $email, string $status)
{ {
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8'); $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
$internal_user = new \controllers\internals\User($bdd); $internal_user = new \controllers\internals\User($bdd);

View File

@ -148,7 +148,7 @@ namespace controllers\internals;
$i = 0; $i = 0;
foreach ($line as $key => $value) foreach ($line as $key => $value)
{ {
$i++; ++$i;
if ($i < 3) if ($i < 3)
{ {
continue; continue;

View File

@ -20,20 +20,23 @@ class ExpressionProvider implements ExpressionFunctionProviderInterface
{ {
//Override default constant() function to make it return null //Override default constant() function to make it return null
//This will prevent the use of constant() func to read constants with security impact (such as session, db credentials, etc.) //This will prevent the use of constant() func to read constants with security impact (such as session, db credentials, etc.)
$neutralized_constant = new ExpressionFunction('constant', function ($str) { $neutralized_constant = new ExpressionFunction('constant', function ($str)
{
return null; return null;
}, function ($arguments, $str) { }, function ($arguments, $str)
{
return null; return null;
}); });
//Exists must be personnalized because it inverse is_null //Exists must be personnalized because it inverse is_null
$exists = new ExpressionFunction('exists', function ($var) { $exists = new ExpressionFunction('exists', function ($var)
{
return sprintf('!is_null(%1$s)', $str); return sprintf('!is_null(%1$s)', $str);
}, function ($arguments, $var) { }, function ($arguments, $var)
return !is_null($var); {
return null !== $var;
}); });
return [ return [
$neutralized_constant, $neutralized_constant,
$exists, $exists,

View File

@ -27,9 +27,9 @@ namespace controllers\internals;
} }
/** /**
* Return unknown error page * Return unknown error page.
*/ */
public function unknown () public function unknown()
{ {
http_response_code(500); http_response_code(500);
$this->render('error/unknown'); $this->render('error/unknown');

View File

@ -1,35 +1,43 @@
<?php <?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace controllers\internals; namespace controllers\internals;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
use Monolog\Logger; use Monolog\Logger;
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
/** /**
* Mailing class * Mailing class.
*/ */
class Mailer extends \descartes\Controller class Mailer extends \descartes\Controller
{ {
private $log; private $log;
private $mail; private $mail;
public function __construct () public function __construct()
{ {
$this->log = new Logger('Mailer'); $this->log = new Logger('Mailer');
$this->log->pushHandler(new StreamHandler(PWD_LOGS . '/mail.log', Logger::DEBUG)); $this->log->pushHandler(new StreamHandler(PWD_LOGS . '/mail.log', Logger::DEBUG));
$this->mail = new PHPMailer(true); $this->mail = new PHPMailer(true);
$this->mail->CharSet = 'utf-8'; $this->mail->CharSet = 'utf-8';
$this->mail->SMTPDebug = SMTP::DEBUG_OFF; $this->mail->SMTPDebug = SMTP::DEBUG_OFF;
$this->mail->isSMTP(); $this->mail->isSMTP();
$this->mail->Host = MAIL['SMTP']['HOST']; $this->mail->Host = MAIL['SMTP']['HOST'];
$this->mail->SMTPAuth = true; $this->mail->SMTPAuth = true;
$this->mail->Username = MAIL['SMTP']['USER']; $this->mail->Username = MAIL['SMTP']['USER'];
$this->mail->Password = MAIL['SMTP']['PASS']; $this->mail->Password = MAIL['SMTP']['PASS'];
$this->mail->Port = MAIL['SMTP']['PORT']; $this->mail->Port = MAIL['SMTP']['PORT'];
$this->mail->setFrom(MAIL['FROM']); $this->mail->setFrom(MAIL['FROM']);
if (MAIL['SMTP']['TLS']) if (MAIL['SMTP']['TLS'])
@ -39,15 +47,17 @@ class Mailer extends \descartes\Controller
} }
/** /**
* Send email * Send email.
* @param array $destinations : Destinations address *
* @param string $subject : Message subject * @param array $destinations : Destinations address
* @param string $message : Message * @param string $subject : Message subject
* @param ?string $alt_message : Alt Message if no html support. Null if message is not html. * @param string $message : Message
* @param array $attachments : List of path to attachment files * @param ?string $alt_message : Alt Message if no html support. Null if message is not html.
* @param array $attachments : List of path to attachment files
*
* @return bool : false on error, true else * @return bool : false on error, true else
*/ */
public function send (array $destinations, string $subject, string $message, ?string $alt_message = null, array $attachments = []) public function send(array $destinations, string $subject, string $message, ?string $alt_message = null, array $attachments = [])
{ {
try try
{ {
@ -74,32 +84,61 @@ class Mailer extends \descartes\Controller
} }
$mail->send(); $mail->send();
return true; return true;
} }
catch (\Throwable $t) catch (\Throwable $t)
{ {
$this->log->error('Error sending mail : ' . $t); $this->log->error('Error sending mail : ' . $t);
return false; return false;
} }
} }
/** /**
* Generate an email body * Enqueue an email for later sending.
* @param array $settings : [
* string 'type' => Internal RaspiSMS email type,
* string 'subject' => Email subject,
* string 'template' => Email template to use
* ?string 'alt_template' => Template to use for alt message, if null ignore
* ]
* *
* @param string $destination : email address to send email to
* @param array $settings : Email settings
* @param array $datas : Datas to inject into email template
*
* @return bool : true on success, false on error
*/
public function enqueue(string $destination, array $settings, array $datas): bool
{
$response = $this->generate_body($settings, $datas);
$message = [
'destinations' => [$destination],
'subject' => $settings['subject'],
'body' => $response['body'],
'alt_body' => $response['alt_body'],
];
$error_code = null;
$queue = msg_get_queue(QUEUE_ID_EMAIL);
$success = msg_send($queue, QUEUE_TYPE_EMAIL, $message, true, true, $error_code);
return (bool) $success;
}
/**
* Generate an email body.
*
* @param array $settings : [
* string 'type' => Internal RaspiSMS email type,
* string 'subject' => Email subject,
* string 'template' => Email template to use
* ?string 'alt_template' => Template to use for alt message, if null ignore
* ]
* @param array : Datas to inject into email template * @param array : Datas to inject into email template
* *
* @return array [ * @return array [
* string 'body' => email body * string 'body' => email body
* ?string 'alt_body' => email alternative body if needed * ?string 'alt_body' => email alternative body if needed
* ] * ]
*/ */
private function generate_body(array $settings, array $datas) : array private function generate_body(array $settings, array $datas): array
{ {
//Generate body of email //Generate body of email
ob_start(); ob_start();
@ -116,32 +155,8 @@ class Mailer extends \descartes\Controller
} }
return [ return [
'body' => $body, 'body' => $body,
'alt_body' => $alt_body, 'alt_body' => $alt_body,
]; ];
} }
/**
* Enqueue an email for later sending
* @param string $destination : email address to send email to
* @param array $settings : Email settings
* @param array $datas : Datas to inject into email template
* @return bool : true on success, false on error
*/
public function enqueue (string $destination, array $settings, array $datas) : bool
{
$response = $this->generate_body($settings, $datas);
$message = [
'destinations' => [$destination],
'subject' => $settings['subject'],
'body' => $response['body'],
'alt_body' => $response['alt_body'],
];
$error_code = null;
$queue = msg_get_queue(QUEUE_ID_EMAIL);
$success = msg_send($queue, QUEUE_TYPE_EMAIL, $message, true, true, $error_code);
return (bool) $success;
}
} }

View File

@ -28,7 +28,7 @@ namespace controllers\internals;
} }
/** /**
* Return a phone by his name * Return a phone by his name.
* *
* @param string $name : Phone name * @param string $name : Phone name
* *
@ -40,10 +40,10 @@ namespace controllers\internals;
} }
/** /**
* Return a phone for a user by a name * Return a phone for a user by a name.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param string $name : Phone name * @param string $name : Phone name
* *
* @return array * @return array
*/ */
@ -56,7 +56,7 @@ namespace controllers\internals;
* Create a phone. * Create a phone.
* *
* @param int $id_user : User to insert phone for * @param int $id_user : User to insert phone for
* @param string $name : The name of the phone * @param string $name : The name of the phone
* @param string $adapter : The adapter to use the phone * @param string $adapter : The adapter to use the phone
* @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api) * @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
* *
@ -79,7 +79,7 @@ namespace controllers\internals;
* *
* @param int $id_user : User to insert phone for * @param int $id_user : User to insert phone for
* @param int $id : Phone id * @param int $id : Phone id
* @param string $name : The name of the phone * @param string $name : The name of the phone
* @param string $adapter : The adapter to use the phone * @param string $adapter : The adapter to use the phone
* @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api) * @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api)
* *

View File

@ -36,9 +36,9 @@ namespace controllers\internals;
* @param int $id_phone : Id of the number the message was send with * @param int $id_phone : Id of the number the message was send with
* @param $at : Reception date * @param $at : Reception date
* @param $text : Text of the message * @param $text : Text of the message
* @param string $origin : Number of the sender * @param string $origin : Number of the sender
* @param string $status : Status of the received message * @param string $status : Status of the received message
* @param bool $command : Is the sms a command * @param bool $command : Is the sms a command
* *
* @return mixed : false on error, new received id else * @return mixed : false on error, new received id else
*/ */
@ -203,31 +203,21 @@ namespace controllers\internals;
} }
/** /**
* Get the model for the Controller. * Receive a SMS message.
* *
* @return \descartes\Model * @param int $id_user : Id of user to create sended message for
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Received($this->bdd);
return $this->model;
}
/**
* Receive a SMS message
* @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the phone the message was sent to * @param int $id_phone : Id of the phone the message was sent to
* @param $text : Text of the message * @param $text : Text of the message
* @param string $origin : Number of the sender * @param string $origin : Number of the sender
* @param ?string $at : Message reception date, if null use current date * @param ?string $at : Message reception date, if null use current date
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD * @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
*
* @return array : [ * @return array : [
* bool 'error' => false if success, true else * bool 'error' => false if success, true else
* ?string 'error_message' => null if success, error message else * ?string 'error_message' => null if success, error message else
* ] * ]
*/ */
public function receive (int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD) : array public function receive(int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD): array
{ {
$return = [ $return = [
'error' => false, 'error' => false,
@ -240,8 +230,8 @@ namespace controllers\internals;
//Process the message to check plus potentially execute command and anonymize text //Process the message to check plus potentially execute command and anonymize text
$internal_command = new Command($this->bdd); $internal_command = new Command($this->bdd);
$response = $internal_command->analyze_and_process($id_user, $text); $response = $internal_command->analyze_and_process($id_user, $text);
if ($response !== false) //Received sms is a command an we must use anonymized text if (false !== $response)
{ { //Received sms is a command an we must use anonymized text
$is_command = true; $is_command = true;
$text = $response; $text = $response;
} }
@ -251,6 +241,7 @@ namespace controllers\internals;
{ {
$return['error'] = true; $return['error'] = true;
$return['error_message'] = 'Impossible to insert the sms in database.'; $return['error_message'] = 'Impossible to insert the sms in database.';
return $return; return $return;
} }
@ -267,6 +258,19 @@ namespace controllers\internals;
$internal_user = new User($this->bdd); $internal_user = new User($this->bdd);
$internal_user->transfer_received($id_user, $received); $internal_user->transfer_received($id_user, $received);
return $return; return $return;
} }
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Received($this->bdd);
return $this->model;
}
} }

View File

@ -18,7 +18,7 @@ namespace controllers\internals;
/** /**
* Create a sended. * Create a sended.
* *
* @param int $id_user : Id of user to create sended message for * @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the number the message was send with * @param int $id_phone : Id of the number the message was send with
* @param $at : Reception date * @param $at : Reception date
* @param $text : Text of the message * @param $text : Text of the message
@ -111,7 +111,7 @@ namespace controllers\internals;
/** /**
* Return sended for an uid and an adapter. * Return sended for an uid and an adapter.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param string $uid : Uid of the sended * @param string $uid : Uid of the sended
* @param string $adapter : Adapter used to send the message * @param string $adapter : Adapter used to send the message
* *
@ -157,32 +157,22 @@ namespace controllers\internals;
} }
/** /**
* Get the model for the Controller. * Send a SMS message.
* *
* @return \descartes\Model * @param \adapters\AdapterInterface $adapter : Adapter object to use to send the message
*/ * @param int $id_user : Id of user to create sended message for
protected function get_model(): \descartes\Model * @param int $id_phone : Id of the phone the message was send with
{
$this->model = $this->model ?? new \models\Sended($this->bdd);
return $this->model;
}
/**
* Send a SMS message
* @param \adapters\AdapterInterface $adapter : Adapter object to use to send the message
* @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the phone the message was send with
* @param $text : Text of the message * @param $text : Text of the message
* @param string $destination : Number of the receiver * @param string $destination : Number of the receiver
* @param bool $flash : Is the sms a flash. By default false. * @param bool $flash : Is the sms a flash. By default false.
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN * @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
*
* @return array : [ * @return array : [
* bool 'error' => false if success, true else * bool 'error' => false if success, true else
* ?string 'error_message' => null if success, error message else * ?string 'error_message' => null if success, error message else
* ] * ]
*/ */
public function send (\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, string $status = \models\Sended::STATUS_UNKNOWN) : array public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, string $status = \models\Sended::STATUS_UNKNOWN): array
{ {
$return = [ $return = [
'error' => false, 'error' => false,
@ -198,6 +188,7 @@ namespace controllers\internals;
$return['error_message'] = $response['error_message']; $return['error_message'] = $response['error_message'];
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
$this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $status); $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $status);
return $return; return $return;
} }
@ -213,7 +204,19 @@ namespace controllers\internals;
$internal_webhook = new Webhook($this->bdd); $internal_webhook = new Webhook($this->bdd);
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND, $sended); $internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND, $sended);
return $return; return $return;
} }
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Sended($this->bdd);
return $this->model;
}
} }

View File

@ -17,7 +17,7 @@ namespace controllers\internals;
public function __construct(?\PDO $bdd = null) public function __construct(?\PDO $bdd = null)
{ {
if ($bdd === null) if (null === $bdd)
{ {
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
} }

View File

@ -107,11 +107,10 @@ namespace controllers\internals;
return (bool) $this->model_user->update_email($id, $email); return (bool) $this->model_user->update_email($id, $email);
} }
/** /**
* Update user status. * Update user status.
* *
* @param string $id : user id * @param string $id : user id
* @param string $status : new status * @param string $status : new status
* *
* @return boolean; * @return boolean;
@ -181,13 +180,13 @@ namespace controllers\internals;
/** /**
* Update a user by his id. * Update a user by his id.
* *
* @param mixed $id * @param mixed $id
* @param mixed $email * @param mixed $email
* @param mixed $password * @param mixed $password
* @param mixed $admin * @param mixed $admin
* @param mixed $api_key * @param mixed $api_key
* @param string $status : User status * @param string $status : User status
* @param bool $encrypt_password : Should the password be encrypted, by default true * @param bool $encrypt_password : Should the password be encrypted, by default true
* *
* @return int : Number of modified user * @return int : Number of modified user
*/ */
@ -210,9 +209,9 @@ namespace controllers\internals;
* @param mixed $email * @param mixed $email
* @param mixed $password * @param mixed $password
* @param mixed $admin * @param mixed $admin
* @param ?string $api_key : The api key of the user, if null generate randomly * @param ?string $api_key : The api key of the user, if null generate randomly
* @param string $status : User status, default \models\User::STATUS_ACTIVE * @param string $status : User status, default \models\User::STATUS_ACTIVE
* @param bool $encrypt_password : Should the password be encrypted, by default true * @param bool $encrypt_password : Should the password be encrypted, by default true
* *
* @return mixed bool|int : false on error, id of the new user else * @return mixed bool|int : false on error, id of the new user else
*/ */
@ -255,21 +254,21 @@ namespace controllers\internals;
return bin2hex(random_bytes(16)); return bin2hex(random_bytes(16));
} }
/** /**
* Transfer a received sms to user email * Transfer a received sms to user email.
* @param int $id_user : User id *
* @param int $id_user : User id
* @param array $received : [ * @param array $received : [
* int 'id' => sms id, * int 'id' => sms id,
* string 'at' => sms reception date, * string 'at' => sms reception date,
* string 'text' => sms content, * string 'text' => sms content,
* string 'destination' => id of phone the sms was sent to * string 'destination' => id of phone the sms was sent to
* string 'origin' => phone number that sent the sms * string 'origin' => phone number that sent the sms
* ] * ]
* *
* @return bool : False if no transfer, true else * @return bool : False if no transfer, true else
*/ */
public function transfer_received (int $id_user, array $received) : bool public function transfer_received(int $id_user, array $received): bool
{ {
$settings = $this->internal_setting->gets_for_user($id_user); $settings = $this->internal_setting->gets_for_user($id_user);
@ -291,6 +290,7 @@ namespace controllers\internals;
} }
$mailer = new Mailer(); $mailer = new Mailer();
return $mailer->enqueue($user['email'], EMAIL_TRANSFER_SMS, [ return $mailer->enqueue($user['email'], EMAIL_TRANSFER_SMS, [
'at' => $received['at'], 'at' => $received['at'],
'origin' => $received['origin'], 'origin' => $received['origin'],

View File

@ -87,33 +87,22 @@ class Webhook extends StandardController
return $this->get_model()->gets_for_type_and_user($id_user, $type); return $this->get_model()->gets_for_type_and_user($id_user, $type);
} }
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Webhook($this->bdd);
return $this->model;
}
/** /**
* Trigger a webhook and transmit the signal to webhook daemon if needed. * Trigger a webhook and transmit the signal to webhook daemon if needed.
* @param int $id_user : User to trigger the webhook for *
* @param string $type : Type of webhook to trigger * @param int $id_user : User to trigger the webhook for
* @param array $sms : The sms [ * @param string $type : Type of webhook to trigger
* int 'id' => SMS id, * @param array $sms : The sms [
* string 'at' => SMS date, * int 'id' => SMS id,
* string 'text' => sms body, * string 'at' => SMS date,
* string 'origin' => sms origin (number or phone id) * string 'text' => sms body,
* string 'destination' => sms destination (number or phone id) * string 'origin' => sms origin (number or phone id)
* ] * string 'destination' => sms destination (number or phone id)
* ]
*
* @return bool : False if no trigger, true else * @return bool : False if no trigger, true else
*/ */
public function trigger (int $id_user, string $type, array $sms) public function trigger(int $id_user, string $type, array $sms)
{ {
$internal_setting = new Setting($this->bdd); $internal_setting = new Setting($this->bdd);
$settings = $internal_setting->gets_for_user($id_user); $settings = $internal_setting->gets_for_user($id_user);
@ -141,7 +130,20 @@ class Webhook extends StandardController
$error_code = null; $error_code = null;
$queue = msg_get_queue(QUEUE_ID_WEBHOOK); $queue = msg_get_queue(QUEUE_ID_WEBHOOK);
$success = msg_send($queue, QUEUE_TYPE_WEBHOOK, $message, true, true, $error_code); $success = msg_send($queue, QUEUE_TYPE_WEBHOOK, $message, true, true, $error_code);
return (bool) $success; return (bool) $success;
} }
} }
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Webhook($this->bdd);
return $this->model;
}
} }

View File

@ -91,7 +91,7 @@ namespace controllers\publics;
exit(self::ERROR_CODES['INVALID_CREDENTIALS']); exit(self::ERROR_CODES['INVALID_CREDENTIALS']);
} }
if ($this->user['status'] !== \models\User::STATUS_ACTIVE) if (\models\User::STATUS_ACTIVE !== $this->user['status'])
{ {
$return = self::DEFAULT_RETURN; $return = self::DEFAULT_RETURN;
$return['error'] = self::ERROR_CODES['SUSPENDED_USER']; $return['error'] = self::ERROR_CODES['SUSPENDED_USER'];
@ -121,6 +121,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER']; $return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'entry_type must be one of : ' . implode(', ', $entry_types) . '.'; $return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'entry_type must be one of : ' . implode(', ', $entry_types) . '.';
$this->auto_http_code(false); $this->auto_http_code(false);
return $this->json($return); return $this->json($return);
} }
@ -165,6 +166,7 @@ namespace controllers\publics;
} }
$this->auto_http_code(true); $this->auto_http_code(true);
return $this->json($return); return $this->json($return);
} }
@ -182,7 +184,7 @@ namespace controllers\publics;
* *
* @return : Id of scheduled created * @return : Id of scheduled created
*/ */
public function post_scheduled () public function post_scheduled()
{ {
$at = $_POST['at'] ?? false; $at = $_POST['at'] ?? false;
$text = $_POST['text'] ?? false; $text = $_POST['text'] ?? false;
@ -193,10 +195,10 @@ namespace controllers\publics;
$groups = $_POST['groups'] ?? []; $groups = $_POST['groups'] ?? [];
$conditional_groups = $_POST['conditional_groups'] ?? []; $conditional_groups = $_POST['conditional_groups'] ?? [];
$numbers = is_array($numbers) ? $numbers : [$numbers]; $numbers = \is_array($numbers) ? $numbers : [$numbers];
$contacts = is_array($contacts) ? $contacts : [$contacts]; $contacts = \is_array($contacts) ? $contacts : [$contacts];
$groups = is_array($groups) ? $groups : [$groups]; $groups = \is_array($groups) ? $groups : [$groups];
$conditional_groups = is_array($conditional_groups) ? $conditional_groups : [$conditional_groups]; $conditional_groups = \is_array($conditional_groups) ? $conditional_groups : [$conditional_groups];
if (!$at) if (!$at)
{ {
@ -209,6 +211,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER']; $return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . ($at ? '' : 'at ') . ($text ? '' : 'text'); $return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . ($at ? '' : 'at ') . ($text ? '' : 'text');
$this->auto_http_code(false); $this->auto_http_code(false);
return $this->json($return); return $this->json($return);
} }
@ -218,6 +221,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER']; $return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'at must be a date of format "Y-m-d H:i:s".'; $return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'at must be a date of format "Y-m-d H:i:s".';
$this->auto_http_code(false); $this->auto_http_code(false);
return $this->json($return); return $this->json($return);
} }
@ -241,6 +245,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER']; $return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . 'You must specify at least one valid number, contact, group or conditional_group.'; $return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . 'You must specify at least one valid number, contact, group or conditional_group.';
$this->auto_http_code(false); $this->auto_http_code(false);
return $this->json($return); return $this->json($return);
} }
@ -250,6 +255,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER']; $return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'id_phone : You must specify an id_phone number among thoses of user phones.'; $return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'id_phone : You must specify an id_phone number among thoses of user phones.';
$this->auto_http_code(false); $this->auto_http_code(false);
return $this->json($return); return $this->json($return);
} }
@ -260,12 +266,14 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['CANNOT_CREATE']; $return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE']; $return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'];
$this->auto_http_code(false); $this->auto_http_code(false);
return $this->json($return); return $this->json($return);
} }
$return = self::DEFAULT_RETURN; $return = self::DEFAULT_RETURN;
$return['response'] = $scheduled_id; $return['response'] = $scheduled_id;
$this->auto_http_code(true); $this->auto_http_code(true);
return $this->json($return); return $this->json($return);
} }
@ -292,6 +300,7 @@ namespace controllers\publics;
$return['response'] = true; $return['response'] = true;
$this->auto_http_code(true); $this->auto_http_code(true);
return $this->json($return); return $this->json($return);
} }
} }

View File

@ -114,9 +114,10 @@ use Monolog\Logger;
} }
//Do not update if current status is delivered or failed //Do not update if current status is delivered or failed
if ($sended['status'] === \models\Sended::STATUS_DELIVERED || $sended['status'] === \models\Sended::STATUS_FAILED) if (\models\Sended::STATUS_DELIVERED === $sended['status'] || \models\Sended::STATUS_FAILED === $sended['status'])
{ {
$this->logger->info('Callback status update message ignore because status is already ' . $sended['status'] . '.'); $this->logger->info('Callback status update message ignore because status is already ' . $sended['status'] . '.');
return false; return false;
} }
@ -126,17 +127,16 @@ use Monolog\Logger;
return true; return true;
} }
/** /**
* Function call on sms reception notification * Function call on sms reception notification
* We return nothing, and we let the adapter do his things. * We return nothing, and we let the adapter do his things.
* *
* @param string $adapter_uid : Uid of the adapter to use * @param string $adapter_uid : Uid of the adapter to use
* @param int $id_phone : Phone id * @param int $id_phone : Phone id
* *
* @return bool : true on success, false on error * @return bool : true on success, false on error
*/ */
public function reception (string $adapter_uid, int $id_phone) public function reception(string $adapter_uid, int $id_phone)
{ {
$this->logger->info('Callback reception call with adapter uid : ' . $adapter_uid); $this->logger->info('Callback reception call with adapter uid : ' . $adapter_uid);
@ -171,6 +171,7 @@ use Monolog\Logger;
if ($response['error']) if ($response['error'])
{ {
$this->logger->error('Callback reception with adapter ' . $adapter_uid . ' failed : ' . $response['error_message']); $this->logger->error('Callback reception with adapter ' . $adapter_uid . ' failed : ' . $response['error_message']);
return false; return false;
} }
@ -180,10 +181,12 @@ use Monolog\Logger;
if ($response['error']) if ($response['error'])
{ {
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']); $this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
return false; return false;
} }
$this->logger->info('Callback reception successfully received message : ' . json_encode($sms)); $this->logger->info('Callback reception successfully received message : ' . json_encode($sms));
return true; return true;
} }
} }

View File

@ -64,7 +64,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Connect', 'login')); return $this->redirect(\descartes\Router::url('Connect', 'login'));
} }
if ($user['status'] !== \models\User::STATUS_ACTIVE) if (\models\User::STATUS_ACTIVE !== $user['status'])
{ {
\FlashMessage\FlashMessage::push('danger', 'Votre compte est actuellement suspendu.'); \FlashMessage\FlashMessage::push('danger', 'Votre compte est actuellement suspendu.');

View File

@ -303,7 +303,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Contact', 'list')); return $this->redirect(\descartes\Router::url('Contact', 'list'));
} }
$msg = ($result == 1 ? '1' : 'Pas de') . ' nouveau contact inséré.'; $msg = (1 === $result ? '1' : 'Pas de') . ' nouveau contact inséré.';
if ($result > 1) if ($result > 1)
{ {
$msg = $result . ' nouveaux contacts ont été insérés.'; $msg = $result . ' nouveaux contacts ont été insérés.';

View File

@ -52,6 +52,7 @@ class Phone extends \descartes\Controller
if (!$adapter) if (!$adapter)
{ {
$phone['adapter'] = 'Inconnu'; $phone['adapter'] = 'Inconnu';
continue; continue;
} }
@ -111,7 +112,7 @@ class Phone extends \descartes\Controller
* Create a new phone. * Create a new phone.
* *
* @param $csrf : CSRF token * @param $csrf : CSRF token
* @param string $_POST['name'] : Phone name * @param string $_POST['name'] : Phone name
* @param string $_POST['adapter'] : Phone adapter * @param string $_POST['adapter'] : Phone adapter
* @param array $_POST['adapter_datas'] : Phone adapter datas * @param array $_POST['adapter_datas'] : Phone adapter datas
*/ */

View File

@ -50,7 +50,7 @@ namespace controllers\publics;
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']); $this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
} }
if ($received['id_phone'] !== null) if (null !== $received['id_phone'])
{ {
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']); $phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
if ($phone) if ($phone)
@ -80,7 +80,7 @@ namespace controllers\publics;
{ {
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']); $this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
if ($received['id_phone'] !== null) if (null !== $received['id_phone'])
{ {
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']); $phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
if ($phone) if ($phone)

View File

@ -46,7 +46,7 @@ namespace controllers\publics;
foreach ($sendeds as $key => $sended) foreach ($sendeds as $key => $sended)
{ {
if ($sended['id_phone'] !== null) if (null !== $sended['id_phone'])
{ {
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $sended['id_phone']); $phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $sended['id_phone']);
if ($phone) if ($phone)

View File

@ -46,17 +46,16 @@ class User extends \descartes\Controller
$this->render('user/list', ['users' => $users]); $this->render('user/list', ['users' => $users]);
} }
/** /**
* Update status of users * Update status of users.
* *
* @param array int $_GET['ids'] : User ids * @param array int $_GET['ids'] : User ids
* @param mixed $csrf * @param mixed $csrf
* @param int $status : 1 -> active, 0 -> suspended * @param int $status : 1 -> active, 0 -> suspended
* *
* @return boolean; * @return boolean;
*/ */
public function update_status ($csrf, int $status) public function update_status($csrf, int $status)
{ {
if (!$this->verify_csrf($csrf)) if (!$this->verify_csrf($csrf))
{ {
@ -65,7 +64,7 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'list')); return $this->redirect(\descartes\Router::url('User', 'list'));
} }
if ($status == 0) if (0 === $status)
{ {
$status = \models\User::STATUS_SUSPENDED; $status = \models\User::STATUS_SUSPENDED;
} }
@ -83,7 +82,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'list')); return $this->redirect(\descartes\Router::url('User', 'list'));
} }
/** /**
* Cette fonction va supprimer une liste de users. * Cette fonction va supprimer une liste de users.
* *

View File

@ -77,7 +77,6 @@ class Launcher extends AbstractDaemon
exec('php ' . PWD . '/console.php controllers/internals/Console.php sender > /dev/null 2>&1 &'); exec('php ' . PWD . '/console.php controllers/internals/Console.php sender > /dev/null 2>&1 &');
} }
/** /**
* Function to start mailer daemon. * Function to start mailer daemon.
*/ */

View File

@ -60,6 +60,7 @@ class Mailer extends AbstractDaemon
{ {
$this->logger->critical('Error for mailer queue reading, error code : ' . $error_code); $this->logger->critical('Error for mailer queue reading, error code : ' . $error_code);
$find_message = false; $find_message = false;
continue; continue;
} }
@ -77,6 +78,7 @@ class Mailer extends AbstractDaemon
if (!$success) if (!$success)
{ {
$this->logger->error('Failed sending email'); $this->logger->error('Failed sending email');
continue; continue;
} }

View File

@ -135,7 +135,6 @@ class Phone extends AbstractDaemon
//Update last message time //Update last message time
$this->last_message_at = microtime(true); $this->last_message_at = microtime(true);
//Do message sending //Do message sending
$this->logger->info('Try send message : ' . json_encode($message)); $this->logger->info('Try send message : ' . json_encode($message));
@ -143,6 +142,7 @@ class Phone extends AbstractDaemon
if ($response['error']) if ($response['error'])
{ {
$this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']); $this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']);
continue; continue;
} }
@ -167,6 +167,7 @@ class Phone extends AbstractDaemon
if ($response['error']) if ($response['error'])
{ {
$this->logger->info('Error reading received smss : ' . $response['error_message']); $this->logger->info('Error reading received smss : ' . $response['error_message']);
return false; return false;
} }
@ -184,11 +185,11 @@ class Phone extends AbstractDaemon
if ($response['error']) if ($response['error'])
{ {
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']); $this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
continue; continue;
} }
$this->logger->info('Message received successfully.'); $this->logger->info('Message received successfully.');
} }
} }
} }

View File

@ -62,6 +62,7 @@ class Webhook extends AbstractDaemon
{ {
$this->logger->critical('Error for webhook queue reading, error code : ' . $error_code); $this->logger->critical('Error for webhook queue reading, error code : ' . $error_code);
$find_message = false; $find_message = false;
continue; continue;
} }

View File

@ -17,7 +17,7 @@ namespace models;
* Return a phone by his name and user. * Return a phone by his name and user.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param string $name : phone name * @param string $name : phone name
* *
* @return array * @return array
*/ */

View File

@ -44,7 +44,6 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Count number of unread received sms for user. * Count number of unread received sms for user.
* *

View File

@ -74,7 +74,7 @@ namespace models;
/** /**
* Return sended for an uid and an adapter. * Return sended for an uid and an adapter.
* *
* @param int $id_user : Id of the user * @param int $id_user : Id of the user
* @param string $uid : Uid of the sended * @param string $uid : Uid of the sended
* @param string $adapter : Adapter used to send the message * @param string $adapter : Adapter used to send the message
* *

View File

@ -16,7 +16,6 @@ namespace models;
const TYPE_SEND = 'send_sms'; const TYPE_SEND = 'send_sms';
const TYPE_RECEIVE = 'receive_sms'; const TYPE_RECEIVE = 'receive_sms';
/** /**
* Find all webhooks for a user and for a type of webhook. * Find all webhooks for a user and for a type of webhook.
* *

View File

@ -1,7 +1,7 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
function help () function help()
{ {
echo 'Usage : ' . __FILE__ . ' <arg>' . "\n" . echo 'Usage : ' . __FILE__ . ' <arg>' . "\n" .
'Args :' . "\n" . 'Args :' . "\n" .
@ -20,22 +20,21 @@
'php ' . __DIR__ . '/php-cs-fixer.phar --config="' . __DIR__ . '/php_cs.config" fix', 'php ' . __DIR__ . '/php-cs-fixer.phar --config="' . __DIR__ . '/php_cs.config" fix',
]; ];
if (count($argv) < 2 || 'help' === $argv[1])
if (count($argv) < 2 || $argv[1] === 'help')
{ {
help(); help();
} }
if ($argv[1] === 'lint') if ('lint' === $argv[1])
{ {
echo "######################" . "\n"; echo '######################' . "\n";
echo "# SHOW ERRORS TO FIX #" . "\n"; echo '# SHOW ERRORS TO FIX #' . "\n";
echo "######################" . "\n"; echo '######################' . "\n";
echo "\n"; echo "\n";
foreach ($lint_commands as $lint_command) foreach ($lint_commands as $lint_command)
{ {
echo "Run : " . $lint_command . " \n"; echo 'Run : ' . $lint_command . " \n";
$return = shell_exec($lint_command); $return = shell_exec($lint_command);
echo $return; echo $return;
echo "\n\n"; echo "\n\n";
@ -44,16 +43,16 @@
exit(0); exit(0);
} }
if ($argv[1] === 'fix') if ('fix' === $argv[1])
{ {
echo "##############" . "\n"; echo '##############' . "\n";
echo "# FIX ERRORS #" . "\n"; echo '# FIX ERRORS #' . "\n";
echo "##############" . "\n"; echo '##############' . "\n";
echo "\n"; echo "\n";
foreach ($fix_commands as $fix_command) foreach ($fix_commands as $fix_command)
{ {
echo "Run : " . $fix_command . " \n"; echo 'Run : ' . $fix_command . " \n";
$return = shell_exec($fix_command); $return = shell_exec($fix_command);
echo $return; echo $return;
echo "\n\n"; echo "\n\n";
@ -62,5 +61,5 @@
exit(0); exit(0);
} }
echo "Invalid arg : " . $argv[1] . "\n"; echo 'Invalid arg : ' . $argv[1] . "\n";
help(); help();