From 57f4c369e99b8f1a02449ad526e56f4ac798ea81 Mon Sep 17 00:00:00 2001
From: Ward Pieters <19374765+wardpieters@users.noreply.github.com>
Date: Tue, 29 May 2018 14:13:49 +0200
Subject: [PATCH] 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
---
README.rst | 4 +
docs/credits.rst | 9 +-
docs/intro.rst | 4 +
src/includes/functions.inc.php | 12 ++
src/psm/Txtmsg/Callr.php | 90 +++++++++++++++
src/psm/Txtmsg/FreeMobileSMS.php | 65 +++++++----
src/psm/Txtmsg/FreeVoipDeal.php | 83 +++++++++-----
src/psm/Txtmsg/GatewayAPI.php | 87 +++++++++++++++
src/psm/Txtmsg/Inetworx.php | 173 ++++++++++-------------------
src/psm/Txtmsg/Mosms.php | 85 +++++++++-----
src/psm/Txtmsg/Nexmo.php | 96 ++++++++++------
src/psm/Txtmsg/Octopush.php | 122 ++++++++++----------
src/psm/Txtmsg/Plivo.php | 92 +++++++++++++++
src/psm/Txtmsg/Smsglobal.php | 109 ++++++++++--------
src/psm/Txtmsg/Smsit.php | 99 +++++++++--------
src/psm/Txtmsg/SolutionsInfini.php | 83 ++++++++++++++
16 files changed, 840 insertions(+), 373 deletions(-)
create mode 100644 src/psm/Txtmsg/Callr.php
create mode 100644 src/psm/Txtmsg/GatewayAPI.php
create mode 100644 src/psm/Txtmsg/Plivo.php
create mode 100644 src/psm/Txtmsg/SolutionsInfini.php
diff --git a/README.rst b/README.rst
index 44c0c882..c93e1ef0 100755
--- a/README.rst
+++ b/README.rst
@@ -57,6 +57,10 @@ The following SMS gateways are currently available:
* FreeMobile (FR) -
* Twilio -
* CM Telecom -
+* GatewayAPI -
+* SolutionsInfini -
+* Plivo -
+* Callr -
diff --git a/docs/credits.rst b/docs/credits.rst
index 9cf67435..861d069d 100644
--- a/docs/credits.rst
+++ b/docs/credits.rst
@@ -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
diff --git a/docs/intro.rst b/docs/intro.rst
index 5c1e77ac..40c66a4e 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -61,6 +61,10 @@ The following SMS gateways are currently available:
* FreeMobile (FR) -
* Twilio -
* CM Telecom -
+* GatewayAPI -
+* SolutionsInfini -
+* Plivo -
+* Callr -
Please note: for these gateways you will need an account with sufficient credits.
diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php
index 0232df1f..7a3fb2b2 100644
--- a/src/includes/functions.inc.php
+++ b/src/includes/functions.inc.php
@@ -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
diff --git a/src/psm/Txtmsg/Callr.php b/src/psm/Txtmsg/Callr.php
new file mode 100644
index 00000000..d69da71b
--- /dev/null
+++ b/src/psm/Txtmsg/Callr.php
@@ -0,0 +1,90 @@
+.
+ *
+ * @package phpservermon
+ * @author Ward Pieters
+ * @author Tim Zandbergen
+ * @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/
+ * @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;
+ }
+}
diff --git a/src/psm/Txtmsg/FreeMobileSMS.php b/src/psm/Txtmsg/FreeMobileSMS.php
index 36eafb06..16acd9ff 100644
--- a/src/psm/Txtmsg/FreeMobileSMS.php
+++ b/src/psm/Txtmsg/FreeMobileSMS.php
@@ -18,7 +18,7 @@
* along with PHP Server Monitor. If not, see .
*
* @package phpservermon
- * @author Michiel van der Wulp
+ * @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@
@@ -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;
}
}
diff --git a/src/psm/Txtmsg/FreeVoipDeal.php b/src/psm/Txtmsg/FreeVoipDeal.php
index f05b77d4..c1b2d80d 100755
--- a/src/psm/Txtmsg/FreeVoipDeal.php
+++ b/src/psm/Txtmsg/FreeVoipDeal.php
@@ -17,38 +17,69 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author Michiel van der Wulp
- * @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/
+ * @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/
+ * @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;
}
}
diff --git a/src/psm/Txtmsg/GatewayAPI.php b/src/psm/Txtmsg/GatewayAPI.php
new file mode 100644
index 00000000..86a867c6
--- /dev/null
+++ b/src/psm/Txtmsg/GatewayAPI.php
@@ -0,0 +1,87 @@
+.
+ *
+ * @package phpservermon
+ * @author Ward Pieters
+ * @author Tim Zandbergen
+ * @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/
+ * @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;
+ }
+}
diff --git a/src/psm/Txtmsg/Inetworx.php b/src/psm/Txtmsg/Inetworx.php
index f9b9808e..18ee538f 100644
--- a/src/psm/Txtmsg/Inetworx.php
+++ b/src/psm/Txtmsg/Inetworx.php
@@ -17,129 +17,76 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author Pepijn Over
- * @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/
+ * @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 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
-
}
diff --git a/src/psm/Txtmsg/Mosms.php b/src/psm/Txtmsg/Mosms.php
index becaaf12..49861d46 100644
--- a/src/psm/Txtmsg/Mosms.php
+++ b/src/psm/Txtmsg/Mosms.php
@@ -17,40 +17,71 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author Andreas Ek
- * @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/
- * @since phpservermon 2.1
+ * @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/
+ * @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;
}
}
diff --git a/src/psm/Txtmsg/Nexmo.php b/src/psm/Txtmsg/Nexmo.php
index 9898b56f..b5f9eba2 100644
--- a/src/psm/Txtmsg/Nexmo.php
+++ b/src/psm/Txtmsg/Nexmo.php
@@ -17,42 +17,72 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author Andreas Ek
- * @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/
- * @since phpservermon 3.1.1
+ * @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/
+ * @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;
+ }
}
diff --git a/src/psm/Txtmsg/Octopush.php b/src/psm/Txtmsg/Octopush.php
index dd644dda..cdb5725e 100644
--- a/src/psm/Txtmsg/Octopush.php
+++ b/src/psm/Txtmsg/Octopush.php
@@ -17,69 +17,75 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author Alexis Urien
- * @copyright Copyright (c) 2016 Alexis Urien
- * @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
+ * @Author Tim Zandbergen
+ * @author Ward Pieters
+ * @copyright Copyright (c) 2016 Alexis Urien
+ * @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;
+ }
}
diff --git a/src/psm/Txtmsg/Plivo.php b/src/psm/Txtmsg/Plivo.php
new file mode 100644
index 00000000..5441ed8d
--- /dev/null
+++ b/src/psm/Txtmsg/Plivo.php
@@ -0,0 +1,92 @@
+.
+ *
+ * @package phpservermon
+ * @author Tim Zandbergen
+ * @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/
+ * @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;
+ }
+}
diff --git a/src/psm/Txtmsg/Smsglobal.php b/src/psm/Txtmsg/Smsglobal.php
index 6ae92df5..906950da 100644
--- a/src/psm/Txtmsg/Smsglobal.php
+++ b/src/psm/Txtmsg/Smsglobal.php
@@ -17,64 +17,75 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author Victor Macko
- * @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/
- * @since phpservermon 3.1
+ * @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/
+ * @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;
}
}
diff --git a/src/psm/Txtmsg/Smsit.php b/src/psm/Txtmsg/Smsit.php
index 99dd0d54..58b626c8 100644
--- a/src/psm/Txtmsg/Smsit.php
+++ b/src/psm/Txtmsg/Smsit.php
@@ -17,55 +17,66 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see .
*
- * @package phpservermon
- * @author nerdalertdk
- * @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/
- * @since phpservermon 3.1
+ * @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/
+ * @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;
+ }
}
diff --git a/src/psm/Txtmsg/SolutionsInfini.php b/src/psm/Txtmsg/SolutionsInfini.php
new file mode 100644
index 00000000..b4cb09a5
--- /dev/null
+++ b/src/psm/Txtmsg/SolutionsInfini.php
@@ -0,0 +1,83 @@
+.
+ *
+ * @package phpservermon
+ * @author Ward Pieters
+ * @author Tim Zandbergen
+ * @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/
+ * @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;
+ }
+}