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 (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 timeout = tag->getInt("timeout", 5, 1);
101 std::string file = tag->getString("file");
107 FileReader reader(file);
108 policy_reply = reader.GetString();
110 catch (CoreException&)
112 const std::string error_message = "A file was specified for FlashPD, but it could not be loaded.";
113 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, error_message);
114 ServerInstance->SNO->WriteGlobalSno('a', error_message);
115 policy_reply.clear();
120 // A file was not specified. Set the default setting.
121 // We allow access to all client ports by default
122 std::string to_ports;
123 for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i)
125 ListenSocket* ls = *i;
126 if (ls->bind_tag->getString("type", "clients") != "clients" || ls->bind_tag->getString("ssl", "plaintext") != "plaintext")
129 to_ports.append(ConvToStr(ls->bind_port)).push_back(',');
132 if (to_ports.empty())
134 policy_reply.clear();
138 to_ports.erase(to_ports.size() - 1);
141 "<?xml version=\"1.0\"?>\
142 <!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\
143 <cross-domain-policy>\
144 <site-control permitted-cross-domain-policies=\"master-only\"/>\
145 <allow-access-from domain=\"*\" to-ports=\"" + to_ports + "\" />\
146 </cross-domain-policy>";
151 for (insp::intrusive_list<FlashPDSocket>::const_iterator i = sockets.begin(); i != sockets.end(); ++i)
153 FlashPDSocket* sock = *i;
156 return Module::cull();
159 Version GetVersion() CXX11_OVERRIDE
161 return Version("Flash Policy Daemon. Allows Flash IRC clients to connect", VF_VENDOR);
165 MODULE_INIT(ModuleFlashPD)