26ccead31840c04e9af960e290ca0d42b91efc02
[BackupPC.git] / lib / BackupPC / Config.pm
1 package BackupPC::Config;
2
3 use warnings;
4 use Data::Dumper;
5
6 our %ConfigDef;
7
8 # this currently isn't used (or completed)
9 sub CheckConfigInfo
10 {
11     my($self) = @_;
12     my $errstr = '';
13     
14     my($attr, $val, $def, $ref);
15     
16     foreach $attr (sort keys %{ $self->{Conf} }) {
17         print AA "Checking $attr...";
18         $val = $self->{Conf}->{$attr};
19         $ref = ref $val;
20         $def = $ConfigDef{$attr};
21         
22         if (!defined $def) {
23             $errstr .= "Unknown attribute $attr; ";
24         } elsif ($def->{struct} eq 'SCALAR' && $ref) {
25             $errstr .= "$attr expected to be SCALAR but is $ref; ";
26         } elsif ($def->{struct} =~ /^ARRAY(OFHASH)$/ && $ref && $ref ne 'ARRAY') {
27             $errstr .= "$attr expected to be ARRAY but is $ref; ";
28         } elsif ($def->{struct} =~ /^HASH(OFARRAY)$/ && $ref && $ref ne 'HASH') {
29             $errstr .= "$attr expected to be HASH but is $ref; ";
30         # still working out this logic..
31         #} elsif (defined $val && !$ref) {
32         #    # if we got a scalar but were expecting a reference, fix it
33         #    
34         #    if($def->{struct} eq 'ARRAY') {
35         #        $val = [ $val ];
36         #    } elsif ($def->{struct} eq 'HASH') {
37         #        $val = { $val };
38         #    } elsif ($def->{struct} eq 'ARRAYOFHASH') {
39         #        $val = [ { $val } ];
40         #    } elsif ($def->{struct} eq 'HASHOFARRAY') {
41         #        $val = { [ $val ] };
42         #    }
43             
44         }
45     }
46     
47     return $errstr;
48 }
49
50 sub TopDir
51 {
52     my($self) = @_;
53     return $self->{TopDir};
54 }
55
56 sub BinDir
57 {
58     my($self) = @_;
59     return $self->{BinDir};
60 }
61
62 sub Version
63 {
64     my($self) = @_;
65     return $self->{Version};
66 }
67
68 sub Conf
69 {
70     my($self) = @_;
71     return %{$self->{Conf}};
72 }
73
74 sub ConfigDef
75 {
76     my($self) = @_;
77     return \%ConfigDef;
78 }
79
80 sub Lang
81 {
82     my($self) = @_;
83     return $self->{Lang};
84 }
85
86 sub adminJob
87 {
88     return " admin ";
89 }
90
91 sub trashJob
92 {
93     return " trashClean ";
94 }
95
96 sub timeStamp
97 {
98     my($self, $t, $noPad) = @_;
99     my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
100               = localtime($t || time);
101     $year += 1900;
102     $mon++;
103     return "$year/$mon/$mday " . sprintf("%02d:%02d:%02d", $hour, $min, $sec)
104             . ($noPad ? "" : " ");
105 }
106
107 sub ConnectData {
108     # fallback routine in case no database used
109     return 1;
110
111 }
112
113 ###########################
114
115
116 %ConfigDef = (
117     ServerHost                   => {struct => 'SCALAR',
118                                      type   => 'STRING', },
119
120     ServerPort                   => {struct => 'SCALAR',
121                                      type   => 'INT', },
122
123     ServerMesgSecret             => {struct => 'SCALAR',
124                                      type   => 'STRING', },
125
126     MyPath                       => {struct => 'SCALAR',
127                                      type   => 'STRING', },
128
129     UmaskMode                    => {struct => 'SCALAR',
130                                      type   => 'INT', },
131
132     WakeupSchedule               => {struct => 'ARRAY',
133                                      type   => 'INT', },
134
135     MaxBackups                   => {struct => 'SCALAR',
136                                      type   => 'INT', },
137
138     MaxUserBackups               => {struct => 'SCALAR',
139                                      type   => 'INT', },
140
141     MaxPendingCmds               => {struct => 'SCALAR',
142                                      type   => 'INT', },
143
144     MaxOldLogFiles               => {struct => 'SCALAR',
145                                      type   => 'INT', },
146
147     DfPath                       => {struct => 'SCALAR',
148                                      type   => 'STRING', },
149
150     DfMaxUsagePct                => {struct => 'SCALAR',
151                                      type   => 'INT', },
152
153     TrashCleanSleepSec           => {struct => 'SCALAR',
154                                      type   => 'INT', },
155
156     DHCPAddressRanges            => {struct => 'ARRAYOFHASH',
157                                      type   => {ipAddrBase => 'STRING',
158                                                 first      => 'INT',
159                                                 last       => 'INT',}, },
160
161     BackupPCUser                 => {struct => 'SCALAR',
162                                      type   => 'STRING', },
163
164     CgiDir                       => {struct => 'SCALAR',
165                                      type   => 'STRING', },
166
167     InstallDir                   => {struct => 'SCALAR',
168                                      type   => 'STRING', },
169
170     BackupPCUserVerify           => {struct => 'SCALAR',
171                                      type   => 'BOOLEAN', },
172
173     SmbShareName                 => {struct => 'ARRAY',
174                                      type   => 'STRING', },
175
176     SmbShareUserName             => {struct => 'SCALAR',
177                                      type   => 'STRING', },
178
179     SmbSharePasswd               => {struct => 'SCALAR',
180                                      type   => 'STRING', },
181
182     TarShareName                 => {struct => 'ARRAY',
183                                      type   => 'STRING', },
184
185     FullPeriod                   => {struct => 'SCALAR',
186                                      type   => 'FLOAT', },
187
188     IncrPeriod                   => {struct => 'SCALAR',
189                                      type   => 'FLOAT', },
190
191     FullKeepCnt                  => {struct => 'SCALAR',
192                                      type   => 'INT', },
193
194     FullKeepCntMin               => {struct => 'SCALAR',
195                                      type   => 'INT', },
196
197     FullAgeMax                   => {struct => 'SCALAR',
198                                      type   => 'INT', },
199
200     IncrKeepCnt                  => {struct => 'SCALAR',
201                                      type   => 'INT', },
202
203     IncrKeepCntMin               => {struct => 'SCALAR',
204                                      type   => 'INT', },
205
206     IncrAgeMax                   => {struct => 'SCALAR',
207                                      type   => 'INT', },
208
209     IncrFill                     => {struct => 'SCALAR',
210                                      type   => 'BOOLEAN', },
211
212     RestoreInfoKeepCnt           => {struct => 'SCALAR',
213                                      type   => 'INT', },
214
215     BackupFilesOnly              => {struct => 'HASHOFARRAY',
216                                      type   => 'STRING', },
217
218     BackupFilesExclude           => {struct => 'HASHOFARRAY',
219                                      type   => 'STRING', },
220
221     BlackoutBadPingLimit         => {struct => 'SCALAR',
222                                      type   => 'INT', },
223
224     BlackoutGoodCnt              => {struct => 'SCALAR',
225                                      type   => 'INT', },
226
227     BlackoutHourBegin            => {struct => 'SCALAR',
228                                      type   => 'FLOAT', },
229
230     BlackoutHourEnd              => {struct => 'SCALAR',
231                                      type   => 'FLOAT', },
232
233     BlackoutWeekDays             => {struct => 'ARRAY',
234                                      type   => 'INT', },
235
236     XferMethod                   => {struct => 'SCALAR',
237                                      type   => 'STRING', },
238
239     SmbClientPath                => {struct => 'SCALAR',
240                                      type   => 'STRING', },
241
242     SmbClientArgs                => {struct => 'SCALAR',
243                                      type   => 'STRING', },
244
245     TarClientCmd                 => {struct => 'SCALAR',
246                                      type   => 'STRING', },
247
248     TarFullArgs                  => {struct => 'SCALAR',
249                                      type   => 'STRING', },
250
251     TarIncrArgs                  => {struct => 'SCALAR',
252                                      type   => 'STRING', },
253
254     TarClientRestoreCmd          => {struct => 'SCALAR',
255                                      type   => 'STRING', },
256
257     TarClientPath                => {struct => 'SCALAR',
258                                      type   => 'STRING', },
259
260     SshPath                      => {struct => 'SCALAR',
261                                      type   => 'STRING', },
262
263     NmbLookupPath                => {struct => 'SCALAR',
264                                      type   => 'STRING', },
265
266     FixedIPNetBiosNameCheck      => {struct => 'SCALAR',
267                                      type   => 'BOOLEAN', },
268
269     PingPath                     => {struct => 'SCALAR',
270                                      type   => 'STRING', },
271
272     PingArgs                     => {struct => 'SCALAR',
273                                      type   => 'STRING', },
274
275     CompressLevel                => {struct => 'SCALAR',
276                                      type   => 'INT', },
277
278     PingMaxMsec                  => {struct => 'SCALAR',
279                                      type   => 'INT', },
280
281     SmbClientTimeout             => {struct => 'SCALAR',
282                                      type   => 'INT', },
283
284     MaxOldPerPCLogFiles          => {struct => 'SCALAR',
285                                      type   => 'INT', },
286
287     SendmailPath                 => {struct => 'SCALAR',
288                                      type   => 'STRING', },
289
290     EMailNotifyMinDays           => {struct => 'SCALAR',
291                                      type   => 'INT', },
292
293     EMailFromUserName            => {struct => 'SCALAR',
294                                      type   => 'STRING', },
295
296     EMailAdminUserName           => {struct => 'SCALAR',
297                                      type   => 'STRING', },
298
299     EMailNoBackupEverMesg        => {struct => 'SCALAR',
300                                      type   => 'MEMO', },
301
302     EMailNotifyOldBackupDays     => {struct => 'SCALAR',
303                                      type   => 'INT', },
304
305     EMailNoBackupRecentMesg      => {struct => 'SCALAR',
306                                      type   => 'MEMO', },
307
308     EMailNotifyOldOutlookDays    => {struct => 'SCALAR',
309                                      type   => 'INT', },
310
311     EMailOutlookBackupMesg       => {struct => 'SCALAR',
312                                      type   => 'MEMO', },
313
314     CgiAdminUserGroup            => {struct => 'SCALAR',
315                                      type   => 'STRING', },
316
317     CgiAdminUsers                => {struct => 'SCALAR',
318                                      type   => 'STRING', },
319
320     Language                     => {struct => 'SCALAR',
321                                      type   => 'STRING', },
322
323     CgiUserHomePageCheck         => {struct => 'SCALAR',
324                                      type   => 'STRING', },
325
326     CgiUserUrlCreate             => {struct => 'SCALAR',
327                                      type   => 'STRING', },
328
329     CgiDateFormatMMDD            => {struct => 'SCALAR',
330                                      type   => 'BOOLEAN', },
331
332     CgiNavBarAdminAllHosts       => {struct => 'SCALAR',
333                                      type   => 'BOOLEAN', },
334
335     CgiHeaderFontType            => {struct => 'SCALAR',
336                                      type   => 'STRING', },
337
338     CgiHeaderFontSize            => {struct => 'SCALAR',
339                                      type   => 'INT', },
340
341     CgiNavBarBgColor             => {struct => 'SCALAR',
342                                      type   => 'STRING', },
343
344     CgiHeaderBgColor             => {struct => 'SCALAR',
345                                      type   => 'STRING', },
346
347     CgiHeaders                   => {struct => 'SCALAR',
348                                      type   => 'STRING', },
349
350     CgiImageDir                  => {struct => 'SCALAR',
351                                      type   => 'STRING', },
352
353     CgiImageDirURL               => {struct => 'SCALAR',
354                                      type   => 'STRING', },
355
356 );
357
358 1;