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