line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2004, 2005 Anders Ardö |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## $Id: Config.pm 326 2011-05-27 07:44:58Z it-aar $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# See the file LICENCE included in the distribution. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Combine::Config; |
8
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
362275
|
use strict; |
|
11
|
|
|
|
|
40
|
|
|
11
|
|
|
|
|
573
|
|
10
|
11
|
|
|
11
|
|
16159
|
use Config::General qw(SaveConfigString); |
|
11
|
|
|
|
|
426703
|
|
|
11
|
|
|
|
|
5364
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '4.005'; |
13
|
|
|
|
|
|
|
our %serverbypreferred = (); |
14
|
|
|
|
|
|
|
our %serverbyalias = (); |
15
|
|
|
|
|
|
|
our @allow = (); |
16
|
|
|
|
|
|
|
our @exclude = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#Default values |
19
|
|
|
|
|
|
|
my $jobname = 'alvistest'; |
20
|
|
|
|
|
|
|
my $dbname = 'alvistest'; |
21
|
|
|
|
|
|
|
my $baseConfigDir = '/etc/combine'; |
22
|
|
|
|
|
|
|
my %configValues; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _private_initConfig_ { |
25
|
|
|
|
|
|
|
#default values |
26
|
10
|
|
|
10
|
|
410
|
my $conf = new Config::General(-ConfigFile => "$baseConfigDir/default.cfg", |
27
|
|
|
|
|
|
|
-BackslashEscape => 0, |
28
|
|
|
|
|
|
|
-MergeDuplicateBlocks => 1, |
29
|
|
|
|
|
|
|
-AutoTrue => 1 |
30
|
|
|
|
|
|
|
); |
31
|
10
|
|
|
|
|
139649
|
my %defConf = $conf->getall; |
32
|
|
|
|
|
|
|
#use Data::Dumper; print "Dumping Default\n"; print Dumper(\%defConf); |
33
|
10
|
|
|
|
|
546
|
my $configDir = $baseConfigDir . '/' . $jobname; |
34
|
10
|
|
|
|
|
160
|
$conf = new Config::General(-ConfigFile => "$configDir/combine.cfg", |
35
|
|
|
|
|
|
|
-BackslashEscape => 0, |
36
|
|
|
|
|
|
|
-MergeDuplicateBlocks => 1, |
37
|
|
|
|
|
|
|
-AutoTrue => 1 |
38
|
|
|
|
|
|
|
); |
39
|
10
|
|
|
|
|
54059
|
%configValues = $conf->getall; |
40
|
|
|
|
|
|
|
#Merge |
41
|
10
|
|
|
|
|
252
|
foreach my $opt (keys(%defConf)) { |
42
|
400
|
|
|
|
|
618
|
my $c=$defConf{$opt}; |
43
|
400
|
|
|
|
|
487
|
my $r = ref($c); |
44
|
|
|
|
|
|
|
# print "DefConf $opt: $r\n"; |
45
|
400
|
100
|
100
|
|
|
2150
|
if ( (ref($defConf{$opt}) eq '') && !defined($configValues{$opt})) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# print "Assigning $opt Def\n"; |
47
|
350
|
|
|
|
|
852
|
$configValues{$opt} = $defConf{$opt}; |
48
|
|
|
|
|
|
|
} elsif ( (ref($defConf{$opt}) eq 'ARRAY') ) { |
49
|
0
|
|
|
|
|
0
|
warn("$opt not supported in default config"); |
50
|
|
|
|
|
|
|
} elsif ( (ref($defConf{$opt}) eq 'HASH') ) { |
51
|
30
|
100
|
|
|
|
138
|
if (!defined($configValues{$opt})) { |
|
|
50
|
|
|
|
|
|
52
|
10
|
|
|
|
|
42
|
$configValues{$opt}=$defConf{$opt}; |
53
|
|
|
|
|
|
|
} elsif (ref($configValues{$opt}) eq 'HASH') { |
54
|
20
|
|
|
|
|
41
|
my $tmp1 = SaveConfigString(\%{$configValues{$opt}}); |
|
20
|
|
|
|
|
118
|
|
55
|
20
|
|
|
|
|
8525
|
my $tmp2 = SaveConfigString(\%{$defConf{$opt}}); |
|
20
|
|
|
|
|
84
|
|
56
|
20
|
|
|
|
|
6131
|
my $tconf = new Config::General(-String => $tmp1 . $tmp2, |
57
|
|
|
|
|
|
|
-BackslashEscape => 0, |
58
|
|
|
|
|
|
|
-MergeDuplicateBlocks => 1, |
59
|
|
|
|
|
|
|
-AutoTrue => 1, |
60
|
|
|
|
|
|
|
-IncludeRelative => 1 |
61
|
|
|
|
|
|
|
); |
62
|
20
|
|
|
|
|
46124
|
%{$configValues{$opt}} = $tconf->getall; |
|
20
|
|
|
|
|
4494
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
|
|
|
85
|
$configValues{'jobname'} = $jobname; |
68
|
10
|
|
|
|
|
35
|
$configValues{'configDir'} = $configDir; |
69
|
10
|
|
|
|
|
29
|
$configValues{'baseConfigDir'} = $baseConfigDir; |
70
|
|
|
|
|
|
|
# open CONF, "<$baseConfigDir/$jobname/$configFile" or |
71
|
|
|
|
|
|
|
# die "**ERROR: Can't open Combine's configuration file $baseConfigDir/$jobname/$configFile"; |
72
|
|
|
|
|
|
|
#use Data::Dumper; print "Dumping Merged\n"; print Dumper(\%configValues); |
73
|
|
|
|
|
|
|
|
74
|
11
|
|
|
11
|
|
28697
|
use DBI; |
|
11
|
|
|
|
|
252765
|
|
|
11
|
|
|
|
|
14145
|
|
75
|
10
|
50
|
|
|
|
54
|
if ( defined($configValues{'DBItraceFile'}) ) { |
76
|
0
|
|
|
|
|
0
|
DBI->trace(1,$configValues{'DBItraceFile'}); |
77
|
|
|
|
|
|
|
} |
78
|
10
|
50
|
|
|
|
71
|
$dbname = $configValues{'MySQLdatabase'} if defined($configValues{'MySQLdatabase'}); |
79
|
|
|
|
|
|
|
# print "Using database: $dbname\n"; |
80
|
|
|
|
|
|
|
#parse $dbname according to user@host:database |
81
|
10
|
|
|
|
|
62
|
my $dbhost='localhost'; |
82
|
10
|
|
|
|
|
48
|
my $dbuser='combine'; |
83
|
10
|
|
|
|
|
45
|
my $database='alvistest'; |
84
|
10
|
50
|
|
|
|
103
|
if ($dbname =~ /^([^@]+)@([^:]+):(.+)$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
85
|
10
|
|
|
|
|
40
|
$dbuser=$1; $dbhost=$2; $database=$3; |
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
33
|
|
86
|
|
|
|
|
|
|
} elsif ($dbname =~ /^([^:]+):(.+)$/) { |
87
|
0
|
|
|
|
|
0
|
$dbhost=$1; $database=$2; |
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
} elsif ($dbname =~ /^([^@]+)@(.+)$/) { |
89
|
0
|
|
|
|
|
0
|
$dbuser=$1; $dbhost=$2; |
|
0
|
|
|
|
|
0
|
|
90
|
0
|
|
|
|
|
0
|
} else { $database=$dbname; } |
91
|
|
|
|
|
|
|
# print " Parsed: host=$dbhost; user=$dbuser; db=$database\n"; |
92
|
|
|
|
|
|
|
#!!Handle passwd in connect |
93
|
10
|
0
|
|
|
|
513
|
my $sv = DBI->connect("DBI:mysql:database=$database;host=$dbhost", $dbuser, "", |
94
|
|
|
|
|
|
|
{ShowErrorStatement => 1, RaiseError => 1, AutoCommit => 0 }) or |
95
|
|
|
|
|
|
|
die("Fatal error, can't connect to MySQL: $DBI::errstr"); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
##Store handle as a config-var that can be reused |
98
|
0
|
|
|
|
|
0
|
$configValues{'MySQLhandle'} = $sv; |
99
|
0
|
|
|
|
|
0
|
my $url = Combine::Config::Get('url'); |
100
|
0
|
|
|
|
|
0
|
my $servalias = ${$url}{'serveralias'}; |
|
0
|
|
|
|
|
0
|
|
101
|
0
|
|
|
|
|
0
|
foreach my $preferred (keys(%{$servalias})) |
|
0
|
|
|
|
|
0
|
|
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
|
|
0
|
my @ALIAS; |
104
|
0
|
|
|
|
|
0
|
my $alias = ${$servalias}{$preferred}; |
|
0
|
|
|
|
|
0
|
|
105
|
0
|
0
|
|
|
|
0
|
if(ref($alias) eq "ARRAY") { |
106
|
0
|
|
|
|
|
0
|
@ALIAS = @{$alias}; |
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
0
|
@ALIAS = ($alias); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
$serverbypreferred{$preferred} = \@ALIAS; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
foreach my $host (@ALIAS) |
114
|
|
|
|
|
|
|
{ |
115
|
0
|
|
|
|
|
0
|
$serverbyalias{$host} = $preferred; |
116
|
|
|
|
|
|
|
# print "$host -> $preferred\n"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# config_allow |
121
|
|
|
|
|
|
|
# Here, we cannot allow end-of-line comments because they could clash |
122
|
|
|
|
|
|
|
# with regex patterns- however unlikely. |
123
|
|
|
|
|
|
|
# We will keep this info in an array of array refs like: |
124
|
|
|
|
|
|
|
# [ H|U precompiled-pattern original-line ] |
125
|
|
|
|
|
|
|
# where H or U specifies if this is a HOST or URL match. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# open(CONF, "
|
128
|
|
|
|
|
|
|
# while(my $l = ) |
129
|
|
|
|
|
|
|
# { |
130
|
|
|
|
|
|
|
# chomp($l); |
131
|
|
|
|
|
|
|
# next if $l =~ /^\s*$/; |
132
|
|
|
|
|
|
|
# next if $l =~ /^\s*\#/; # whole comment line |
133
|
|
|
|
|
|
|
# |
134
|
0
|
|
|
|
|
0
|
my $all = ${$url}{'allow'}; |
|
0
|
|
|
|
|
0
|
|
135
|
0
|
|
|
|
|
0
|
my $l; |
136
|
0
|
0
|
|
|
|
0
|
if ( ref( ${$all}{'URL'} ) eq '' ) { |
|
0
|
|
|
|
|
0
|
|
137
|
0
|
|
|
|
|
0
|
$l = ${$all}{'URL'}; |
|
0
|
|
|
|
|
0
|
|
138
|
0
|
0
|
|
|
|
0
|
if ($l) { push(@allow, [ 'U', qr/$l/, $l ] ); } |
|
0
|
|
|
|
|
0
|
|
139
|
0
|
|
|
|
|
0
|
} else { foreach $l ( @{${$all}{'URL'}} ) { push(@allow, [ 'U', qr/$l/, $l ] ); } } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
140
|
0
|
0
|
|
|
|
0
|
if ( ref( ${$all}{'HOST:'} ) eq '' ) { |
|
0
|
|
|
|
|
0
|
|
141
|
0
|
|
|
|
|
0
|
$l = ${$all}{'HOST:'}; |
|
0
|
|
|
|
|
0
|
|
142
|
0
|
0
|
|
|
|
0
|
if ($l) { push(@allow, [ 'H', qr/$l/, 'HOST: ' . $l ] ); } |
|
0
|
|
|
|
|
0
|
|
143
|
0
|
|
|
|
|
0
|
} else { foreach $l ( @{${$all}{'HOST:'}} ) { push(@allow, [ 'H', qr/$l/, 'HOST: ' . $l ] ); } } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# my($hostind, $patt) = $l =~ /\s*(HOST:)?\s*(.*)$/; |
146
|
|
|
|
|
|
|
# # Is this a host or full URL match? |
147
|
|
|
|
|
|
|
# $hostind = defined $hostind ? 'H' : 'U'; |
148
|
|
|
|
|
|
|
# push(@selurl::allow, [ $hostind, qr/$patt/, $l ] ); |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# } |
151
|
|
|
|
|
|
|
# close(CONF); |
152
|
|
|
|
|
|
|
#foreach my $l (@allow) { print join(' ',@{$l}) . "\n"; } |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
# # config_exclude |
156
|
|
|
|
|
|
|
# # Same tea as config_allow in other porcelain. |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
# open(CONF, "
|
159
|
|
|
|
|
|
|
# while(my $l = ) |
160
|
|
|
|
|
|
|
# { |
161
|
|
|
|
|
|
|
# chomp($l); |
162
|
|
|
|
|
|
|
# next if $l =~ /^\s*$/; |
163
|
|
|
|
|
|
|
# next if $l =~ /^\s*\#/; # whole comment line |
164
|
|
|
|
|
|
|
# |
165
|
0
|
|
|
|
|
0
|
my $excl = ${$url}{'exclude'}; |
|
0
|
|
|
|
|
0
|
|
166
|
0
|
0
|
|
|
|
0
|
if ( ref( ${$excl}{'URL'} ) eq '' ) { |
|
0
|
|
|
|
|
0
|
|
167
|
0
|
|
|
|
|
0
|
$l = ${$excl}{'URL'}; |
|
0
|
|
|
|
|
0
|
|
168
|
0
|
0
|
|
|
|
0
|
if ($l) { push(@exclude, [ 'U', qr/$l/, $l ] ); } |
|
0
|
|
|
|
|
0
|
|
169
|
0
|
|
|
|
|
0
|
} else { foreach $l ( @{${$excl}{'URL'}} ) { push(@exclude, [ 'U', qr/$l/, $l ] ); } } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
170
|
0
|
0
|
|
|
|
0
|
if ( ref( ${$excl}{'HOST:'} ) eq '' ) { |
|
0
|
|
|
|
|
0
|
|
171
|
0
|
|
|
|
|
0
|
$l = ${$excl}{'HOST:'}; |
|
0
|
|
|
|
|
0
|
|
172
|
0
|
0
|
|
|
|
0
|
if ($l) { push(@exclude, [ 'H', qr/$l/, 'HOST: ' . $l ] ); } |
|
0
|
|
|
|
|
0
|
|
173
|
0
|
|
|
|
|
0
|
} else { foreach $l ( @{${$excl}{'HOST:'}} ) { push(@exclude, [ 'H', qr/$l/, 'HOST: ' . $l ] ); } } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# my($hostind, $patt) = $l =~ /\s*(HOST:)?\s*(.*)$/; |
176
|
|
|
|
|
|
|
# # Is this a host or full URL match? |
177
|
|
|
|
|
|
|
# $hostind = defined $hostind ? 'H' : 'U'; |
178
|
|
|
|
|
|
|
# push(@selurl::exclude, [ $hostind, qr/$patt/, $l ] ); |
179
|
|
|
|
|
|
|
# |
180
|
|
|
|
|
|
|
# } |
181
|
|
|
|
|
|
|
# close(CONF); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _sql_error { |
186
|
0
|
|
|
0
|
|
0
|
my $a; |
187
|
0
|
|
|
|
|
0
|
warn "MySQLhdb; SQL ERROR\n"; |
188
|
0
|
|
|
|
|
0
|
foreach $a (@_) { |
189
|
0
|
|
|
|
|
0
|
warn "$a\n"; |
190
|
|
|
|
|
|
|
} |
191
|
0
|
|
|
|
|
0
|
return undef; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#Externaly available |
195
|
|
|
|
|
|
|
sub Init { |
196
|
|
|
|
|
|
|
#Assign to $configFile or $dbname |
197
|
11
|
|
|
11
|
0
|
676333
|
my ($jname, $baseDir) = @_; |
198
|
11
|
50
|
|
|
|
269
|
if (scalar(%configValues)) { |
199
|
0
|
|
|
|
|
0
|
warn "**ERROR: JobName $jname discarded - config already initialized!\n"; |
200
|
0
|
|
|
|
|
0
|
return; |
201
|
|
|
|
|
|
|
} |
202
|
11
|
|
|
|
|
156
|
$jobname=$jname; |
203
|
11
|
50
|
|
|
|
169
|
if (defined($baseDir)) { $baseConfigDir = $baseDir; } |
|
11
|
|
|
|
|
101
|
|
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub Get { |
207
|
10
|
|
|
10
|
0
|
95
|
my ($name) = @_; |
208
|
|
|
|
|
|
|
|
209
|
10
|
50
|
|
|
|
254
|
if (!scalar(%configValues)) { |
210
|
10
|
|
|
|
|
112
|
_private_initConfig_(); |
211
|
|
|
|
|
|
|
} |
212
|
0
|
|
|
|
|
|
my $value = $configValues{$name}; |
213
|
0
|
0
|
|
|
|
|
if (!defined($value)) { |
214
|
|
|
|
|
|
|
# warn "**ERROR: Undefined Combine configuration parameter $name\n"; |
215
|
|
|
|
|
|
|
#Return undefined if value not available |
216
|
0
|
|
|
|
|
|
return undef; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
return $value; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub Set { |
223
|
|
|
|
|
|
|
# Changes/Sets a config-value localy, in-memory |
224
|
0
|
|
|
0
|
0
|
|
my ($name, $value) = @_; |
225
|
0
|
|
|
|
|
|
$configValues{$name} = $value; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub SetSQL { |
229
|
|
|
|
|
|
|
# Changes/Sets a config-value globaly, in the SQL database |
230
|
0
|
|
|
0
|
0
|
|
my ($name, $value) = @_; |
231
|
0
|
|
|
|
|
|
warn "ConfigSQL::SetSQL is not implemented yet"; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1; |