-
Notifications
You must be signed in to change notification settings - Fork 1
/
WritePLookupDirectory.pm
134 lines (105 loc) · 3.81 KB
/
WritePLookupDirectory.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package WritePLookupDirectory;
use strict;
use Log::Log4perl qw(get_logger);
use File::Copy;
sub HtmlFileHeader ($) {
my $title = shift;
my $RetVal = <<HEAD;
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="-100">
<title>$title</title>
<link href="../SwitchMap.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="page-title">$title</div>
<hr>
HEAD
return $RetVal;
}
sub WriteIpAddressesIndexFile() {
my $logger = get_logger('log4');
$logger->debug("called");
SwitchUtils::SetupDirectory $Constants::PLookupIpAddressesDirectory; # create or empty out the directory
my $IndexFileName = File::Spec->catfile($Constants::PLookupIpAddressesDirectory, 'index.html');
$logger->info("writing $IndexFileName");
open INDEXFILE, ">$IndexFileName" or do {
$logger->fatal("Couldn't open $IndexFileName for writing, $!");
exit;
};
print INDEXFILE HtmlFileHeader 'IP Addresses in Port Lists';
print "";
print INDEXFILE SwitchUtils::HtmlTrailer;
close INDEXFILE;
SwitchUtils::AllowAllToReadFile $IndexFileName;
$logger->debug("returning");
}
sub WriteIpAddressesFiles($) {
my $SwitchesRef = shift;
my $logger = get_logger('log4');
$logger->debug("called");
my $IpAddressFileName = File::Spec->catfile($Constants::PLookupIpAddressesDirectory, 'ip-addresses.html');
$logger->info("writing $IpAddressFileName");
open IPADDRESSFILE, ">$IpAddressFileName" or do {
$logger->fatal("Couldn't open $IpAddressFileName for writing, $!");
exit;
};
print IPADDRESSFILE HtmlFileHeader 'IP Addresses in Port Lists';
print IPADDRESSFILE "<table>\n";
my $MacIpAddrRef = MacIpTables::getMacIpAddr();
my $MacHostNameRef = MacIpTables::getMacHostName();
foreach my $Switch (@$SwitchesRef) {
my $SwitchName = GetName $Switch;
next if $SwitchName =~ /^---/; # skip it if it's a group name
$logger->debug("\$SwitchName = $SwitchName");
foreach my $PortName (Portically::PortSort keys %{$Switch->{Ports}}) {
$logger->debug("\$PortName = \"$PortName\"");
my $Port = $Switch->{Ports}{$PortName};
if (keys %{$Port->{Mac}} != 0) {
my $HtmlRow = SwitchUtils::MakeHtmlRow($Switch,
$Port,
$MacIpAddrRef,
$MacHostNameRef,
0);
print IPADDRESSFILE $HtmlRow;
}
}
}
print IPADDRESSFILE "</table>\n";
print IPADDRESSFILE SwitchUtils::HtmlTrailer;
close IPADDRESSFILE;
SwitchUtils::AllowAllToReadFile $IpAddressFileName;
$logger->debug("returning");
}
sub WriteIpAddressesDirectory($) {
my $SwitchesRef = shift;
my $logger = get_logger('log3');
$logger->debug("called");
WriteIpAddressesIndexFile();
WriteIpAddressesFiles($SwitchesRef);
$logger->debug("returning");
}
sub WriteSwitchMapCssFile() {
my $SrcCssFileName = File::Spec->catfile($ThisSite::DestinationDirectory, $Constants::CssFile);
my $DstCssFileName = File::Spec->catfile($Constants::PLookupDirectory, $Constants::CssFile);
copy($SrcCssFileName, $DstCssFileName);
}
sub WritePLookupDirectory ($) {
my $SwitchesRef = shift;
my $logger = get_logger('log2');
$logger->debug("called");
SwitchUtils::SetupDirectory $Constants::PLookupDirectory; # create or empty out the directory
# WriteCiscoSerialNumbersDirectory($SwitchesRef);
WriteSwitchMapCssFile;
WriteIpAddressesDirectory($SwitchesRef);
# WriteLocationLabelsDirectory($SwitchesRef);
# WriteMacAddressesDirectory($SwitchesRef);
# WriteStringsDirectory($SwitchesRef);
# WriteVlansDirectory($SwitchesRef);
$logger->debug("returning");
}
1;