From 170193ecda6d6c466829e9a477566f539f42c821 Mon Sep 17 00:00:00 2001 From: Oliver Weimar-Drese Date: Sun, 11 Aug 2024 19:11:56 +0200 Subject: [PATCH 1/3] reimport TELNET_TLS and SOCKET_ROOT usage --- backend/src/core/environment/environment.ts | 6 ++++++ backend/src/core/environment/types/environment-keys.ts | 6 ++++-- backend/src/core/environment/types/environment.ts | 3 +++ backend/src/core/middleware/use-sockets.ts | 3 ++- backend/src/core/sockets/socket-manager.ts | 3 ++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/src/core/environment/environment.ts b/backend/src/core/environment/environment.ts index ba111b08..3da1e417 100644 --- a/backend/src/core/environment/environment.ts +++ b/backend/src/core/environment/environment.ts @@ -16,12 +16,14 @@ export class Environment implements IEnvironment { public readonly port: number; public readonly telnetHost: string; public readonly telnetPort: number; + public readonly telnetTLS: boolean; public readonly tls?: { cert: string; key: string; }; public readonly charset: string; public readonly projectRoot: string; + public readonly socketRoot: string; public readonly socketTimeout: number; /** @@ -50,6 +52,8 @@ export class Environment implements IEnvironment { this.telnetPort = Number(getEnvironmentVariable('TELNET_PORT')); + this.telnetTLS =Boolean(getEnvironmentVariable('TELNET_TLS',false,'false')); + this.charset = String(getEnvironmentVariable('CHARSET', false, 'utf8')); this.socketTimeout = Number( @@ -58,6 +62,8 @@ export class Environment implements IEnvironment { this.projectRoot = resolveModulePath('../../../main.js'); + this.socketRoot = String(getEnvironmentVariable('SOCKET_ROOT',false,'/socket.io')); + logger.info('[Environment] initialized', this); } diff --git a/backend/src/core/environment/types/environment-keys.ts b/backend/src/core/environment/types/environment-keys.ts index b5a19c0d..51556ab7 100644 --- a/backend/src/core/environment/types/environment-keys.ts +++ b/backend/src/core/environment/types/environment-keys.ts @@ -3,8 +3,10 @@ export type EnvironmentKeys = | 'PORT' | 'TELNET_HOST' | 'TELNET_PORT' - | 'SOCKET_TIMEOUT' // in milliseconds | default: 900000 (15 min) | determines how long messages are buffed for the disconnected frontend and when the telnet connection is closed + | 'TELNET_TLS' + | 'SOCKET_TIMEOUT' // in milliseconds | default: 900000 (15 min) | determines how long messages are buffed for the disconnected frontend and when the telnet connection is closed1 | 'TLS' | 'TLS_CERT' | 'TLS_KEY' - | 'CHARSET'; + | 'CHARSET' + | 'SOCKET_ROOT'; diff --git a/backend/src/core/environment/types/environment.ts b/backend/src/core/environment/types/environment.ts index fe17b889..923fd199 100644 --- a/backend/src/core/environment/types/environment.ts +++ b/backend/src/core/environment/types/environment.ts @@ -1,6 +1,7 @@ export interface IEnvironment { readonly telnetHost: string; readonly telnetPort: number; + readonly telnetTLS: boolean; readonly tls?: { cert: string; @@ -8,6 +9,8 @@ export interface IEnvironment { }; readonly projectRoot: string; + + readonly socketRoot: string; readonly charset: string; diff --git a/backend/src/core/middleware/use-sockets.ts b/backend/src/core/middleware/use-sockets.ts index 619bb253..15e2f70a 100644 --- a/backend/src/core/middleware/use-sockets.ts +++ b/backend/src/core/middleware/use-sockets.ts @@ -11,6 +11,7 @@ export const useSockets = ( new SocketManager(httpServer, { telnetHost: environment.telnetHost, telnetPort: environment.telnetPort, - useTls: environment.tls !== undefined, + useTls: environment.telnetTLS, + socketRoot: environment.socketRoot, }); }; diff --git a/backend/src/core/sockets/socket-manager.ts b/backend/src/core/sockets/socket-manager.ts index c8773292..39919f72 100644 --- a/backend/src/core/sockets/socket-manager.ts +++ b/backend/src/core/sockets/socket-manager.ts @@ -25,10 +25,11 @@ export class SocketManager extends Server< telnetHost: string; telnetPort: number; useTls: boolean; + socketRoot: string; }, ) { super(server, { - path: '/socket.io', + path: telnetOptions.socketRoot, transports: ['websocket'], connectionStateRecovery: { maxDisconnectionDuration: Environment.getInstance().socketTimeout, From 9399a7d37bfdd3c41d0bb4078270d135db6d75fd Mon Sep 17 00:00:00 2001 From: Oliver Weimar-Drese Date: Sun, 11 Aug 2024 22:48:15 +0200 Subject: [PATCH 2/3] Fixes at the environment to get it running locally --- backend/src/core/environment/environment.ts | 2 +- frontend/src/environments/environment.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/core/environment/environment.ts b/backend/src/core/environment/environment.ts index 3da1e417..2a0a847f 100644 --- a/backend/src/core/environment/environment.ts +++ b/backend/src/core/environment/environment.ts @@ -52,7 +52,7 @@ export class Environment implements IEnvironment { this.telnetPort = Number(getEnvironmentVariable('TELNET_PORT')); - this.telnetTLS =Boolean(getEnvironmentVariable('TELNET_TLS',false,'false')); + this.telnetTLS =Boolean(getEnvironmentVariable('TELNET_TLS',false,'')); this.charset = String(getEnvironmentVariable('CHARSET', false, 'utf8')); diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index acf2c3c6..5e44efb8 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -7,7 +7,8 @@ import { Environment } from './environment.interface'; export const environment: Environment = { production: false, // Change this to your local IP if you want to test on a mobile device in the same network - backendUrl: () => 'http://192.168.178.76:5000', + // backendUrl: () => 'http://192.168.178.76:5000', + backendUrl: () => window.location.origin, }; /* From f26b99c4232595cfc0b659b5ef9a5f6653f733ef Mon Sep 17 00:00:00 2001 From: Oliver Weimar-Drese Date: Sun, 11 Aug 2024 22:49:13 +0200 Subject: [PATCH 3/3] preparation of Dockerfiles, still in test mode --- Dockerfile | 36 ++++++++++-- dockerfiles/.bashrc | 24 ++++++++ dockerfiles/driver_full.sh | 74 +++++++++++++++++++++++++ dockerfiles/env-wm3local.list | 9 +++ dockerfiles/env-wm3testuni.list | 8 +++ dockerfiles/homemud_manual.dockerfile | 53 ++++++++++++++++++ dockerfiles/ng_unitopia_test.dockerfile | 43 -------------- 7 files changed, 199 insertions(+), 48 deletions(-) create mode 100644 dockerfiles/.bashrc create mode 100644 dockerfiles/driver_full.sh create mode 100644 dockerfiles/env-wm3local.list create mode 100644 dockerfiles/env-wm3testuni.list create mode 100644 dockerfiles/homemud_manual.dockerfile delete mode 100644 dockerfiles/ng_unitopia_test.dockerfile diff --git a/Dockerfile b/Dockerfile index 78011627..d25fb92c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,31 @@ -FROM node:20.12.2 +FROM node:20.12.2 AS ng-build-stage + +# docker build --progress=plain -f Dockerfile -t myonara/webmud3:latest . +# docker build --no-cache --progress=plain -f Dockerfile -t myonara/webmud3:latest . # Setze das Arbeitsverzeichnis im Container -WORKDIR /usr/src/app +WORKDIR /webmud3 # Kompilat kopieren -COPY backend/dist ./ +COPY ./ ./ # Installiere die Abhängigkeiten -RUN npm install --no-package-lock --include=prod +RUN apt-get update -y \ + && apt upgrade -y \ + && npm install -g npm@10.8.2 +RUN npm install +RUN npm run build + +# get fresh deployment +FROM node:20.12.2 AS webmud3 + +# Setze das Arbeitsverzeichnis im Container +WORKDIR /webmud3 + +# copy from build stage +COPY --from=ng-build-stage /webmud3/backend/dist/ /webmud3/ + +RUN npm install -g npm@10.8.2 && npm install # Setze die Umgebungsvariable PORT ENV PORT=5000 @@ -16,4 +34,12 @@ ENV PORT=5000 EXPOSE 5000 # Starte die Anwendung -CMD ["node", "main.js"] \ No newline at end of file +# CMD ["node", "/webmud3/main.js"] + +# for debugging: +ADD dockerfiles/.bashrc /root/ + +CMD ["/bin/bash"] + +# docker run -it -p 5000:5000 --env-file dockerfiles/env-wm3local.list --name wm3test --hostname wm3test myonara/webmud3:latest +# docker run -it -p 2019:5000 --env-file dockerfiles/env-wm3testuni.list --name wm3test --hostname wm3test myonara/webmud3:latest \ No newline at end of file diff --git a/dockerfiles/.bashrc b/dockerfiles/.bashrc new file mode 100644 index 00000000..7f065e12 --- /dev/null +++ b/dockerfiles/.bashrc @@ -0,0 +1,24 @@ +# ~/.bashrc: executed by bash(1) for non-login shells. + +# Note: PS1 and umask are already set in /etc/profile. You should not +# need this unless you want different defaults for root. +# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ ' +# umask 022 + +# You may uncomment the following lines if you want `ls' to be colorized: +export LS_OPTIONS='--color=auto' +# eval "$(dircolors)" +alias ls='ls $LS_OPTIONS' +alias ll='ls $LS_OPTIONS -lA' +# +# Some more alias to avoid making mistakes: +alias rm='rm -i' +alias cp='cp -i' +alias mv='mv -i' + +# start webmud3 +alias startwm3='node /webmud3/main.js &' +# startmud +alias startmud='/usr/local/bin/driver_full.sh &' +# copy from mud to mud9 +alias copy2mud9='cd /mud && tar cf - . | (cd /mud9 && tar xvf - )' \ No newline at end of file diff --git a/dockerfiles/driver_full.sh b/dockerfiles/driver_full.sh new file mode 100644 index 00000000..bd674540 --- /dev/null +++ b/dockerfiles/driver_full.sh @@ -0,0 +1,74 @@ +#! /bin/sh + +# if [ ! -e /mud/lib/secure/master.c ]; then +# tar -zxf /mud/lib.tar.gz -C /mud/lib --no-same-owner +# fi + +# Erstmal das Logfile linken (wird fuer den Fehlerbrowser gebraucht) +LOGFILE=log/sys/debug.`date +%s` +ln -sf $LOGFILE lib/UNItopia.debug.log + +export LC_ALL=de_DE.UTF-8@sz +export PYTHONUNBUFFERED=1 + +# TELNET_CERT="`openssl x509 -in /UNItopia/mudadm/magyra/tls/keys/telnet.pem -noout -fingerprint -sha1 | sed -e 's/.*=//;'`" +# exec /usr/local/bin/ldmud --no-erq -m /mud/lib -M secure/master.c --python-script ../startup.pyz +# --define TELNET_CERT="\"$TELNET_CERT\"" \ +# --define PORTAL_CERT='"00:CC:57:A3:12:39:95:5B:9B:EA:C6:28:69:1E:42:F8:5E:8E:9A:F3"' \ +# --tls-keydirectory /UNItopia/mudadm/magyra/tls/keys \ +# --tls-trustdirectory /UNItopia/mudadm/magyra/tls/trust \ +# --tls-crldirectory /UNItopia/mudadm/magyra/tls/crl \ +# [::ffff:172.17.0.2]:23 \ +# [::ffff:172.17.0.2]:992 \ +# [::ffff:172.17.0.2]:3333 \ +# [2a00:1828:2000:161::2]:23 \ +# [2a00:1828:2000:161::2]:992 \ +# [2a00:1828:2000:161::2]:3333 \ +# 3332 4444 5555 8080 \ +# --define UNItopia \ + +exec /usr/local/bin/ldmud \ + --define AUTO_COUNTOB \ + --define UNION_TYPES \ + --define MONSTER_SCHIESSEN_IM_HEARTBEAT \ + --define MOVE_UMSTELLUNG \ + --define AUX_PORT=33033 \ + --mudlib /mud/lib \ + --master /secure/master.c \ + --hostname homemud \ + --hostaddr 172.17.0.2 \ + --no-erq \ + --python-script ../python.pyz \ + --eval-cost 1500000 \ + --max-file 100000 \ + --max-bytes 100000 \ + --max-mapping-keys 10000 \ + --max-array 10000 \ + --cleanup-time 5400 \ + --reset-time 2400 \ + --hard-malloc-limit 4294967296 \ + --min-malloc 268435456 \ + --min-small-malloc 134217728 \ + --reserve-user 8388608 \ + --reserve-master 2097152 \ + --reserve-system 4194304 \ + --swap-file /mud/UNItopia.swp \ + --swap-time -1 \ + --swap-variables -1 \ + --gcollect-outfd /mud/gcollect.out \ + --pidfile /mud/UNItopia.pid \ + --debug-file $LOGFILE \ + --strict-euids \ + --no-compat \ + --udp 3335 \ + [::ffff:172.17.0.2]:23 \ + [::ffff:172.17.0.2]:992 \ + [::ffff:172.17.0.2]:3333 \ + [::ffff:127.0.0.1]:23 \ + [::ffff:127.0.0.1]:992 \ + [::ffff:127.0.0.1]:3333 \ + [::1]:23 \ + [::1]:992 \ + [::1]:3333 \ + 33033 \ + "$@" diff --git a/dockerfiles/env-wm3local.list b/dockerfiles/env-wm3local.list new file mode 100644 index 00000000..7686dff8 --- /dev/null +++ b/dockerfiles/env-wm3local.list @@ -0,0 +1,9 @@ +# env file for webmud3 local +# docker run -d --env-file dockerfiles/env-wm3local.list -p 5000:5000 --name wm3local myonara/webmud3:local +NODE_ENV=development +HOST=wm3test +# TELNET_HOST=unitopia.de +# TELNET_PORT=9988 +# TELNET_TLS=false +TELNET_HOST=localhost +TELNET_PORT=3333 diff --git a/dockerfiles/env-wm3testuni.list b/dockerfiles/env-wm3testuni.list new file mode 100644 index 00000000..f87ec53f --- /dev/null +++ b/dockerfiles/env-wm3testuni.list @@ -0,0 +1,8 @@ +# env file for webmud3 local +# docker run -d --env-file dockerfiles/env-wm3local.list -p 5000:5000 --name wm3local myonara/webmud3:local +NODE_ENV=development +HOST=wm3test +TELNET_HOST=unitopia.de +TELNET_PORT=9988 +TELNET_TLS=true +SOCKET_ROOT=/mysocket-test.io \ No newline at end of file diff --git a/dockerfiles/homemud_manual.dockerfile b/dockerfiles/homemud_manual.dockerfile new file mode 100644 index 00000000..08e917d0 --- /dev/null +++ b/dockerfiles/homemud_manual.dockerfile @@ -0,0 +1,53 @@ +# +# docker build --progress=plain -f dockerfiles/homemud_manual.dockerfile -t homemud . +# docker build --no-cache --progress=plain -f dockerfiles/homemud_manual.dockerfile -t homemud . + +# _T\armageddon.dockerfile +FROM debian:bookworm + +RUN apt-get update + +RUN apt-get install -y --no-install-recommends build-essential ca-certificates git bison autoconf autogen automake wget pkg-config libgcrypt20-dev libgnutls28-dev libsqlite3-dev python3-dev libxml2-dev zlib1g-dev libpcre3-dev libc-ares-dev python3-hunspell hunspell-de-de locales \ + && echo "de_DE.UTF-8 UTF-8" > /etc/locale.gen \ + && dpkg-reconfigure --frontend=noninteractive locales \ + && update-locale LANG=de_DE.UTF-8 + +RUN git clone -b unitopia https://github.com/amotzkau/ldmud.git \ + && cd ldmud/src \ + && ./autogen.sh \ + && settings/unitopia --prefix=/usr/local \ + && make install-driver \ + && cd ../.. \ + && rm -rf ldmud + +RUN mkdir /mud && cd /mud && mkdir /mud/lib \ + && cd /mud && wget -O - https://www.unitopia.de/pub/UNItopia/mudlib.tar.gz | tar -zxf - \ + && wget -O - https://www.unitopia.de/pub/UNItopia/muddocs.tar.gz | tar -zxf - \ + && wget -O - https://www.unitopia.de/pub/UNItopia/python-support.tar.gz | tar -zxf - + +RUN apt-get clean \ + && apt-mark manual libgnutls30 libsqlite3-0 libpython3.11 libxml2 libpcre3 \ + && apt-get remove --purge -y build-essential ca-certificates git bison autoconf autogen automake wget pkg-config libgcrypt20-dev libgnutls28-dev libsqlite3-dev python3-dev libxml2-dev zlib1g-dev libpcre3-dev \ + && apt-get autoremove -y +RUN apt-get install -y procps tf net-tools + +RUN /mud/lib/doc/driver/setup_mudlib + +RUN mkdir mud9 + +ENV LANG=de_DE.UTF-8 +ENV LC_ALL=de_DE.UTF-8 + +ADD dockerfiles/driver_full.sh /usr/local/bin/ +ADD dockerfiles/.bashrc /root + +EXPOSE 23 992 3333 3335/udp + +# CMD [ "/usr/local/bin/driver_full.sh" ] +CMD [ "/bin/bash" ] + +# run docker /bash) to copy mfrom mud to mud9 once (tail /root/.bashrc => copy2mud9) Adapt local path if applicable! +# docker run -it -p 23:23 -p 3333:3333 --name homemud --hostname homemud -v C:/_M/mud9:/mud9 docker.io/library/homemud + +# run docker (bash) with local volume (adapt local path if applicable) +# docker run -it -p 23:23 -p 3333:3333 --name homemud --hostname homemud -v C:/_M/mud9:/mud docker.io/library/homemud diff --git a/dockerfiles/ng_unitopia_test.dockerfile b/dockerfiles/ng_unitopia_test.dockerfile deleted file mode 100644 index 24d980e6..00000000 --- a/dockerfiles/ng_unitopia_test.dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -# based on node 10, alpine for least resource requirements. -FROM node:20-alpine3.18 AS ng-build-stage - -# working dir in build stage -WORKDIR /app - -# fetching packages and... -COPY UI17/package*.json /app/ - -RUN echo https://alpine.mirror.wearetriple.com/v3.18/main > /etc/apk/repositories; \ - echo https://alpine.mirror.wearetriple.com/v3.18/community >> /etc/apk/repositories - -# ... install them together with angular-cli, prequisite git included. -RUN apk update && apk upgrade && \ - apk add --no-cache bash git openssh \ - && npm install --location=global @angular/cli \ - && npm install - -# fetch the angular sources and stuff -COPY ./UI17/ /app/ - -# create the output of the angular app -RUN ng build --configuration development-unitopia --output-path=dist/out - -# produces the final node.js immage. -FROM node:20-alpine3.18 AS webmud3 - -# again a working dir... -WORKDIR /app - -# fetch the backend source files... -COPY ./backend/ /app/ - -#fetch the angular distribution for serving from node.js -COPY --from=ng-build-stage /app/dist/out/ /app/dist/ - -# mkdir runs -RUN mkdir /run/secrets \ - && mkdir /run/db \ - && npm install --only=prod - -CMD node server.js -