require 'optparse' require 'ftools' require 'fileutils' module Rpanel class CLI IGNORE_DIRECTORIES = ['.', '..','.cpan', '.cpcpan', 'cpeasyapache', 'cprubybuild', 'cprubygemsbuild', 'domlogs', 'liquidweb', 'lost+found', 'fantasti', 'MySQL-install', 'virtfs'] def self.execute(stdout, arguments=[]) options = { :fix_sc => nil, :fix_owner => nil, :fix_files => nil, :fix_directories => nil, :username => nil, :all_accounts => nil } mandatory_options = %w( ) parser = OptionParser.new do |opts| opts.banner = <<-BANNER.gsub(/^ /,'') This application is wonderful because... Usage: #{File.basename($0)} [options] Options are: BANNER opts.separator "" opts.on("-l", "--list", "List all accounts"){ |arg| options[:list] = true } opts.on("-s", "--fix-source-control", "Ensure .svn or .git directories are not group or world-readable") { |arg| options[:fix_sc] = true } opts.on("-o", "--fix-owner", "Ensure all files in public_html are owned by the account username") { |arg| options[:fix_owner] = true } opts.on("-f", "--fix-files", "Ensure all normal files are set no higher than 0644") { |arg| options[:fix_files] = true } opts.on("-d", "--fix-directories", "Ensure all normal files are set no higher than 0755") { |arg| options[:fix_directories] = true } opts.on("-u", "--apply-user=USER", String, "Your cpanel account username (ex: peppyhep)") { |arg| options[:username] = arg.strip } opts.on("-a", "--apply-all-accounts", "Value for PassengerPoolIdleTime which sets the idle time", "for an application instance before it shuts down") { |arg| options[:apply_all_accounts] = true } opts.on("-e", "--all", "Value for PassengerPoolIdleTime which sets the idle time", "for an application instance before it shuts down") {|args| options[:all] = true } opts.on("-h", "--help", "Show this help message.") { stdout.puts opts; exit } opts.parse!(arguments) if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? } stdout.puts opts; exit end end if options[:list] dirs = Dir.entries('/Users/jerrod') - IGNORE_DIRECTORIES accounts = dirs.sort{|a,z| a.downcase <=>z.downcase} puts accounts end username = options[:username] if options[:all] options[:fix_sc] = true options[:fix_owner] = true options[:fix_files] = true options[:fix_directories] = true end puts "-s" if options[:fix_sc] puts "-o" if options[:fix_owner] puts "-f" if options[:fix_files] puts "-d" if options[:fix_directories] puts "-u" if options[:username] puts "-a" if options[:apply_all_accounts] stdout.puts "* Checking permissions for #{username}" # raise "Path is required!" unless File.directory?(rails_app_path) or File.directory?("#{rails_app_path}/public") # FileUtils::mkdir_p(config_path) end end end