source: genesis/tools/g_list.pl@ 4949

Last change on this file since 4949 was 4317, checked in by dirkx, 20 years ago

Fixing line types

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.1 KB
RevLine 
[4081]1#!/usr/bin/perl -w
[2592]2#
[4174]3# Copyright 2005 Stichting Wireless Leiden
4# Rick van der Zwet
[2592]5#
6
[4174]7# Config located at other file
8my $conf_file="/home/genesis/tools/genesis.conf";
9do($conf_file) || die("Cann't open $conf_file");
[4075]10
[4064]11
12
[4086]13my $HTML=1;
[2592]14
[4081]15#laden van tool file
16do($toolfile) || die("Cann't open $toolfile");
17
[4064]18#gebruik van simple subje om ervoor te zorgen dat de print netjes in het
19#programma gestopt kan worden
20sub printline {
21 print "$_[0] \n";
22};
[2592]23
24
[4081]25#REQUEST parsen
26$request=$ENV{'REQUEST_URI'};
[4087]27if( $request=~/cgi-bin\/g_list.pl\/(.*)$/) {
[4081]28 ($node,$file)=split(/\//,$1);
29 $title="$node $file";
30}
31else {
32 $title="listing";
33};
[4064]34
35
[4081]36#controleer wat de browser is
37#en zorgen dan er de nodige tags geprint worden
[2592]38$browser=$ENV{'HTTP_USER_AGENT'};
[4087]39if( $browser=~/curl|wget|fetch/i) {
[4064]40 $HTML=0;
41 printline("Content-type: text/html\n\n");
[2592]42}
[4064]43else {
44 $HTML=1;
45 printline("Content-type: text/html\n\n");
46 printline("<HTML>");
47 printline("<TITLE>Genesis $title</TITLE>");
48 printline("<BODY BGcolor=white>");
49};
[2592]50
51
[4081]52#als geen node gespecificeerd dan kijken of svn geupdate is gevraagd
[4087]53if( $node eq '') {
54 if( $ENV{"QUERY_STRING"}=~/update/i) {
[4127]55 printline("<H2>Please wait while updating svn...</H2><P><PRE>");
[4064]56 select(STDERR); $| = 1; # make unbuffered
57 select(STDOUT); $| = 1; # make unbuffered
[4128]58 system("$svn update $home");
[4064]59 printline("</PRE>");
60 printline("<H2>Done.<H2><P>");
61 printline("Click <A HREF=$source>here</A>");
62 printline("if you're not forwarded automaticly in 5 seconds.<P>");
63 printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
64 }
65 else {
66 g_list( );
67 };
68}
69else {
[4087]70 if( $file eq '') {
[4081]71 foreach $file ( sort @filelist) {
[4087]72 if( $HTML) {
[4064]73 print "$file<BR>\n";
74 }
75 else {
76 print "$file\n";
77 };
78 };
79 }
[4087]80 elsif( $file eq 'config') {
[4064]81 g_print($hostname);
82 }
[4075]83 else {
[4081]84 foreach my $tmpFile ( sort @filelist) {
[4075]85 if( $file eq $tmpFile ) {
[4081]86 g_generate($file);
[4075]87 };
88 };
[4064]89 };
90};
[2592]91
[4081]92#plaats de sluit HTML tags
[4087]93if( $HTML) {
[4064]94 print <<EOF;
[2592]95</BODY>
96</HTML>
97EOF
98}
99
[4081]100
101#Het opbouwen van het begin scherm
[4064]102sub g_list {
[4087]103 if( $HTML) {
[4086]104 my $svn_version=svn_version("$ndir");
[4087]105 if( $svn_version=~/Last Changed Rev: (\d+)/) {
[4064]106 $revision=$1;
107 };
108 printline("<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>");
109 printline("$svn_version");
110 printline("</PRE>");
111 printline("<FORM METHOD=get ACTION=$source>");
112 printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
113 printline("</FORM>");
114 printline("<TABLE BORDER=1>");
115 };
[2592]116
117 opendir(DIR, $ndir) || die "can't opendir $home: $!";
118 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
[4064]119 closedir DIR;
120 foreach $dir (sort @dirs) {
[4087]121 if( $dir=~/attic/ ) {
[4064]122 next;
123 };
[4086]124 my $node = $dir;
[4087]125 if( ! $HTML ) {
[4086]126 print "$node\n";
[4064]127 }
128 else {
[4086]129 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
[4081]130 foreach $file (sort @filelist) {
[4086]131 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
[4064]132 };
133 };
134 };
[4087]135 if( $HTML ) {
136 printline("</TABLE><P>");
137 };
[4064]138};
[2592]139
140
141
[4081]142#ophalen svn versie
[4064]143sub svn_version {
144 local($file,$char)=@_;
145 local($svn_version);
146 $svn_version=`$svn info $file`;
[4087]147 if( $char ne '' ) {
[4064]148 $svn_version=~s/^([^$char].*)/$char $1/mgi;
149 };
150 return($svn_version);
[4025]151};
[2592]152
[4025]153
[4081]154
155#netjes de configuratie printen
[4064]156sub g_print {
[4104]157 my $config="$ndir/$node/$configfile";
[4081]158 parse_config($config);
159
160 printline("<H1>Genesis configuratie voor: $node</H1><P>");
161 printline("<PRE>" . svn_version($config) . "</PRE><P>");
[4025]162
[2592]163
[4081]164 my $TP='';
[4087]165 if( $tproxy !~ m/no/i ) {
[4081]166 $TP .= "\n";
167 $TP .= "Tproxy on cidr range $tproxy";
168 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
169 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
170 };
[2592]171
[4081]172 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>");
173 printline("master_ip=$master_ip");
174 printline("AGGREGATE=$AGGREGATE");
175 printline("");
176 printline("gw_open=$gw_open");
177 printline("nodetype=$nodetype");
178 printline("nodename=$nodename");
179 printline("");
180 printline("NS_forward=$NS_forward");
181 printline("NS_resolv=$NS_resolv");
182 printline("");
183 printline("location=$location");
184 printline("DISK=$DISK");
185 printline("");
186 printline("X=$X");
187 printline("Y=$Y");
188 printline("");
189 printline("OS=$OS");
190 printline("");
191 printline("$TP");
192 printline("</PRE></TD></TR>");
[2592]193
[4087]194 foreach $if( sort keys %config) {
195 if( $if=~/^(.*):\d+/ ) {
[4081]196 $subs{$1}++;
197 };
198 };
[2592]199
[4087]200 foreach $if( sort keys %config) {
201 if( $if=~/^([^:]+)/ ) {
[4081]202 $mymain=$1;
203 }
204 else {
205 $mymain='';
206 };
207
[4087]208 if( $if!~/:\d+/ ) {
[4081]209 $main=1;$cc='66'
210 }
211 else {
212 $main=0;
213 $cc='cc';
214 };
215
[4087]216 if(! ($ip=$IP{$if}) ) {
[4081]217 $ip='dhcp?';
218 };
[4087]219 if( $TYPE{$if}=~/wireless/ ) {
[4081]220 $color="#${cc}FFFF";
221 };
[4087]222 if( $TYPE{$if}=~/ethernet/) {
[4081]223 $color="#FFFF${cc}";
224 };
225
226 $cfg=$config{$if};
227 $cfg=~s/(.*KEY.*=).*/${1}***********/;
228 $cfg=~s/(.*PWD.*=).*/${1}***********/;
229 $cfg=~s/(.*CODE.*=).*/${1}***********/;
230 $cfg=~s/(.*PASS.*=).*/${1}***********/;
[2592]231
[4087]232 if( $main) {
[4081]233 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};
234 $c=4;
235 }
236 else {
237 $c=3;
238 print "<TR bgcolor=$color>";
239 };
240 $cfg=~s/</&lt;/gi;
241 $cfg=~s/>/&gt;/gi;
[2592]242
[4081]243 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>");
244 printline("<TR><TD COLSPAN=$c><PRE>");
245 printline("$cfg");
246 printline("</PRE></TD>");
247 printline("<TR><TD COLSPAN=$c>&nbsp;</TD>");
248 };
249 printline("</TABLE>");
[4064]250};
[2592]251
252
[4081]253
254#Generen config
[4064]255sub g_generate {
[4081]256 my $file=$_[0];
[4104]257 $config="$ndir/$node/$configfile";
[4081]258 $svn_versiont=svn_version($toolfile,$char);
259 $svn_versionc=svn_version($config,$char);
[2592]260
[4087]261 if( $svn_versiont=~/Last Changed Rev: (\d+)/ ) {
[4081]262 $tool_rev=$1;
263 };
[4087]264 if( $svn_versionc=~/Last Changed Rev: (\d+)/ ) {
[4081]265 $config_rev=$1;
266 };
267
[4087]268 if( $tool_rev >= $config_rev) {
[4081]269 $svn_version=$svn_versiont . $svn_versionc;
270 }
[4064]271 else {
[4081]272 $svn_version=$svn_versionc;
273 };
[2592]274
[4087]275 if( $HTML) {
[4081]276 printline("<H1>Genesis $file voor: $hostname</H1><P>");
277 };
[2592]278
[4081]279 parse_config($config);
280 $pr=do_it($file);
[2592]281
282
[4087]283 if( $HTML ) {
[4081]284 $pr=~s/</&lt;/gi;
285 printline("<PRE>$pr</PRE>");
286 }
287 else {
288 print $pr;
[4064]289 };
290};
Note: See TracBrowser for help on using the repository browser.