From 74b97db66f7d021bfc781906aa854a5b4d776cfc Mon Sep 17 00:00:00 2001 From: Dylan Ysmal Date: Wed, 12 Aug 2020 21:26:28 +0200 Subject: [PATCH] Add Ysmal.fr SMS gateway (#906) --- src/includes/functions.inc.php | 2 + src/psm/Txtmsg/Ysmal.php | 92 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/psm/Txtmsg/Ysmal.php diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 73128915..59717599 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -794,6 +794,8 @@ namespace { case 'solutionsinfini': $sms = new \psm\Txtmsg\SolutionsInfini(); break; + case 'ysmal': + $sms = new \psm\Txtmsg\Ysmal(); case 'smsapi': $sms = new \psm\Txtmsg\SMSAPI(); break; diff --git a/src/psm/Txtmsg/Ysmal.php b/src/psm/Txtmsg/Ysmal.php new file mode 100644 index 00000000..3daf956e --- /dev/null +++ b/src/psm/Txtmsg/Ysmal.php @@ -0,0 +1,92 @@ +. + * + * @package phpservermon + * @author Perri Vardy-Mason + * @author Dylan Ysmal + * @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.5 + **/ + +namespace psm\Txtmsg; + +class Ysmal extends Core +{ + + /** + * Send sms using the Hermes SMS API on Ysmal.fr + * @var string $message + * @var array $this->recipients + * @var string $this->password + * + * @var mixed $result + * @var array $headers + * + * @var int $success + * @var string $error + * + * @return bool|string + */ + + public function sendSMS($message) + { + $success = 1; + $error = ''; + + foreach ($this->recipients as $recipient) { + $opts['http'] = [ + 'method' => 'POST', + 'header' => "Content-Type: application/x-www-form-urlencoded\r\n" . + 'User-Agent: PHPServerMonitor (+https://phpservermonitor.org)', + 'content' => http_build_query([ + 'key' => $this->password, + 'number' => $recipient, + 'message' => $message + ]), + 'ignore_errors' => true + ]; + + $api = 'https://sms-api.ysmal.fr/'; + $ctx = stream_context_create($opts); + $res = file_get_contents($api, false, $ctx); + + $json = json_decode($res, true); + if ($json === NULL) { + $success = 0; + $error = "($recipient) json_decode_error"; + break; + } + + if ($json['status'] !== 'success') { + $success = 0; + $error = "($recipient) $json[error]"; + break; + } + } + + if ($success) { + return 1; + } + return $error; + } +}