Anope IRC Services  Version 2.0
set.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  bool can_set = false;
19  TemplateFileServer page("chanserv/set.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  ChannelInfo *ci = ChannelInfo::Find(chname);
30 
31  if (!ci)
32  {
33  page.Serve(server, page_name, client, message, reply, replacements);
34  return true;
35  }
36 
37  replacements["OKAY"];
38 
39  if (ci->AccessFor(na->nc).HasPriv("SET"))
40  {
41  replacements["CAN_SET"];
42  can_set = true;
43  }
44 
45  if (can_set && message.post_data.empty() == false)
46  {
47  if (ci->HasExt("KEEPTOPIC") != message.post_data.count("keeptopic"))
48  {
49  if (!ci->HasExt("KEEPTOPIC"))
50  ci->Extend<bool>("KEEPTOPIC");
51  else
52  ci->Shrink<bool>("KEEPTOPIC");
53  replacements["MESSAGES"] = "Secure updated";
54  }
55  if (ci->HasExt("PEACE") != message.post_data.count("peace"))
56  {
57  if (!ci->HasExt("PEACE"))
58  ci->Extend<bool>("PEACE");
59  else
60  ci->Shrink<bool>("PEACE");
61  replacements["MESSAGES"] = "Peace updated";
62  }
63  if (ci->HasExt("CS_PRIVATE") != message.post_data.count("private"))
64  {
65  if (!ci->HasExt("CS_PRIVATE"))
66  ci->Extend<bool>("CS_PRIVATE");
67  else
68  ci->Shrink<bool>("CS_PRIVATE");
69  replacements["MESSAGES"] = "Private updated";
70  }
71  if (ci->HasExt("RESTRICTED") != message.post_data.count("restricted"))
72  {
73  if (!ci->HasExt("RESTRICTED"))
74  ci->Extend<bool>("RESTRICTED");
75  else
76  ci->Shrink<bool>("RESTRICTED");
77  replacements["MESSAGES"] = "Restricted updated";
78  }
79  if (ci->HasExt("CS_SECURE") != message.post_data.count("secure"))
80  {
81  if (!ci->HasExt("CS_SECURE"))
82  ci->Extend<bool>("CS_SECURE");
83  else
84  ci->Shrink<bool>("CS_SECURE");
85  replacements["MESSAGES"] = "Secure updated";
86  }
87  if (ci->HasExt("SECUREOPS") != message.post_data.count("secureops"))
88  {
89  if (!ci->HasExt("SECUREOPS"))
90  ci->Extend<bool>("SECUREOPS");
91  else
92  ci->Shrink<bool>("SECUREOPS");
93  replacements["MESSAGES"] = "Secureops updated";
94  }
95  if (ci->HasExt("TOPICLOCK") != message.post_data.count("topiclock"))
96  {
97  if (!ci->HasExt("TOPICLOCK"))
98  ci->Extend<bool>("TOPICLOCK");
99  else
100  ci->Shrink<bool>("TOPICLOCK");
101  replacements["MESSAGES"] = "Topiclock updated";
102  }
103  }
104 
105  replacements["CHANNEL"] = HTTPUtils::Escape(ci->name);
106  replacements["CHANNEL_ESCAPED"] = HTTPUtils::URLEncode(ci->name);
107  if (ci->GetFounder())
108  replacements["FOUNDER"] = ci->GetFounder()->display;
109  if (ci->GetSuccessor())
110  replacements["SUCCESSOR"] = ci->GetSuccessor()->display;
111  replacements["TIME_REGISTERED"] = Anope::strftime(ci->time_registered, na->nc);
112  replacements["LAST_USED"] = Anope::strftime(ci->last_used, na->nc);
113  replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname);
114 
115  if (!ci->last_topic.empty())
116  {
117  replacements["LAST_TOPIC"] = HTTPUtils::Escape(ci->last_topic);
118  replacements["LAST_TOPIC_SETTER"] = HTTPUtils::Escape(ci->last_topic_setter);
119  }
120 
121  if (can_set)
122  {
123  if (ci->HasExt("KEEPTOPIC"))
124  replacements["KEEPTOPIC"];
125 
126  if (ci->HasExt("PEACE"))
127  replacements["PEACE"];
128 
129  if (ci->HasExt("CS_PRIVATE"))
130  replacements["PRIVATE"];
131 
132  if (ci->HasExt("RESTRICTED"))
133  replacements["RESTRICTED"];
134 
135  if (ci->HasExt("CS_SECURE"))
136  replacements["SECURE"];
137 
138  if (ci->HasExt("SECUREOPS"))
139  replacements["SECUREOPS"];
140 
141  if (ci->HasExt("TOPICLOCK"))
142  replacements["TOPICLOCK"];
143  }
144 
145  page.Serve(server, page_name, client, message, reply, replacements);
146  return true;
147 }
148 
149 std::set<Anope::string> WebCPanel::ChanServ::Set::GetData()
150 {
151  std::set<Anope::string> v;
152  v.insert("channel");
153  return v;
154 }
155 
Serialize::Reference< NickCore > nc
Definition: account.h:47
bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override
Definition: set.cpp:15
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
Set(const Anope::string &cat, const Anope::string &u)
Definition: set.cpp:11
Anope::string name
Definition: regchannel.h:63
void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements)
Definition: utils.cpp:24
Anope::string URLEncode(const Anope::string &url)
Definition: httpd.h:187
T * Extend(const Anope::string &name, const T &what)
Definition: extensible.h:224
NickCore * GetSuccessor() const
Definition: regchannel.cpp:378
bool HasPriv(const Anope::string &priv) const
Definition: access.cpp:384
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
NickCore * GetFounder() const
Definition: regchannel.cpp:364
void Shrink(const Anope::string &name)
Definition: extensible.h:253
time_t last_used
Definition: regchannel.h:67
Anope::string display
Definition: account.h:113
bool empty() const
Definition: anope.h:126
Anope::string last_topic_setter
Definition: regchannel.h:70
AccessGroup AccessFor(const User *u)
Definition: regchannel.cpp:413
std::map< Anope::string, Anope::string > post_data
Definition: httpd.h:81
Anope::string last_topic
Definition: regchannel.h:69
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
std::set< Anope::string > GetData() anope_override
Definition: set.cpp:149
bool HasExt(const Anope::string &name) const
Definition: extensible.cpp:31
time_t time_registered
Definition: regchannel.h:66