source: genesis/tools/configcleaner.pl@ 4095

Last change on this file since 4095 was 4092, checked in by rick, 20 years ago

Tooltje om snel alle configs op te schonen en netjes te zetten

File size: 2.8 KB
Line 
1#!/usr/bin/perl -w
2#
3#Tooltje om de wleiden files er generiek uit te laten zien
4#
5#Rick van der Zwet (rick@wirelessleiden.nl)
6use IP;
7
8my $debug = 0;
9
10#maak een mooi systeem met hash aanroepen om snel gegevens te verwerken
11sub parse_config {
12 foreach my $id (sort keys %config) {
13 my $rawData = $config{$id};
14 $rawData =~ s/#.*\n/\n/g; #wegslopen comments
15 $rawData =~ s/\s*[\r,\n]+\s*/:::/g; #spaties+enter+spaties vervangen door :::
16 $rawData =~ s/^::://; #::: aan het begin weghalen
17 $rawData =~ s/:::$//; #::: aan het eind weghalen
18 my @configArray = split( /:::/, $rawData); #array er van maken
19 foreach $line (@configArray) {
20 (my $name, my $value) = split( /\=/, $line);
21 $$name{$id} = $value;
22 }
23 }
24}
25
26
27sub genericConfig {
28 my $configfile = $_[0];
29 open( CONF, "> $configfile");
30 print CONF <<EOP;
31#
32# Config cleaned up bij configcleaner
33# config for $nodetype$nodename
34#
35\$master_ip='$master_ip';
36\$nodetype='$nodetype';
37\$nodename='$nodename';
38\$status='$status';
39
40\$location="$location";
41\$X='$X';
42\$Y='$Y';
43\$labelpos='$labelpos';
44
45\$OS='$OS';
46
47EOP
48
49 if(! $static_dhcp[0] eq "" ) {
50 for( my $ctr=0; $ctr < scalar(@static_dhcp); $ctr++ ) {
51 print CONF "\$dhcp_static[$ctr]='$static_dhcp[$ctr]';" . "\n";
52 }
53 }
54
55 foreach my $key (sort keys %config) {
56 my $keyTerminator = $key;
57 $keyTerminator =~ tr/a-z/A-Z/;
58 $keyTerminator =~ s/://;
59 print CONF <<EOP;
60
61\$config{'$key'}=sprintf <<$keyTerminator;
62 IP=$IP{$key}
63 TYPE=$TYPE{$key}
64EOP
65
66 if( lc($TYPE{$key}) eq "wireless" ) {
67 print CONF <<EOP;
68 MODE=$MODE{$key}
69 ESSID=$ESSID{$key}
70 CHANNEL=$CHANNEL{$key}
71EOP
72 }
73
74 print CONF <<EOP;
75 SPEED=$SPEED{$key}
76
77 DESC=$DESC{$key}
78 SDESC=$SDESC{$key}
79
80 POINT_TO_POINT=$POINT_TO_POINT{$key}
81 DHCP=$DHCP{$key}
82EOP
83
84 if( lc($TYPE{$key}) eq "wireless" ) {
85 print CONF <<EOP;
86
87 POLAR=$POLAR{$key}
88 ANTENNA=$ANTENNA{$key}
89 GAIN=$GAIN{$key}
90 DIRECTION=$DIRECTION{$key}
91 CABLE=$CABLE{$key}
92 HEIGHT=$HEIGTH{$key}
93EOP
94 }
95 print CONF "$keyTerminator" . "\n";
96 }
97 print CONF "\n" . "# End of Config File" . "\n";
98 close ( CONF );
99}
100
101
102foreach my $file (@ARGV) {
103 if($debug) {
104 $file_output = "test.conf";
105 }
106 else
107 {$file_output = $file;
108 }
109 print "Working on $file...\n";
110 @$_ = [] foreach qw(static_dhcp);
111 $static_dhcp[0]="";
112 $$_ = "" foreach qw(location master_ip gw_open nodetype nodename
113 OS status X Y N E OS DISK AGGREGATE);
114 %$_ = () foreach qw(config TYPE IP DESC SDESC SPEED DHCP DHCP_STATIC
115 OSPF_BROADCAST OSPF_NEIGHBORS MODE ESSID CHANNEL
116 POLAR ANTENNA GAIN DIRECTION BEAMWIDTH CABLE
117 HEIGHT ROUTE);
118 do($file) || die("Cann't open file");
119 print "\t Parsing config...";
120 parse_config;
121 print "DONE\n";
122 print "\t Applying generic rules ...";
123 genericConfig($file_output);
124 print "DONE\n";
125}
126
Note: See TracBrowser for help on using the repository browser.