summaryrefslogtreecommitdiff
path: root/modules/webcpanel/pages/nickserv/info.cpp
blob: f3c3530447819125b48e62f4293de7aa0d0a7904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Anope IRC Services
 *
 * Copyright (C) 2012-2016 Anope Team <team@anope.org>
 *
 * This file is part of Anope. Anope is free software; you can
 * redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software
 * Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see see <http://www.gnu.org/licenses/>.
 */

#include "../../webcpanel.h"

WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
}

bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements)
{
	if (message.post_data.empty() == false)
	{
		if (message.post_data.count("email") > 0)
		{
			if (message.post_data["email"] != na->GetAccount()->GetEmail())
			{
				if (!message.post_data["email"].empty() && !Mail::Validate(message.post_data["email"]))
					replacements["ERRORS"] = "Invalid email";
				else
				{
					na->GetAccount()->SetEmail(message.post_data["email"]);
					replacements["MESSAGES"] = "Email updated";
				}
			}
		}
		if (message.post_data.count("greet") > 0)
		{
			Anope::string *greet = na->GetAccount()->GetExt<Anope::string>("greet");
			const Anope::string &post_greet = HTTPUtils::URLDecode(message.post_data["greet"].replace_all_cs("+", " "));

			if (post_greet.empty())
				na->GetAccount()->Shrink<Anope::string>("greet");
			else if (!greet || post_greet != *greet)
				na->GetAccount()->Extend<Anope::string>("greet", post_greet);

			replacements["MESSAGES"] = "Greet updated";
		}
		if (na->GetAccount()->HasFieldS("AUTOOP") != message.post_data.count("autoop"))
		{
			if (!na->GetAccount()->HasFieldS("AUTOOP"))
				na->GetAccount()->SetS<bool>("AUTOOP", true);
			else
				na->GetAccount()->UnsetS<bool>("AUTOOP");
			replacements["MESSAGES"] = "Autoop updated";
		}
		if (na->GetAccount()->HasFieldS("NS_PRIVATE") != message.post_data.count("private"))
		{
			if (!na->GetAccount()->HasFieldS("NS_PRIVATE"))
				na->GetAccount()->SetS<bool>("NS_PRIVATE", true);
			else
				na->GetAccount()->UnsetS<bool>("NS_PRIVATE");
			replacements["MESSAGES"] = "Private updated";
		}
		if (na->GetAccount()->HasFieldS("NS_SECURE") != message.post_data.count("secure"))
		{
			if (!na->GetAccount()->HasFieldS("NS_SECURE"))
				na->GetAccount()->SetS<bool>("NS_SECURE", true);
			else
				na->GetAccount()->UnsetS<bool>("NS_SECURE");
			replacements["MESSAGES"] = "Secure updated";
		}
		if (message.post_data["kill"] == "on" && !na->GetAccount()->HasFieldS("KILLPROTECT"))
		{
			na->GetAccount()->SetS<bool>("KILLPROTECT", true);
			na->GetAccount()->UnsetS<bool>("KILL_QUICK");
			replacements["MESSAGES"] = "Kill updated";
		}
		else if (message.post_data["kill"] == "quick" && !na->GetAccount()->HasFieldS("KILL_QUICK"))
		{
			na->GetAccount()->UnsetS<bool>("KILLPROTECT");
			na->GetAccount()->SetS<bool>("KILL_QUICK", true);
			replacements["MESSAGES"] = "Kill updated";
		}
		else if (message.post_data["kill"] == "off" && (na->GetAccount()->HasFieldS("KILLPROTECT") || na->GetAccount()->HasFieldS("KILL_QUICK")))
		{
			na->GetAccount()->UnsetS<bool>("KILLPROTECT");
			na->GetAccount()->UnsetS<bool>("KILL_QUICK");
			replacements["MESSAGES"] = "Kill updated";
		}
	}

	replacements["DISPLAY"] = HTTPUtils::Escape(na->GetAccount()->GetDisplay());
	if (na->GetAccount()->GetEmail().empty() == false)
		replacements["EMAIL"] = HTTPUtils::Escape(na->GetAccount()->GetEmail());
	replacements["TIME_REGISTERED"] = Anope::strftime(na->GetTimeRegistered(), na->GetAccount());
	if (na->HasVhost())
	{
		if (na->GetVhostIdent().empty() == false)
			replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
		else
			replacements["VHOST"] = na->GetVhostHost();
	}
	Anope::string *greet = na->GetAccount()->GetExt<Anope::string>("greet");
	if (greet)
		replacements["GREET"] = HTTPUtils::Escape(*greet);
	if (na->GetAccount()->HasFieldS("AUTOOP"))
		replacements["AUTOOP"];
	if (na->GetAccount()->HasFieldS("NS_PRIVATE"))
		replacements["PRIVATE"];
	if (na->GetAccount()->HasFieldS("NS_SECURE"))
		replacements["SECURE"];
	if (na->GetAccount()->HasFieldS("KILLPROTECT"))
		replacements["KILL_ON"];
	if (na->GetAccount()->HasFieldS("KILL_QUICK"))
		replacements["KILL_QUICK"];
	if (!na->GetAccount()->HasFieldS("KILLPROTECT") && !na->GetAccount()->HasFieldS("KILL_QUICK"))
		replacements["KILL_OFF"];

	TemplateFileServer page("nickserv/info.html");
	page.Serve(server, page_name, client, message, reply, replacements);
	return true;
}