freifunk: serve sysinfo-json.cgi

This commit is contained in:
Astro 2020-04-16 22:46:37 +02:00
parent f5e258382e
commit 80273f027e
3 changed files with 123 additions and 85 deletions

View File

@ -1,50 +0,0 @@
{
"version": "15",
"timestamp": "1586882346",
"data": {
"firmware": {
"version": "0.0.0",
"DISTRIB_ID": "NixOS",
"DISTRIB_RELEASE": "20.03",
"DISTRIB_REVISION": "",
"DISTRIB_CODENAME": "",
"DISTRIB_TARGET": "x86_64",
"DISTRIB_DESCRIPTION": "NixOS 20.03"
},
"system": {
"uptime": "0 0",
"uname": "Linux 5.3.18",
"nameserver": [
],
"date": "Tue Apr 14 18:39:06 CEST 2020",
"cpuinfo": "Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz",
"cpucount": "40",
"bmxd": "bmxd",
"essid": "ZW public",
"node_type": "router",
"splash": 0,
"email_notification": 0,
"autoupdate": 0,
"available_flash_size": "16T",
"bmxd_restart_counter": 0
},
"common": {
"city": "Dresden",
"node": "51073",
"domain": "freifunk-dresden.de",
"ip": "10.200.200.74",
"network_id": "1206"
},
"gps": {
"latitude": 51.0810624,
"longitude": 13.7285866,
"altitude": 100
},
"contact": {
"name": "C3D2",
"location": "Zentralwerk Haus B Souterrain",
"email": "astro%40spaceboyz.net",
"note": ""
}
}
}

View File

