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