feat: moved services from source to here, still untested: vsftpd,

mongodb, mysql, nginx
This commit is contained in:
Mahdi Dibaiee
2017-03-18 18:06:18 +03:30
parent a5cc8582fc
commit 5550b17522
22 changed files with 990 additions and 8 deletions

View File

@ -0,0 +1,50 @@
{-# LANGUAGE NamedFieldPuns #-}
module Main (call, main) where
import System.Serverman.Types
import System.Serverman.Utils
import Types
import System.Directory hiding (writable)
import System.IO
import System.IO.Error
import System.FilePath
import System.Process
import Control.Concurrent.Async
import Control.Monad
import Control.Monad.Free
import Data.List
import Data.Either
import Control.Monad.State
call :: Service -> App ()
call s@(Service { name, version, service })= do
(AppState { os, arguments }) <- get
let params@(FileSharingParams { directory, port, user, pass, anonymous, anonymousWrite, writable, recreateUser }) = toFSParams arguments
let content = show params
config = "/etc/"
original = config </> "vsftpd.conf"
userList = config </> "vsftpd-serverman-user-list"
when recreateUser $ executeRoot "userdel" [user] "" True >> return ()
(Right opensslResponse) <- execute "openssl" ["passwd", "-1", pass] "" True
let encryptedPassword = head . lines $ opensslResponse
executeRoot "useradd" [user, "-d", directory, "-G", "ftp", "-p", encryptedPassword] "" True
liftIO $ do
renameFileIfMissing original (original ++ ".backup")
writeFile original content
writeFile userList user
result <- restartService "vsftpd"
case result of
Left err -> return ()
Right _ ->
liftIO $ putStrLn $ "restarted vsftpd"
main :: IO ()
main = return ()

View File

@ -0,0 +1,55 @@
{-# LANGUAGE NamedFieldPuns #-}
module Types ( FileSharingParams (..)
, toFSParams) where
import System.Serverman.Utils
import Data.Default.Class
toFSParams :: [(String, Maybe String)] -> FileSharingParams
toFSParams (("directory", Just value):xs) = (toFSParams xs) { directory = value }
toFSParams (("user", Just value):xs) = (toFSParams xs) { user = value }
toFSParams (("pass", Just value):xs) = (toFSParams xs) { pass = value }
toFSParams (("port", Just value):xs) = (toFSParams xs) { port = value }
toFSParams (("writable", Nothing):xs) = (toFSParams xs) { writable = True }
toFSParams (("anonymous", Nothing):xs) = (toFSParams xs) { anonymous = True }
toFSParams (("anonymous-write", Nothing):xs) = (toFSParams xs) { anonymousWrite = True }
toFSParams (("recreate-user", Nothing):xs) = (toFSParams xs) { recreateUser = True }
toFSParams _ = def
data FileSharingParams = FileSharingParams { directory :: FilePath
, user :: String
, pass :: String
, port :: String
, writable :: Bool
, anonymous :: Bool
, anonymousWrite :: Bool
, recreateUser :: Bool
} deriving (Eq)
instance Default FileSharingParams where
def = FileSharingParams { directory = "/srv/ftp/serverman"
, user = "serverman"
, pass = "serverman"
, port = "20"
, writable = True
, anonymous = False
, anonymousWrite = False
, recreateUser = False
}
instance Show FileSharingParams where
show (FileSharingParams { directory, user, pass, port, writable, anonymous, anonymousWrite }) =
let boolToEnglish True = "YES"
boolToEnglish False = "NO"
in
keyvalue [ ("anonymous_enable", boolToEnglish anonymous)
, ("write_enable", boolToEnglish writable)
, ("allow_writeable_chroot", boolToEnglish writable)
, ("anon_upload_enable", boolToEnglish anonymousWrite)
, ("anon_mkdir_write_enable", boolToEnglish anonymousWrite)
, ("listen", "YES")
, ("userlist_enable", "YES")
, ("userlist_file", "/etc/vsftpd-serverman-user-list")
, ("userlist_deny", "NO")
, ("chroot_local_user", "YES")
, ("xferlog_enable", "YES")
, ("local_enable", "YES")] "="