]>
gitweb.michael.orlitzky.com - dead/janitor.git/blob - src/apache_conf_file.rb
3 def initialize(conf_file_path
)
4 if conf_file_path
.nil? or not File
.file
?(conf_file_path
)
5 raise(ArgumentError
.new('How about passing in a real file?'))
8 # Read each line of the conf file into an array.
9 # Apache config directives are all one-line, right?
12 File
::open(conf_file_path
) do |f
|
13 @file_lines = f
.readlines()
16 if @file_lines.length
< 1
17 raise(ArgumentError
.new('Your file sucks.'))
23 def get_php_admin_values(directive_name
)
24 # First, we have to regex-ize the directive name,
25 # since they can contain periods (at the least!).
26 directive_name
.sub!
('.', '\.')
28 # Our return variable, an array of matching directive values.
31 # Loop through each line in the conf file looking a
33 @file_lines.each
do |line
|
34 matches
= line
.match(/php_admin_value[[:space:]]+#{directive_name}[[:space:]](.*)$/)
37 # If there's a match, there should be only one
38 # (in addition to [0], the entire matched string).
40 raise(StandardError
.new('Matched the Regex more than once?'))
43 # If there's only one, add it to our list.
44 # These are probably likely to have some extra
45 # whitespace around them one way or another.
46 values
<< matches
[1].strip
54 def get_php_temporary_directory_list(remove_duplicates
= true)
55 # Return a list of all PHP "temporary" directories.
56 # I.e. upload_tmp_dir, session.save_path
58 temp_dirs +
= self.get_php_admin_values('upload_tmp_dir')
59 temp_dirs +
= self.get_php_admin_values('session.save_path')
61 # We expect these to have been strip()ed already