SMS: 4 gateways added and others rewritten (#593)

* Closes #588

* Not relevant anymore: closes #223

* Create Plivo.php

* Create SolutionsInfini.php, closes #460 

* Create Callr.php, closes #586

* Create GatewayAPI.php

* Update README.rst

* Update credits.rst

* Update functions.inc.php

* Update Octopush.php

* Update Smsit.php

* Update Mosms.php

* Update Smsglobal.php

* Update Smsit.php

* Update FreeVoipDeal.php

* Update FreeMobileSMS.php

* Update Inetworx.php
This commit is contained in:
Ward Pieters 2018-05-29 14:13:49 +02:00 committed by Tim
parent c3751e7e57
commit 57f4c369e9
16 changed files with 840 additions and 373 deletions

View File

@ -57,6 +57,10 @@ The following SMS gateways are currently available:
* FreeMobile (FR) - <https://mobile.free.fr/>
* Twilio - <https://twilio.com>
* CM Telecom - <https://www.cm.com/>
* GatewayAPI - <https://gatewayapi.com/>
* SolutionsInfini - <https://solutionsinfini.com/>
* Plivo - <https://www.plivo.com/>
* Callr - <https://www.callr.com/>

View File

@ -12,7 +12,7 @@ The following people have contributed to the development of PHP Server Monitor:
* Pepijn Over - https://github.com/dopeh
* Creator and project maintainer
* Creator
* Samuel Denis-D'Ortun - https://github.com/sadortun
@ -20,7 +20,7 @@ The following people have contributed to the development of PHP Server Monitor:
* Tim Zandbergen - https://github.com/TimZ99
* Project developer
* Project developer & maintainer
* Jérôme Cabanis - https://github.com/Abawell
@ -29,6 +29,11 @@ The following people have contributed to the development of PHP Server Monitor:
* Mobile compatibility
* Various fixes and improvements
* Ward Pieters - https://github.com/WardPieters
* GatewayAPI, Plivo, Callr and SolutionsInfini SMS Gateway
* Other SMS Gateways rewritten
* Perri Vardy-Mason - https://github.com/VeoPVM
* Textmarketer SMS gateway

View File

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

View File

@ -601,6 +601,18 @@ function psm_build_sms() {
case 'cmbulksms':
$sms = new \psm\Txtmsg\CMBulkSMS();
break;
case 'gatewayapi':
$sms = new \psm\Txtmsg\GatewayAPI();
break;
case 'callr':
$sms = new \psm\Txtmsg\Callr();
break;
case 'plivo':
$sms = new \psm\Txtmsg\Plivo();
break;
case 'solutionsinfini':
$sms = new \psm\Txtmsg\SolutionsInfini();
break;
}
// copy login information from the config file

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

@ -0,0 +1,90 @@
<?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
* @author Ward Pieters <ward@wardpieters.nl>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.3.0
**/
namespace psm\Txtmsg;
class Callr extends Core {
/**
* Send sms using the Callr API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
* @var string $recipient
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
foreach($this->recipients as $recipient) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.callr.com/rest/v1.1/sms",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode(
array(
"to" => $recipient,
"from" => $this->originator,
"body" => urlencode($message),
"options" => null,
)
),
CURLOPT_HTTPHEADER => array(
"authorization: Basic " . base64_encode($this->username . ":" . $this->password),
"content-type: application/json"
),
));
$result = json_decode(curl_exec($curl), true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($err = curl_errno($curl) || $httpcode != 200 || $result['status'] == "error") {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result['data']['code']." - ".$result['data']['message'];
}
curl_close($curl);
}
if($success) return 1;
return $error;
}
}

View File

@ -18,7 +18,7 @@
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Michiel van der Wulp <michiel@vanderwulp.be>
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
@ -28,25 +28,48 @@
namespace psm\Txtmsg;
class FreeMobileSMS extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
public function sendSMS($message) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://smsapi.free-mobile.fr/sendmsg?user=$this->username&pass=$this->password&msg=" . urlencode( $message ) );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
curl_close($ch);
return true;
/**
* Send sms using the FreeMobileSMS API
*
* @var string $message
* @var string $this->password
* @var string $this->username
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
* @var string $http_code
*
* @return int or string
*/
public function sendSMS($message) {
$success = 1;
$error = "";
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_URL, "https://smsapi.free-mobile.fr/sendmsg?" . http_build_query(
array(
"user" => $this->username,
"pass" => $this->password,
"msg" => urlencode($message),
)
)
);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($err = curl_errno($curl) || $httpcode != 200) {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err);
}
curl_close($curl);
if($success) return 1;
return $error;
}
}

