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 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/perl -w -T
use strict;
use CGI qw(:standard);
#set this for testing purposes only
#use CGI::Carp qw(fatalsToBrowser);
use File::Temp;
#some security-settings
$CGI::POST_MAX = 1024 * 100;
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
#gather all mibs in smipath into @mibnames
my $smipath = "@smipath@";
my @smidirs = split(/:/,$smipath);
my @mibnames;
foreach my $dir (@smidirs) {
opendir(MIBDIR,$dir);
my @entries = grep !/^\.\.?\z/, readdir(MIBDIR);
closedir(MIBDIR);
@mibnames = (@mibnames, @entries);
}
if (param()) {
#params present.
my @options;
my $localfh;
my $localfn;
my @mibs = param('mibs');
my $width = param('width');
my $height = param('height');
#parse options and add safe strings to the options-array
if (param('deprobs')) {
if (param('deprobs') eq "deprecated") {
@options = (@options, "--svg-show-deprecated");
} elsif (param('deprobs') eq "obsolete") {
@options = (@options, "--svg-show-depr-obsolete");
}
}
if (param('static')) {
@options = (@options, "--svg-static-output");
}
if ($width =~ /(\d+)/) {
if ($1 <= 2147483647) {
@options = (@options, "--svg-width=$1");
}
}
if ($height =~ /(\d+)/) {
if ($1 <= 2147483647) {
@options = (@options, "--svg-height=$1");
}
}
#parse selected MIBs
foreach my $mibname (@mibnames) {
foreach my $mib (@mibs) {
if ($mibname eq $mib) {
$mibname =~ /([\w\-]+)/;
@options = (@options, "$1");
}
}
}
#handle file upload
if (param('uploadmib')) {
my $remotefh = upload('uploadmib');
($localfh, $localfn)
= File::Temp->tempfile('tempMIBXXXX', DIR => '/tmp', UNLINK => 1)
or die "Error opening outfile\n";
while (<$remotefh>) {
print $localfh $_;
}
close $remotefh;
close $localfh;
@options = (@options, $localfn);
}
#call smidump
my $res = open (SMIDUMP, "-|");
die "Couldn't open pipe to subprocess" unless defined($res);
exec "@prefix@/bin/smidump",'-u','-f','svg',@options
or die "Couldn't exec smidump" if $res == 0;
my @svg = <SMIDUMP>;
close (SMIDUMP);
#serve svg
my $svglength = @svg;
if ($svglength eq 0) {
print header;
print start_html("MIB to SVG");
print h2("Sorry, smidump output contained no data.");
print end_html;
} else {
#FIXME - or + ?
print header(-TYPE => "image/svg-xml");
print "@svg";
}
} else {
#no params present
#send form
print header;
print start_html("MIB to SVG");
print h2("Generate a SVG Diagram from MIB Modules");
print start_multipart_form();
print p("select one or more MIBs: ", scrolling_list(
-NAME => "mibs",
-VALUES => [@mibnames],
-SIZE => 10,
-MULTIPLE => 1,
));
print p("or upload a MIB: ", filefield(
-NAME => "uploadmib"
));
print p("diagram width: ", textfield(
-NAME => "width",
-DEFAULT => "1100"
));
print p("diagram height: ", textfield(
-NAME => "height",
-DEFAULT => "700"
));
print p(radio_group(
-NAME => "deprobs",
-VALUES => [ qw(none deprecated obsolete) ],
-LINEBREAK => 1,
-LABELS => {
none => "show only current objects",
deprecated => "show current and deprecated objects",
obsolete => "show all objects",
},
));
print p(checkbox(
-NAME => "static",
-LABEL => "generate a smaller, non-interactive SVG diagram",
));
print p(submit("generate SVG"), reset("reset form"));
print end_form;
print end_html;
}
|