diff --git a/VERSION b/VERSION index ed530b3..6eef43b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.1.5 +v3.1.4 diff --git a/adapters/OctopushShortcodeAdapter.php b/adapters/OctopushShortcodeAdapter.php index d7ed533..4a645e6 100644 --- a/adapters/OctopushShortcodeAdapter.php +++ b/adapters/OctopushShortcodeAdapter.php @@ -16,8 +16,10 @@ namespace adapters; */ class OctopushShortcodeAdapter implements AdapterInterface { - const SMS_TYPE_LOWCOST = 'sms_low_cost'; - const SMS_TYPE_PREMIUM = 'sms_premium'; + const ERROR_CODE_OK = '000'; + const SMS_TYPE_LOWCOST = 'XXX'; + const SMS_TYPE_PREMIUM = 'FR'; + const SMS_TYPE_INTERNATIONAL = 'WWW'; /** * Data used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.). @@ -38,17 +40,11 @@ class OctopushShortcodeAdapter implements AdapterInterface * Sender name to use instead of shortcode. */ private $sender; - - /** - * Octopush SMS type - */ - private $sms_type; /** * Octopush api baseurl. */ - private $api_url = 'https://api.octopush.com/v1/public'; - + private $api_url = 'https://www.octopush-dm.com/api'; /** * Adapter constructor, called when instanciated by RaspiSMS. @@ -62,13 +58,6 @@ class OctopushShortcodeAdapter implements AdapterInterface $this->login = $this->data['login']; $this->api_key = $this->data['api_key']; - - $this->sms_type = self::SMS_TYPE_LOWCOST; - if (($this->data['sms_type'] ?? false) && $this->data['sms_type'] === 'premium') - { - $this->sms_type = self::SMS_TYPE_PREMIUM; - } - $this->sender = $this->data['sender'] ?? null; } @@ -141,12 +130,6 @@ class OctopushShortcodeAdapter implements AdapterInterface 'description' => 'Clef API octopush. Trouvable sur la page des identifiants API Octopush.', 'required' => true, ], - [ - 'name' => 'sms_type', - 'title' => 'Type de SMS à employer', - 'description' => 'Type de SMS à employer coté Octopush, rentrez "low cost" ou "premium" selon le type de SMS que vous souhaitez employer. Laissez vide pour utiliser par défaut des SMS low cost.', - 'required' => false, - ], [ 'name' => 'sender', 'title' => 'Nom de l\'expéditeur', @@ -226,32 +209,21 @@ class OctopushShortcodeAdapter implements AdapterInterface try { - $headers = [ - 'api-login: ' . $this->login, - 'api-key: ' . $this->api_key, - 'Content-Type: application/json', - ]; - $data = [ - 'text' => $text, - 'recipients' => [['phone_number' => $destination]], - 'sms_type' => $this->sms_type, - 'purpose' => 'alert', + 'user_login' => $this->login, + 'api_key' => $this->api_key, + 'sms_text' => $text, + 'sms_recipients' => str_replace('+', '00', $destination), //Must use 00 instead of + notation + 'sms_sender' => '12345', + 'sms_type' => self::SMS_TYPE_LOWCOST, ]; - if ($this->sender) + if (null !== $this->sender) { - $data['sender'] = $this->sender; - } - else - { - $data['with_replies'] = "True"; + $data['sms_sender'] = $this->sender; } - $data = json_encode($data); - - - $endpoint = $this->api_url . '/sms-campaign/send'; + $endpoint = $this->api_url . '/sms/json'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $endpoint); @@ -259,13 +231,10 @@ class OctopushShortcodeAdapter implements AdapterInterface curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - $curl_response = curl_exec($curl); - $http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); + $response = curl_exec($curl); curl_close($curl); - if (false === $curl_response) + if (false === $response) { $response['error'] = true; $response['error_message'] = 'HTTP query failed.'; @@ -273,7 +242,7 @@ class OctopushShortcodeAdapter implements AdapterInterface return $response; } - $response_decode = json_decode($curl_response, true); + $response_decode = json_decode($response, true); if (null === $response_decode) { $response['error'] = true; @@ -282,15 +251,15 @@ class OctopushShortcodeAdapter implements AdapterInterface return $response; } - if (200 !== $http_code) + if (self::ERROR_CODE_OK !== $response_decode['error_code']) { $response['error'] = true; - $response['error_message'] = 'Response indicate error code : ' . $response_decode['code'] . ' -> """' . $response_decode['message'] . '""" AND HTTP CODE -> ' . $http_code; + $response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code']; return $response; } - $uid = $response_decode['sms_ticket'] ?? false; + $uid = $response_decode['ticket'] ?? false; if (!$uid) { $response['error'] = true; @@ -328,29 +297,34 @@ class OctopushShortcodeAdapter implements AdapterInterface return false; } - if (!empty($this->data['sms_type']) && !in_array($this->data['sms_type'], ['premium', 'low cost'])) - { - return false; - } - - $headers = [ - 'api-login: ' . $this->login, - 'api-key: ' . $this->api_key, - 'Content-Type: application/json', + $data = [ + 'user_login' => $this->login, + 'api_key' => $this->api_key, ]; //Check service name - $endpoint = $this->api_url . '/wallet/check-balance'; + $endpoint = $this->api_url . '/balance/json'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $endpoint); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $response = curl_exec($curl); - $http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); - if ($http_code !== 200) + if (false === $response) + { + return false; + } + + $response_decode = json_decode($response, true); + if (null === $response_decode) + { + return false; + } + + if (self::ERROR_CODE_OK !== $response_decode['error_code']) { return false; } @@ -369,23 +343,14 @@ class OctopushShortcodeAdapter implements AdapterInterface header('Content-Encoding: none'); header('Content-Length: 0'); - - $input = file_get_contents('php://input'); - $content = json_decode($input, true); - if (null === $content) - { - return false; - } - - $uid = $content['message_id'] ?? false; - $status = $content['status'] ?? false; + $uid = $_POST['message_id'] ?? false; + $status = $_POST['status'] ?? false; if (false === $uid || false === $status) { return false; } - switch ($status) { case 'DELIVERED': @@ -393,8 +358,10 @@ class OctopushShortcodeAdapter implements AdapterInterface break; - case 'NOT_DELIVERED': case 'NOT_ALLOWED': + case 'INVALID_DESTINATION_ADDRESS': + case 'OUT_OF_DATE': + case 'EXPIRED': case 'BLACKLISTED_NUMBER': $status = \models\Sended::STATUS_FAILED; @@ -420,20 +387,10 @@ class OctopushShortcodeAdapter implements AdapterInterface header('Connection: close'); header('Content-Encoding: none'); header('Content-Length: 0'); - - $input = file_get_contents('php://input'); - $content = json_decode($input, true); - if (null === $content) - { - $response['error'] = true; - $response['error_message'] = 'Cannot read input data from callback request.'; - - return $response; - } - $number = $content['number'] ?? false; - $text = $content['text'] ?? false; - $at = $content['reception_date'] ?? false; + $number = $_POST['number'] ?? false; + $text = $_POST['text'] ?? false; + $at = $_POST['reception_date'] ?? false; if (!$number || !$text || !$at) { @@ -443,11 +400,11 @@ class OctopushShortcodeAdapter implements AdapterInterface return $response; } - $origin = \controllers\internals\Tool::parse_phone($number); + $origin = \controllers\internals\Tool::parse_phone('+' . mb_substr($number, 2)); if (!$origin) { $response['error'] = true; - $response['error_message'] = 'Invalid origin number : ' . $number; + $response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2); return $response; } diff --git a/adapters/OctopushVirtualNumberAdapter.php b/adapters/OctopushVirtualNumberAdapter.php index 33473f9..ca3c986 100644 --- a/adapters/OctopushVirtualNumberAdapter.php +++ b/adapters/OctopushVirtualNumberAdapter.php @@ -16,8 +16,10 @@ namespace adapters; */ class OctopushVirtualNumberAdapter implements AdapterInterface { - const SMS_TYPE_LOWCOST = 'sms_low_cost'; - const SMS_TYPE_PREMIUM = 'sms_premium'; + const ERROR_CODE_OK = '000'; + const SMS_TYPE_LOWCOST = 'XXX'; + const SMS_TYPE_PREMIUM = 'FR'; + const SMS_TYPE_INTERNATIONAL = 'WWW'; /** * Data used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.). @@ -35,15 +37,19 @@ class OctopushVirtualNumberAdapter implements AdapterInterface private $api_key; /** - * Octopush SMS type + * Number phone to use. */ - private $sms_type; + private $number; + + /** + * Number phone to use formated for octopush compatibility. + */ + private $formatted_number; /** * Octopush api baseurl. */ - private $api_url = 'https://api.octopush.com/v1/public'; - + private $api_url = 'https://www.octopush-dm.com/api'; /** * Adapter constructor, called when instanciated by RaspiSMS. @@ -58,12 +64,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface $this->login = $this->data['login']; $this->api_key = $this->data['api_key']; $this->number = $this->data['number']; - - $this->sms_type = self::SMS_TYPE_LOWCOST; - if (($this->data['sms_type'] ?? false) && $this->data['sms_type'] === 'premium') - { - $this->sms_type = self::SMS_TYPE_PREMIUM; - } + $this->formatted_number = '+' . mb_substr($this->data['number'], 2); } /** @@ -113,7 +114,6 @@ class OctopushVirtualNumberAdapter implements AdapterInterface Envoi de SMS avec un numéro virtuel en utilisant Octopush. Pour trouver vos clés API Octopush cliquez ici.
Pour plus d\'information sur l\'utilisation de ce téléphone, reportez-vous à la documentation sur les téléphones "Octopush Numéro Virtuel". '; - } /** @@ -143,13 +143,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface 'required' => true, 'number' => true, ], - [ - 'name' => 'sms_type', - 'title' => 'Type de SMS à employer', - 'description' => 'Type de SMS à employer coté Octopush, rentrez "low cost" ou "premium" selon le type de SMS que vous souhaitez employer. Laissez vide pour utiliser par défaut des SMS low cost.', - 'required' => false, - ], - ]; + ]; } /** @@ -220,25 +214,16 @@ class OctopushVirtualNumberAdapter implements AdapterInterface try { - $headers = [ - 'api-login: ' . $this->login, - 'api-key: ' . $this->api_key, - 'Content-Type: application/json', - ]; - $data = [ - 'text' => $text, - 'recipients' => [['phone_number' => $destination]], - 'sms_type' => $this->sms_type, - 'purpose' => 'alert', - 'sender' => $this->number, - 'with_replies' => "True", + 'user_login' => $this->login, + 'api_key' => $this->api_key, + 'sms_text' => $text, + 'sms_recipients' => str_replace('+', '00', $destination), //Must use 00 instead of + notation + 'sms_sender' => $this->formatted_number, + 'sms_type' => self::SMS_TYPE_LOWCOST, ]; - $data = json_encode($data); - - - $endpoint = $this->api_url . '/sms-campaign/send'; + $endpoint = $this->api_url . '/sms/json'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $endpoint); @@ -246,13 +231,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - $curl_response = curl_exec($curl); - $http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); + $response = curl_exec($curl); curl_close($curl); - if (false === $curl_response) + if (false === $response) { $response['error'] = true; $response['error_message'] = 'HTTP query failed.'; @@ -260,7 +242,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface return $response; } - $response_decode = json_decode($curl_response, true); + $response_decode = json_decode($response, true); if (null === $response_decode) { $response['error'] = true; @@ -269,15 +251,15 @@ class OctopushVirtualNumberAdapter implements AdapterInterface return $response; } - if (200 !== $http_code) + if (self::ERROR_CODE_OK !== $response_decode['error_code']) { $response['error'] = true; - $response['error_message'] = 'Response indicate error code : ' . $response_decode['code'] . ' -> """' . $response_decode['message'] . '""" AND HTTP CODE -> ' . $http_code; + $response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code']; return $response; } - $uid = $response_decode['sms_ticket'] ?? false; + $uid = $response_decode['ticket'] ?? false; if (!$uid) { $response['error'] = true; @@ -310,35 +292,39 @@ class OctopushVirtualNumberAdapter implements AdapterInterface { $success = true; - if (!empty($this->data['sms_type']) && !in_array($this->data['sms_type'], ['premium', 'low cost'])) + if ($this->data['sender'] && (mb_strlen($this->data['sender']) < 3 || mb_strlen($this->data['sender'] > 11))) { return false; } - $origin = \controllers\internals\Tool::parse_phone($this->data['number']); - if (!$origin) - { - return false; - } - - $headers = [ - 'api-login: ' . $this->login, - 'api-key: ' . $this->api_key, - 'Content-Type: application/json', + $data = [ + 'user_login' => $this->login, + 'api_key' => $this->api_key, ]; //Check service name - $endpoint = $this->api_url . '/wallet/check-balance'; + $endpoint = $this->api_url . '/balance/json'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $endpoint); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $response = curl_exec($curl); - $http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); - if ($http_code !== 200) + if (false === $response) + { + return false; + } + + $response_decode = json_decode($response, true); + if (null === $response_decode) + { + return false; + } + + if (self::ERROR_CODE_OK !== $response_decode['error_code']) { return false; } @@ -357,23 +343,14 @@ class OctopushVirtualNumberAdapter implements AdapterInterface header('Content-Encoding: none'); header('Content-Length: 0'); - - $input = file_get_contents('php://input'); - $content = json_decode($input, true); - if (null === $content) - { - return false; - } - - $uid = $content['message_id'] ?? false; - $status = $content['status'] ?? false; + $uid = $_POST['message_id'] ?? false; + $status = $_POST['status'] ?? false; if (false === $uid || false === $status) { return false; } - switch ($status) { case 'DELIVERED': @@ -381,8 +358,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface break; - case 'NOT_DELIVERED': case 'NOT_ALLOWED': + case 'INVALID_DESTINATION_ADDRESS': + case 'OUT_OF_DATE': + case 'EXPIRED': case 'BLACKLISTED_NUMBER': $status = \models\Sended::STATUS_FAILED; @@ -402,26 +381,16 @@ class OctopushVirtualNumberAdapter implements AdapterInterface $response = [ 'error' => false, 'error_message' => null, - 'sms' => null, + 'uid' => null, ]; header('Connection: close'); header('Content-Encoding: none'); header('Content-Length: 0'); - - $input = file_get_contents('php://input'); - $content = json_decode($input, true); - if (null === $content) - { - $response['error'] = true; - $response['error_message'] = 'Cannot read input data from callback request.'; - - return $response; - } - $number = $content['number'] ?? false; - $text = $content['text'] ?? false; - $at = $content['reception_date'] ?? false; + $number = $_POST['number'] ?? false; + $text = $_POST['text'] ?? false; + $at = $_POST['reception_date'] ?? false; if (!$number || !$text || !$at) { @@ -431,11 +400,11 @@ class OctopushVirtualNumberAdapter implements AdapterInterface return $response; } - $origin = \controllers\internals\Tool::parse_phone($number); + $origin = \controllers\internals\Tool::parse_phone('+' . mb_substr($number, 2)); if (!$origin) { $response['error'] = true; - $response['error_message'] = 'Invalid origin number : ' . $number; + $response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2); return $response; } diff --git a/assets/js/custom.js b/assets/js/custom.js index 112625c..b25910a 100644 --- a/assets/js/custom.js +++ b/assets/js/custom.js @@ -139,15 +139,4 @@ jQuery(document).ready(function() form.trigger("reset"); }); }); - - jQuery('body').on('change', '.datatable #check-all', function (e) { - if (jQuery(e.target).is(':checked')) - { - jQuery(e.target).parents('.datatable').find('input[type="checkbox"]').prop('checked', true); - } - else - { - jQuery(e.target).parents('.datatable').find('input[type="checkbox"]').prop('checked', false); - } - }); }); diff --git a/controllers/publics/Callback.php b/controllers/publics/Callback.php index a9c8fa0..db68632 100644 --- a/controllers/publics/Callback.php +++ b/controllers/publics/Callback.php @@ -191,7 +191,7 @@ use Monolog\Logger; } $sms = $response['sms']; - $mms = (bool) ($sms['mms'] ?? false); + $mms = (bool) $sms['mms'] ?? false; $medias = empty($sms['medias']) ? [] : $sms['medias']; $response = $this->internal_received->receive($this->user['id'], $id_phone, $sms['text'], $sms['origin'], $sms['at'], \models\Received::STATUS_UNREAD, $mms, $medias); diff --git a/controllers/publics/Dashboard.php b/controllers/publics/Dashboard.php index 9cb84ac..280026f 100644 --- a/controllers/publics/Dashboard.php +++ b/controllers/publics/Dashboard.php @@ -77,11 +77,11 @@ namespace controllers\publics; $stats_start_date_formated = $stats_start_date->format('Y-m-d'); //If user have a quota and the quota start before today, use quota start date instead - $quota_unused = false; + $quota_limit = false; $quota = $this->internal_quota->get_user_quota($id_user); if ($quota && (new \DateTime($quota['start_date']) <= $now) && (new \DateTime($quota['expiration_date']) > $now)) { - $quota_unused = $quota['credit'] + $quota['additional'] - $quota['consumed']; + $quota_limit = $quota['credit'] + $quota['additional']; $stats_start_date = new \DateTime($quota['start_date']); $stats_start_date_formated = $stats_start_date->format('Y-m-d'); @@ -141,7 +141,7 @@ namespace controllers\publics; 'nb_unreads' => $nb_unreads, 'avg_sendeds' => $avg_sendeds, 'avg_receiveds' => $avg_receiveds, - 'quota_unused' => $quota_unused, + 'quota_limit' => $quota_limit, 'sendeds' => $sendeds, 'receiveds' => $receiveds, 'events' => $events, diff --git a/templates/call/list.php b/templates/call/list.php index 208a8d5..76d2eaf 100644 --- a/templates/call/list.php +++ b/templates/call/list.php @@ -44,7 +44,7 @@ Début de l'appel Fin de l'appel Direction - + ✓ diff --git a/templates/command/list.php b/templates/command/list.php index 602bc05..df6b555 100644 --- a/templates/command/list.php +++ b/templates/command/list.php @@ -42,7 +42,7 @@ Nom Script Admin obligatoire - + ✓ diff --git a/templates/conditional_group/list.php b/templates/conditional_group/list.php index b688bc4..bca9c0f 100644 --- a/templates/conditional_group/list.php +++ b/templates/conditional_group/list.php @@ -43,7 +43,7 @@ Condition Date de création Dernière modification - + ✓ diff --git a/templates/contact/list.php b/templates/contact/list.php index 03de988..c8f17e1 100644 --- a/templates/contact/list.php +++ b/templates/contact/list.php @@ -46,7 +46,7 @@ Numéro Date de création Dernière modification - + ✓ diff --git a/templates/dashboard/show.php b/templates/dashboard/show.php index 9c5f52f..b461521 100644 --- a/templates/dashboard/show.php +++ b/templates/dashboard/show.php @@ -123,9 +123,9 @@

Activité de la semaine :

SMS envoyés (moyenne = par jour).
SMS reçus (moyenne = par jour). - +
- Crédits restants : . + Limite max de SMS sur la période ().
@@ -254,8 +254,8 @@ ykeys: ['sendeds', 'receiveds'], labels: ['SMS envoyés', 'SMS reçus'], lineColors: ['#5CB85C', '#EDAB4D'], - goals: [, ], - goalLineColors: ['#5CB85C', '#EDAB4D'], + goals: [, ], + goalLineColors: ['#5CB85C', '#EDAB4D', '#d9534f'], goalStrokeWidth: 2, pointSize: 4, hideHover: 'auto', diff --git a/templates/event/list.php b/templates/event/list.php index 17a69c6..48086c1 100644 --- a/templates/event/list.php +++ b/templates/event/list.php @@ -43,7 +43,7 @@ Date Texte - + ✓ diff --git a/templates/group/list.php b/templates/group/list.php index eb1e7c1..6c5c2fb 100644 --- a/templates/group/list.php +++ b/templates/group/list.php @@ -43,7 +43,7 @@ Nombre de contacts Date de création Dernière modification - + ✓ diff --git a/templates/incs/nav.php b/templates/incs/nav.php index a40d176..5a5d3c3 100644 --- a/templates/incs/nav.php +++ b/templates/incs/nav.php @@ -69,7 +69,7 @@ - +
  • Logs