diff --git a/debian.cfg b/debian.cfg index 4d98e41..d57ef62 100644 --- a/debian.cfg +++ b/debian.cfg @@ -188,14 +188,16 @@ d-i preseed/early_command string true; \ } >>/etc/motd; \ mem=$(grep ^MemTotal: /proc/meminfo | { read -r _ y _; echo "$((y / 1024))"; }); \ if command -v websocketd && [ "$mem" -ge 400 ]; then \ + mkdir -p /tmp/web; \ + echo 'Wrong Path' >/tmp/web/index.html; \ for _ in {1..10}; do \ - if wget "$confhome/logviewer.html" -O /tmp/index.html; then \ + if wget "$confhome/logviewer.html" -O /tmp/web$web_path; then \ break; \ fi; \ sleep 5; \ done; \ - run_as_service_with_screen websocketd --port "$web_port" --loglevel=fatal --staticdir=/tmp \ - sh -c "tail -fn+0 /var/log/syslog | tr '\r' '\n' | grep -Fiv -e password -e token" ; \ + run_as_service_with_screen websocketd --port "$web_port" --loglevel=fatal --staticdir=/tmp/web \ + sh -c "if [ \"\$PATH_INFO\" = \"$web_path\" ]; then tail -fn+0 /var/log/syslog | tr '\r' '\n' | grep -Fiv -e password -e token; fi" ; \ fi; \ fi; \ diff --git a/logviewer.html b/logviewer.html index edd6065..efda03b 100644 --- a/logviewer.html +++ b/logviewer.html @@ -143,7 +143,7 @@ } } - var ws = new ReconnectingWebSocket('ws://' + location.host + '/'); + var ws = new ReconnectingWebSocket(window.location.href.replace(/^http/, 'ws')); ws.onopen = function () { bufferMessage('WebSocket Connected.'); }; diff --git a/reinstall.sh b/reinstall.sh index 64f7ac0..0feefd7 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -732,6 +732,10 @@ assert_cpu_supports_x86_64_v3() { fi } +get_http_log_url() { + echo "http://IP$([ "${web_port:-80}" = 80 ] || echo :$web_port)$web_path" +} + # 判断语言字符是否合法,允许全名和缩写 is_valid_lang_chars() { [[ "$1" =~ ^[A-Za-z_-]+$ ]] @@ -3505,7 +3509,7 @@ build_extra_cmdline() { # https://salsa.debian.org/installer-team/rootskel/-/blob/master/src/lib/debian-installer-startup.d/S02module-params?ref_type=heads for key in confhome hold force_boot_mode force_cn force_old_windows_setup cloud_image main_disk \ elts deb_mirror \ - username ssh_port rdp_port web_port allow_ping; do + username ssh_port rdp_port web_port web_path allow_ping; do value=${!key} if [ -n "$value" ]; then is_need_quote "$value" && @@ -4115,6 +4119,10 @@ get_ip_conf_cmd() { fi } +is_need_web_viewer() { + ! { [ "$distro" = netboot.xyz ] || is_alpine_live; } +} + mod_initrd_alpine() { # hack 1 v3.19 和之前的 virt 内核需添加 ipv6 模块 if virt_dir=$(ls -d $initrd_dir/lib/modules/*-virt 2>/dev/null); then @@ -5139,6 +5147,11 @@ if [ "$nextos_distro" = alpine ] || is_distro_like_debian "$nextos_distro"; then mod_initrd fi +# web 路径 +if is_need_web_viewer; then + web_path="/$(tr -dc "A-Za-z0-9" /tmp/web/index.html + # shellcheck disable=SC2154 + wget $confhome/logviewer.html -O /tmp/web$web_path + killall -q websocketd || true # websocketd 遇到 \n 才推送,因此要转换 \r 为 \n - websocketd --port "$web_port" --loglevel=fatal --staticdir=/tmp \ - stdbuf -oL -eL sh -c "tail -fn+0 /reinstall.log | tr '\r' '\n' | grep -Fiv -e password -e token" & + websocketd --port "$web_port" --loglevel=fatal --staticdir=/tmp/web \ + stdbuf -oL -eL \ + sh -c "if [ \"\$PATH_INFO\" = \"$web_path\" ]; then tail -fn+0 /reinstall.log | tr '\r' '\n' | grep -Fiv -e password -e token; fi" & } get_approximate_ram_size() {