From 1e4a5aa09c1c8f43722c9c260f011398799a8e8f Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Wed, 6 Mar 2024 06:29:24 -0800 Subject: rename `tools` to `packages` to follow convention The convention is to use `pkgs` or `packages` for overlays and definition of custom packages. Since I'm already using `pkg` for go, I prefer to use `packages` for my scripts. --- tools/dnsmasq-leases-html/README.md | 37 --------------- tools/dnsmasq-leases-html/default.nix | 36 -------------- tools/dnsmasq-leases-html/dnsmasq-leases-html.py | 37 --------------- tools/dnsmasq-leases-html/templates/index.html | 60 ------------------------ 4 files changed, 170 deletions(-) delete mode 100644 tools/dnsmasq-leases-html/README.md delete mode 100644 tools/dnsmasq-leases-html/default.nix delete mode 100755 tools/dnsmasq-leases-html/dnsmasq-leases-html.py delete mode 100644 tools/dnsmasq-leases-html/templates/index.html (limited to 'tools/dnsmasq-leases-html') diff --git a/tools/dnsmasq-leases-html/README.md b/tools/dnsmasq-leases-html/README.md deleted file mode 100644 index 2437deb..0000000 --- a/tools/dnsmasq-leases-html/README.md +++ /dev/null @@ -1,37 +0,0 @@ -Generates a static HTML page with a list of all the leases allocated by `dnsmasq`. - -A simple template written in the jinja syntax is used. - -The file containing the leases is expected to be at `/var/lib/dnsmasq/dnsmasq.leases`, but this can be overwritten by setting the environment variable `DNSMASQ_LEASES`. - -The output of the script is written to `/var/lib/dnsmasq/leases.html` by default, but the destination can be overwritten by setting the environment variable `DNSMASQ_LEASES_OUT`. - -The script can be executed automatically by `dnsmasq` if the configuration for `dhcp-script` is set to the path of the script. This will only be executed when a *new* lease is created or an *old* lease is deleted. To execute the script when a lease is *updated* you need to use the configuration `script-on-renewal`. - -A configuration looks like this: - -``` ini -dhcp-script=${pkgs.tools.dnsmasq-to-html}/bin/dnsmasq-leases-html -script-on-renewal -``` - -## nginx -To serve the page with nginx, you can use the following configuration: - -``` nix -services.nginx = { - enable = true; - virtualHosts."dnsmasq" = { - listen = [ - { - addr = "192.168.6.1"; - port = 8067; - } - ]; - locations."/" = { - root = "/var/lib/dnsmasq"; - index = "leases.html"; - }; - }; -}; -``` diff --git a/tools/dnsmasq-leases-html/default.nix b/tools/dnsmasq-leases-html/default.nix deleted file mode 100644 index 478c4cc..0000000 --- a/tools/dnsmasq-leases-html/default.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ lib, stdenvNoCC, pkgs }: - -stdenvNoCC.mkDerivation rec { - pname = "dnsmasq-leases-html"; - src = ./dnsmasq-leases-html.py; - templates = ./templates; - version = "0.1.0"; - - buildInputs = [ - (pkgs.python310.withPackages (ps: with ps; [ - jinja2 - ])) - ]; - - propagatedBuildInputs = [ - (pkgs.python310.withPackages (ps: with ps; [ - jinja2 - ])) - ]; - - dontUnpack = true; - dontBuild = true; - - installPhase = '' - mkdir -p $out/bin - cp $src $out/bin/${pname} - cp -r $templates $out/bin/templates - ''; - - meta = with pkgs.lib; { - description = "CLI to generate a HTML page with dnsmasq leases."; - license = licenses.mit; - platforms = platforms.unix; - maintainers = [ ]; - }; -} diff --git a/tools/dnsmasq-leases-html/dnsmasq-leases-html.py b/tools/dnsmasq-leases-html/dnsmasq-leases-html.py deleted file mode 100755 index c1f03db..0000000 --- a/tools/dnsmasq-leases-html/dnsmasq-leases-html.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 - -import datetime -import ipaddress -import os - -from jinja2 import Environment, FileSystemLoader - - -outfile = os.getenv("DNSMASQ_LEASES_OUT", "/var/lib/dnsmasq/leases.html") -leases_file = os.getenv("DNSMASQ_LEASES", "/var/lib/dnsmasq/dnsmasq.leases") - -leases = [] - -with open(leases_file, "r") as f: - for line in f: - content = line.rstrip("\n").split(" ") - lease = dict() - if int(content[0]) == 0: - lease["expire"] = "never" - else: - lease["expire"] = datetime.datetime.fromtimestamp(int(content[0])) - lease["MAC"] = content[1] - lease["IP"] = ipaddress.ip_address(content[2]) - lease["hostname"] = content[3] - leases.append(lease) - -leases = sorted(leases, key=lambda d: d["IP"]) - -dir_path = os.path.dirname(os.path.realpath(__file__)) -templates_dir = os.path.join(dir_path, "templates") -environment = Environment(loader=FileSystemLoader(templates_dir)) -template = environment.get_template("index.html") - -content = template.render(leases=leases) -with open(outfile, "w") as fh: - print(content, file=fh) diff --git a/tools/dnsmasq-leases-html/templates/index.html b/tools/dnsmasq-leases-html/templates/index.html deleted file mode 100644 index 913a0c9..0000000 --- a/tools/dnsmasq-leases-html/templates/index.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - Leases assigned by dnsmasq - - - - - - - - - - - - {% for lease in leases %} - - - - - - - {% endfor %} -
IP addressMAC addressHostnameExpire
{{ lease.IP }}{{ lease.MAC }}{{ lease.hostname }}{{ lease.expire }}
- - -- cgit 1.4.1