From 87b4ea9f3e42b72743cf9d3c09a2c0f87bad32a8 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 4 May 2024 00:38:59 -0700 Subject: [PATCH] Add HTML to vps.acmcsuf.com --- servers/cs306/configuration.nix | 2 +- servers/cs306/user-vms.nix | 63 --------------------- servers/cs306/user-vms/default.nix | 89 ++++++++++++++++++++++++++++++ servers/cs306/user-vms/vps.html | 59 ++++++++++++++++++++ 4 files changed, 149 insertions(+), 64 deletions(-) delete mode 100644 servers/cs306/user-vms.nix create mode 100644 servers/cs306/user-vms/default.nix create mode 100644 servers/cs306/user-vms/vps.html diff --git a/servers/cs306/configuration.nix b/servers/cs306/configuration.nix index 193a107..647623a 100644 --- a/servers/cs306/configuration.nix +++ b/servers/cs306/configuration.nix @@ -10,9 +10,9 @@ # ./hardware-configuration.nix ./services.nix - ./user-vms.nix ./recovery.nix ./telemetry.nix + ./user-vms ./caddy ]; diff --git a/servers/cs306/user-vms.nix b/servers/cs306/user-vms.nix deleted file mode 100644 index e02acbb..0000000 --- a/servers/cs306/user-vms.nix +++ /dev/null @@ -1,63 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - inherit (import { inherit pkgs; }) - hostOrderToIP - ips; - - findUserIDWithIP = - ip: - lib.findFirst (user: user.ip == ip) null config.acm.user-vms.usersInfo; -in - -{ - imports = [ - - ]; - - acm.user-vms = { - enable = true; - users = builtins.fromJSON (builtins.readFile ); - # Pin all CPU usages to the 4 host cores. - cpuPinning = [4 5 6 7]; - poolDirectory = "/var/lib/acm-vm"; - }; - - services.diamondburned.caddy.sites."http://vps.acmcsuf.com" = '' - root * ${pkgs.writeTextDir "vps.json" (builtins.toJSON config.acm.user-vms.usersInfo)} - rewrite * /vps.json - header Cache-Control "must-revalidate" - file_server - ''; - - services.sshwifty = { - enable = true; - config = { - Servers = [ - { - ListenInterface = "127.0.0.1"; - ListenPort = 38274; - } - ]; - Presets = map - (order: - let - ip = hostOrderToIP order; - user = findUserIDWithIP ip; - in - { - Title = - if user != null then "${user.id} (${ip})" else "${ip}"; - Type = "SSH"; - Host = "${ip}:22"; - } - ) - (ips.range); - OnlyAllowPresetRemotes = true; - }; - }; - - services.diamondburned.caddy.sites."http://ssh.acmcsuf.com" = '' - reverse_proxy * localhost:38274 - ''; -} diff --git a/servers/cs306/user-vms/default.nix b/servers/cs306/user-vms/default.nix new file mode 100644 index 0000000..62d8f56 --- /dev/null +++ b/servers/cs306/user-vms/default.nix @@ -0,0 +1,89 @@ +{ config, lib, pkgs, ... }: + +let + inherit (import { inherit pkgs; }) + hostOrderToIP + ips; + + findUserIDWithIP = + ip: + lib.findFirst (user: user.ip == ip) null config.acm.user-vms.usersInfo; + + vpsFiles = pkgs.runCommand "www-vps.acmcsuf.com" { + nativeBuildInputs = with pkgs; [ + gomplate + ]; + } '' + mkdir $out + + gomplate \ + --file ${./vps.html} \ + --out $out/index.html \ + --datasource users=file://${pkgs.writeFile "users.json" (builtins.toString config.acm.user-vms.users)} \ + --datasource usersInfo=file://${pkgs.writeFile "usersInfo.json" (builtins.toString config.acm.user-vms.usersInfo)} + ''; +in + +{ + imports = [ + + ]; + + acm.user-vms = { + enable = true; + users = builtins.fromJSON (builtins.readFile ); + # Pin all CPU usages to the 4 host cores. + cpuPinning = [4 5 6 7]; + poolDirectory = "/var/lib/acm-vm"; + }; + + services.sshwifty = { + enable = true; + config = { + Servers = [ + { + ListenInterface = "127.0.0.1"; + ListenPort = 38274; + } + ]; + Presets = map + (order: + let + ip = hostOrderToIP order; + user = findUserIDWithIP ip; + in + { + Title = + if user != null then "${user.id} (${ip})" else "${ip}"; + Type = "SSH"; + Host = "${ip}:22"; + } + ) + (ips.range); + OnlyAllowPresetRemotes = true; + }; + }; + + services.diamondburned.caddy.sites = + { + "http://ssh.acmcsuf.com" = '' + reverse_proxy * localhost:38274 + ''; + "http://vps.acmcsuf.com" = '' + header Cache-Control "must-revalidate" + handle /vps.json { + root * ${pkgs.writeTextDir "vps.json" (builtins.toJSON config.acm.user-vms.usersInfo)} + file_server + } + handle { + root * ${vpsFiles} + file_server + } + ''; + } // (builtins.listToAttrs (map (user: { + name = ["http://${user.id}.vps.acmcsuf.com"]; + value = '' + reverse_proxy * http://${user.ip}:80 + ''; + }) config.acm.user-vms.usersInfo)); +} diff --git a/servers/cs306/user-vms/vps.html b/servers/cs306/user-vms/vps.html new file mode 100644 index 0000000..7327979 --- /dev/null +++ b/servers/cs306/user-vms/vps.html @@ -0,0 +1,59 @@ + + + + + +vps.acmcsuf.com + +
+

vps.acmcsuf.com

+

Virtual private servers (VPS) provided to members of ACM at CSUF.

+
+ +
+

SSH Usage

+

+ To work around the school's networking policies, SSH access must be done via + ssh.acmcsuf.com. Simply wait for the + page to load, then click on the + button and find your username + on the list. +

+
+ +
+

Users

+
    + {{ range $i := until (len .users) }} +
  1. + {{ $user := index .users $i }} + {{ $info := index .usersInfo $i }} + {{ $user.id }} + ({{ $user.name }}) + +
  2. + {{ end }} +
+
+ +
+

Extras

+ +
+ +