summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-03-26 17:46:41 +0000
committerOlivier Blin <oblin@mandriva.com>2008-03-26 17:46:41 +0000
commitbf6a0a31b4a357136ff0784dd77c6c42c6635cb0 (patch)
treeaf7f7b6e3ff41ac27e9475c75441aee813b57d7f /bin
parent46a40161aefff9f30e9f73966bef27ec3fc0cb73 (diff)
downloaddrakguard-bf6a0a31b4a357136ff0784dd77c6c42c6635cb0.tar
drakguard-bf6a0a31b4a357136ff0784dd77c6c42c6635cb0.tar.gz
drakguard-bf6a0a31b4a357136ff0784dd77c6c42c6635cb0.tar.bz2
drakguard-bf6a0a31b4a357136ff0784dd77c6c42c6635cb0.tar.xz
drakguard-bf6a0a31b4a357136ff0784dd77c6c42c6635cb0.zip
factorize writting a single config line
Diffstat (limited to 'bin')
-rwxr-xr-xbin/drakguard21
1 files changed, 12 insertions, 9 deletions
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 {