@ -11,6 +11,10 @@ let
ddmeshNode = 51073;
ddmeshAddrPart = "200.74";
rt_table = 7;
bmxd = import (toString <lib/pkgs/bmxd.nix>) { inherit pkgs; };
sysinfo-json = import <this-host/sysinfo-json.nix> {
inherit pkgs bmxd ddmeshNode;
};
in {
imports = [
<nixpkgs/nixos/modules/profiles/minimal.nix>
@ -113,10 +117,7 @@ in {
};
};
};
systemd.services.bmxd =
let
bmxd = import (toString <lib/pkgs/bmxd.nix>) { inherit pkgs; };
in {
systemd.services.bmxd = {
after = [ "systemd-networkd.service" ];
wantedBy = [ "network.target" ];
serviceConfig = {
@ -148,6 +149,17 @@ in {
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "daily";
};
systemd.services.sysinfo-json = {
script = ''
${sysinfo-json}/bin/bmxddump.sh
${sysinfo-json}/bin/sysinfo-json.cgi > /tmp/sysinfo.json
'';
};
systemd.timers.sysinfo-json = {
partOf = [ "sysinfo-json.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "minutely";
};
services.bird2 = {
enable = true;
@ -202,47 +214,53 @@ in {
recommendedOptimisation = true;
recommendedGzipSettings = true;
virtualHosts =
let
aliasFile = path: {
alias = path;
extraConfig = ''
etag off;
add_header etag "\"${builtins.substring 11 32 path}\"";
'';
};
in {
"c3d2.ffdd" = {
default = true;
root = <this-host/assets>;
locations = {
"/".index = "index.html";
"/sysinfo-json.cgi".extraConfig = ''
virtualHosts = {
"c3d2.ffdd" = {
default = true;
root = <this-host/assets>;
locations = {
"/" = {
index = "index.html";
extraConfig = ''
etag off;
add_header etag "\"${builtins.substring 11 32 (<this-host> + "/assets")}\"";
'';
};
"=/sysinfo-json.cgi" = {
alias = "/tmp/sysinfo.json";
extraConfig = ''
add_header Content-Type "application/json;charset=UTF-8";
'';
};
"=/sysinfo.json" = {
alias = "/tmp/sysinfo.json";
extraConfig = ''
add_header Content-Type "application/json;charset=UTF-8";
'';
};
};
"storage.hq.c3d2.ffdd" = {
locations = {
"/".proxyPass = "http://storage.hq.c3d2.de/";
};
};
"storage.hq.c3d2.ffdd" = {
locations = {
"/".proxyPass = "http://storage.hq.c3d2.de/";
};
"grafana.hq.c3d2.ffdd" = {
locations = {
"/" = {
proxyPass = "https://grafana.hq.c3d2.de/";
extraConfig = ''
};
"grafana.hq.c3d2.ffdd" = {
locations = {
"/" = {
proxyPass = "https://grafana.hq.c3d2.de/";
extraConfig = ''
proxy_ssl_server_name on;
'';
};
};
};
"influxdb.hq.c3d2.ffdd" = {
locations = {
"/".proxyPass = "http://grafana.hq.c3d2.de:8086/";
};
};
};
"influxdb.hq.c3d2.ffdd" = {
locations = {
"/".proxyPass = "http://grafana.hq.c3d2.de:8086/";
};
};
};
};
# This value determines the NixOS release with which your system is to be

View File

@ -0,0 +1,70 @@
{ pkgs ? import <nixpkgs> {},
ffdd-server ? builtins.fetchGit "https://github.com/Freifunk-Dresden/ffdd-server.git",
bmxd,
ddmeshNode,
... }:
with pkgs;
let
nvram = {
ddmesh_node = toString ddmeshNode;
city = "Dresden";
autoupdate = "0";
contact_name = "C3D2";
contact_location = "Zentralwerk";
contact_email = "astro@spaceboyz.net";
contact_note = "http://www.c3d2.ffdd/";
gps_latitude = "51.0810624";
gps_longitude = "13.7285866";
gps_altitude = "100";
};
in
stdenv.mkDerivation {
name = "sysinfo-json";
src = "${ffdd-server}/salt/freifunk/base/ddmesh/";
buildPhase = ''
cat > bmxddump.sh <<EOF
#!${bash}/bin/bash
DB_PATH=/var/lib/freifunk/bmxd
mkdir -p \$DB_PATH
${bmxd}/sbin/bmxd -c --gateways > \$DB_PATH/gateways
${bmxd}/sbin/bmxd -c --links > \$DB_PATH/links
${bmxd}/sbin/bmxd -c --originators > \$DB_PATH/originators
${bmxd}/sbin/bmxd -c --status > \$DB_PATH/status
#${bmxd}/sbin/bmxd -c --networks > \$DB_PATH/networks
${bmxd}/sbin/bmxd -ci > \$DB_PATH/info
EOF
cat > lsb_release <<EOF
#!${bash}/bin/bash
${lsb-release}/bin/lsb_release \$@ | \
${gnused}/bin/sed -e 's/"//g'
EOF
substitute usr/local/bin/ddmesh-ipcalc.sh ddmesh-ipcalc.sh \
--replace awk ${gawk}/bin/awk
substitute var/www_freifunk/sysinfo-json.cgi sysinfo-json.cgi \
--replace "echo 'Content-Type: application/json;charset=UTF-8'" "" \
--replace '"node_type":"server"' '"node_type":"node"' \
--replace ddmesh-ipcalc.sh $out/bin/ddmesh-ipcalc.sh \
--replace lsb_release $out/bin/lsb_release \
--replace ${lib.strings.escapeShellArg "$(sudo /sbin/iptables -w -xvn -L stat_from_ovpn | awk '/RETURN/{print $2}')"} 0 \
--replace ${lib.strings.escapeShellArg "$(sudo /sbin/iptables -w -xvn -L stat_to_ovpn | awk '/RETURN/{print $2}')"} 0 \
--replace 'nettype_lookup[$2]' '"lan"' \
--replace awk ${gawk}/bin/awk
'' +
lib.strings.concatStrings (lib.attrsets.mapAttrsToList (
var: value: "substituteInPlace sysinfo-json.cgi --replace ${lib.strings.escapeShellArg "$(nvram get ${var})"} '${value}'\n"
) nvram);
installPhase = ''
pwd
mkdir -p $out/bin
ls -la
install -m 0755 sysinfo-json.cgi $out/bin/
install -m 0755 ddmesh-ipcalc.sh $out/bin/
install -m 0755 bmxddump.sh $out/bin/
install -m 0755 lsb_release $out/bin/
'';
}