Refactor to Go standards; add print queue and own ESC/POS library
CI / Lint, test and scan (push) Successful in 1m41s

Restructure the daemon to follow the project's Go coding standards and
expand its features.

Layout and tooling
- cmd/uberbringer/main.go is now thin; all logic lives under internal/.
- Module path is git.anomalous.dev/57_Wolve/uberbringer, go 1.26, every
  dependency upgraded, vendor/ removed.
- staticcheck, govulncheck and goimports pinned as go tools; add a
  Makefile, CI workflow, goreleaser v2 config and Alpine Dockerfile.

Features
- Background print queue with job status (GET /api/v1/jobs/:id), send
  retries with backoff, and graceful shutdown.
- New {"elements": [...]} job format on POST /api/v1/print. Breaking:
  replaces {"data": [...]}, and the response is now JSON 202.
- In-house ESC/POS library replacing justinmichaelvieira/escpos: sizes
  1-8, Font B, CODE39/CODE128, QR, banded raster images, DLE EOT status.
- UTF-8 text transcoded to CP437 (configurable) with word-aware wrapping.
- Images from URL or base64, scaled and dithered; URL fetches refuse
  internal addresses (SSRF guard).
- Fiber v3 HTTP server, TypeID (UUIDv7) job and request IDs, /healthz
  with live printer status, `secret` and `token` subcommands.

Fixes
- Jobs are validated before anything is sent; a failed printer dial no
  longer panics.
- Request logs never contain tokens; Sentry no longer receives the
  Authorization header or print contents.
- Rate limiting is per client behind nginx (X-Real-IP).
- install.sh writes the [printer] section, runs the service as a
  dedicated user and uses a current nginx TLS config.

config.toml is no longer tracked; start from configs/config.example.toml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-29 21:17:16 -06:00
1 parent bb73348433
commit 6502d9551d
807 files changed
+6659 -500291

No files matched your search

