source: genesis/tools/configcleaner.pl@ 6021

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

Fixing line types

  • Property svn:eol-style set to native
File size: 2.9 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
47\$tproxy='$tproxy';
48EOP
49
50 if(! $static_dhcp[0] eq "" ) {
51 for( my $ctr=0; $ctr < scalar(@static_dhcp); $ctr++ ) {
52 print CONF "\$dhcp_static[$ctr]='$static_dhcp[$ctr]';" . "\n";
53 }
54 }
55
56 foreach my $key (sort keys %config) {
57 my $keyTerminator = $key;
58 $keyTerminator =~ tr/a-z/A-Z/;
59 $keyTerminator =~ s/://;
60 print CONF <<EOP;
61
62\$config{'$key'}=sprintf <<$keyTerminator;
63 IP=$IP{$key}
64 TYPE=$TYPE{$key}
65EOP
66
67 if( lc($TYPE{$key}) eq "wireless" ) {
68 print CONF <<EOP;
69 MODE=$MODE{$key}
70 ESSID=$ESSID{$key}
71 CHANNEL=$CHANNEL{$key}
72EOP
73 }
74
75 print CONF <<EOP;
76 SPEED=$SPEED{$key}
77
78 DESC=$DESC{$key}
79 SDESC=$SDESC{$key}
80
81 POINT_TO_POINT=$POINT_TO_POINT{$key}
82 DHCP=$DHCP{$key}
83EOP
84
85 if( lc($TYPE{$key}) eq "wireless" ) {
86 print CONF <<EOP;
87
88 POLAR=$POLAR{$key}
89 ANTENNA=$ANTENNA{$key}
90 GAIN=$GAIN{$key}
91 DIRECTION=$DIRECTION{$key}
92 CABLE=$CABLE{$key}
93 HEIGHT=$HEIGTH{$key}
94EOP
95 }
96 print CONF "$keyTerminator" . "\n";
97 }
98 print CONF "\n" . "# End of Config File" . "\n";
99 close ( CONF );
100}
101
102
103foreach my $file (@ARGV) {
104 if($debug) {
105 $file_output = "test.conf";
106 }
107 else
108 {$file_output = $file;
109 }
110 print "Working on $file...\n";
111 @$_ = [] foreach qw(static_dhcp);
112 $static_dhcp[0]="";
113 $$_ = "" foreach qw(location master_ip gw_open nodetype nodename
114 OS status X Y N E OS DISK AGGREGATE);
115 %$_ = () foreach qw(config TYPE IP DESC SDESC SPEED DHCP DHCP_STATIC
116 OSPF_BROADCAST OSPF_NEIGHBORS MODE ESSID CHANNEL
117 POLAR ANTENNA GAIN DIRECTION BEAMWIDTH CABLE
118 HEIGHT ROUTE);
119 do($file) || die("Cann't open file");
120 print "\t Parsing config...";
121 parse_config;
122 print "DONE\n";
123 print "\t Applying generic rules ...";
124 genericConfig($file_output);
125 print "DONE\n";
126}
127
Note: See TracBrowser for help on using the repository browser.