Anope IRC Services  Version 2.0
modes.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 #include "utils.h"
10 
12 {
13 }
14 
16 {
17  const Anope::string &chname = message.get_data["channel"];
18  const Anope::string &mode = message.get_data["m"];
19  TemplateFileServer Page("chanserv/modes.html");
20 
21  BuildChanList(na, replacements);
22 
23  if (chname.empty())
24  {
25  Page.Serve(server, page_name, client, message, reply, replacements);
26  return true;
27  }
28 
29  replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname);
30  ChannelInfo *ci = ChannelInfo::Find(chname);
31 
32  if (!ci)
33  {
34  Page.Serve(server, page_name, client, message, reply, replacements);
35  return true;
36  }
37 
38  Channel *c = Channel::Find(chname);
39 
40  if (!c)
41  {
42  replacements["MESSAGES"] = Anope::printf(CHAN_X_NOT_IN_USE, chname.c_str());
43  Page.Serve(server, page_name, client, message, reply, replacements);
44  return true;
45  }
46 
47  AccessGroup u_access = ci->AccessFor(na->nc);
48  bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/administration");
49 
50  if (!u_access.HasPriv("MODE") && !has_priv)
51  {
52  replacements["MESSAGES"] = "Access denied.";
53  Page.Serve(server, page_name, client, message, reply, replacements);
54  return true;
55  }
56 
57  replacements["MODE"] = "YES";
58 
59  /* build a list with the names of all listmodes */
60  for (unsigned i = 0; i < ModeManager::GetChannelModes().size(); ++i)
61  {
63 
64  if (cm->type == MODE_LIST && cm->mchar)
65  replacements["LISTMODES"] = cm->mchar;
66  }
67 
68  if (mode.empty())
69  {
70  Page.Serve(server, page_name, client, message, reply, replacements);
71  return true;
72  }
73  replacements["ESCAPED_MODE"] = HTTPUtils::URLEncode(mode);
74 
76  if (cm)
77  {
78  if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
79  {
80  std::vector<Anope::string> params;
81  params.push_back(ci->name);
82  params.push_back("SET");
83  params.push_back("-" + Anope::string(cm->mchar));
84  params.push_back(message.get_data["mask"]);
85  WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements);
86  }
87  else if (message.post_data["mask"].empty() == false)
88  {
89  std::vector<Anope::string> params;
90  params.push_back(ci->name);
91  params.push_back("SET");
92  params.push_back("+" + Anope::string(cm->mchar));
93  params.push_back(message.post_data["mask"]);
94  WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements);
95  }
96 
97  std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> ml = c->GetModeList(cm->name);
98  for (; ml.first != ml.second; ++ml.first)
99  replacements["MASKS"] = HTTPUtils::Escape(ml.first->second);
100  }
101 
102  Page.Serve(server, page_name, client, message, reply, replacements);
103  return true;
104 }
105 
106 std::set<Anope::string> WebCPanel::ChanServ::Modes::GetData()
107 {
108  std::set<Anope::string> v;
109  v.insert("channel");
110  return v;
111 }
112 
Serialize::Reference< NickCore > nc
Definition: account.h:47
std::set< Anope::string > GetData() anope_override
Definition: modes.cpp:106
static const std::vector< ChannelMode * > & GetChannelModes()
Definition: modes.cpp:571
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
void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements)
Definition: utils.cpp:24
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
Modes(const Anope::string &cat, const Anope::string &u)
Definition: modes.cpp:11
Anope::string URLEncode(const Anope::string &url)
Definition: httpd.h:187
CoreExport string printf(const char *fmt,...)
Definition: misc.cpp:536
bool HasPriv(const Anope::string &priv) const
Definition: access.cpp:384
std::pair< ModeList::iterator, ModeList::iterator > GetModeList(const Anope::string &name)
Definition: channels.cpp:243
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
ModeType type
Definition: modes.h:49
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
char mchar
Definition: modes.h:47
static ChannelMode * FindChannelModeByChar(char mode)
Definition: modes.cpp:524
bool empty() const
Definition: anope.h:126
AccessGroup AccessFor(const User *u)
Definition: regchannel.cpp:413
std::map< Anope::string, Anope::string > post_data
Definition: httpd.h:81
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
const char * c_str() const
Definition: anope.h:117
std::map< Anope::string, Anope::string > get_data
Definition: httpd.h:80
bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override
Definition: modes.cpp:15
Anope::string name
Definition: modes.h:43