@data=@values=();
$recordCount=0;
while(($resultSetObj->MoveNext()) == 1) {
$data=$resultSetObj->GetAllColumnValues(0);
#print "DATA:\"".join("\",\"",@$data)."\"
";
if($lastRecord && ($lastRecord ne $$data[$j]))
{
#print "COMPARE:$lastRecord $$data[1]
";
for($i=0;$i<@fields;$i++)
{
$value=join(',',sort keys(%{$results{$fields[$i]}}));
push(@values,$value);
#push(@values,";");
}
#print "VALUES:@values
";
push(@data,[@values]);
$recordCount++;
undef @values;
undef %results;
}
for($i=0;$i<@$data;$i+=2)
{
$results{$$data[$i]}{$$data[$i+1]}++;
}
#print "RESULT:".Dumper(\%results)."
";
$j=0;
while($$data[$j] ne "id")
{
$j++;
}
$j++;
$lastRecord=$$data[$j];
}
if ($lastRecord){
for($i=0;$i<@fields;$i++)
{
$value=join(',',sort keys(%{$results{$fields[$i]}}));
push(@values,$value);
}
$recordCount++;
push(@data,[@values]);
undef @values;
undef %results;
}
techba
Tuesday, July 19, 2011
Thursday, May 5, 2011
checkout
#!/usr/bin/perl
#base reference directory
#note -- these directories & files MUST BE ALL LOWERCASE :)
#############
# These two directories need to be created under this directory:
# data/
# history/
# and need to be reflected in the names below
#The Data Directory. ("data" -> data/)
$based="/usr/local/apache2/htdocs/checkout-3.18/data";
#The History Directory ("history" -> history/)
$save="/usr/local/apache2/htdocs/checkout-3.18/history";
#set the path to your images (to be accessed like $images/cisco_logo.gif)
$images="/images";
#what directory are we in?
#$mydir="/home/httpd/checkout-sj";
$mydir="/usr/local/apache2/htdocs/checkout-3.18";
#if you want a background, set it here:
##bg scheme 1
#$background="bgcolor=#d0d0d0 background=$images/bkgnd.jpg";
#$eback=" bgcolor=lightgrey ";
#$ebacknofill=" bgcolor=lightgrey ";
#$heading=" bgcolor=#f9f9ea ";
##bg scheme #2
$background=" bgcolor=white ";
$eback=" bgcolor=#dcdcff ";
$ebacknofill=" bgcolor=lightgrey ";
$heading=" bgcolor=#f9f9e0 ";
#################
# Theoretically, nothing below this line needs to be changed...
#################
#
#
#
# Lab Equipment Reservation Program
# Checkout Page Cisco Systems
#
# Author: Steve Padgett -- stpadget@cisco.com
#
# History:
# 13-Dec-1999 - tgage - Added code to protect '<', '>', and '"' in
# edit mode. Also expanded field lengths for
# name & type to allow imbedded HTML.
#
# 20-May-1999 - tgage - Changed problem reports footer to send
# email to checkout@cisco.com, also changed data
# file pointers to point at the checkout page's
# new home.
# Feb 1999, Version 3 Released
# * Lab support
# * Layout redesign
# Jan 1998, Version 2 Released
# * Flat file database structure
# * Paging support
# * File locking
# Pre 1998 (?)
#
# The current maintainer of this script is Tim Gage or Steve Padgett
# (when he returns), Please send any bugs, wish lists, etc, to
# checkout@cisco.com so that the appropriate person can help you.
#
$VERSION="VER 3.18";
@wdate=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
@day=('U','M','T','W','R','F','S');
&Handle_Path;
&Get_Input;
if ($ARGV[0] eq "pager") {
chdir("$mydir");
&do_find_pageable;
exit(0);
}
%USER=&read_info_file("$save/$ENV{'REMOTE_ADDR'}.hist");
if (defined $FORM{'doredir'}) {
&print_redirect($FORM{'redirto'});
}
if (defined $FORM{'available'}) {
$USER{'available'}=$FORM{'available'};
&write_info_file("$save/$ENV{'REMOTE_ADDR'}.hist",%USER);
}
if ($FORM{'lab'} eq "pager") {
&paging_service($FORM{'user'});
exit(0);
}
#short-circuit the validation process
if (($labvalid=&valid_lab($FORM{'lab'})) && ($groupvalid=&valid_group($FORM{'lab'},$FORM{'group'})))
{ $zonevalid=&valid_zone($FORM{'lab'},$FORM{'group'},$FORM{'zone'}); }
if ((!defined $labvalid) || (!$labvalid)) { undef $labvalid; undef $FORM{'lab'}; }
if ((!defined $groupvalid) || (!$groupvalid)) { undef $groupvalid; undef $FORM{'group'}; }
if ((!defined $zonevalid) || (!$zonevalid)) { undef $zonevalid; undef $FORM{'zone'}; }
#
# handle stats processing
#
if (defined $FORM{'stats'}) {
&show_stats($FORM{'lab'},$FORM{'group'},$FORM{'zone'});
exit(0);
}
#
# handle searches
#
if (($FORM{'stext'} ne "")) {
$msg="";
$|=1; #do this, makes it (look) faster on searches
$msg=&save_checkout if (defined $FORM{'checkout'});
&do_search($msg);
exit(0);
}
#
# handle the pop-up boxes
#
if (defined $FORM{'short'}) {
&print_short;
exit(0);
}
#
#handle checkouts/in, edits, purges, and creates
#
$editmode=1 if (defined $FORM{'editz'});
&save_data if (defined $FORM{'save'});
&purge_zones if (defined $FORM{'purge'});
&create_itm if (defined $FORM{'create'});
#
#Is it a valid lab?
#
if (($FORM{'lab'} eq "") || (!defined $labvalid)) {
&read_and_show_labs;
exit(0);
}
# $labvalid=1;
#
#Is it a valid group?
#
if (($FORM{'group'} eq "") || (!defined $groupvalid)) {
&read_and_show_groups($FORM{'lab'});
exit(0);
}
# $groupvalid=1;
#
#handle new zone creation (new commserver)
#
&create_new_zone("$based/$FORM{'lab'}/$FORM{'group'}") if (defined $FORM{'newzone'});
#
# Is it a valid zone?
#
if (($FORM{'zone'} ne "") && (defined $zonevalid)) {
# $zonevalid=1;
$msg="";
$msg=&save_checkout if (defined $FORM{'checkout'});
#
# Is it a valid machine?
#
if (($FORM{'machine'} ne "") && (&valid_machine($FORM{'lab'},$FORM{'group'},$FORM{'zone'},$FORM{'machine'}))) {
$machinevalid=1;
&show_machine($FORM{'lab'},$FORM{'group'},$FORM{'zone'},$FORM{'machine'});
exit(0);
}
$editmode=2 if (defined $FORM{'editz'});
%zones=&read_zone_file($FORM{'lab'},$FORM{'group'},$FORM{'zone'});
&show_zones($FORM{'lab'},$FORM{'group'},$msg,%zones);
exit(0);
}
#
#otherwise, we're here...
#
# if (($FORM{'zone'} eq "")) {
$msg="";
$msg=&save_checkout if (defined $FORM{'checkout'});
%zones=&read_zones("$FORM{'lab'}","$FORM{'group'}");
&show_zones($FORM{'lab'},$FORM{'group'},$msg,%zones);
exit(0);
# }
print "Content-type: text/plain\n\n";
&print_env;
#
#is the lab name valid?
#
sub valid_lab {
my($lab)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($lab));
return 0 if (! -d "$based/$lab");
return 1;
}
#
#just test to see if the name characters are valid.
#
sub valid_name {
my($lab)=@_;
return 0 if ((!defined $lab) || ($lab =~ /[^A-Za-z0-9 \-\_\+\=\.]/) || ($lab =~ /^\./) || ($lab eq ""));
return 1;
}
#
#is the group name valid?
#
sub valid_group {
my($lab,$group)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($group));
return 0 if (! -d "$based/$lab/$group");
return 1;
}
#
#is the zone name valid?
#
sub valid_zone {
my($lab,$group,$zone)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($zone));
return 0 if (! -d "$based/$lab/$group/$zone");
return 1;
}
#
#is the machine name valid?
#
sub valid_machine {
my($lab,$group,$zone,$machine)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($machine));
return 0 if (! -e "$based/$lab/$group/$zone/$machine.eq");
return 1;
}
#
#log message to file
#
sub log_msg {
my($path,$message)=@_;
my($nowtime);
$nowtime=localtime();
open(DATA,">>$path");
print DATA "$nowtime($ENV{'REMOTE_ADDR'}-".time()."): $message\n";
close(DATA);
}
#
#write out the file supplied to it as a name=value pair
#
sub write_info_file {
my($infofile,%INFO)=@_;
my($line,$itm);
$line="";
#put it into a buffer
foreach $itm (sort keys %INFO) {
$line.="$itm=$INFO{$itm}\n"
}
#write it out
system("/usr/bin/lockfile $infofile.lock");
open(DATA,">$infofile");
print DATA $line;
close(DATA);
unlink("$infofile.lock");
}
#
#read out the info file passed into it, and return it as hashes
#
sub read_info_file {
my(@if)=@_;
my($infofile,%INFO);
foreach $infofile (@if) {
# print "opening file $infofile\n" if ($infofile =~ /info$/);
if (open(DATA,"$infofile")) {
while () {
chomp;
next if ((/^#/) || (!/^(.*?)\=(.*)/));
$INFO{$1}=$2;
}
close(DATA);
}
}
return %INFO;
}
#
#read and return just one zone.
#
sub read_zone_file {
my($lab,$group,$file)=@_;
my(%INF);
%{$INF{$file}}=&read_info_file("$based/$lab/$group/$file/.info");
%{$INF{$file}{'equ'}}=&read_equipment("$based/$lab/$group/$file");
delete $INF{$file}{'equ'} if (defined $INF{$file}{'equ'}{'a!a'});
return %INF;
}
#
#read the zones file out of the directory
#
sub read_zones {
my($lab,$group)=@_;
my(%INF);
opendir(DIR,"$based/$lab/$group");
@files=readdir(DIR);
closedir(DIR);
undef %INF;
foreach $file (@files) {
next if (($file =~ /^\./) || (! -d "$based/$lab/$group/$file"));
%{$INF{$file}}=&read_info_file("$based/$lab/$group/$file/.info");
%{$INF{$file}{'equ'}}=&read_equipment("$based/$lab/$group/$file");
delete $INF{$file}{'equ'} if (defined $INF{$file}{'equ'}{'a!a'});
}
return %INF;
}
#
#read in the .eq files from the directory.
#
sub read_equipment {
my($dir)=@_;
my(@files,%INF,$file,$st,$found);
$found=0;
opendir(DIR,$dir);
@files=grep(/\.eq$/,readdir(DIR));
closedir(DIR);
foreach $file (@files) {
%{$INF{$file}}=&read_info_file("$dir/$file");
#process the searching stuff
$st="${1}[0-9][0-9]" if ($FORM{'stext'} =~ /(.*)00$/);
if (($FORM{'stext'} ne "")
&& ($INF{$file}{'name'} !~ /$FORM{'stext'}/i)
&& ($INF{$file}{'checkout-login'} !~ /$FORM{'stext'}/i)
&& ($INF{$file}{'type'} !~ /$FORM{'stext'}/i)
&& ((!defined $st) || ($INF{$file}{'type'} !~ /$st/i))
&& ($INF{$file}{'checkout-comment'} !~ /$FORM{'stext'}/i)) {
delete $INF{$file};
} elsif (($FORM{'stext'} ne "") && (defined $FORM{'short'}) && (uc($INF{$file}{'checkout-login'}) ne uc($FORM{'stext'}))) {
delete $INF{$file};
} else { $found++; }
#end search processing
}
return %INF if ($found > 0);
#return this special thing to notify the calling function that it didn't find anything
return ('a!a' => 1);
}
#
#convert a unix time to a date/time, significant figures determined by the units passed to it
#
sub str_time {
my($mtime,$units)=@_;
my(@d,$buf,$day);
$day=int($mtime/(60*60*24));
if ($day < 1) {
$buf=sprintf "%d:%02d hrs",($mtime/(60*60)),($mtime/60)%60;
} elsif ($day < 3000) {
$buf=sprintf "%d day%s %d:%02d hrs",$day,($day != 1)?"s":"",($mtime/(60*60))%24,($mtime/60)%60;
} else {
@d=localtime($mtime);
$buf=sprintf "%s %d-%d-%02d",$wdate[$d[6]],$d[4]+1,$d[3],$d[5]%100;
if ($units eq "hours") {
$buf.=sprintf " %d:00",$d[2]+1; #yes, weird, but this is how we perceive it... right?
} elsif ($units eq "minutes") {
$buf.=sprintf " %d:%02d",$d[2],$d[1];
}
}
return $buf;
}
#
#print out the ".banner" file in the directory
#
sub print_banner {
my($dir,$editm)=@_;
return if ((! -e "$dir/.banner") && (!defined $editm));
if ($editm==2) {
print "
HTML FORMATTED-BANNER, optional
\n" if ($editm==2);
}
#
#send out a HTTP redirect
#
sub print_redirect {
my($urlto)=@_;
my($port)="";
$port=":$ENV{'SERVER_PORT'}" if ($ENV{'SERVER_PORT'} ne 80);
if ($ENV{'REQUEST_URI'} eq $urlto) {
if ($urlto =~ /\?$/) { $urlto=substr($urlto,0,-1); } else { $urlto.="?"; }
}
print <Moved...
It's moved to here.
You would be taken there automatically without ever seeing this message, but your browser didn't like the redirect... hmm.
EOM
exit(0);
}
#
#a searchin' we shall go... a searchin' we shall go... hi ho 'la 'dar-i-o a searching we shall go.
#
sub print_search_bar {
my($lab,$group,$zone,$labt,$groupt,$zonet)=@_;
my(%SEL);
print <
\n";
}
#
#print out the checkout box to the screen
#
sub print_checkout_box {
my($gr,$max,$savegr,$mult,$i,$grinc,@d,$days);
$i=localtime();
print <
Depending on the individual group setup, checkout times may be truncated to the max-checkout-time.
Leave the Login field blank to check in
\n$i
EOM
}
#
#print out the history bar on the screen
#
sub print_history_bar {
my($ip)=@_;
my(%HISTI,@histi,$itm);
%HISTI=&read_info_file("$save/$ip.hist");
@hist=grep(/^HIST/,keys %HISTI);
return if ($#hist < 0); #don't display anything if the history dosen't exist
print <
EOM
}
#
# Toggle paging for the user
#
sub paging_service {
my($user)=@_;
my(%USERS);
&print_header("Paging Services","Paging Services");
%USERS=&read_info_file("$save/nopage.users");
if (defined $FORM{'paging-off'}) {
$USERS{$FORM{'for'}}=1;
&write_info_file("$save/nopage.users",%USERS);
} elsif (defined $FORM{'paging-on'}) {
delete $USERS{$FORM{'for'}};
&write_info_file("$save/nopage.users",%USERS);
}
print <
EOM
if ($user ne "") {
if ($USERS{$user} ne "") {
print <
EOM
} else {
print <
EOM
}
}
print " Back\n";
&print_trailer;
}
#
#actually print out the equipment...
#this is pretty much the guts of the display
#
sub print_equipment_list {
my($lab,$group,%ZONES)=@_;
my($zone,%ZM,$equ,$tel,$nexttime,@nowtime,$nowtime,$citime,$cotime,$newitm,$itmon,$mx,$pr);
#global GROUP INFORMATION variable
%{$GI{$group}}=&read_info_file("$based/.info","$based/$lab/.info","$based/$lab/$group/.info") if (!defined $GI{$group});
$pr=0;
#compute the time-at-the-next-increment-unit ;)
@nowtime=localtime();
$nowtime=time();
if ($GI{$group}{'checkout-increment-units'} eq "minutes") {
$mx=60;
$nexttime=$nowtime-$nowtime[0]; #+59
} elsif ($GI{$group}{'checkout-increment-units'} eq "hours") {
$nexttime=$nowtime -($nowtime[0]) - ($nowtime[1])*60; #+59+59*60
$mx=60*60;
} else {
# } elsif ($GI{$group}{'checkout-increment-units'} eq "days") {
#default of days
$nexttime=$nowtime-$nowtime[0]-($nowtime[1]+($nowtime[2])*60)*60; #+59+59*60+23*60*60
$mx=60*60*24;
}
$mx*=$GI{$group}{'max-checkout-time'}; #we want the max checkout time in mx
foreach $zone (sort {uc($ZONES{$a}{'name'}) cmp uc($ZONES{$b}{'name'})} keys %ZONES) {
#skip it if there's nothing to print & we're not in editmode
next if ((!defined $ZONES{$zone}{'equ'}) && (!defined $editmode) && (($FORM{'zone'} ne $zone) || ($FORM{'stext'} ne "")));
if (!defined $ZONES{$zone}{'equ'}) {
$ZONES{$zone}{'empty'}=1;
}
if ($ZONES{$zone}{'ip'}) {
$tel="telnet://$ZONES{$zone}{'ip'}"; #can telnet
$name="$ZONES{$zone}{'name'}";
} else {
$name="$ZONES{$zone}{'name'}";
$tel=""; #no telnet
}
$pr++;
#$aa=localtime($nexttime);
#print "$aa $nexttime";
if ($editmode==2) {
print <
EOM
}
#
#print out what we just did...
#
sub print_did_box {
my($msg)=@_;
if ($msg ne "") {
print <
EOM
}
}
#
#print out the zone(s) on the screen.
#
sub show_zones {
my($lab,$group,$msg,%ZONES)=@_;
my($zone,%GRP,%SEL,%RST,$owner);
%RST=&read_info_file("$based/.info","$based/$lab/.info");
%GRP=&read_info_file("$based/$lab/$group/.info");
$GRP{'name'}=$GRP{'name'}||"$group";
foreach $zone (keys %RST) {
$GRP{$zone}=$RST{$zone} if (!defined $GRP{$zone});
}
if ((defined $FORM{'commgen'}) && (defined $zonevalid)) {
&generate_commserver_text("$lab","$group","$FORM{'zone'}");
exit(0);
}
&print_header("Zone Selection -- $GRP{'name'}","Zone Selection for $GRP{'name'}");
if ((defined $editmode) && (!defined $zonevalid)) {
&show_editor_head("$lab/$group",%GRP);
}
&print_banner("$based/$lab/$group",($editmode==1)?2:0);
if ((defined $editmode) && (!defined $zonevalid)) {
print <
EOM
foreach $zone (keys %ZONES) {
# print "\n-$ZONES{$zone}{'equ'}-\n";
next if ((defined $ZONES{$zone}{'equ'}));
# && (%{$ZONES{$zone}{'equ'}} > 0));
print "\n";
}
}
&print_did_box($msg);
&print_equipment_list($lab,$group,%ZONES);
if ((!defined $editmode) && (!defined $FORM{'short'})) {
&print_checkout_box;
$owner="This equipment maintained by $GRP{'contact-name'}
" if ($GRP{'contact-name'} ne "");
print <
\n";
}
&print_trailer;
}
#
#print out the zone(s) on the screen.
#
sub show_machine {
my($lab,$group,$zone,$machine)=@_;
my(%INFO,@lines,$i,$lines,$status,%GRP,@nowtime,$nowtime,$nexttime,$mx,%LOC,$location,$notes,$confstr);
%INFO=&read_info_file("$based/$lab/$group/$zone/$machine.eq");
%GRP=&read_info_file("$based/.info","$based/$lab/.info","$based/$lab/$group/.info");
%LOC=&read_info_file("$based/$lab/$group/$zone/.info");
$INFO{'name'}=$INFO{'name'}||"$machine";
if (defined $FORM{'savenotes'}) {
&log_msg("$based/$lab/$group/$zone/$machine.eq.log","Notes Updated");
open(DATA,">$based/$lab/$group/$zone/$machine.eq.notes");
print DATA "$FORM{'notes'}";
close(DATA);
&print_redirect("$ENV{'SCRIPT_NAME'}/$lab/$group/$zone/$machine");
exit(0);
}
&print_header("Equipment View -- $INFO{'name'}","Equipment View");
if (open(DATA,"$based/$lab/$group/$zone/$machine.eq.notes")) {
while () { $notes.=$_; }
close(DATA);
}
if (open(DATA,"$based/$lab/$group/$zone/$machine.eq.log")) {
while () { push @lines,$_; }
close(DATA);
}
for ($i=$#lines;(($i >= 0) && (($i >= $#lines - 19) || (defined $FORM{'logall'})));$i--) {
$lines=sprintf "%d. %s%s",$i+1,$lines[$i],$lines;
}
chomp $lines;
if ($INFO{'static'} ne "yes") {
$status="Not currently checked out";
#### compute nexttime
@nowtime=localtime();
$nowtime=time();
if ($GRP{'checkout-increment-units'} eq "minutes") {
$nexttime=$nowtime-$nowtime[0]; #+59
$mx=60;
} elsif ($GRP{'checkout-increment-units'} eq "hours") {
$nexttime=$nowtime -($nowtime[0]) - ($nowtime[1])*60; #+59+59*60
$mx=60*60;
} else {
#default of days
$nexttime=$nowtime-$nowtime[0]-($nowtime[1]+($nowtime[2])*60)*60; #+59+59*60+23*60*60
$mx=60*60*24;
}
###########
$mx*=$GRP{'max-checkout-time'}; #we want the max checkout time in mx
if (($INFO{'checkout-login'} ne "") && ($INFO{'checkout-to'} > $nexttime)) {
$status=sprintf "Checked out from %s to %s by %s for \"%s\"",
&str_time($INFO{'checkout-from'},$GRP{'checkout-increment-units'}),&str_time($INFO{'checkout-to'},$GRP{'checkout-increment-units'}),$INFO{'checkout-login'},$INFO{'checkout-comment'};
}
} else {
$status="Static: $INFO{'static-text'}";
}
$location=sprintf "%s in %s", $LOC{'name'}||$zone,$GRP{'name'}||$group;
if (($LOC{'ip'} ne "") && ($INFO{'port'} ne "")) {
$location=sprintf "%s (%s) on port %s in %s -- Connect",$LOC{'name'}||$zone,$LOC{'ip'},$INFO{'port'},$GRP{'name'}||$group,$LOC{'ip'},$INFO{'port'};
$confstr=sprintf "Configuration (IOS only):
[Reconfigure]
[View Running Config]",
&webify($INFO{'name'}),&webify($INFO{'port'}),&webify($LOC{'ip'}),
&webify($INFO{'name'}),&webify($INFO{'port'}),&webify($LOC{'ip'});
}
print <
EOM
if (!defined $FORM{'updnotes'}) {
print <
EOM
} else {
print <
EOM
}
print <
EOM
$GI{$group}={%GRP};
&print_checkout_box if ($INFO{'static'} ne "yes");
&print_trailer;
}
#
#save the history to the file -- rotating out old entries and bumping up new ones...
#
sub save_history {
my($ip,$path,$lab,$group,$zone,$mach)=@_;
my(%HISTI,@save,$itm,$max);
$max=4;
$lab="$1..." if ((length($lab) > 8) && ($lab =~ /^(.....)/));
$group="$1..." if ((length($group) > 9) && ($group =~ /^(......)/));
%HISTI=&read_info_file("$save/$ip.hist");
$HISTI{'accesses'}++;
$path=$1 if ($path =~ /^(.*)\/$/);
push @savep,$path;
push @save,sprintf "%s:%s%s%s",$lab,$group,($zone ne "")?":$zone":"",(($zone ne "") && ($mach ne ""))?":$mach":"";
foreach $itm (sort grep(/^HIST/,keys %HISTI)) {
if ($path ne $HISTI{"P$itm"}) {
push @save,$HISTI{$itm};
push @savep,$HISTI{"P$itm"};
last if ($max-- == 0);
}
}
#now delete the entries out of HISTI
foreach $itm (sort grep(/^HIST/,keys %HISTI)) {
delete $HISTI{$itm};
delete $HISTI{"P$itm"};
}
#and save the new ones
$max=0;
foreach $itm (@save) {
$HISTI{"HIST$max"}=$itm;
$HISTI{"PHIST$max"}=$savep[$max];
$max++;
}
&write_info_file("$save/$ip.hist",%HISTI);
}
#
# Read in groups from the directory
#
sub read_groups {
my($labdir,$all)=@_;
my($group,%GROUPS,%INFO);
foreach $group (&read_dir("$labdir")) {
%INFO=&read_info_file("$labdir/$group/.info");
if ((($INFO{'hidden'} eq "") || (defined $all)) || (defined $FORM{'short'})) {
$GROUPS{$group}=$INFO{'name'}||$group;
}
}
return %GROUPS;
}
#
#read in the labs from the directory
#
sub read_labs {
my($labdir,$all)=@_;
#
#does the same thing, why rewrite it now?
#
return &read_groups($labdir,$all);
}
#
#read in the name of the groups from the lab and show them.
#
sub read_and_show_groups {
my($lab)=@_;
my($group,%GROUPS,$zone,@files,%INFO,$col,%INF,$inf,$cnt);
$col=0;
%INFO=&read_info_file("$based/$lab/.info");
$INFO{'name'}=$INFO{'name'}||$lab;
&print_header("Group Selection -- $INFO{'name'}","Group Selection");
if (defined $editmode) {
&show_editor_head("$lab/$group",%INFO);
print <
EOM
}
&print_banner("$based/$lab",(defined $editmode)?2:0);
#
#get a listing of all the groups
#
%GROUPS=&read_groups("$based/$lab");
undef %INFO;
print "
\n";
if (!defined $editmode) {
print "Edit Mode\n";
}
&print_trailer;
}
#
#Print out the "short" screen -- nothing but the top, search box, and trailer
#
sub print_short {
&print_header("Personal Screen","Enter your Username");
&print_trailer;
}
#
#read the names of the valid labs and print the on the screen!
#
sub read_and_show_labs {
my(%LABS,$lab,$printblank,%GROUPS,$col,%INFO,$cnt);
$col=0;
#get a listing of all the labs
%LABS=&read_labs("$based");
&print_header("Lab Selection","Lab Selection");
if (defined $editmode) {
print <
EOM
}
&print_banner("$based",(defined $editmode)?2:0);
print "
\n";
if (!defined $editmode) {
print "Edit Mode\n";
}
&print_trailer;
}
#
#the trailer
#
sub print_trailer {
my(@d);
#get the last modify time, yes this is y2k compliant
@d=stat($ENV{'SCRIPT_FILENAME'});
@d=localtime($d[9]); $d[4]++; $d[5]+=1900;
#print it out
print <

Last modified on $d[4]-$d[3]-$d[5] - $VERSION - Send complaints/requests to ADI-AUTOMATION-TEAM mailing-list
EOM
}
#
#the header.
#pretty straightfoward.
#
sub print_header {
my($title,$top)=@_;
my($nowtime,%INFO,$sb,$groupt,$labt,$zonet,$refresh,$machinet,$which);
$nowtime=localtime();
$title=" -- $title" if ($title ne "");
$sb="$ENV{'SCRIPT_NAME'}"||"/";
if (!defined $editmode) {
if ((defined $labvalid) && (defined $groupvalid)) {
%INFO=&read_info_file("$based/.info","$based/$FORM{'lab'}/.info","$based/$FORM{'lab'}/$FORM{'group'}/.info");
$refresh="Refresh: $INFO{'default-refresh-seconds'}" if ($INFO{'default-refresh-seconds'} > 0);
} else {
$refresh="Refresh: 600";
}
}
if (defined $FORM{'short'}) {
&print_short_header($title,$top);
} else {
print <
Checkout Page$title
#base reference directory
#note -- these directories & files MUST BE ALL LOWERCASE :)
#############
# These two directories need to be created under this directory:
# data/
# history/
# and need to be reflected in the names below
#The Data Directory. ("data" -> data/)
$based="/usr/local/apache2/htdocs/checkout-3.18/data";
#The History Directory ("history" -> history/)
$save="/usr/local/apache2/htdocs/checkout-3.18/history";
#set the path to your images (to be accessed like $images/cisco_logo.gif)
$images="/images";
#what directory are we in?
#$mydir="/home/httpd/checkout-sj";
$mydir="/usr/local/apache2/htdocs/checkout-3.18";
#if you want a background, set it here:
##bg scheme 1
#$background="bgcolor=#d0d0d0 background=$images/bkgnd.jpg";
#$eback=" bgcolor=lightgrey ";
#$ebacknofill=" bgcolor=lightgrey ";
#$heading=" bgcolor=#f9f9ea ";
##bg scheme #2
$background=" bgcolor=white ";
$eback=" bgcolor=#dcdcff ";
$ebacknofill=" bgcolor=lightgrey ";
$heading=" bgcolor=#f9f9e0 ";
#################
# Theoretically, nothing below this line needs to be changed...
#################
#
#
#
# Lab Equipment Reservation Program
# Checkout Page Cisco Systems
#
# Author: Steve Padgett -- stpadget@cisco.com
#
# History:
# 13-Dec-1999 - tgage - Added code to protect '<', '>', and '"' in
# edit mode. Also expanded field lengths for
# name & type to allow imbedded HTML.
#
# 20-May-1999 - tgage - Changed problem reports footer to send
# email to checkout@cisco.com, also changed data
# file pointers to point at the checkout page's
# new home.
# Feb 1999, Version 3 Released
# * Lab support
# * Layout redesign
# Jan 1998, Version 2 Released
# * Flat file database structure
# * Paging support
# * File locking
# Pre 1998 (?)
#
# The current maintainer of this script is Tim Gage or Steve Padgett
# (when he returns), Please send any bugs, wish lists, etc, to
# checkout@cisco.com so that the appropriate person can help you.
#
$VERSION="VER 3.18";
@wdate=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
@day=('U','M','T','W','R','F','S');
&Handle_Path;
&Get_Input;
if ($ARGV[0] eq "pager") {
chdir("$mydir");
&do_find_pageable;
exit(0);
}
%USER=&read_info_file("$save/$ENV{'REMOTE_ADDR'}.hist");
if (defined $FORM{'doredir'}) {
&print_redirect($FORM{'redirto'});
}
if (defined $FORM{'available'}) {
$USER{'available'}=$FORM{'available'};
&write_info_file("$save/$ENV{'REMOTE_ADDR'}.hist",%USER);
}
if ($FORM{'lab'} eq "pager") {
&paging_service($FORM{'user'});
exit(0);
}
#short-circuit the validation process
if (($labvalid=&valid_lab($FORM{'lab'})) && ($groupvalid=&valid_group($FORM{'lab'},$FORM{'group'})))
{ $zonevalid=&valid_zone($FORM{'lab'},$FORM{'group'},$FORM{'zone'}); }
if ((!defined $labvalid) || (!$labvalid)) { undef $labvalid; undef $FORM{'lab'}; }
if ((!defined $groupvalid) || (!$groupvalid)) { undef $groupvalid; undef $FORM{'group'}; }
if ((!defined $zonevalid) || (!$zonevalid)) { undef $zonevalid; undef $FORM{'zone'}; }
#
# handle stats processing
#
if (defined $FORM{'stats'}) {
&show_stats($FORM{'lab'},$FORM{'group'},$FORM{'zone'});
exit(0);
}
#
# handle searches
#
if (($FORM{'stext'} ne "")) {
$msg="";
$|=1; #do this, makes it (look) faster on searches
$msg=&save_checkout if (defined $FORM{'checkout'});
&do_search($msg);
exit(0);
}
#
# handle the pop-up boxes
#
if (defined $FORM{'short'}) {
&print_short;
exit(0);
}
#
#handle checkouts/in, edits, purges, and creates
#
$editmode=1 if (defined $FORM{'editz'});
&save_data if (defined $FORM{'save'});
&purge_zones if (defined $FORM{'purge'});
&create_itm if (defined $FORM{'create'});
#
#Is it a valid lab?
#
if (($FORM{'lab'} eq "") || (!defined $labvalid)) {
&read_and_show_labs;
exit(0);
}
# $labvalid=1;
#
#Is it a valid group?
#
if (($FORM{'group'} eq "") || (!defined $groupvalid)) {
&read_and_show_groups($FORM{'lab'});
exit(0);
}
# $groupvalid=1;
#
#handle new zone creation (new commserver)
#
&create_new_zone("$based/$FORM{'lab'}/$FORM{'group'}") if (defined $FORM{'newzone'});
#
# Is it a valid zone?
#
if (($FORM{'zone'} ne "") && (defined $zonevalid)) {
# $zonevalid=1;
$msg="";
$msg=&save_checkout if (defined $FORM{'checkout'});
#
# Is it a valid machine?
#
if (($FORM{'machine'} ne "") && (&valid_machine($FORM{'lab'},$FORM{'group'},$FORM{'zone'},$FORM{'machine'}))) {
$machinevalid=1;
&show_machine($FORM{'lab'},$FORM{'group'},$FORM{'zone'},$FORM{'machine'});
exit(0);
}
$editmode=2 if (defined $FORM{'editz'});
%zones=&read_zone_file($FORM{'lab'},$FORM{'group'},$FORM{'zone'});
&show_zones($FORM{'lab'},$FORM{'group'},$msg,%zones);
exit(0);
}
#
#otherwise, we're here...
#
# if (($FORM{'zone'} eq "")) {
$msg="";
$msg=&save_checkout if (defined $FORM{'checkout'});
%zones=&read_zones("$FORM{'lab'}","$FORM{'group'}");
&show_zones($FORM{'lab'},$FORM{'group'},$msg,%zones);
exit(0);
# }
print "Content-type: text/plain\n\n";
&print_env;
#
#is the lab name valid?
#
sub valid_lab {
my($lab)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($lab));
return 0 if (! -d "$based/$lab");
return 1;
}
#
#just test to see if the name characters are valid.
#
sub valid_name {
my($lab)=@_;
return 0 if ((!defined $lab) || ($lab =~ /[^A-Za-z0-9 \-\_\+\=\.]/) || ($lab =~ /^\./) || ($lab eq ""));
return 1;
}
#
#is the group name valid?
#
sub valid_group {
my($lab,$group)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($group));
return 0 if (! -d "$based/$lab/$group");
return 1;
}
#
#is the zone name valid?
#
sub valid_zone {
my($lab,$group,$zone)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($zone));
return 0 if (! -d "$based/$lab/$group/$zone");
return 1;
}
#
#is the machine name valid?
#
sub valid_machine {
my($lab,$group,$zone,$machine)=@_;
#not valid if any character OTHER THAN A-Z,a-z,0-9,-,_,.,=,+
return 0 if (!&valid_name($machine));
return 0 if (! -e "$based/$lab/$group/$zone/$machine.eq");
return 1;
}
#
#log message to file
#
sub log_msg {
my($path,$message)=@_;
my($nowtime);
$nowtime=localtime();
open(DATA,">>$path");
print DATA "$nowtime($ENV{'REMOTE_ADDR'}-".time()."): $message\n";
close(DATA);
}
#
#write out the file supplied to it as a name=value pair
#
sub write_info_file {
my($infofile,%INFO)=@_;
my($line,$itm);
$line="";
#put it into a buffer
foreach $itm (sort keys %INFO) {
$line.="$itm=$INFO{$itm}\n"
}
#write it out
system("/usr/bin/lockfile $infofile.lock");
open(DATA,">$infofile");
print DATA $line;
close(DATA);
unlink("$infofile.lock");
}
#
#read out the info file passed into it, and return it as hashes
#
sub read_info_file {
my(@if)=@_;
my($infofile,%INFO);
foreach $infofile (@if) {
# print "opening file $infofile\n" if ($infofile =~ /info$/);
if (open(DATA,"$infofile")) {
while () {
chomp;
next if ((/^#/) || (!/^(.*?)\=(.*)/));
$INFO{$1}=$2;
}
close(DATA);
}
}
return %INFO;
}
#
#read and return just one zone.
#
sub read_zone_file {
my($lab,$group,$file)=@_;
my(%INF);
%{$INF{$file}}=&read_info_file("$based/$lab/$group/$file/.info");
%{$INF{$file}{'equ'}}=&read_equipment("$based/$lab/$group/$file");
delete $INF{$file}{'equ'} if (defined $INF{$file}{'equ'}{'a!a'});
return %INF;
}
#
#read the zones file out of the directory
#
sub read_zones {
my($lab,$group)=@_;
my(%INF);
opendir(DIR,"$based/$lab/$group");
@files=readdir(DIR);
closedir(DIR);
undef %INF;
foreach $file (@files) {
next if (($file =~ /^\./) || (! -d "$based/$lab/$group/$file"));
%{$INF{$file}}=&read_info_file("$based/$lab/$group/$file/.info");
%{$INF{$file}{'equ'}}=&read_equipment("$based/$lab/$group/$file");
delete $INF{$file}{'equ'} if (defined $INF{$file}{'equ'}{'a!a'});
}
return %INF;
}
#
#read in the .eq files from the directory.
#
sub read_equipment {
my($dir)=@_;
my(@files,%INF,$file,$st,$found);
$found=0;
opendir(DIR,$dir);
@files=grep(/\.eq$/,readdir(DIR));
closedir(DIR);
foreach $file (@files) {
%{$INF{$file}}=&read_info_file("$dir/$file");
#process the searching stuff
$st="${1}[0-9][0-9]" if ($FORM{'stext'} =~ /(.*)00$/);
if (($FORM{'stext'} ne "")
&& ($INF{$file}{'name'} !~ /$FORM{'stext'}/i)
&& ($INF{$file}{'checkout-login'} !~ /$FORM{'stext'}/i)
&& ($INF{$file}{'type'} !~ /$FORM{'stext'}/i)
&& ((!defined $st) || ($INF{$file}{'type'} !~ /$st/i))
&& ($INF{$file}{'checkout-comment'} !~ /$FORM{'stext'}/i)) {
delete $INF{$file};
} elsif (($FORM{'stext'} ne "") && (defined $FORM{'short'}) && (uc($INF{$file}{'checkout-login'}) ne uc($FORM{'stext'}))) {
delete $INF{$file};
} else { $found++; }
#end search processing
}
return %INF if ($found > 0);
#return this special thing to notify the calling function that it didn't find anything
return ('a!a' => 1);
}
#
#convert a unix time to a date/time, significant figures determined by the units passed to it
#
sub str_time {
my($mtime,$units)=@_;
my(@d,$buf,$day);
$day=int($mtime/(60*60*24));
if ($day < 1) {
$buf=sprintf "%d:%02d hrs",($mtime/(60*60)),($mtime/60)%60;
} elsif ($day < 3000) {
$buf=sprintf "%d day%s %d:%02d hrs",$day,($day != 1)?"s":"",($mtime/(60*60))%24,($mtime/60)%60;
} else {
@d=localtime($mtime);
$buf=sprintf "%s %d-%d-%02d",$wdate[$d[6]],$d[4]+1,$d[3],$d[5]%100;
if ($units eq "hours") {
$buf.=sprintf " %d:00",$d[2]+1; #yes, weird, but this is how we perceive it... right?
} elsif ($units eq "minutes") {
$buf.=sprintf " %d:%02d",$d[2],$d[1];
}
}
return $buf;
}
#
#print out the ".banner" file in the directory
#
sub print_banner {
my($dir,$editm)=@_;
return if ((! -e "$dir/.banner") && (!defined $editm));
if ($editm==2) {
print "
HTML FORMATTED-BANNER, optional
\n" if ($editm==2);
}
#
#send out a HTTP redirect
#
sub print_redirect {
my($urlto)=@_;
my($port)="";
$port=":$ENV{'SERVER_PORT'}" if ($ENV{'SERVER_PORT'} ne 80);
if ($ENV{'REQUEST_URI'} eq $urlto) {
if ($urlto =~ /\?$/) { $urlto=substr($urlto,0,-1); } else { $urlto.="?"; }
}
print <
It's moved to here.
You would be taken there automatically without ever seeing this message, but your browser didn't like the redirect... hmm.
EOM
exit(0);
}
#
#a searchin' we shall go... a searchin' we shall go... hi ho 'la 'dar-i-o a searching we shall go.
#
sub print_search_bar {
my($lab,$group,$zone,$labt,$groupt,$zonet)=@_;
my(%SEL);
print <
|
|
}
#
#print out the checkout box to the screen
#
sub print_checkout_box {
my($gr,$max,$savegr,$mult,$i,$grinc,@d,$days);
$i=localtime();
print <
Depending on the individual group setup, checkout times may be truncated to the max-checkout-time.
Leave the Login field blank to check in
\n$i
EOM
}
#
#print out the history bar on the screen
#
sub print_history_bar {
my($ip)=@_;
my(%HISTI,@histi,$itm);
%HISTI=&read_info_file("$save/$ip.hist");
@hist=grep(/^HIST/,keys %HISTI);
return if ($#hist < 0); #don't display anything if the history dosen't exist
print <
| History: |
EOM
}
#
# Toggle paging for the user
#
sub paging_service {
my($user)=@_;
my(%USERS);
&print_header("Paging Services","Paging Services");
%USERS=&read_info_file("$save/nopage.users");
if (defined $FORM{'paging-off'}) {
$USERS{$FORM{'for'}}=1;
&write_info_file("$save/nopage.users",%USERS);
} elsif (defined $FORM{'paging-on'}) {
delete $USERS{$FORM{'for'}};
&write_info_file("$save/nopage.users",%USERS);
}
print <
| Paging Service for username: |
|---|
EOM
if ($user ne "") {
if ($USERS{$user} ne "") {
print <
| Paging service is currently: OFF |
|---|
EOM
} else {
print <
| Paging service is currently: ON |
|---|
EOM
}
}
print "
&print_trailer;
}
#
#actually print out the equipment...
#this is pretty much the guts of the display
#
sub print_equipment_list {
my($lab,$group,%ZONES)=@_;
my($zone,%ZM,$equ,$tel,$nexttime,@nowtime,$nowtime,$citime,$cotime,$newitm,$itmon,$mx,$pr);
#global GROUP INFORMATION variable
%{$GI{$group}}=&read_info_file("$based/.info","$based/$lab/.info","$based/$lab/$group/.info") if (!defined $GI{$group});
$pr=0;
#compute the time-at-the-next-increment-unit ;)
@nowtime=localtime();
$nowtime=time();
if ($GI{$group}{'checkout-increment-units'} eq "minutes") {
$mx=60;
$nexttime=$nowtime-$nowtime[0]; #+59
} elsif ($GI{$group}{'checkout-increment-units'} eq "hours") {
$nexttime=$nowtime -($nowtime[0]) - ($nowtime[1])*60; #+59+59*60
$mx=60*60;
} else {
# } elsif ($GI{$group}{'checkout-increment-units'} eq "days") {
#default of days
$nexttime=$nowtime-$nowtime[0]-($nowtime[1]+($nowtime[2])*60)*60; #+59+59*60+23*60*60
$mx=60*60*24;
}
$mx*=$GI{$group}{'max-checkout-time'}; #we want the max checkout time in mx
foreach $zone (sort {uc($ZONES{$a}{'name'}) cmp uc($ZONES{$b}{'name'})} keys %ZONES) {
#skip it if there's nothing to print & we're not in editmode
next if ((!defined $ZONES{$zone}{'equ'}) && (!defined $editmode) && (($FORM{'zone'} ne $zone) || ($FORM{'stext'} ne "")));
if (!defined $ZONES{$zone}{'equ'}) {
$ZONES{$zone}{'empty'}=1;
}
if ($ZONES{$zone}{'ip'}) {
$tel="telnet://$ZONES{$zone}{'ip'}"; #can telnet
$name="$ZONES{$zone}{'name'}";
} else {
$name="$ZONES{$zone}{'name'}";
$tel=""; #no telnet
}
$pr++;
#$aa=localtime($nexttime);
#print "$aa $nexttime";
if ($editmode==2) {
print <
|
Name: IP: EOM } else { #not edit mode print <
\n"; } #return the number of zones we saw & displayed return $pr; } #ok, that's a long function. # #The function to print out a piece of equipment in "standard" format # sub print_table_column_standard { my($lab,$group,$zone,$equ,$tel,$ciu,$mx,$nexttime,%ZO)=@_; next if (($USER{'available'} != 0) && (($ZO{'static'} eq "yes") || (($ZO{'checkout-login'} ne "") && ($ZO{'checkout-to'} > $nexttime)))); print " | ||||||||||||||||||||||||||||||||||
| "; | \n"; | $ZO{'name'} | \n";$ZO{'name'} | \n";$ZO{'name'} | \n";$ZO{'type'} | \n";$ZO{'checkout-login'} | $cotime | $citime | $ZO{'checkout-comment'} | $based/$lab/$group/$zone/$equ | \n";"; | %s | \n",$ZO{'static-text'}||"Static";Zoom | |||||||||||||||||||||
| $ZO{'name'} | \n";$ZO{'name'} | \n";$ZO{'type'} | $ZO{'port'} | \n";$citime | $ZO{'checkout-comment'} | $based/$lab/$group/$zone/$equ | \n";"; | %s | \n",$ZO{'static-text'}||"Static";Zoom | |||||||||||||||||||||||||
| Y: ",$lab,$group,$zone,$equ,($ZO{'static'} ne "yes")?"":"CHECKED";
printf "N: | ",$lab,$group,$zone,$equ,($ZO{'static'} eq "yes")?"":"CHECKED";
||||||||||||||||||||||||||||||||||
| Name: | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Refresh Time: | seconds | ||||||||||||||||||||||||||||||||||||||||||||
| Contact Name & Email: | Name: Email: | ||||||||||||||||||||||||||||||||||||||||||||
| Page Hidden: |
NO YES Making the page hidden will remove it from all lists and searches. | ||||||||||||||||||||||||||||||||||||||||||||
| Checkout Time: |
In Multiples of , up to total. Every 2 hours, up to 48 would mean that you could check out the equipment up until 2 days, in multiples of 2 hour blocks. | ||||||||||||||||||||||||||||||||||||||||||||
| Check-In Notification: |
Send pages at (HHMM) for equipment that expires within the next hours. Example: Page at 1400 for equipment that expires within 10 hours would page at 2PM for equipment that expires up until midnight. | ||||||||||||||||||||||||||||||||||||||||||||
| Paging/Email |
| ||||||||||||||||||||||||||||||||||||||||||||
EOM
}
#
#print out what we just did...
#
sub print_did_box {
my($msg)=@_;
if ($msg ne "") {
print <
| Actions Performed
EOM if ($FORM{'checkout-user'} ne "") { print < |
|---|
| $msg |
EOM
}
}
#
#print out the zone(s) on the screen.
#
sub show_zones {
my($lab,$group,$msg,%ZONES)=@_;
my($zone,%GRP,%SEL,%RST,$owner);
%RST=&read_info_file("$based/.info","$based/$lab/.info");
%GRP=&read_info_file("$based/$lab/$group/.info");
$GRP{'name'}=$GRP{'name'}||"$group";
foreach $zone (keys %RST) {
$GRP{$zone}=$RST{$zone} if (!defined $GRP{$zone});
}
if ((defined $FORM{'commgen'}) && (defined $zonevalid)) {
&generate_commserver_text("$lab","$group","$FORM{'zone'}");
exit(0);
}
&print_header("Zone Selection -- $GRP{'name'}","Zone Selection for $GRP{'name'}");
if ((defined $editmode) && (!defined $zonevalid)) {
&show_editor_head("$lab/$group",%GRP);
}
&print_banner("$based/$lab/$group",($editmode==1)?2:0);
if ((defined $editmode) && (!defined $zonevalid)) {
print <
|
|
EOM
foreach $zone (keys %ZONES) {
# print "\n-$ZONES{$zone}{'equ'}-\n";
next if ((defined $ZONES{$zone}{'equ'}));
# && (%{$ZONES{$zone}{'equ'}} > 0));
print "\n";
}
}
&print_did_box($msg);
&print_equipment_list($lab,$group,%ZONES);
if ((!defined $editmode) && (!defined $FORM{'short'})) {
&print_checkout_box;
$owner="This equipment maintained by $GRP{'contact-name'}
" if ($GRP{'contact-name'} ne "");
print <
|
$owner Edit Mode Pop-Up Window |
Toggle My Paging Checkout Stats EOM print " Generate Commserver/Mail Information\n" if ((defined $zonevalid) && ($ZONES{$FORM{'zone'}}{'ip'} =~ /\./)); print " |
}
&print_trailer;
}
#
#print out the zone(s) on the screen.
#
sub show_machine {
my($lab,$group,$zone,$machine)=@_;
my(%INFO,@lines,$i,$lines,$status,%GRP,@nowtime,$nowtime,$nexttime,$mx,%LOC,$location,$notes,$confstr);
%INFO=&read_info_file("$based/$lab/$group/$zone/$machine.eq");
%GRP=&read_info_file("$based/.info","$based/$lab/.info","$based/$lab/$group/.info");
%LOC=&read_info_file("$based/$lab/$group/$zone/.info");
$INFO{'name'}=$INFO{'name'}||"$machine";
if (defined $FORM{'savenotes'}) {
&log_msg("$based/$lab/$group/$zone/$machine.eq.log","Notes Updated");
open(DATA,">$based/$lab/$group/$zone/$machine.eq.notes");
print DATA "$FORM{'notes'}";
close(DATA);
&print_redirect("$ENV{'SCRIPT_NAME'}/$lab/$group/$zone/$machine");
exit(0);
}
&print_header("Equipment View -- $INFO{'name'}","Equipment View");
if (open(DATA,"$based/$lab/$group/$zone/$machine.eq.notes")) {
while () { $notes.=$_; }
close(DATA);
}
if (open(DATA,"$based/$lab/$group/$zone/$machine.eq.log")) {
while () { push @lines,$_; }
close(DATA);
}
for ($i=$#lines;(($i >= 0) && (($i >= $#lines - 19) || (defined $FORM{'logall'})));$i--) {
$lines=sprintf "%d. %s%s",$i+1,$lines[$i],$lines;
}
chomp $lines;
if ($INFO{'static'} ne "yes") {
$status="Not currently checked out";
#### compute nexttime
@nowtime=localtime();
$nowtime=time();
if ($GRP{'checkout-increment-units'} eq "minutes") {
$nexttime=$nowtime-$nowtime[0]; #+59
$mx=60;
} elsif ($GRP{'checkout-increment-units'} eq "hours") {
$nexttime=$nowtime -($nowtime[0]) - ($nowtime[1])*60; #+59+59*60
$mx=60*60;
} else {
#default of days
$nexttime=$nowtime-$nowtime[0]-($nowtime[1]+($nowtime[2])*60)*60; #+59+59*60+23*60*60
$mx=60*60*24;
}
###########
$mx*=$GRP{'max-checkout-time'}; #we want the max checkout time in mx
if (($INFO{'checkout-login'} ne "") && ($INFO{'checkout-to'} > $nexttime)) {
$status=sprintf "Checked out from %s to %s by %s for \"%s\"",
&str_time($INFO{'checkout-from'},$GRP{'checkout-increment-units'}),&str_time($INFO{'checkout-to'},$GRP{'checkout-increment-units'}),$INFO{'checkout-login'},$INFO{'checkout-comment'};
}
} else {
$status="Static: $INFO{'static-text'}";
}
$location=sprintf "%s in %s", $LOC{'name'}||$zone,$GRP{'name'}||$group;
if (($LOC{'ip'} ne "") && ($INFO{'port'} ne "")) {
$location=sprintf "%s (%s) on port %s in %s -- Connect",$LOC{'name'}||$zone,$LOC{'ip'},$INFO{'port'},$GRP{'name'}||$group,$LOC{'ip'},$INFO{'port'};
$confstr=sprintf "Configuration (IOS only):
[Reconfigure]
[View Running Config]",
&webify($INFO{'name'}),&webify($INFO{'port'}),&webify($LOC{'ip'}),
&webify($INFO{'name'}),&webify($INFO{'port'}),&webify($LOC{'ip'});
}
print <
| Equipment Name: | $INFO{'name'} | Type: | $INFO{'type'} |
|---|---|---|---|
| Location: | $location | ||
| Status: | $status | ||
EOM
if (!defined $FORM{'updnotes'}) {
print <
| Machine Notes (Update) |
|---|
| $notes |
EOM
} else {
print <
| Machine Notes |
|---|
EOM
}
print <
| Log File
EOM if (defined $FORM{'logall'}) { print "(everything)"; } else { print "(most recent 20 events) [show all]"; } print < |
$lines |
EOM
$GI{$group}={%GRP};
&print_checkout_box if ($INFO{'static'} ne "yes");
&print_trailer;
}
#
#save the history to the file -- rotating out old entries and bumping up new ones...
#
sub save_history {
my($ip,$path,$lab,$group,$zone,$mach)=@_;
my(%HISTI,@save,$itm,$max);
$max=4;
$lab="$1..." if ((length($lab) > 8) && ($lab =~ /^(.....)/));
$group="$1..." if ((length($group) > 9) && ($group =~ /^(......)/));
%HISTI=&read_info_file("$save/$ip.hist");
$HISTI{'accesses'}++;
$path=$1 if ($path =~ /^(.*)\/$/);
push @savep,$path;
push @save,sprintf "%s:%s%s%s",$lab,$group,($zone ne "")?":$zone":"",(($zone ne "") && ($mach ne ""))?":$mach":"";
foreach $itm (sort grep(/^HIST/,keys %HISTI)) {
if ($path ne $HISTI{"P$itm"}) {
push @save,$HISTI{$itm};
push @savep,$HISTI{"P$itm"};
last if ($max-- == 0);
}
}
#now delete the entries out of HISTI
foreach $itm (sort grep(/^HIST/,keys %HISTI)) {
delete $HISTI{$itm};
delete $HISTI{"P$itm"};
}
#and save the new ones
$max=0;
foreach $itm (@save) {
$HISTI{"HIST$max"}=$itm;
$HISTI{"PHIST$max"}=$savep[$max];
$max++;
}
&write_info_file("$save/$ip.hist",%HISTI);
}
#
# Read in groups from the directory
#
sub read_groups {
my($labdir,$all)=@_;
my($group,%GROUPS,%INFO);
foreach $group (&read_dir("$labdir")) {
%INFO=&read_info_file("$labdir/$group/.info");
if ((($INFO{'hidden'} eq "") || (defined $all)) || (defined $FORM{'short'})) {
$GROUPS{$group}=$INFO{'name'}||$group;
}
}
return %GROUPS;
}
#
#read in the labs from the directory
#
sub read_labs {
my($labdir,$all)=@_;
#
#does the same thing, why rewrite it now?
#
return &read_groups($labdir,$all);
}
#
#read in the name of the groups from the lab and show them.
#
sub read_and_show_groups {
my($lab)=@_;
my($group,%GROUPS,$zone,@files,%INFO,$col,%INF,$inf,$cnt);
$col=0;
%INFO=&read_info_file("$based/$lab/.info");
$INFO{'name'}=$INFO{'name'}||$lab;
&print_header("Group Selection -- $INFO{'name'}","Group Selection");
if (defined $editmode) {
&show_editor_head("$lab/$group",%INFO);
print <
| New Group Name: | |
|---|---|
EOM
}
&print_banner("$based/$lab",(defined $editmode)?2:0);
#
#get a listing of all the groups
#
%GROUPS=&read_groups("$based/$lab");
undef %INFO;
print "
\n
# print " | ||||||||||||
if (!defined $editmode) {
print "Edit Mode\n";
}
&print_trailer;
}
#
#Print out the "short" screen -- nothing but the top, search box, and trailer
#
sub print_short {
&print_header("Personal Screen","Enter your Username");
&print_trailer;
}
#
#read the names of the valid labs and print the on the screen!
#
sub read_and_show_labs {
my(%LABS,$lab,$printblank,%GROUPS,$col,%INFO,$cnt);
$col=0;
#get a listing of all the labs
%LABS=&read_labs("$based");
&print_header("Lab Selection","Lab Selection");
if (defined $editmode) {
print <
| New Lab Name: | |
|---|---|
EOM
}
&print_banner("$based",(defined $editmode)?2:0);
print "
\n
| ||||||||
if (!defined $editmode) {
print "Edit Mode\n";
}
&print_trailer;
}
#
#the trailer
#
sub print_trailer {
my(@d);
#get the last modify time, yes this is y2k compliant
@d=stat($ENV{'SCRIPT_FILENAME'});
@d=localtime($d[9]); $d[4]++; $d[5]+=1900;
#print it out
print <

Last modified on $d[4]-$d[3]-$d[5] - $VERSION - Send complaints/requests to ADI-AUTOMATION-TEAM mailing-list
EOM
}
#
#the header.
#pretty straightfoward.
#
sub print_header {
my($title,$top)=@_;
my($nowtime,%INFO,$sb,$groupt,$labt,$zonet,$refresh,$machinet,$which);
$nowtime=localtime();
$title=" -- $title" if ($title ne "");
$sb="$ENV{'SCRIPT_NAME'}"||"/";
if (!defined $editmode) {
if ((defined $labvalid) && (defined $groupvalid)) {
%INFO=&read_info_file("$based/.info","$based/$FORM{'lab'}/.info","$based/$FORM{'lab'}/$FORM{'group'}/.info");
$refresh="Refresh: $INFO{'default-refresh-seconds'}" if ($INFO{'default-refresh-seconds'} > 0);
} else {
$refresh="Refresh: 600";
}
}
if (defined $FORM{'short'}) {
&print_short_header($title,$top);
} else {
print <
clearcase batch
################################
###For CleaCase checkin#########
################################
my $cmds = qq{ /ap/local/SunOS_sparc/bin/zsh -c '/usr/atria/bin/cleartool setview -exec "/usr/atria/bin/cleartool checkout -nc /vobs/esam/build/fulltests/COMMON/$tag$file" Tracker_Tool'};
my @arrs = `$cmds 2>&1`;
print LO "CO: @arrs\n";
my @content = `cat $file_name`;
open(SIH, ">/view/Tracker_Tool/vobs/esam/build/fulltests/COMMON/$tag$file");# or print LO "Cannot open the file $!";
print SIH "@content";print LO "CONTENT: @content\n";
close SIH;
my $cmds1 = qq{/ap/local/SunOS_sparc/bin/zsh -c '/usr/atria/bin/cleartool setview -exec "/usr/atria/bin/cleartool checkin -nc /vobs/esam/build/fulltests/COMMON/$tag$file" Tracker_Tool'};
my @arrs1 = `$cmds1 2>&1`;
if(grep/Unable to check in/, @arrs1){
my $unco = qq{/ap/local/SunOS_sparc/bin/zsh -c '/usr/atria/bin/cleartool setview -exec "/usr/atria/bin/cleartool uncheckout -rm /vobs/esam/build/fulltests/COMMON/$tag$file" Tracker_Tool'};
my @arrs2 = `$unco 2>&1`;
# print "ARRS2: @arrs2\n";
}
print LO @arrs1;
}
}
open(TH, ">Fstats");#print LO "Updating File stats\n";
print TH "@upd_content";
close TH;
close LO;
###For CleaCase checkin#########
##############################
my $cmds = qq{ /ap/local/SunOS_sparc/bin/zsh -c '/usr/atria/bin/cleartool setview -exec "/usr/atria/bin/cleartool checkout -nc /vobs/esam/build/fulltests/
my @arrs = `$cmds 2>&1`;
print LO "CO: @arrs\n";
my @content = `cat $file_name`;
open(SIH, ">/view/Tracker_Tool/vobs/
print SIH "@content";print LO "CONTENT: @content\n";
close SIH;
my $cmds1 = qq{/ap/local/SunOS_sparc/bin/
my @arrs1 = `$cmds1 2>&1`;
if(grep/Unable to check in/, @arrs1){
my $unco = qq{/ap/local/SunOS_sparc/bin/
my @arrs2 = `$unco 2>&1`;
# print "ARRS2: @arrs2\n";
}
print LO @arrs1;
}
}
open(TH, ">Fstats");#print LO "Updating File stats\n";
print TH "@upd_content";
close TH;
close LO;
Subscribe to:
Comments (Atom)