Enable validation according to WebSocket resource and origin.
This commit is contained in:
@@ -36,8 +36,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
ServerAcceptWebHelper::ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService)
|
||||
: m_ioService(ioService), m_serverCallback(serverCallback)
|
||||
ServerAcceptWebHelper::ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService,
|
||||
const string &webSocketResource, const string &webSocketOrigin)
|
||||
: m_ioService(ioService), m_serverCallback(serverCallback),
|
||||
m_webSocketResource(webSocketResource), m_webSocketOrigin(webSocketOrigin)
|
||||
{
|
||||
m_webSocketServer.reset(new server);
|
||||
}
|
||||
@@ -71,9 +73,15 @@ ServerAcceptWebHelper::Close()
|
||||
}
|
||||
|
||||
bool
|
||||
ServerAcceptWebHelper::validate(websocketpp::connection_hdl /*hdl*/)
|
||||
ServerAcceptWebHelper::validate(websocketpp::connection_hdl hdl)
|
||||
{
|
||||
return true;
|
||||
bool retVal = false;
|
||||
server::connection_ptr con = m_webSocketServer->get_con_from_hdl(hdl);
|
||||
if ((m_webSocketResource.empty() || con->get_resource() == m_webSocketResource)
|
||||
&& (m_webSocketOrigin.empty() || (con->get_origin() != "null" && con->get_origin() == m_webSocketOrigin))) {
|
||||
retVal = true;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -78,7 +78,8 @@ ServerManager::~ServerManager()
|
||||
}
|
||||
|
||||
void
|
||||
ServerManager::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir)
|
||||
ServerManager::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir,
|
||||
const string &webSocketResource, const string &webSocketOrigin)
|
||||
{
|
||||
GetLobbyThread().Init(logDir);
|
||||
|
||||
@@ -95,7 +96,8 @@ ServerManager::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int
|
||||
}*/
|
||||
if (proto & TRANSPORT_PROTOCOL_WEBSOCKET)
|
||||
{
|
||||
boost::shared_ptr<ServerAcceptInterface> webAcceptHelper(new ServerAcceptWebHelper(GetGui(), m_ioService));
|
||||
boost::shared_ptr<ServerAcceptInterface> webAcceptHelper(
|
||||
new ServerAcceptWebHelper(GetGui(), m_ioService, webSocketResource, webSocketOrigin));
|
||||
webAcceptHelper->Listen(websocketPort, ipv6, logDir, m_lobbyThread);
|
||||
m_acceptHelperPool.push_back(webAcceptHelper);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ ServerManagerIrc::~ServerManagerIrc()
|
||||
}
|
||||
|
||||
void
|
||||
ServerManagerIrc::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir)
|
||||
ServerManagerIrc::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir,
|
||||
const std::string &webSocketResource, const std::string &webSocketOrigin)
|
||||
{
|
||||
boost::shared_ptr<IrcThread> tmpIrcAdminThread;
|
||||
boost::shared_ptr<IrcThread> tmpIrcLobbyThread;
|
||||
@@ -83,7 +84,7 @@ ServerManagerIrc::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, i
|
||||
|
||||
m_adminBot->Init(m_lobbyThread, tmpIrcAdminThread, myConfig.readConfigString("CacheDir"));
|
||||
m_lobbyBot->Init(m_lobbyThread, tmpIrcLobbyThread);
|
||||
ServerManager::Init(serverPort, websocketPort, ipv6, proto, logDir);
|
||||
ServerManager::Init(serverPort, websocketPort, ipv6, proto, logDir, webSocketResource, webSocketOrigin);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
class ServerAcceptWebHelper : public ServerAcceptInterface
|
||||
{
|
||||
public:
|
||||
ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService);
|
||||
ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService,
|
||||
const std::string &webSocketResource, const std::string &webSocketOrigin);
|
||||
|
||||
virtual void Listen(unsigned serverPort, bool ipv6, const std::string &logDir,
|
||||
boost::shared_ptr<ServerLobbyThread> lobbyThread);
|
||||
@@ -61,6 +62,8 @@ private:
|
||||
ServerCallback &m_serverCallback;
|
||||
boost::shared_ptr<server> m_webSocketServer;
|
||||
SessionMap m_sessionMap;
|
||||
std::string m_webSocketResource;
|
||||
std::string m_webSocketOrigin;
|
||||
|
||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||
};
|
||||
|
||||
@@ -54,7 +54,8 @@ public:
|
||||
virtual ~ServerManager();
|
||||
|
||||
// Set the parameters.
|
||||
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir);
|
||||
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir,
|
||||
const std::string &webSocketResource, const std::string &webSocketOrigin);
|
||||
|
||||
// Main start function.
|
||||
virtual void RunAll();
|
||||
|
||||
@@ -45,7 +45,8 @@ public:
|
||||
virtual ~ServerManagerIrc();
|
||||
|
||||
// Set the parameters.
|
||||
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir);
|
||||
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir,
|
||||
const std::string &webSocketResource, const std::string &webSocketOrigin);
|
||||
|
||||
// Main start function.
|
||||
virtual void RunAll();
|
||||
|
||||
Reference in New Issue
Block a user