From 340239dd0fdf7e8a63ebaae809e548df3cda105b Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Mon, 17 Mar 2008 19:56:48 +0000 Subject: * optionally precreate the directory structure under 'dyndir' if 'precreateperms' is set --niko --- lib/Smokeping.pm | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm index 71e64d4..36977d9 100644 --- a/lib/Smokeping.pm +++ b/lib/Smokeping.pm @@ -153,6 +153,21 @@ sub dyndir ($) { return $cfg->{General}{dyndir} || $cfg->{General}{datadir}; } +sub make_cgi_directories { + my $targets = shift; + my $dir = shift; + my $perms = shift; + while (my ($k, $v) = each %$targets) { + next if ref $v ne "HASH"; + if ( ! -d "$dir/$k" ) { + my $saved = umask 0; + mkdir "$dir/$k", oct($perms); + umask $saved; + } + make_cgi_directories($targets->{$k}, "$dir/$k", $perms); + } +} + sub update_dynaddr ($$){ my $cfg = shift; my $q = shift; @@ -2404,7 +2419,7 @@ DOC [ qw(owner imgcache imgurl datadir dyndir pagedir piddir sendmail offset smokemail cgiurl mailhost snpphost contact display_name syslogfacility syslogpriority concurrentprobes changeprocessnames tmail - changecgiprogramname linkstyle) ], + changecgiprogramname linkstyle precreateperms ) ], _mandatory => [ qw(owner imgcache imgurl datadir piddir @@ -2528,6 +2543,20 @@ Complete URL path of the SmokePing.cgi DOC }, + precreateperms => + { + _re => '[0-7]+', + _re_error => 'please specify the permissions in octal', + _example => '2755', + _doc => < { _re => '(?:absolute|relative|original)', @@ -3640,6 +3669,10 @@ sub load_cfg ($;$) { init_alerts $cfg if $cfg->{Alerts}; add_targets $cfg, $probes, $cfg->{Targets}, $cfg->{General}{datadir}; init_target_tree $cfg, $probes, $cfg->{Targets}, $cfg->{General}{datadir}; + if (defined $cfg->{General}{precreateperms} && !$cgimode) { + make_cgi_directories($cfg->{Targets}, dyndir($cfg), + $cfg->{General}{precreateperms}); + } #use Data::Dumper; #die Dumper $cfg->{__hierarchies}; } else { -- cgit v1.2.3-24-g4f1b