Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # get_current_value(parameter_name)
- # returns a scalar corresponding to the value of the parameter
- ## modified to allow main_parameter:subparameter
- sub get_current_value
- {
- # First try to get the value from main.cf directly
- my ($name,$key)=split /:/,$_[0];
- my $lref = &read_file_lines($config{'postfix_config_file'});
- my $out;
- my ($begin_flag, $end_flag);
- foreach my $l (@$lref) {
- # changes made to this loop by Dan Hartman of Rae Internet /
- # Message Partners for multi-line parsing 2007-06-04
- if ($begin_flag == 1 && $l =~ /\S/ && $l =~ /^(\s+[^#].+)/) {
- # non-comment continuation line, and replace tabs with spaces
- $out .= $1;
- $out =~ s/^\s+/ /;
- }
- if ($l =~ /^\s*([a-z0-9\_]+)\s*=\s*(.*)|^\s*([a-z0-9\_]+)\s*=\s*$/ &&
- $1 . $3 eq $name) {
- # Found the one we're looking for, set a flag
- $out = $2;
- $begin_flag = 1;
- }
- if ($l =~ /^\s*([a-z0-9\_]+)\s*=\s*(.*)|^\s*([a-z0-9\_]+)\s*=\s*$/ &&
- $1 . $3 ne $name && $begin_flag == 1) {
- # after the beginning, another configuration variable
- # found! Stop!
- $end_flag = 1;
- last;
- }
- }
- if (!defined($out)) {
- # Fall back to asking Postfix
- # -h tells postconf not to output the name of the parameter
- $out = &backquote_command("$config{'postfix_config_command'} -c $config_dir -h ".
- quotemeta($name)." 2>/dev/null", 1);
- if ($?) {
- &error(&text('query_get_efailed', $name, $out));
- }
- elsif ($out =~ /warning:.*unknown\s+parameter/) {
- return undef;
- }
- chop($out);
- }
- else {
- # Trim trailing whitespace
- $out =~ s/\s+$//;
- }
- if ($key) {
- # If the value asked for was like foo:bar, extract from the value
- # the parts after bar
- my @res = ( );
- while($out =~ /^(.*?)\Q$key\E\s+(\S+)(.*)$/) {
- my $v = $2;
- $out = $3;
- $v =~ s/,$//;
- push(@res, $v);
- }
- return join(" ", @res);
- }
- return $out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement