Cabin Chat 4.0: accounts, https, PWA, mentions, notifications
- accounts with name + password (salted sha256), one account on several devices at once, profile menu: change password, profile picture, link another device (QR code + one-time link), logout, delete account - @mentions with picker and highlighting - https by default with the router web admin's certificate; --http, --cert/--key installer options - logo/favicon, app manifest, service worker (installable PWA) - browser notifications via the service worker, no internet needed - devserver: https option, ignore connections reset by the browser Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
863d30eeba
commit
1459b3228d
+91
-15
@@ -3,11 +3,15 @@
|
||||
# Uses only what the firmware already ships (uhttpd, busybox, uci).
|
||||
#
|
||||
# sh install-cabinchat.sh install, or upgrade an existing install
|
||||
# (keeps messages, photos and the port)
|
||||
# (keeps accounts, messages, photos, port)
|
||||
# sh install-cabinchat.sh -p 8090 install/upgrade on a specific port
|
||||
# sh install-cabinchat.sh --http plain http instead of https
|
||||
# sh install-cabinchat.sh --cert C --key K https with your own certificate
|
||||
# sh install-cabinchat.sh wipe delete all messages and photos
|
||||
# sh install-cabinchat.sh uninstall remove Cabin Chat completely
|
||||
#
|
||||
# https uses the certificate of the router's web admin unless --cert is given.
|
||||
#
|
||||
# Generated by build.sh - edit www/ and installer.sh.in instead of this file.
|
||||
|
||||
VERSION="@@VERSION@@"
|
||||
@@ -24,16 +28,35 @@ info() { echo ">> $*"; }
|
||||
warn() { echo "WARNING: $*" >&2; }
|
||||
die() { echo "ERROR: $*" >&2; rm -rf "$STAGE"; exit 1; }
|
||||
usage() {
|
||||
if [ -f "$0" ]; then sed -n '4,9p' "$0" | sed 's/^# \{0,1\}//'
|
||||
else echo "usage: sh install-cabinchat.sh [-p <port> | wipe | uninstall]"; fi
|
||||
if [ -f "$0" ]; then sed -n '4,13p' "$0" | sed 's/^# \{0,1\}//'
|
||||
else echo "usage: sh install-cabinchat.sh [-p <port>] [--http | --cert <file> --key <file>] [wipe | uninstall]"; fi
|
||||
}
|
||||
|
||||
listening() { netstat -tln 2>/dev/null | grep -qE "[:.]$1[[:space:]]"; }
|
||||
|
||||
configured_port() {
|
||||
uci -q get uhttpd.chat.listen_http | tr ' ' '\n' | sed -n 's/.*:\([0-9][0-9]*\)$/\1/p' | head -n 1
|
||||
{ uci -q get uhttpd.chat.listen_https; uci -q get uhttpd.chat.listen_http; } |
|
||||
tr ' ' '\n' | sed -n 's/.*:\([0-9][0-9]*\)$/\1/p' | head -n 1
|
||||
}
|
||||
|
||||
# the certificate of the router's own web admin -> CERT, KEY
|
||||
# (GL.iNet firmware: nginx; plain OpenWrt: uhttpd)
|
||||
admin_cert() {
|
||||
for f in /etc/nginx/conf.d/*.conf /etc/nginx/nginx.conf; do
|
||||
[ -f "$f" ] || continue
|
||||
c=$(sed -n 's/^[[:space:]]*ssl_certificate[[:space:]]\{1,\}\([^;[:space:]]*\);.*/\1/p' "$f" | head -n 1)
|
||||
k=$(sed -n 's/^[[:space:]]*ssl_certificate_key[[:space:]]\{1,\}\([^;[:space:]]*\);.*/\1/p' "$f" | head -n 1)
|
||||
if [ -s "$c" ] && [ -s "$k" ]; then CERT=$c; KEY=$k; return 0; fi
|
||||
done
|
||||
c=$(uci -q get uhttpd.main.cert); k=$(uci -q get uhttpd.main.key)
|
||||
if [ -s "$c" ] && [ -s "$k" ]; then CERT=$c; KEY=$k; return 0; fi
|
||||
if [ -s /etc/uhttpd.crt ] && [ -s /etc/uhttpd.key ]; then CERT=/etc/uhttpd.crt; KEY=/etc/uhttpd.key; return 0; fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# uhttpd does TLS through libustream-ssl
|
||||
have_tls() { ls /lib/libustream-ssl.so* /usr/lib/libustream-ssl.so* >/dev/null 2>&1; }
|
||||
|
||||
remove_config() {
|
||||
if uci -q get uhttpd.chat >/dev/null; then
|
||||
uci delete uhttpd.chat
|
||||
@@ -85,6 +108,31 @@ do_install() {
|
||||
die "port $PORT is already in use - choose another one with -p <port>"
|
||||
fi
|
||||
|
||||
# https unless asked otherwise; an upgrade of a 4.x+ http install stays on http
|
||||
OLDCERT=$(uci -q get uhttpd.chat.cert)
|
||||
if [ -z "$TLS" ]; then
|
||||
TLS=1
|
||||
case $OLDVER in [4-9].*|[1-9][0-9]*)
|
||||
uci -q get uhttpd.chat.listen_https >/dev/null || TLS=0 ;;
|
||||
esac
|
||||
fi
|
||||
CERT=; KEY=
|
||||
if [ "$TLS" = 1 ]; then
|
||||
if [ -n "$CERT_ARG" ]; then
|
||||
[ -s "$CERT_ARG" ] && [ -s "$KEY_ARG" ] || die "--cert and --key need two existing files (PEM)"
|
||||
elif [ "$OLDCERT" = "$DATA/tls/cert.pem" ] && [ -s "$OLDCERT" ] && [ -s "$DATA/tls/key.pem" ]; then
|
||||
CERT=$OLDCERT; KEY=$DATA/tls/key.pem # keep the certificate given last time
|
||||
elif ! admin_cert; then
|
||||
warn "no certificate of the router's web admin found - using plain http"
|
||||
TLS=0
|
||||
fi
|
||||
if [ "$TLS" = 1 ] && ! have_tls; then
|
||||
warn "uhttpd has no TLS support (libustream-ssl missing) - using plain http"
|
||||
TLS=0
|
||||
fi
|
||||
fi
|
||||
[ "$TLS" = 1 ] && SCHEME=https || SCHEME=http
|
||||
|
||||
if [ -n "$OLDVER" ]; then
|
||||
info "upgrading Cabin Chat $OLDVER -> $VERSION"
|
||||
else
|
||||
@@ -125,9 +173,23 @@ do_install() {
|
||||
rm -rf "$KEEPIMG"
|
||||
[ -f "$CLOCK" ] || date +%s > "$CLOCK"
|
||||
|
||||
info "configuring web server on $LANIP:$PORT"
|
||||
if [ "$TLS" = 1 ] && [ -n "$CERT_ARG" ]; then
|
||||
mkdir -p "$DATA/tls"
|
||||
cp "$CERT_ARG" "$DATA/tls/cert.pem" && cp "$KEY_ARG" "$DATA/tls/key.pem" || die "cannot copy the certificate"
|
||||
chmod 600 "$DATA/tls/key.pem"
|
||||
CERT=$DATA/tls/cert.pem; KEY=$DATA/tls/key.pem
|
||||
fi
|
||||
|
||||
info "configuring web server on $SCHEME://$LANIP:$PORT"
|
||||
uci set uhttpd.chat=uhttpd
|
||||
uci add_list uhttpd.chat.listen_http="$LANIP:$PORT"
|
||||
if [ "$TLS" = 1 ]; then
|
||||
info "certificate: $CERT"
|
||||
uci add_list uhttpd.chat.listen_https="$LANIP:$PORT"
|
||||
uci set uhttpd.chat.cert="$CERT"
|
||||
uci set uhttpd.chat.key="$KEY"
|
||||
else
|
||||
uci add_list uhttpd.chat.listen_http="$LANIP:$PORT"
|
||||
fi
|
||||
uci set uhttpd.chat.home="$WEB"
|
||||
uci set uhttpd.chat.cgi_prefix='/cgi-bin'
|
||||
uci set uhttpd.chat.index_page='index.html'
|
||||
@@ -152,17 +214,22 @@ do_install() {
|
||||
sleep 1
|
||||
listening "$PORT" || die "uhttpd is not listening on port $PORT - check: logread | grep uhttpd"
|
||||
if command -v wget >/dev/null; then
|
||||
case $(wget -q -O - "http://$LANIP:$PORT/cgi-bin/chat?k=00000000000000000000000000000000&since=0" 2>/dev/null | head -n 1) in
|
||||
@*) info "self-test passed" ;;
|
||||
*) warn "the chat backend did not answer as expected - check: logread | grep uhttpd" ;;
|
||||
case $(wget -q --no-check-certificate -O - "$SCHEME://$LANIP:$PORT/cgi-bin/chat?a=ping" 2>/dev/null | head -n 1) in
|
||||
@cabinchat*) info "self-test passed" ;;
|
||||
*) warn "the chat backend did not answer as expected - check: logread | grep uhttpd"
|
||||
[ "$TLS" = 1 ] && warn "if https is the problem, run the installer again with --http" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
n=$(grep -c . "$DATA/messages" 2>/dev/null); n=${n:-0}
|
||||
a=$(ls "$DATA/accounts" 2>/dev/null | grep -c .); a=${a:-0}
|
||||
echo
|
||||
info "Cabin Chat $VERSION is running ($n messages from the last 24 h kept)"
|
||||
echo " http://$LANIP:$PORT"
|
||||
echo " http://$DNSNAME:$PORT"
|
||||
info "Cabin Chat $VERSION is running ($a accounts, $n messages from the last 24 h kept)"
|
||||
echo " $SCHEME://$LANIP:$PORT"
|
||||
echo " $SCHEME://$DNSNAME:$PORT"
|
||||
if [ "$TLS" = 1 ] && [ -z "$CERT_ARG" ] && [ "$CERT" != "$DATA/tls/cert.pem" ]; then
|
||||
echo " (the router's certificate is self-signed: browsers warn once, accept it to continue)"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------ uninstall
|
||||
@@ -177,19 +244,28 @@ do_uninstall() {
|
||||
|
||||
do_wipe() {
|
||||
[ -d "$APP" ] || die "Cabin Chat is not installed"
|
||||
rm -rf "$DATA" "$WEB/img"
|
||||
mkdir -p "$DATA" "$WEB/img"
|
||||
rm -rf "$DATA/messages" "$DATA/seq" "$WEB/img"
|
||||
mkdir -p "$WEB/img"
|
||||
g=$(cat "$DATA/gen" 2>/dev/null); case $g in ''|*[!0-9]*) g=0 ;; esac
|
||||
echo $((g + 1)) > "$DATA/gen"
|
||||
# wake up waiting browsers so they notice the empty chat
|
||||
[ -d "$RUN" ] && echo "wipe.$$" > "$RUN/ev"
|
||||
info "all messages and photos deleted"
|
||||
info "all messages and photos deleted (accounts are kept)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------ main
|
||||
CMD=install
|
||||
PORT=
|
||||
TLS=
|
||||
CERT_ARG=
|
||||
KEY_ARG=
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-p|--port) [ -n "$2" ] || die "-p needs a port number"; PORT=$2; shift 2 ;;
|
||||
--http|--no-https) TLS=0; shift ;;
|
||||
--https) TLS=1; shift ;;
|
||||
--cert) [ -n "$2" ] || die "--cert needs a file"; CERT_ARG=$2; TLS=1; shift 2 ;;
|
||||
--key) [ -n "$2" ] || die "--key needs a file"; KEY_ARG=$2; shift 2 ;;
|
||||
[0-9]*) PORT=$1; shift ;;
|
||||
install|upgrade) CMD=install; shift ;;
|
||||
uninstall|remove) CMD=uninstall; shift ;;
|
||||
|
||||
Reference in New Issue
Block a user