Dynamically update user list

This commit is contained in:
floppydiskette 2024-08-13 15:45:55 +01:00
commit f751af45ef
No known key found for this signature in database
4 changed files with 28 additions and 8 deletions

View file

@ -1,2 +1,23 @@
require 'open3'
module HomeHelper
def list_all_users
stdout, stderr, status = Open3.capture3('getent', 'passwd')
return [] unless status.success?
valid_users = stdout.split("\n").select { |user| user.start_with?(/\w/) }.map(&:split).map(&:first)
valid_users.map do |user|
user.split(':')[0]
end
end
def users_with_public_html(users)
users.select do |user|
home_dir = Dir.home(user)
File.exist?(File.join(home_dir, 'public_html'))
end
end
users = list_all_users
users_with_public_html(users)
end