View File

@ -17,38 +17,69 @@
* 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
* @author Michiel van der Wulp <michiel@vanderwulp.be>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1
**/
namespace psm\Txtmsg;
class FreeVoipDeal extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
/**
* Send sms using the FreeVoipDeal API
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
*
* @var resource $curl
* @var string $err
* @var string $recipient
* @var string $from
* @var string $result
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$local_url = "https://www.freevoipdeal.com/myaccount/sendsms.php";
$local_data = rawurlencode( $message );
foreach( $this->recipients as $phone ){
$result = file_get_contents( $local_url . "?username=" . $this->username
. "&password=" . $this->password . "&from=" . $this->originator . "&to=" . $phone
. "&text=" . $local_data );
$error = "";
$success = 1;
$message = rawurlencode($message);
foreach($this->recipients as $recipient) {
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, "https://www.freevoipdeal.com/myaccount/sendsms.php?" . http_build_query(
array(
"username" => $this->username,
"password" => $this->password,
"from" => substr($this->originator, 0, 11),
"to" => $recipient,
"text" => $message,
)
)
);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if($err || is_numeric(strpos($result, "failure"))) {
$success = 0;
$error = $result;
}
}
return $result;
if($success) return 1;
return $error;
}
}

View File

@ -0,0 +1,87 @@
<?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
* @author Ward Pieters <ward@wardpieters.nl>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.2
**/
namespace psm\Txtmsg;
class GatewayAPI extends Core {
/**
* Send sms using the GatewayAPI API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
* @Var string $recipient
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
if(empty($this->recipients)) return false;
$json = [
'sender' => isset($this->originator) ? $this->originator : "PHPServerMon",
'message' => $message,
'recipients' => [],
];
foreach($this->recipients as $recipient) {
$json['recipients'][] = ['msisdn' => $recipient];
}
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, "https://gatewayapi.com/rest/mtsms");
curl_setopt($curl,CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl,CURLOPT_USERPWD, $this->password . ":");
curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($json));
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($curl),true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_error($curl);
curl_close($curl);
if($err || $httpcode != 200) {
$success = 0;
$error = $result['code']." - ".$result['message'];
}
if($success) return 1;
return $error;
}
}

View File

@ -17,129 +17,76 @@
* 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
* @author Pepijn Over <pep@mailbox.org>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;
class Inetworx extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
// =========================================================================
// [ Methods ]
// =========================================================================
/**
* Send a text message to one or more recipients
*
* @param string $subject
* @param string $body
* @return boolean
*/
* Send sms using the Inetworx API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
*
* @var resource $curl
* @var string $err
* @Var string $recipient
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
foreach($this->recipients as $recipient) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://sms.inetworx.ch/smsapp/sendsms.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query(
array(
"user" => $this->username,
"pass" => $this->password,
"sender" => $this->originator,
"rcpt" => $recipient,
"msgbody" => $message,
)
),
CURLOPT_HTTPHEADER => array(
"authorization: Basic " . base64_encode("inetworxag:conn2smsapp"),
"content-type: application/x-www-form-urlencoded"
),
));
if(empty($this->recipients)) {
return false;
}
$result = curl_exec($curl);
$errors = 0;
foreach($this->recipients as $receiver) {
if(!$this->executeSend($message, $receiver, $this->originator)) {
$errors++;
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($err = curl_errno($curl) || $httpcode != 200 || strpos($result, "200") === false) {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". \nResult: ".$result;
}
curl_close($curl);
}
$this->recipients = array();
return ($errors > 0) ? false : true;
if($success) return 1;
return $error;
}
/**
* Performs the actual send operation
*
* @param string $subject
* @param string $body
* @param string $receiver
* @param string $sender
* @return unknown
*/
protected function executeSend($message, $receiver, $sender) {
$con_https[0] = 'sms.inetworx.ch';
$con_https[1] = '443';
$con_https[2] = 'inetworxag:conn2smsapp';
$posturl = "/smsapp/sendsms.php";
if(!empty($receiver)) {
$postvars = 'user=' . urlencode($this->username) .
'&pass=' . urlencode($this->password) .
'&sender=' . urldecode($sender) .
'&rcpt=' . urlencode($receiver) .
'&msgbody=' . urlencode($message)
;
//if enabled, it sends a flash-message (not stored in Inbox!!)
//$postvars .= "&mclass=1";
$rtnval = $this->_auth_https_post(array($con_https[0], $con_https[1], $con_https[2], $posturl, $postvars));
return $rtnval;
//echo "SMS-Send-Result: $rtnval";
} else {
return false;
}
}
protected function _auth_https_post($inarray) {
// AUTH_HTTPS_POST: Request POST URL using basic authentication and SSL.
// Input: inarray[0]: host name
// inarray[1]: service port
// inarray[2]: user/password
// inarray[3]: URL request
// inarray[4]: POST variables
// Output: Message returned by server.
// Build the header.
$header = "POST ".$inarray[3]." HTTP/1.0\r\n";
$header .= "Authorization: Basic ".base64_encode("$inarray[2]")."\r\n";
$header .= "Host: ".$inarray[0]."\r\n";
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$header .= "Content-length: ".strlen($inarray[4])."\r\n\r\n";
// Connect to the server.
$connection = fsockopen("ssl://".$inarray[0], $inarray[1], $errnum, $errdesc, 10);
$msg = "";
if (! $connection){
$msg = $errdesc." (".$errnum.")";
}
else
{
socket_set_blocking($connection,false);
fputs($connection,$header.$inarray[4]);
while (! feof($connection))
{
$newline = fgets($connection,128);
switch ($newline)
{
// Skip http headers.
case (strstr($newline, 'Content-')): break;
case (strstr($newline, 'HTTP/1')): break;
case (strstr($newline, 'Date:')): break;
case (strstr($newline, 'Server:')): break;
case (strstr($newline, 'X-Powered-By:')): break;
case (strstr($newline, 'Connection:')): break;
case "": break;
case "\r\n": break;
default: $msg .= $newline;
} //end switch
} //end while
fclose($connection);
} //end else
return $msg;
} //end function auth_https_post
}

