Skip to content

Commit 285fd93

Browse files
authored
smp server: notices about server pages and port 443, enable store log by default (#1501)
* smp server: notices about server pages and port 443, enable store log by default * enable store log by default for ntf and xftp servers, fix tests
1 parent 7636bc7 commit 285fd93

6 files changed

Lines changed: 67 additions & 36 deletions

File tree

src/Simplex/FileTransfer/Server/Main.hs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE ApplicativeDo #-}
12
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE NamedFieldPuns #-}
@@ -220,14 +221,19 @@ cliCommandP cfgPath logPath iniFile =
220221
)
221222
where
222223
initP :: Parser InitOptions
223-
initP =
224-
InitOptions
225-
<$> switch
226-
( long "store-log"
227-
<> short 'l'
228-
<> help "Enable store log for persistence"
224+
initP = do
225+
enableStoreLog <-
226+
flag' False
227+
( long "disable-store-log"
228+
<> help "Disable store log for persistence (enabled by default)"
229229
)
230-
<*> option
230+
<|> flag True True
231+
( long "store-log"
232+
<> short 'l'
233+
<> help "Enable store log for persistence (DEPRECATED, enabled by default)"
234+
)
235+
signAlgorithm <-
236+
option
231237
(maybeReader readMaybe)
232238
( long "sign-algorithm"
233239
<> short 'a'
@@ -236,30 +242,35 @@ cliCommandP cfgPath logPath iniFile =
236242
<> showDefault
237243
<> metavar "ALG"
238244
)
239-
<*> strOption
245+
ip <-
246+
strOption
240247
( long "ip"
241248
<> help
242249
"Server IP address, used as Common Name for TLS online certificate if FQDN is not supplied"
243250
<> value "127.0.0.1"
244251
<> showDefault
245252
<> metavar "IP"
246253
)
247-
<*> (optional . strOption)
254+
fqdn <-
255+
(optional . strOption)
248256
( long "fqdn"
249257
<> short 'n'
250258
<> help "Server FQDN used as Common Name for TLS online certificate"
251259
<> showDefault
252260
<> metavar "FQDN"
253261
)
254-
<*> strOption
262+
filesPath <-
263+
strOption
255264
( long "path"
256265
<> short 'p'
257266
<> help "Path to the directory to store files"
258267
<> metavar "PATH"
259268
)
260-
<*> strOption
269+
fileSizeQuota <-
270+
strOption
261271
( long "quota"
262272
<> short 'q'
263273
<> help "File storage quota (e.g. 100gb)"
264274
<> metavar "QUOTA"
265275
)
276+
pure InitOptions {enableStoreLog, signAlgorithm, ip, fqdn, filesPath, fileSizeQuota}

src/Simplex/Messaging/Notifications/Server/Main.hs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE ApplicativeDo #-}
12
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE NamedFieldPuns #-}
@@ -222,14 +223,19 @@ cliCommandP cfgPath logPath iniFile =
222223
)
223224
where
224225
initP :: Parser InitOptions
225-
initP =
226-
InitOptions
227-
<$> switch
228-
( long "store-log"
229-
<> short 'l'
230-
<> help "Enable store log for persistence"
226+
initP = do
227+
enableStoreLog <-
228+
flag' False
229+
( long "disable-store-log"
230+
<> help "Disable store log for persistence (enabled by default)"
231231
)
232-
<*> option
232+
<|> flag True True
233+
( long "store-log"
234+
<> short 'l'
235+
<> help "Enable store log for persistence (DEPRECATED, enabled by default)"
236+
)
237+
signAlgorithm <-
238+
option
233239
(maybeReader readMaybe)
234240
( long "sign-algorithm"
235241
<> short 'a'
@@ -238,18 +244,21 @@ cliCommandP cfgPath logPath iniFile =
238244
<> showDefault
239245
<> metavar "ALG"
240246
)
241-
<*> strOption
247+
ip <-
248+
strOption
242249
( long "ip"
243250
<> help
244251
"Server IP address, used as Common Name for TLS online certificate if FQDN is not supplied"
245252
<> value "127.0.0.1"
246253
<> showDefault
247254
<> metavar "IP"
248255
)
249-
<*> (optional . strOption)
256+
fqdn <-
257+
(optional . strOption)
250258
( long "fqdn"
251259
<> short 'n'
252260
<> help "Server FQDN used as Common Name for TLS online certificate"
253261
<> showDefault
254262
<> metavar "FQDN"
255263
)
264+
pure InitOptions {enableStoreLog, signAlgorithm, ip, fqdn}

src/Simplex/Messaging/Server/CLI.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,15 @@ printServerConfig transports logFile = do
302302
printServerTransports transports
303303

304304
printServerTransports :: [(ServiceName, ATransport, AddHTTP)] -> IO ()
305-
printServerTransports = mapM_ $ \(p, ATransport t, addHTTP) -> do
306-
let descr = p <> " (" <> transportName t <> ")..."
307-
putStrLn $ "Serving SMP protocol on port " <> descr
308-
when addHTTP $ putStrLn $ "Serving static site on port " <> descr
305+
printServerTransports ts = do
306+
forM_ ts $ \(p, ATransport t, addHTTP) -> do
307+
let descr = p <> " (" <> transportName t <> ")..."
308+
putStrLn $ "Serving SMP protocol on port " <> descr
309+
when addHTTP $ putStrLn $ "Serving static site on port " <> descr
310+
unless (any (\(p, _, _) -> p == "443") ts) $
311+
putStrLn
312+
"\nWARNING: the clients will use port 443 by default soon.\n\
313+
\Set `port` in smp-server.ini section [TRANSPORT] to `5223,443`\n"
309314

310315
printSMPServerConfig :: [(ServiceName, ATransport, AddHTTP)] -> AServerStoreCfg -> IO ()
311316
printSMPServerConfig transports (ASSCfg _ _ cfg) = case cfg of

src/Simplex/Messaging/Server/Env/STM.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,10 @@ newEnv config@ServerConfig {smpCredentials, httpCredentials, serverStoreCfg, smp
384384
getCredentials protocol creds = do
385385
files <- missingCreds
386386
unless (null files) $ do
387-
putStrLn $ "Error: no " <> protocol <> " credentials: " <> intercalate ", " files
388-
when (protocol == "HTTPS") $ putStrLn letsEncrypt
387+
putStrLn $ "----------\nError: no " <> protocol <> " credentials: " <> intercalate ", " files
388+
when (protocol == "HTTPS") $ do
389+
putStrLn "Server should serve static pages to show connection links in the browser."
390+
putStrLn letsEncrypt
389391
exitFailure
390392
loadServerCredential creds
391393
where
@@ -400,7 +402,7 @@ newEnv config@ServerConfig {smpCredentials, httpCredentials, serverStoreCfg, smp
400402
_ -> do
401403
putStrLn $ "Error: unsupported HTTPS credentials, required 4096-bit RSA\n" <> letsEncrypt
402404
exitFailure
403-
letsEncrypt = "Use Let's Encrypt to generate: certbot certonly --standalone -d yourdomainname --key-type rsa --rsa-key-size 4096"
405+
letsEncrypt = "Use Let's Encrypt to generate: certbot certonly --standalone -d yourdomainname --key-type rsa --rsa-key-size 4096\n----------"
404406
serverInfo =
405407
ServerInformation
406408
{ information,

src/Simplex/Messaging/Server/Main.hs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath =
281281
enableStoreLog <- onOffPrompt "Enable store log to restore queues and messages on server restart" True
282282
logStats <- onOffPrompt "Enable logging daily statistics" False
283283
putStrLn "Require a password to create new messaging queues?"
284-
password <- withPrompt "'r' for random (default), 'n' - no password, or enter password: " serverPassword
284+
password <- withPrompt "'r' for random (default), 'n' - no password (recommended for public servers), or enter password: " serverPassword
285285
let host = fromMaybe ip fqdn
286286
host' <- withPrompt ("Enter server FQDN or IP address for certificate (" <> host <> "): ") getLine
287287
sourceCode' <- withPrompt ("Enter server source code URI (" <> maybe simplexmqSource T.unpack src' <> "): ") getServerSourceCode
288-
staticPath' <- withPrompt ("Enter path to store generated static site with server information (" <> fromMaybe defaultStaticPath sp' <> "): ") getLine
288+
staticPath' <- withPrompt ("Enter path to store generated server pages to show connection links (" <> fromMaybe defaultStaticPath sp' <> "): ") getLine
289289
initialize
290290
opts
291291
{ enableStoreLog,
@@ -659,11 +659,15 @@ cliCommandP cfgPath logPath iniFile =
659659
initP :: Parser InitOptions
660660
initP = do
661661
enableStoreLog <-
662-
switch
663-
( long "store-log"
664-
<> short 'l'
665-
<> help "Enable store log for persistence"
662+
flag' False
663+
( long "disable-store-log"
664+
<> help "Disable store log for persistence (enabled by default)"
666665
)
666+
<|> flag True True
667+
( long "store-log"
668+
<> short 'l'
669+
<> help "Enable store log for persistence (DEPRECATED, enabled by default)"
670+
)
667671
dbOptions <- dbOptsP
668672
logStats <-
669673
switch

tests/CLITests.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cliTests = do
8080
smpServerTest :: Bool -> Bool -> IO ()
8181
smpServerTest storeLog basicAuth = do
8282
-- init
83-
capture_ (withArgs (["init", "-y"] <> ["-l" | storeLog] <> ["--no-password" | not basicAuth]) $ smpServerCLI cfgPath logPath)
83+
capture_ (withArgs (["init", "-y"] <> ["--disable-store-log" | not storeLog] <> ["--no-password" | not basicAuth]) $ smpServerCLI cfgPath logPath)
8484
>>= (`shouldSatisfy` (("Server initialized, please provide additional server information in " <> cfgPath <> "/smp-server.ini") `isPrefixOf`))
8585
Right ini <- readIniFile $ cfgPath <> "/smp-server.ini"
8686
lookupValue "STORE_LOG" "enable" ini `shouldBe` Right (if storeLog then "on" else "off")
@@ -184,7 +184,7 @@ smpServerTestStatic = do
184184

185185
ntfServerTest :: Bool -> IO ()
186186
ntfServerTest storeLog = do
187-
capture_ (withArgs (["init"] <> ["-l" | storeLog]) $ ntfServerCLI ntfCfgPath ntfLogPath)
187+
capture_ (withArgs (["init"] <> ["--disable-store-log" | not storeLog]) $ ntfServerCLI ntfCfgPath ntfLogPath)
188188
>>= (`shouldSatisfy` (("Server initialized, you can modify configuration in " <> ntfCfgPath <> "/ntf-server.ini") `isPrefixOf`))
189189
Right ini <- readIniFile $ ntfCfgPath <> "/ntf-server.ini"
190190
lookupValue "STORE_LOG" "enable" ini `shouldBe` Right (if storeLog then "on" else "off")
@@ -202,7 +202,7 @@ ntfServerTest storeLog = do
202202

203203
xftpServerTest :: Bool -> IO ()
204204
xftpServerTest storeLog = do
205-
capture_ (withArgs (["init", "-p", "tests/tmp", "-q", "10gb"] <> ["-l" | storeLog]) $ xftpServerCLI fileCfgPath fileLogPath)
205+
capture_ (withArgs (["init", "-p", "tests/tmp", "-q", "10gb"] <> ["--disable-store-log" | not storeLog]) $ xftpServerCLI fileCfgPath fileLogPath)
206206
>>= (`shouldSatisfy` (("Server initialized, you can modify configuration in " <> fileCfgPath <> "/file-server.ini") `isPrefixOf`))
207207
Right ini <- readIniFile $ fileCfgPath <> "/file-server.ini"
208208
lookupValue "STORE_LOG" "enable" ini `shouldBe` Right (if storeLog then "on" else "off")

0 commit comments

Comments
 (0)