[6439] | 1 | #!/usr/bin/env perl
|
---|
| 2 | use Geo::Coordinates::RDNAP qw/from_rd to_rd dms/;
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | # RD X,Y -> RD Noorderbreedte, Oosterbreedte
|
---|
| 6 | # http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
|
---|
| 7 |
|
---|
| 8 | # Little perl to convert genesis files into python config files,
|
---|
| 9 | # Which gonna be used for more logic stuff ;-)
|
---|
| 10 |
|
---|
[6508] | 11 | # Avoid junk node imports, use following line to import valid nodes
|
---|
| 12 | # Usage: for file in CNode*/wleiden.conf proxy*/wleiden.conf; do ./genesis-to-py.pl $file; done > py.conf
|
---|
[6439] | 13 | do($ARGV[0]) || die;
|
---|
| 14 |
|
---|
[6463] | 15 | my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
|
---|
| 16 |
|
---|
[6439] | 17 | $interfaces = join(',',keys %config);
|
---|
| 18 | if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
|
---|
| 19 | ($lat, $lon, $h) = from_rd( $X, $Y, 0);
|
---|
| 20 | } else {
|
---|
| 21 | $lat = $lon = $h = 0;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[6463] | 24 | $status = $status_labels{$status} || 'up'; # ensure reporting a correct status
|
---|
| 25 |
|
---|
[6439] | 26 | print <<EOF;
|
---|
| 27 | [$nodename]
|
---|
| 28 | location = $location
|
---|
| 29 | status = $status
|
---|
| 30 | latitude = $lat
|
---|
| 31 | longitude = $lon
|
---|
| 32 | interfaces = $interfaces
|
---|
| 33 | x = $X
|
---|
| 34 | y = $Y
|
---|
[6463] | 35 | masterip = $master_ip
|
---|
[6439] | 36 | nodetype = $nodetype
|
---|
[6463] | 37 | name = $nodename
|
---|
[6439] | 38 | configtype = node
|
---|
| 39 |
|
---|
| 40 | EOF
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | foreach $if (keys %config) {
|
---|
| 44 | print <<EOF;
|
---|
| 45 | [$nodename/$if]
|
---|
| 46 | EOF
|
---|
| 47 | %tmp = (
|
---|
| 48 | 'configtype' => 'interface',
|
---|
| 49 | 'dhcp' => 'no',
|
---|
[6508] | 50 | 'compass-direction' => '',
|
---|
[6439] | 51 | );
|
---|
| 52 | foreach $line (split('\n',$config{$if})) {
|
---|
| 53 | ($key, $value) = split(/=/,$line);
|
---|
| 54 | if ($key and (lc($key) =~ /^[a-z].*/)) {
|
---|
| 55 | #print "$key : $value\n";
|
---|
[6463] | 56 | $value = lc($value);
|
---|
| 57 | if ($key =~ /^type$/i) {
|
---|
| 58 | if ($value eq 'ethernet') {
|
---|
| 59 | $value = 'eth';
|
---|
| 60 | } else {
|
---|
| 61 | $value = '11b';
|
---|
| 62 | }
|
---|
| 63 | } elsif ($key =~ /^mode$/i) {
|
---|
| 64 | if ($value eq 'master') {
|
---|
| 65 | $value = 'ms';
|
---|
| 66 | } else { # managed
|
---|
| 67 | $value = 'mn';
|
---|
| 68 | }
|
---|
[6474] | 69 | } elsif ($key =~ /^polar$/i) {
|
---|
| 70 | if ($value eq 'hor') {
|
---|
| 71 | $value = 'hr';
|
---|
| 72 | } else {
|
---|
| 73 | $value = 'vr';
|
---|
| 74 | }
|
---|
| 75 | } elsif ($key =~ /^essid$/i) {
|
---|
| 76 | $key = 'ssid';
|
---|
[6508] | 77 |
|
---|
| 78 | # Dirty hack to fetch compass direction of essid
|
---|
| 79 | $value =~ /[a-z]+-([a-z]+)\..*/;
|
---|
| 80 | $direction = $1;
|
---|
| 81 | # Translate into English
|
---|
| 82 | if ($direction ne "omni") {
|
---|
| 83 | $direction =~ tr/oz/es/;
|
---|
| 84 | }
|
---|
[6541] | 85 | # node AMwtrt1 and 'test' directions
|
---|
| 86 | if ($direction eq "wtrtr" or $direction eq "test") {
|
---|
| 87 | $direction = '';
|
---|
| 88 | }
|
---|
[6508] | 89 | $tmp{'compass-direction'} = $direction;
|
---|
[6474] | 90 | } elsif ($key =~ /^gain$/i) {
|
---|
| 91 | $value =~ s/dbi//;
|
---|
[6463] | 92 | }
|
---|
| 93 | $tmp{lc($key)} = $value;
|
---|
[6439] | 94 | }
|
---|
| 95 | }
|
---|
[6564] | 96 | # ethernet2wifi bridges
|
---|
| 97 | if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
|
---|
| 98 | $tmp{type} = '11b';
|
---|
| 99 | }
|
---|
[6541] | 100 | # 11a
|
---|
[6535] | 101 | if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
|
---|
| 102 | $tmp{type} = '11a';
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[6439] | 105 | foreach $key (keys %tmp) {
|
---|
[6535] | 106 | print "$key=$tmp{$key}\n";
|
---|
[6439] | 107 | }
|
---|
| 108 | print "\n";
|
---|
| 109 | }
|
---|