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