<commit_before># apache-lib.pl
# Common functions for apache configuration

BEGIN { push(@INC, ".."); };
use WebminCore;
$directive_type_count = 20;

our ($saved_conf_files);

if ($module_name ne 'htaccess') {
	&init_config();
	%access = &get_module_acl();
	@access_types = $access{'types'} eq '*' ? (0 .. $directive_type_count)
					: split(/\s+/, $access{'types'});
	}
else {
	@access_types = (0 .. $directive_type_count);
	}
map { $access_types{$_}++ } @access_types;
$site_file = ($config{'webmin_apache'} || $module_config_directory)."/site";
$httpd_info_cache = $module_config_directory."/httpd-info";
$last_config_change_flag = $module_var_directory."/config-flag";
$last_restart_time_flag = $module_var_directory."/restart-flag";

# Check if a list of supported modules needs to be built. This is done
# if the Apache binary changes, when Webmin is upgraded, or once every five
# minutes if automatic rebuilding is enabled.
if ($module_name ne 'htaccess') {
	local %oldsite;
	local $httpd = &find_httpd();
	local @st = stat($httpd);
	&read_file($site_file, \%oldsite);
	local @sst = stat($site_file);
	if ($oldsite{'path'} ne $httpd ||
	    $oldsite{'size'} != $st[7] ||
	    $oldsite{'webmin'} != &get_webmin_version() ||
	    $config{'auto_mods'} && $sst[9] < time()-5*60) {
		# Need to build list of supported modules
		local ($ver, $mods, $fullver) = &httpd_info($httpd);
		if ($ver) {
			local @mods = map { "$_/$ver" } &configurable_modules();
			foreach my $m (@mods) {
				if ($m =~ /(\S+)\/(\S+)/) {
					$httpd_modules{$1} = $2;
					}
				}
			# Call again now that known modules have been set, as
			# sometimes there are dependencies due to LoadModule
			# statements in an IfModule block
			@mods = map { "$_/$ver" } &configurable_modules();
			local %site = ( 'size' => $st[7],
					'path' => $httpd,
					'modules' => join(' ', @mods),
					'version' => $ver,
					'fullversion' => $fullver,
					'webmin' => &get_webmin_version() );
			&lock_file($site_file);
			&write_file($site_file, \%site);
			chmod(0644, $site_file);
			&unlock_file($site_file);
			}
		}
	}

# Read the site-specific setup file, then require in all the module-specific
# .pl files
if (&read_file($site_file, \%site)) {
	local($m, $f, $d);
	$httpd_size = $site{'size'};
	foreach $m (split(/\s+/, $site{'modules'})) {
		if ($m =~ /(\S+)\/(\S+)/) {
			$httpd_modules{$1} = $2;
			}
		}
	foreach $m (keys %httpd_modules) {
		if (!-r "$module_root_directory/$m.pl") {
			delete($httpd_modules{$m});
			}
		}
	foreach $f (split(/\s+/, $site{'htaccess'})) {
		if (-r $f) { push(@htaccess_files, $f); }
		}
	foreach $m (keys %httpd_modules) {
		do "$m.pl";
		}
	foreach $d (split(/\s+/, $site{'defines'})) {
		$httpd_defines{$d}++;
		}
	}

$apache_docbase = $config{'apache_docbase'} ? $config{'apache_docbase'} :
		  $httpd_modules{'core'} >= 2.0 ?
			"http://httpd.apache.org/docs-2.0/mod/" :
			"http://httpd.apache.org/docs/mod/";

