[8266] | 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) {
|
---|
[8294] | 27 | $output = $file;
|
---|
| 28 | $output =~ s/conf$/yaml/;
|
---|
| 29 | print `perl $ENV{_} $file > $output`;
|
---|
[8266] | 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);
|
---|
[8270] | 74 | $iflabel .= "_alias${alias}" if ($alias =~ m/[0-9]/);
|
---|
[8266] | 75 |
|
---|
| 76 | print <<EOF;
|
---|
| 77 | iface_$iflabel:
|
---|
| 78 | EOF
|
---|
| 79 | %tmp = (
|
---|
| 80 | 'dhcp' => 'False',
|
---|
[8273] | 81 | 'compass' => 'None',
|
---|
[8266] | 82 | 'interface' => $if,
|
---|
| 83 | );
|
---|
| 84 | foreach $line (split('\n',$config{$if})) {
|
---|
| 85 | ($key, $value) = split(/=/,$line);
|
---|
[8300] | 86 | # Remove trailing and leading white spaces
|
---|
| 87 | $value =~ s/^\s+//;
|
---|
| 88 | $value =~ s/\s+$//;
|
---|
[8266] | 89 | if ($key and (lc($key) =~ /^[a-z].*/)) {
|
---|
| 90 | #print "$key : $value\n";
|
---|
| 91 | $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
|
---|
| 92 | if ($key =~ /^type$/i) {
|
---|
| 93 | if ($value eq 'ethernet') {
|
---|
| 94 | $value = 'eth';
|
---|
| 95 | } else {
|
---|
| 96 | $value = '11b';
|
---|
| 97 | }
|
---|
| 98 | } elsif ($key =~ /^mode$/i) {
|
---|
| 99 | if ($value eq 'master') {
|
---|
[8273] | 100 | $value = 'ap-wds';
|
---|
[8266] | 101 | } else { # managed
|
---|
[8273] | 102 | $value = 'station-wds';
|
---|
[8266] | 103 | }
|
---|
| 104 | } elsif ($key =~ /^polar$/i) {
|
---|
| 105 | if ($value eq 'hor') {
|
---|
| 106 | $value = 'hr';
|
---|
| 107 | } else {
|
---|
| 108 | $value = 'vr';
|
---|
| 109 | }
|
---|
| 110 | } elsif ($key =~ /^essid$/i) {
|
---|
| 111 | $key = 'ssid';
|
---|
| 112 |
|
---|
| 113 | # Dirty hack to fetch compass direction of essid
|
---|
| 114 | $value =~ /[a-z]+-([a-z]+)\..*/;
|
---|
| 115 | $direction = $1;
|
---|
| 116 | # Translate into English
|
---|
| 117 | if ($direction ne "omni") {
|
---|
| 118 | $direction =~ tr/oz/es/;
|
---|
| 119 | }
|
---|
| 120 | # node AMwtrt1 and 'test' directions
|
---|
| 121 | if ($direction eq "wtrtr" or $direction eq "test") {
|
---|
| 122 | $direction = 'None';
|
---|
| 123 | }
|
---|
[8273] | 124 | $tmp{'compass'} = $direction;
|
---|
[8266] | 125 | } elsif ($key =~ /^gain$/i) {
|
---|
| 126 | $value =~ s/dbi//;
|
---|
| 127 | }
|
---|
| 128 | $tmp{lc($key)} = $value;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | # ethernet2wifi bridges
|
---|
| 132 | if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
|
---|
[8273] | 133 | $tmp{type} = 'eth';
|
---|
[8266] | 134 | }
|
---|
| 135 | # 11a
|
---|
| 136 | if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
|
---|
| 137 | $tmp{type} = '11a';
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | foreach $key (sort keys %tmp) {
|
---|
[8270] | 141 | printf " %-11s: '$tmp{$key}'\n", $key;
|
---|
[8266] | 142 | }
|
---|
| 143 | print "\n";
|
---|
| 144 | }
|
---|
| 145 |
|
---|