View File

@ -17,40 +17,71 @@
* 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
* @author Andreas Ek
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/
namespace psm\Txtmsg;
class Mosms extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
/**
* Send sms using the Mosms API
*
* @var string $message
* @var array $this->username
* @var string $this->password
* @var array $this->recipients
* @var string $recipient
* @var array $this->originator (Max 11 characters)
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$mosms_url = "https://www.mosms.com/se/sms-send.php";
$mosms_data = rawurlencode( $message );
foreach( $this->recipients as $phone ){
$result = file_get_contents( $mosms_url . "?username=" . $this->username
. "&password=" . $this->password . "&nr=" . $phone . "&type=text"
. "&data=" . $mosms_data );
$error = "";
$success = 1;
$message = rawurlencode($message);
foreach($this->recipients as $recipient) {
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, "https://www.mosms.com/se/sms-send.php?" . http_build_query(
array(
"username" => $this->username,
"password" => $this->password,
"customsender" => substr($this->originator, 0, 11),
"nr" => $recipient,
"type" => "text",
"data" => $message,
)
)
);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$result = curl_exec($curl);
$err = curl_error($curl);
if($err = curl_errno($curl) || $httpcode != 200 || $result == 2 || $result == 5) {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". \nResult: ".$result;
}
curl_close($curl);
}
return $result;
if($success) return 1;
return $error;
}
}

View File

@ -17,42 +17,72 @@
* 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
* @author Andreas Ek
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1.1
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1.1
**/
namespace psm\Txtmsg;
class Nexmo extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
public function sendSMS($message) {
$nexmo_url = "https://rest.nexmo.com/sms/json";
$nexmo_data = rawurlencode( $message );
foreach( $this->recipients as $phone ){
$result = file_get_contents( $nexmo_url .
"?api_key=" . $this->username .
"&api_secret=" . $this->password .
"&from=" . $this->originator .
"&to=" . $phone .
"&type=text" .
"&text=" . $nexmo_data
);
}
return $result;
}
/**
* Send sms using the GatewayAPI API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
* @Var string $recipient
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$success = 1;
$error = "";
$message = rawurlencode($message);
foreach($this->recipients as $recipient) {
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_URL, "https://rest.nexmo.com/sms/json?" . http_build_query(
array(
"api_key" => $this->username,
"api_secret" => $this->password,
"from" => $this->originator,
"to" => $recipient,
"text" => $message,
)
)
);
$result = json_decode(curl_exec($curl),true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_error($curl);
if($err = curl_errno($curl) || $httpcode != 200 || $result['messages'][0]['status'] != "0") {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". \nResult: ".$result['messages'][0]['error-text'];
}
curl_close($curl);
}
if($success) return 1;
return $error;
}
}

View File

@ -17,69 +17,75 @@
* 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
* @author Alexis Urien
* @copyright Copyright (c) 2016 Alexis Urien <alexis.urien@free.fr>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
* @package phpservermon
* @author Alexis Urien <Alexis.urien@free.fr>
* @Author Tim Zandbergen <Tim@Xervion.nl>
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2016 Alexis Urien <alexis.urien@free.fr>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/
namespace psm\Txtmsg;
class Octopush extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
/**
* Send sms using the Octopush API
* @var string $message
* @var string $this->username
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
*
* @var resource $curl
* @var SimpleXMLElement $xmlResults
* @var string $err
* @var string $recipient
* @var string $smsType
* @var string $result
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
$smsType = "XXX"; //FR = premium, WWW = world, XXX = Low cost
$recipients = join(',', $this->recipients);
$message = ($smsType == "FR") ? urlencode($message . " STOP au XXXX") : urlencode($message);
public function sendSMS($message) {
// Octopush exemple url
// french documentation can be found here: http://www.octopush-dm.com/public/docs/envoyer-des-sms-avec-octopush.pdf (need to be logged in)
//'http://www.octopush-dm.com/api/sms/?user_login=*****%40******.com&api_key=****************&sms_text=un+exemple+de+texte&sms_recipients=0033601010101&sms_type=FR&sms_sender=UnSender'
if(count($this->recipients) == 0)
return false;
$testMode = false;
$highPriority = true;
if ($highPriority) {
$sms_type = 'FR';
$sms_sender = 'phpServerMon';
$sms_more = ' STOP au XXXXX';
}
else {
$sms_type = 'XXX';
$sms_more = '';
}
$recipients = urlencode(implode(',', $this->recipients));
$octopush_url = "https://www.octopush-dm.com/api/sms/";
$octopush_data = urlencode( $message . $sms_more );
$URL = $octopush_url. "?" .
"user_login=" . $this->username .
"&api_key=" . $this->password .
"&sms_recipients=" . $recipients .
"&sms_type=" . $sms_type .
($testMode ? '&request_mode=simu' : '') .
(isset($sms_sender) ? '&sms_sender='.$sms_sender : '') .
"&sms_text=" . $octopush_data;
$result = file_get_contents( $URL );
$xmlResults = simplexml_load_string($result);
if ($xmlResults === false)
return false;
if ($xmlResults->error_code == '000')
return true;
return false;
}
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, "http://www.octopush-dm.com/api/sms/?" . http_build_query(
array(
"user_login" => $this->username,
"api_key" => $this->password,
"sms_recipients" => $recipients,
"sms_type" => $smsType,
"sms_sender" => substr($this->originator, 0, 11),
"sms_text" => $message,
)
)
);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$xmlResults = simplexml_load_string($result);
if($err = curl_errno($curl) || $httpcode != 200 || $xmlResults === false || $xmlResults->error_code != '000') {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". \nResult: ".$xmlResults->error_code.". Look at http://www.octopush-dm.com/en/errors for the error description.";
}
curl_close($curl);
if($success) return 1;
return $error;
}
}

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

@ -0,0 +1,92 @@
<?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
* @author Tim Zandbergen <Tim@Xervion.nl>
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.3.0
**/
namespace psm\Txtmsg;
class Plivo extends Core {
/**
* Send sms using the Plivo API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
* @var string $recipients
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
if(empty($this->recipients)) return false;
$recipients = join('<', $this->recipients);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.plivo.com/v1/Account/" . $this->username . "/Message/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode(
array(
"src" => $this->originator,
"dst" => $recipients,
"text" => urlencode($message)
)
),
CURLOPT_HTTPHEADER => array(
"authorization: Basic " . base64_encode($this->username . ":" . $this->password),
"content-type: application/json"
),
));
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($err = curl_errno($curl) || ($httpcode != '200' && $httpcode != '201' && $httpcode != '202')) {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result."";
}
curl_close($curl);
if($success) return 1;
return $error;
}
}

View File

@ -17,64 +17,75 @@
* 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
* @author Victor Macko
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1
**/
namespace psm\Txtmsg;
class Smsglobal extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
/**
* Send the SMS message
* @param string $message
* @return boolean (true = message was sent successfully, false = there was a problem sending the message)
*/
* Send sms using the Smsglobal API
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
*
* @var resource $curl
* @var string $err
* @var string $recipient
* @var string $from
* @var string $result
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
$recipients = join(',', $this->recipients);
if(count($recipients) == 0) {
return false;
$from = substr($this->originator,0 , 11); // Max 11 Characters
$message = substr(rawurlencode($message), 0, 153);
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_TIMEOUT, 30);
curl_setopt($curl,CURLOPT_URL, "https://www.smsglobal.com/http-api.php?" . http_build_query(
array(
"action" => "sendsms",
"user" => $this->username,
"password" => $this->password,
"from" => $from,
"to" => $recipients,
"clientcharset" => "ISO-8859-1",
"text" => $message,
)
));
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$result = curl_exec($curl);
$err = curl_error($curl);
if($err = curl_errno($curl) || substr($result, 0, 5) != "OK: 0") {
$success = 0;
$result = ($result == '') ? 'Wrong input, please check if all values are correct!' : $result;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". \nResult: ".$result;
}
/**
* Documentation is here: http://www.smsglobal.com/http-api/
* Recipient numbers should be in the MSIDSN format (eg. 61400111222). The '+' sign should not be included before the country code.
*/
$from = urlencode(substr($this->originator,0 , 11)); // Max 11 Char.
$url = 'http://www.smsglobal.com/http-api.php' .
'?action=sendsms' .
'&user=' . $this->username .
'&password=' . $this->password .
'&from=' . $from .
'&to=' . rawurlencode($recipients) .
'&clientcharset=ISO-8859-1' .
'&text=' . substr(rawurlencode($message), 0, 153);
$returnedData = file_get_contents($url);
$isOk = strpos($returnedData, 'OK: 0') !== false;
$this->success = $isOk;
$this->resultmessage = $returnedData;
if(!$isOk) {
error_log($this->resultmessage, E_USER_NOTICE);
}
return $isOk;
curl_close($curl);
if($success) return 1;
return $error;
}
}

