rewrite networking modules

This commit is contained in:
Schrottkatze 2025-03-27 20:18:54 +01:00
parent 49298541e5
commit 0bbb0aa204
Signed by: schrottkatze
SSH key fingerprint: SHA256:FPOYVeBy3QP20FEM42uWF1Wa/Qhlk+L3S2+Wuau/Auo
11 changed files with 69 additions and 71 deletions

View file

@ -3,8 +3,8 @@
./shell
./desktop
./hardware
./firewall.nix
./de
./net
./input
./media
./graphics.nix

View file

@ -9,7 +9,6 @@ with lib; {
./gaming.nix
./syncthing.nix
./kdeconnect.nix
./networking.nix
./social.nix
];

View file

@ -1,69 +0,0 @@
{
config,
lib,
pkgs,
...
}: let
addNuShebang = path:
builtins.concatStringsSep "\n\n" [
"#!${pkgs.nushell}/bin/nu"
(builtins.readFile path)
];
in {
config = {
networking = {
networkmanager = {
wifi.backend = "wpa_supplicant";
dispatcherScripts = [
{
type = "basic";
source = pkgs.writeText "dispatcher" (addNuShebang ../../other/scripts/dispatcher.nu);
}
];
};
hosts = {
"127.0.0.1" = [
"www.tiktok.com"
"www.twitter.com"
"www.instagram.com"
"www.facebook.com"
"www.snapchat.com"
"tiktok.com"
"twitter.com"
"instagram.com"
"facebook.com"
"snapchat.com"
"google-analytics.com"
"stats.g.doubleclick.net"
"googleadservices.com"
"googletagmanager.com"
"googletagservices.com"
"googlesyndication.com"
];
};
};
environment.etc = with builtins; (
listToAttrs (
map (v: {
name = "networkhooks/${v}";
value = {
text = addNuShebang ../../other/scripts/networkhooks/${v};
mode = "0755";
};
})
(attrNames (readDir ../../other/scripts/networkhooks))
)
);
systemd.services."NetworkManager-wait-online".enable = false;
services.mullvad-vpn.enable = true;
home-manager.users.jade = {pkgs, ...}: {
home.packages = with pkgs; [
networkmanagerapplet
mullvad-vpn
macchanger
];
};
};
}

17
modules/net/default.nix Normal file
View file

@ -0,0 +1,17 @@
{...}: {
imports = [
./firewall.nix
./hosts.nix
./dispatchers
];
networking.networkmanager.wifi.backend = "wpa_supplicant";
systemd.services."NetworkManager-wait-online".enable = false;
services.mullvad-vpn.enable = true;
home-manager.users.jade = {pkgs, ...}: {
home.packages = with pkgs; [
networkmanagerapplet
mullvad-vpn
macchanger
];
};
}

View file

@ -0,0 +1,27 @@
{pkgs, ...}: let
addNuShebang = path:
builtins.concatStringsSep "\n\n" [
"#!${pkgs.nushell}/bin/nu"
(builtins.readFile path)
];
in {
networking.networkmanager.dispatcherScripts = [
{
type = "basic";
source = pkgs.writeText "dispatcher" (addNuShebang ./dispatcher.nu);
}
];
environment.etc = with builtins; (
listToAttrs (
map (v: {
name = "networkhooks/${v}";
value = {
text = addNuShebang ./hooks/${v};
mode = "0755";
};
})
(attrNames (readDir ./hooks))
)
);
}

View file

@ -0,0 +1,21 @@
def main [
interface: string
type: string
] {
$env.PATH = ($env.PATH | split row (char esep) | append '/run/current-system/sw/bin');
let currentnet = (
nmcli -m tabular connection show --active
| from ssv
| first
| get name
);
systemd-cat echo $"($currentnet) \(($interface)): ($type)";
if $interface starts-with 'wlp' {
let p = $"/etc/networkhooks/($currentnet).nu";
systemd-cat echo $p;
^$p $interface $type
}
}

