line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zonemaster::Backend::Config; |
2
|
|
|
|
|
|
|
our $VERSION = '1.1.0'; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
37
|
|
6
|
2
|
|
|
2
|
|
20
|
use 5.14.2; |
|
2
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
903
|
use Config::IniFiles; |
|
2
|
|
|
|
|
30190
|
|
|
2
|
|
|
|
|
69
|
|
9
|
2
|
|
|
2
|
|
18
|
use File::ShareDir qw[dist_file]; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1298
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $path; |
12
|
|
|
|
|
|
|
if ($ENV{ZONEMASTER_BACKEND_CONFIG_FILE}) { |
13
|
|
|
|
|
|
|
$path = $ENV{ZONEMASTER_BACKEND_CONFIG_FILE}; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
elsif ( -e '/etc/zonemaster/backend_config.ini' ) { |
16
|
|
|
|
|
|
|
$path = '/etc/zonemaster/backend_config.ini'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
|
|
|
|
|
|
$path = dist_file('Zonemaster-Backend', "backend_config.ini"); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _load_config { |
24
|
2
|
|
|
2
|
|
20
|
my $cfg = Config::IniFiles->new( -file => $path ); |
25
|
2
|
50
|
|
|
|
9524
|
die "UNABLE TO LOAD $path\n" unless ( $cfg ); |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
6
|
return $cfg; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub BackendDBType { |
31
|
0
|
|
|
0
|
0
|
0
|
my $cfg = _load_config(); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $result; |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
0
|
if ( lc( $cfg->val( 'DB', 'engine' ) ) eq 'sqlite' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$result = 'SQLite'; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ( lc( $cfg->val( 'DB', 'engine' ) ) eq 'postgresql' ) { |
39
|
0
|
|
|
|
|
0
|
$result = 'PostgreSQL'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ( lc( $cfg->val( 'DB', 'engine' ) ) eq 'mysql' ) { |
42
|
0
|
|
|
|
|
0
|
$result = 'MySQL'; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
return $result; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub DB_user { |
49
|
0
|
|
|
0
|
0
|
0
|
my $cfg = _load_config(); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
return $cfg->val( 'DB', 'user' ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub DB_password { |
55
|
0
|
|
|
0
|
0
|
0
|
my $cfg = _load_config(); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
return $cfg->val( 'DB', 'password' ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub DB_name { |
61
|
0
|
|
|
0
|
0
|
0
|
my $cfg = _load_config(); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
return $cfg->val( 'DB', 'database_name' ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub DB_connection_string { |
67
|
2
|
|
|
2
|
0
|
15
|
my $cfg = _load_config(); |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
33
|
|
|
8
|
my $db_engine = $_[1] || $cfg->val( 'DB', 'engine' ); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
4
|
my $result; |
72
|
|
|
|
|
|
|
|
73
|
2
|
50
|
|
|
|
10
|
if ( lc( $db_engine ) eq 'sqlite' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
74
|
2
|
|
|
|
|
10
|
$result = sprintf('DBI:SQLite:dbname=%s', $cfg->val( 'DB', 'database_name' )); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif ( lc( $db_engine ) eq 'postgresql' ) { |
77
|
0
|
|
|
|
|
0
|
$result = sprintf('DBI:Pg:database=%s;host=%s', $cfg->val( 'DB', 'database_name' ), $cfg->val( 'DB', 'database_host' )); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif ( lc( $db_engine ) eq 'mysql' ) { |
80
|
0
|
|
|
|
|
0
|
$result = sprintf('DBI:mysql:database=%s;host=%s', $cfg->val( 'DB', 'database_name' ), $cfg->val( 'DB', 'database_host' )); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
88
|
return $result; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub LogDir { |
87
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $cfg->val( 'LOG', 'log_dir' ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub PerlIntereter { |
93
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $cfg->val( 'PERL', 'interpreter' ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub PollingInterval { |
99
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $cfg->val( 'DB', 'polling_interval' ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub MaxZonemasterExecutionTime { |
105
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $cfg->val( 'ZONEMASTER', 'max_zonemaster_execution_time' ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub NumberOfProcessesForFrontendTesting { |
111
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $nb = $cfg->val( 'ZONEMASTER', 'number_of_professes_for_frontend_testing' ); |
114
|
0
|
0
|
|
|
|
|
$nb = $cfg->val( 'ZONEMASTER', 'number_of_processes_for_frontend_testing' ) unless ($nb); |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $nb; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub NumberOfProcessesForBatchTesting { |
120
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $nb = $cfg->val( 'ZONEMASTER', 'number_of_professes_for_batch_testing' ); |
123
|
0
|
0
|
|
|
|
|
$nb = $cfg->val( 'ZONEMASTER', 'number_of_processes_for_batch_testing' ) unless ($nb); |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $nb; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub Maxmind_ISP_DB_File { |
129
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $cfg->val( 'GEOLOCATION', 'maxmind_isp_db_file' ); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub Maxmind_City_DB_File { |
135
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $cfg->val( 'GEOLOCATION', 'maxmind_city_db_file' ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub force_hash_id_use_in_API_starting_from_id { |
141
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $val = $cfg->val( 'ZONEMASTER', 'force_hash_id_use_in_API_starting_from_id' ); |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
return ($val)?($val):(0); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub CustomProfilesPath { |
149
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $value = $cfg->val( 'ZONEMASTER', 'cutom_profiles_path' ); |
152
|
0
|
0
|
|
|
|
|
$value = $cfg->val( 'ZONEMASTER', 'custom_profiles_path' ) unless ($value); |
153
|
0
|
|
|
|
|
|
return $value; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub GetCustomConfigParameter { |
157
|
0
|
|
|
0
|
0
|
|
my ($slef, $section, $param_name) = @_; |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
my $cfg = _load_config(); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return $cfg->val( $section, $param_name ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub lock_on_queue { |
165
|
0
|
|
|
0
|
0
|
|
my $cfg = _load_config(); |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $val = $cfg->val( 'ZONEMASTER', 'lock_on_queue' ); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
return $val; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |