| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\PLUGINS\SMS; |
| 4 |
|
| 5 |
/* |
| 6 |
|
| 7 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 8 |
Copyright (C) 2025 - 2026 Roland Gruber |
| 9 |
|
| 10 |
This program is free software; you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation; either version 2 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program; if not, write to the Free Software |
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
|
| 24 |
*/ |
| 25 |
|
| 26 |
use LAMException; |
| 27 |
|
| 28 |
/** |
| 29 |
* SMSBOX SMS provider. |
| 30 |
* |
| 31 |
* @author Roland Gruber |
| 32 |
*/ |
| 33 |
|
| 34 |
/** |
| 35 |
* SMSBOX SMS provider. |
| 36 |
* |
| 37 |
* @package LAM\PLUGINS\SMS |
| 38 |
*/ |
| 39 |
class SmsboxSms implements SmsProvider { |
| 40 |
|
| 41 |
/** |
| 42 |
* @inheritDoc |
| 43 |
*/ |
| 44 |
public function getLabel(): string { |
| 45 |
return 'SMSBOX'; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @inheritDoc |
| 50 |
*/ |
| 51 |
public function getId(): string { |
| 52 |
return 'smsbox'; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @inheritDoc |
| 57 |
*/ |
| 58 |
public function sendSms(string $message, string $number, ?string $apiKey = '', ?string $apiToken = '', |
| 59 |
?string $accountId = '', ?string $region = '', ?string $from = '', ?string $subject = ''): void { |
| 60 |
$curl = curl_init(); |
| 61 |
$postData = [ |
| 62 |
"dest" => $number, |
| 63 |
"msg" => $message, |
| 64 |
'charset' => 'utf-8', |
| 65 |
'mode' => 'Standard', |
| 66 |
'strategy' => '2' |
| 67 |
]; |
| 68 |
curl_setopt_array($curl, [ |
| 69 |
CURLOPT_URL => 'https://api.smsbox.pro/1.1/api.php', |
| 70 |
CURLOPT_RETURNTRANSFER => true, |
| 71 |
CURLOPT_POST => true, |
| 72 |
CURLOPT_POSTFIELDS => http_build_query($postData), |
| 73 |
CURLOPT_HTTPHEADER => [ |
| 74 |
'Content-Type: application/x-www-form-urlencoded', |
| 75 |
'Authorization: App ' . $apiKey, |
| 76 |
], |
| 77 |
]); |
| 78 |
$response = curl_exec($curl); |
| 79 |
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
| 80 |
logNewMessage(LOG_DEBUG, 'SMS gateway response: ' . $response); |
| 81 |
if (($httpCode !== 200) || ($response !== 'OK')) { |
| 82 |
logNewMessage(LOG_ERR, 'Unable to send SMS: ' . $response); |
| 83 |
throw new LAMException(null, ''); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* @inheritDoc |
| 89 |
*/ |
| 90 |
public function usesApiToken(): bool { |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* @inheritDoc |
| 96 |
*/ |
| 97 |
public function usesApiKey(): bool { |
| 98 |
return true; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* @inheritDoc |
| 103 |
*/ |
| 104 |
public function usesAccountId(): bool { |
| 105 |
return false; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* @inheritDoc |
| 110 |
*/ |
| 111 |
public function usesFrom(): bool { |
| 112 |
return false; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* @inheritDoc |
| 117 |
*/ |
| 118 |
public function usesRegion(): bool { |
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* @inheritDoc |
| 124 |
*/ |
| 125 |
public function usesSubject(): bool { |
| 126 |
return false; |
| 127 |
} |
| 128 |
|
| 129 |
} |