class ApacheConfFile def initialize(conf_file_path) if conf_file_path.nil? or not File.file?(conf_file_path) raise(ArgumentError.new('How about passing in a real file?')) end # Read each line of the conf file into an array. # Apache config directives are all one-line, right? @file_lines = [] File::open(conf_file_path) do |f| @file_lines = f.readlines() end if @file_lines.length < 1 raise(ArgumentError.new('Your file sucks.')) end end def get_php_admin_values(directive_name) # First, we have to regex-ize the directive name, # since they can contain periods (at the least!). directive_name.sub!('.', '\.') # Our return variable, an array of matching directive values. values = [] # Loop through each line in the conf file looking a # matching pattern. @file_lines.each do |line| matches = line.match(/php_admin_value[[:space:]]+#{directive_name}[[:space:]](.*)$/) if not matches.nil? # If there's a match, there should be only one # (in addition to [0], the entire matched string). if matches.length > 2 raise(StandardError.new('Matched the Regex more than once?')) end # If there's only one, add it to our list. # These are probably likely to have some extra # whitespace around them one way or another. values << matches[1].strip end end return values end def get_php_temporary_directory_list(remove_duplicates = true) # Return a list of all PHP "temporary" directories. # I.e. upload_tmp_dir, session.save_path temp_dirs = [] temp_dirs += self.get_php_admin_values('upload_tmp_dir') temp_dirs += self.get_php_admin_values('session.save_path') # We expect these to have been strip()ed already if remove_duplicates return temp_dirs.uniq else return temp_dirs end end end