feat: moved services from source to here, still untested: vsftpd,
mongodb, mysql, nginx
This commit is contained in:
21
services/vsftpd/serverman-service-vsftpd.cabal
Normal file
21
services/vsftpd/serverman-service-vsftpd.cabal
Normal file
@ -0,0 +1,21 @@
|
||||
name: serverman-service-vsftpd
|
||||
version: 0.1.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
homepage: https://github.com/mdibaiee/vsftpd#readme
|
||||
license: GPL-3
|
||||
license-file: LICENSE
|
||||
author: Mahdi Dibaiee
|
||||
maintainer: mahdi@theread.me
|
||||
copyright: 2017 Mahdi Dibaiee
|
||||
category: ftp
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
|
||||
executable vsftpd
|
||||
hs-source-dirs: src
|
||||
main-is: Main.hs
|
||||
default-language: Haskell2010
|
||||
build-depends: base >= 4.7 && < 5
|
||||
, data-default-class
|
||||
, mtl
|
50
services/vsftpd/src/Main.hs
Normal file
50
services/vsftpd/src/Main.hs
Normal 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 ()
|
55
services/vsftpd/src/Types.hs
Normal file
55
services/vsftpd/src/Types.hs
Normal 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")] "="
|
66
services/vsftpd/stack.yaml
Normal file
66
services/vsftpd/stack.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
# This file was automatically generated by 'stack init'
|
||||
#
|
||||
# Some commonly used options have been documented as comments in this file.
|
||||
# For advanced use and comprehensive documentation of the format, please see:
|
||||
# http://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||
|
||||
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
|
||||
# A snapshot resolver dictates the compiler version and the set of packages
|
||||
# to be used for project dependencies. For example:
|
||||
#
|
||||
# resolver: lts-3.5
|
||||
# resolver: nightly-2015-09-21
|
||||
# resolver: ghc-7.10.2
|
||||
# resolver: ghcjs-0.1.0_ghc-7.10.2
|
||||
# resolver:
|
||||
# name: custom-snapshot
|
||||
# location: "./custom-snapshot.yaml"
|
||||
resolver: lts-8.5
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
#
|
||||
# packages:
|
||||
# - some-directory
|
||||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||
# - location:
|
||||
# git: https://github.com/commercialhaskell/stack.git
|
||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
# extra-dep: true
|
||||
# subdirs:
|
||||
# - auto-update
|
||||
# - wai
|
||||
#
|
||||
# A package marked 'extra-dep: true' will only be built if demanded by a
|
||||
# non-dependency (i.e. a user package), and its test suites and benchmarks
|
||||
# will not be run. This is useful for tweaking upstream packages.
|
||||
packages:
|
||||
- '.'
|
||||
# Dependency packages to be pulled from upstream that are not in the resolver
|
||||
# (e.g., acme-missiles-0.3)
|
||||
extra-deps: []
|
||||
|
||||
# Override default flag values for local packages and extra-deps
|
||||
flags: {}
|
||||
|
||||
# Extra package databases containing global packages
|
||||
extra-package-dbs: []
|
||||
|
||||
# Control whether we use the GHC we find on the path
|
||||
# system-ghc: true
|
||||
#
|
||||
# Require a specific version of stack, using version ranges
|
||||
# require-stack-version: -any # Default
|
||||
# require-stack-version: ">=1.1"
|
||||
#
|
||||
# Override the architecture used by stack, especially useful on Windows
|
||||
# arch: i386
|
||||
# arch: x86_64
|
||||
#
|
||||
# Extra directories used by stack for building
|
||||
# extra-include-dirs: [/path/to/dir]
|
||||
# extra-lib-dirs: [/path/to/dir]
|
||||
#
|
||||
# Allow a newer minor version of GHC than the snapshot specifies
|
||||
# compiler-check: newer-minor
|
Reference in New Issue
Block a user