Freifunk

Meshviewer Konfiguration

"Unprivileged" user for ffmap-backend

sudo useradd -m -U -s /bin/zsh --system -G alfred map
sudo echo 'map ALL = NOPASSWD: /usr/sbin/batctl' | sudo tee /etc/sudoers.d/map

ffmap-backend

sudo apt-get install python3-networkx
sudo -u map -i
git clone https://github.com/ffnord/ffmap-backend.git

/etc/systemd/system/ffmap-backend@.service

[Unit]
Description=gathers information from the batman network (connection %I)
Requires=alfred@%i.service

[Service]
Type=oneshot
User=map
ExecStart=/home/map/ffmap-backend/backend.py -m %i-bat -d /home/map/data-%i/

/etc/systemd/system/ffmap-backend@ffmr.timer

[Unit]
Description=gathers information from the batman network (connection %I)
Requires=alfred@%i.service

[Timer]
OnBootSec=0
OnUnitActiveSec=60
Persistent=false

[Install]
WantedBy=timers.target
sudo systemctl enable ffmap-backend@ffmr.timer
sudo systemctl start ffmap-backend@ffmr.timer

/etc/nginx/sites-enabled/api_marburg_freifunk_net.conf

server {
        listen 443 ssl spdy;
        listen [::]:443 ssl spdy;

        ssl_certificate_key /etc/letsencrypt/live/map.marburg.freifunk.net/privkey.pem;
        ssl_certificate /etc/letsencrypt/live/map.marburg.freifunk.net/fullchain.pem;

        server_name api.marburg.freifunk.net;

        root /home/map/data-ffmr;

        autoindex on;
        charset utf-8;

        expires -1;
        add_header Access-Control-Allow-Origin "*";
}

Freifunk API

/home/map/update-freifunk-api-nodecount.py

#!/usr/bin/env python3

import sys
import os.path
import json
from collections import OrderedDict
from datetime import datetime

def get_nodelist_count(nodelist_location: str) -> int:
    with open(nodelist_location, 'r') as nodelist:
        nodes = [
            node['id'] for node
            in json.load(nodelist)['nodes']
            if node['status']['online']
        ]
        return len(nodes)

def get_freifunk_api(ffapi_location: str) -> OrderedDict:
    with open(ffapi_location, 'r') as ffapi:
        return json.load(ffapi, object_pairs_hook=OrderedDict)

def update_freifunk_api(ffapi_location: str, nodelist_location: str):
    ffapi_data = get_freifunk_api(ffapi_location)
    ffapi_data['state']['nodes'] = get_nodelist_count(nodelist_location)
    ffapi_data['state']['lastchange'] = datetime.utcnow().isoformat()

    with open(ffapi_location, 'w') as ffapi:
        json.dump(ffapi_data, ffapi, indent=2)


update_freifunk_api(
    os.path.join(sys.argv[1], 'freifunk-marburg.json'),  # first argument is basepath
    os.path.join(sys.argv[1], 'nodelist.json')
)

/etc/systemd/system/update-freifunk-api-nodecount@.service

[Unit]
Description=updates freifunk api node count (community %I)
Wants=multi-user.target

[Service]
Type=oneshot
User=map
ExecStart=/home/map/update-freifunk-api-nodecount.py /home/map/data-%i/

/etc/systemd/system/update-freifunk-api-nodecount@ffmr.timer

[Unit]
Description=updates freifunk api node count (community %I)
Wants=multi-user.target

[Timer]
OnCalendar=hourly
Persistent=false

[Install]
WantedBy=timers.target
sudo chmod +x /home/map/update-freifunk-api-nodecount.py
sudo systemctl enable update-freifunk-api-nodecount@ffmr.timer
sudo systemctl start update-freifunk-api-nodecount@ffmr.timer

Meshviewer

sudo apt-get install npm ruby-sass
sudo -u map -i
git clone https://github.com/hackspace-marburg/ffmr-meshviewer.git meshviewer
cd meshviewer
npm install
npm install bower grunt-cli
nodejs node_modules/.bin/bower install
ln -s config.js.ffmr.js config.js
nodejs node_modules/.bin/grunt

/etc/nginx/sites-enabled/map_marburg_freifunk_net.conf

server {
        listen 443 ssl spdy;
        listen [::]:443 ssl spdy;

        ssl_certificate_key /etc/letsencrypt/live/map.marburg.freifunk.net/privkey.pem;
        ssl_certificate /etc/letsencrypt/live/map.marburg.freifunk.net/fullchain.pem;

        server_name map.marburg.freifunk.net;

        root /home/map/meshviewer/build;

        autoindex off;
        charset utf-8;

        location ~* \.(js|css|svg|png|woff|woff2|ttf|eot) {
                expires 1M;
        }
}