diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index dde0f585..c43bda98 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -578,6 +578,9 @@ function psm_build_sms() { case 'twilio': $sms = new \psm\Txtmsg\Twilio(); break; + case 'gatewayapi': + $sms = new \psm\Txtmsg\GatewayAPI(); + break; } // copy login information from the config file diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 29c0697c..49f295b0 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -254,6 +254,7 @@ $sm_lang = array( 'sms_gateway_nexmo' => 'Nexmo', 'sms_gateway_smsgw' => 'SMSgw', 'sms_gateway_twilio' => 'Twilio', + 'sms_gateway_gatewayapi' => 'GatewayAPI', 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', 'sms_from' => 'Sender\'s phone number', diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index d0d80e2c..b07ee646 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -378,6 +378,7 @@ class ConfigController extends AbstractController { 'label_sms_gateway_freemobilesms' => psm_get_lang('config', 'sms_gateway_freemobilesms'), 'label_sms_gateway_clicksend' => psm_get_lang('config', 'sms_gateway_clicksend'), 'label_sms_gateway_twilio' => psm_get_lang('config', 'sms_gateway_twilio'), + 'label_sms_gateway_gatewayapi' => psm_get_lang('config', 'sms_gateway_gatewayapi'), 'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'), 'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'), 'label_sms_from' => psm_get_lang('config', 'sms_from'), diff --git a/src/psm/Txtmsg/GatewayAPI.php b/src/psm/Txtmsg/GatewayAPI.php new file mode 100644 index 00000000..46138197 --- /dev/null +++ b/src/psm/Txtmsg/GatewayAPI.php @@ -0,0 +1,96 @@ +. + * + * @package phpservermon + * @author Ward Pieters + * @copyright Copyright (c) 2008-2017 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://www.phpservermonitor.org/ + **/ + +namespace psm\Txtmsg; + +class GatewayAPI extends Core { + + /** + * Send sms using GatewayAPI + * @var string $message + * @var array $this->recipients + * @var string $recipient + * @var string $this->password + * @var string $this->originator + * @var int $success + * @var string $error + * @return int or string + */ + + public function sendSMS($message) { + $sender = $this->originator; + $apikey = $this->password; + $userref = $this->userref; + $destaddr = $this->destaddr; + $recipients = $this->recipients; + + $errors = array(); + + if(is_null($destaddr)) $destaddr = 'MOBILE'; + if(is_null($userref)) $userref = ''; + + + foreach($recipients as $recipient) { + $json = [ + 'sender' => $sender, + 'message' => $message, + 'recipients' => [], + 'destaddr' => $destaddr, + 'userref' => $userref, + ]; + + $json['recipients'][] = ['msisdn' => $recipient]; + + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL, "https://gatewayapi.com/rest/mtsms"); + curl_setopt($ch,CURLOPT_HTTPHEADER, array("Content-Type: application/json")); + curl_setopt($ch,CURLOPT_USERPWD, $apikey.":"); + curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($json)); + curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + $result = json_decode($result,true); + $addidtional_information = array(); + foreach($result as $key => $value) { if($key != 'ids') $addidtional_information[$key] = $value; } + + if($httpcode == 200) { + // SMS is gelukt + $output = array('success' => true, 'ids' => $result['ids'], 'addidtional_information' => $addidtional_information); + } + else { + // SMS is niet gelukt + $output = array('success' => false, 'code' => $result['code'], 'message' => $result['message'], 'variables' => $result['variables']); + array_push($errors, $output); + } + } + if(!empty($errors)) return false; + else return true; + } +} diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index d60eab4c..d0af60bb 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -194,15 +194,16 @@ - - - - - - - - + + + + + + + + +