View file

@ -0,0 +1,40 @@
def main [
interface: string
type: string
] {
if not ($type == 'up') {
exit
};
mullvad disconnect;
let page = http get 'http://172.0.0.1/';
let hotspot_ip = $page | htmlq 'input[name=uamip]' -a 'value';
let hotspot_port = $page | htmlq 'input[name=uamport]' -a 'value';
let pl_data = $page
| htmlq input -a name -r input[name=button]
| lines
| wrap name
| merge (
$page
| htmlq input -a value
| lines
| wrap value
)
| drop 1;
let payload = $pl_data
| each {|kv| [
($kv.name | url encode --all)
($kv.value | url encode --all) ]
| str join '='
} | str join '&';
let res = curl --insecure --resolve $"www.hotsplots.de:($hotspot_port):($hotspot_ip)" -H 'Content-Type: application/x-www-form-urlencoded' "https://www.hotsplots.de/auth/login.php" --data-raw $"($payload)" ;
let url = $res | htmlq 'meta[http-equiv=refresh]' -a 'content' | parse '0;url={url}';
http get $url.url.0;
mullvad connect;
}

View file

@ -0,0 +1,22 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p curl htmlq
# echo "Fetching cookie and CSRF token..."
# form=$(curl --silent --location --junk-session-cookies --cookie-jar /tmp/wifionice "https://login.wifionice.de/en/" --resolve login.wifionice.de:443:10.101.64.10 -i | htmlq "input")
# keys=$(htmlq "input" --attribute "name" <<< "$form")
# values=$(htmlq "input" --attribute "value" <<< "$form")
# payload=$(paste --delimiters="=" <(echo "$keys") <(echo "$values") | tr "\n" "&")
# echo "Payload: \"$payload\""
# echo "POSTing payload..."
# curl --cookie /tmp/wifionice "https://login.wifionice.de/en/" --resolve login.wifionice.de:443:10.101.64.10 -d "$payload"
def main [
interface: string
type: string
] {
let form = curl --silent --location --junk-session-cookies --cookie-jar /tmp/wifionice 'https://login.wifionice.de/en/' --resolve 'login.wifionice.de:443:10.101.64.10' -i | htmlq 'input';
# TODO
}

View file

@ -0,0 +1,40 @@
const wave_timeout = 15min;
def main [
interface: string
type: string
] {
if not ('/var/lib/ccchh-winken/last' | path exists) {
mkdir '/var/lib/ccchh-winken';
0 | into datetime | save '/var/lib/ccchh-winken/last' -f;
}
let $last_waved = open '/var/lib/ccchh-winken/last' --raw | into datetime;
if ((date now) - $last_waved) > $wave_timeout {
if $type == "up" {
mullvad disconnect;
curl mqtt://mqtt.z9/winkekatze/katz9/eye/set -d (rand-color);
curl mqtt://mqtt.z9/winkekatze/Viktoria/eye/set -d (rand-color);
curl mqtt://mqtt.z9/winkekatze/allcats -d 'wink';
date now | save '/var/lib/ccchh-winken/last' -f;
}
}
}
def rand-color [] {
const colors = [
"blue"
"cyan"
"green"
"pink"
"red"
"white"
"yellow"
];
$colors | get (random int 0..(($colors | length) - 1))
}

24
modules/net/hosts.nix Normal file
View file

@ -0,0 +1,24 @@
{...}: {
networking.hosts = {
"127.0.0.1" = [
"www.tiktok.com"
"www.twitter.com"
"www.instagram.com"
"www.facebook.com"
"www.snapchat.com"
"tiktok.com"
"twitter.com"
"instagram.com"
"facebook.com"
"snapchat.com"
"google-analytics.com"
"stats.g.doubleclick.net"
"googleadservices.com"
"googletagmanager.com"
"googletagservices.com"
"googlesyndication.com"
];
};
}