- Timestamp:
- Mar 16, 2005, 6:10:04 PM (20 years ago)
- Location:
- tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/g_list.pl
r4075 r4081 1 #! 1 #!/usr/bin/perl -w 2 2 # 3 3 # 4 4 # 5 5 6 # eerst even een subje om ervoor te zorgen dat de hostname + file bekend 7 # is 8 $filelist[0]="txtconfig"; 9 $filelist[1]="dhcpd.conf"; 10 $filelist[2]="rc.local"; 11 $filelist[3]="rc.node.local"; 12 $filelist[4]="resolv.conf"; 13 $filelist[5]="named.conf"; 14 $filelist[6]="snmpd.local.conf"; 15 16 $request=$ENV{'REQUEST_URI'}; 17 if ($request=~/cgi-bin\/g_list.pl\/(.*)$/) { 18 ($hostname,$file)=split(/\//,$1); 19 $title="$hostname $file"; 20 } 21 else { 22 $title="listing"; 23 }; 6 7 #filelist 8 my @filelist = (); 9 $filelist[0]="dhcpd.conf"; 10 $filelist[1]="rc.local"; 11 $filelist[2]="rc.node.local"; 12 $filelist[3]="resolv.conf"; 13 $filelist[4]="named.conf"; 14 $filelist[5]="snmpd.local.conf"; 15 $filelist[6]="txtconfig"; 24 16 25 17 #(inter)net env 26 $cgi_dir="$hostname/cgi-bin"; 27 $source="$cgi_dir/g_list.pl"; 18 my $hostname=`hostname`; 19 my $cgi_dir="$hostname/cgi-bin"; 20 my $source="$cgi_dir/g_list.pl"; 28 21 29 22 #path variablen 30 $home="/home/rick/svn/genesis/";31 $ndir="$home/nodes";32 $toolfile="$home/tools/wleiden.pl";23 my $home="/home/rick/svn/genesis"; 24 my $ndir="$home/nodes"; 25 my $toolfile="$home/tools/wleiden.pl"; 33 26 34 27 #exec vars 35 $svn='/usr/local/bin/svn'; 36 $html=1; 37 38 $functions_only=1; 39 do $toolfile || die; 28 my $svn="/usr/local/bin/svn"; 29 30 ######################## END OF CONFIG ########################## 31 my $html=1; 32 33 #laden van tool file 34 do($toolfile) || die("Cann't open $toolfile"); 40 35 41 36 #gebruik van simple subje om ervoor te zorgen dat de print netjes in het … … 46 41 47 42 48 49 43 #REQUEST parsen 44 $request=$ENV{'REQUEST_URI'}; 45 if ($request=~/cgi-bin\/g_list.pl\/(.*)$/) { 46 ($node,$file)=split(/\//,$1); 47 $title="$node $file"; 48 } 49 else { 50 $title="listing"; 51 }; 52 53 54 #controleer wat de browser is 55 #en zorgen dan er de nodige tags geprint worden 50 56 $browser=$ENV{'HTTP_USER_AGENT'}; 51 57 if ($browser=~/curl|wget|fetch/i) { … … 63 69 64 70 65 if ($hostname eq '') { 71 #als geen node gespecificeerd dan kijken of svn geupdate is gevraagd 72 if ($node eq '') { 66 73 if ($ENV{"QUERY_STRING"}=~/update/i) { 67 74 select(STDERR); $| = 1; # make unbuffered … … 81 88 } 82 89 else { 83 $dir="$ndir/$hostname"; 84 if (! -d $dir ) { 85 if ($HTML) { 86 print "<H1>Host $hostname not found: $dir</H1><P>\n"; 87 } 88 else { 89 print "Host $hostname not found: $dir\n"; 90 }; 91 } 92 elsif ($file eq '') { 93 foreach $file (@filelist) { 90 if ($file eq '') { 91 foreach $file ( sort @filelist) { 94 92 if ($HTML) { 95 93 print "$file<BR>\n"; … … 103 101 g_print($hostname); 104 102 } 105 elsif ($file eq 'txtconfig') {106 $HTML=0;g_print($hostname);107 }108 103 else { 109 foreach my $tmpFile ( @filelist) {104 foreach my $tmpFile ( sort @filelist) { 110 105 if( $file eq $tmpFile ) { 111 g_generate($file ,$hostname);106 g_generate($file); 112 107 }; 113 108 }; … … 115 110 }; 116 111 117 112 #plaats de sluit HTML tags 118 113 if ($HTML) { 119 114 print <<EOF; … … 123 118 } 124 119 120 121 #Het opbouwen van het begin scherm 125 122 sub g_list { 126 123 if ($HTML) { … … 151 148 else { 152 149 printline("<TR><TD><A HREF=g_list.pl/$hostname/config>$hostname</A></TD>"); 153 foreach $file ( @filelist) {150 foreach $file (sort @filelist) { 154 151 printline("<TD><A HREF=g_list.pl/$hostname/$file>$file</A></TD>\n"); 155 152 }; … … 161 158 162 159 160 #ophalen svn versie 163 161 sub svn_version { 164 162 local($file,$char)=@_; … … 172 170 173 171 172 173 #netjes de configuratie printen 174 174 sub g_print { 175 local($hostname)=@_; 176 $config="$ndir/$hostname/wleiden.conf"; 177 178 if (! $HTML) { 179 print svn_version($config,'#'); 180 open (CFG,$config) || die; 181 while (<CFG>) {print $_;} 182 close(CFG); 175 my $config="$ndir/$node/wleiden.conf"; 176 parse_config($config); 177 178 printline("<H1>Genesis configuratie voor: $node</H1><P>"); 179 printline("<PRE>" . svn_version($config) . "</PRE><P>"); 180 181 182 my $TP=''; 183 if ($tproxy !~ m/no/i) { 184 $TP .= "\n"; 185 $TP .= "Tproxy on cidr range $tproxy"; 186 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>" 187 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/; 188 }; 189 190 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>"); 191 printline("master_ip=$master_ip"); 192 printline("AGGREGATE=$AGGREGATE"); 193 printline(""); 194 printline("gw_open=$gw_open"); 195 printline("nodetype=$nodetype"); 196 printline("nodename=$nodename"); 197 printline(""); 198 printline("NS_forward=$NS_forward"); 199 printline("NS_resolv=$NS_resolv"); 200 printline(""); 201 printline("location=$location"); 202 printline("DISK=$DISK"); 203 printline(""); 204 printline("X=$X"); 205 printline("Y=$Y"); 206 printline(""); 207 printline("OS=$OS"); 208 printline(""); 209 printline("$TP"); 210 printline("</PRE></TD></TR>"); 211 212 foreach $if (sort keys %config) { 213 if ($if=~/^(.*):\d+/) { 214 $subs{$1}++; 215 }; 216 }; 217 218 foreach $if (sort keys %config) { 219 if ($if=~/^([^:]+)/) { 220 $mymain=$1; 221 } 222 else { 223 $mymain=''; 224 }; 225 226 if ($if!~/:\d+/) { 227 $main=1;$cc='66' 228 } 229 else { 230 $main=0; 231 $cc='cc'; 232 }; 233 234 if (! ($ip=$IP{$if})) { 235 $ip='dhcp?'; 236 }; 237 if ($TYPE{$if}=~/wireless/) { 238 $color="#${cc}FFFF"; 239 }; 240 if ($TYPE{$if}=~/ethernet/) { 241 $color="#FFFF${cc}"; 242 }; 243 244 $cfg=$config{$if}; 245 $cfg=~s/(.*KEY.*=).*/${1}***********/; 246 $cfg=~s/(.*PWD.*=).*/${1}***********/; 247 $cfg=~s/(.*CODE.*=).*/${1}***********/; 248 $cfg=~s/(.*PASS.*=).*/${1}***********/; 249 250 if ($main) { 251 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if}; 252 $c=4; 253 } 254 else { 255 $c=3; 256 print "<TR bgcolor=$color>"; 257 }; 258 $cfg=~s/</</gi; 259 $cfg=~s/>/>/gi; 260 261 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>"); 262 printline("<TR><TD COLSPAN=$c><PRE>"); 263 printline("$cfg"); 264 printline("</PRE></TD>"); 265 printline("<TR><TD COLSPAN=$c> </TD>"); 266 }; 267 printline("</TABLE>"); 268 }; 269 270 271 272 #Generen config 273 sub g_generate { 274 my $file=$_[0]; 275 $config="$ndir/$node/wleiden.conf"; 276 $svn_versiont=svn_version($toolfile,$char); 277 $svn_versionc=svn_version($config,$char); 278 279 if ($svn_versiont=~/Last Changed Rev: (\d+)/) { 280 $tool_rev=$1; 281 }; 282 if ($svn_versionc=~/Last Changed Rev: (\d+)/) { 283 $config_rev=$1; 284 }; 285 286 if ($tool_rev >= $config_rev) { 287 $svn_version=$svn_versiont . $svn_versionc; 183 288 } 184 289 else { 185 printline("<H1>Genesis configuratie voor: $hostname</H1><P>"); 186 printline("<PRE>" . svn_version($config) . "</PRE><P>"); 187 188 do($config) || die; 189 parse_config(); 190 191 $TP=''; 192 if ($tproxy !~ m/no/i) { 193 $TP .= "\n"; 194 $TP .= "Tproxy on cidr range $tproxy"; 195 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>" 196 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/; 197 }; 198 199 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>"); 200 printline("master_ip=$master_ip"); 201 printline("AGGREGATE=$AGGREGATE"); 202 printline(""); 203 printline("gw_open=$gw_open"); 204 printline("nodetype=$nodetype"); 205 printline("nodename=$nodename"); 206 printline(""); 207 printline("NS_forward=$NS_forward"); 208 printline("NS_resolv=$NS_resolv"); 209 printline(""); 210 printline("location=$location"); 211 printline("DISK=$DISK"); 212 printline(""); 213 printline("X=$X"); 214 printline("Y=$Y"); 215 printline(""); 216 printline("OS=$OS"); 217 printline(""); 218 printline("$TP"); 219 printline("</PRE></TD></TR>"); 220 221 foreach $if (sort keys %config) { 222 if ($if=~/^(.*):\d+/) { 223 $subs{$1}++; 224 }; 225 }; 226 227 foreach $if (sort keys %config) { 228 if ($if=~/^([^:]+)/) { 229 $mymain=$1; 230 } 231 else { 232 $mymain=''; 233 }; 234 235 if ($if!~/:\d+/) { 236 $main=1;$cc='66' 237 } 238 else { 239 $main=0; 240 $cc='cc'; 241 }; 242 243 if (! ($ip=$IP{$if})) { 244 $ip='dhcp?'; 245 }; 246 if ($TYPE{$if}=~/wireless/) { 247 $color="#${cc}FFFF"; 248 }; 249 if ($TYPE{$if}=~/ethernet/) { 250 $color="#FFFF${cc}"; 251 }; 252 253 $cfg=$config{$if}; 254 $cfg=~s/(.*KEY.*=).*/${1}***********/; 255 $cfg=~s/(.*PWD.*=).*/${1}***********/; 256 $cfg=~s/(.*CODE.*=).*/${1}***********/; 257 $cfg=~s/(.*PASS.*=).*/${1}***********/; 258 259 if ($main) { 260 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if}; 261 $c=4; 262 } 263 else { 264 $c=3; 265 print "<TR bgcolor=$color>"; 266 }; 267 $cfg=~s/</</gi; 268 $cfg=~s/>/>/gi; 269 270 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>"); 271 printline("<TR><TD COLSPAN=$c><PRE>"); 272 printline("$cfg"); 273 printline("</PRE></TD>"); 274 printline("<TR><TD COLSPAN=$c> </TD>"); 275 }; 276 printline("</TABLE>"); 277 }; 278 }; 279 280 281 sub g_generate { 282 ($file,$hostname)=@_; 283 $config="$ndir/$hostname/wleiden.conf"; 284 285 if (! -r $config) { 286 if ($HTML) { 287 printline("<H1>File $file not found: $config</H1><P>"); 288 } 289 else { 290 printline("File $file not found: $config"); 291 }; 292 } 290 $svn_version=$svn_versionc; 291 }; 292 293 if ($HTML) { 294 printline("<H1>Genesis $file voor: $hostname</H1><P>"); 295 }; 296 297 parse_config($config); 298 $pr=do_it($file); 299 300 301 if ($HTML) { 302 $pr=~s/</</gi; 303 printline("<PRE>$pr</PRE>"); 304 } 293 305 else { 294 $svn_versiont=svn_version($toolfile,$char); 295 $svn_versionc=svn_version($config,$char); 296 297 if ($svn_versiont=~/Last Changed Rev: (\d+)/) { 298 $tool_rev=$1; 299 }; 300 if ($svn_versionc=~/Last Changed Rev: (\d+)/) { 301 $config_rev=$1; 302 }; 303 304 if ($tool_rev >= $config_rev) { 305 $svn_version=$svn_versiont . $svn_versionc; 306 } 307 else { 308 $svn_version=$svn_versionc; 309 }; 310 311 if ($HTML) { 312 printline("<H1>Genesis $file voor: $hostname</H1><P>"); 313 }; 314 315 parse_config($config); 316 $pr=do_it($file); 317 318 319 if ($HTML) { 320 $pr=~s/</</gi;$mrtg=~s/>/>/gi; 321 printline("<PRE>$pr</PRE>"); 322 } 323 else { 324 print $pr; 325 }; 326 }; 327 }; 306 print $pr; 307 }; 308 }; -
tools/wleiden.pl
r4079 r4081 1 #!/usr/bin/perl -w 1 2 # 2 3 # 3 4 # maart 2004 rick@wirelessleiden.nl 4 5 # 5 6 6 7 7 my $debug=0; … … 13 13 14 14 #variablen 15 my $workingfile = "";16 15 my $time=gmtime(); 17 16 my $source=`/bin/hostname -s`; … … 20 19 21 20 #slurp IP berekeningen info 22 do ( $IP_pmPath) || die ("Cann't open $IP_pmPath");21 do ("$IP_pmPath") || die ("Cann't open $IP_pmPath"); 23 22 #slurp dns info 24 do ( $dnsheader_confPath) || die ("Cann't open $dnsheader_confPath");23 do ("$dnsheader_confPath") || die ("Cann't open $dnsheader_confPath"); 25 24 26 25 … … 35 34 if( $1 eq $master_ip ) { 36 35 return(0); 37 break;38 36 }; 39 37 }; … … 59 57 60 58 61 62 59 sub txtconfig { 63 my $output = `cat $workingfile`; 64 return($output); 65 }; 66 60 my $output = ""; 61 foreach $interface (keys %config) { 62 $output .= $config{$interface}; 63 }; 64 return($output); 65 }; 67 66 68 67 … … 169 168 170 169 171 sub rc_ conf{170 sub rc_local { 172 171 my $output = genHeader("#"); 173 172 my $masterNotUsed = master_ipNotUsed(); 174 print $masterNotUsed;175 173 $output.= 176 174 "hostname=\"$nodetype$nodename.wLeiden.NET\"\n" . … … 298 296 299 297 sub parse_config { 300 $workingfile = $_[0];298 my $workingfile = $_[0]; 301 299 do($workingfile) || die("Cann't open/parse $workingfile"); 302 foreach $if (keys %config) {303 $cfg=$config{$if};300 foreach my $if (keys %config) { 301 my $cfg=$config{$if}; 304 302 while ($cfg) { 305 303 $cfg=~s/^([^\n\r]+)[\r\n]*//m; 306 $line=$1;304 my $line=$1; 307 305 $line=~s/\s*#.*//; 308 if ((( $name,$value)=split(/=/,$line)) eq 2) {309 $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}";306 if (((my $name, my $value)=split(/=/,$line)) eq 2) { 307 my $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\";$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}"; 310 308 eval($doit); 311 309 }; … … 324 322 }; 325 323 326 if( $debug) {324 if( exists $ARGV[0] ) { 327 325 if( exists $ARGV[1] ) { 328 326 parse_config($ARGV[0]); … … 333 331 }; 334 332 }; 333 334 1;
Note:
See TracChangeset
for help on using the changeset viewer.