summaryrefslogtreecommitdiff
path: root/roles/install_fastd/files/fastd-api.php
diff options
context:
space:
mode:
authorNiklas Yann Wettengel <niyawe@niyawe.de>2017-03-17 22:35:38 +0100
committerNiklas Yann Wettengel <niyawe@niyawe.de>2017-03-17 22:35:38 +0100
commit4b97c64f947662cd4e2c233a51114c1ff3a9815c (patch)
tree07882522000071bfe7ffe7b10e773198bd6b06dd /roles/install_fastd/files/fastd-api.php
parent711f968dda1acca7d6b2a86e28a1535449938941 (diff)
updated setup_fastd playbook
added features: - install_bind - install_dhcp - install_fastd - setup_batman
Diffstat (limited to 'roles/install_fastd/files/fastd-api.php')
-rw-r--r--roles/install_fastd/files/fastd-api.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/roles/install_fastd/files/fastd-api.php b/roles/install_fastd/files/fastd-api.php
new file mode 100644
index 0000000..98da7a7
--- /dev/null
+++ b/roles/install_fastd/files/fastd-api.php
@@ -0,0 +1,45 @@
+#!/usr/bin/php -f
+<?php
+//$url = 'http://register.freifunk-myk.de/srvapi.php';
+$url = 'https://www.freifunk-myk.de/node/keys';
+$out = '/etc/fastd/ffmyk/peers/';
+
+if(!is_dir($out)) die('Output Dir missing');
+if(!is_writable($out)) die('Output Dir perms');
+
+if( ($data = file_get_contents($url)) === FALSE ) die('Error getting keys');
+$data = unserialize($data);
+
+$active=array();
+
+foreach($data as $router) {
+ $router['MAC'] = trim($router['MAC']);
+ $router['PublicKey'] = trim($router['PublicKey']);
+ if(!preg_match('/^[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}$/', $router['MAC'])) {
+ //trigger_error('Router mit falscher MAC?!', E_USER_WARNING);
+ }elseif(!preg_match('/^[A-F0-9]{64}$/', $router['PublicKey'])) {
+ //trigger_error('Router mit falschem Key?!'.$router['MAC'], E_USER_WARNING);
+ }else{
+ $filename='client_'.str_replace(':', '-', $router['MAC']);
+ $fp=fopen($out.$filename, 'w');
+ fwrite($fp, 'key "'.$router['PublicKey'].'";'."\n");
+ fclose($fp);
+ $active[] = $filename;
+ }
+}
+
+//Check if we fscked up
+if(count($active) < 10) die('Less than 10 nodes? Database broken?');
+
+$dh = opendir($out);
+while(($file = readdir($dh)) !== false) {
+ if($file != '.' && $file != '..') {
+ if(!in_array($file, $active) && (strpos($file, 'client_') !== false)) {
+ unlink($out.$file);
+ }
+ }
+}
+
+exec('killall -SIGHUP fastd');
+
+?>