📄 lib.pm
字号:
{ 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/ ) { foreach my $host ( grep(/admin/, keys(%Status)) ) { delete($Status{$host}) if ( $bpc->isAdminJob($host) ); } delete($Status{$bpc->trashJob}); }}sub ReadUserEmailInfo{ if ( (stat("$LogDir/UserEmailInfo.pl"))[9] != $UserEmailInfoMTime ) { do "$LogDir/UserEmailInfo.pl"; $UserEmailInfoMTime = (stat("$LogDir/UserEmailInfo.pl"))[9]; }}## Check if the user is privileged. A privileged user can access# any information (backup files, logs, status pages etc).## A user is privileged if they belong to the group# $Conf{CgiAdminUserGroup}, or they are in $Conf{CgiAdminUsers}# or they are the user assigned to a host in the host file.#sub CheckPermission{ my($host) = @_; my $Privileged = 0; return 0 if ( $User eq "" && $Conf{CgiAdminUsers} ne "*" || $host ne "" && !defined($Hosts->{$host}) ); if ( $Conf{CgiAdminUserGroup} ne "" ) { my($n,$p,$gid,$mem) = getgrnam($Conf{CgiAdminUserGroup}); $Privileged ||= ($mem =~ /\b\Q$User\E\b/); } if ( $Conf{CgiAdminUsers} ne "" ) { $Privileged ||= ($Conf{CgiAdminUsers} =~ /\b\Q$User\E\b/); $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 $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($getAll) = @_; my @hosts; if ( $getAll && CheckPermission() ) { @hosts = sort keys %$Hosts; } else { @hosts = sort grep { $Hosts->{$_}{user} eq $User || defined($Hosts->{$_}{moreUsers}{$User}) } keys(%$Hosts); } return @hosts;}## Given a host name tries to find the IP address. For non-dhcp hosts# we just return the host name. For dhcp hosts we check the address# the user is using ($ENV{REMOTE_ADDR}) and also the last-known IP# address for $host. (Later we should replace this with a broadcast# nmblookup.)#sub ConfirmIPAddress{ my($host) = @_; my $ipAddr = $host; if ( defined($Hosts->{$host}) && $Hosts->{$host}{dhcp} && $ENV{REMOTE_ADDR} =~ /^(\d+[\.\d]*)$/ ) { $ipAddr = $1; my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($ipAddr); if ( $netBiosHost ne $host ) { my($tryIP); GetStatusInfo("host(${EscURI($host)})"); if ( defined($StatusHost{dhcpHostIP}) && $StatusHost{dhcpHostIP} ne $ipAddr ) { $tryIP = eval("qq{$Lang->{tryIP}}"); ($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($StatusHost{dhcpHostIP}); } if ( $netBiosHost ne $host ) { ErrorExit(eval("qq{$Lang->{Can_t_find_IP_address_for}}"), eval("qq{$Lang->{host_is_a_DHCP_host}}")); } $ipAddr = $StatusHost{dhcpHostIP}; } } return $ipAddr;}############################################################################ HTML layout subroutines###########################################################################sub Header{ my($title, $content, $noBrowse, $contentSub, $contentPost) = @_; my @adminLinks = ( { link => "", name => $Lang->{Status}}, { link => "?action=summary", name => $Lang->{PC_Summary}}, { link => "?action=editConfig", name => $Lang->{CfgEdit_Edit_Config}, priv => 1}, { link => "?action=editConfig&newMenu=hosts", name => $Lang->{CfgEdit_Edit_Hosts}, priv => 1}, { link => "?action=adminOpts", name => $Lang->{Admin_Options}, priv => 1}, { 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}; binmode(STDOUT, ":utf8"); print $Cgi->header(-charset => "utf-8"); print <<EOF;<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>$title</title><link rel=stylesheet type="text/css" href="$Conf{CgiImageDirURL}/$Conf{CgiCSSFile}" title="CSSFile">$Conf{CgiHeaders}<script src="$Conf{CgiImageDirURL}/sorttable.js"></script></head><body onLoad="document.getElementById('NavMenu').style.height=document.body.scrollHeight"><a href="http://backuppc.sourceforge.net"><img src="$Conf{CgiImageDirURL}/logo.gif" hspace="5" vspace="7" border="0"></a><br>EOF if ( defined($Hosts) && defined($host) && defined($Hosts->{$host}) ) { print "<div class=\"NavMenu\">"; NavSectionTitle("${EscHTML($host)}"); print <<EOF;</div><div class="NavMenu">EOF NavLink("?host=${EscURI($host)}", "$host $Lang->{Home}", " class=\"navbar\""); NavLink("?action=browse&host=${EscURI($host)}", $Lang->{Browse}, " class=\"navbar\"") if ( !$noBrowse ); NavLink("?action=view&type=LOG&host=${EscURI($host)}", $Lang->{LOG_file}, " class=\"navbar\""); NavLink("?action=LOGlist&host=${EscURI($host)}", $Lang->{LOG_files}, " class=\"navbar\""); 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}, " class=\"navbar\""); NavLink("?action=view&type=XferErrbad&host=${EscURI($host)}", $Lang->{Last_bad_XferLOG_errors_only}, " class=\"navbar\""); } 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=view&type=config&host=${EscURI($host)}", $Lang->{Config_file}, " class=\"navbar\""); } print "</div>\n"; } print("<div id=\"Content\">\n$content\n"); if ( defined($contentSub) && ref($contentSub) eq "CODE" ) { while ( (my $s = &$contentSub()) ne "" ) { print($s); } } print($contentPost) if ( defined($contentPost) ); print <<EOF;<br><br><br></div><div class="NavMenu" id="NavMenu" style="height:100%">EOF my $hostSelectbox = "<option value=\"#\">$Lang->{Select_a_host}</option>"; my @hosts = GetUserHosts($Conf{CgiNavBarAdminAllHosts}); NavSectionTitle($Lang->{Hosts}); if ( defined($Hosts) && %$Hosts > 0 && @hosts ) { foreach my $host ( @hosts ) { NavLink("?host=${EscURI($host)}", $host) if ( @hosts < $Conf{CgiNavBarAdminAllHosts} ); my $sel = " selected" if ( $host eq $In{host} ); $hostSelectbox .= "<option value=\"?host=${EscURI($host)}\"$sel>" . "$host</option>"; } } if ( @hosts >= $Conf{CgiNavBarAdminAllHosts} ) { print <<EOF;<br><select onChange="document.location=this.value">$hostSelectbox</select><br><br>EOF } if ( $Conf{CgiSearchBoxEnable} ) { print <<EOF;<form action="$MyURL" method="get"> <input type="text" name="host" size="14" maxlength="64"> <input type="hidden" name="action" value="hostInfo"><input type="submit" value="$Lang->{Go}" name="ignore"> </form>EOF } NavSectionTitle($Lang->{NavSectionTitle_}); foreach my $l ( @adminLinks ) { if ( $PrivAdmin || !$l->{priv} ) { my $txt = $l->{lname} ne "" ? $Lang->{$l->{lname}} : $l->{name}; NavLink($l->{link}, $txt); } } print <<EOF;<br><br><br></div>EOF}sub Trailer{ print <<EOF;</body></html>EOF}sub NavSectionTitle{ my($head) = @_; print <<EOF;<div class="NavTitle">$head</div>EOF}sub NavSectionStart{}sub NavSectionEnd{}sub NavLink{ my($link, $text) = @_; 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 <<EOF;<a href="$link"$class>$text</a>EOF } else { print <<EOF;$text<br>EOF }}sub h1{ my($str) = @_; return \<<EOF;<div class="h1">$str</div>EOF}sub h2{ my($str) = @_; return \<<EOF;<div class="h2">$str</div>EOF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -