1 | #!/usr/bin/env perl
|
---|
2 |
|
---|
3 | eval {
|
---|
4 | require Geo::Coordinates::RDNAP;
|
---|
5 | };
|
---|
6 | if (! $@) {
|
---|
7 | Geo::Coordinates::RDNAP->import(qw/from_rd to_rd dms/);
|
---|
8 | } else {
|
---|
9 | sub from_rd {
|
---|
10 | return (0,0,0);
|
---|
11 | }
|
---|
12 | }
|
---|
13 |
|
---|
14 | # RD X,Y -> RD Noorderbreedte, Oosterbreedte
|
---|
15 | # http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
|
---|
16 |
|
---|
17 | # Little perl to convert genesis files into python config files,
|
---|
18 | # Which gonna be used for more logic stuff ;-)
|
---|
19 |
|
---|
20 | $argc = $#ARGV + 1;
|
---|
21 | if ($argc == 0) {
|
---|
22 | print STDERR "Usage $_ <wleiden.conf> ...\n";
|
---|
23 | exit 1;
|
---|
24 | # Hack to easy support multiple files without remembering any variable in between
|
---|
25 | } elsif ($argc > 1) {
|
---|
26 | foreach $file (@ARGV) {
|
---|
27 | $output = $file;
|
---|
28 | $output =~ s/conf$/yaml/;
|
---|
29 | print `perl $ENV{_} $file > $output`;
|
---|
30 | }
|
---|
31 | exit 0;
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 | do($ARGV[0]) || die;
|
---|
36 |
|
---|
37 | my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
|
---|
38 |
|
---|
39 | $interfaces = [];
|
---|
40 | foreach $if (keys %config) {
|
---|
41 | push(@interfaces, $if) if ($if =~ m/^[a-z0-9]+$/g);
|
---|
42 | }
|
---|
43 | $interfaces = join(",",@interfaces);
|
---|
44 |
|
---|
45 | if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
|
---|
46 | ($lat, $lon, $h) = from_rd( $X, $Y, 0);
|
---|
47 | } else {
|
---|
48 | $lat = $lon = $h = 0;
|
---|
49 | }
|
---|
50 |
|
---|
51 | $status = $status_labels{$status} || 'up'; # ensure reporting a correct status
|
---|
52 | $comment = $comment || 'None';
|
---|
53 |
|
---|
54 | print <<EOF;
|
---|
55 | # Genesis config yaml style
|
---|
56 | # vim:ts=2:et:sw=2:ai
|
---|
57 | #
|
---|
58 | comment : $comment
|
---|
59 | interfaces: $interfaces
|
---|
60 | latitude : $lat
|
---|
61 | location : $location
|
---|
62 | longitude : $lon
|
---|
63 | masterip : $master_ip
|
---|
64 | nodename : $nodename
|
---|
65 | nodetype : $nodetype
|
---|
66 | rdnap_x : $X
|
---|
67 | rdnap_y : $Y
|
---|
68 | status : $status
|
---|
69 | EOF
|
---|
70 |
|
---|
71 |
|
---|
72 | foreach $if (keys %config) {
|
---|
73 | ($iflabel, $alias) = split(':',$if);
|
---|
74 | $iflabel .= "_alias${alias}" if ($alias =~ m/[0-9]/);
|
---|
75 |
|
---|
76 | print <<EOF;
|
---|
77 | iface_$iflabel:
|
---|
78 | EOF
|
---|
79 | %tmp = (
|
---|
80 | 'dhcp' => 'False',
|
---|
81 | 'compass' => 'None',
|
---|
82 | 'interface' => $if,
|
---|
83 | );
|
---|
84 | foreach $line (split('\n',$config{$if})) {
|
---|
85 | ($key, $value) = split(/=/,$line);
|
---|
86 | if ($key and (lc($key) =~ /^[a-z].*/)) {
|
---|
87 | #print "$key : $value\n";
|
---|
88 | $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
|
---|
89 | if ($key =~ /^type$/i) {
|
---|
90 | if ($value eq 'ethernet') {
|
---|
91 | $value = 'eth';
|
---|
92 | } else {
|
---|
93 | $value = '11b';
|
---|
94 | }
|
---|
95 | } elsif ($key =~ /^mode$/i) {
|
---|
96 | if ($value eq 'master') {
|
---|
97 | $value = 'ap-wds';
|
---|
98 | } else { # managed
|
---|
99 | $value = 'station-wds';
|
---|
100 | }
|
---|
101 | } elsif ($key =~ /^polar$/i) {
|
---|
102 | if ($value eq 'hor') {
|
---|
103 | $value = 'hr';
|
---|
104 | } else {
|
---|
105 | $value = 'vr';
|
---|
106 | }
|
---|
107 | } elsif ($key =~ /^essid$/i) {
|
---|
108 | $key = 'ssid';
|
---|
109 |
|
---|
110 | # Dirty hack to fetch compass direction of essid
|
---|
111 | $value =~ /[a-z]+-([a-z]+)\..*/;
|
---|
112 | $direction = $1;
|
---|
113 | # Translate into English
|
---|
114 | if ($direction ne "omni") {
|
---|
115 | $direction =~ tr/oz/es/;
|
---|
116 | }
|
---|
117 | # node AMwtrt1 and 'test' directions
|
---|
118 | if ($direction eq "wtrtr" or $direction eq "test") {
|
---|
119 | $direction = 'None';
|
---|
120 | }
|
---|
121 | $tmp{'compass'} = $direction;
|
---|
122 | } elsif ($key =~ /^gain$/i) {
|
---|
123 | $value =~ s/dbi//;
|
---|
124 | }
|
---|
125 | $tmp{lc($key)} = $value;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | # ethernet2wifi bridges
|
---|
129 | if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
|
---|
130 | $tmp{type} = 'eth';
|
---|
131 | }
|
---|
132 | # 11a
|
---|
133 | if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
|
---|
134 | $tmp{type} = '11a';
|
---|
135 | }
|
---|
136 |
|
---|
137 | foreach $key (sort keys %tmp) {
|
---|
138 | printf " %-11s: '$tmp{$key}'\n", $key;
|
---|
139 | }
|
---|
140 | print "\n";
|
---|
141 | }
|
---|
142 |
|
---|