From 769fb80c48557fcbc13e7990b40af4dd1d45d995 Mon Sep 17 00:00:00 2001 From: shodan Date: Thu, 13 Aug 2015 11:40:18 +0200 Subject: [PATCH] Add Pushjet support --- README.md | 7 +++- push.cpp | 113 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 76 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 7dd9b32..de3a4e4 100755 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ conditions. ZNC Push current supports the following services: * [Faast][] * [Nexmo][] * [Pushalot][] +* [Pushjet][] * Custom URL GET requests 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` * `airgram` * `nexmo` + * `pushjet` * `url` * `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. - 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 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: ` ` 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: ` ` @@ -525,6 +527,7 @@ from me and not from my employer. See the `LICENSE` file for details. [Faast]: http://faast.io/ [Nexmo]: https://www.nexmo.com [Pushalot]: https://pushalot.com/ +[Pushjet]: http://pushjet.io [faq]: https://github.com/jreese/znc-push/blob/master/doc/faq.md [examples]: https://github.com/jreese/znc-push/blob/master/doc/examples.md diff --git a/push.cpp b/push.cpp index 242bf6d..f2697bd 100755 --- a/push.cpp +++ b/push.cpp @@ -295,14 +295,14 @@ class CPushMod : public CModule { params["device_iden"] = options["target"]; } - + if (message_uri == "") { params["type"] = "note"; } else { params["type"] = "link"; params["url"] = message_uri; - } + } params["title"] = message_title; params["body"] = message_content; } @@ -414,30 +414,30 @@ class CPushMod : public CModule else if (service == "pushalot") { - if (options["secret"] == "") - { + if (options["secret"] == "") + { PutModule("Error: secret (authorization token) not set"); return; - } + } - service_host = "pushalot.com"; - service_url = "/api/sendmessage"; + service_host = "pushalot.com"; + service_url = "/api/sendmessage"; - params["AuthorizationToken"] = options["secret"]; - params["Title"] = message_title; - params["Body"] = message_content; + params["AuthorizationToken"] = options["secret"]; + params["Title"] = message_title; + params["Body"] = message_content; - if (message_uri != "") - { + if (message_uri != "") + { params["Link"] = message_uri; - } + } - if ( options["message_uri_title"] != "" ) - { + if ( options["message_uri_title"] != "" ) + { params["LinkTitle"] = options["message_uri_title"]; - } + } } - + else if (service == "prowl") { if (options["secret"] == "") @@ -505,29 +505,29 @@ class CPushMod : public CModule { if (options["username"] == "") { - PutModule("Error: username (api key) not set"); - return; + PutModule("Error: username (api key) not set"); + return; } if (options["secret"] == "") { - PutModule("Error: secret (api secret) not set"); - return; + PutModule("Error: secret (api secret) not set"); + return; } if (options["target"] == "") { - PutModule("Error: destination mobile number (in international format) not set"); - return; + PutModule("Error: destination mobile number (in international format) not set"); + return; } - + service_host = "rest.nexmo.com"; service_url = "/sms/json"; - + params["api_secret"] = options["secret"]; params["api_key"] = options["username"]; params["from"] = message_title; params["to"] = options["target"]; params["text"] = message_content; - + } else if (service == "url") { @@ -651,25 +651,50 @@ class CPushMod : public CModule 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 { PutModule("Error: service type not selected"); return; } - PutDebug("service: " + service); - PutDebug("service_host: " + service_host); - PutDebug("service_url: " + service_url); - PutDebug("service_auth: " + service_auth); - PutDebug("use_port: " + CString(use_port)); - PutDebug("use_ssl: " + CString(use_ssl ? 1 : 0)); - PutDebug("use_post: " + CString(use_post ? 1 : 0)); + PutDebug("service: " + service); + PutDebug("service_host: " + service_host); + PutDebug("service_url: " + service_url); + PutDebug("service_auth: " + service_auth); + PutDebug("use_port: " + CString(use_port)); + PutDebug("use_ssl: " + CString(use_ssl ? 1 : 0)); + PutDebug("use_post: " + CString(use_post ? 1 : 0)); #ifdef USE_CURL - 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"); + 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"); #else - PutDebug("NOT using libcurl"); + PutDebug("NOT using libcurl"); // Create the socket connection, write to it, and add it to the queue CPushSocket *sock = new CPushSocket(this); sock->Connect(service_host, use_port, use_ssl); @@ -885,7 +910,7 @@ class CPushMod : public CModule return false; } - + /** * Determine if the given context matches any context rules. * @@ -925,7 +950,7 @@ class CPushMod : public CModule return false; } - + /** * Check if the idle condition is met. @@ -1004,7 +1029,7 @@ class CPushMod : public CModule return true; } - + /** * Check if the network_blacklist condition is met. * @@ -1353,9 +1378,9 @@ class CPushMod : public CModule } 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") { 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)"); } + else if (value == "pushjet") + { + PutModule("Note: Pushjet requires setting 'secret' (service key) option"); + } else { PutModule("Error: unknown service name"); @@ -1626,7 +1655,7 @@ class CPushMod : public CModule table.AddRow(); table.SetCell("Condition", "idle"); table.SetCell("Status", CString(ago) + " seconds"); - + table.AddRow(); table.SetCell("Condition", "network_blacklist"); // network_blacklist() is True if the network is not in a blacklist