X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FCGI%2FLib.pm;h=683dd5879386d43c20206934ff602f79eddd11c7;hp=078f3fd18ca098ca003372ccd6f237556737b8a9;hb=3ae3b7557db4829ebfc6f580ceac30376717db6a;hpb=359a795122e5fd5888ad92731147dcd7c1d6db12 diff --git a/lib/BackupPC/CGI/Lib.pm b/lib/BackupPC/CGI/Lib.pm index 078f3fd..683dd58 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 2.1.0_CVS, released 13 Mar 2004. # # See http://backuppc.sourceforge.net. # @@ -48,7 +48,7 @@ use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc); use vars qw(%Status %Info %Jobs @BgQueue @UserQueue @CmdQueue %QueueLen %StatusHost); use vars qw($Hosts $HostsMTime $ConfigMTime $PrivAdmin); -use vars qw(%UserEmailInfo $UserEmailInfoMTime %RestoreReq); +use vars qw(%UserEmailInfo $UserEmailInfoMTime %RestoreReq %ArchiveReq); use vars qw($Lang); @ISA = qw(Exporter); @@ -80,7 +80,7 @@ use vars qw($Lang); %Status %Info %Jobs @BgQueue @UserQueue @CmdQueue %QueueLen %StatusHost $Hosts $HostsMTime $ConfigMTime $PrivAdmin - %UserEmailInfo $UserEmailInfoMTime %RestoreReq + %UserEmailInfo $UserEmailInfoMTime %RestoreReq %ArchiveReq $Lang ); @@ -93,11 +93,24 @@ 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, 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"); + } + # # 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}. @@ -108,21 +121,6 @@ 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->ConfigRead(); - %Conf = $bpc->Conf(); - $ConfigMTime = $bpc->ConfigMTime(); - $Lang = $bpc->Lang(); - } - # # Clean up %ENV for taint checking # @@ -223,10 +221,6 @@ sub ErrorExit my(@mesg) = @_; my($head) = shift(@mesg); my($mesg) = join("

\n

", @mesg); - $Conf{CgiHeaderFontType} ||= "arial"; - $Conf{CgiHeaderFontSize} ||= "3"; - $Conf{CgiNavBarBgColor} ||= "#ddeeee"; - $Conf{CgiHeaderBgColor} ||= "#99cc33"; if ( !defined($ENV{REMOTE_USER}) ) { $mesg .= <ServerMesg("log User $User (host=$In{host}) got CGI error: $head") if ( defined($bpc) ); if ( !defined($Lang->{Error}) ) { - Header("BackupPC: Error"); $mesg = <$mesg

