}
//! Check remote address against netmaskgroup ng
- bool acl(NetmaskGroup &ng)
+ bool acl(const NetmaskGroup &ng)
{
ComboAddress remote;
if (getRemote(remote))
if(!d_server)
return;
try {
- NetmaskGroup acl;
- acl.toMasks(::arg()["webserver-allow-from"]);
-
while(true) {
try {
auto client = d_server->accept();
if (!client) {
continue;
}
- if (client->acl(acl)) {
+ if (client->acl(d_acl)) {
std::thread webHandler(WebServerConnectionThreadStart, this, client);
webHandler.detach();
} else {
public:
WebServer(const string &listenaddress, int port);
virtual ~WebServer() { };
+
+ void setACL(const NetmaskGroup &nmg) {
+ d_acl = nmg;
+ }
+
void bind();
void go();
int d_port;
string d_password;
std::shared_ptr<Server> d_server;
+
+ NetmaskGroup d_acl;
};
#endif /* WEBSERVER_HH */
registerAllStats();
d_ws = new AsyncWebServer(fdm, arg()["webserver-address"], arg().asNum("webserver-port"));
+
+ NetmaskGroup acl;
+ acl.toMasks(::arg()["webserver-allow-from"]);
+ d_ws->setACL(acl);
+
d_ws->bind();
// legacy dispatch
// This is an entry point from FDM, so it needs to catch everything.
void AsyncWebServer::serveConnection(std::shared_ptr<Socket> client) const
try {
+ if (!client->acl(d_acl)) {
+ return;
+ }
+
HttpRequest req;
YaHTTP::AsyncRequestLoader yarl;
yarl.initialize(&req);
class AsyncServer : public Server {
public:
- AsyncServer(const string &localaddress, int port) : Server(localaddress, port) { };
+ AsyncServer(const string &localaddress, int port) : Server(localaddress, port)
+ {
+ d_server_socket.setNonBlocking();
+ };
friend void AsyncServerNewConnectionMT(void *p);