View File

@ -17,55 +17,66 @@
* 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
* @author nerdalertdk
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.1
**/
namespace psm\Txtmsg;
class Smsit extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
public function sendSMS($message) {
// http://www.smsit.dk/api/sendSms.php?apiKey=[KEY]x&senderId=[SENDER]&mobile=[PHONENUMBER]&message=[MESSAGE]
// Use USERNAME as API KEY, password not needed
$apiurl = "http://www.smsit.dk/api/sendSms.php";
$msg = urlencode( $message );
$from = urlencode( substr($this->originator,0,11) ); // Max 11 Char.
foreach( $this->recipients as $phone ){
$URL = $apiurl."?apiKey=" . $this->username . "&mobile=" . $phone . "&message=" . $msg . "&senderId=" . $from;
$result = file_get_contents( $URL );
/**
* Send sms using the Smsit API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
*
* @var resource $curl
* @var string $err
* @var String $recipient
* @var string $result
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$success = 1;
$error = "":
foreach( $this->recipients as $recipient ){
/*
0 Everything went as it should
1 Invalid API key
2 Invalid sender name
3 Invalid character set (charset)
4 Invalid mobile number
5 There is not filled out a message
6 The message is too long (That was she said)
7 API-key does not exist
*/
if((int)$result == 0) {
$success = true;
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_URL, "https://www.smsit.dk/api/v2?" . http_build_query(
array(
"apiKey" => $this->password,
"mobile" => $recipient,
"message" => urlencode($message),
"senderId" => substr($this->originator,0,11),
)
)
);
$result = curl_exec($curl);
$err =curl_error($curl);
curl_close($curl);
if($err || is_numeric(strpos($result, "{\"errors\":[{\"code\":"))) {
$success = 0;
$error = $result;
}
}
return $result;
}
}
if($success) return 1;
return $error;
}
}

View File

@ -0,0 +1,83 @@
<?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
* @author Ward Pieters <ward@wardpieters.nl>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.3.0
**/
namespace psm\Txtmsg;
class SolutionsInfini extends Core {
/**
* Send sms using the SolutionsInfini API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var string $recipients
* @var array $this->originator (Max 11 characters)
*
* @var resource $curl
* @var string $err
* @var int $success
* @var string $error
*
* @return int or string
*/
public function sendSMS($message) {
$error = "";
$success = 1;
$message = urlencode($message);
$recipients = join(',', $this->recipients);
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, "https://api-alerts.solutionsinfini.com/v4/?" . http_build_query(
array(
"api_key" => $this->password,
"method" => "sms",
"to" => $recipients,
"sender" => substr($this->originator, 0, 11),
"message" => $message,
)
)
);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$result = json_decode(curl_exec($curl), true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($err = curl_errno($curl) || $httpcode != 200 || $result['status'] != "OK") {
$success = 0;
$error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result['status']." - ".$result['message'].".";
}
curl_close($curl);
if($success) return 1;
return $error;
}
}