diff --git a/ChangeLog.md b/ChangeLog.md index 266afbe..fc57a6a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,21 @@ # Changelog for haskellDB ## Unreleased changes + +## [V0.1] - 2019/10/09 +### Added +- First working version of the software! + +## [V0.2] - 2019/10/22 +### Added +- Functions for tracking use of processings and filaments + +### Fixed +- Dropdown menu behaviour in the client interface + +## [V0.3] - 2019/11/03 +### Added +- This CHANGELOG + +### Changed +- There is no more need for storing passwords in plain text! Check the README for more info! diff --git a/README.md b/README.md index 011e213..c22f1df 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ It's a lovely mix of Haskell, HTML, Javascript and CSS. dbLocation="localhost" dbPort=5432 dbUser="your_db_user" - dbPswd="your_db_user_password" port=8080 apiName="MSManager" ``` @@ -32,20 +31,19 @@ It's a lovely mix of Haskell, HTML, Javascript and CSS. The following steps are needed to create the first admin user. -- In the GHCI prompt use `connectWithInfo "localhost" 5432 "your_db_user" "your_db_user_password" "name_of_your_db" >>= insertUser "username" "password"`, changing the function arguments with the ones yuo need and wish to use. +- In the GHCI prompt use `connectWithInfo "localhost" 5432 "your_db_user" "your_db_user_password" "name_of_your_db" >>= insertUser "username" "password"`, changing the function arguments with the ones you need and wish to use. - Open pgAdmin (or whatever tool you use to execute queries in the database) and execute the query `UPDATE utenti SET admin = true WHERE username = 'username'`, changing username with the one chosen in the previous step. You have now created your first admin user! -- Return to the GHCI prompt, use `main` +- Return to the GHCI prompt, use `:main PASSWORD`, where PASSWORD is the password of the PostgreSQL user you used in the "server.cfg" file + - If you wish to execute the server outside of the GHCI prompt (and that would be great!) use Stack to build and install the application, and call it from the command line with PASSWORD as the first argument - Open your browser, and connect to `localhost:8080` - The web interface was tested on Firefox, but it should work on other browsers too (please, avoid Internet Explorer) - That's it. Log in, and everything should work! ## A little disclaimer - This system doesn't aim to be safe: at the moment, I don't have the knowledge to make it safe. So, it isn't. Don't use as if it were. In particular, the main problems are: - - the database password is saved in a plain-text file. I think it's pretty clear why that's bad - - knowing that, notice that the users' data is at risk, too - there is no safe connection to the server (no https), so your passwords are sent without encryption - This is not easy to install, and some operations are doable only through SQL queries: again, I have neither the knowledge nor the time to resolve this - The user interface is probably badly written, and not accessible: I'm still learning, and I will (probably) correct it in the future diff --git a/app/Main.hs b/app/Main.hs index a7f1eb4..8477c45 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,12 +2,26 @@ module Main where +import Data.Semigroup ((<>)) +import Options.Applicative +import Query import Schema import Server -import Query configFile :: FilePath configFile = "server.cfg" +passwordParser :: Parser String +passwordParser = argument str (metavar "PASSWORD") + +pswdInfo :: ParserInfo String +pswdInfo = + info (passwordParser <**> helper) + ( fullDesc + <> progDesc "Starts the server application using the PASSWORD for connecting to the database" + ) + main :: IO () -main = parseConfig configFile >>= runServer +main = do + pswd <- execParser pswdInfo + parseConfig configFile >>= (flip runServer pswd) diff --git a/package.yaml b/package.yaml index 10d0d46..d009a6f 100644 --- a/package.yaml +++ b/package.yaml @@ -30,6 +30,7 @@ dependencies: - hvect - memory - mtl +- optparse-applicative - postgresql-libpq - scientific - Spock >= 0.11 diff --git a/src/Server.hs b/src/Server.hs index a8feb36..5cd2f16 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -42,7 +42,6 @@ data ApiCfg acfg_db_location :: Text, acfg_db_port :: Integer, acfg_db_user :: Text, - acfg_db_pswd :: Text, acfg_port :: Int, acfg_name :: Text } @@ -72,10 +71,9 @@ parseConfig cfgFile = do dbLocation <- C.require cfg "dbLocation" dbPort <- C.require cfg "dbPort" dbUser <- C.require cfg "dbUser" - dbPassword <- C.require cfg "dbPswd" port <- C.require cfg "port" name <- C.require cfg "apiName" - return (ApiCfg db dbLocation dbPort dbUser dbPassword port name) + return (ApiCfg db dbLocation dbPort dbUser port name) -- |Function used to get the connection used to interrogate the database getFabLabConnection @@ -210,13 +208,14 @@ missingParameter :: MonadIO m => ActionCtxT ctx m b missingParameter = messageJson 422 "Parametro mancante" -- server functions -runServer :: ApiCfg -> IO () -runServer cfg = +-- |Runs the server using the given configuration and the password for the database +runServer :: ApiCfg -> String -> IO () +runServer cfg pswd = let ioConn = getFabLabConnection (unpack $ acfg_db_location cfg) (acfg_db_port cfg) (unpack $ acfg_db_user cfg) - (unpack $ acfg_db_pswd cfg) + pswd (unpack $ acfg_db cfg) in do spockCfg <- defaultSpockCfg Nothing (getPoolOrConn ioConn) () @@ -456,7 +455,7 @@ app = do else missingParameter post "assign_cut_operator" $ do maybeCf <- param "operator" - maybeCode <- param "print" + maybeCode <- param "cut" if testParameters [maybeCode, maybeCf] then executeModifyQueryAndSendResult