2021-12-31 23:09:58 +01:00
|
|
|
<?php
|
2022-01-02 13:47:41 +01:00
|
|
|
class notificationFreemobile
|
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
private $url = "https://smsapi.free-mobile.fr/sendmsg?user=";
|
2022-01-02 13:47:41 +01:00
|
|
|
private $name = "freemobile";
|
2022-01-02 18:14:13 +01:00
|
|
|
public $active = true;
|
|
|
|
public $level;
|
2022-07-10 19:33:19 +02:00
|
|
|
public $curlErr;
|
|
|
|
public $lastTry;
|
|
|
|
public $lastTryTimeout = 5;
|
|
|
|
protected $dest = array(
|
2022-09-05 13:47:41 +02:00
|
|
|
"Daniel" => "15480189&pass=yVpPmCWmUl2HGp",
|
2022-03-28 00:40:34 +02:00
|
|
|
);
|
2022-01-02 13:47:41 +01:00
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
2022-01-23 09:46:06 +01:00
|
|
|
$this->level = ALERT | ERROR;
|
2022-01-02 13:47:41 +01:00
|
|
|
}
|
|
|
|
|
2022-04-23 02:00:52 +02:00
|
|
|
function send($message, $destinataire=NOTIF_DEFAULT_DEST)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
2022-09-09 16:53:19 +02:00
|
|
|
logger(DEBUG, _("Function send SMS (with Curl)"), __FILE__ . ":" . __LINE__);
|
2022-07-10 19:33:19 +02:00
|
|
|
$error = false;
|
2022-05-29 01:55:22 +02:00
|
|
|
if ($this->active === true)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
|
|
|
$ch = curl_init();
|
|
|
|
// set url
|
2022-04-23 02:00:52 +02:00
|
|
|
curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire] . "&msg=" . urlencode(trim($message)));
|
2022-08-02 23:25:59 +02:00
|
|
|
|
|
|
|
// return the transfer as a string
|
2022-09-05 13:47:41 +02:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
2022-01-03 21:11:52 +01:00
|
|
|
// $result contains the output string
|
2022-07-10 19:33:19 +02:00
|
|
|
if ($this->curlErr <= 5)
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
2022-08-12 10:41:55 +02:00
|
|
|
logger(DEBUG, _("Curl sending message"), __FILE__ . ":" . __LINE__);
|
2022-07-10 19:33:19 +02:00
|
|
|
echo $this->url . urlencode(trim($message)) . EOL;
|
|
|
|
curl_exec($ch);
|
|
|
|
if (curl_errno($ch) != 0)
|
2022-01-03 21:11:52 +01:00
|
|
|
{
|
2022-07-10 19:33:19 +02:00
|
|
|
$this->curlErr += 1;
|
|
|
|
$this->lastTry = time();
|
2022-08-12 10:41:55 +02:00
|
|
|
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), __FILE__ . ":" . __LINE__);
|
2022-07-10 19:33:19 +02:00
|
|
|
$error = true;
|
2022-03-28 00:40:34 +02:00
|
|
|
}else
|
2022-01-03 21:11:52 +01:00
|
|
|
{
|
2022-08-12 10:41:55 +02:00
|
|
|
logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), curl_error($ch)), __FILE__ . ":" . __LINE__);
|
2022-07-10 19:33:19 +02:00
|
|
|
$this->curlErr = 0;
|
2022-03-28 00:40:34 +02:00
|
|
|
}
|
2022-07-10 19:33:19 +02:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
if ((time() - $this->lastTry) > ($this->lastTryTimeout*60))
|
|
|
|
{
|
|
|
|
$this->curlErr -= 1;
|
|
|
|
}
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
//TODO managing curl errors
|
2022-01-02 13:47:41 +01:00
|
|
|
// close curl resource to free up system resources
|
|
|
|
curl_close($ch);
|
|
|
|
}
|
2022-07-10 19:33:19 +02:00
|
|
|
return $error;
|
2022-01-02 13:47:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 10:41:55 +02:00
|
|
|
// constant definition
|
|
|
|
define("NOTIF_DEFAULT_DEST", "daniel");
|
|
|
|
|
|
|
|
//init class
|
2022-01-02 18:14:13 +01:00
|
|
|
$notificationMethods["freemobile"] = new notificationFreemobile();
|
2022-01-02 13:47:41 +01:00
|
|
|
?>
|