2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Robby <robby@chatbelgie.be>
5 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
6 * Copyright (C) 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2014 JustArchi <JustArchi@JustArchi.net>
8 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
9 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 insp::intrusive_list<FlashPDSocket> sockets;
32 std::string policy_reply;
33 const std::string expected_request("<policy-file-request/>\0", 23);
36 class FlashPDSocket : public BufferedSocket, public Timer, public insp::intrusive_list_node<FlashPDSocket>
38 /** True if this object is in the cull list
42 bool Tick(time_t currtime) CXX11_OVERRIDE
49 FlashPDSocket(int newfd, unsigned int timeoutsec)
50 : BufferedSocket(newfd)
54 ServerInstance->Timers.AddTimer(this);
62 void OnError(BufferedSocketError) CXX11_OVERRIDE
67 void OnDataReady() CXX11_OVERRIDE
69 if (recvq == expected_request)
70 WriteData(policy_reply);
81 ServerInstance->GlobalCulls.AddItem(this);
85 class ModuleFlashPD : public Module
90 ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
92 if (!stdalgo::string::equalsci(from->bind_tag->getString("type"), "flashpolicyd"))
93 return MOD_RES_PASSTHRU;
95 if (policy_reply.empty())
98 sockets.push_front(new FlashPDSocket(nfd, timeout));
102 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
104 ConfigTag* tag = ServerInstance->Config->ConfValue("flashpolicyd");
105 std::string file = tag->getString("file");
111 FileReader reader(file);
112 policy_reply = reader.GetString();
114 catch (CoreException&)
116 throw ModuleException("A file was specified for FlashPD, but it could not be loaded at " + tag->getTagLocation());
121 // A file was not specified. Set the default setting.
122 // We allow access to all client ports by default
123 std::string to_ports;
124 for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i)
126 ListenSocket* ls = *i;
127 if (!stdalgo::string::equalsci(ls->bind_tag->getString("type", "clients", 1), "clients"))
130 if (!ls->bind_tag->getString("ssl").empty())
133 to_ports.append(ConvToStr(ls->bind_sa.port())).push_back(',');
136 if (to_ports.empty())
138 policy_reply.clear();
142 to_ports.erase(to_ports.size() - 1);
145 "<?xml version=\"1.0\"?>\
146 <!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\
147 <cross-domain-policy>\
148 <site-control permitted-cross-domain-policies=\"master-only\"/>\
149 <allow-access-from domain=\"*\" to-ports=\"" + to_ports + "\" />\
150 </cross-domain-policy>";
151 timeout = tag->getDuration("timeout", 5, 1);
154 CullResult cull() CXX11_OVERRIDE
156 for (insp::intrusive_list<FlashPDSocket>::const_iterator i = sockets.begin(); i != sockets.end(); ++i)
158 FlashPDSocket* sock = *i;
161 return Module::cull();
164 Version GetVersion() CXX11_OVERRIDE
166 return Version("Allows connection policies to be served to IRC clients that use Adobe Flash.", VF_VENDOR);
170 MODULE_INIT(ModuleFlashPD)