# parse_config_file(handle, lines, file, [recursive])
# Parses lines of text from some config file into a data structure. The
# return value is an array of references, one for each directive in the file.
# Each reference points to an associative array containing
#  line -	The line number this directive is at
#  eline -	The line number this directive ends at
#  file -	The file this directive is from
#  type -	0 for a normal directive, 1 for a container directive
#  name -	The name of this directive
#  value -	Value (possibly with spaces)
#  members -	For type 1, a reference to the array of members
#  indent -     Number of spaces before the name
sub parse_config_file
{
local($fh, @rv, $line, %dummy);
$fh = $_[0];
$dummy{'line'} = $dummy{'eline'} = $_[1]-1;
$dummy{'file'} = $_[2];
$dummy{'type'} = 0;
$dummy{'name'} = "dummy";
@rv = (\%dummy);
local %defs;
foreach my $d (&get_httpd_defines()) {
	if ($d =~ /^(\S+)=(.*)$/) {
		$defs{$1} = $2;
		}
	else {
		$defs{$d} = '';
		}
	}
while($line = <$fh>) {
	chop;
	$line =~ s/^\s*#.*$//g;
	if ($line =~ /^\s*<\/(\S+)\s*(.*)>/) {
		# end of a container directive. This can only happen in a
		# recursive call to this function
		$_[1]++;
		last if (lc($_[3]) eq lc($1));
		}
	elsif ($line =~ /^\s*<IfModule\s+(\!?)(\S+)\.c>/i ||
	       $line =~ /^\s*<IfModule\s+(\!?)(\S+)>/i) {
		# start of an IfModule block. Read it, and if the module
		# exists put the directives in this section.
		local ($not, $mod) = ($1, $2);
		local $oldline = $_[1];
		$_[1]++;
		local @dirs = &parse_config_file($fh, $_[1], $_[2], 'IfModule');
		local $altmod = $mod;
		$altmod =~ s/^(\S+)_module$/mod_$1/g;
		local $mpmmod = $mod;
		$mpmmod =~ s/^mpm_//; $mpmmod =~ s/_module$//;
		if (!$not && $httpd_modules{$mod} ||
		    $not && !$httpd_modules{$mod} ||
		    !$not && $httpd_modules{$altmod} ||
		    $not && !$httpd_modules{$altmod} ||<commit_msg>Handle case where <IfModeule prefork.c> is used<commit_after># apache-lib.pl
# Common functions for apache configuration

BEGIN { push(@INC, ".."); };
use WebminCore;
$directive_type_count = 20;

our ($saved_conf_files);

if ($module_name ne 'htaccess') {
	&init_config();
	%access = &get_module_acl();
	@access_types = $access{'types'} eq '*' ? (0 .. $directive_type_count)
					: split(/\s+/, $access{'types'});
	}
else {
	@access_types = (0 .. $directive_type_count);
	}
map { $access_types{$_}++ } @access_types;
$site_file = ($config{'webmin_apache'} || $module_config_directory)."/site";
$httpd_info_cache = $module_config_directory."/httpd-info";
$last_config_change_flag = $module_var_directory."/config-flag";
$last_restart_time_flag = $module_var_directory."/restart-flag";

# Check if a list of supported modules needs to be built. This is done
# if the Apache binary changes, when Webmin is upgraded, or once every five
# minutes if automatic rebuilding is enabled.
if ($module_name ne 'htaccess') {
	local %oldsite;
	local $httpd = &find_httpd();
	local @st = stat($httpd);
	&read_file($site_file, \%oldsite);
	local @sst = stat($site_file);
	if ($oldsite{'path'} ne $httpd ||
	    $oldsite{'size'} != $st[7] ||
	    $oldsite{'webmin'} != &get_webmin_version() ||
	    $config{'auto_mods'} && $sst[9] < time()-5*60) {
		# Need to build list of supported modules
		local ($ver, $mods, $fullver) = &httpd_info($httpd);
		if ($ver) {
			local @mods = map { "$_/$ver" } &configurable_modules();
			foreach my $m (@mods) {
				if ($m =~ /(\S+)\/(\S+)/) {
					$httpd_modules{$1} = $2;
					}
				}
			# Call again now that known modules have been set, as
			# sometimes there are dependencies due to LoadModule
			# statements in an IfModule block
			@mods = map { "$_/$ver" } &configurable_modules();
			local %site = ( 'size' => $st[7],
					'path' => $httpd,
					'modules' => join(' ', @mods),
					'version' => $ver,
					'fullversion' => $fullver,
					'webmin' => &get_webmin_version() );
			&lock_file($site_file);
			&write_file($site_file, \%site);
			chmod(0644, $site_file);
			&unlock_file($site_file);
			}
		}
	}

# Read the site-specific setup file, then require in all the module-specific
# .pl files
if (&read_file($site_file, \%site)) {
	local($m, $f, $d);
	$httpd_size = $site{'size'};
	foreach $m (split(/\s+/, $site{'modules'})) {
		if ($m =~ /(\S+)\/(\S+)/) {
			$httpd_modules{$1} = $2;
			}
		}
	foreach $m (keys %httpd_modules) {
		if (!-r "$module_root_directory/$m.pl") {
			delete($httpd_modules{$m});
			}
		}
	foreach $f (split(/\s+/, $site{'htaccess'})) {
		if (-r $f) { push(@htaccess_files, $f); }
		}
	foreach $m (keys %httpd_modules) {
		do "$m.pl";
		}
	foreach $d (split(/\s+/, $site{'defines'})) {
		$httpd_defines{$d}++;
		}
	}

$apache_docbase = $config{'apache_docbase'} ? $config{'apache_docbase'} :
		  $httpd_modules{'core'} >= 2.0 ?
			"http://httpd.apache.org/docs-2.0/mod/" :
			"http://httpd.apache.org/docs/mod/";

# parse_config_file(handle, lines, file, [recursive])
# Parses lines of text from some config file into a data structure. The
# return value is an array of references, one for each directive in the file.
# Each reference points to an associative array containing
#  line -	The line number this directive is at
#  eline -	The line number this directive ends at
#  file -	The file this directive is from
#  type -	0 for a normal directive, 1 for a container directive
#  name -	The name of this directive
#  value -	Value (possibly with spaces)
#  members -	For type 1, a reference to the array of members
#  indent -     Number of spaces before the name
sub parse_config_file
{
local($fh, @rv, $line, %dummy);
$fh = $_[0];
$dummy{'line'} = $dummy{'eline'} = $_[1]-1;
$dummy{'file'} = $_[2];
$dummy{'type'} = 0;
$dummy{'name'} = "dummy";
@rv = (\%dummy);
local %defs;
foreach my $d (&get_httpd_defines()) {
	if ($d =~ /^(\S+)=(.*)$/) {
		$defs{$1} = $2;
		}
	else {
		$defs{$d} = '';
		}
	}
while($line = <$fh>) {
	$line =~ s/\r|\n//g;
	$line =~ s/^\s*#.*$//g;
	if ($line =~ /^\s*<\/(\S+)\s*(.*)>/) {
		# end of a container directive. This can only happen in a
		# recursive call to this function
		$_[1]++;
		last if (lc($_[3]) eq lc($1));
		}
	elsif ($line =~ /^\s*<IfModule\s+(\!?)(\S+)\.c>/i ||
	       $line =~ /^\s*<IfModule\s+(\!?)(\S+)>/i) {
		# start of an IfModule block. Read it, and if the module
		# exists put the directives in this section.
		local ($not, $mod) = ($1, $2);
		local $oldline = $_[1];
		$_[1]++;
		local @dirs = &parse_config_file($fh, $_[1], $_[2], 'IfModule');
		local $altmod = $mod;
		$altmod =~ s/^(\S+)_module$/mod_$1/g;
		local $mpmmod = $mod;
		$mpmmod =~ s/^mpm_//; $mpmmod =~ s/_module$//;
		if ($mod eq "prefork") {
			# Special case for all the prefork aliases
			($mod, $altmod, $mpmmod) = ("mod_".$mod."_module",
						    "mod_mpm_".$mod, $mod);
			}
		if (!$not && $httpd_modules{$mod} ||
		    $not && !$httpd_modules{$mod} ||
		    !$not && $httpd_modules{$altmod} ||
		    $not && !$httpd_modules{$altmod} ||
{'fraction_non_alphanumeric': 0.20536530840361752, 'fraction_numerical': 0.008535717914846053, 'mean_word_length': 3.646836638338055, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1161060', 'n_tokens_mistral': 4093, 'n_tokens_neox': 3759, 'n_words': 962}