summaryrefslogtreecommitdiff
path: root/modules/webcpanel/pages/chanserv/set.cpp
blob: d3cca72cc201304576842a73730a419c78f9aec1 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * 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"
#include "utils.h"

WebCPanel::ChanServ::Set::Set(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
}

bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements)
{
	const Anope::string &chname = message.get_data["channel"];
	bool can_set = false;
	TemplateFileServer page("chanserv/set.html");

	BuildChanList(na, replacements);

	if (chname.empty())
	{
		page.Serve(server, page_name, client, message, reply, replacements);
		return true;
	}

	::ChanServ::Channel *ci = ::ChanServ::Find(chname);

	if (!ci)
	{
		page.Serve(server, page_name, client, message, reply, replacements);
		return true;
	}

	replacements["OKAY"];

	if (ci->AccessFor(na->GetAccount()).HasPriv("SET"))
	{
		replacements["CAN_SET"];
		can_set = true;
	}

	if (can_set && message.post_data.empty() == false)
	{
		if (ci->HasFieldS("KEEPTOPIC") != message.post_data.count("keeptopic"))
		{
			if (!ci->HasFieldS("KEEPTOPIC"))
				ci->SetS<bool>("KEEPTOPIC", true);
			else
				ci->UnsetS<bool>("KEEPTOPIC");
			replacements["MESSAGES"] = "Secure updated";
		}
		if (ci->HasFieldS("PEACE") != message.post_data.count("peace"))
		{
			if (!ci->HasFieldS("PEACE"))
				ci->SetS<bool>("PEACE", true);
			else
				ci->UnsetS<bool>("PEACE");
			replacements["MESSAGES"] = "Peace updated";
		}
		if (ci->HasFieldS("CS_PRIVATE") != message.post_data.count("private"))
		{
			if (!ci->HasFieldS("CS_PRIVATE"))
				ci->SetS<bool>("CS_PRIVATE", true);
			else
				ci->UnsetS<bool>("CS_PRIVATE");
			replacements["MESSAGES"] = "Private updated";
		}
		if (ci->HasFieldS("RESTRICTED") != message.post_data.count("restricted"))
		{
			if (!ci->HasFieldS("RESTRICTED"))
				ci->SetS<bool>("RESTRICTED", true);
			else
				ci->UnsetS<bool>("RESTRICTED");
			replacements["MESSAGES"] = "Restricted updated";
		}
		if (ci->HasFieldS("CS_SECURE") != message.post_data.count("secure"))
		{
			if (!ci->HasFieldS("CS_SECURE"))
				ci->SetS<bool>("CS_SECURE", true);
			else
				ci->UnsetS<bool>("CS_SECURE");
			replacements["MESSAGES"] = "Secure updated";
		}
		if (ci->HasFieldS("SECUREOPS") != message.post_data.count("secureops"))
		{
			if (!ci->HasFieldS("SECUREOPS"))
				ci->SetS<bool>("SECUREOPS", true);
			else
				ci->UnsetS<bool>("SECUREOPS");
			replacements["MESSAGES"] = "Secureops updated";
		}
		if (ci->HasFieldS("TOPICLOCK") != message.post_data.count("topiclock"))
		{
			if (!ci->HasFieldS("TOPICLOCK"))
				ci->SetS<bool>("TOPICLOCK", true);
			else
				ci->UnsetS<bool>("TOPICLOCK");
			replacements["MESSAGES"] = "Topiclock updated";
		}
	}

	replacements["CHANNEL"] = HTTPUtils::Escape(ci->GetName());
	replacements["CHANNEL_ESCAPED"] = HTTPUtils::URLEncode(ci->GetName());
	if (ci->GetFounder())
		replacements["FOUNDER"] = ci->GetFounder()->GetDisplay();
	if (ci->GetSuccessor())
		replacements["SUCCESSOR"] = ci->GetSuccessor()->GetDisplay();
	replacements["TIME_REGISTERED"] = Anope::strftime(ci->GetTimeRegistered(), na->GetAccount());
	replacements["LAST_USED"] = Anope::strftime(ci->GetLastUsed(), na->GetAccount());
	replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname);

	if (!ci->GetLastTopic().empty())
	{
		replacements["LAST_TOPIC"] = HTTPUtils::Escape(ci->GetLastTopic());
		replacements["LAST_TOPIC_SETTER"] = HTTPUtils::Escape(ci->GetLastTopicSetter());
	}

	if (can_set)
	{
		if (ci->HasFieldS("KEEPTOPIC"))
			replacements["KEEPTOPIC"];

		if (ci->HasFieldS("PEACE"))
			replacements["PEACE"];

		if (ci->HasFieldS("CS_PRIVATE"))
			replacements["PRIVATE"];

		if (ci->HasFieldS("RESTRICTED"))
			replacements["RESTRICTED"];

		if (ci->HasFieldS("CS_SECURE"))
			replacements["SECURE"];

		if (ci->HasFieldS("SECUREOPS"))
			replacements["SECUREOPS"];

		if (ci->HasFieldS("TOPICLOCK"))
			replacements["TOPICLOCK"];
	}

	page.Serve(server, page_name, client, message, reply, replacements);
	return true;
}

std::set<Anope::string> WebCPanel::ChanServ::Set::GetData()
{
	std::set<Anope::string> v;
	v.insert("channel");
	return v;
}