Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ INSTALL_IMAGE = ytl-install-24.iso
IMAGE = ubuntu.iso
VM_NAME ?= YTL Linux
VM_DISK_SIZE ?= 51200
VM_DISK_PATH ?= $(shell echo "${HOME}/VirtualBox VMs/$(VM_NAME)" | sed -e 's/ /\\ /g')
VM_DISK_PATH ?= $(shell echo "${HOME}/VirtualBox VMs/$(VM_NAME)")
VM_MEMORY_SIZE ?= 4096
VM_CPUS ?= 2
VM_VIDEO_MEMORY_SIZE ?= 16
Expand Down
15 changes: 1 addition & 14 deletions packages/ytl-linux-digabi2-examnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,7 @@ deb:
cp -r NetworkManager/* $(DEB_ROOT)/etc/NetworkManager/conf.d/

# Bouncer
(cd digabi2-examnet-bouncer \
&& \
docker build \
-f Dockerfile.build \
--platform linux/amd64 \
-t registry.invalid/digabi2-examnet-bouncer-build \
. \
&& \
docker run \
--rm \
--mount type=bind,src=$(shell pwd)/$(DEB_ROOT)/usr/local/sbin/,dst=/out \
registry.invalid/digabi2-examnet-bouncer-build \
install -o $(shell id -u) /dist/digabi2-examnet-bouncer /out \
)
(cd digabi2-examnet-bouncer && deno compile --allow-net --allow-read --target x86_64-unknown-linux-gnu --output $(DEB_ROOT)/usr/local/sbin/digabi2-examnet-bouncer)

chmod 755 $(DEB_ROOT)/usr/local/sbin/*

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tasks": {
"dev": "deno run --allow-net --allow-read --watch src/main.ts"
},
"imports": {
"@gabriel/ts-pattern": "jsr:@gabriel/ts-pattern@^5.9.0",
"@std/cli": "jsr:@std/cli@^1.0.28",
"@zod/zod": "jsr:@zod/zod@^4.3.6"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { match } from '@gabriel/ts-pattern'
import { Config } from './config.ts'

export function bouncerApp(config: Config): (req: Request) => Response {
const { ncsiHostnames, friendlyNames } = config
const friendlyHostnames = friendlyNames.map(x => `${x}.${config.dns.searchDomain}`)

return function bouncerHandler(req: Request): Response {
const url = new URL(req.url)
return match(url.hostname)
.when(
x => friendlyHostnames.includes(x),
() => redirectHandler(req)
)
.when(
x => ncsiHostnames.includes(x),
() => ncsiHandler(req)
)
.otherwise(() => new Response(null, { status: 404 }))
}

function ncsiHandler(req: Request): Response {
const url = new URL(req.url)
return match(url.pathname)
.with('/connecttest.txt', () => new Response('Microsoft Connect Test'))
.with('/ncsi.txt', () => new Response('Microsoft NCSI'))
.otherwise(() => new Response(null, { status: 404 }))
}

function redirectHandler(req: Request): Response {
const url = new URL(req.url)
return match([req.method, url.pathname.replace(/\/$/, '')])
.with(['GET', '/valvoja'], () => {
const targetURL = new URL(url)
targetURL.protocol = 'https'
targetURL.host = config.dns.domain
targetURL.pathname = '/'
return redirect(targetURL)
})
.with(['GET', '/'], () => {
const targetURL = new URL(url)
targetURL.protocol = 'https'
targetURL.hostname = config.dns.domain
targetURL.port = '8010'
return redirect(targetURL)
})
.with(['POST', '/ktp/hello'], () => {
const targetURL = new URL(url)
targetURL.protocol = 'https'
targetURL.hostname = config.dns.domain
targetURL.port = '8010'
return redirect(targetURL)
})
.otherwise(() => new Response(null, { status: 404 }))
}
}

function redirect(targetURL: URL) {
return new Response(null, {
status: 307,
headers: {
'Access-Control-Allow-Origin': '*',
Location: targetURL.toString()
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { z } from '@zod/zod/v4-mini'

const TextFileContentSchema = z.pipe(
z.string(),
z.transform(async filename => await Deno.readTextFile(filename))
)

const CommaSeparatedTransform = z.transform((x: string) => x.split(','))

const DNSSchema = z.object({
schoolNumber: z.pipe(z.coerce.number(), z.int()),
serverNumber: z.pipe(z.coerce.number(), z.int().check(z.minimum(1), z.maximum(24))),
domain: z.string(),
searchDomain: z.string()
})

export const ConfigSchema = z.object({
friendlyNames: z.pipe(TextFileContentSchema, CommaSeparatedTransform),
ncsiHostnames: z.pipe(TextFileContentSchema, CommaSeparatedTransform),
dns: z.pipe(
z.pipe(
TextFileContentSchema,
z.transform(input => {
const match = input.trim().match(/^ktp(\d+)\.(\d+)\.([a-z.]+)$/)
console.log(input)
const [domain, serverNumber, schoolNumber, searchDomain] = match ?? []
return { domain, serverNumber, schoolNumber, searchDomain } as unknown
})
),
DNSSchema
),
ports: z.object({
discovery: z.int().check(z.minimum(1), z.maximum(0xffff)),
bouncer: z.int().check(z.minimum(1), z.maximum(0xffff))
})
})
export type Config = z.output<typeof ConfigSchema>

export const SecretsSchema = z.object({
key: TextFileContentSchema,
cert: TextFileContentSchema
})
export type Secrets = z.output<typeof SecretsSchema>

This file was deleted.

This file was deleted.

Loading
Loading