From d8b181718cebb3be1f72f4fe86d15461a42d791c Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Sun, 2 Jan 2011 00:34:22 +0000 Subject: [PATCH 1/2] send_raw: Add a web interface --- modules/extra/send_raw.cpp | 33 ++++++++++++++++++++++ modules/extra/send_raw/tmpl/index.tmpl | 39 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 modules/extra/send_raw/tmpl/index.tmpl diff --git a/modules/extra/send_raw.cpp b/modules/extra/send_raw.cpp index 4145ddde..6c3af533 100644 --- a/modules/extra/send_raw.cpp +++ b/modules/extra/send_raw.cpp @@ -25,6 +25,39 @@ public: return true; } + virtual CString GetWebMenuTitle() { return "Send Raw"; } + virtual bool WebRequiresAdmin() { return true; } + + virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) { + if (sPageName == "index") { + if (WebSock.IsPost()) { + CUser *pUser = CZNC::Get().FindUser(WebSock.GetParam("user")); + bool bOutgoing = WebSock.GetParam("direction") == "out"; + const CString sLine = WebSock.GetParam("line"); + + if (!pUser) { + Tmpl["user"] = WebSock.GetParam("user"); + Tmpl[bOutgoing ? "direction_out" : "direction_in"] = "true"; + Tmpl["line"] = sLine; + WebSock.GetSession()->AddError("User not found"); + return true; + } + + if (bOutgoing) { + pUser->PutIRC(sLine); + } else { + pUser->PutUser(sLine); + } + + WebSock.GetSession()->AddSuccess("Line sent"); + } + + return true; + } + + return false; + } + virtual void OnModCommand(const CString& sLine) { const CString sUser = sLine.Token(0); const CString sDirection = sLine.Token(1); diff --git a/modules/extra/send_raw/tmpl/index.tmpl b/modules/extra/send_raw/tmpl/index.tmpl new file mode 100644 index 00000000..c8ee0a8f --- /dev/null +++ b/modules/extra/send_raw/tmpl/index.tmpl @@ -0,0 +1,39 @@ + + +
+ + +
+

Send a raw IRC line

+ +
+
+
+
User:
+
+
+ +
+
Direction:
+
+ +
+
+ +
+
Line:
+
+
+ +
+ +
+
+
+
+
+ + From a93a586f53de9aecdd79eac58df963758a95530b Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Tue, 22 Feb 2011 16:06:43 +0000 Subject: [PATCH 2/2] Show a list of users in the send_raw web interface --- modules/extra/send_raw.cpp | 6 ++++++ modules/extra/send_raw/tmpl/index.tmpl | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/extra/send_raw.cpp b/modules/extra/send_raw.cpp index 6c3af533..342f1a84 100644 --- a/modules/extra/send_raw.cpp +++ b/modules/extra/send_raw.cpp @@ -52,6 +52,12 @@ public: WebSock.GetSession()->AddSuccess("Line sent"); } + const map& msUsers = CZNC::Get().GetUserMap(); + for (map::const_iterator it = msUsers.begin(); it != msUsers.end(); ++it) { + CTemplate& l = Tmpl.AddRow("UserLoop"); + l["Username"] = (*it->second).GetUserName(); + } + return true; } diff --git a/modules/extra/send_raw/tmpl/index.tmpl b/modules/extra/send_raw/tmpl/index.tmpl index c8ee0a8f..a5b833e0 100644 --- a/modules/extra/send_raw/tmpl/index.tmpl +++ b/modules/extra/send_raw/tmpl/index.tmpl @@ -10,7 +10,11 @@
User:
-
+