Anope IRC Services  Version 2.0
info.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  if (message.post_data.empty() == false)
17  {
18  if (message.post_data.count("email") > 0)
19  {
20  if (message.post_data["email"] != na->nc->email)
21  {
22  if (!message.post_data["email"].empty() && !Mail::Validate(message.post_data["email"]))
23  replacements["ERRORS"] = "Invalid email";
24  else
25  {
26  na->nc->email = message.post_data["email"];
27  replacements["MESSAGES"] = "Email updated";
28  }
29  }
30  }
31  if (message.post_data.count("greet") > 0)
32  {
33  Anope::string *greet = na->nc->GetExt<Anope::string>("greet");
34  const Anope::string &post_greet = HTTPUtils::URLDecode(message.post_data["greet"].replace_all_cs("+", " "));
35 
36  if (post_greet.empty())
37  na->nc->Shrink<Anope::string>("greet");
38  else if (!greet || post_greet != *greet)
39  na->nc->Extend<Anope::string>("greet", post_greet);
40 
41  replacements["MESSAGES"] = "Greet updated";
42  }
43  if (na->nc->HasExt("AUTOOP") != message.post_data.count("autoop"))
44  {
45  if (!na->nc->HasExt("AUTOOP"))
46  na->nc->Extend<bool>("AUTOOP");
47  else
48  na->nc->Shrink<bool>("AUTOOP");
49  replacements["MESSAGES"] = "Autoop updated";
50  }
51  if (na->nc->HasExt("NS_PRIVATE") != message.post_data.count("private"))
52  {
53  if (!na->nc->HasExt("NS_PRIVATE"))
54  na->nc->Extend<bool>("NS_PRIVATE");
55  else
56  na->nc->Shrink<bool>("NS_PRIVATE");
57  replacements["MESSAGES"] = "Private updated";
58  }
59  if (na->nc->HasExt("NS_SECURE") != message.post_data.count("secure"))
60  {
61  if (!na->nc->HasExt("NS_SECURE"))
62  na->nc->Extend<bool>("NS_SECURE");
63  else
64  na->nc->Shrink<bool>("NS_SECURE");
65  replacements["MESSAGES"] = "Secure updated";
66  }
67  if (message.post_data["kill"] == "on" && !na->nc->HasExt("KILLPROTECT"))
68  {
69  na->nc->Extend<bool>("KILLPROTECT");
70  na->nc->Shrink<bool>("KILL_QUICK");
71  replacements["MESSAGES"] = "Kill updated";
72  }
73  else if (message.post_data["kill"] == "quick" && !na->nc->HasExt("KILL_QUICK"))
74  {
75  na->nc->Shrink<bool>("KILLPROTECT");
76  na->nc->Extend<bool>("KILL_QUICK");
77  replacements["MESSAGES"] = "Kill updated";
78  }
79  else if (message.post_data["kill"] == "off" && (na->nc->HasExt("KILLPROTECT") || na->nc->HasExt("KILL_QUICK")))
80  {
81  na->nc->Shrink<bool>("KILLPROTECT");
82  na->nc->Shrink<bool>("KILL_QUICK");
83  replacements["MESSAGES"] = "Kill updated";
84  }
85  }
86 
87  replacements["DISPLAY"] = HTTPUtils::Escape(na->nc->display);
88  if (na->nc->email.empty() == false)
89  replacements["EMAIL"] = HTTPUtils::Escape(na->nc->email);
90  replacements["TIME_REGISTERED"] = Anope::strftime(na->time_registered, na->nc);
91  if (na->HasVhost())
92  {
93  if (na->GetVhostIdent().empty() == false)
94  replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
95  else
96  replacements["VHOST"] = na->GetVhostHost();
97  }
98  Anope::string *greet = na->nc->GetExt<Anope::string>("greet");
99  if (greet)
100  replacements["GREET"] = HTTPUtils::Escape(*greet);
101  if (na->nc->HasExt("AUTOOP"))
102  replacements["AUTOOP"];
103  if (na->nc->HasExt("NS_PRIVATE"))
104  replacements["PRIVATE"];
105  if (na->nc->HasExt("NS_SECURE"))
106  replacements["SECURE"];
107  if (na->nc->HasExt("KILLPROTECT"))
108  replacements["KILL_ON"];
109  if (na->nc->HasExt("KILL_QUICK"))
110  replacements["KILL_QUICK"];
111  if (!na->nc->HasExt("KILLPROTECT") && !na->nc->HasExt("KILL_QUICK"))
112  replacements["KILL_OFF"];
113 
114  TemplateFileServer page("nickserv/info.html");
115  page.Serve(server, page_name, client, message, reply, replacements);
116  return true;
117 }
118 
Serialize::Reference< NickCore > nc
Definition: account.h:47
void Serve(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, Replacements &)
Anope::string Escape(const Anope::string &src)
Definition: httpd.h:206
const Anope::string & GetVhostHost() const
Definition: nickalias.cpp:106
bool HasVhost() const
Definition: nickalias.cpp:96
Info(const Anope::string &cat, const Anope::string &u)
Definition: info.cpp:10
CoreExport bool Validate(const Anope::string &email)
Definition: mail.cpp:115
time_t time_registered
Definition: account.h:44
bool empty() const
Definition: anope.h:126
std::map< Anope::string, Anope::string > post_data
Definition: httpd.h:81
Anope::string URLDecode(const Anope::string &url)
Definition: httpd.h:163
bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override
Definition: info.cpp:14
CoreExport Anope::string strftime(time_t t, const NickCore *nc=NULL, bool short_output=false)
Definition: misc.cpp:356
const Anope::string & GetVhostIdent() const
Definition: nickalias.cpp:101