+156 -137
View File
@@ -1,52 +1,141 @@
#!/bin/bash
set -e
# Installs Überbringer behind nginx with a Let's Encrypt certificate.
#
# Usage: sudo ./install.sh <domain> <acme-email> <printer-address>
set -euo pipefail
DOMAIN=$1
ACME_EMAIL=$2
DOMAIN="${1:-}"
ACME_EMAIL="${2:-}"
PRINTER_ADDRESS="${3:-}"
LOG=/var/log/uberbringer-install.log
CONFIG_DIR=/etc/uberbringer
BIN=/usr/local/bin/uberbringer
SERVICE_USER=uberbringer
RELEASE_URL=https://git.anomalous.dev/57_Wolve/uberbringer/releases/download/latest
if [[ "$EUID" -ne 0 ]]; then
echo -e "\e[31m[FATAL]\e[39m Currently this script requires being ran as root user - please try again as root."
echo -e "\e[31m[FATAL]\e[39m This script must be run as root."
exit 1
fi
echo -e "\n\nINSTALL LOG FOR Uberbringer: $(date --rfc-3339=seconds)\n" >> /var/log/uberbringer-install.log
if [[ -z "$DOMAIN" || -z "$ACME_EMAIL" || -z "$PRINTER_ADDRESS" ]]; then
echo "Usage: $0 <domain> <acme-email> <printer-address>"
exit 1
fi
echo -e "\n\nINSTALL LOG FOR Uberbringer: $(date --rfc-3339=seconds)\n" >> "$LOG"
info() {
echo -e "\e[34m[INFO]\e[39m $1"
echo "[INFO] $1" >> /var/log/uberbringer-install.log
echo "[INFO] $1" >> "$LOG"
}
debug() {
if [[ ! -z "$DEBUG" ]]; then
if [[ -n "${DEBUG:-}" ]]; then
echo -e "\e[96m[DEBUG]\e[39m $1"
fi
echo "[DEBUG] $1" >> /var/log/uberbringer-install.log
}
warn() {
echo -e "\e[33m[WARNING]\e[39m $1"
echo "[WARNING] $1" >> /var/log/uberbringer-install.log
echo "[DEBUG] $1" >> "$LOG"
}
fatal() {
echo -e "\e[31m[FATAL]\e[39m $1"
echo "[FATAL] $1" >> /var/log/uberbringer-install.log
echo "[FATAL] $1" >> "$LOG"
exit 1
}
create_jwt(){
jwt_header=$(echo -n '{"alg":"HS256","typ":"JWT"}' | base64 | sed s/\+/-/g | sed 's/\//_/g' | sed -E s/=+$//)
payload=$(echo -n '{"user_id":"uberbringer"}' | base64 | sed s/\+/-/g |sed 's/\//_/g' | sed -E s/=+$//)
secret=$(openssl rand -base64 32)
hexsecret=$(echo -n "$secret" | xxd -p | paste -sd "")
hmac_signature=$(echo -n "${jwt_header}.${payload}" | openssl dgst -sha256 -mac HMAC -macopt hexkey:$hexsecret -binary | base64 | sed s/\+/-/g | sed 's/\//_/g' | sed -E s/=+$//)
JWT_TOKEN="${jwt_header}.${payload}.${hmac_signature}"
require() {
command -v "$1" > /dev/null 2>&1 || fatal "Couldn't find $1 - please install it and rerun the script."
}
install_nginx(){
info "Installing nginx..."
detect_arch() {
case "$(uname -m)" in
x86_64) echo "amd64" ;;
aarch64 | arm64) echo "arm64" ;;
armv7l) echo "armv7" ;;
armv6l) echo "armv6" ;;
*) fatal "Unsupported architecture: $(uname -m)" ;;
esac
}
mkdir -p /etc/nginx/includes
install_uberbringer_binary() {
local arch archive tmp
arch="$(detect_arch)"
archive="uberbringer_linux_${arch}.tar"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' RETURN
info "Downloading ${archive}..."
curl -fsSL -o "$tmp/$archive" "$RELEASE_URL/$archive"
tar -xf "$tmp/$archive" -C "$tmp"
install -m 0755 "$tmp/uberbringer" "$BIN"
}
create_service_user() {
if ! id "$SERVICE_USER" > /dev/null 2>&1; then
info "Creating system user $SERVICE_USER..."
useradd --system --no-create-home --shell /usr/sbin/nologin "$SERVICE_USER"
fi
}
write_config() {
mkdir -p "$CONFIG_DIR"
if [[ -f "$CONFIG_DIR/config.toml" ]]; then
info "Keeping existing $CONFIG_DIR/config.toml"
return
fi
info "Creating Uberbringer config..."
local secret
secret="$("$BIN" secret)"
cat <<EOT > "$CONFIG_DIR/config.toml"
[webserver]
bind_ip = "127.0.0.1"
port = 8080
[api]
secret = "$secret"
[printer]
address = "$PRINTER_ADDRESS"
EOT
chown root:"$SERVICE_USER" "$CONFIG_DIR/config.toml"
chmod 0640 "$CONFIG_DIR/config.toml"
}
install_service() {
info "Creating uberbringer.service..."
cat <<EOT > /etc/systemd/system/uberbringer.service
[Unit]
Description=Uberbringer Daemon
Wants=network-online.target
After=network.target network-online.target
[Service]
User=$SERVICE_USER
Group=$SERVICE_USER
WorkingDirectory=$CONFIG_DIR
ExecStart=$BIN --config $CONFIG_DIR/config.toml
Restart=on-failure
RestartSec=5
LimitNOFILE=4096
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
systemctl enable uberbringer
debug "Starting Uberbringer Web Service..."
systemctl restart uberbringer
}
install_nginx() {
info "Configuring nginx..."
mkdir -p /etc/nginx/includes "/var/www/$DOMAIN"
cat <<EOT > /etc/nginx/includes/letsencrypt-webroot
location / {
@@ -54,8 +143,7 @@ location / {
}
EOT
rm /etc/nginx/sites-enabled/default || true
rm /etc/nginx/sites-available/default || true
rm -f /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default
cat <<EOT > /etc/nginx/sites-available/default.conf
server {
@@ -67,157 +155,88 @@ server {
}
EOT
ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf || true
ln -sf /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
systemctl enable nginx
debug "Starting Nginx..."
systemctl restart nginx
}
install_acmesh() {
mkdir -p /etc/letsencrypt/live/$DOMAIN > /dev/null 2>&1
mkdir -p "/etc/letsencrypt/live/$DOMAIN"
info "Installing Acme.sh..."
curl https://get.acme.sh | sh -s email=$ACME_EMAIL
info "Installing acme.sh..."
curl -fsSL https://get.acme.sh | sh -s email="$ACME_EMAIL"
info "Issuing SSL Certificate..."
/root/.acme.sh/acme.sh --issue -w /var/www/$DOMAIN --keypath /etc/letsencrypt/live/$DOMAIN/privkey.pem --fullchainpath /etc/letsencrypt/live/$DOMAIN/fullchain.pem -d $DOMAIN --reloadcmd "systemctl restart nginx" --force
info "Issuing SSL certificate..."
/root/.acme.sh/acme.sh --issue -w "/var/www/$DOMAIN" \
--keypath "/etc/letsencrypt/live/$DOMAIN/privkey.pem" \
--fullchainpath "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" \
-d "$DOMAIN" --reloadcmd "systemctl reload nginx" --force
info "Enabling Acme.sh Automatic Upgrade..."
info "Enabling acme.sh automatic upgrade..."
/root/.acme.sh/acme.sh --upgrade --auto-upgrade || true
cat <<EOT > /etc/nginx/sites-available/reverse-proxy.conf
server {
listen 443;
listen [::]:443;
listen 443 ssl;
listen [::]:443 ssl;
server_name $DOMAIN;
ssl on;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AES128:EECDH+AES256:+SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RSA+3DES:!DSS';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
# Set the access log location
error_log /var/log/nginx/default_error.log;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/uberbringer_error.log;
access_log /var/log/nginx/uberbringer_access.log;
client_max_body_size 4m;
location / {
# Set the proxy headers
proxy_redirect off;
proxy_pass_request_headers on;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
proxy_set_header Referer \$http_referer;
# Uberbringer trusts X-Real-IP from 127.0.0.1 for per-client rate limits.
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
# Configure which address the request is proxied to
proxy_pass http://127.0.0.1:8080/;
proxy_read_timeout 90;
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 90;
# Security headers
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "origin";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy "no-referrer" always;
}
}
EOT
ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf || true
debug "Restarting Nginx..."
systemctl restart nginx > /dev/null 2>&1
}
install_uberbringer(){
info "Installing Uberbringer web service..."
mkdir -p /etc/uberbringer > /dev/null 2>&1
info "Creating Uberbringer config..."
cat <<EOT > /etc/uberbringer/config.toml
[webserver]
bind_ip = "127.0.0.1"
port = 8080
[api]
secret = "$secret"
EOT
info "Downloading uberbringer_linux_amd64..."
wget -O uberbringer_linux_amd64.tar https://git.anomalous.dev/57_Wolve/uberbringer/releases/download/latest/uberbringer_linux_amd64.tar || true
tar xvf uberbringer_linux_amd64.tar -C /usr/local/bin/
rm uberbringer_linux_amd64.tar.gz > /dev/null 2>&1 || true
chmod u+x /usr/local/bin/uberbringer
info "Creating uberbringer.service..."
cat <<EOT > /etc/systemd/system/uberbringer.service
[Unit]
Description=Uberbringer Daemon
Wants=network-online.target
After=network.target network-online.target
[Service]
User=root
WorkingDirectory=/etc/uberbringer
LimitNOFILE=4096
PIDFile=/var/run/uberbringer/daemon.pid
ExecStart=/usr/local/bin/uberbringer
Restart=on-failure
StartLimitInterval=600
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload > /dev/null 2>&1 || true
systemctl enable uberbringer > /dev/null 2>&1 || true
debug "Starting Uberbringer Web Service..."
systemctl start uberbringer > /dev/null 2>&1 || true
ln -sf /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
nginx -t
debug "Reloading Nginx..."
systemctl reload nginx
}
main() {
info "Script loaded, starting the install process..."
info "Installing curl, socat, xxd, and nginx..."
apt install -y nginx curl openssl xxd socat > /dev/null 2>&1
info "Installing curl, socat and nginx..."
apt-get install -y nginx curl socat > /dev/null 2>&1
if [[ ! -x "$(command -v nginx)" ]]; then
fatal "Couldn't find curl installed on the system - please install it first and rerun the script."
fi
require nginx
require curl
require socat
if [[ ! -x "$(command -v openssl)" ]]; then
fatal "Couldn't find openssl installed on the system - please install it first and rerun the script."
fi
if [[ ! -x "$(command -v curl)" ]]; then
fatal "Couldn't find curl installed on the system - please install it first and rerun the script."
fi
if [[ ! -x "$(command -v socat)" ]]; then
fatal "Couldn't find socat installed on the system - please install it first and rerun the script."
fi
create_jwt
install_uberbringer_binary
create_service_user
write_config
install_service
install_nginx
install_acmesh
install_uberbringer
info "Uberbringer Service is now installed, install script finished."
echo -e "\e[34m[INFO]\e[39m API Token: $JWT_TOKEN"
info "Uberbringer service is now installed."
echo -e "\e[34m[INFO]\e[39m API token: $("$BIN" token --config "$CONFIG_DIR/config.toml")"
}
main