Skip to content

Commit

Permalink
Add HTML to vps.acmcsuf.com
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed May 4, 2024
1 parent b1a6360 commit 87b4ea9
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 64 deletions.
2 changes: 1 addition & 1 deletion servers/cs306/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# <acm-aws/containers/cs306/test.nix>
./hardware-configuration.nix
./services.nix
./user-vms.nix
./recovery.nix
./telemetry.nix
./user-vms
./caddy
];

Expand Down
63 changes: 0 additions & 63 deletions servers/cs306/user-vms.nix

This file was deleted.

89 changes: 89 additions & 0 deletions servers/cs306/user-vms/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{ config, lib, pkgs, ... }:

let
inherit (import <acm-aws/user-machines/vm/config.nix> { 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-aws/user-machines/vm>
];

acm.user-vms = {
enable = true;
users = builtins.fromJSON (builtins.readFile <acm-aws/user-machines/secrets/user-vms.json>);
# 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));
}
59 changes: 59 additions & 0 deletions servers/cs306/user-vms/vps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="https://acmcsuf.com/favicon.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" />
<title>vps.acmcsuf.com</title>

<hgroup>
<h1>vps.acmcsuf.com</h1>
<p>Virtual private servers (VPS) provided to members of <a href="https://acmcsuf.com">ACM at CSUF</a>.</p>
</hgroup>

<section>
<h2>SSH Usage</h2>
<p>
To work around the school's networking policies, SSH access must be done via
<a href="https://ssh.acmcsuf.com">ssh.acmcsuf.com</a>. Simply wait for the
page to load, then click on the <kbd>+</kbd> button and find your username
on the list.
</p>
</section>

<section>
<h2>Users</h2>
<ol class="users-list">
{{ range $i := until (len .users) }}
<li>
{{ $user := index .users $i }}
{{ $info := index .usersInfo $i }}
<b class="user-id">{{ $user.id }}</b>
<span>(<span class="user-name">{{ $user.name }}</span>)</span>
<ul class="users-info-list">
<li>
<b>URL:</b>
<a href="https://{{ $user.id }}.vps.acmcsuf.com">{{ $user.id }}.vps.acmcsuf.com</a>
</li>
<li>
<b>SSH:</b>
Check <a href="https://ssh.acmcsuf.com">ssh.acmcsuf.com</a> for your username.
</li>
</ul>
</li>
{{ end }}
</ol>
</section>

<section>
<h2>Extras</h2>
<ul>
<li><a href="/vps.json">JSON IP list</a></li>
</ul>
</section>

<footer>
<p>
<span><a href="https://acmcsuf.com">ACM at CSUF</a></span> &bull;
<span>Provided by <a href="https://libdb.so">Diamond</a> with ❤️ and 🏳️‍⚧️</span>
</p>
</footer>

0 comments on commit 87b4ea9

Please sign in to comment.