source: genesis/tools/genesis-to-yaml.pl@ 14354

Last change on this file since 14354 was 10109, checked in by rick, 13 years ago

Included two keys which are missing sometimes.

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