diff --git a/README.rst b/README.rst index d72d8f95..832f23e3 100644 --- a/README.rst +++ b/README.rst @@ -61,6 +61,7 @@ The following SMS gateways are currently available: * Plivo - * Callr - * SMSAPI - +* OVH SMS PRO - diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index db077969..960c04ba 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -758,6 +758,9 @@ namespace { case 'octopush': $sms = new \psm\Txtmsg\Octopush(); break; + case 'ovhsms': + $sms = new \psm\Txtmsg\OVHsms(); + break; case 'smsgw': $sms = new \psm\Txtmsg\Smsgw(); break; diff --git a/src/psm/Txtmsg/OVHsms.php b/src/psm/Txtmsg/OVHsms.php new file mode 100644 index 00000000..709f9d19 --- /dev/null +++ b/src/psm/Txtmsg/OVHsms.php @@ -0,0 +1,101 @@ +. + * + * @package phpservermon + * @author Alexis Urien + * @Author Tim Zandbergen + * @author Ward Pieters + * @author Alexandre ZANELLI + * @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 3.5 + **/ + +namespace psm\Txtmsg; + +class OVHsms extends Core { + + /** + * Send sms using the OVH http2sms gateway + * Online documentation :https://docs.ovh.com/fr/sms/envoyer_des_sms_depuis_une_url_-_http2sms/ + * Ovh need Account and Login, then use format login@account in username field. + * + * @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 mixed $result + * + * @var int $success + * @var string $error + * + * @return bool|string + */ + + + public function sendSMS($message) { + $error = ""; + $success = 1; + + $account_login = explode('@',$this->username); + + $recipients = join(',', $this->recipients); + + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, "https://www.ovh.com/cgi-bin/sms/http2sms.cgi?".http_build_query( + array( + "account" => $account_login[1], + "login" => $account_login[0], + "password" => $this->password, + "from" => str_replace('+', '00', $this->originator), + "to" => $recipients, + "message" => $message, + "contentType" => "text/xml", + "noStop" => 1, + ) + ) + ); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($curl); + $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $xmlResults = simplexml_load_string($result); + $err = curl_errno($curl); + + if ($err != 0 || $httpcode != 200 || $xmlResults === false ||($xmlResults->status != '100' && $xmlResults->status != '101')) { + $success = 0; + $error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". \nResult: ".$xmlResults->status." \n".$xmlResults->Message; + } + curl_close($curl); + + if ($success) { + return 1; + } + return $error; + } +}