diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 388075a4b..f33e34ff1 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -1678,7 +1678,7 @@ function isCommandlineSafeEmailAddress($address) { * @throws LAMException error during SMS connection */ function sendSmsTestMessage(string $providerId, ?string $apiKey, ?string $apiToken, string $number): void { - include_once __DIR__ . '/plugins/sms/SmsProvider.inc'; + include_once __DIR__ . '/plugins/sms/SmsService.inc'; $smsService = new SmsService(); try { $smsService->sendSms(_('LAM test message'), $number, $providerId, $apiKey, $apiToken); diff --git a/lam/lib/plugins/sms/GatewayApiSmsProvider.inc b/lam/lib/plugins/sms/GatewayApiSmsProvider.inc new file mode 100644 index 000000000..6876ca3cb --- /dev/null +++ b/lam/lib/plugins/sms/GatewayApiSmsProvider.inc @@ -0,0 +1,107 @@ + [ + ['msisdn' => $number] + ], + "message" => $message, + "label" => "LAM Pro", + "sender" => "LAM Pro" + ]; + $postJson = json_encode($postData); + curl_setopt_array($curl, [ + CURLOPT_URL => 'https://gatewayapi.eu/rest/mtsms', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $postJson, + CURLOPT_USERPWD => $apiToken, + CURLOPT_HTTPHEADER => [ + 'Content-Type: application/json', + 'Accept: application/json', + ], + ]); + logNewMessage(LOG_DEBUG, 'SMS message for: ' . $number); + $response = curl_exec($curl); + $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + curl_close($curl); + logNewMessage(LOG_DEBUG, 'SMS gateway response: ' . $response); + $responseJson = json_decode($response, true); + if (($httpCode !== 200)) { + logNewMessage(LOG_ERR, 'Unable to send SMS: ' . $response); + $message = $responseJson['message'] ?? ''; + throw new LAMException(null, $message); + } + } + + /** + * @inheritDoc + */ + public function usesApiToken(): bool { + return true; + } + + /** + * @inheritDoc + */ + public function usesApiKey(): bool { + return false; + } + +} diff --git a/lam/lib/plugins/sms/SmsApiSms.inc b/lam/lib/plugins/sms/SmsApiSmsProvider.inc similarity index 98% rename from lam/lib/plugins/sms/SmsApiSms.inc rename to lam/lib/plugins/sms/SmsApiSmsProvider.inc index 99c6f9b5c..31a8282ff 100644 --- a/lam/lib/plugins/sms/SmsApiSms.inc +++ b/lam/lib/plugins/sms/SmsApiSmsProvider.inc @@ -34,7 +34,7 @@ use LAMException; /** * SMSAPI SMS provider. * - * @package LAM\PLUGINS\CAPTCHA + * @package LAM\PLUGINS\SMS */ class SmsApiSms implements SmsProvider { diff --git a/lam/lib/plugins/sms/SmsProvider.inc b/lam/lib/plugins/sms/SmsService.inc similarity index 99% rename from lam/lib/plugins/sms/SmsProvider.inc rename to lam/lib/plugins/sms/SmsService.inc index 560aaad8d..97cabec0b 100644 --- a/lam/lib/plugins/sms/SmsProvider.inc +++ b/lam/lib/plugins/sms/SmsService.inc @@ -26,7 +26,7 @@ namespace LAM\PLUGINS\SMS; use LAMException; /** - * SMS providers. + * SMS service. * * @author Roland Gruber */ diff --git a/lam/lib/plugins/sms/SweegoSms.inc b/lam/lib/plugins/sms/SweegoSmsProvider.inc similarity index 98% rename from lam/lib/plugins/sms/SweegoSms.inc rename to lam/lib/plugins/sms/SweegoSmsProvider.inc index 615969ac3..597070dec 100644 --- a/lam/lib/plugins/sms/SweegoSms.inc +++ b/lam/lib/plugins/sms/SweegoSmsProvider.inc @@ -34,7 +34,7 @@ use LAMException; /** * Sweego SMS provider. * - * @package LAM\PLUGINS\CAPTCHA + * @package LAM\PLUGINS\SMS */ class SweegoSms implements SmsProvider { diff --git a/lam/templates/config/mainmanage.php b/lam/templates/config/mainmanage.php index aecb36289..df9632ecc 100644 --- a/lam/templates/config/mainmanage.php +++ b/lam/templates/config/mainmanage.php @@ -70,7 +70,7 @@ include_once(__DIR__ . '/../../lib/status.inc'); /** LAM Pro */ include_once(__DIR__ . '/../../lib/selfService.inc'); /** SMS */ -include_once __DIR__ . '/../../lib/plugins/sms/SmsProvider.inc'; +include_once __DIR__ . '/../../lib/plugins/sms/SmsService.inc'; // start session if (isFileBasedSession()) {