X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FCGI%2FLib.pm;h=bec4ea8240e869fa39562923e4ff51cf9be8626b;hp=a9dad66961a06c9f39b7b4440d58d3c5df7d5574;hb=5b3e6091d542c2e7445d5dd511cdf6e20aec8b8d;hpb=a7e968ce327855f2ba2624ca8517069a936c9b5b diff --git a/lib/BackupPC/CGI/Lib.pm b/lib/BackupPC/CGI/Lib.pm index a9dad66..bec4ea8 100644 --- a/lib/BackupPC/CGI/Lib.pm +++ b/lib/BackupPC/CGI/Lib.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.1.0_CVS, released 3 Jul 2003. +# Version 3.0.0alpha, released 23 Jan 2006. # # See http://backuppc.sourceforge.net. # @@ -44,7 +44,7 @@ require Exporter; use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS ); -use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc); +use vars qw($Cgi %In $MyURL $User %Conf $TopDir $LogDir $BinDir $bpc); use vars qw(%Status %Info %Jobs @BgQueue @UserQueue @CmdQueue %QueueLen %StatusHost); use vars qw($Hosts $HostsMTime $ConfigMTime $PrivAdmin); @@ -76,7 +76,7 @@ use vars qw($Lang); NavLink h1 h2 - $Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc + $Cgi %In $MyURL $User %Conf $TopDir $LogDir $BinDir $bpc %Status %Info %Jobs @BgQueue @UserQueue @CmdQueue %QueueLen %StatusHost $Hosts $HostsMTime $ConfigMTime $PrivAdmin @@ -93,11 +93,27 @@ sub NewRequest $Cgi = new CGI; %In = $Cgi->Vars; + if ( !defined($bpc) ) { + ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log}) + if ( !($bpc = BackupPC::Lib->new(undef, undef, undef, 1)) ); + $TopDir = $bpc->TopDir(); + $LogDir = $bpc->LogDir(); + $BinDir = $bpc->BinDir(); + %Conf = $bpc->Conf(); + $Lang = $bpc->Lang(); + $ConfigMTime = $bpc->ConfigMTime(); + } elsif ( $bpc->ConfigMTime() != $ConfigMTime ) { + $bpc->ConfigRead(); + %Conf = $bpc->Conf(); + $Lang = $bpc->Lang(); + $ConfigMTime = $bpc->ConfigMTime(); + } + # # Default REMOTE_USER so in a miminal installation the user # has a sensible default. # - $ENV{REMOTE_USER} = $Conf{BackupPCUser} if ( !defined($ENV{REMOTE_USER}) ); + $ENV{REMOTE_USER} = $Conf{BackupPCUser} if ( $ENV{REMOTE_USER} eq "" ); # # We require that Apache pass in $ENV{SCRIPT_NAME} and $ENV{REMOTE_USER}. @@ -107,19 +123,10 @@ sub NewRequest # $MyURL = $ENV{SCRIPT_NAME}; $User = $ENV{REMOTE_USER}; - - if ( !defined($bpc) ) { - ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log}) - if ( !($bpc = BackupPC::Lib->new(undef, undef, 1)) ); - $TopDir = $bpc->TopDir(); - $BinDir = $bpc->BinDir(); - %Conf = $bpc->Conf(); - $Lang = $bpc->Lang(); - $ConfigMTime = $bpc->ConfigMTime(); - } elsif ( $bpc->ConfigMTime() != $ConfigMTime ) { - $bpc->ServerMesg("log Re-read config file because mtime changed"); - $bpc->ServerMesg("server reload"); - } + # + # Handle LDAP uid=user when using mod_authz_ldap + # + $User = $1 if ( $User =~ /uid=([^,]+)/i ); # # Clean up %ENV for taint checking @@ -154,6 +161,15 @@ EOF {map {$_, 1} split(",", $Hosts->{$host}{moreUsers}) } } } + + # + # Untaint the host name + # + if ( $In{host} =~ /^([\w.\s-]+)$/ ) { + $In{host} = $1; + } else { + delete($In{host}); + } } sub timeStamp2 @@ -205,7 +221,7 @@ sub EscHTML $s =~ s/\"/"/g; $s =~ s/>/>/g; $s =~ s/{Unable_to_connect_to_BackupPC_server}}")); - print (eval("qq{$Lang->{Admin_Start_Server}}")); + my $content = eval("qq{$Lang->{Admin_Start_Server}}"); + Header(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}"), $content); Trailer(); exit(1); } else { @@ -278,21 +294,25 @@ sub GetStatusInfo { my($status) = @_; ServerConnect(); + %Status = () if ( $status =~ /\bhosts\b/ ); + %StatusHost = () if ( $status =~ /\bhost\(/ ); my $reply = $bpc->ServerMesg("status $status"); $reply = $1 if ( $reply =~ /(.*)/s ); eval($reply); # ignore status related to admin and trashClean jobs if ( $status =~ /\bhosts\b/ ) { - delete($Status{$bpc->adminJob}); + foreach my $host ( grep(/admin/, keys(%Status)) ) { + delete($Status{$host}) if ( $bpc->isAdminJob($host) ); + } delete($Status{$bpc->trashJob}); } } sub ReadUserEmailInfo { - if ( (stat("$TopDir/log/UserEmailInfo.pl"))[9] != $UserEmailInfoMTime ) { - do "$TopDir/log/UserEmailInfo.pl"; - $UserEmailInfoMTime = (stat("$TopDir/log/UserEmailInfo.pl"))[9]; + if ( (stat("$LogDir/UserEmailInfo.pl"))[9] != $UserEmailInfoMTime ) { + do "$LogDir/UserEmailInfo.pl"; + $UserEmailInfoMTime = (stat("$LogDir/UserEmailInfo.pl"))[9]; } } @@ -320,35 +340,31 @@ sub CheckPermission $Privileged ||= $Conf{CgiAdminUsers} eq "*"; } $PrivAdmin = $Privileged; + return $Privileged if ( !defined($host) ); + $Privileged ||= $User eq $Hosts->{$host}{user}; $Privileged ||= defined($Hosts->{$host}{moreUsers}{$User}); - return $Privileged; } # # Returns the list of hosts that should appear in the navigation bar -# for this user. If $Conf{CgiNavBarAdminAllHosts} is set, the admin -# gets all the hosts. Otherwise, regular users get hosts for which -# they are the user or are listed in the moreUsers column in the -# hosts file. +# for this user. If $getAll is set, the admin gets all the hosts. +# Otherwise, regular users get hosts for which they are the user or +# are listed in the moreUsers column in the hosts file. # sub GetUserHosts { - my($host) = @_; + my($getAll) = @_; my @hosts; - if ( $Conf{CgiNavBarAdminAllHosts} && CheckPermission() ) { + if ( $getAll && CheckPermission() ) { @hosts = sort keys %$Hosts; } else { @hosts = sort grep { $Hosts->{$_}{user} eq $User || defined($Hosts->{$_}{moreUsers}{$User}) } keys(%$Hosts); } - # - # return the selected host first (if present) - # - return @hosts if ( !defined($host) || !grep(/^$host$/, @hosts) ); - return ($host, grep(!/^$host$/, @hosts)); + return @hosts; } # @@ -392,96 +408,100 @@ sub ConfirmIPAddress sub Header { - my($title, $content) = @_; + my($title, $content, $noBrowse, $contentSub, $contentPost) = @_; my @adminLinks = ( - { link => "", name => $Lang->{Status}, - priv => 1}, - { link => "?action=adminOpts", name => $Lang->{Admin_Options} }, - { link => "?action=summary", name => $Lang->{PC_Summary} }, - { link => "?action=view&type=LOG", name => $Lang->{LOG_file} }, - { link => "?action=LOGlist", name => $Lang->{Old_LOGs} }, - { link => "?action=emailSummary", name => $Lang->{Email_summary} }, - { link => "?action=view&type=config", name => $Lang->{Config_file} }, - { link => "?action=view&type=hosts", name => $Lang->{Hosts_file} }, - { link => "?action=queue", name => $Lang->{Current_queues} }, - { link => "?action=view&type=docs", name => $Lang->{Documentation}, - priv => 1}, - { link => "http://backuppc.sourceforge.net/faq", name => "FAQ", - priv => 1}, - { link => "http://backuppc.sourceforge.net", name => "SourceForge", - priv => 1}, + { link => "", name => $Lang->{Status}}, + { link => "?action=adminOpts", name => $Lang->{Admin_Options}, + priv => 1}, + { link => "?action=editConfig", name => $Lang->{CfgEdit_Edit_Config}, + priv => 1}, + { link => "?action=editConfig&newMenu=hosts", + name => $Lang->{CfgEdit_Edit_Hosts}, + priv => 1}, + { link => "?action=summary", name => $Lang->{PC_Summary}}, + { link => "?action=view&type=LOG", name => $Lang->{LOG_file}, + priv => 1}, + { link => "?action=LOGlist", name => $Lang->{Old_LOGs}, + priv => 1}, + { link => "?action=emailSummary", name => $Lang->{Email_summary}, + priv => 1}, + { link => "?action=queue", name => $Lang->{Current_queues}, + priv => 1}, + @{$Conf{CgiNavBarLinks} || []}, ); - print $Cgi->header(); + my $host = $In{host}; + + print $Cgi->header(-charset => "utf-8"); print < $title -$Conf{CSSstylesheet} + $Conf{CgiHeaders} -
+
EOF - if (!defined($In{host})) { - print < -$content -


+ + if ( defined($Hosts) && defined($host) && defined($Hosts->{$host}) ) { + print "
"; + NavSectionTitle("${EscHTML($host)}"); + print < -