Anope IRC Services  Version 2.0
memos.cpp
Go to the documentation of this file.
1 /*
2  * (C) 2003-2014 Anope Team
3  * Contact us at team@anope.org
4  *
5  * Please read COPYING and README for further details.
6  */
7 
8 #include "../../webcpanel.h"
9 
11 {
12 }
13 
15 {
16  const Anope::string &chname = message.get_data["channel"];
17  ChannelInfo *ci;
18  const MemoInfo *mi;
19  Memo *m;
20 
21  for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
22  {
23  ci = it->second;
24 
25  if (ci->AccessFor(na->nc).HasPriv("MEMO"))
26  {
27  replacements["CHANNEL_NAMES"] = ci->name;
28  replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name);
29  }
30  }
31 
32  if (chname.empty())
33  {
34  replacements["MESSAGES"] = "No Channel specified, displaying the memos for your Nick";
35  mi = &na->nc->memos;
36  }
37  else
38  {
39  ci = ChannelInfo::Find(chname);
40  if (ci)
41  {
42  replacements["MESSAGES"] = "Displaying the memos for " + chname + ".";
43  mi = &ci->memos;
44  }
45  else
46  {
47  replacements["MESSAGES"] = "Channel " + chname + " not found, displaying the memos for your nick";
48  mi = &na->nc->memos;
49  }
50 
51  replacements["CHANNEL_NAME"] = ci->name;
52  replacements["ESCAPED_CHANNEL_NAME"] = HTTPUtils::URLEncode(ci->name);
53  }
54  if (message.post_data.count("receiver") > 0 && message.post_data.count("message") > 0)
55  {
56  std::vector<Anope::string> params;
57  params.push_back(HTTPUtils::URLDecode(message.post_data["receiver"]));
58  params.push_back(HTTPUtils::URLDecode(message.post_data["message"]));
59 
60  WebPanel::RunCommand(na->nc->display, na->nc, "MemoServ", "memoserv/send", params, replacements, "CMDR");
61  }
62  if (message.get_data.count("del") > 0 && message.get_data.count("number") > 0)
63  {
64  std::vector<Anope::string> params;
65  if (!chname.empty())
66  params.push_back(chname);
67  params.push_back(message.get_data["number"]);
68 
69  WebPanel::RunCommand(na->nc->display, na->nc, "MemoServ", "memoserv/del", params, replacements, "CMDR");
70  }
71  if (message.get_data.count("read") > 0 && message.get_data.count("number") > 0)
72  {
73  std::vector<Anope::string> params;
74  int number = -1;
75 
76  try
77  {
78  number = convertTo<int>(message.get_data["number"]);
79  }
80  catch (const ConvertException &ex)
81  {
82  replacements["MESSAGES"] = "ERROR - invalid parameter for NUMBER";
83  }
84 
85  if (number > 0)
86  {
87  m = mi->GetMemo(number-1);
88 
89  if (!m)
90  replacements["MESSAGES"] = "ERROR - invalid memo number.";
91  else if (message.get_data["read"] == "1")
92  m->unread = false;
93  else if (message.get_data["read"] == "2")
94  m->unread = true;
95  }
96  }
97 
98  for (unsigned i = 0; i < mi->memos->size(); ++i)
99  {
100  m = mi->GetMemo(i);
101  replacements["NUMBER"] = stringify(i+1);
102  replacements["SENDER"] = m->sender;
103  replacements["TIME"] = Anope::strftime(m->time);
104  replacements["TEXT"] = HTTPUtils::Escape(m->text);
105  if (m->unread)
106  replacements["UNREAD"] = "YES";
107  else
108  replacements["UNREAD"] = "NO";
109  }
110 
111  TemplateFileServer page("memoserv/memos.html");
112  page.Serve(server, page_name, client, message, reply, replacements);
113  return true;
114 }
115 
Serialize::Reference< NickCore > nc
Definition: account.h:47
void Serve(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, Replacements &)
Definition: hashcomp.h:84
Anope::string Escape(const Anope::string &src)
Definition: httpd.h:206
Anope::string name
Definition: regchannel.h:63
Anope::string text
Definition: memo.h:34
Anope::string URLEncode(const Anope::string &url)
Definition: httpd.h:187
Anope::string sender
Definition: memo.h:33
bool HasPriv(const Anope::string &priv) const
Definition: access.cpp:384
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override
Definition: memos.cpp:14
Definition: memo.h:40
CoreExport Serialize::Checker< registered_channel_map > RegisteredChannelList
Definition: memo.h:19
void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector< Anope::string > &params, TemplateFileServer::Replacements &r, const Anope::string &key)
Definition: webcpanel.cpp:234
Memos(const Anope::string &cat, const Anope::string &u)
Definition: memos.cpp:10
Memo * GetMemo(unsigned index) const
Definition: memos.cpp:82
bool empty() const
Definition: anope.h:126
MemoInfo memos
Definition: regchannel.h:77
AccessGroup AccessFor(const User *u)
Definition: regchannel.cpp:413
Anope::string stringify(const T &x)
Definition: anope.h:710
std::map< Anope::string, Anope::string > post_data
Definition: httpd.h:81
Serialize::Checker< std::vector< Memo * > > memos
Definition: memo.h:43
time_t time
Definition: memo.h:32
Anope::string URLDecode(const Anope::string &url)
Definition: httpd.h:163
std::map< Anope::string, Anope::string > get_data
Definition: httpd.h:80
CoreExport Anope::string strftime(time_t t, const NickCore *nc=NULL, bool short_output=false)
Definition: misc.cpp:356
bool unread
Definition: memo.h:22