Skip to content

Instantly share code, notes, and snippets.

@jplitza
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jplitza/9176916 to your computer and use it in GitHub Desktop.
Save jplitza/9176916 to your computer and use it in GitHub Desktop.
fastd add key script
<?php
require("write_key.inc.php");
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<title>Mesh-VPN-Schlüssel eintragen</title>
<style type="text/css">
.jumbotron h1:first-child {
margin-top: 0;
}
body {
padding-top: 20px;
}
</style>
</head>
<body class="container">
<div class="jumbotron">
<?php
if ( empty($_GET['key'])
|| empty($_GET['name'])
|| !write_key($_GET['name'], $_GET['key'], $_GET['mac'])) {
?>
<p class="lead text-danger">Entschuldigung, beim Eintragen deines Mesh-VPN-Schlüssels ist
leider etwas schief gelaufen!</p>
<p>Bitte gehe
<a href="javascript:history.back()">eine Seite zurück</a> und sende den dort
angezeigten Schlüssel zusammen mit der MAC-Adresse, die unten auf deinem Gerät
steht, an
<a href="mailto:liste@bremen.freifunk.net">liste@bremen.freifunk.net</a>.
Danke!</p>
<?php
} else {
?>
<p class="lead text-success">Vielen Dank, dein Mesh-VPN-Schlüssel wurde erfolgreich
eingetragen.</p>
<p>Dein
Router kann sich jetzt mit unseren Servern verbinden und ist somit auch
verbunden, wenn gerade kein anderer Freifunk-Router in der Nähe ist.</p>
<p>Willkommen beim <a href="http://bremen.freifunk.net/">Freifunk Bremen</a>!</p>
<?php
}
?>
</div>
</body>
</html>
<?php
define('PEERS_PATH', '/etc/fastd/ffhb/peers');
function write_key($name, $key, $mac = NULL) {
if (!preg_match('/^[0-9a-f]{64}$/', $key)) {
return false;
}
if (!$mac)
$mac = $name;
$fd = fopen(PEERS_PATH . "/" . $mac . ".conf", "w");
if ($fd) {
fwrite($fd, "#name \"" . $name . "\";\n");
fwrite($fd, "key \"" . $key . "\";\n");
fwrite($fd, "float yes;\n");
fclose($fd);
// reload config
exec("sudo /usr/local/bin/reload-fastd.sh ffhb");
} else {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment