mirror of https://github.com/SeanOMik/znc-push.git
Add Pushjet support
This commit is contained in:
parent
878af545ac
commit
769fb80c48
|
@ -22,6 +22,7 @@ conditions. ZNC Push current supports the following services:
|
||||||
* [Faast][]
|
* [Faast][]
|
||||||
* [Nexmo][]
|
* [Nexmo][]
|
||||||
* [Pushalot][]
|
* [Pushalot][]
|
||||||
|
* [Pushjet][]
|
||||||
* Custom URL GET requests
|
* Custom URL GET requests
|
||||||
|
|
||||||
This project is still a Work In Progress, but should be functional enough and stable enough
|
This project is still a Work In Progress, but should be functional enough and stable enough
|
||||||
|
@ -241,6 +242,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
|
||||||
* `pushbullet`
|
* `pushbullet`
|
||||||
* `airgram`
|
* `airgram`
|
||||||
* `nexmo`
|
* `nexmo`
|
||||||
|
* `pushjet`
|
||||||
* `url`
|
* `url`
|
||||||
|
|
||||||
* `username` Default: ` `
|
* `username` Default: ` `
|
||||||
|
@ -256,7 +258,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
|
||||||
|
|
||||||
Authentication token for push notifications.
|
Authentication token for push notifications.
|
||||||
|
|
||||||
This option must be set when using Notify My Android, Pushover, Prowl, Supertoasty, Airgram authenticated services, PushBullet, or Nexmo.
|
This option must be set when using Notify My Android, Pushover, Prowl, Supertoasty, Airgram authenticated services, PushBullet, Nexmo or Pushjet.
|
||||||
|
|
||||||
When using the custom URL service, if this option is set it will enable HTTP basic
|
When using the custom URL service, if this option is set it will enable HTTP basic
|
||||||
authentication and be used as password.
|
authentication and be used as password.
|
||||||
|
@ -318,7 +320,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
|
||||||
* `message_priority` Default: ` `
|
* `message_priority` Default: ` `
|
||||||
|
|
||||||
Priority level that will be used for the push notification.
|
Priority level that will be used for the push notification.
|
||||||
Currently supported only by Pushover.net and Notify My Android.
|
Currently supported only by Pushover.net, Notify My Android and Pushjet.
|
||||||
|
|
||||||
* `message_sound` Default: ` `
|
* `message_sound` Default: ` `
|
||||||
|
|
||||||
|
@ -525,6 +527,7 @@ from me and not from my employer. See the `LICENSE` file for details.
|
||||||
[Faast]: http://faast.io/
|
[Faast]: http://faast.io/
|
||||||
[Nexmo]: https://www.nexmo.com
|
[Nexmo]: https://www.nexmo.com
|
||||||
[Pushalot]: https://pushalot.com/
|
[Pushalot]: https://pushalot.com/
|
||||||
|
[Pushjet]: http://pushjet.io
|
||||||
|
|
||||||
[faq]: https://github.com/jreese/znc-push/blob/master/doc/faq.md
|
[faq]: https://github.com/jreese/znc-push/blob/master/doc/faq.md
|
||||||
[examples]: https://github.com/jreese/znc-push/blob/master/doc/examples.md
|
[examples]: https://github.com/jreese/znc-push/blob/master/doc/examples.md
|
||||||
|
|
113
push.cpp
113
push.cpp
|
@ -295,14 +295,14 @@ class CPushMod : public CModule
|
||||||
{
|
{
|
||||||
params["device_iden"] = options["target"];
|
params["device_iden"] = options["target"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message_uri == "")
|
if (message_uri == "")
|
||||||
{
|
{
|
||||||
params["type"] = "note";
|
params["type"] = "note";
|
||||||
} else {
|
} else {
|
||||||
params["type"] = "link";
|
params["type"] = "link";
|
||||||
params["url"] = message_uri;
|
params["url"] = message_uri;
|
||||||
}
|
}
|
||||||
params["title"] = message_title;
|
params["title"] = message_title;
|
||||||
params["body"] = message_content;
|
params["body"] = message_content;
|
||||||
}
|
}
|
||||||
|
@ -414,30 +414,30 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
else if (service == "pushalot")
|
else if (service == "pushalot")
|
||||||
{
|
{
|
||||||
if (options["secret"] == "")
|
if (options["secret"] == "")
|
||||||
{
|
{
|
||||||
PutModule("Error: secret (authorization token) not set");
|
PutModule("Error: secret (authorization token) not set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
service_host = "pushalot.com";
|
service_host = "pushalot.com";
|
||||||
service_url = "/api/sendmessage";
|
service_url = "/api/sendmessage";
|
||||||
|
|
||||||
params["AuthorizationToken"] = options["secret"];
|
params["AuthorizationToken"] = options["secret"];
|
||||||
params["Title"] = message_title;
|
params["Title"] = message_title;
|
||||||
params["Body"] = message_content;
|
params["Body"] = message_content;
|
||||||
|
|
||||||
if (message_uri != "")
|
if (message_uri != "")
|
||||||
{
|
{
|
||||||
params["Link"] = message_uri;
|
params["Link"] = message_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( options["message_uri_title"] != "" )
|
if ( options["message_uri_title"] != "" )
|
||||||
{
|
{
|
||||||
params["LinkTitle"] = options["message_uri_title"];
|
params["LinkTitle"] = options["message_uri_title"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (service == "prowl")
|
else if (service == "prowl")
|
||||||
{
|
{
|
||||||
if (options["secret"] == "")
|
if (options["secret"] == "")
|
||||||
|
@ -505,29 +505,29 @@ class CPushMod : public CModule
|
||||||
{
|
{
|
||||||
if (options["username"] == "")
|
if (options["username"] == "")
|
||||||
{
|
{
|
||||||
PutModule("Error: username (api key) not set");
|
PutModule("Error: username (api key) not set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (options["secret"] == "")
|
if (options["secret"] == "")
|
||||||
{
|
{
|
||||||
PutModule("Error: secret (api secret) not set");
|
PutModule("Error: secret (api secret) not set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (options["target"] == "")
|
if (options["target"] == "")
|
||||||
{
|
{
|
||||||
PutModule("Error: destination mobile number (in international format) not set");
|
PutModule("Error: destination mobile number (in international format) not set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
service_host = "rest.nexmo.com";
|
service_host = "rest.nexmo.com";
|
||||||
service_url = "/sms/json";
|
service_url = "/sms/json";
|
||||||
|
|
||||||
params["api_secret"] = options["secret"];
|
params["api_secret"] = options["secret"];
|
||||||
params["api_key"] = options["username"];
|
params["api_key"] = options["username"];
|
||||||
params["from"] = message_title;
|
params["from"] = message_title;
|
||||||
params["to"] = options["target"];
|
params["to"] = options["target"];
|
||||||
params["text"] = message_content;
|
params["text"] = message_content;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (service == "url")
|
else if (service == "url")
|
||||||
{
|
{
|
||||||
|
@ -651,25 +651,50 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
PutDebug("payload: " + params["payload"]);
|
PutDebug("payload: " + params["payload"]);
|
||||||
}
|
}
|
||||||
|
else if (service == "pushjet")
|
||||||
|
{
|
||||||
|
if (options["secret"] == "")
|
||||||
|
{
|
||||||
|
PutModule("Error: secret (service key) not set");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
service_host = "api.pushjet.io";
|
||||||
|
service_url = "/message";
|
||||||
|
|
||||||
|
params["secret"] = options["secret"];
|
||||||
|
params["title"] = message_title;
|
||||||
|
params["message"] = message_content;
|
||||||
|
|
||||||
|
if (message_uri != "")
|
||||||
|
{
|
||||||
|
params["link"] = message_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options["message_priority"] != "")
|
||||||
|
{
|
||||||
|
params["level"] = options["message_priority"];
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PutModule("Error: service type not selected");
|
PutModule("Error: service type not selected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PutDebug("service: " + service);
|
PutDebug("service: " + service);
|
||||||
PutDebug("service_host: " + service_host);
|
PutDebug("service_host: " + service_host);
|
||||||
PutDebug("service_url: " + service_url);
|
PutDebug("service_url: " + service_url);
|
||||||
PutDebug("service_auth: " + service_auth);
|
PutDebug("service_auth: " + service_auth);
|
||||||
PutDebug("use_port: " + CString(use_port));
|
PutDebug("use_port: " + CString(use_port));
|
||||||
PutDebug("use_ssl: " + CString(use_ssl ? 1 : 0));
|
PutDebug("use_ssl: " + CString(use_ssl ? 1 : 0));
|
||||||
PutDebug("use_post: " + CString(use_post ? 1 : 0));
|
PutDebug("use_post: " + CString(use_post ? 1 : 0));
|
||||||
|
|
||||||
#ifdef USE_CURL
|
#ifdef USE_CURL
|
||||||
PutDebug("using libcurl");
|
PutDebug("using libcurl");
|
||||||
make_curl_request(service_host, service_url, service_auth, params, use_port, use_ssl, use_post, options["proxy"], options["proxy_ssl_verify"] != "no", options["debug"] == "on");
|
make_curl_request(service_host, service_url, service_auth, params, use_port, use_ssl, use_post, options["proxy"], options["proxy_ssl_verify"] != "no", options["debug"] == "on");
|
||||||
#else
|
#else
|
||||||
PutDebug("NOT using libcurl");
|
PutDebug("NOT using libcurl");
|
||||||
// Create the socket connection, write to it, and add it to the queue
|
// Create the socket connection, write to it, and add it to the queue
|
||||||
CPushSocket *sock = new CPushSocket(this);
|
CPushSocket *sock = new CPushSocket(this);
|
||||||
sock->Connect(service_host, use_port, use_ssl);
|
sock->Connect(service_host, use_port, use_ssl);
|
||||||
|
@ -885,7 +910,7 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the given context matches any context rules.
|
* Determine if the given context matches any context rules.
|
||||||
*
|
*
|
||||||
|
@ -925,7 +950,7 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the idle condition is met.
|
* Check if the idle condition is met.
|
||||||
|
@ -1004,7 +1029,7 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the network_blacklist condition is met.
|
* Check if the network_blacklist condition is met.
|
||||||
*
|
*
|
||||||
|
@ -1353,9 +1378,9 @@ class CPushMod : public CModule
|
||||||
}
|
}
|
||||||
else if (value == "pushalot")
|
else if (value == "pushalot")
|
||||||
{
|
{
|
||||||
PutModule("Note: Pushalot requires setting the 'secret' (to user key) (to authorization token) option");
|
PutModule("Note: Pushalot requires setting the 'secret' (to user key) (to authorization token) option");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (value == "prowl")
|
else if (value == "prowl")
|
||||||
{
|
{
|
||||||
PutModule("Note: Prowl requires setting the 'secret' option");
|
PutModule("Note: Prowl requires setting the 'secret' option");
|
||||||
|
@ -1384,6 +1409,10 @@ class CPushMod : public CModule
|
||||||
{
|
{
|
||||||
PutModule("Note: Slack requires setting 'secret' (from webhook) and 'target' (channel or username), optional 'username' (bot name)");
|
PutModule("Note: Slack requires setting 'secret' (from webhook) and 'target' (channel or username), optional 'username' (bot name)");
|
||||||
}
|
}
|
||||||
|
else if (value == "pushjet")
|
||||||
|
{
|
||||||
|
PutModule("Note: Pushjet requires setting 'secret' (service key) option");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PutModule("Error: unknown service name");
|
PutModule("Error: unknown service name");
|
||||||
|
@ -1626,7 +1655,7 @@ class CPushMod : public CModule
|
||||||
table.AddRow();
|
table.AddRow();
|
||||||
table.SetCell("Condition", "idle");
|
table.SetCell("Condition", "idle");
|
||||||
table.SetCell("Status", CString(ago) + " seconds");
|
table.SetCell("Status", CString(ago) + " seconds");
|
||||||
|
|
||||||
table.AddRow();
|
table.AddRow();
|
||||||
table.SetCell("Condition", "network_blacklist");
|
table.SetCell("Condition", "network_blacklist");
|
||||||
// network_blacklist() is True if the network is not in a blacklist
|
// network_blacklist() is True if the network is not in a blacklist
|
||||||
|
|
Loading…
Reference in New Issue