2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 insp::intrusive_list<FlashPDSocket> sockets;
27 std::string policy_reply;
28 const std::string expected_request("<policy-file-request/>\0", 23);
31 class FlashPDSocket : public BufferedSocket, public Timer, public insp::intrusive_list_node<FlashPDSocket>
33 /** True if this object is in the cull list
37 bool Tick(time_t currtime) CXX11_OVERRIDE
44 FlashPDSocket(int newfd, unsigned int timeoutsec)
45 : BufferedSocket(newfd)
49 ServerInstance->Timers.AddTimer(this);
57 void OnError(BufferedSocketError) CXX11_OVERRIDE
62 void OnDataReady() CXX11_OVERRIDE
64 if (recvq == expected_request)
65 WriteData(policy_reply);
76 ServerInstance->GlobalCulls.AddItem(this);
80 class ModuleFlashPD : public Module
85 ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
87 if (!stdalgo::string::equalsci(from->bind_tag->getString("type"), "flashpolicyd"))
88 return MOD_RES_PASSTHRU;
90 if (policy_reply.empty())
93 sockets.push_front(new FlashPDSocket(nfd, timeout));
97 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
99 ConfigTag* tag = ServerInstance->Config->ConfValue("flashpolicyd");
100 std::string file = tag->getString("file");
106 FileReader reader(file);
107 policy_reply = reader.GetString();
109 catch (CoreException&)
111 throw ModuleException("A file was specified for FlashPD, but it could not be loaded at " + tag->getTagLocation());
116 // A file was not specified. Set the default setting.
117 // We allow access to all client ports by default
118 std::string to_ports;
119 for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i)
121 ListenSocket* ls = *i;
122 if (!stdalgo::string::equalsci(ls->bind_tag->getString("type", "clients"), "clients") || !ls->bind_tag->getString("ssl").empty())
125 to_ports.append(ConvToStr(ls->bind_sa.port())).push_back(',');
128 if (to_ports.empty())
130 policy_reply.clear();
134 to_ports.erase(to_ports.size() - 1);
137 "<?xml version=\"1.0\"?>\
138 <!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\
139 <cross-domain-policy>\
140 <site-control permitted-cross-domain-policies=\"master-only\"/>\
141 <allow-access-from domain=\"*\" to-ports=\"" + to_ports + "\" />\
142 </cross-domain-policy>";
143 timeout = tag->getDuration("timeout", 5, 1);
146 CullResult cull() CXX11_OVERRIDE
148 for (insp::intrusive_list<FlashPDSocket>::const_iterator i = sockets.begin(); i != sockets.end(); ++i)
150 FlashPDSocket* sock = *i;
153 return Module::cull();
156 Version GetVersion() CXX11_OVERRIDE
158 return Version("Flash Policy Daemon, allows Flash IRC clients to connect", VF_VENDOR);
162 MODULE_INIT(ModuleFlashPD)