mirror of https://github.com/SeanOMik/znc-push.git
parent
0af5679f1d
commit
4667fd52bc
60
push.cpp
60
push.cpp
|
@ -144,13 +144,6 @@ class CPushMod : public CModule
|
||||||
// Application name
|
// Application name
|
||||||
CString app;
|
CString app;
|
||||||
|
|
||||||
// BASIC auth string, needs to be encoded each time username/secret is changed
|
|
||||||
CString notifo_auth;
|
|
||||||
|
|
||||||
// Host and URL to send messages to
|
|
||||||
CString notifo_host;
|
|
||||||
CString notifo_url;
|
|
||||||
|
|
||||||
// Time last notification was sent for a given context
|
// Time last notification was sent for a given context
|
||||||
map <CString, unsigned int> last_notification_time;
|
map <CString, unsigned int> last_notification_time;
|
||||||
|
|
||||||
|
@ -176,9 +169,6 @@ class CPushMod : public CModule
|
||||||
app = "ZNC";
|
app = "ZNC";
|
||||||
|
|
||||||
idle_time = time(NULL);
|
idle_time = time(NULL);
|
||||||
notifo_auth = "";
|
|
||||||
notifo_host = "api.notifo.com";
|
|
||||||
notifo_url = "/v1/send_notification";
|
|
||||||
|
|
||||||
// Current user
|
// Current user
|
||||||
user = GetUser();
|
user = GetUser();
|
||||||
|
@ -229,16 +219,6 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
|
||||||
* Re-encode the authentication credentials.
|
|
||||||
*/
|
|
||||||
void authencode()
|
|
||||||
{
|
|
||||||
// BASIC auth, base64-encoded username:password
|
|
||||||
CString auth = options["username"] + CString(":") + options["secret"];
|
|
||||||
notifo_auth = auth.Base64Encode_n();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs string expansion on a set of keywords.
|
* Performs string expansion on a set of keywords.
|
||||||
* Given an initial string and a dictionary of string replacments,
|
* Given an initial string and a dictionary of string replacments,
|
||||||
|
@ -298,17 +278,41 @@ class CPushMod : public CModule
|
||||||
replace["{unixtime}"] = CString(time(NULL));
|
replace["{unixtime}"] = CString(time(NULL));
|
||||||
CString uri = expand(options["message_uri"], replace);
|
CString uri = expand(options["message_uri"], replace);
|
||||||
|
|
||||||
|
// Set up the connection profile
|
||||||
|
CString service = options["service"];
|
||||||
|
bool use_post = true;
|
||||||
|
int use_port = 443;
|
||||||
|
bool use_ssl = true;
|
||||||
|
CString service_host;
|
||||||
|
CString service_url;
|
||||||
|
CString service_auth;
|
||||||
MCString params;
|
MCString params;
|
||||||
|
|
||||||
|
if (service == "notifo")
|
||||||
|
{
|
||||||
|
service_host = "api.notifo.com";
|
||||||
|
service_url = "/v1/send_notification";
|
||||||
|
|
||||||
|
// BASIC auth, base64-encoded username:password
|
||||||
|
service_auth = options["username"] + CString(":") + options["secret"];
|
||||||
|
service_auth.Base64Encode();
|
||||||
|
|
||||||
params["to"] = options["username"];
|
params["to"] = options["username"];
|
||||||
params["msg"] = short_message;
|
params["msg"] = short_message;
|
||||||
params["label"] = app;
|
params["label"] = app;
|
||||||
params["title"] = title;
|
params["title"] = title;
|
||||||
params["uri"] = uri;
|
params["uri"] = uri;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PutModule("Error: service type not selected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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(notifo_host, 443, true);
|
sock->Connect(service_host, use_port, use_ssl);
|
||||||
sock->Request(true, notifo_host, notifo_url, params, notifo_auth);
|
sock->Request(use_post, service_host, service_url, params, service_auth);
|
||||||
AddSocket(sock);
|
AddSocket(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,8 +681,6 @@ class CPushMod : public CModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authencode();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,8 +905,6 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
options[option] = value;
|
options[option] = value;
|
||||||
SetNV(option, options[option]);
|
SetNV(option, options[option]);
|
||||||
|
|
||||||
authencode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// APPEND command
|
// APPEND command
|
||||||
|
@ -933,8 +933,6 @@ class CPushMod : public CModule
|
||||||
options[option] += " " + value;
|
options[option] += " " + value;
|
||||||
options[option].Trim();
|
options[option].Trim();
|
||||||
SetNV(option, options[option]);
|
SetNV(option, options[option]);
|
||||||
|
|
||||||
authencode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// PREPEND command
|
// PREPEND command
|
||||||
|
@ -963,8 +961,6 @@ class CPushMod : public CModule
|
||||||
options[option] = value + " " + options[option];
|
options[option] = value + " " + options[option];
|
||||||
options[option].Trim();
|
options[option].Trim();
|
||||||
SetNV(option, options[option]);
|
SetNV(option, options[option]);
|
||||||
|
|
||||||
authencode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// UNSET command
|
// UNSET command
|
||||||
|
@ -987,8 +983,6 @@ class CPushMod : public CModule
|
||||||
{
|
{
|
||||||
options[option] = defaults[option];
|
options[option] = defaults[option];
|
||||||
DelNV(option);
|
DelNV(option);
|
||||||
|
|
||||||
authencode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// GET command
|
// GET command
|
||||||
|
@ -1099,8 +1093,6 @@ class CPushMod : public CModule
|
||||||
SetNV(option, options[option]);
|
SetNV(option, options[option]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authencode();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue