DTux
/
dtux__moha
Archived
1
0
Fork 0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__moha/hooks/notifiers/notificationfreemobile.php

71 lines
1.9 KiB
PHP

<?php
class notificationFreemobile
{
private $url = "https://smsapi.free-mobile.fr/sendmsg?user=";
private $name = "freemobile";
public $active = true;
public $level;
public $curlErr;
public $lastTry;
public $lastTryTimeout = 5;
protected $dest = array(
"Daniel" => "32886706&pass=JTGUY6l5OG73zX",
);
function __construct()
{
$this->level = ALERT | ERROR;
}
function send($message, $destinataire=NOTIF_DEFAULT_DEST)
{
logger(DEBUG, _("Function send SMS (with Curl)"), __FILE__ . ":" . __LINE__);
$error = false;
if ($this->active === true)
{
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire] . "&msg=" . urlencode(trim($message)));
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $result contains the output string
if ($this->curlErr <= 5)
{
logger(DEBUG, _("Curl sending message"), __FILE__ . ":" . __LINE__);
echo $this->url . urlencode(trim($message)) . EOL;
curl_exec($ch);
if (curl_errno($ch) != 0)
{
$this->curlErr += 1;
$this->lastTry = time();
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), __FILE__ . ":" . __LINE__);
$error = true;
}else
{
logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), curl_error($ch)), __FILE__ . ":" . __LINE__);
$this->curlErr = 0;
}
}else
{
if ((time() - $this->lastTry) > ($this->lastTryTimeout*60))
{
$this->curlErr -= 1;
}
$error = true;
}
//TODO managing curl errors
// close curl resource to free up system resources
curl_close($ch);
}
return $error;
}
}
// constant definition
define("NOTIF_DEFAULT_DEST", "daniel");
//init class
$notificationMethods["freemobile"] = new notificationFreemobile();
?>