- fixed configure.pl and makeDist.
[BackupPC.git] / lib / BackupPC / CGI / Lib.pm
index 70a7e49..bec4ea8 100644 (file)
@@ -29,7 +29,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0, released 20 Jun 2004.
+# 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
@@ -95,8 +95,9 @@ sub NewRequest
 
     if ( !defined($bpc) ) {
        ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log})
-           if ( !($bpc = BackupPC::Lib->new(undef, undef, 1)) );
+           if ( !($bpc = BackupPC::Lib->new(undef, undef, undef, 1)) );
        $TopDir = $bpc->TopDir();
+       $LogDir = $bpc->LogDir();
        $BinDir = $bpc->BinDir();
        %Conf   = $bpc->Conf();
        $Lang   = $bpc->Lang();
@@ -220,7 +221,7 @@ sub EscHTML
     $s =~ s/\"/"/g;
     $s =~ s/>/>/g;
     $s =~ s/</&lt;/g;
-    $s =~ s{([^[:print:]])}{sprintf("&\#x%02X;", ord($1));}eg;
+    ### $s =~ s{([^[:print:]])}{sprintf("&\#x%02X;", ord($1));}eg;
     return \$s;
 }
 
@@ -309,9 +310,9 @@ sub GetStatusInfo
 
 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];
     }
 }
 
@@ -409,31 +410,28 @@ sub Header
 {
     my($title, $content, $noBrowse, $contentSub, $contentPost) = @_;
     my @adminLinks = (
-        { link => "",                         name => $Lang->{Status}},
-        { link => "?action=adminOpts",        name => $Lang->{Admin_Options},
-                                              priv => 1},
-        { link => "?action=editConfig",       name => "Edit Config",
-                                              priv => 1},
-        { link => "?action=editHosts",        name => "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=view&type=config", name => $Lang->{Config_file},
-                                              priv => 1},
-        { link => "?action=view&type=hosts",  name => $Lang->{Hosts_file},
-                                              priv => 1},
-        { link => "?action=queue",            name => $Lang->{Current_queues},
-                                              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} || []},
     );
     my $host = $In{host};
 
-    print $Cgi->header();
+    print $Cgi->header(-charset => "utf-8");
     print <<EOF;
 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html><head>
@@ -469,11 +467,14 @@ EOF
                    $Lang->{Last_bad_XferLOG_errors_only},
                    " class=\"navbar\"");
        }
-        if ( -f "$TopDir/pc/$host/config.pl"
+        if ( $Conf{CgiUserConfigEditEnable} || $PrivAdmin ) {
+            NavLink("?action=editConfig&host=${EscURI($host)}",
+                    $Lang->{CfgEdit_Edit_Config}, " class=\"navbar\"");
+        } elsif ( -f "$TopDir/pc/$host/config.pl"
                     || ($host ne "config" && -f "$TopDir/conf/$host.pl") ) {
-           NavLink("?action=editConfig&host=${EscURI($host)}",
-                   "Edit Config", " class=\"navbar\"");
-       }
+            NavLink("?action=view&type=config&host=${EscURI($host)}",
+                    $Lang->{Config_file}, " class=\"navbar\"");
+        }
        print "</div>\n";
     }
     print("<div id=\"Content\">\n$content\n");