[8266] | 1 | #!/usr/bin/env perl
|
---|
[8621] | 2 | use File::Basename;
|
---|
[8266] | 3 |
|
---|
| 4 | eval {
|
---|
| 5 | require Geo::Coordinates::RDNAP;
|
---|
| 6 | };
|
---|
| 7 | if (! $@) {
|
---|
| 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) {
|
---|
[8294] | 28 | $output = $file;
|
---|
| 29 | $output =~ s/conf$/yaml/;
|
---|
[8342] | 30 | print "# Processing $file\n";
|
---|
[8621] | 31 | $CMD=dirname(__FILE__) . "/genesis-to-yaml.pl";
|
---|
| 32 | `$CMD $file > $output`;
|
---|
[8266] | 33 | }
|
---|
| 34 | exit 0;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | do($ARGV[0]) || die;
|
---|
| 39 |
|
---|
| 40 | my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
|
---|
| 41 |
|
---|
| 42 | $interfaces = [];
|
---|
| 43 | foreach $if (keys %config) {
|
---|
| 44 | push(@interfaces, $if) if ($if =~ m/^[a-z0-9]+$/g);
|
---|
| 45 | }
|
---|
| 46 | $interfaces = join(",",@interfaces);
|
---|
| 47 |
|
---|
| 48 | if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
|
---|
| 49 | ($lat, $lon, $h) = from_rd( $X, $Y, 0);
|
---|
| 50 | } else {
|
---|
| 51 | $lat = $lon = $h = 0;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | $status = $status_labels{$status} || 'up'; # ensure reporting a correct status
|
---|
| 55 | $comment = $comment || 'None';
|
---|
| 56 |
|
---|
| 57 | print <<EOF;
|
---|
| 58 | # Genesis config yaml style
|
---|
| 59 | # vim:ts=2:et:sw=2:ai
|
---|
| 60 | #
|
---|
| 61 | comment : $comment
|
---|
| 62 | interfaces: $interfaces
|
---|
| 63 | latitude : $lat
|
---|
| 64 | location : $location
|
---|
| 65 | longitude : $lon
|
---|
| 66 | masterip : $master_ip
|
---|
[8644] | 67 | release : $release
|
---|
[8266] | 68 | nodename : $nodename
|
---|
| 69 | nodetype : $nodetype
|
---|
| 70 | rdnap_x : $X
|
---|
| 71 | rdnap_y : $Y
|
---|
| 72 | status : $status
|
---|
| 73 | EOF
|
---|
| 74 |
|
---|
[8644] | 75 | if ($ileiden =~ /yes/) {
|
---|
| 76 | print "ileiden : yes\n";
|
---|
| 77 | } else {
|
---|
| 78 | print "ileiden : no\n";
|
---|
| 79 | }
|
---|
[8266] | 80 |
|
---|
| 81 | foreach $if (keys %config) {
|
---|
| 82 | ($iflabel, $alias) = split(':',$if);
|
---|
[8270] | 83 | $iflabel .= "_alias${alias}" if ($alias =~ m/[0-9]/);
|
---|
[8266] | 84 |
|
---|
| 85 | print <<EOF;
|
---|
| 86 | iface_$iflabel:
|
---|
| 87 | EOF
|
---|
| 88 | %tmp = (
|
---|
| 89 | 'dhcp' => 'False',
|
---|
[8273] | 90 | 'compass' => 'None',
|
---|
[8266] | 91 | 'interface' => $if,
|
---|
| 92 | );
|
---|
| 93 | foreach $line (split('\n',$config{$if})) {
|
---|
| 94 | ($key, $value) = split(/=/,$line);
|
---|
[8300] | 95 | # Remove trailing and leading white spaces
|
---|
| 96 | $value =~ s/^\s+//;
|
---|
| 97 | $value =~ s/\s+$//;
|
---|
[8266] | 98 | if ($key and (lc($key) =~ /^[a-z].*/)) {
|
---|
| 99 | #print "$key : $value\n";
|
---|
| 100 | $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
|
---|
| 101 | if ($key =~ /^type$/i) {
|
---|
| 102 | if ($value eq 'ethernet') {
|
---|
| 103 | $value = 'eth';
|
---|
| 104 | } else {
|
---|
| 105 | $value = '11b';
|
---|
| 106 | }
|
---|
[8644] | 107 | } elsif ($key =~ /^status$/i) {
|
---|
| 108 | if ($value eq 'up') {
|
---|
| 109 | $value = 'up';
|
---|
| 110 | } else {
|
---|
| 111 | $value = 'down';
|
---|
| 112 | }
|
---|
[8266] | 113 | } elsif ($key =~ /^mode$/i) {
|
---|
| 114 | if ($value eq 'master') {
|
---|
[8273] | 115 | $value = 'ap-wds';
|
---|
[8266] | 116 | } else { # managed
|
---|
[8273] | 117 | $value = 'station-wds';
|
---|
[8266] | 118 | }
|
---|
| 119 | } elsif ($key =~ /^polar$/i) {
|
---|
| 120 | if ($value eq 'hor') {
|
---|
| 121 | $value = 'hr';
|
---|
| 122 | } else {
|
---|
| 123 | $value = 'vr';
|
---|
| 124 | }
|
---|
| 125 | } elsif ($key =~ /^essid$/i) {
|
---|
| 126 | $key = 'ssid';
|
---|
| 127 |
|
---|
| 128 | # Dirty hack to fetch compass direction of essid
|
---|
| 129 | $value =~ /[a-z]+-([a-z]+)\..*/;
|
---|
| 130 | $direction = $1;
|
---|
| 131 | # Translate into English
|
---|
| 132 | if ($direction ne "omni") {
|
---|
| 133 | $direction =~ tr/oz/es/;
|
---|
| 134 | }
|
---|
| 135 | # node AMwtrt1 and 'test' directions
|
---|
| 136 | if ($direction eq "wtrtr" or $direction eq "test") {
|
---|
| 137 | $direction = 'None';
|
---|
| 138 | }
|
---|
[8586] | 139 | if ($direction) {
|
---|
| 140 | $tmp{'compass'} = $direction;
|
---|
| 141 | } else {
|
---|
| 142 | $tmp{'compass'} = 'None';
|
---|
| 143 | }
|
---|
[8266] | 144 | } elsif ($key =~ /^gain$/i) {
|
---|
| 145 | $value =~ s/dbi//;
|
---|
| 146 | }
|
---|
[8644] | 147 | # Als key niet bestaat, Dan key toevoegen
|
---|
[8266] | 148 | $tmp{lc($key)} = $value;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
[8644] | 151 | # Status
|
---|
| 152 | if ( ! $tmp{status} ) {
|
---|
| 153 | $tmp{status} = 'up';
|
---|
| 154 | }
|
---|
[8266] | 155 | # ethernet2wifi bridges
|
---|
| 156 | if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
|
---|
[8273] | 157 | $tmp{type} = 'eth';
|
---|
[8266] | 158 | }
|
---|
| 159 | # 11a
|
---|
| 160 | if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
|
---|
| 161 | $tmp{type} = '11a';
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | foreach $key (sort keys %tmp) {
|
---|
[8270] | 165 | printf " %-11s: '$tmp{$key}'\n", $key;
|
---|
[8266] | 166 | }
|
---|
| 167 | print "\n";
|
---|
| 168 | }
|
---|
| 169 |
|
---|