EOF + Header("BackupPC: Error", $content); Trailer(); } else { - Header(eval("qq{$Lang->{Error}}")); - print (eval("qq{$Lang->{Error____head}}")); + my $content = eval("qq{$Lang->{Error____head}}"); + Header(eval("qq{$Lang->{Error}}"), $content); Trailer(); } exit(1); @@ -267,7 +261,16 @@ sub ServerConnect return if ( $bpc->ServerOK() ); $bpc->ServerDisconnect(); if ( my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}) ) { - ErrorExit(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}")); + if ( CheckPermission() + && -f $Conf{ServerInitdPath} + && $Conf{ServerInitdStartCmd} ne "" ) { + my $content = eval("qq{$Lang->{Admin_Start_Server}}"); + Header(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}"), $content); + Trailer(); + exit(1); + } else { + ErrorExit(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}")); + } } } @@ -325,19 +328,22 @@ sub CheckPermission # # 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 { - if ( $Conf{CgiNavBarAdminAllHosts} && CheckPermission() ) { - return sort keys %$Hosts; - } + my($host, $getAll) = @_; + my @hosts; - return sort grep { $Hosts->{$_}{user} eq $User || + if ( $getAll && CheckPermission() ) { + @hosts = sort keys %$Hosts; + } else { + @hosts = sort grep { $Hosts->{$_}{user} eq $User || defined($Hosts->{$_}{moreUsers}{$User}) } keys(%$Hosts); + } + return @hosts; } # @@ -381,94 +387,125 @@ sub ConfirmIPAddress sub Header { - my($title) = @_; + my($title, $content, $noBrowse, $contentSub, $contentPost) = @_; my @adminLinks = ( - { link => "", name => $Lang->{Status}, - priv => 1}, - { 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 => "", name => $Lang->{Status}, + priv => 1}, + { link => "?action=adminOpts", name => $Lang->{Admin_Options} }, + { link => "?action=summary", name => $Lang->{PC_Summary}, + priv => 1}, + { 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}, + priv => 1}, { link => "http://backuppc.sourceforge.net", name => "SourceForge", - priv => 1}, + priv => 1}, ); + my $host = $In{host}; + print $Cgi->header(); print < $title +$Conf{CSSstylesheet} $Conf{CgiHeaders} - - - - -
+ +
EOF - NavSectionTitle("BackupPC"); - print " \n"; - if ( defined($In{host}) && defined($Hosts->{$In{host}}) ) { - my $host = $In{host}; - NavSectionTitle( eval("qq{$Lang->{Host_Inhost}}") ); - NavSectionStart(); - NavLink("?host=${EscURI($host)}", $Lang->{Home}); - NavLink("?action=view&type=LOG&host=${EscURI($host)}", $Lang->{LOG_file}); - NavLink("?action=LOGlist&host=${EscURI($host)}", $Lang->{Old_LOGs}); - if ( -f "$TopDir/pc/$host/SmbLOG.bad" - || -f "$TopDir/pc/$host/SmbLOG.bad.z" - || -f "$TopDir/pc/$host/XferLOG.bad" - || -f "$TopDir/pc/$host/XferLOG.bad.z" ) { - NavLink("?action=view&type=XferLOGbad&host=${EscURI($host)}", - $Lang->{Last_bad_XferLOG}); - NavLink("?action=view&type=XferErrbad&host=${EscURI($host)}", - $Lang->{Last_bad_XferLOG_errors_only}); - } - if ( -f "$TopDir/pc/$host/config.pl" ) { - NavLink("?action=view&type=config&host=${EscURI($host)}", $Lang->{Config_file}); - } - NavSectionEnd(); + + if ( defined($Hosts) && defined($host) && defined($Hosts->{$host}) ) { + print "
"; + NavSectionTitle("${EscURI($host)}"); + print < +\n"; } - NavSectionTitle($Lang->{NavSectionTitle_}); - NavSectionStart(); - foreach my $l ( @adminLinks ) { - if ( $PrivAdmin || $l->{priv} ) { - NavLink($l->{link}, $l->{name}); - } else { - NavLink(undef, $l->{name}); - } + print("
\n$content\n"); + if ( defined($contentSub) && ref($contentSub) eq "CODE" ) { + while ( (my $s = &$contentSub()) ne "" ) { + print($s); + } } - NavSectionEnd(); - NavSectionTitle($Lang->{Hosts}); + print($contentPost) if ( defined($contentPost) ); print < -
$Lang->{Host_or_User_name}
- - -
+


+ + EOF } sub Trailer { print < EOF } @@ -478,41 +515,33 @@ sub NavSectionTitle { my($head) = @_; print < -$head - - + EOF } sub NavSectionStart { - my($padding) = @_; - - $padding = 1 if ( !defined($padding) ); - print < -EOF } sub NavSectionEnd { - print "\n"; } sub NavLink { my($link, $text) = @_; - print "·"; if ( defined($link) ) { + my($class); + $class = " class=\"NavCurrent\"" + if ( length($link) && $ENV{REQUEST_URI} =~ /\Q$link\E$/ + || $link eq "" && $ENV{REQUEST_URI} !~ /\?/ ); $link = "$MyURL$link" if ( $link eq "" || $link =~ /^\?/ ); print <$text +$text EOF } else { print <$text +$text
EOF } } @@ -521,12 +550,7 @@ sub h1 { my($str) = @_; return \< - - $str - - +
$str
EOF } @@ -534,11 +558,6 @@ sub h2 { my($str) = @_; return \< - - $str - - +
$str
EOF }