Adding callr and plivo as sms gateways

pull/586/head
Matthias Van Woensel 2018-05-17 16:20:29 +02:00
parent 8ca259d524
commit 656c8d0ffc
7 changed files with 147 additions and 1 deletions

View File

@ -11,7 +11,10 @@
"symfony/http-foundation": "~3.4",
"php-pushover/php-pushover": "dev-master",
"paragonie/random_compat": "^2.0",
"twig/twig": "~2.0"
"twig/twig": "~2.0",
"plivo/plivo-php": "^4.0",
"callr/sdk-php": "^0.10"
},
"autoload": {
"files": [

View File

@ -61,6 +61,8 @@ The following SMS gateways are currently available:
* FreeMobile (FR) - <https://mobile.free.fr/>
* Twilio - <https://twilio.com>
* CM Telecom - <https://www.cm.com/>
* Plivo - <https://plivo.com>
* Callr - <https://callr.com>
Please note: for these gateways you will need an account with sufficient credits.

View File

@ -578,6 +578,12 @@ function psm_build_sms() {
case 'twilio':
$sms = new \psm\Txtmsg\Twilio();
break;
case 'plivo':
$sms = new \psm\Txtmsg\Plivo();
break;
case 'callr':
$sms = new \psm\Txtmsg\Callr();
break;
}
// copy login information from the config file

View File

@ -378,6 +378,8 @@ 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_plivo' => psm_get_lang('config', 'sms_gateway_plivo'),
'label_sms_gateway_callr' => psm_get_lang('config', 'sms_gateway_callr'),
'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'),

68
src/psm/Txtmsg/Callr.php Normal file
View File

@ -0,0 +1,68 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;
class Callr extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
// =========================================================================
// [ Methods ]
// =========================================================================
public function setGateway($gateway) {
$this->gateway = $gateway;
}
public function sendSMS($message) {
//api stuff here
$api = new \CALLR\API\Client;
$api->setAuth(new CALLR\API\Authentication\LoginPasswordAuth($this->username, $this->password));
$options = new stdClass;
$options->force_encoding = 'GSM';
$options->nature = 'ALERTING';
$options->flash_message = false;//set to true if you don't want the SMS to be stored on the phone
try {
foreach($this->recipients as $recipient) {
$api->call('sms.send', [$this->originator, $recipient, $message, $options]);
}
return 1;
} catch(Exception $e){
if($e->getCode() == 22){
return "Exception: Authentication failure\r\n";
} else {
return $e->getMessage();
}
}
}
}

63
src/psm/Txtmsg/Plivo.php Normal file
View File

@ -0,0 +1,63 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;
class Plivo extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
// =========================================================================
// [ Methods ]
// =========================================================================
public function setGateway($gateway) {
$this->gateway = $gateway;
}
public function sendSMS($message) {
$authId = $this->username;
$authToken = $this->password;
$client = new \Plivo\RestClient($authId, $authToken);
/* @var $message_created \Plivo\Resources\Message\MessageCreateResponse */
$message_created = $client->messages->create(
$this->originator,
$this->recipients,
$message
);
if($message_created && count($message_created->getMessageUuid()) ) {
return 1;
} else {
return $message_created->getMessage();
}
}
}

View File

@ -203,6 +203,8 @@
<option value="smsgw" {{ sms_selected_smsgw|raw }}>{{ label_sms_gateway_smsgw }}</option>
<option value="nexmo" {{ sms_selected_nexmo|raw }}>{{ label_sms_gateway_nexmo }}</option>
<option value="twilio" {{ sms_selected_twilio|raw }}>{{ label_sms_gateway_twilio }}</option>
<option value="plivo" {{ sms_selected_plivo|raw }}>{{ label_sms_gateway_plivo }}</option>
<option value="callr" {{ sms_selected_callr|raw }}>{{ label_sms_gateway_callr }}</option>
</select>
</div>
</div>