| 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 |
|
|---|
| 11 | #
|
|---|
| 12 | # Usage: for file in */wleiden.conf; do ./genesis-to-py.pl $file; done > py.conf
|
|---|
| 13 | do($ARGV[0]) || die;
|
|---|
| 14 |
|
|---|
| 15 | my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
|
|---|
| 16 |
|
|---|
| 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 |
|
|---|
| 24 | $status = $status_labels{$status} || 'up'; # ensure reporting a correct status
|
|---|
| 25 |
|
|---|
| 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
|
|---|
| 35 | masterip = $master_ip
|
|---|
| 36 | nodetype = $nodetype
|
|---|
| 37 | name = $nodename
|
|---|
| 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',
|
|---|
| 50 | );
|
|---|
| 51 | foreach $line (split('\n',$config{$if})) {
|
|---|
| 52 | ($key, $value) = split(/=/,$line);
|
|---|
| 53 | if ($key and (lc($key) =~ /^[a-z].*/)) {
|
|---|
| 54 | #print "$key : $value\n";
|
|---|
| 55 | $value = lc($value);
|
|---|
| 56 | if ($key =~ /^type$/i) {
|
|---|
| 57 | if ($value eq 'ethernet') {
|
|---|
| 58 | $value = 'eth';
|
|---|
| 59 | } else {
|
|---|
| 60 | $value = '11b';
|
|---|
| 61 | }
|
|---|
| 62 | } elsif ($key =~ /^mode$/i) {
|
|---|
| 63 | if ($value eq 'master') {
|
|---|
| 64 | $value = 'ms';
|
|---|
| 65 | } else { # managed
|
|---|
| 66 | $value = 'mn';
|
|---|
| 67 | }
|
|---|
| 68 | } elsif ($key =~ /^polar$/i) {
|
|---|
| 69 | if ($value eq 'hor') {
|
|---|
| 70 | $value = 'hr';
|
|---|
| 71 | } else {
|
|---|
| 72 | $value = 'vr';
|
|---|
| 73 | }
|
|---|
| 74 | } elsif ($key =~ /^essid$/i) {
|
|---|
| 75 | $key = 'ssid';
|
|---|
| 76 | } elsif ($key =~ /^gain$/i) {
|
|---|
| 77 | $value =~ s/dbi//;
|
|---|
| 78 | }
|
|---|
| 79 | $tmp{lc($key)} = $value;
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | foreach $key (keys %tmp) {
|
|---|
| 84 | print "$key=$tmp{$key}\n"
|
|---|
| 85 | }
|
|---|
| 86 | print "\n";
|
|---|
| 87 | }
|
|---|