Permalink
Browse files

Merge remote branch 'github-kylef/send_raw'

  • Loading branch information...
psychon committed Feb 22, 2011
2 parents 97d3906 + a93a586 commit f3f49e10929746511a60ab55b1e9133604e8fe44
Showing with 82 additions and 0 deletions.
  1. +39 −0 modules/extra/send_raw.cpp
  2. +43 −0 modules/extra/send_raw/tmpl/index.tmpl
View
@@ -25,6 +25,45 @@ class CSendRaw_Mod: public CModule {
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");
+ }
+
+ const map<CString,CUser*>& msUsers = CZNC::Get().GetUserMap();
+ for (map<CString,CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); ++it) {
+ CTemplate& l = Tmpl.AddRow("UserLoop");
+ l["Username"] = (*it->second).GetUserName();
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
virtual void OnModCommand(const CString& sLine) {
const CString sUser = sLine.Token(0);
const CString sDirection = sLine.Token(1);
@@ -0,0 +1,43 @@
+<? INC Header.tmpl ?>
+
+<form method="post" action="/mods/send_raw/">
+ <? INC _csrf_check.tmpl ?>
+
+ <div class="section">
+ <h3>Send a raw IRC line</h3>
+
+ <div class="sectionbg">
+ <div class="sectionbody">
+ <div class="subsection third">
+ <div class="inputlabel">User:</div>
+ <div><select name="user">
+ <? LOOP UserLoop?>
+ <option value="<? VAR Username ESC=HTML ?>"><? VAR Username ESC=HTML ?></option>
+ <? ENDLOOP ?>
+ </select></div>
+ </div>
+
+ <div class="subsection third">
+ <div class="inputlabel">Direction:</div>
+ <div>
+ <select name="direction">
+ <option value="in"<? IF direction_in ?> selected="yes"<? ENDIF ?>>in</option>
+ <option value="out"<? IF direction_out ?> selected="yes"<? ENDIF ?>>out</option>
+ </select>
+ </div>
+ </div>
+
+ <div class="subsection full">
+ <div class="inputlabel">Line:</div>
+ <div><input type="text" name="line" value="<? VAR line ?>" /></div>
+ </div>
+
+ <div class="subsection submitline">
+ <input type="submit" value="Send">
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+
+<? INC Footer.tmpl ?>

0 comments on commit f3f49e1

Please sign in to comment.