service object to write out config files
This commit is contained in:
36
app/services/ftp_config.rb
Normal file
36
app/services/ftp_config.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
class FtpConfig
|
||||
def build_password_list accounts
|
||||
File.open(password_file, "w+") do |file|
|
||||
Array(accounts).each do |account|
|
||||
file.write "#{account.username}:#{hash_password(account.password)}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def build_user_configs accounts
|
||||
Array(accounts).each do |account|
|
||||
File.open("#{config_path}#{account.username}", "w+") do |file|
|
||||
file.write "local_root=#{ftp_root}#{account.home_folder}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def password_file
|
||||
AppConfig.htpasswd
|
||||
end
|
||||
|
||||
def config_path
|
||||
AppConfig.ftpusers
|
||||
end
|
||||
|
||||
def ftp_root
|
||||
AppConfig.ftproot
|
||||
end
|
||||
|
||||
def hash_password password
|
||||
`openssl passwd -1 -noverify -quiet #{password}`
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user