[2592] | 1 | #! /usr/bin/perl
|
---|
| 2 | #
|
---|
| 3 | #
|
---|
| 4 | #
|
---|
| 5 |
|
---|
[4047] | 6 | $home="/home/genesis/";
|
---|
[2592] | 7 | $ndir="$home/nodes";
|
---|
| 8 | $html=1;
|
---|
[4047] | 9 | $baseref='http://rambo.wleiden.net';
|
---|
| 10 | $base_href="baseref/cgi-bin";
|
---|
| 11 | $source="$base_href/g_list.pl";
|
---|
[2592] | 12 | $svn='/usr/local/bin/svn';
|
---|
[4047] | 13 | $toolfile="wleiden.pl";
|
---|
[2592] | 14 |
|
---|
| 15 | $functions_only=1;do $toolfile || die;
|
---|
| 16 |
|
---|
| 17 | $request=$ENV{'REQUEST_URI'};
|
---|
| 18 |
|
---|
| 19 | if ($request=~/cgi-bin\/g_list.pl\/(.*)$/)
|
---|
| 20 | {
|
---|
| 21 | ($hostname,$file)=split(/\//,$1);
|
---|
| 22 | $title="$hostname $file";
|
---|
| 23 | }
|
---|
| 24 | else {$title="listing";}
|
---|
| 25 |
|
---|
| 26 | $browser=$ENV{'HTTP_USER_AGENT'};
|
---|
| 27 | if ($browser=~/curl|wget|fetch/i)
|
---|
| 28 | {$HTML=0;
|
---|
| 29 | print "Content-type: text/html\n\n";
|
---|
| 30 | # print "Doing: [$hostname][$file]\n";
|
---|
| 31 | }
|
---|
| 32 | else
|
---|
| 33 | {$HTML=1;
|
---|
| 34 | print <<EOH;
|
---|
| 35 | Content-type: text/html\n
|
---|
| 36 |
|
---|
| 37 | <HTML>
|
---|
| 38 | <TITLE>Genesis $title</TITLE>
|
---|
| 39 | <BODY BGcolor=white>
|
---|
[4047] | 40 | <BASE HREF=$base_href>
|
---|
[2592] | 41 | EOH
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | #foreach $key (keys %ENV) {print "$key=$ENV{$key}<BR>\n";}
|
---|
| 47 |
|
---|
| 48 | if ($hostname eq '')
|
---|
| 49 | {
|
---|
| 50 | if ($ENV{"QUERY_STRING"}=~/update/i)
|
---|
| 51 | {
|
---|
| 52 | select(STDERR); $| = 1; # make unbuffered
|
---|
| 53 | select(STDOUT); $| = 1; # make unbuffered
|
---|
| 54 |
|
---|
| 55 | print "<H2>Please wait while updating svn...</H2><P><PRE>\n";
|
---|
[4047] | 56 | system("$svn update $ndir");
|
---|
[2592] | 57 | close(SVN);
|
---|
| 58 | print <<EOZ;
|
---|
| 59 | </PRE>
|
---|
| 60 | <H2>Done.<H2><P>
|
---|
[4047] | 61 | Click <A HREF=$source>here</A> if you're not forwarded automaticly in 5
|
---|
[2592] | 62 | seconds.<P>
|
---|
[4047] | 63 | <META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>\n
|
---|
[2592] | 64 | EOZ
|
---|
| 65 |
|
---|
| 66 | }
|
---|
| 67 | else
|
---|
| 68 | {g_list();}
|
---|
| 69 | }
|
---|
| 70 | else
|
---|
| 71 | {
|
---|
| 72 | $dir="$ndir/$hostname";
|
---|
| 73 | if (! -d $dir )
|
---|
| 74 | {
|
---|
| 75 | if ($HTML) {print "<H1>Host $hostname not found: $dir</H1><P>\n";}
|
---|
| 76 | else {print "Host $hostname not found: $dir\n";}
|
---|
| 77 | } elsif ($file eq '')
|
---|
| 78 | {
|
---|
| 79 | foreach $file ('txtconfig','config','dhcpd.conf','zebra.conf','ospfd.conf',
|
---|
| 80 | 'rc.local','rc.node.local','resolv.conf',
|
---|
| 81 | 'named.conf','snmpd.local.conf')
|
---|
| 82 | {
|
---|
| 83 | if ($HTML) {print "$file<BR>\n";}
|
---|
| 84 | else {print "$file\n";}
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | elsif ($file eq 'config') {g_print($hostname);}
|
---|
| 88 | elsif ($file eq 'txtconfig') {$HTML=0;g_print($hostname);}
|
---|
| 89 | elsif ($file=~/(dhcpd.conf|mrtg.cfg|zebra.conf|ospfd.conf|sh|linux.sh|rc.node.local|rc.local|resolv.conf|named.conf|snmpd.local.conf)/)
|
---|
| 90 | {g_generate($file,$hostname);}
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | if ($HTML)
|
---|
| 94 | {
|
---|
| 95 | print <<EOF;
|
---|
| 96 | </BODY>
|
---|
| 97 | </HTML>
|
---|
| 98 | EOF
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | sub g_list
|
---|
| 102 | {
|
---|
| 103 | if ($HTML)
|
---|
| 104 | {
|
---|
[4047] | 105 | $svn_version=svn_version("$ndir");
|
---|
[2592] | 106 | if ($svn_version=~/Last Changed Rev: (\d+)/) {$revision=$1;}
|
---|
| 107 |
|
---|
| 108 | print "<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>";
|
---|
| 109 | print $svn_version;
|
---|
[4047] | 110 | print <<EOX;
|
---|
| 111 | </PRE>
|
---|
| 112 | <FORM METHOD=get ACTION=g_list.pl>
|
---|
| 113 | <INPUT TYPE="submit" NAME="Update" VALUE="Update">
|
---|
| 114 | </FORM>
|
---|
| 115 | <TABLE BORDER=1>
|
---|
| 116 | EOX
|
---|
[2592] | 117 | }
|
---|
| 118 |
|
---|
| 119 | opendir(DIR, $ndir) || die "can't opendir $home: $!";
|
---|
| 120 | @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
|
---|
| 121 | closedir DIR;
|
---|
| 122 | foreach $dir (sort @dirs)
|
---|
| 123 | {
|
---|
| 124 | if ($dir=~/attic/) {next;}
|
---|
| 125 | $hostname=$dir;
|
---|
| 126 | if (! $HTML) {print "$hostname\n";}
|
---|
| 127 | else
|
---|
| 128 | {
|
---|
| 129 | print "<TR><TD><A HREF=g_list.pl/$hostname/config>$hostname</A></TD>\n";
|
---|
| 130 | foreach $file ('linux.sh','dhcpd.conf','zebra.conf','ospfd.conf',
|
---|
| 131 | 'rc.node.local','rc.local','resolv.conf','named.conf',
|
---|
| 132 | 'snmpd.local.conf')
|
---|
| 133 | {
|
---|
| 134 | print "<TD><A HREF=g_list.pl/$hostname/$file>$file</A></TD>\n\n";
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | if ($HTML) { #print "</TABLE><P>\n";}
|
---|
| 139 | print <<EOX;
|
---|
| 140 | </TABLE><P>
|
---|
| 141 | EOX
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | sub svn_version
|
---|
| 146 | {
|
---|
| 147 | local($file,$char)=@_;
|
---|
| 148 | local($svn_version);
|
---|
| 149 | $svn_version=`$svn info $file`;
|
---|
| 150 | if ($char ne '') {$svn_version=~s/^([^$char].*)/$char $1/mgi;}
|
---|
| 151 | return($svn_version);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | sub g_print
|
---|
| 156 | {
|
---|
| 157 | local($hostname)=@_;
|
---|
| 158 | $config="$ndir/$hostname/wleiden.conf";
|
---|
| 159 |
|
---|
| 160 | if (! $HTML)
|
---|
| 161 | {
|
---|
| 162 | print svn_version($config,'#');
|
---|
| 163 |
|
---|
| 164 | #print "Ahum\n";
|
---|
| 165 | open (CFG,$config) || die;
|
---|
| 166 | while (<CFG>) {print $_;}
|
---|
| 167 | close(CFG);
|
---|
| 168 | } else
|
---|
| 169 | {
|
---|
| 170 | print "<H1>Genesis configuratie voor: $hostname</H1><P>\n";
|
---|
| 171 | print "<PRE>" . svn_version($config) . "</PRE><P>\n";
|
---|
| 172 |
|
---|
| 173 | do($config) || die;
|
---|
| 174 | parse_config();
|
---|
| 175 |
|
---|
[4025] | 176 | $TP='';
|
---|
| 177 | if ($tproxy !~ m/no/i) {
|
---|
| 178 | $TP .= "\n";
|
---|
| 179 | $TP .= "Tproxy on cidr range $tproxy";
|
---|
| 180 | $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
|
---|
| 181 | unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
|
---|
| 182 | };
|
---|
[2592] | 183 |
|
---|
[4025] | 184 |
|
---|
| 185 |
|
---|
[2592] | 186 | print <<EOXY;
|
---|
| 187 | <TABLE BORDER=1><TR><TD COLSPAN=4><PRE>
|
---|
| 188 | master_ip=$master_ip
|
---|
| 189 | AGGREGATE=$AGGREGATE
|
---|
| 190 |
|
---|
| 191 | gw_open=$gw_open
|
---|
| 192 | nodetype=$nodetype
|
---|
| 193 | nodename=$nodename
|
---|
| 194 |
|
---|
| 195 | NS_forward=$NS_forward
|
---|
| 196 | NS_resolv=$NS_resolv
|
---|
| 197 |
|
---|
| 198 | location=$location
|
---|
| 199 | DISK=$DISK
|
---|
| 200 |
|
---|
| 201 | X=$X
|
---|
| 202 | Y=$Y
|
---|
| 203 |
|
---|
[4025] | 204 | OS=$OS
|
---|
[2592] | 205 |
|
---|
[4025] | 206 | $TP
|
---|
[2592] | 207 | </PRE></TD></TR>
|
---|
| 208 | EOXY
|
---|
| 209 |
|
---|
| 210 | foreach $if (sort keys %config)
|
---|
| 211 | {
|
---|
| 212 | if ($if=~/^(.*):\d+/) {$subs{$1}++;}
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | foreach $if (sort keys %config)
|
---|
| 216 | {
|
---|
| 217 | if ($if=~/^([^:]+)/) {$mymain=$1;} else {$mymain='';}
|
---|
| 218 | if ($if!~/:\d+/) {$main=1;$cc='66'} else {$main=0;$cc='cc';}
|
---|
| 219 | if (! ($ip=$IP{$if})) {$ip='dhcp?';}
|
---|
| 220 | if ($TYPE{$if}=~/wireless/) {$color="#${cc}FFFF";}
|
---|
| 221 | if ($TYPE{$if}=~/ethernet/) {$color="#FFFF${cc}";}
|
---|
| 222 |
|
---|
| 223 | $cfg=$config{$if};
|
---|
| 224 | $cfg=~s/(.*KEY.*=).*/${1}***********/;
|
---|
| 225 | $cfg=~s/(.*PWD.*=).*/${1}***********/;
|
---|
| 226 | $cfg=~s/(.*CODE.*=).*/${1}***********/;
|
---|
| 227 | $cfg=~s/(.*PASS.*=).*/${1}***********/;
|
---|
| 228 |
|
---|
| 229 | if ($main) {printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};$c=4}
|
---|
| 230 | else {$c=3;print "<TR bgcolor=$color>";}
|
---|
| 231 | $cfg=~s/</</gi;
|
---|
| 232 | $cfg=~s/>/>/gi;
|
---|
| 233 |
|
---|
| 234 | print <<EOP;
|
---|
| 235 | <TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>
|
---|
| 236 | <TR><TD COLSPAN=$c><PRE>
|
---|
| 237 | $cfg
|
---|
| 238 | </PRE></TD>
|
---|
| 239 | <TR><TD COLSPAN=$c> </TD>
|
---|
| 240 |
|
---|
| 241 | EOP
|
---|
| 242 | }
|
---|
| 243 | print "</TABLE>\n";
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | sub g_generate
|
---|
| 249 | {
|
---|
| 250 | ($file,$hostname)=@_;
|
---|
| 251 |
|
---|
| 252 | #print "[$file][$hostname]\n";
|
---|
| 253 | $config="$ndir/$hostname/wleiden.conf";
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 | if (! -r $config)
|
---|
| 257 | {
|
---|
| 258 | if ($HTML) {print "<H1>File $file not found: $config</H1><P>\n";}
|
---|
| 259 | else {print "File $file not found: $config\n";}
|
---|
| 260 |
|
---|
| 261 | } else
|
---|
| 262 | {
|
---|
| 263 | if ($file=~/(ospfd|zebra)/) {$char='!';} else {$char='#';}
|
---|
| 264 |
|
---|
| 265 | $svn_versiont=svn_version($toolfile,$char);
|
---|
| 266 | $svn_versionc=svn_version($config,$char);
|
---|
| 267 |
|
---|
| 268 | if ($svn_versiont=~/Last Changed Rev: (\d+)/) {$tool_rev=$1;}
|
---|
| 269 | if ($svn_versionc=~/Last Changed Rev: (\d+)/) {$config_rev=$1;}
|
---|
| 270 |
|
---|
| 271 | #print "[$tool_rev $config_rev]<BR>\n";
|
---|
| 272 | if ($tool_rev >= $config_rev)
|
---|
| 273 | {$svn_version=$svn_versiont . $svn_versionc;}
|
---|
| 274 | else {$svn_version=$svn_versionc;}
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 | if ($HTML) {print "<H1>Genesis $file voor: $hostname</H1><P>\n";}
|
---|
| 278 |
|
---|
| 279 | do($config) || die;
|
---|
| 280 | parse_config();
|
---|
| 281 | read_areas();
|
---|
| 282 | do_it();
|
---|
| 283 |
|
---|
| 284 | if ($file=~/ospfd.conf/) {$pr=$ospfd;}
|
---|
| 285 | if ($file=~/zebra.conf/) {$pr=$zebra;}
|
---|
| 286 | if ($file=~/dhcpd.conf/) {$pr=$dhcp;}
|
---|
| 287 | if ($file=~/snmpd.local.conf/){$pr=$snmpd;}
|
---|
| 288 | if ($file=~/mrtg.cfg/) {$pr=$mrtg;}
|
---|
| 289 | if ($file=~/linux.sh/) {$pr=$nwcfg;}
|
---|
| 290 | if ($file=~/sh/) {$pr=$sh;}
|
---|
| 291 | if ($file=~/rc.node.local/) {$pr=$rcconf;}
|
---|
| 292 | if ($file=~/rc.local/) {$pr=$freebsd;}
|
---|
| 293 | if ($file=~/resolv.conf/) {$pr=$resolv;}
|
---|
| 294 | if ($file=~/named.conf/) {$pr=$named;}
|
---|
| 295 |
|
---|
| 296 | if ($HTML)
|
---|
| 297 | {
|
---|
| 298 | $pr=~s/</</gi;$mrtg=~s/>/>/gi;
|
---|
| 299 | print "<PRE>$pr</PRE>\n";
|
---|
| 300 | } else {print $pr;}
|
---|
| 301 | }
|
---|
| 302 | }
|
---|