From bf6a0a31b4a357136ff0784dd77c6c42c6635cb0 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Wed, 26 Mar 2008 17:46:41 +0000 Subject: factorize writting a single config line --- bin/drakguard | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'bin') diff --git a/bin/drakguard b/bin/drakguard index fdfe011..91de07a 100755 --- a/bin/drakguard +++ b/bin/drakguard @@ -205,15 +205,21 @@ sub save() { quit_gui(); } +sub subst_config_line { + my ($file, $line) = @_; + my $key = first(split(' ', $line)); + my $done; + substInFile { + $done = 1 if s|^\s*$key\b.*\n|$line|; + $_ .= $line if eof && !$done; + } $file; +} + sub enable_transparent_proxy { my ($port) = @_; #- FIXME: use network::squid once it is rewritten to be more gentle with the config file - my $done; my $to_add = "http_port $port transparent\n"; - substInFile { - $done = 1 if s|^\s*http_port.*\n|$to_add|; - $_ .= $to_add if eof && !$done; - } $network::squid::squid_conf_file; + subst_config_line($network::squid::squid_conf_file, $to_add); } #- mostly duplicated for MDK::Common::System::getVarsFromSh @@ -232,10 +238,7 @@ sub read_dansguardian() { sub write_dansguardian() { my $done; my $to_add = "naughtynesslimit = $level\n"; - substInFile { - $done = 1 if s|^\s*naughtynesslimit\b.*\n|$to_add|; - $_ .= $to_add if eof && !$done; - } $dansguardian_file; + subst_config_line($dansguardian_file, $to_add); } sub include_guardian_file { -- cgit v1.2.1