2016-10-06 19:31:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class FtpConfig
|
|
|
|
def build_password_list accounts
|
2016-10-09 20:58:30 -05:00
|
|
|
`sudo chown $(whoami) #{password_file}`
|
2016-10-06 19:31:31 -05:00
|
|
|
File.open(password_file, "w+") do |file|
|
|
|
|
Array(accounts).each do |account|
|
|
|
|
file.write "#{account.username}:#{hash_password(account.password)}"
|
|
|
|
end
|
|
|
|
end
|
2016-10-09 20:58:30 -05:00
|
|
|
`sudo chown root #{password_file}`
|
2016-10-06 19:31:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_user_configs accounts
|
2016-10-09 20:58:30 -05:00
|
|
|
`sudo chown -R $(whoami) #{config_path}`
|
2016-10-06 19:31:31 -05:00
|
|
|
Array(accounts).each do |account|
|
|
|
|
File.open("#{config_path}#{account.username}", "w+") do |file|
|
2016-10-09 20:58:30 -05:00
|
|
|
`sudo -u #{ftp_user} mkdir -p #{ftp_root}#{account.home_folder}`
|
2016-10-06 19:31:31 -05:00
|
|
|
file.write "local_root=#{ftp_root}#{account.home_folder}"
|
|
|
|
end
|
|
|
|
end
|
2016-10-09 20:58:30 -05:00
|
|
|
`sudo chown -R root #{config_path}`
|
2016-10-06 19:31:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def password_file
|
|
|
|
AppConfig.htpasswd
|
|
|
|
end
|
|
|
|
|
|
|
|
def config_path
|
|
|
|
AppConfig.ftpusers
|
|
|
|
end
|
|
|
|
|
|
|
|
def ftp_root
|
|
|
|
AppConfig.ftproot
|
|
|
|
end
|
|
|
|
|
2016-10-09 20:58:30 -05:00
|
|
|
def ftp_user
|
|
|
|
AppConfig.ftpaccount
|
|
|
|
end
|
|
|
|
|
2016-10-06 19:31:31 -05:00
|
|
|
def hash_password password
|
|
|
|
`openssl passwd -1 -noverify -quiet #{password}`
|
|
|
|
end
|
|
|
|
end
|