Initial commit, any command triggers HTTP POST

Currently the plugin waits for any command to be sent to *notifo, at
which point it triggers a canned HTTP request to a test URL.  This
canned request will be replaced soon with a proper, authenticated
request to the official Notifo service URL.
This commit is contained in:
John Reese 2011-01-10 22:33:13 -05:00
commit 80e0da5708
3 changed files with 77 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
notifo.so

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
notifo.so: notifo.cpp
znc-buildmod notifo.cpp

73
notifo.cpp Normal file
View File

@ -0,0 +1,73 @@
/**
* ZNC Notifo Module
*
* Allows the user to enter a Notifo user and API token, and sends
* channel highlights and personal messages to Notifo.
*
* Copyright (c) 2011 John Reese
* Licensed under the MIT license
*/
#define REQUIRESSL
#include "znc.h"
#include "Chan.h"
#include "User.h"
#include "Modules.h"
#if (!defined(VERSION_MAJOR) || !defined(VERSION_MINOR) || (VERSION_MAJOR == 0 && VERSION_MINOR < 72))
#error This module needs ZNC 0.072 or newer.
#endif
class CNotifoMod : public CModule
{
public:
MODCONSTRUCTOR(CNotifoMod) {}
virtual ~CNotifoMod() {}
virtual void OnModCommand(const CString& sCommand)
{
PutModule("Sending message...");
sendmessage("foo");
}
protected:
CString urlencode(const CString& str)
{
return str.Escape_n(CString::EASCII, CString::EURL);
}
void sendmessage(const CString& message)
{
CString crlf = "\r\n";
CString auth = "foo:bar";
CString post = "to=";
post += "&msg=" + urlencode(message);
post += "&label=" + urlencode(CString("ZNC"));
post += "&title=" + urlencode(CString("New Message"));
post += "&uri=";
CString headers = "POST /index.php HTTP/1.1" + crlf;
headers += "Host: notifo.leetcode.net" + crlf;
headers += "Content-Type: application/x-www-form-urlencoded" + crlf;
headers += "Content-Length: " + CString(post.length()) + crlf;
headers += "User-Agent: zncnotifo" + crlf;
headers += "Authorization: Basic " + auth.Base64Encode() + crlf;
headers += crlf;
headers += post + crlf;
CSocket *sock = new CSocket(this);
sock->Connect("notifo.leetcode.net", 443, true);
sock->Write(headers);
sock->Close(Csock::CLT_AFTERWRITE);
AddSocket(sock);
FILE *fh = fopen("/tmp/notifo.log", "a");
fputs(headers.c_str(), fh);
fclose(fh);
}
};
MODULEDEFS(CNotifoMod, "Send highlights and personal messages to a Notifo account")