ν`4 X d dl Z d dlZd dlZd dlZd dlmZmZmZmZ G d d Z dS ) N)DictListOptionalAnyc e Zd ZdZdej fdZdee fdZ defdZ dee fdZde eef fdZd ee dee fd Zd ee de eef fdZde eef fdZ ddede eef deddfdZdS )ApacheProcessorz? Collects Apache configuration and module information. loggerc b g d| _ g d| _ || _ d | _ d | _ d | _ d S )N)z/etc/apache2/conf/z/etc/apache2/conf-available/z/etc/apache2/conf.d/z/etc/apache2/conf.modules.d/)z$/etc/apache2/conf.d/userdata/ssl/2_4z$/etc/apache2/conf.d/userdata/std/2_4z$/etc/apache2/conf.d/userdata/ssl/2_2z$/etc/apache2/conf.d/userdata/std/2_2)apache_config_locationsuser_config_base_pathsr _apache_binary_cache_apache_version_cache_apache_modules_cache)selfr s +py/cl_website_collector/apache_processor.py__init__zApacheProcessor.__init__ sQ ( ( ( $' ' ' # $(!%)"%)""" returnc ` | j | j S d} dD ]]}t j | }|rEt j |t j r&| j d| || _ |c S ^n# t $ r}|}Y d}~nd}~ww xY w| j d| d| _ dS )zQ Find Apache binary executable using which command with caching. N)httpdapache2zFound Apache binary: %sz"Apache binary not found in PATH %s) r shutilwhichosaccessX_OKr debug Exception)r errorbinary_namebinary_pathes r _find_apache_binaryz#ApacheProcessor._find_apache_binary+ s $0,, 3 ' '$l;77 '29["'#B#B 'K%%&?MMM0;D-&&&& ' EEEEEE >FFF$(!ts AA3 1A3 3 B =BB c | j | j S | }|sd| _ | j S t j |dgdddd }|j dk rF|j }|r#| d d }|| _ n)d | _ n!d|j | _ n8# t j $ r d| _ Y n t $ r}d | | _ Y d}~nd}~ww xY w| j S )z> Get Apache version information with caching. NzApache binary not foundz-vT Fcapture_outputtexttimeoutcheckr zVersion info emptyzError getting version: zVersion check timed outzVersion check failed: )r r# subprocessrun returncodestdoutstripsplitstderrTimeoutExpiredr )r apache_binaryresultversion_output first_liner" s r _get_apache_versionz#ApacheProcessor._get_apache_versionA s\ %1--0022 .)BD&-- F^%# F A%%!'!4!4!6!6! F!/!5!5d!;!;A!>J1;D..1ED..-^v}GZGZG\G\-^-^*( C C C)BD&&& F F F)E!)E)ED&&&&&& F ))s B C C7 C7# C22C7c | j | j S | }|s(| j d g | _ | j S t j |dgdddd }|j dk rg }|j d }|d d D ]s}| s | d d }|r| | ]# t t f$ r Y pw xY w| j dt | | || _ |S | j d |j g | _ | j S # t j $ r+ | j d g | _ | j cY S t" $ r3}| j d| g | _ | j cY d}~S d}~ww xY w)z Get Apache modules using httpd -M command with caching. Returns: List of module names (e.g., ['core_module', 'so_module', 'http_module', ...]) Nz+Apache binary not found, cannot get modulesz-MTr% Fr&