From 697c8962772d4e3945625ad084124c6e8f31dc50 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 6 Oct 2016 20:10:36 -0500 Subject: [PATCH] db hook to manage files --- .gitignore | 1 + .rubocop.yml | 4 ++++ README.md | 2 ++ _vsftpd/ftpd.passwd | 3 --- _vsftpd/users/client-one | 1 - _vsftpd/users/client-three | 1 - _vsftpd/users/client-two | 1 - app/models/account.rb | 8 ++++++++ test/fixtures/accounts.yml | 2 +- test/test_helper.rb | 13 +++++++++++++ 10 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 _vsftpd/ftpd.passwd delete mode 100644 _vsftpd/users/client-one delete mode 100644 _vsftpd/users/client-three delete mode 100644 _vsftpd/users/client-two diff --git a/.gitignore b/.gitignore index da83347..ca0f56b 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ application.yml # Ignore application configuration /config/application.yml .container-setup +_vsftpd diff --git a/.rubocop.yml b/.rubocop.yml index 2b4f22a..79e2098 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,10 @@ Style/ClassAndModuleChildren: Exclude: - test/test_helper.rb +Style/ClassVars: + Exclude: + - test/test_helper.rb + Style/Documentation: Enabled: false diff --git a/README.md b/README.md index c7626ff..fbc1f2f 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ A simple FTP Virtual User manager + +* be sure to set up config/application.yml[.sample] diff --git a/_vsftpd/ftpd.passwd b/_vsftpd/ftpd.passwd deleted file mode 100644 index 4957595..0000000 --- a/_vsftpd/ftpd.passwd +++ /dev/null @@ -1,3 +0,0 @@ -client-two:$1$Uoqdsd1f$A39luV6N91OtA/VvcdBfC0 -client-one:$1$cVA6ZMIU$K/ITsDMZWeEDFEvoWk0op. -client-three:$1$pGYnsuhu$3MPEsgikbEhX1mZQE/qDc/ diff --git a/_vsftpd/users/client-one b/_vsftpd/users/client-one deleted file mode 100644 index 72f531f..0000000 --- a/_vsftpd/users/client-one +++ /dev/null @@ -1 +0,0 @@ -local_root=_vsftpd/root/client_one \ No newline at end of file diff --git a/_vsftpd/users/client-three b/_vsftpd/users/client-three deleted file mode 100644 index 6dcf1db..0000000 --- a/_vsftpd/users/client-three +++ /dev/null @@ -1 +0,0 @@ -local_root=_vsftpd/root/client_three \ No newline at end of file diff --git a/_vsftpd/users/client-two b/_vsftpd/users/client-two deleted file mode 100644 index bc2b378..0000000 --- a/_vsftpd/users/client-two +++ /dev/null @@ -1 +0,0 @@ -local_root=_vsftpd/root/client_two \ No newline at end of file diff --git a/app/models/account.rb b/app/models/account.rb index 4b853e3..153cfc3 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -6,4 +6,12 @@ class Account < ApplicationRecord validates :password, presence: true validates :home_folder, presence: true validates :contact_email, presence: true, email_format: true + + after_commit :update_vsftpd_files + + def update_vsftpd_files + vsftp = FtpConfig.new + vsftp.build_password_list Account.all + vsftp.build_user_configs self + end end diff --git a/test/fixtures/accounts.yml b/test/fixtures/accounts.yml index e3db3ba..fdb7c80 100644 --- a/test/fixtures/accounts.yml +++ b/test/fixtures/accounts.yml @@ -8,7 +8,7 @@ account1: account2: username: client-two - password: <%= CryptSerializer.dump('azsxdcfvgbhnjmk,l.;/') %> + password: <%= CryptSerializer.dump('azsxdcfvgbhnjmk,l') %> home_folder: client_two contact_email: ftp-user@mailinator.com diff --git a/test/test_helper.rb b/test/test_helper.rb index b18749f..b320d2a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,4 +24,17 @@ class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all + + @@files_checked = false + def verify_test_files + return if @@files_checked + + FileUtils.mkdir_p AppConfig.ftpusers + FileUtils.touch AppConfig.htpasswd + @@files_checked = true + end + + def setup + verify_test_files + end end