Skip to content
Browse files

Added address config option.

  • Loading branch information...
1 parent a831da8 commit 6e3998e53887d27eccb14666a345e00178153c12 @larose larose committed
Showing with 10 additions and 13 deletions.
  1. +2 −0 Network/Gitit/Config.hs
  2. +2 −0 Network/Gitit/Types.hs
  3. +3 −0 data/default.conf
  4. +3 −13 gitit.hs
View
2 Network/Gitit/Config.hs
@@ -79,6 +79,7 @@ extractConfig cp = do
cfTableOfContents <- get cp "DEFAULT" "table-of-contents"
cfMaxUploadSize <- get cp "DEFAULT" "max-upload-size"
cfMaxPageSize <- get cp "DEFAULT" "max-page-size"
+ cfAddress <- get cp "DEFAULT" "address"
cfPort <- get cp "DEFAULT" "port"
cfDebugMode <- get cp "DEFAULT" "debug-mode"
cfFrontPage <- get cp "DEFAULT" "front-page"
@@ -167,6 +168,7 @@ extractConfig cp = do
, tableOfContents = cfTableOfContents
, maxUploadSize = readSize "max-upload-size" cfMaxUploadSize
, maxPageSize = readSize "max-page-size" cfMaxPageSize
+ , address = cfAddress
, portNumber = readNumber "port" cfPort
, debugMode = cfDebugMode
, frontPage = cfFrontPage
View
2 Network/Gitit/Types.hs
@@ -90,6 +90,8 @@ data Config = Config {
maxUploadSize :: Integer,
-- | Max size of page uploads
maxPageSize :: Integer,
+ -- | IP address to bind to
+ address :: String,
-- | Port number to serve content on
portNumber :: Int,
-- | Print debug info to the console?
View
3 data/default.conf
@@ -1,5 +1,8 @@
# gitit wiki configuration file
+address: 0.0.0.0
+# sets the IP address on which the web server will listen.
+
port: 5001
# sets the port on which the web server will run.
View
16 gitit.hs
@@ -34,7 +34,6 @@ import System.Exit
import System.IO (stderr)
import System.Console.GetOpt
import Network.Socket hiding (Debug)
-import Network.URI
import Data.Version (showVersion)
import qualified Data.ByteString.Char8 as B
import Data.ByteString.UTF8 (fromString)
@@ -97,7 +96,7 @@ main = do
-- open the requested interface
sock <- socket AF_INET Stream defaultProtocol
setSocketOption sock ReuseAddr 1
- device <- inet_addr (getListenOrDefault opts)
+ device <- inet_addr (address conf)
bindSocket sock (SockAddrInet (toEnum (portNumber conf)) device)
listen sock 10
@@ -128,7 +127,7 @@ flags =
"Print version information"
, Option ['p'] ["port"] (ReqArg (Right . Port . read) "PORT")
"Specify port"
- , Option ['l'] ["listen"] (ReqArg (Right . Listen . checkListen) "INTERFACE")
+ , Option ['l'] ["listen"] (ReqArg (Right . Listen) "INTERFACE")
"Specify IP address to listen on"
, Option [] ["print-default-config"] (NoArg (Left PrintDefaultConfig))
"Print default configuration"
@@ -138,16 +137,6 @@ flags =
"Specify configuration file"
]
-checkListen :: String -> String
-checkListen l | isIPv6address l = l
- | isIPv4address l = l
- | otherwise = error "Gitit.checkListen: Not a valid interface name"
-
-getListenOrDefault :: [ConfigOpt] -> String
-getListenOrDefault [] = "0.0.0.0"
-getListenOrDefault ((Listen l):_) = l
-getListenOrDefault (_:os) = getListenOrDefault os
-
parseArgs :: [String] -> IO [Opt]
parseArgs argv = do
case getOpt Permute flags argv of
@@ -175,6 +164,7 @@ compileInfo =
handleFlag :: Config -> ConfigOpt -> Config
handleFlag conf Debug = conf{ debugMode = True, logLevel = DEBUG }
handleFlag conf (Port p) = conf { portNumber = p }
+handleFlag conf (Listen l) = conf { address = l }
handleFlag conf _ = conf
putErr :: ExitCode -> String -> IO a

0 comments on commit 6e3998e

Please sign in to comment.
Something went wrong with that request. Please try again.