From 0e55f6a2d9ef77b3ec65c8a78e8fc4eb33b75a91 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 4 Jul 2024 12:21:04 -0300 Subject: [PATCH] Beginnings of terminal support, but tinyproxy doesn't handle UPGRADE --- Dockerfile | 4 ++-- src/daemon/main.cr | 1 + src/daemon/proxyconf.cr | 19 ++++++++++--------- src/daemon/terminal.cr | 20 ++++++++++++++++++++ tinyproxy.conf | 20 +++++++++++--------- 5 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 src/daemon/terminal.cr diff --git a/Dockerfile b/Dockerfile index d6519f6..374e8f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as build -RUN apk add crystal shards yaml-dev openssl-dev zlib-dev libxml2-dev +RUN apk update && apk add crystal shards yaml-dev openssl-dev zlib-dev libxml2-dev && apk cache clean RUN addgroup -S app && adduser app -S -G app WORKDIR /home/app COPY shard.yml ./ @@ -10,7 +10,7 @@ RUN shards build -d --error-trace RUN strip bin/* FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship -RUN apk add tinyproxy multirun openssl zlib yaml pcre2 gc libevent libgcc libxml2 +RUN apk update && apk add tinyproxy multirun openssl zlib yaml pcre2 gc libevent libgcc libxml2 ttyd && apk cache clean # Unprivileged user RUN addgroup -S app && adduser app -S -G app diff --git a/src/daemon/main.cr b/src/daemon/main.cr index 9724b7d..56c9e7a 100644 --- a/src/daemon/main.cr +++ b/src/daemon/main.cr @@ -1,6 +1,7 @@ require "./funko.cr" require "./proxyconf.cr" require "./secrets.cr" +require "./terminal.cr" require "compress/gzip" require "crystar" require "docr" diff --git a/src/daemon/proxyconf.cr b/src/daemon/proxyconf.cr index 0afef86..3a4d152 100644 --- a/src/daemon/proxyconf.cr +++ b/src/daemon/proxyconf.cr @@ -30,15 +30,16 @@ module Proxy funkos.sort! config = %( - User nobody - Group nogroup - Port 8888 - Listen 0.0.0.0 - Timeout 600 - Allow 0.0.0.0/0 - ReverseOnly Yes - ReverseMagic Yes - ReversePath "/admin/" "http://127.0.0.1:3000/" +User nobody +Group nogroup +Port 8888 +Listen 0.0.0.0 +Timeout 600 +Allow 0.0.0.0/0 +ReverseOnly Yes +ReverseMagic Yes +ReversePath "/admin/" "http://127.0.0.1:3000/" +ReversePath "/admin/terminal/" "http://127.0.0.1:7681" ) + funkos.map { |funko| %(ReversePath "/faaso/#{funko.split("-")[0]}/" "http://#{funko}:3000/") }.join("\n") if @@current_config != config diff --git a/src/daemon/terminal.cr b/src/daemon/terminal.cr new file mode 100644 index 0000000..aee1504 --- /dev/null +++ b/src/daemon/terminal.cr @@ -0,0 +1,20 @@ +module Terminal + extend self + + @@terminal_process : Process | Nil = nil + + def start_terminal(_args = ["bash"], readonly = false) + args = ["-p", "7681", "-c", "admin:admin", "-o"] + args += ["-W"] unless readonly + args += _args + # We have a process there, kill it + @@terminal_process.as(Process).terminate if !@@terminal_process.nil? + @@terminal_process = Process.new( + command: "/usr/bin/ttyd", + args: args) + Log.info {"Terminal started on port 7681"} + end +end + + +Terminal.start_terminal \ No newline at end of file diff --git a/tinyproxy.conf b/tinyproxy.conf index 7931997..ca31fc9 100644 --- a/tinyproxy.conf +++ b/tinyproxy.conf @@ -1,10 +1,12 @@ - User nobody - Group nogroup - Port 8888 - Listen 0.0.0.0 - Timeout 600 - Allow 0.0.0.0/0 - ReverseOnly Yes - ReverseMagic Yes - ReversePath "/admin/" "http://127.0.0.1:3000/" +User nobody +Group nogroup +Port 8888 +Listen 0.0.0.0 +Timeout 600 +Allow 0.0.0.0/0 +ReverseOnly Yes +ReverseMagic Yes +ReversePath "/admin/" "http://127.0.0.1:3000/" +ReversePath "/admin/terminal" "http://127.0.0.1:7681" + ReversePath "/faaso/hello/" "http://hello-d89veq:3000/" \ No newline at end of file