Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/web/lib/fog/system.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static function _versionCompare()
public function __construct()
{
self::_versionCompare();
define('FOG_VERSION', '1.5.10.1734');
define('FOG_VERSION', '1.5.10.1735');
define('FOG_SCHEMA', 273);
define('FOG_BCACHE_VER', 141);
define('FOG_CLIENT_VERSION', '0.13.0');
Expand Down
50 changes: 50 additions & 0 deletions packages/web/lib/plugins/ntfy/class/ntfy.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* The ntfy database and object definer
*
* PHP version 5
*
* @category Ntfy
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
/**
* The ntfy database and object definer
*
* @category Ntfy
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
class Ntfy extends FOGController
{
/**
* The ntfy table.
*
* @var string
*/
protected $databaseTable = 'ntfy';
/**
* The database fields and commonized items.
*
* @var array
*/
protected $databaseFields = array(
'id' => 'nID',
'serverURL' => 'nServerURL',
'topicEndpoint' => 'nTopicEndpoint',
'credentials' => 'nCredentials',
);
/**
* The required fields
*
* @var array
*/
protected $databaseFieldsRequired = array(
'serverURL',
'topicEndpoint',
);
}
24 changes: 24 additions & 0 deletions packages/web/lib/plugins/ntfy/class/ntfyexception.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Exception class for ntfy
*
* PHP Version 5
*
* @category NtfyException
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
/**
* Exception class for ntfy
*
* @category NtfyException
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
class NtfyException extends Exception
{
}
110 changes: 110 additions & 0 deletions packages/web/lib/plugins/ntfy/class/ntfyextends.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* The base class of ntfy elements
*
* Extends the ntfy elements into the event class.
*
* PHP version 5
*
* @category NtfyExtends
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/license/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
/**
* The base class of ntfy elements
*
* Extends the ntfy elements into the event class.
*
* @category NtfyExtends
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/license/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
abstract class NtfyExtends extends Event
{
/**
* The name
*
* @var string
*/
protected $name;
/**
* The description
*
* @var string
*/
protected $description;
/**
* The event loop
*
* @var mixed
*/
protected static $eventloop;
/**
* The elements to use
*
* @var mixed
*/
protected static $elements;
/**
* The short description
*
* @var mixed
*/
protected static $shortdesc;
/**
* The message
*
* @var mixed
*/
protected static $message;
/**
* The item is active
*
* @var bool
*/
public $active;
/**
* Initialize the class item
*
* @return void
*/
public function __construct()
{
parent::__construct();
self::$eventloop = function (&$Ntfy) {
self::getClass(
'NtfyHandler',
$Ntfy->get('serverURL'),
$Ntfy->get('topicEndpoint')
)->pushNote(
'',
sprintf(
'%s %s',
self::$elements['HostName'],
_(self::$shortdesc)
),
_(self::$message)
);
};
}
/**
* Perform action
*
* @param string $event the event to enact
* @param mixed $data the data
*
* @return void
*/
public function onEvent($event, $data)
{
self::$elements = $data;
array_map(
self::$eventloop,
(array)self::getClass('NtfyManager')->find()
);
}
}
143 changes: 143 additions & 0 deletions packages/web/lib/plugins/ntfy/class/ntfyhandler.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php
/**
* Ntfy handler
*
* PHP version 5
*
* @category NtfyHandler
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
/**
* Ntfy handler
*
* @category NtfyHandler
* @package FOGProject
* @author Tony Lam <tonylam5349@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
class NtfyHandler extends Ntfy
{
private $_curlCallback;
/**
* The associated link + endpoint to send curl request to
*
* @var string
*/
private $topicURL;
/**
* Ntfy constructor.
*
* @throws NtfyException
*/
public function __construct($serverURL, $topicEndpoint)
{
$this->topicURL = $serverURL . '/' . $topicEndpoint;
if (!function_exists('curl_init')) {
throw new NftyException(
'cURL library is not loaded.'
);
}
}
/**
* Push a note.
*
* @param string $recipient The recipient.
* @param string $title The note's title.
* @param string $body The note's message.
*
* @return object Response.
* @throws NtfyException
*/
public function pushNote(
$recipient,
$title,
$body = null
) {
$data = array();
NtfyHandler::_parseRecipient(
$recipient,
$data
);
$data['type'] = 'note';
$data['title'] = $title;
$data['body'] = $body;

return $this->_curlRequest(
$this->topicURL,
'POST',
$data
);
}
/**
* Add a callback function that will be invoked
* right before executing each cURL request.
*
* @param callable $callback The callback function.
*
* @return void
*/
public function addCurlCallback(callable $callback)
{
$this->_curlCallback = $callback;
}
/**
* Parse recipient.
*
* @param string $recipient Recipient string.
* @param array $data Data array to populate with
* the correct recipient parameter.
*
* @return void
*/
private static function _parseRecipient($recipient, array &$data)
{
if (!empty($recipient)) {
if (filter_var($recipient, FILTER_VALIDATE_EMAIL) !== false) {
$data[email] = $recipient;
} else {
if (substr($recipient, 0, 1) == "#") {
$data[channel_tag] = substr($recipient, 1);
} else {
$data[device_iden] = $recipient;
}
}
}
}
/**
* Send a request to a remote server using cURL.
*
* @param string $url URL to send the request to.
* @param string $method HTTP method.
* @param array $data Query data.
* @param bool $sendAsJSON Send the request as JSON.
* @param bool $auth Use the API key to authenticate
*
* @return object Response.
* @throws NtfyException
*/
private function _curlRequest(
$url,
$method,
$data = null,
$sendAsJSON = false,
$auth = true
) {
$data = self::$FOGURLRequests->process(
$url,
$method,
$data,
$sendAsJSON,
(
$auth ?
$this->_apiKey :
false
),
$this->_curlCallback
);
return json_decode($data[0]);
}
}
Loading