blob: 50feb24fe8bfb6765043e6a620776d06543bccf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/usr/bin/perl
#
# This file is part of the exilog suite.
#
# http://duncanthrax.net/exilog/
#
# (c) Tom Kistner 2004
#
# See LICENSE for licensing information.
#
package exilog_config;
use strict;
use Fcntl ':mode';
use lib "/usr/lib/exilog/";
BEGIN {
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
$VERSION = 0.1;
@ISA = qw(Exporter);
@EXPORT = qw(
$config
$version
);
%EXPORT_TAGS = ();
# your exported package globals go here,
# as well as any optionally exported functions
@EXPORT_OK = qw();
use vars qw( $config $version );
}
my $cfg_file = "/etc/exilog/exilog.conf";
$version = "0.5.1";
# check file permissions of exilog.conf
my $mode = (stat($cfg_file))[2];
# mask out file type;
$mode = $mode & 07777;
# we care only about others now
$mode = $mode & 0007;
if ( $mode > 0 ) {
print STDERR "($$) [exilog_config] Attention - $cfg_file is readable by 'others'. Fix file permissions!\n";
exit(0);
}
if ( ! -e $cfg_file ) {
print STDERR "($$) [exilog_config] $cfg_file does not exist!\n";
exit(0);
}
if ( ! -r $cfg_file ) {
my $username = getpwuid($<);
print STDERR "($$) [exilog_config] $cfg_file is not readable by user ". $username ."!\n";
exit(0);
}
$config = _read_ph($cfg_file);
# check if user forgots to add a trailing slash - if so, add it here
if (
defined($config->{web}->{webroot}) &&
$config->{web}->{webroot} !~ /\/$/
) {
$config->{web}->{webroot}.="/";
}
unless ($config) {
print STDERR "($$) [exilog_config] Can't parse configuration file.\n";
exit(0);
};
sub _read_ph {
my $file = shift;
open(PH,"< $file");
undef $/;
my $tmp = (eval(<PH>));
print STDERR "Eval Error: ".$@."\n" if ($@);
$/ = "\n";
close(PH);
return $tmp;
};
1;
|