diff --git a/src/System/Serverman/Actions/Nginx.hs b/src/System/Serverman/Actions/Nginx.hs index fb37bf2..83167d1 100644 --- a/src/System/Serverman/Actions/Nginx.hs +++ b/src/System/Serverman/Actions/Nginx.hs @@ -16,7 +16,7 @@ module System.Serverman.Actions.Nginx (nginx) where import Data.List nginx :: ServerParams -> IO () - nginx params@(ServerParams { ssl, serverService, domain, directory, serverType }) = + nginx params@(ServerParams { ssl, serverService, domain, directory, serverType, email }) = do -- Turn SSL off at first, because we have not yet received a certificate let content = show (params { ssl = False, port = "80" }) @@ -64,7 +64,7 @@ module System.Serverman.Actions.Nginx (nginx) where putStrLn $ "restarted " ++ show serverService createCert path cmd = do - result <- execute cmd ["certonly", "--webroot", "--webroot-path", directory, "-d", domain] "" False + result <- execute cmd ["certonly", "--webroot", "--webroot-path", directory, "-d", domain, "--email", email] "" False case result of Left _ -> if cmd == "letsencrypt" then createCert path "certbot" else return () Right stdout -> do diff --git a/src/System/Serverman/Actions/WebServer.hs b/src/System/Serverman/Actions/WebServer.hs index 3b550ee..40c79b2 100644 --- a/src/System/Serverman/Actions/WebServer.hs +++ b/src/System/Serverman/Actions/WebServer.hs @@ -9,6 +9,7 @@ module System.Serverman.Actions.WebServer (ServerParams(..), ServerType(..)) whe , domain :: String , port :: String , forward :: String + , email :: String , ssl :: Bool , serverType :: ServerType , serverService :: Service diff --git a/src/System/Term.hs b/src/System/Term.hs index ed0e103..3b021c5 100644 --- a/src/System/Term.hs +++ b/src/System/Term.hs @@ -9,8 +9,10 @@ module System.Term ( initialize ) where import qualified System.Console.CmdArgs.Explicit as E import System.Environment import System.Directory + import System.Exit import Data.Monoid import Data.Maybe + import Control.Monad initialize = do args <- getArgs @@ -48,6 +50,7 @@ module System.Term ( initialize ) where , forward :: String , wService :: String , ssl :: Bool + , email :: String } | DatabaseParams { databaseName :: String , dService :: String } @@ -61,6 +64,7 @@ module System.Term ( initialize ) where , port = def &= typ "PORT" &= help "port number to listen to, defaults to 80 for http and 443 for https" , forward = def &= typ "PORT" &= help "the port to forward to (in case of a port-forwarding server)" , ssl = False &= help "create a letsencrypt certificate for this domain, defaults to false" + , email = def &= help "email required for registering your certificate" , wService = "nginx" &= help "service to build config for: nginx, defaults to nginx" &= explicit &= name "service" } &= explicit &= name "webserver" @@ -72,7 +76,9 @@ module System.Term ( initialize ) where install = InstallParams { iService = def &= argPos 0 } &= explicit &= name "install" - webserverSetup (WebServerParams { directory, domain, port, ssl, forward, wService }) = do + webserverSetup (WebServerParams { directory, domain, port, ssl, forward, wService, email }) = do + when (ssl && null email) $ die "Email is required for generating a certificate" + let serverType | (not . null) forward = S.PortForwarding | otherwise = S.Static @@ -93,6 +99,7 @@ module System.Term ( initialize ) where , S.forward = forward , S.serverType = serverType , S.serverService = serviceName + , S.email = email } S.run $ S.detectOS >>= (S.install serviceName) >> S.newServer params