Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to latest version #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 11 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
FROM debian:stretch-slim
FROM debian:bookworm-slim

ENV OPENRESTY_VERSION=1.15.8.3 \
BUILD_DEPS="libreadline6-dev libncurses5-dev libpcre3-dev libssl-dev zlib1g-dev make build-essential wget git" \
ENV OPENRESTY_VERSION=1.25.3.1 \
BUILD_DEPS="libreadline6-dev libncurses5-dev libpcre3-dev libssl-dev zlib1g-dev make build-essential wget git libssl3" \
WSPROXY_ADDR="172.17.0.1:23" \
WSPROXY_CONN_DATA=""

RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y ${BUILD_DEPS} libssl1.1 \
&& \
mkdir -p /tmp/build && \
RUN apt-get update && apt-get install -y ${BUILD_DEPS}
RUN mkdir -p /tmp/build && \
cd /tmp/build && \
wget https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz && \
wget -c https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz && \
tar xfz openresty-${OPENRESTY_VERSION}.tar.gz && \
cd /tmp/build/openresty-${OPENRESTY_VERSION} && \
./configure \
--with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now' \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_sub_module \
--with-stream_ssl_module \
--with-pcre-jit \
--with-ipv6 \
--with-http_v2_module \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/dev/stdout \
--error-log-path=/dev/stderr \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--http-client-body-temp-path=/tmp/body \
Expand All @@ -45,15 +29,10 @@ RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y ${BUILD_DEPS
--user=www-data \
--group=www-data \
&& \
make && make install && \
mkdir -p /app/lib && \
make && make install clean
RUN mkdir -p /app/lib && \
git clone https://github.com/toxicfrog/vstruct/ /app/lib/vstruct && \
apt-get purge -y ${BUILD_DEPS} && \
apt-get autoremove -y && \
apt-get autoclean && \
rm -rf /tmp/build && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
rm -rf /tmp/build

COPY wsproxy.lua /app/wsproxy.lua
COPY nginx.conf /etc/nginx/nginx.conf
Expand Down
24 changes: 22 additions & 2 deletions wsproxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ local origin_whitelist = {
function check_origin()
local origin = ngx.req.get_headers().origin

if origin == nil then
ngx.log(ngx.ERR, "Origin header missing")
return ngx.exit(400)
end
if type(origin) ~= "string" then
ngx.log(ngx.ERR, "only single origin expected, got: ", origin)
return ngx.exit(400)
Expand Down Expand Up @@ -46,6 +50,7 @@ function connect_mbbsd()
local _, err = mbbsd:send(build_conn_data())
if err then
ngx.log(ngx.ERR, "failed to send conn data to mbbsd: ", err)
mbbsd:close()
return ngx.exit(555)
end
end
Expand All @@ -71,6 +76,8 @@ function ws2sock(ws, sock)
local data, typ, err = ws:recv_frame()
if err or not data then
ngx.log(ngx.ERR, "failed to receive a frame: ", err)
sock:close() -- Close the BBS connection
ws:send_close(1000, "error receiving frame") -- Close the WebSocket connection
return ngx.exit(444)
end

Expand Down Expand Up @@ -119,11 +126,14 @@ function sock2ws(sock, ws)
if not data then
ws:send_close(1000, "bbs died")
ngx.log(ngx.ERR, "failed to recv from mbbsd: ", err)
sock:close() -- Close the BBS connection
return ngx.exit(444)
else
bytes, err = ws:send_binary(data)
if not bytes then
ngx.log(ngx.ERR, "failed to send a binary frame: ", err)
sock:close() -- Close the BBS connection
ws:send_close(1000, "error sending frame") -- Close the WebSocket connection
return ngx.exit(444)
end
end
Expand All @@ -136,5 +146,15 @@ local ws = start_websocket_server()
local sock = connect_mbbsd()
ngx.log(ngx.ERR, "client connect over websocket, ",
ngx.var.server_name, ":", ngx.var.server_port, " ", ngx.var.server_protocol)
ngx.thread.spawn(ws2sock, ws, sock)
ngx.thread.spawn(sock2ws, sock, ws)

local _, err = ngx.thread.spawn(ws2sock, ws, sock)
if err then
ngx.log(ngx.ERR, "failed to spawn ws2sock thread: ", err)
return ngx.exit(555)
end

local _, err = ngx.thread.spawn(sock2ws, sock, ws)
if err then
ngx.log(ngx.ERR, "failed to spawn sock2ws thread: ", err)
return ngx.exit(555)
end