Browse Source

Get Linux OS specific Apache conf file

master
Pekka Helenius 2 years ago
parent
commit
b5799df58f
1 changed files with 38 additions and 6 deletions
  1. +38
    -6
      apache-logparser/logparser.py

+ 38
- 6
apache-logparser/logparser.py View File

@ -78,6 +78,34 @@ class program(object):
} }
return out_fields return out_fields
"""
Get default Apache HTTPD configuration file location
"""
def get_apache_conf_path(self):
path = None
os_data_file = '/etc/os-release'
conf_path = [
{ 'os_check_file': os_data_file, 'os_like': 'Arch Linux', 'path': '/etc/httpd/conf/httpd.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'Debian', 'path': '/etc/apache2/apache2.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'Ubuntu', 'path': '/etc/apache2/apache2.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'Linux Mint', 'path': '/etc/apache2/apache2.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'openSUSE', 'path': '/etc/apache2/httpd.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'Gentoo', 'path': '/etc/apache2/httpd.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'Red Hat', 'path': '/etc/httpd/conf/httpd.conf'},
{ 'os_check_file': os_data_file, 'os_like': 'Fedora', 'path': '/etc/httpd/conf/httpd.conf'}
]
if self.check_file(os_data_file, "os.R_OK"):
with open(os_data_file, 'r') as f:
for line in f:
if re.match('^[ ]?NAME=\"', line):
for a in conf_path:
if re.match('.*' + a['os_like'] + '.*', line):
path = a['path']
return path
return path
""" """
Argument parser Argument parser
""" """
@ -111,21 +139,22 @@ class program(object):
'-c', '--status-codes', '-c', '--status-codes',
help = 'Print only these numerical status codes.\nRegular expressions supported.', help = 'Print only these numerical status codes.\nRegular expressions supported.',
nargs = '+', nargs = '+',
dest = 'codes'
dest = 'codes',
required = False
) )
argparser.add_argument( argparser.add_argument(
'-cf', '--countries', '-cf', '--countries',
help = 'Include only these countries.\nNegative match (exclude): "\!Country"', help = 'Include only these countries.\nNegative match (exclude): "\!Country"',
nargs = '?', nargs = '?',
type = lambda x: [i for i in x.split(',')], type = lambda x: [i for i in x.split(',')],
dest = 'countries'
dest = 'countries',
required = False
) )
argparser.add_argument( argparser.add_argument(
'-tf', '--time-format', '-tf', '--time-format',
help = 'Output time format.', help = 'Output time format.',
nargs = '?', nargs = '?',
dest = 'time_format', dest = 'time_format',
default = out_time_format
) )
argparser.add_argument( argparser.add_argument(
'-if', '--included-fields', '-if', '--included-fields',
@ -154,7 +183,7 @@ class program(object):
help = '"geoiplookup" tool executable found in PATH.', help = '"geoiplookup" tool executable found in PATH.',
nargs = '?', nargs = '?',
dest = 'geotool_exec', dest = 'geotool_exec',
default = "geoiplookup"
default = 'geoiplookup'
) )
argparser.add_argument( argparser.add_argument(
'-gd', '--geo-database-dir', '-gd', '--geo-database-dir',
@ -204,7 +233,7 @@ class program(object):
help = 'Apache HTTPD configuration file with LogFormat directive.', help = 'Apache HTTPD configuration file with LogFormat directive.',
action = 'store_true', action = 'store_true',
dest = 'httpd_conf_file', dest = 'httpd_conf_file',
default = '/etc/httpd/conf/httpd.conf'
default = self.get_apache_conf_path()
) )
argparser.add_argument( argparser.add_argument(
'--httpd-log-nickname', '--httpd-log-nickname',
@ -370,7 +399,10 @@ class program(object):
break break
if os.access(file_path, eval(flag)): if os.access(file_path, eval(flag)):
self.txt.print_verbose('File check', file_path, 'flags: ' + flag)
try:
self.txt.print_verbose('File check', file_path, 'flags: ' + flag)
except AttributeError:
pass
return True return True
return False return False


Loading…
Cancel
Save