From f64668543d9062d3fa7844337f23669951626fd3 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Sun, 9 Oct 2016 20:58:30 -0500 Subject: [PATCH] bad file access "fix" --- app/services/ftp_config.rb | 10 +++++++++- config/application.yml.sample | 1 + config/environments/development.rb | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/services/ftp_config.rb b/app/services/ftp_config.rb index 6113f54..87c9c62 100644 --- a/app/services/ftp_config.rb +++ b/app/services/ftp_config.rb @@ -1,20 +1,24 @@ # frozen_string_literal: true class FtpConfig def build_password_list accounts + `sudo chown $(whoami) #{password_file}` File.open(password_file, "w+") do |file| Array(accounts).each do |account| file.write "#{account.username}:#{hash_password(account.password)}" end end + `sudo chown root #{password_file}` end def build_user_configs accounts + `sudo chown -R $(whoami) #{config_path}` Array(accounts).each do |account| File.open("#{config_path}#{account.username}", "w+") do |file| - FileUtils.mkdir_p "#{ftp_root}#{account.home_folder}" + `sudo -u #{ftp_user} mkdir -p #{ftp_root}#{account.home_folder}` file.write "local_root=#{ftp_root}#{account.home_folder}" end end + `sudo chown -R root #{config_path}` end private @@ -31,6 +35,10 @@ class FtpConfig AppConfig.ftproot end + def ftp_user + AppConfig.ftpaccount + end + def hash_password password `openssl passwd -1 -noverify -quiet #{password}` end diff --git a/config/application.yml.sample b/config/application.yml.sample index 400a78c..8e714dd 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -13,6 +13,7 @@ defaults: &defaults htpasswd: "/path/to/vsftpd/password.file" ftpusers: "/path/to/vsftpd/users/configs" ftproot: "/path/to/root/ftp/prefix/" + ftpaccount: vsftpd development: <<: *defaults diff --git a/config/environments/development.rb b/config/environments/development.rb index 613b531..903b694 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -52,4 +52,6 @@ Rails.application.configure do # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.web_console.whitelisted_ips = '192.168.76.0/16' end