Commit acdab857 authored by Bas Lijnse's avatar Bas Lijnse

Added an engine option to limit webserver connections to localhost (on by default)

parent 6362be43
Pipeline #21057 passed with stage
in 4 minutes and 46 seconds
......@@ -63,6 +63,7 @@ instance Startable (a,b) | Startable a & Startable b
, appVersion :: String
, serverPort :: Int
, serverUrl :: String
, localhostOnly :: Bool // Only allow connections from localhost. (default to true)
, keepaliveTime :: Timespec
, sessionTime :: Timespec
, persistTasks :: Bool
......
......@@ -203,6 +203,7 @@ defaultEngineOptions world
, appVersion = appVersion
, serverPort = IF_POSIX_OR_WINDOWS 8080 80
, serverUrl = "http://localhost/"
, localhostOnly = True
, keepaliveTime = {tv_sec=300,tv_nsec=0} // 5 minutes
, sessionTime = {tv_sec=60,tv_nsec=0} // 1 minute, (the client pings every 10 seconds by default)
, persistTasks = False
......
......@@ -126,6 +126,7 @@ createClientIWorld serverURL currentInstance
, appVersion = locundef "appVersion"
, serverPort = 80
, serverUrl = locundef "serverUrl"
, localhostOnly = False
, keepaliveTime = locundef "keepaliveTime"
, sessionTime = locundef "sessionTime"
, persistTasks = False
......
......@@ -129,12 +129,16 @@ where
wsockTextMsg :: String -> [String]
wsockTextMsg payload = [wsockMsgFrame WS_OP_TEXT True payload]
import StdDebug
httpServer :: !Int !Timespec ![WebService r w] (sds () r w) -> ConnectionTask | TC r & TC w & RWShared sds
httpServer port keepAliveTime requestProcessHandlers sds
= wrapIWorldConnectionTask {ConnectionHandlersIWorld|onConnect=onConnect, onData=onData, onShareChange=onShareChange, onTick=onTick, onDisconnect=onDisconnect, onDestroy=onDestroy} sds
where
onConnect connId host r iworld=:{IWorld|world,clock}
= (Ok (NTIdle host clock),Nothing,[],False,{IWorld|iworld & world = world})
onConnect connId host r iworld=:{IWorld|world,clock,options}
| options.localhostOnly && host <> "127.0.0.1"
= (Ok (NTIdle host clock),Nothing,[],True,{IWorld|iworld & world = world})
| otherwise
= (Ok (NTIdle host clock),Nothing,[],False,{IWorld|iworld & world = world})
onData data connState=:(NTProcessingRequest request localState) r env
//Select handler based on request path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment