smodusermc commited on
Commit
6dee41c
·
verified ·
1 Parent(s): e6584d9

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +800 -375
start.sh CHANGED
@@ -1,5 +1,11 @@
1
  #!/bin/bash
2
 
 
 
 
 
 
 
3
  JAVA_HOME_DIR=$(find /usr/lib/jvm -maxdepth 1 -name "java-17-openjdk-*" -type d 2>/dev/null | head -1)
4
  if [ -z "$JAVA_HOME_DIR" ]; then
5
  echo "ERROR: Java 17 not found!"
@@ -11,28 +17,24 @@ BUNGEE_DIR="/opt/server/bungee"
11
  BACKEND_DIR="/opt/server/backend"
12
  PLUGIN_DIR="$BACKEND_DIR/plugins"
13
 
14
- # Security log locations (append-only, synced to the HF bucket every
15
- # $SYNC_INTERVAL seconds, see SAVE_DIRS below):
16
- # hf://buckets/smodusermc/1.12/game-data/security-logs/logins.log
17
- # hf://buckets/smodusermc/1.12/game-data/security-logs/commands.log
18
- # hf://buckets/smodusermc/1.12/game-data/security-logs/client-checks.log
19
- # hf://buckets/smodusermc/1.12/game-data/security-logs/shared-ips.txt
20
  SEC_DIR="$BACKEND_DIR/security-logs"
21
- LOGIN_LOG="$SEC_DIR/logins.log"
22
- CMD_LOG="$SEC_DIR/commands.log"
23
- SHARED_REPORT="$SEC_DIR/shared-ips.txt"
24
- CLIENT_LOG="$SEC_DIR/client-checks.log"
25
-
26
- # Private log locations - NEVER synced to the bucket (private-logs is not in
27
- # SAVE_DIRS, see the check further down):
28
- # auth.log full /login, /register, /changepassword lines (passwords in
29
- # clear, for password resets) - everything except the
30
- # verified client, i.e. your own password is never written
31
- # player-ips.log the real IPs that were hidden as "ip=hidden" in the synced
32
- # logs, in case you ever need to look your own up
33
  PRIV_DIR="$BACKEND_DIR/private-logs"
34
  AUTH_LOG="$PRIV_DIR/auth.log"
35
- IP_MAP_FILE="$PRIV_DIR/player-ips.log"
 
 
36
 
37
  # Runtime caches (in /tmp, never written to disk)
38
  # VERDICT_CACHE : "<name>\t<VERDICT>" - last verdict per player
@@ -54,16 +56,14 @@ mkdir -p "$PLUGIN_DIR" "$SEC_DIR" "$PRIV_DIR"
54
  HF_BUCKET_HANDLE="hf://buckets/smodusermc/1.12"
55
 
56
  # The bucket is the only place the logs can be read from outside the Space, so
57
- # BOTH log folders are synced:
58
- # game-data/security-logs/ logins.log, commands.log, client-checks.log, shared-ips.txt
59
- # game-data/private-logs/ auth.log (full /login lines), player-ips.log (the
60
- # real IPs that show as "hidden"), the private reports
61
- # SYNC_PRIVATE_LOGS=false uploads only the sanitised security-logs (then
62
- # auth.log and the real IPs stay inside the Space - and you cannot read them
63
- # from outside either).
64
  SYNC_PRIVATE_LOGS="${SYNC_PRIVATE_LOGS:-true}"
65
 
66
- SAVE_DIRS="world world_nether world_the_end players banned-ips.json banned-players.json ops.json whitelist.json plugins security-logs"
 
 
67
  [ "$SYNC_PRIVATE_LOGS" = true ] && SAVE_DIRS="$SAVE_DIRS private-logs"
68
 
69
  if [ "$SYNC_PRIVATE_LOGS" = true ]; then
@@ -72,15 +72,20 @@ if [ "$SYNC_PRIVATE_LOGS" = true ]; then
72
  echo " Keep $HF_BUCKET_HANDLE private."
73
  fi
74
 
75
- SYNC_INTERVAL="${SYNC_INTERVAL:-300}"
76
- # logs are small, so they get their own much faster sync (in seconds)
 
 
 
77
  LOG_SYNC_INTERVAL="${LOG_SYNC_INTERVAL:-60}"
78
- # also upload the tail of the raw Paper/Bungee consoles (boot errors, crashes)
79
- # to game-data/logs/ so they can be read without access to the Space
80
  SYNC_CONSOLE_LOGS="${SYNC_CONSOLE_LOGS:-true}"
81
  CONSOLE_LOG_LINES="${CONSOLE_LOG_LINES:-1000}"
82
  FULL_STAGING="/tmp/hf-staging"
83
  LOG_STAGING="/tmp/hf-log-staging"
 
 
 
84
 
85
  # How the bucket is written: `auto` tries the hf CLI first and falls back to
86
  # the Python API (huggingface_hub ships in the image), `cli` / `python` force
@@ -95,7 +100,7 @@ BUCKET_ERROR=""
95
  ONLINE_STATE="${ONLINE_STATE:-/tmp/online-players.txt}"
96
  # how often the RCON player list is polled as the safety net for logins that
97
  # never showed up in a log line (a different Paper version, a rotated file, ...)
98
- PLAYERLIST_POLL="${PLAYERLIST_POLL:-20}"
99
  IDLE_MODE=false
100
 
101
  # =============================================
@@ -199,9 +204,8 @@ unset _pair
199
 
200
  # true = ONLY the verified client may stay on the server; everybody else is
201
  # kicked right after the login. DEFAULT IS FALSE: everybody may join with any
202
- # client and the verified client is only *marked* in the logs (your IP is
203
- # hidden, your lines carry no client=... tag). Turn it on if you ever want the
204
- # server to be exclusive.
205
  ENFORCE_VERIFIED_CLIENT=false
206
  # also kick real (Java) Minecraft clients - only has an effect while
207
  # ENFORCE_VERIFIED_CLIENT is true
@@ -255,7 +259,7 @@ FORWARD_IP_RETRY_INTERVAL="${FORWARD_IP_RETRY_INTERVAL:-600}"
255
  # a logged address that equals a peer is the proxy's, never a player's.
256
  PROXY_PEERS_PY="${PROXY_PEERS_PY:-/tmp/proxy_peers.py}"
257
  PROXY_PEERS_STATE="$PRIV_DIR/proxy-peers.log"
258
- PROXY_PEERS_VIEW="$SEC_DIR/proxy-peers.txt"
259
  GAME_PORT="${GAME_PORT:-7860}"
260
 
261
  # =============================================
@@ -1097,7 +1101,7 @@ javap_verify_patch() { # $1 patched jar, $2 original jar, $3 dotted class
1097
 
1098
  # Patch every auth plugin jar before Paper starts, so that /login reaches the
1099
  # console again. Prints what happened and leaves a one line summary in
1100
- # AUTH_PATCH_STATUS (written to logger-status.log, which is synced).
1101
  apply_auth_filter_patch() {
1102
  ensure_auth_filter_patch_py
1103
  local jar name status plugin class markers backup err dotted rc verify found=0 summary=""
@@ -1207,15 +1211,46 @@ auth_patch_post_start_check() {
1207
  }
1208
 
1209
  # -------------------------------------------------------------
1210
- # The console tails that are synced to the bucket are copies of the raw logs, so
1211
- # they must not become a second place where the verified client's password or
1212
- # address shows up. private-logs/auth.log stays the one place passwords can be
1213
- # read from (full for everybody except the verified client); in the bucket copy
1214
- # every auth command argument is masked and the verified client's address is
1215
- # written as "hidden".
1216
  # -------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1217
  mask_console_tail() {
1218
- awk -v cache="$VERDICT_CACHE" -v hide="${HIDE_VERIFIED_IP:-true}" '
1219
  BEGIN {
1220
  while ((getline l < cache) > 0) {
1221
  n = index(l, "\t")
@@ -1240,24 +1275,26 @@ mask_console_tail() {
1240
  }
1241
  }
1242
  }
 
 
 
 
 
 
1243
  print line
1244
  }'
1245
  }
1246
 
1247
 
1248
- # how the login logger is reported: logins.log row format + a status file so
1249
- # "it is not logging logins" can be answered from the bucket in one look
1250
  LOG_STATUS_INTERVAL="${LOG_STATUS_INTERVAL:-60}"
1251
- SCRIPT_VERSION="${SCRIPT_VERSION:-v2-gated-client}"
1252
 
1253
- # The login line is written before the client check has finished. When the IP
1254
- # is hidden the tag is left off as well, so a login by the verified client is
1255
- # just "DATE | LOGIN | name | hidden" with nothing marking it.
1256
- if [ "$HIDE_VERIFIED_IP" = true ]; then
1257
- LOGIN_CLIENT_FIELD=""
1258
- else
1259
- LOGIN_CLIENT_FIELD=" | client=CHECK PENDING"
1260
- fi
1261
 
1262
  # Open the Bungee console pipe now, before any background subshell exists, so
1263
  # every part of this script can push console commands into the proxy.
@@ -1297,29 +1334,28 @@ echo " Java: $($JAVA -version 2>&1 | head -1)"
1297
  echo " Bucket: $HF_BUCKET_HANDLE"
1298
  [ -n "$OP_USERNAME" ] && echo " OP Account: $OP_USERNAME"
1299
  echo " Plugins synced: WorldEdit, WorldGuard, MineResetLite, Shopkeepers, SafeTrade, Skript, PvPManager"
1300
- echo " Security logs: $SEC_DIR"
1301
- echo " Private logs: $PRIV_DIR"
1302
- echo " Both are synced to the bucket every ${LOG_SYNC_INTERVAL}s (full game-data sync: ${SYNC_INTERVAL}s):"
1303
- echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/logins.log logins + verdicts"
1304
- echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/commands.log every command"
1305
- echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/client-checks.log verified/other/vanilla per login"
1306
- echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/shared-ips.txt shared-IP report"
1307
  if [ "$SYNC_PRIVATE_LOGS" = true ]; then
1308
- echo " ${HF_BUCKET_HANDLE}/game-data/private-logs/auth.log full /login lines (passwords!)"
1309
- echo " ${HF_BUCKET_HANDLE}/game-data/private-logs/player-ips.log real IPs of \"hidden\" lines"
1310
- echo " ${HF_BUCKET_HANDLE}/game-data/private-logs/logins-real-ips.log, shared-ips-private.txt"
1311
  else
1312
- echo " (SYNC_PRIVATE_LOGS=false: auth.log / player-ips.log stay inside the Space)"
1313
  fi
1314
  [ "$SYNC_CONSOLE_LOGS" = true ] && \
1315
- echo " ${HF_BUCKET_HANDLE}/game-data/logs/{paper,bungee}.log last ${CONSOLE_LOG_LINES} console lines (passwords masked)"
1316
- echo " Login capture: the LoginSecurity/AuthMe password filters are neutralised at"
1317
- echo " startup, so /login reaches the console (see logger-status.log)"
1318
  if [ "$HIDE_VERIFIED_IP" = true ]; then
1319
- echo " The verified client is hidden in the security-logs: its IP is written as"
1320
- echo " \"hidden\" and it gets no client=... tag / VERIFY line"
1321
  fi
1322
- echo " Verified client: $VERIFIED_CLIENT_BRAND ($VERIFIED_CLIENT_UUID)"
1323
  if [ "$ENFORCE_VERIFIED_CLIENT" = true ]; then
1324
  echo " Enforce verified client: ON - only the verified client may join"
1325
  echo " -> kick vanilla clients too: $ENFORCE_KICK_VANILLA | kick unresolved checks: $ENFORCE_KICK_ON_UNKNOWN"
@@ -1360,6 +1396,7 @@ PAPER_JVM_FLAGS=(
1360
  -XX:-UseCodeCacheFlushing
1361
  -Xss256k
1362
  -Djline.terminal=jline.UnsupportedTerminal
 
1363
  -Dio.netty.allocator.maxCachedBufferCapacity=524288
1364
  -Dio.netty.recycler.maxCapacityPerThread=0
1365
  -Dio.netty.eventLoopThreads=${NETTY_THREADS}
@@ -1402,6 +1439,7 @@ BUNGEE_JVM_FLAGS=(
1402
  -XX:MaxMetaspaceSize=128M
1403
  -XX:ReservedCodeCacheSize=64M
1404
  -Xss256k
 
1405
  -Dio.netty.allocator.maxCachedBufferCapacity=524288
1406
  -Dio.netty.recycler.maxCapacityPerThread=0
1407
  -Dio.netty.eventLoopThreads=${NETTY_THREADS}
@@ -1594,29 +1632,21 @@ proxy_peer_addrs() { # the proxy's own addresses (kernel tables, no ss needed)
1594
  python3 "$PROXY_PEERS_PY" --port "$GAME_PORT" 2>/dev/null
1595
  }
1596
 
1597
- # Remember every peer we have seen: the proxy is not a single machine, and a
1598
- # peer may be gone by the time a report is written. The list is written into
1599
- # private-logs/ (which is restored from the bucket, so it survives a restart)
1600
- # and a readable copy goes into the synced security-logs/.
1601
  proxy_peers_record() {
1602
  local addr new=0
1603
  [ -n "$PRIV_DIR" ] || return 0
1604
- mkdir -p "$PRIV_DIR" "$SEC_DIR" 2>/dev/null
1605
  touch "$PROXY_PEERS_STATE" 2>/dev/null
1606
  while IFS= read -r addr; do
1607
  [ -n "$addr" ] || continue
1608
  grep -qF "$(printf '\t')$addr" "$PROXY_PEERS_STATE" 2>/dev/null && continue
1609
- printf '%s\t%s\n' "$(date '+%F %T')" "$addr" >> "$PROXY_PEERS_STATE" 2>/dev/null
1610
  new=$((new + 1))
1611
  done <<< "$(proxy_peer_addrs)"
1612
  [ "${new:-0}" -gt 0 ] 2>/dev/null && echo " proxy peers: $new new address(es) recorded"
1613
- {
1614
- echo "The addresses the proxy in front of the server connects from."
1615
- echo "An address in the logs that equals one of these is the PROXY's, not a player's."
1616
- echo "updated: $(date '+%F %T')"
1617
- echo ""
1618
- awk -F'\t' 'NF>1 {print " " $2 " (first seen " $1 ")"}' "$PROXY_PEERS_STATE" 2>/dev/null | sort -u
1619
- } > "$PROXY_PEERS_VIEW" 2>/dev/null
1620
  return 0
1621
  }
1622
 
@@ -1642,7 +1672,7 @@ logged_ip_is_proxy() {
1642
  return 1
1643
  }
1644
 
1645
- # What a log line's address really is, in one sentence, for logger-status.log
1646
  ip_evidence_line() {
1647
  if ! proxy_peer_list 2>/dev/null | grep -q .; then
1648
  echo "no proxy peer recorded yet - the players' addresses cannot be told from the proxy's"
@@ -1829,32 +1859,17 @@ start_bungee() {
1829
  }
1830
 
1831
  # =============================================================
1832
- # SECURITY LOGGER — logins/IPs + commands (append-only)
1833
  # =============================================================
1834
- # logins.log : DATE | LOGIN | name | ip | client=CHECK PENDING
1835
- # DATE | VERIFY | name | ip | <label> | brand=... | version=... | uuid=...
1836
- # DATE | LOGOUT | name | ip | client=...
1837
- # commands.log : DATE | name | ip | command | client=...
1838
- # shared-ips.txt : report of shared IPs / multi-IP accounts
1839
- #
1840
- # When HIDE_VERIFIED_IP=true the IP of the verified client is written as
1841
- # "hidden" everywhere in these files and its "client=..." tag and VERIFY line
1842
- # are left out, so a verified login is just "DATE | LOGIN | name | hidden".
1843
- # Everybody else keeps the full ip / client=... information.
1844
  #
1845
- # VERIFIED CLIENT
1846
- # client-checks.log : DATE | VERDICT | name | ip | brand=... | version=... | uuid=...
1847
- # VERIFIED = the client from this repo (unique Eagler brand UUID)
1848
- # UNVERIFIED = some other Eaglercraft client / fork
1849
- # VANILLA = a real Minecraft client (not Eaglercraft)
1850
- # UNKNOWN = could not be checked
1851
- #
1852
- # private-logs/auth.log : DATE | name | ip | full /login command | client=...
1853
- # (verified client: "/login ********" with ip=hidden,
1854
- # password never written; everybody else: full command)
1855
- # every password-reset relevant command from everybody EXCEPT the verified
1856
- # client, so you can read "what password did they set" without ever writing
1857
- # your own password down. Never synced to the bucket.
1858
  # =============================================================
1859
 
1860
  # last known (real) IP of a player - from the runtime map, so it also works
@@ -1870,16 +1885,37 @@ is_real_ip() {
1870
  return 0
1871
  }
1872
 
1873
- # record one sighting: every source is kept, with where it came from
1874
  record_ip() {
1875
- local name="$1" ip="$2" source="${3:-?}"
1876
  [ -n "$name" ] || return 0
1877
- printf '%s\t%s\t%s\t%s\n' "$name" "${ip:-unknown}" "$source" "$(date +%s)" >> "$IP_MAP"
 
1878
  if [ "$PRIVATE_IP_LOG" = true ]; then
1879
- printf '%s | %s | %s | source=%s\n' "$(date '+%F %T')" "$name" "${ip:-unknown}" "$source" >> "$IP_MAP_FILE"
1880
  fi
1881
  }
1882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1883
  # The most recent *real* address of a player. Sources are treated equally but
1884
  # the newest wins, and a placeholder never overwrites a real address.
1885
  last_ip_for() {
@@ -1915,19 +1951,10 @@ hide_ip_for() {
1915
  esac
1916
  }
1917
 
1918
- # " | client=LABEL" for a log line. While the owner's identity is hidden only
1919
- # the clients that are definitely not the verified one are tagged (and those
1920
- # are the lines that also carry a real IP), so nothing in the synced logs
1921
- # points back at the verified client.
1922
  client_field() {
1923
- local v="${1:-UNKNOWN}"
1924
- if [ "$HIDE_VERIFIED_IP" = true ]; then
1925
- case "$v" in
1926
- UNVERIFIED|VANILLA) ;;
1927
- *) return 0 ;;
1928
- esac
1929
- fi
1930
- printf ' | client=%s' "$(verdict_label "$v")"
1931
  }
1932
 
1933
  # -------------------------------------------------------------
@@ -1948,7 +1975,7 @@ verdict_for() {
1948
 
1949
  # Human readable form used next to logins/commands so the raw logs say it
1950
  # plainly. VERIFIED CLIENT is the only label containing that phrase, so
1951
- # "grep 'VERIFIED CLIENT' logins.log" always means "this was my client".
1952
  verdict_label() {
1953
  case "${1:-UNKNOWN}" in
1954
  VERIFIED) echo "VERIFIED CLIENT" ;;
@@ -1962,8 +1989,8 @@ verdict_label() {
1962
  # -------------------------------------------------------------
1963
  # Password / register / login commands
1964
  # -------------------------------------------------------------
1965
- # auth-style commands are masked in commands.log (which can be read by other
1966
- # people and is synced) but kept in full in private-logs/auth.log, so a lost
1967
  # password can be looked up. The verified client's own commands are the one
1968
  # exception: your password is never written anywhere.
1969
  is_auth_cmd() {
@@ -2008,9 +2035,9 @@ flush_pending_auth() {
2008
  # command happened, so auth.log shows the capture path working
2009
  write_auth_masked "$name" "$cmd" "VERIFIED CLIENT" "$v" "$epoch"
2010
  elif [ "$v" != "PENDING" ]; then
2011
- echo "$(date -d "@$epoch" '+%F %T') | $name | $ip | $cmd | client=$(verdict_label "$v")" >> "$AUTH_LOG"
2012
  elif [ $(( $(date +%s) - epoch )) -gt 300 ]; then
2013
- echo "$(date -d "@$epoch" '+%F %T') | $name | $ip | $cmd | client=UNKNOWN CLIENT (check never resolved)" >> "$AUTH_LOG"
2014
  else
2015
  printf '%s\t%s\t%s\n' "$epoch" "$name" "$cmd" >> "$tmp"
2016
  fi
@@ -2031,7 +2058,7 @@ write_auth_masked() {
2031
  fi
2032
  fi
2033
  [ -n "$epoch" ] || epoch=$(date +%s)
2034
- echo "$(date -d "@$epoch" '+%F %T') | $name | $ip | ${cmd%% *} ******** | client=$label (password not recorded)" >> "$AUTH_LOG"
2035
  }
2036
 
2037
  # mask passwords in the log lines that leave the Space; the full command is
@@ -2065,7 +2092,7 @@ mask_cmd() {
2065
  if ! auth_seen_recently "$name" "$cmd"; then
2066
  record_auth_seen "$name" "$cmd"
2067
  ip=$(last_ip_for "$name"); ip="${ip:-unknown}"
2068
- echo "$(date '+%F %T') | $name | $ip | $cmd | client=$(verdict_label "$verdict")" >> "$AUTH_LOG"
2069
  fi ;;
2070
  esac ;;
2071
  esac
@@ -2108,12 +2135,12 @@ record_login() {
2108
  local name="$1" ip="${2:-unknown}" src="${3:-?}"
2109
  is_real_ip "$ip" && record_ip "$name" "$ip" "$src"
2110
  if is_online "$name"; then
2111
- return 0 # this join is already in logins.log
2112
  fi
2113
  mark_online "$name"
2114
- echo "$(date '+%F %T') | LOGIN | $name | $(ip_field "$name" "$ip" PENDING)${LOGIN_CLIENT_FIELD:-}" >> "$LOGIN_LOG"
2115
  set_verdict "$name" PENDING
2116
- echo "[LOG] LOGIN $name (seen by $src)"
2117
  check_player_client "$name" "$ip" &
2118
  }
2119
 
@@ -2123,8 +2150,8 @@ record_logout() {
2123
  mark_offline "$name"
2124
  v=$(verdict_for "$name")
2125
  ip=$(last_ip_for "$name")
2126
- echo "$(date '+%F %T') | LOGOUT | $name | $(ip_field "$name" "${ip:-unknown}" "$v")$(client_field "$v")" >> "$LOGIN_LOG"
2127
- echo "[LOG] LOGOUT $name (seen by $src)"
2128
  }
2129
 
2130
  # -------------------------------------------------------------
@@ -2152,7 +2179,7 @@ playerlist_names() { # pull the names out of a `list` answer
2152
 
2153
  playerlist_check() {
2154
  local raw names name ip
2155
- PLAYERLIST_LAST="$(date '+%T')"
2156
  raw=$(mc_command "list" 2>/dev/null)
2157
  if [ -n "$raw" ]; then
2158
  PLAYERLIST_LAST="$PLAYERLIST_LAST got: $(printf '%s' "$raw" | tr -d '\n' | cut -c1-120)"
@@ -2184,7 +2211,7 @@ playerlist_check() {
2184
 
2185
  playerlist_loop() {
2186
  while true; do
2187
- sleep "${PLAYERLIST_POLL:-20}"
2188
  playerlist_check || true
2189
  done
2190
  }
@@ -2195,11 +2222,10 @@ playerlist_loop() {
2195
  # so the patterns match the payload only and never the prefix. Anything the
2196
  # patterns miss is still caught by the RCON player list (see playerlist_check).
2197
  handle_paper_line() {
2198
- local line="${1%$'\r'}" name ip cmd v NOW
2199
  local LOGIN_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] logged in with entity id'
2200
  local CMD_RE='([A-Za-z0-9_.-]{1,16}) issued server command: (.*)$'
2201
  local LEAVE_RE='([A-Za-z0-9_.-]{1,16}) (left the game|lost connection)'
2202
- NOW=$(date '+%F %T')
2203
 
2204
  if [[ "$line" =~ $LOGIN_RE ]]; then
2205
  name="${BASH_REMATCH[1]}"; ip="${BASH_REMATCH[2]}"
@@ -2209,7 +2235,7 @@ handle_paper_line() {
2209
  v=$(verdict_for "$name")
2210
  cmd=$(mask_cmd "$name" "${BASH_REMATCH[2]}" "$v")
2211
  ip=$(last_ip_for "$name")
2212
- echo "$NOW | $name | $(ip_field "$name" "${ip:-unknown}" "$v") | $cmd$(client_field "$v")" >> "$CMD_LOG"
2213
  elif [[ "$line" =~ $LEAVE_RE ]]; then
2214
  record_logout "${BASH_REMATCH[1]}" paper
2215
  fi
@@ -2227,12 +2253,11 @@ handle_paper_line() {
2227
  # never appear here - the auth lines come from Paper's console instead, which is
2228
  # why the plugins' password filters have to be patched (see AUTH LOG CAPTURE).
2229
  handle_bungee_line() {
2230
- local line="${1%$'\r'}" name ip cmd v NOW
2231
  local JOIN_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] <-> ServerConnector \[?[^]]*\]? has connected'
2232
  local SEEN_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] <-> InitialHandler has connected'
2233
  local QUIT_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] <-> UpstreamBridge has disconnected'
2234
  local BC_RE='([A-Za-z0-9_.-]+)\]? executed command: (.*)$'
2235
- NOW=$(date '+%F %T')
2236
 
2237
  if [[ "$line" =~ $JOIN_RE ]]; then
2238
  name="${BASH_REMATCH[1]}"; ip="${BASH_REMATCH[2]}"
@@ -2250,7 +2275,7 @@ handle_bungee_line() {
2250
  v=$(verdict_for "$name")
2251
  cmd=$(mask_cmd "$name" "${BASH_REMATCH[2]}" "$v")
2252
  ip=$(last_ip_for "$name")
2253
- echo "$NOW | $name | $(ip_field "$name" "${ip:-unknown}" "$v") | [bungee] $cmd$(client_field "$v")" >> "$CMD_LOG"
2254
  fi
2255
  }
2256
 
@@ -2371,7 +2396,7 @@ warn_verified_client_mismatch() {
2371
  [ "${builtin%%|*}" = "$VERIFIED_CLIENT_BRAND" ] && return 0
2372
  echo ""
2373
  echo "!! VERIFIED CLIENT: the pair in the environment (${VERIFIED_CLIENT_BRAND})"
2374
- echo "!! is not the one this build was made for (hidden, see logger-status.log)."
2375
  echo "!! If you just rotated the client, delete the old secrets"
2376
  echo "!! (VERIFIED_CLIENT_BRAND / VERIFIED_CLIENT_UUID) and restart."
2377
  echo ""
@@ -2386,8 +2411,18 @@ warn_verified_client_problem() {
2386
  echo ""
2387
  }
2388
 
 
 
 
 
 
 
 
 
 
 
2389
  check_player_client() {
2390
- local name="$1" ip="$2" res verdict brand version uuid mcbrand now
2391
  sleep 1 # give the Eagler handshake a moment to finish
2392
  res=$(query_client_brand "$name")
2393
  IFS='|' read -r verdict brand version uuid mcbrand <<< "$res"
@@ -2397,20 +2432,20 @@ check_player_client() {
2397
  IFS='|' read -r verdict brand version uuid mcbrand <<< "$res"
2398
  fi
2399
 
2400
- now=$(date '+%F %T')
2401
  verdict="${verdict:-UNKNOWN}"
2402
  set_verdict "$name" "$verdict"
 
2403
  flush_pending_auth
2404
- local shown_ip=$(ip_field "$name" "$ip" "$verdict")
2405
- echo "$now | ${verdict} | $name | $shown_ip | brand=${brand:-?} | version=${version:-?} | uuid=${uuid:-?}" >> "$CLIENT_LOG"
2406
- # Everybody except the verified client also gets a plainly readable VERIFY
2407
- # line in logins.log, so logins.log alone answers "was this me?" with
2408
- # "grep 'VERIFIED CLIENT' logins.log". For the verified client the line is
2409
- # omitted (see client_field) - a login by it is just LOGIN + LOGOUT.
2410
- if [ "$verdict" != "VERIFIED" ] || [ "$HIDE_VERIFIED_IP" != true ]; then
2411
- echo "$now | VERIFY | $name | $shown_ip | $(verdict_label "$verdict") | brand=${brand:-?} | version=${version:-?} | uuid=${uuid:-?}" >> "$LOGIN_LOG"
2412
  fi
2413
- echo "[CLIENT] $(date '+%H:%M:%S') $name ($shown_ip): ${verdict} / $(verdict_label "$verdict") brand=${brand:-?} version=${version:-?}"
 
2414
 
2415
  enforce_client_policy "$name" "$verdict"
2416
  }
@@ -2461,116 +2496,108 @@ enforce_client_policy() {
2461
  }
2462
 
2463
  # =============================================================
2464
- # Shared IP / verified client report
2465
  # =============================================================
2466
- # $1 = logins.log-style file to analyse, $2 = file to write
2467
- shared_report_body() {
2468
- awk -F' [|] ' '
2469
- $2=="LOGIN" {
2470
- ip=$4; n=$3
2471
- if (!((ip SUBSEP n) in s1)) { s1[ip,n]=1; ipn[ip]=ipn[ip] " " n; ipc[ip]++ }
2472
- if (!((n SUBSEP ip) in s2)) { s2[n,ip]=1; nip[n]=nip[n] " " ip; nc[n]++ }
2473
- }
2474
- END {
2475
- print "=== IPs used by MULTIPLE accounts ==="
2476
- for (i in ipc) if (ipc[i]>1) print i " ->" ipn[i]
2477
- print ""
2478
- print "=== Accounts logged in from MULTIPLE IPs ==="
2479
- for (n in nc) if (nc[n]>1) print n " ->" nip[n]
2480
- }' "$1" > "$2"
2481
-
2482
- {
2483
- echo ""
2484
- echo "=== Verified client checks (client-checks.log) ==="
2485
- if [ -s "$CLIENT_LOG" ]; then
2486
- awk -F' \\| ' '
2487
- { c[$2]++; last[$2]=$0 }
2488
- END {
2489
- for (k in c) print k ": " c[k] " login(s) (last seen " last[k] ")"
2490
- }' "$CLIENT_LOG" | sort
2491
- echo ""
2492
- echo "=== Logins NOT using the verified client ==="
2493
- grep -E "UNVERIFIED|VANILLA" "$CLIENT_LOG" 2>/dev/null | tail -20
2494
- else
2495
- echo "no client checks recorded yet"
2496
- fi
2497
- } >> "$2"
2498
- }
2499
-
2500
- # Per-account IP report: every address a player was seen from, where it came
2501
- # from and how often. This is the file to look at when two accounts show the
2502
- # same IP (or one account turns up with several) - a proxy address appears here
2503
- # for every account, a real client address does not. With $3=yes the owner's
2504
- # own addresses are left out, for the copy that gets synced.
2505
  ip_report_body() {
2506
- local map="$1" out="$2" skip_verified="${3:-no}" skip=""
2507
  if [ "$skip_verified" = yes ]; then
2508
- skip=$(awk -F'\t' '{print $1}' "$map" 2>/dev/null | sort -u | while IFS= read -r n; do
2509
- [ -n "$n" ] || continue
2510
- [ "$(verdict_for "$n")" = "VERIFIED" ] && printf '%s,' "$n"
2511
- done)
 
 
 
2512
  fi
2513
- awk -F'\t' -v skip="$skip" -v peersfile="${PROXY_PEERS_STATE:-}" '
2514
- BEGIN {
2515
- m = split(skip, a, ","); for (i = 1; i <= m; i++) if (a[i] != "") hidden[a[i]] = 1
2516
- if (peersfile != "") {
2517
- while ((getline l < peersfile) > 0) {
2518
- p = index(l, "\t")
2519
- if (p > 1) {
2520
- addr = substr(l, p + 1)
2521
- if (addr != "") { peer[addr] = 1; npeer++ }
 
 
 
 
 
 
 
 
 
 
 
 
2522
  }
 
2523
  }
2524
  }
2525
- }
2526
- $1 != "" && $2 != "" && $2 != "unknown" && $2 != "hidden" && !($1 in hidden) {
2527
- pair = $1 SUBSEP $2
2528
- if (!(pair in seen)) {
2529
- seen[pair] = 1
2530
- sources[pair] = $3
2531
- ips[$1] = ips[$1] (ips[$1] ? ", " : "") $2 " (" $3 ")"
2532
- }
2533
- hits[pair]++
2534
- rows++
2535
- who[$2] = who[$2] " " $1
2536
- users[$2]++
2537
- if (!($2 in peer)) fam[$1] = fam[$1] (index($2, ":") ? "6" : "4")
2538
- }
2539
- END {
2540
- print "=== Accounts and the IPs they were seen from ==="
2541
- for (pair in hits) {
2542
- split(pair, parts, SUBSEP)
2543
- print " " parts[1] " -> " parts[2] " (" sources[pair] ") x" hits[pair]
2544
- }
2545
- if (rows == 0) print " (no IPs recorded yet)"
2546
- print ""
2547
- print "=== One IP, several accounts ==="
2548
- for (ip in users) if (users[ip] > 1) print " " ip " ->" who[ip]
2549
- print ""
2550
- print "=== Which address is a real client address ==="
2551
- if (npeer == 0) print " (no proxy peer recorded yet - see security-logs/proxy-peers.txt)"
2552
- for (ip in users) {
2553
- if (ip in peer) print " " ip " -> the PROXY address (not a player), " users[ip] " account(s)"
2554
- else print " " ip " -> a real client address (not a proxy peer), " users[ip] " account(s)"
2555
- }
2556
- proxied = 0; own = 0
2557
- for (ip in users) { if (ip in peer) proxied++; else own++ }
2558
- if (rows > 0) {
2559
- if (own == 0) print " verdict: every address here is the PROXY address - the real client IPs are not in these logs"
2560
- else if (proxied == 0) print " verdict: the addresses here are the real client addresses (a forwarded header is in use)"
2561
- else print " verdict: both kinds are present - a row with the PROXY address had no forwarded header"
2562
  }
2563
- print ""
2564
- print "=== One device, two protocols (IPv4 + IPv6) ==="
2565
- duals = 0
2566
- for (n in fam) {
2567
- if (fam[n] ~ /4/ && fam[n] ~ /6/) {
2568
- print " " duals + 1 " account(s) -> seen over IPv4 and IPv6 - that is one device, not two"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2569
  duals++
2570
  }
2571
- }
2572
- if (duals == 0) print " (none)"
2573
- }' "$map" 2>/dev/null | sort > "$out"
 
2574
  }
2575
 
2576
  # What "the IP in the log" really is: the player's own address when a forwarded
@@ -2588,87 +2615,63 @@ real_client_ip_line() {
2588
  }
2589
 
2590
  # =============================================================
2591
- # LOGGER STATUS (security-logs/logger-status.log)
2592
  # =============================================================
2593
- # "It is not logging logins" used to be unanswerable from outside: the file was
2594
- # empty and there was no way to tell whether the server saw no joins, or the
2595
- # lines arrived in a shape the parser did not know. This file says which, and
2596
- # prints the raw lines the parser is being fed, so a mismatch is visible in the
2597
- # bucket without access to the Space.
2598
  write_logger_status() {
2599
- local out="$SEC_DIR/logger-status.log" tmp
2600
  [ -n "$SEC_DIR" ] || return 0
2601
  mkdir -p "$SEC_DIR" 2>/dev/null
2602
  tmp="${out}.tmp"
 
 
 
2603
  {
2604
- echo "verified-client logger status $(date '+%F %T')"
2605
- echo "version : ${SCRIPT_VERSION:-unknown}"
2606
- echo "paper.log : $(wc -l < /tmp/paper.log 2>/dev/null || echo 0) lines"
2607
- echo "bungee.log : $(wc -l < /tmp/bungee.log 2>/dev/null || echo 0) lines"
2608
- echo "online now : $(tr '\n' ' ' < "${ONLINE_STATE:-/dev/null}" 2>/dev/null)"
2609
- echo "logins.log : $(grep -c '| LOGIN |' "$LOGIN_LOG" 2>/dev/null) logins, $(grep -c '| LOGOUT |' "$LOGIN_LOG" 2>/dev/null) logouts"
2610
- echo "commands.log : $(wc -l < "$CMD_LOG" 2>/dev/null || echo 0) rows"
2611
- echo "client-checks : $(wc -l < "$CLIENT_LOG" 2>/dev/null || echo 0) rows"
2612
- echo "playerlist : ${PLAYERLIST_LAST:-not polled yet}"
2613
- echo "real client IPs: $(real_client_ip_line)"
2614
- echo "proxy peers : $(proxy_peer_list 2>/dev/null | tr '\n' ' ')"
2615
- echo "ip evidence : $(ip_evidence_line)"
2616
- echo "login capture : ${AUTH_PATCH_STATUS:-not run}"
 
2617
  if [ "$VERIFIED_CLIENT_CONFIGURED" = true ]; then
2618
- echo "verified client: ${VERIFIED_CLIENT_BRAND} (uuid ${VERIFIED_CLIENT_UUID})"
2619
- echo " from : ${VERIFIED_CLIENT_SOURCE:-?}$([ "$VERIFIED_CLIENT_SOURCE" = environment ] && echo " - the Space secrets win over the built-in pair")"
2620
  else
2621
- echo "verified client: NOT CONFIGURED (nobody is marked as you)"
2622
  fi
2623
  local _vcproblem
2624
  _vcproblem=$(verified_client_problem)
2625
  [ -n "$_vcproblem" ] && printf '%s\n' "$_vcproblem" | sed 's/^/ !! /'
2626
- echo "enforcement : ENFORCE_VERIFIED_CLIENT=${ENFORCE_VERIFIED_CLIENT:-false} (false = everybody may join)"
2627
- echo "tail of logins.log:"
2628
- tail -3 "$LOGIN_LOG" 2>/dev/null | sed 's/^/ /'
2629
- echo ""
2630
- echo "--- raw lines the parsers see (last 6 login/command-like lines of each) ---"
2631
- echo "if a join is missing from logins.log, compare its shape with the patterns"
2632
- echo "paper.log:"
2633
- grep -a -E 'logged in|left the game|lost connection|issued server command|\.\[IP' /tmp/paper.log 2>/dev/null | tail -6 | sed 's/^/ /'
2634
- echo "bungee.log:"
2635
- grep -a -E 'has connected|has disconnected|executed command|disconnecting' /tmp/bungee.log 2>/dev/null | tail -6 | sed 's/^/ /'
2636
  } > "$tmp" 2>/dev/null
2637
  mv "$tmp" "$out" 2>/dev/null
2638
  }
2639
 
2640
  report_shared_ips() {
 
2641
  flush_pending_auth
2642
- [ -s "$LOGIN_LOG" ] || return
2643
- ip_report_body "$IP_MAP" "$SEC_DIR/ip-report.log" yes
2644
- [ "$PRIVATE_IP_LOG" = true ] && ip_report_body "$IP_MAP" "$PRIV_DIR/ip-report-private.log" no
2645
- {
2646
- echo "=== Shared IP report $(date '+%F %T') ==="
2647
- [ "$HIDE_VERIFIED_IP" = true ] && \
2648
- echo "(the verified client's own IP shows as \"hidden\" here - see private-logs/shared-ips-private.txt)"
2649
- } > "$SHARED_REPORT"
2650
- shared_report_body "$LOGIN_LOG" "$SHARED_REPORT"
2651
-
2652
- # private copy with the real IPs put back in, for your own analysis
2653
- if [ "$HIDE_VERIFIED_IP" = true ] && [ "$PRIVATE_IP_LOG" = true ]; then
2654
- local name ip line
2655
- : > "$PRIV_DIR/logins-real-ips.log"
2656
- while IFS= read -r line; do
2657
- if [[ "$line" == *"| hidden"* ]]; then
2658
- name=$(awk -F' [|] ' '{print $3}' <<<"$line")
2659
- ip=$(last_ip_for "$name")
2660
- line="${line//| hidden/| ${ip:-unknown}}"
2661
- fi
2662
- printf '%s\n' "$line" >> "$PRIV_DIR/logins-real-ips.log"
2663
- done < "$LOGIN_LOG"
2664
- echo "=== Shared IP report (real IPs) $(date '+%F %T') ===" > "$PRIV_DIR/shared-ips-private.txt"
2665
- shared_report_body "$PRIV_DIR/logins-real-ips.log" "$PRIV_DIR/shared-ips-private.txt"
2666
- {
2667
- echo ""
2668
- echo "=== Last 20 logins with their real IPs ==="
2669
- tail -20 "$PRIV_DIR/logins-real-ips.log"
2670
- } >> "$PRIV_DIR/shared-ips-private.txt"
2671
  fi
 
 
 
 
 
 
2672
  }
2673
 
2674
  # =============================================================
@@ -2829,12 +2832,19 @@ def cmd_sync(args):
2829
  if not root.is_dir():
2830
  fail(f"{root} is not a directory")
2831
 
2832
- local = {rel: size for rel, _path, size in iter_local(root)}
2833
  remote = list_remote(api, args.bucket_id, args.prefix)
2834
 
2835
- add = [(str(path), join(args.prefix, rel), size)
2836
- for rel, path, size in iter_local(root)
2837
- if remote.get(rel) != size]
 
 
 
 
 
 
 
 
2838
  delete = [join(args.prefix, rel) for rel in remote
2839
  if args.delete and rel not in local]
2840
 
@@ -2920,12 +2930,363 @@ ensure_bucket_sync_py() {
2920
  }
2921
  # <<< embedded bucket_sync.py <<<
2922
 
2923
- # The bucket sync, the world copy and the log parsers run on the same two cores
2924
- # as Paper. They are pushed to the lowest CPU (and disk) priority so the tick
2925
- # loop always wins the core: the upload then takes a little longer, but a player
2926
- # never feels it as a lag spike. Both tools are probed once - a container
2927
- # without ionice (or without the permission to set an I/O class) silently falls
2928
- # back to nice, and a container without nice runs them as before.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2929
  BG_PRIORITY=()
2930
  if command -v ionice >/dev/null 2>&1 && ionice -c3 true >/dev/null 2>&1; then
2931
  BG_PRIORITY=(nice -n 19 ionice -c3)
@@ -3033,73 +3394,132 @@ bucket_write_probe() {
3033
  }
3034
 
3035
  hf_restore_saves() {
 
3036
  echo " Restoring game data..."
3037
- hf buckets sync "${HF_BUCKET_HANDLE}/game-data" "$BACKEND_DIR" 2>&1 | tail -5
 
 
3038
  for dir in $SAVE_DIRS; do
3039
  [ -e "$BACKEND_DIR/$dir" ] && echo " Found: $dir"
3040
  done
3041
  }
3042
 
3043
- # Copying the whole world out and hashing it in the bucket costs CPU (and disk)
3044
- # on the same two cores Paper runs on, so every run reports how long it took:
3045
- # if the game hitches in a regular rhythm, these lines are the first thing to
3046
- # look at (SYNC_INTERVAL is a Space variable if you want it less often).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3047
  hf_push_saves() {
3048
- report_shared_ips
3049
- local STAGING="$FULL_STAGING" out rc STARTED TOOK
3050
  STARTED=$(date +%s)
3051
- rm -rf "$STAGING" && mkdir -p "$STAGING"
 
3052
  for item in $SAVE_DIRS; do
 
 
 
3053
  if [ -e "$BACKEND_DIR/$item" ]; then
3054
  mkdir -p "$STAGING/$(dirname "$item")"
3055
  "${BG_PRIORITY[@]}" cp -a "$BACKEND_DIR/$item" "$STAGING/$item"
3056
  fi
3057
  done
 
 
 
 
3058
  if bucket_sync_dir "$STAGING" "${HF_BUCKET_HANDLE}/game-data" --delete; then
3059
  TOOK=$(($(date +%s) - STARTED))
3060
- echo "[SYNC] OK $(date '+%H:%M:%S') via ${BUCKET_VIA:-?} (took ${TOOK}s)"
 
3061
  else
3062
  TOOK=$(($(date +%s) - STARTED))
3063
- echo "[SYNC] FAIL $(date '+%H:%M:%S') - ${BUCKET_ERROR:-unknown error} (took ${TOOK}s)"
 
3064
  fi
3065
- rm -rf "$STAGING"
 
 
3066
  }
3067
 
3068
- # Fast log-only sync: the bucket is the only way to read the logs from outside
3069
- # the Space, so the log folders are pushed every $LOG_SYNC_INTERVAL seconds
3070
- # instead of waiting for the full game-data sync. No --delete here: this must
3071
- # never remove anything from game-data (world, plugins, ...).
 
3072
  hf_push_logs() {
 
 
 
3073
  flush_pending_auth
3074
  report_shared_ips
3075
- proxy_peers_record
3076
- local STAGING="$LOG_STAGING" out rc STARTED TOOK
3077
- STARTED=$(date +%s)
3078
- rm -rf "$STAGING" && mkdir -p "$STAGING"
3079
- [ -d "$SEC_DIR" ] && cp -a "$SEC_DIR" "$STAGING/security-logs"
3080
  if [ "$SYNC_PRIVATE_LOGS" = true ] && [ -d "$PRIV_DIR" ]; then
3081
- cp -a "$PRIV_DIR" "$STAGING/private-logs"
3082
  fi
3083
  if [ "$SYNC_CONSOLE_LOGS" = true ]; then
3084
- mkdir -p "$STAGING/logs"
3085
- # mask_console_tail: no password and no verified-client address in the
3086
- # copies that leave the Space (auth.log keeps the full commands)
3087
- [ -f /tmp/paper.log ] && tail -n "$CONSOLE_LOG_LINES" /tmp/paper.log | mask_console_tail > "$STAGING/logs/paper.log" 2>/dev/null
3088
- [ -f /tmp/bungee.log ] && tail -n "$CONSOLE_LOG_LINES" /tmp/bungee.log | mask_console_tail > "$STAGING/logs/bungee.log" 2>/dev/null
3089
  fi
3090
- LOG_SYNC_FILES=$(cd "$STAGING" 2>/dev/null && find . -type f -printf '%P(%s) ' 2>/dev/null | sort)
3091
- if bucket_sync_dir "$STAGING" "${HF_BUCKET_HANDLE}/game-data"; then
3092
- TOOK=$(($(date +%s) - STARTED))
3093
- echo "[LOGSYNC] OK $(date '+%H:%M:%S') via ${BUCKET_VIA:-?} (took ${TOOK}s) (security-logs$([ "$SYNC_PRIVATE_LOGS" = true ] && echo ' + private-logs')$([ "$SYNC_CONSOLE_LOGS" = true ] && echo ' + console tails'))"
3094
- echo " $(printf '%s' "$LOG_SYNC_FILES")"
 
 
 
 
 
 
 
 
 
3095
  else
3096
- TOOK=$(($(date +%s) - STARTED))
3097
- echo "[LOGSYNC] FAIL $(date '+%H:%M:%S') - ${BUCKET_ERROR:-unknown error} (took ${TOOK}s)"
3098
  fi
3099
- rm -rf "$STAGING"
 
 
3100
  }
3101
 
3102
  hf_sync_loop() {
 
3103
  while true; do
3104
  sleep "$SYNC_INTERVAL"
3105
  hf_push_saves
@@ -3107,6 +3527,7 @@ hf_sync_loop() {
3107
  }
3108
 
3109
  log_sync_loop() {
 
3110
  while true; do
3111
  hf_push_logs
3112
  sleep "$LOG_SYNC_INTERVAL"
@@ -3122,7 +3543,10 @@ hf_ensure_bucket
3122
  bucket_write_probe || true
3123
  hf_restore_saves
3124
  mkdir -p "$SEC_DIR" "$PRIV_DIR"
3125
- touch "$LOGIN_LOG" "$CMD_LOG" "$CLIENT_LOG" "$AUTH_LOG"
 
 
 
3126
  : > "$ONLINE_STATE"
3127
  echo ""
3128
 
@@ -3467,10 +3891,11 @@ if [ "$PORT_READY" = true ]; then
3467
  else
3468
  echo " bucket uploads: FAILING - see the [BUCKET] lines above"
3469
  fi
3470
- echo " security-logs/{logins,commands,client-checks}.log"
3471
- echo " + shared-ips.txt, ip-report.log, logger-status.log"
3472
  [ "$SYNC_PRIVATE_LOGS" = true ] && \
3473
- echo " private-logs/{auth,player-ips,logins-real-ips,ip-report-private}.log"
 
 
3474
  if [ "$VERIFIED_CLIENT_CONFIGURED" = true ]; then
3475
  echo " Verified client: $VERIFIED_CLIENT_BRAND (uuid $VERIFIED_CLIENT_UUID)"
3476
  echo " pair from: $VERIFIED_CLIENT_SOURCE$([ "$VERIFIED_CLIENT_SOURCE" = environment ] && echo ' (Space secrets override the built-in pair)')"
@@ -3479,7 +3904,7 @@ if [ "$PORT_READY" = true ]; then
3479
  echo " the Space's Variables and secrets (nobody is marked as you)"
3480
  fi
3481
  echo " everybody may join (ENFORCE_VERIFIED_CLIENT=$ENFORCE_VERIFIED_CLIENT); the"
3482
- echo " verified client is only marked in the logs (IP hidden, no client= tag)"
3483
  echo " every brand ever committed to the repo (Eaglercraft[VER], EaglercraftX[V2],"
3484
  echo " the stock one) is refused - it cannot make anybody 'verified' any more"
3485
  echo " real client IPs: $(forward_ip_setting 2>/dev/null)"
@@ -3567,7 +3992,7 @@ while true; do
3567
  fi
3568
 
3569
  if ! kill -0 $BACKEND_PID 2>/dev/null; then
3570
- echo "[$(date '+%H:%M:%S')] Paper crashed — restarting..."
3571
  hf_push_saves
3572
  IDLE_MODE=false
3573
  start_paper
@@ -3586,7 +4011,7 @@ while true; do
3586
  fi
3587
 
3588
  if ! kill -0 $BUNGEE_PID 2>/dev/null; then
3589
- echo "[$(date '+%H:%M:%S')] BungeeCord crashed — restarting..."
3590
  patch_eagler_port
3591
  start_bungee
3592
  fi
@@ -3597,7 +4022,7 @@ while true; do
3597
  fi
3598
 
3599
  if [ -z "${LOGSYNC_PID:-}" ] || ! kill -0 "$LOGSYNC_PID" 2>/dev/null; then
3600
- echo "[$(date '+%H:%M:%S')] Log sync died — restarting..."
3601
  log_sync_loop &
3602
  LOGSYNC_PID=$!
3603
  fi
@@ -3608,7 +4033,7 @@ while true; do
3608
  fi
3609
 
3610
  if ! kill -0 "$SECLOG_PID" 2>/dev/null; then
3611
- echo "[$(date '+%H:%M:%S')] Security logger died — restarting..."
3612
  start_security_logger
3613
  fi
3614
 
@@ -3630,7 +4055,7 @@ while true; do
3630
  CURRENT_LINE=$(wc -l < /tmp/paper.log 2>/dev/null || echo 0)
3631
  if [ "$CURRENT_LINE" -gt "$LAST_LOG_LINE" ]; then
3632
  NEW_ERRORS=$(tail -n +"$((LAST_LOG_LINE + 1))" /tmp/paper.log | grep -c "ERROR\|SEVERE" || echo 0)
3633
- [ "$NEW_ERRORS" -gt 0 ] && echo "[$(date '+%H:%M:%S')] $NEW_ERRORS errors" && \
3634
  tail -n +"$((LAST_LOG_LINE + 1))" /tmp/paper.log | grep "ERROR\|SEVERE" | tail -3
3635
  LAST_LOG_LINE=$CURRENT_LINE
3636
  fi
@@ -3643,7 +4068,7 @@ while true; do
3643
  # Truncate in place so Java and the security logger keep working
3644
  tail -1000 "$LF" > "${LF}.old"
3645
  : > "$LF"
3646
- echo "[$(date '+%H:%M:%S')] Trimmed $(basename $LF)"
3647
  fi
3648
  done
3649
  LAST_LOG_LINE=$(wc -l < /tmp/paper.log 2>/dev/null || echo 0)
 
1
  #!/bin/bash
2
 
3
+ # The container can be rescheduled onto hosts with different default zones.
4
+ # Pin shell tools and JVMs to New York time so timestamps do not jump between
5
+ # UTC/local time; 12-hour formatting is applied to the curated log files.
6
+ export TZ="America/New_York"
7
+ export LC_ALL=C
8
+
9
  JAVA_HOME_DIR=$(find /usr/lib/jvm -maxdepth 1 -name "java-17-openjdk-*" -type d 2>/dev/null | head -1)
10
  if [ -z "$JAVA_HOME_DIR" ]; then
11
  echo "ERROR: Java 17 not found!"
 
17
  BACKEND_DIR="/opt/server/backend"
18
  PLUGIN_DIR="$BACKEND_DIR/plugins"
19
 
20
+ # Human-readable logs. One activity stream replaces the old login, command and
21
+ # client-check files; separate copies of those same events were hard to follow.
 
 
 
 
22
  SEC_DIR="$BACKEND_DIR/security-logs"
23
+ ACTIVITY_LOG="$SEC_DIR/activity.log"
24
+ LOGIN_LOG="$ACTIVITY_LOG" # aliases used by the event handlers below
25
+ CMD_LOG="$ACTIVITY_LOG"
26
+ CLIENT_LOG="$ACTIVITY_LOG"
27
+ ADDRESS_REPORT="$SEC_DIR/addresses.txt"
28
+ STATUS_FILE="$SEC_DIR/status.txt"
29
+
30
+ # Private logs are synced to the private bucket folder by default. auth.log
31
+ # keeps other players' full /login lines for password resets (never yours);
32
+ # addresses.log is the private address history, including your hidden IP.
 
 
33
  PRIV_DIR="$BACKEND_DIR/private-logs"
34
  AUTH_LOG="$PRIV_DIR/auth.log"
35
+ IP_MAP_FILE="$PRIV_DIR/addresses.log"
36
+ PRIVATE_ADDRESS_REPORT="$PRIV_DIR/addresses.txt"
37
+ LOG_MIGRATOR_PY="${LOG_MIGRATOR_PY:-/tmp/log_migrate.py}"
38
 
39
  # Runtime caches (in /tmp, never written to disk)
40
  # VERDICT_CACHE : "<name>\t<VERDICT>" - last verdict per player
 
56
  HF_BUCKET_HANDLE="hf://buckets/smodusermc/1.12"
57
 
58
  # The bucket is the only place the logs can be read from outside the Space, so
59
+ # the curated activity/address/status files and the private password/IP history
60
+ # are synced there. The private folder contains clear-text passwords and real
61
+ # IPs: keep this bucket private. SYNC_PRIVATE_LOGS=false disables its upload.
 
 
 
 
62
  SYNC_PRIVATE_LOGS="${SYNC_PRIVATE_LOGS:-true}"
63
 
64
+ # `logs` is included in the full mirror so --delete never erases the console
65
+ # snapshot. The two log-only syncs below target only their own folder prefixes.
66
+ SAVE_DIRS="world world_nether world_the_end players banned-ips.json banned-players.json ops.json whitelist.json plugins security-logs logs"
67
  [ "$SYNC_PRIVATE_LOGS" = true ] && SAVE_DIRS="$SAVE_DIRS private-logs"
68
 
69
  if [ "$SYNC_PRIVATE_LOGS" = true ]; then
 
72
  echo " Keep $HF_BUCKET_HANDLE private."
73
  fi
74
 
75
+ # Full world snapshots do a lot of file walking and hashing. Paper autosaves
76
+ # every 10 minutes; a 10-minute backup interval avoids a redundant full scan
77
+ # every five minutes while keeping the normal rollback window short.
78
+ SYNC_INTERVAL="${SYNC_INTERVAL:-600}"
79
+ # Curated logs stay fresh independently of world snapshots (seconds).
80
  LOG_SYNC_INTERVAL="${LOG_SYNC_INTERVAL:-60}"
81
+ # One combined, password/IP-redacted console snapshot is kept for boot errors.
 
82
  SYNC_CONSOLE_LOGS="${SYNC_CONSOLE_LOGS:-true}"
83
  CONSOLE_LOG_LINES="${CONSOLE_LOG_LINES:-1000}"
84
  FULL_STAGING="/tmp/hf-staging"
85
  LOG_STAGING="/tmp/hf-log-staging"
86
+ BUCKET_SYNC_LOCK="${BUCKET_SYNC_LOCK:-/tmp/hf-bucket-sync.lock}"
87
+ REPORT_INTERVAL="${REPORT_INTERVAL:-300}"
88
+ REPORT_STATE="${REPORT_STATE:-/tmp/addresses-report-last-update}"
89
 
90
  # How the bucket is written: `auto` tries the hf CLI first and falls back to
91
  # the Python API (huggingface_hub ships in the image), `cli` / `python` force
 
100
  ONLINE_STATE="${ONLINE_STATE:-/tmp/online-players.txt}"
101
  # how often the RCON player list is polled as the safety net for logins that
102
  # never showed up in a log line (a different Paper version, a rotated file, ...)
103
+ PLAYERLIST_POLL="${PLAYERLIST_POLL:-60}"
104
  IDLE_MODE=false
105
 
106
  # =============================================
 
204
 
205
  # true = ONLY the verified client may stay on the server; everybody else is
206
  # kicked right after the login. DEFAULT IS FALSE: everybody may join with any
207
+ # client and the verified client is marked in the logs while its IP and private
208
+ # brand/UUID are hidden. Turn it on if you ever want the server to be exclusive.
 
209
  ENFORCE_VERIFIED_CLIENT=false
210
  # also kick real (Java) Minecraft clients - only has an effect while
211
  # ENFORCE_VERIFIED_CLIENT is true
 
259
  # a logged address that equals a peer is the proxy's, never a player's.
260
  PROXY_PEERS_PY="${PROXY_PEERS_PY:-/tmp/proxy_peers.py}"
261
  PROXY_PEERS_STATE="$PRIV_DIR/proxy-peers.log"
262
+ VERIFIED_PLAYER_STATE="$PRIV_DIR/verified-players.txt"
263
  GAME_PORT="${GAME_PORT:-7860}"
264
 
265
  # =============================================
 
1101
 
1102
  # Patch every auth plugin jar before Paper starts, so that /login reaches the
1103
  # console again. Prints what happened and leaves a one line summary in
1104
+ # AUTH_PATCH_STATUS (shown in security-logs/status.txt, which is synced).
1105
  apply_auth_filter_patch() {
1106
  ensure_auth_filter_patch_py
1107
  local jar name status plugin class markers backup err dotted rc verify found=0 summary=""
 
1211
  }
1212
 
1213
  # -------------------------------------------------------------
1214
+ # One timestamp style for all curated append-only logs: Eastern time with the
1215
+ # date, 12-hour clock and an explicit EST/EDT marker. A dated divider is added
1216
+ # on the first event of each day. `flock` makes the divider + row atomic even
1217
+ # when Paper, Bungee and the RCON safety-net report at nearly the same time.
 
 
1218
  # -------------------------------------------------------------
1219
+ now_eastern() {
1220
+ date '+%Y-%m-%d %I:%M:%S %p %Z'
1221
+ }
1222
+
1223
+ format_epoch_eastern() {
1224
+ local epoch="${1:-$(date +%s)}"
1225
+ date -d "@$epoch" '+%Y-%m-%d %I:%M:%S %p %Z'
1226
+ }
1227
+
1228
+ append_dated_log() { # $1=file, $2=epoch seconds, $3=message (without timestamp)
1229
+ local file="$1" epoch="${2:-$(date +%s)}" message="$3"
1230
+ local stamp day weekday last_line last_day
1231
+ [[ "$epoch" =~ ^[0-9]+$ ]] || epoch=$(date +%s)
1232
+ stamp=$(format_epoch_eastern "$epoch") || return 1
1233
+ day="${stamp:0:10}"
1234
+ weekday=$(date -d "@$epoch" '+%A, %B %-d, %Y')
1235
+ mkdir -p "$(dirname "$file")" 2>/dev/null || return 1
1236
+ {
1237
+ flock -x 8
1238
+ last_line=$(tail -n 1 "$file" 2>/dev/null || true)
1239
+ last_day="${last_line:0:10}"
1240
+ if [ "$last_day" != "$day" ]; then
1241
+ [ -s "$file" ] && printf '\n' >&8
1242
+ printf '%s\n\n' "==================== $weekday | $day ====================" >&8
1243
+ fi
1244
+ printf '%s | %s\n' "$stamp" "$message" >&8
1245
+ flock -u 8
1246
+ } 8>>"$file"
1247
+ }
1248
+
1249
+ # The console snapshot is deliberately the only raw-console copy. It is a tail,
1250
+ # while activity.log records structured player events. Mask passwords, hide the
1251
+ # verified client's address, and redact the brand UUID from the synced copy.
1252
  mask_console_tail() {
1253
+ "${BG_PRIORITY[@]}" awk -v cache="$VERDICT_CACHE" -v hide="${HIDE_VERIFIED_IP:-true}" '
1254
  BEGIN {
1255
  while ((getline l < cache) > 0) {
1256
  n = index(l, "\t")
 
1275
  }
1276
  }
1277
  }
1278
+ # The console log has no reliable player marker on these replies,
1279
+ # so redact protocol identity fields for every client.
1280
+ if (index(line, "Eagler Client Brand:") > 0)
1281
+ sub(/Eagler Client Brand:.*/, "Eagler Client Brand: [redacted]", line)
1282
+ if (index(line, "Eagler Client UUID:") > 0)
1283
+ sub(/Eagler Client UUID:.*/, "Eagler Client UUID: [redacted]", line)
1284
  print line
1285
  }'
1286
  }
1287
 
1288
 
1289
+ # One compact status snapshot is refreshed periodically; detailed events live
1290
+ # in activity.log and raw diagnostics in logs/console.log.
1291
  LOG_STATUS_INTERVAL="${LOG_STATUS_INTERVAL:-60}"
1292
+ SCRIPT_VERSION="${SCRIPT_VERSION:-v3-compact-logs}"
1293
 
1294
+ # A login is written immediately (so a failed client check cannot erase it).
1295
+ # The following CHECK row adds the final marker, and the IP stays hidden while
1296
+ # the verdict is pending or verified.
1297
+ LOGIN_CLIENT_FIELD=" | client=CHECK PENDING"
 
 
 
 
1298
 
1299
  # Open the Bungee console pipe now, before any background subshell exists, so
1300
  # every part of this script can push console commands into the proxy.
 
1334
  echo " Bucket: $HF_BUCKET_HANDLE"
1335
  [ -n "$OP_USERNAME" ] && echo " OP Account: $OP_USERNAME"
1336
  echo " Plugins synced: WorldEdit, WorldGuard, MineResetLite, Shopkeepers, SafeTrade, Skript, PvPManager"
1337
+ echo " Security logs: $ACTIVITY_LOG, addresses.txt, status.txt"
1338
+ echo " Private logs: $PRIV_DIR (private bucket folder; passwords and real IPs)"
1339
+ echo " Curated logs sync every ${LOG_SYNC_INTERVAL}s; full game-data snapshot every ${SYNC_INTERVAL}s"
1340
+ echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/activity.log logins, checks, commands, dated in Eastern time"
1341
+ echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/addresses.txt one public IP summary (verified account omitted)"
1342
+ echo " ${HF_BUCKET_HANDLE}/game-data/security-logs/status.txt current logger health"
 
1343
  if [ "$SYNC_PRIVATE_LOGS" = true ]; then
1344
+ echo " ${HF_BUCKET_HANDLE}/game-data/private-logs/auth.log full other-player auth commands (passwords!)"
1345
+ echo " ${HF_BUCKET_HANDLE}/game-data/private-logs/addresses.log full address history; keep the bucket private"
1346
+ echo " ${HF_BUCKET_HANDLE}/game-data/private-logs/addresses.txt private address summary"
1347
  else
1348
+ echo " SYNC_PRIVATE_LOGS=false: prior private bucket logs are removed and no new ones upload"
1349
  fi
1350
  [ "$SYNC_CONSOLE_LOGS" = true ] && \
1351
+ echo " ${HF_BUCKET_HANDLE}/game-data/logs/console.log one masked Paper + Bungee tail"
1352
+ echo " Login capture: LoginSecurity filters are neutralised before Paper starts"
1353
+ echo " (health details are in security-logs/status.txt)"
1354
  if [ "$HIDE_VERIFIED_IP" = true ]; then
1355
+ echo " The verified client's IP is hidden in the public activity/address logs;"
1356
+ echo " the client marker remains visible so the owner can identify their lines."
1357
  fi
1358
+ echo " Verified client: configured (brand/UUID values are not printed to logs)"
1359
  if [ "$ENFORCE_VERIFIED_CLIENT" = true ]; then
1360
  echo " Enforce verified client: ON - only the verified client may join"
1361
  echo " -> kick vanilla clients too: $ENFORCE_KICK_VANILLA | kick unresolved checks: $ENFORCE_KICK_ON_UNKNOWN"
 
1396
  -XX:-UseCodeCacheFlushing
1397
  -Xss256k
1398
  -Djline.terminal=jline.UnsupportedTerminal
1399
+ -Duser.timezone=America/New_York
1400
  -Dio.netty.allocator.maxCachedBufferCapacity=524288
1401
  -Dio.netty.recycler.maxCapacityPerThread=0
1402
  -Dio.netty.eventLoopThreads=${NETTY_THREADS}
 
1439
  -XX:MaxMetaspaceSize=128M
1440
  -XX:ReservedCodeCacheSize=64M
1441
  -Xss256k
1442
+ -Duser.timezone=America/New_York
1443
  -Dio.netty.allocator.maxCachedBufferCapacity=524288
1444
  -Dio.netty.recycler.maxCapacityPerThread=0
1445
  -Dio.netty.eventLoopThreads=${NETTY_THREADS}
 
1632
  python3 "$PROXY_PEERS_PY" --port "$GAME_PORT" 2>/dev/null
1633
  }
1634
 
1635
+ # Remember proxy peers in private state so a later address report can classify
1636
+ # them. The same list is included in addresses.txt; there is no second public
1637
+ # proxy-peers.txt copy to keep in sync.
 
1638
  proxy_peers_record() {
1639
  local addr new=0
1640
  [ -n "$PRIV_DIR" ] || return 0
1641
+ mkdir -p "$PRIV_DIR" 2>/dev/null
1642
  touch "$PROXY_PEERS_STATE" 2>/dev/null
1643
  while IFS= read -r addr; do
1644
  [ -n "$addr" ] || continue
1645
  grep -qF "$(printf '\t')$addr" "$PROXY_PEERS_STATE" 2>/dev/null && continue
1646
+ printf '%s\t%s\n' "$(now_eastern)" "$addr" >> "$PROXY_PEERS_STATE" 2>/dev/null
1647
  new=$((new + 1))
1648
  done <<< "$(proxy_peer_addrs)"
1649
  [ "${new:-0}" -gt 0 ] 2>/dev/null && echo " proxy peers: $new new address(es) recorded"
 
 
 
 
 
 
 
1650
  return 0
1651
  }
1652
 
 
1672
  return 1
1673
  }
1674
 
1675
+ # What a log line's address really is, in one sentence, for security-logs/status.txt
1676
  ip_evidence_line() {
1677
  if ! proxy_peer_list 2>/dev/null | grep -q .; then
1678
  echo "no proxy peer recorded yet - the players' addresses cannot be told from the proxy's"
 
1859
  }
1860
 
1861
  # =============================================================
1862
+ # SECURITY LOGGER — one append-only activity stream
1863
  # =============================================================
1864
+ # security-logs/activity.log combines LOGIN, LOGOUT, CHECK and COMMAND rows.
1865
+ # It uses New York time, a 12-hour clock and a day divider, so the duplicate
1866
+ # login/command/check files from older builds are no longer needed.
 
 
 
 
 
 
 
1867
  #
1868
+ # Public activity/address reports hide the verified client's real IP, but keep
1869
+ # the explicit VERIFIED CLIENT marker visible. The private address history has
1870
+ # the full IPs. Password commands are masked in activity.log and kept in full
1871
+ # only in private-logs/auth.log for everyone except the verified client.
1872
+ # The verified brand and UUID are redacted from all synced logs.
 
 
 
 
 
 
 
 
1873
  # =============================================================
1874
 
1875
  # last known (real) IP of a player - from the runtime map, so it also works
 
1885
  return 0
1886
  }
1887
 
1888
+ # Record one sighting in memory and in the private, date-divided history.
1889
  record_ip() {
1890
+ local name="$1" ip="$2" source="${3:-?}" epoch
1891
  [ -n "$name" ] || return 0
1892
+ epoch=$(date +%s)
1893
+ printf '%s\t%s\t%s\t%s\n' "$name" "${ip:-unknown}" "$source" "$epoch" >> "$IP_MAP"
1894
  if [ "$PRIVATE_IP_LOG" = true ]; then
1895
+ append_dated_log "$IP_MAP_FILE" "$epoch" "IP | $name | ${ip:-unknown} | source=$source"
1896
  fi
1897
  }
1898
 
1899
+ # Recover the persistent private address history after a Space restart. The
1900
+ # runtime TSV stays a fast, per-account cache; it is never copied to the bucket.
1901
+ restore_ip_map() {
1902
+ local stamp type name ip source epoch
1903
+ [ -s "$IP_MAP_FILE" ] || return 0
1904
+ while IFS='|' read -r stamp type name ip source; do
1905
+ stamp="${stamp# }"; stamp="${stamp% }"
1906
+ type="${type# }"; type="${type% }"
1907
+ [ "$type" = IP ] || continue
1908
+ name="${name# }"; name="${name% }"
1909
+ ip="${ip# }"; ip="${ip% }"
1910
+ source="${source# }"; source="${source% }"
1911
+ source="${source#source=}"
1912
+ [[ "$stamp" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2} ]] || continue
1913
+ epoch=$(date -d "$stamp" +%s 2>/dev/null) || continue
1914
+ [ -n "$name" ] && [ -n "$ip" ] || continue
1915
+ printf '%s\t%s\t%s\t%s\n' "$name" "$ip" "${source:-?}" "$epoch" >> "$IP_MAP"
1916
+ done < "$IP_MAP_FILE"
1917
+ }
1918
+
1919
  # The most recent *real* address of a player. Sources are treated equally but
1920
  # the newest wins, and a placeholder never overwrites a real address.
1921
  last_ip_for() {
 
1951
  esac
1952
  }
1953
 
1954
+ # The explicit client marker is useful to the owner and does not expose the
1955
+ # address: verified/pending IPs are still rendered as "hidden" separately.
 
 
1956
  client_field() {
1957
+ printf ' | client=%s' "$(verdict_label "${1:-UNKNOWN}")"
 
 
 
 
 
 
 
1958
  }
1959
 
1960
  # -------------------------------------------------------------
 
1975
 
1976
  # Human readable form used next to logins/commands so the raw logs say it
1977
  # plainly. VERIFIED CLIENT is the only label containing that phrase, so
1978
+ # "grep 'VERIFIED CLIENT' activity.log" identifies the verified account.
1979
  verdict_label() {
1980
  case "${1:-UNKNOWN}" in
1981
  VERIFIED) echo "VERIFIED CLIENT" ;;
 
1989
  # -------------------------------------------------------------
1990
  # Password / register / login commands
1991
  # -------------------------------------------------------------
1992
+ # auth-style commands are masked in activity.log (which is synced) but kept
1993
+ # in full in private-logs/auth.log, so a lost
1994
  # password can be looked up. The verified client's own commands are the one
1995
  # exception: your password is never written anywhere.
1996
  is_auth_cmd() {
 
2035
  # command happened, so auth.log shows the capture path working
2036
  write_auth_masked "$name" "$cmd" "VERIFIED CLIENT" "$v" "$epoch"
2037
  elif [ "$v" != "PENDING" ]; then
2038
+ append_dated_log "$AUTH_LOG" "$epoch" "$name | $ip | $cmd | client=$(verdict_label "$v")"
2039
  elif [ $(( $(date +%s) - epoch )) -gt 300 ]; then
2040
+ append_dated_log "$AUTH_LOG" "$epoch" "$name | $ip | $cmd | client=UNKNOWN CLIENT (check never resolved)"
2041
  else
2042
  printf '%s\t%s\t%s\n' "$epoch" "$name" "$cmd" >> "$tmp"
2043
  fi
 
2058
  fi
2059
  fi
2060
  [ -n "$epoch" ] || epoch=$(date +%s)
2061
+ append_dated_log "$AUTH_LOG" "$epoch" "$name | $ip | ${cmd%% *} ******** | client=$label (password not recorded)"
2062
  }
2063
 
2064
  # mask passwords in the log lines that leave the Space; the full command is
 
2092
  if ! auth_seen_recently "$name" "$cmd"; then
2093
  record_auth_seen "$name" "$cmd"
2094
  ip=$(last_ip_for "$name"); ip="${ip:-unknown}"
2095
+ append_dated_log "$AUTH_LOG" "$(date +%s)" "$name | $ip | $cmd | client=$(verdict_label "$verdict")"
2096
  fi ;;
2097
  esac ;;
2098
  esac
 
2135
  local name="$1" ip="${2:-unknown}" src="${3:-?}"
2136
  is_real_ip "$ip" && record_ip "$name" "$ip" "$src"
2137
  if is_online "$name"; then
2138
+ return 0 # this join is already in activity.log
2139
  fi
2140
  mark_online "$name"
2141
+ append_dated_log "$LOGIN_LOG" "$(date +%s)" "LOGIN | $name | $(ip_field "$name" "$ip" PENDING)${LOGIN_CLIENT_FIELD:-}"
2142
  set_verdict "$name" PENDING
2143
+ echo "[$(now_eastern)] [LOG] LOGIN $name (seen by $src)"
2144
  check_player_client "$name" "$ip" &
2145
  }
2146
 
 
2150
  mark_offline "$name"
2151
  v=$(verdict_for "$name")
2152
  ip=$(last_ip_for "$name")
2153
+ append_dated_log "$LOGIN_LOG" "$(date +%s)" "LOGOUT | $name | $(ip_field "$name" "${ip:-unknown}" "$v")$(client_field "$v")"
2154
+ echo "[$(now_eastern)] [LOG] LOGOUT $name (seen by $src)"
2155
  }
2156
 
2157
  # -------------------------------------------------------------
 
2179
 
2180
  playerlist_check() {
2181
  local raw names name ip
2182
+ PLAYERLIST_LAST="$(now_eastern)"
2183
  raw=$(mc_command "list" 2>/dev/null)
2184
  if [ -n "$raw" ]; then
2185
  PLAYERLIST_LAST="$PLAYERLIST_LAST got: $(printf '%s' "$raw" | tr -d '\n' | cut -c1-120)"
 
2211
 
2212
  playerlist_loop() {
2213
  while true; do
2214
+ sleep "${PLAYERLIST_POLL:-60}"
2215
  playerlist_check || true
2216
  done
2217
  }
 
2222
  # so the patterns match the payload only and never the prefix. Anything the
2223
  # patterns miss is still caught by the RCON player list (see playerlist_check).
2224
  handle_paper_line() {
2225
+ local line="${1%$'\r'}" name ip cmd v
2226
  local LOGIN_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] logged in with entity id'
2227
  local CMD_RE='([A-Za-z0-9_.-]{1,16}) issued server command: (.*)$'
2228
  local LEAVE_RE='([A-Za-z0-9_.-]{1,16}) (left the game|lost connection)'
 
2229
 
2230
  if [[ "$line" =~ $LOGIN_RE ]]; then
2231
  name="${BASH_REMATCH[1]}"; ip="${BASH_REMATCH[2]}"
 
2235
  v=$(verdict_for "$name")
2236
  cmd=$(mask_cmd "$name" "${BASH_REMATCH[2]}" "$v")
2237
  ip=$(last_ip_for "$name")
2238
+ append_dated_log "$CMD_LOG" "$(date +%s)" "COMMAND | $name | $(ip_field "$name" "${ip:-unknown}" "$v") | $cmd$(client_field "$v")"
2239
  elif [[ "$line" =~ $LEAVE_RE ]]; then
2240
  record_logout "${BASH_REMATCH[1]}" paper
2241
  fi
 
2253
  # never appear here - the auth lines come from Paper's console instead, which is
2254
  # why the plugins' password filters have to be patched (see AUTH LOG CAPTURE).
2255
  handle_bungee_line() {
2256
+ local line="${1%$'\r'}" name ip cmd v
2257
  local JOIN_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] <-> ServerConnector \[?[^]]*\]? has connected'
2258
  local SEEN_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] <-> InitialHandler has connected'
2259
  local QUIT_RE='([A-Za-z0-9_.-]{1,16})\[/([^]]+):[0-9]+\] <-> UpstreamBridge has disconnected'
2260
  local BC_RE='([A-Za-z0-9_.-]+)\]? executed command: (.*)$'
 
2261
 
2262
  if [[ "$line" =~ $JOIN_RE ]]; then
2263
  name="${BASH_REMATCH[1]}"; ip="${BASH_REMATCH[2]}"
 
2275
  v=$(verdict_for "$name")
2276
  cmd=$(mask_cmd "$name" "${BASH_REMATCH[2]}" "$v")
2277
  ip=$(last_ip_for "$name")
2278
+ append_dated_log "$CMD_LOG" "$(date +%s)" "COMMAND | $name | $(ip_field "$name" "${ip:-unknown}" "$v") | [bungee] $cmd$(client_field "$v")"
2279
  fi
2280
  }
2281
 
 
2396
  [ "${builtin%%|*}" = "$VERIFIED_CLIENT_BRAND" ] && return 0
2397
  echo ""
2398
  echo "!! VERIFIED CLIENT: the pair in the environment (${VERIFIED_CLIENT_BRAND})"
2399
+ echo "!! is not the one this build was made for (hidden, see security-logs/status.txt)."
2400
  echo "!! If you just rotated the client, delete the old secrets"
2401
  echo "!! (VERIFIED_CLIENT_BRAND / VERIFIED_CLIENT_UUID) and restart."
2402
  echo ""
 
2411
  echo ""
2412
  }
2413
 
2414
+ remember_verified_player() {
2415
+ local name="$1"
2416
+ mkdir -p "$PRIV_DIR" 2>/dev/null
2417
+ {
2418
+ flock -x 8
2419
+ grep -qxF "$name" "$VERIFIED_PLAYER_STATE" 2>/dev/null || printf '%s\n' "$name" >&8
2420
+ flock -u 8
2421
+ } 8>>"$VERIFIED_PLAYER_STATE"
2422
+ }
2423
+
2424
  check_player_client() {
2425
+ local name="$1" ip="$2" res verdict brand version uuid mcbrand now shown_ip
2426
  sleep 1 # give the Eagler handshake a moment to finish
2427
  res=$(query_client_brand "$name")
2428
  IFS='|' read -r verdict brand version uuid mcbrand <<< "$res"
 
2432
  IFS='|' read -r verdict brand version uuid mcbrand <<< "$res"
2433
  fi
2434
 
2435
+ now=$(date +%s)
2436
  verdict="${verdict:-UNKNOWN}"
2437
  set_verdict "$name" "$verdict"
2438
+ [ "$verdict" = VERIFIED ] && remember_verified_player "$name"
2439
  flush_pending_auth
2440
+ shown_ip=$(ip_field "$name" "$ip" "$verdict")
2441
+ if [ "$verdict" = VERIFIED ]; then
2442
+ # Keep the verified marker useful, but do not put the current brand or
2443
+ # UUID in the synced activity or console snapshots.
2444
+ brand="redacted"
2445
+ uuid="redacted"
 
 
2446
  fi
2447
+ append_dated_log "$CLIENT_LOG" "$now" "CHECK | $name | $shown_ip | client=$(verdict_label "$verdict") | brand=${brand:-?} | version=${version:-?} | uuid=${uuid:-?}"
2448
+ echo "[$(format_epoch_eastern "$now")] [CLIENT] $name ($shown_ip): ${verdict} / $(verdict_label "$verdict")"
2449
 
2450
  enforce_client_policy "$name" "$verdict"
2451
  }
 
2496
  }
2497
 
2498
  # =============================================================
2499
+ # Address report (one public view and one private view)
2500
  # =============================================================
2501
+ # Builds one deterministic snapshot with account/address pairs, shared IPs,
2502
+ # proxy-vs-player classification and dual-stack notes. The public report omits
2503
+ # every account ever marked VERIFIED; the private address history remains the
2504
+ # place to read the owner's real address.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2505
  ip_report_body() {
2506
+ local map="$1" out="$2" skip_verified="${3:-no}" skip="" name tmp
2507
  if [ "$skip_verified" = yes ]; then
2508
+ while IFS= read -r name; do
2509
+ [ -n "$name" ] || continue
2510
+ if [ "$(verdict_for "$name")" = VERIFIED ] || \
2511
+ grep -qxF "$name" "${VERIFIED_PLAYER_STATE:-/dev/null}" 2>/dev/null; then
2512
+ skip="${skip}${skip:+,}$name"
2513
+ fi
2514
+ done < <(awk -F'\t' 'NF>0 {print $1}' "$map" 2>/dev/null | sort -u)
2515
  fi
2516
+ tmp="${out}.tmp"
2517
+ mkdir -p "$(dirname "$out")" 2>/dev/null
2518
+ {
2519
+ printf '00\tIP ADDRESS REPORT\n'
2520
+ printf '01\tUpdated: %s\n' "$(now_eastern)"
2521
+ if [ "$skip_verified" = yes ]; then
2522
+ printf '02\tVerified-client addresses are omitted from this public report.\n'
2523
+ else
2524
+ printf '02\tPrivate report includes the verified-client real address.\n'
2525
+ fi
2526
+ awk -F'\t' -v skip="$skip" -v peersfile="${PROXY_PEERS_STATE:-}" '
2527
+ BEGIN {
2528
+ m = split(skip, a, ",")
2529
+ for (i = 1; i <= m; i++) if (a[i] != "") hidden[a[i]] = 1
2530
+ if (peersfile != "") {
2531
+ while ((getline l < peersfile) > 0) {
2532
+ p = index(l, "\t")
2533
+ if (p > 1) {
2534
+ addr = substr(l, p + 1)
2535
+ if (addr != "" && !(addr in peer)) { peer[addr] = 1; npeer++ }
2536
+ }
2537
  }
2538
+ close(peersfile)
2539
  }
2540
  }
2541
+ $1 != "" && $2 != "" && $2 != "unknown" && $2 != "hidden" && !($1 in hidden) {
2542
+ pair = $1 SUBSEP $2
2543
+ if (!(pair in seen_pair)) {
2544
+ seen_pair[pair] = 1
2545
+ owner[pair] = $1
2546
+ address[pair] = $2
2547
+ }
2548
+ hits[pair]++
2549
+ if (!source_seen[pair SUBSEP $3]++)
2550
+ sources[pair] = sources[pair] (sources[pair] ? ", " : "") $3
2551
+ if (!account_seen[$2 SUBSEP $1]++) {
2552
+ accounts[$2] = accounts[$2] (accounts[$2] ? ", " : "") $1
2553
+ account_count[$2]++
2554
+ }
2555
+ rows++
2556
+ if (!($2 in peer)) families[$1] = families[$1] (index($2, ":") ? "6" : "4")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2557
  }
2558
+ END {
2559
+ print "03\t"
2560
+ print "04\tACCOUNTS AND ADDRESSES"
2561
+ if (rows == 0) print "05\t(no real addresses recorded yet)"
2562
+ for (pair in hits)
2563
+ print "05\t" owner[pair] "\t" address[pair] "\t" sources[pair] " (seen " hits[pair] " time(s))"
2564
+ print "06\t"
2565
+ print "07\tADDRESSES SHARED BY ACCOUNTS"
2566
+ found = 0
2567
+ for (ip in account_count) if (account_count[ip] > 1) {
2568
+ print "08\t" ip "\t" accounts[ip]
2569
+ found = 1
2570
+ }
2571
+ if (!found) print "08\t(none)"
2572
+ print "09\t"
2573
+ print "10\tPROXY VS PLAYER ADDRESSES"
2574
+ if (npeer == 0) print "11\t(no proxy peer recorded yet)"
2575
+ proxied = 0; client = 0
2576
+ for (ip in account_count) {
2577
+ if (ip in peer) {
2578
+ print "11\t" ip "\tPROXY address (not a player)\t" account_count[ip] " account(s)"
2579
+ proxied++
2580
+ } else {
2581
+ print "11\t" ip "\treal client address\t" account_count[ip] " account(s)"
2582
+ client++
2583
+ }
2584
+ }
2585
+ if (rows > 0) {
2586
+ if (client == 0) print "12\tEvery logged address is a proxy peer; forwarded client IPs are unavailable."
2587
+ else if (proxied == 0) print "12\tAll logged addresses are client addresses (forwarded IP is working)."
2588
+ else print "12\tBoth proxy and client addresses are present; some connections lack a forwarded IP."
2589
+ }
2590
+ print "13\t"
2591
+ print "14\tACCOUNTS SEEN OVER BOTH IPv4 AND IPv6"
2592
+ duals = 0
2593
+ for (n in families) if (families[n] ~ /4/ && families[n] ~ /6/) {
2594
+ print "15\t" n "\tone device/account using both protocols"
2595
  duals++
2596
  }
2597
+ if (!duals) print "15\t(none)"
2598
+ }' "$map"
2599
+ } | LC_ALL=C sort -t "$(printf '\t')" -k1,1 -k2,2 -k3,3 | cut -f2- > "$tmp"
2600
+ mv "$tmp" "$out"
2601
  }
2602
 
2603
  # What "the IP in the log" really is: the player's own address when a forwarded
 
2615
  }
2616
 
2617
  # =============================================================
2618
+ # LOGGER STATUS (security-logs/status.txt)
2619
  # =============================================================
2620
+ # This is a small, replace-in-place health snapshot. It deliberately avoids
2621
+ # rescanning the growing event log once a minute; raw parser input is in the
2622
+ # single, masked console snapshot instead.
 
 
2623
  write_logger_status() {
2624
+ local out="${STATUS_FILE:-$SEC_DIR/status.txt}" tmp paper_bytes bungee_bytes activity_bytes
2625
  [ -n "$SEC_DIR" ] || return 0
2626
  mkdir -p "$SEC_DIR" 2>/dev/null
2627
  tmp="${out}.tmp"
2628
+ paper_bytes=$(stat -c%s /tmp/paper.log 2>/dev/null || echo 0)
2629
+ bungee_bytes=$(stat -c%s /tmp/bungee.log 2>/dev/null || echo 0)
2630
+ activity_bytes=$(stat -c%s "$ACTIVITY_LOG" 2>/dev/null || echo 0)
2631
  {
2632
+ echo "Server log status"
2633
+ echo "Updated : $(now_eastern)"
2634
+ echo "Timezone : America/New_York (EST/EDT), 12-hour clock"
2635
+ echo "Build : ${SCRIPT_VERSION:-unknown}"
2636
+ echo "Online now : $(tr '\n' ' ' < "${ONLINE_STATE:-/dev/null}" 2>/dev/null)"
2637
+ echo "Activity log : $activity_bytes bytes"
2638
+ echo "Last activity : $(tail -n 1 "$ACTIVITY_LOG" 2>/dev/null || echo none)"
2639
+ echo "Paper console : $paper_bytes bytes in /tmp/paper.log"
2640
+ echo "Bungee console: $bungee_bytes bytes in /tmp/bungee.log"
2641
+ echo "Player list : ${PLAYERLIST_LAST:-not polled yet}"
2642
+ echo "Client IPs : $(real_client_ip_line)"
2643
+ echo "Proxy peers : $(proxy_peer_list 2>/dev/null | tr '\n' ' ')"
2644
+ echo "IP evidence : $(ip_evidence_line)"
2645
+ echo "Login capture : ${AUTH_PATCH_STATUS:-not run}"
2646
  if [ "$VERIFIED_CLIENT_CONFIGURED" = true ]; then
2647
+ echo "Verified client: configured (value kept out of synced logs)"
 
2648
  else
2649
+ echo "Verified client: NOT CONFIGURED (nobody is marked as you)"
2650
  fi
2651
  local _vcproblem
2652
  _vcproblem=$(verified_client_problem)
2653
  [ -n "$_vcproblem" ] && printf '%s\n' "$_vcproblem" | sed 's/^/ !! /'
2654
+ echo "Enforcement : ENFORCE_VERIFIED_CLIENT=${ENFORCE_VERIFIED_CLIENT:-false} (false = everybody may join)"
 
 
 
 
 
 
 
 
 
2655
  } > "$tmp" 2>/dev/null
2656
  mv "$tmp" "$out" 2>/dev/null
2657
  }
2658
 
2659
  report_shared_ips() {
2660
+ local now last
2661
  flush_pending_auth
2662
+ now=$(date +%s)
2663
+ last=$(cat "$REPORT_STATE" 2>/dev/null || echo 0)
2664
+ if [[ "$last" =~ ^[0-9]+$ ]] && [ $((now - last)) -lt "$REPORT_INTERVAL" ] && \
2665
+ [ -s "$ADDRESS_REPORT" ] && \
2666
+ { [ "$PRIVATE_IP_LOG" != true ] || [ -s "$PRIVATE_ADDRESS_REPORT" ]; }; then
2667
+ return 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2668
  fi
2669
+ proxy_peers_record
2670
+ ip_report_body "$IP_MAP" "$ADDRESS_REPORT" yes
2671
+ if [ "$PRIVATE_IP_LOG" = true ]; then
2672
+ ip_report_body "$IP_MAP" "$PRIVATE_ADDRESS_REPORT" no
2673
+ fi
2674
+ printf '%s\n' "$now" > "$REPORT_STATE"
2675
  }
2676
 
2677
  # =============================================================
 
2832
  if not root.is_dir():
2833
  fail(f"{root} is not a directory")
2834
 
 
2835
  remote = list_remote(api, args.bucket_id, args.prefix)
2836
 
2837
+ # Walk/stat the staged tree once. The previous two-pass implementation
2838
+ # repeated os.walk + stat over every world file on every Python fallback
2839
+ # sync, even though the staging tree is immutable for the duration of the
2840
+ # upload. Keep only the local names needed by --delete and the changed-file
2841
+ # upload list; this reduces work and avoids comparing two different walks.
2842
+ local = set()
2843
+ add = []
2844
+ for rel, path, size in iter_local(root):
2845
+ local.add(rel)
2846
+ if remote.get(rel) != size:
2847
+ add.append((str(path), join(args.prefix, rel), size))
2848
  delete = [join(args.prefix, rel) for rel in remote
2849
  if args.delete and rel not in local]
2850
 
 
2930
  }
2931
  # <<< embedded bucket_sync.py <<<
2932
 
2933
+ # >>> embedded log_migrate.py (generated from tools/log_migrate.py) >>>
2934
+ write_log_migrator_py() {
2935
+ mkdir -p "$(dirname "$LOG_MIGRATOR_PY")" 2>/dev/null
2936
+ cat > "$LOG_MIGRATOR_PY" <<'LOG_MIGRATOR_PY_EOF'
2937
+ #!/usr/bin/env python3
2938
+ """Migrate the old many-file logs into the compact, date-divided log layout.
2939
+
2940
+ The old Docker image used UTC by default. Its timestamps are converted to the
2941
+ requested display timezone; new events are timestamped by start.sh directly in
2942
+ that zone. This does not rewrite or guess timestamps in the live Paper logs.
2943
+ """
2944
+ from __future__ import annotations
2945
+
2946
+ import argparse
2947
+ import os
2948
+ import re
2949
+ import sys
2950
+ import tempfile
2951
+ from dataclasses import dataclass
2952
+ from datetime import datetime, timezone
2953
+ from pathlib import Path
2954
+ from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
2955
+
2956
+ FORMAT_MARKER = "# log-format: 2"
2957
+ LEGACY_STAMP = re.compile(r"^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) \| (.*)$")
2958
+
2959
+ VERDICT_LABELS = {
2960
+ "VERIFIED": "VERIFIED CLIENT",
2961
+ "UNVERIFIED": "OTHER EAGLERCRAFT CLIENT",
2962
+ "VANILLA": "JAVA CLIENT",
2963
+ "PENDING": "CHECK PENDING",
2964
+ "CONSOLE_DOWN": "CONSOLE DOWN",
2965
+ "UNKNOWN": "UNKNOWN CLIENT",
2966
+ }
2967
+
2968
+
2969
+ @dataclass(frozen=True)
2970
+ class Record:
2971
+ epoch: float
2972
+ order: int
2973
+ message: str
2974
+
2975
+
2976
+ def _legacy_epoch(value: str) -> float:
2977
+ """The old Debian image used UTC (its default); convert that wall time."""
2978
+ parsed = datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
2979
+ return parsed.replace(tzinfo=timezone.utc).timestamp()
2980
+
2981
+
2982
+ def _local_stamp(epoch: float, zone: ZoneInfo) -> tuple[str, str, str]:
2983
+ local = datetime.fromtimestamp(epoch, zone)
2984
+ day = local.strftime("%Y-%m-%d")
2985
+ stamp = local.strftime("%Y-%m-%d %I:%M:%S %p %Z")
2986
+ weekday = f"{local.strftime('%A, %B')} {local.day}, {local.year}"
2987
+ return day, stamp, weekday
2988
+
2989
+
2990
+ def _read_timestamped(path: Path, zone: ZoneInfo, convert, order_start: int) -> list[Record]:
2991
+ records: list[Record] = []
2992
+ try:
2993
+ lines = path.read_text(encoding="utf-8", errors="replace").splitlines()
2994
+ except OSError:
2995
+ return records
2996
+
2997
+ for index, line in enumerate(lines):
2998
+ match = LEGACY_STAMP.match(line)
2999
+ if not match:
3000
+ if not line.strip() or line.startswith("#") or line.startswith("==="):
3001
+ continue
3002
+ # Do not silently throw away a malformed historical row. Keep it
3003
+ # in a dated LEGACY event with an explicit unavailable timestamp.
3004
+ epoch = datetime.now(timezone.utc).timestamp()
3005
+ records.append(Record(epoch, order_start + index, f"LEGACY | timestamp unavailable | {line}"))
3006
+ continue
3007
+ epoch = _legacy_epoch(match.group(1))
3008
+ message = convert(match.group(2))
3009
+ if message:
3010
+ records.append(Record(epoch, order_start + index, message))
3011
+ return records
3012
+
3013
+
3014
+ def _activity_records(security_dir: Path) -> list[Record]:
3015
+ records: list[Record] = []
3016
+ checks_path = security_dir / "client-checks.log"
3017
+ has_checks = checks_path.is_file() and checks_path.stat().st_size > 0
3018
+
3019
+ def keep_login(payload: str) -> str:
3020
+ parts = payload.split(" | ", 1)
3021
+ kind = parts[0]
3022
+ if kind == "VERIFY":
3023
+ # The old login file and client-checks.log both stored the same
3024
+ # result. Prefer the richer check row below, exactly once.
3025
+ if has_checks:
3026
+ return ""
3027
+ legacy = parts[1] if len(parts) > 1 else "legacy verification"
3028
+ legacy = re.sub(r"(?i)(brand|uuid)=([^|]*)", r"\1=redacted", legacy)
3029
+ return "CHECK | " + legacy
3030
+ return payload
3031
+
3032
+ def command(payload: str) -> str:
3033
+ return "COMMAND | " + payload
3034
+
3035
+ def check(payload: str) -> str:
3036
+ parts = payload.split(" | ")
3037
+ if len(parts) < 4:
3038
+ return "CHECK | " + payload
3039
+ verdict, name, ip = parts[0], parts[1], parts[2]
3040
+ label = VERDICT_LABELS.get(verdict, "UNKNOWN CLIENT")
3041
+ details = parts[3:]
3042
+ if verdict == "VERIFIED":
3043
+ # Do not move the verified client's real address, brand or UUID
3044
+ # into the public activity log. The private address history remains
3045
+ # the owner-readable source of the actual IP.
3046
+ ip = "hidden"
3047
+ version = next((p for p in details if p.startswith("version=")), "version=redacted")
3048
+ details = ["brand=redacted", version, "uuid=redacted"]
3049
+ return "CHECK | " + " | ".join([name, ip, f"client={label}", *details])
3050
+
3051
+ sources = (
3052
+ ("logins.log", keep_login),
3053
+ ("commands.log", command),
3054
+ ("client-checks.log", check),
3055
+ )
3056
+ for source_index, (filename, transform) in enumerate(sources):
3057
+ path = security_dir / filename
3058
+ records.extend(_read_timestamped(path, ZoneInfo("UTC"), transform,
3059
+ source_index * 1_000_000))
3060
+ records.sort(key=lambda row: (row.epoch, row.order))
3061
+ return records
3062
+
3063
+
3064
+ def _write_dated(path: Path, records: list[Record], zone: ZoneInfo, marker_note: str) -> None:
3065
+ path.parent.mkdir(parents=True, exist_ok=True)
3066
+ lines = [f"{FORMAT_MARKER}; timezone={zone.key}; 12-hour clock", marker_note]
3067
+ current_day = None
3068
+ for record in records:
3069
+ day, stamp, weekday = _local_stamp(record.epoch, zone)
3070
+ if day != current_day:
3071
+ if current_day is not None:
3072
+ lines.append("")
3073
+ lines.append(f"==================== {weekday} | {day} ====================")
3074
+ lines.append("")
3075
+ current_day = day
3076
+ lines.append(f"{stamp} | {record.message}")
3077
+ payload = "\n".join(lines) + "\n"
3078
+ mode = 0o600 if "private-logs" in path.parts else 0o644
3079
+ try:
3080
+ mode = path.stat().st_mode & 0o777
3081
+ except OSError:
3082
+ pass
3083
+ fd, temp_name = tempfile.mkstemp(prefix=f".{path.name}.", dir=path.parent)
3084
+ try:
3085
+ with os.fdopen(fd, "w", encoding="utf-8", newline="\n") as stream:
3086
+ stream.write(payload)
3087
+ stream.flush()
3088
+ os.fsync(stream.fileno())
3089
+ os.chmod(temp_name, mode)
3090
+ os.replace(temp_name, path)
3091
+ finally:
3092
+ try:
3093
+ os.unlink(temp_name)
3094
+ except FileNotFoundError:
3095
+ pass
3096
+
3097
+
3098
+ def _has_marker(path: Path) -> bool:
3099
+ try:
3100
+ with path.open("r", encoding="utf-8", errors="replace") as stream:
3101
+ return FORMAT_MARKER in stream.readline()
3102
+ except OSError:
3103
+ return False
3104
+
3105
+
3106
+ def _migrate_append_log(path: Path, zone: ZoneInfo, transform=lambda x: x) -> bool:
3107
+ if _has_marker(path):
3108
+ return False
3109
+ records = _read_timestamped(path, zone, transform, 0)
3110
+ note = f"# Previous timestamps converted from the old container's UTC clock to {zone.key}."
3111
+ _write_dated(path, records, zone, note)
3112
+ return bool(records)
3113
+
3114
+
3115
+ def _verified_names(security_dir: Path, private_dir: Path) -> set[str]:
3116
+ """Names already identified as the owner, from durable historical evidence."""
3117
+ names: set[str] = set()
3118
+
3119
+ state = private_dir / "verified-players.txt"
3120
+ if state.is_file():
3121
+ names.update(line.strip().casefold() for line in state.read_text(
3122
+ encoding="utf-8", errors="replace").splitlines() if line.strip())
3123
+
3124
+ for filename in ("client-checks.log", "logins.log"):
3125
+ path = security_dir / filename
3126
+ if not path.is_file():
3127
+ continue
3128
+ for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
3129
+ match = LEGACY_STAMP.match(line)
3130
+ if not match:
3131
+ continue
3132
+ parts = match.group(2).split(" | ")
3133
+ if not parts:
3134
+ continue
3135
+ if filename == "client-checks.log" and parts[0].upper() == "VERIFIED" and len(parts) > 1:
3136
+ names.add(parts[1].casefold())
3137
+ elif filename == "client-checks.log" and parts[0].upper() == "CHECK" and len(parts) > 1:
3138
+ if any("VERIFIED CLIENT" in part.upper() for part in parts[2:]):
3139
+ names.add(parts[1].casefold())
3140
+ elif filename == "logins.log" and parts[0].upper() in {"VERIFY", "CHECK"} and len(parts) > 1:
3141
+ if any("VERIFIED" in part.upper() for part in parts[2:]):
3142
+ names.add(parts[1].casefold())
3143
+ return names
3144
+
3145
+
3146
+ def _mask_verified_auth(names: set[str]):
3147
+ """Never migrate a verified owner's historical auth password in clear."""
3148
+ auth_command = re.compile(
3149
+ r"^([^|]+) \| ([^|]+) \| (/(?:login|l|log|register|reg|unregister|unreg|"
3150
+ r"changepassword|changepass|cp|authme))\b.*$", re.IGNORECASE)
3151
+
3152
+ def transform(payload: str) -> str:
3153
+ match = auth_command.match(payload)
3154
+ if not match or match.group(1).strip().casefold() not in names:
3155
+ return payload
3156
+ name = match.group(1).strip()
3157
+ command = match.group(3)
3158
+ return f"{name} | hidden | {command} ******** | client=VERIFIED CLIENT (password not recorded)"
3159
+
3160
+ return transform
3161
+
3162
+
3163
+ def _migrate_activity(security_dir: Path, zone: ZoneInfo) -> int:
3164
+ target = security_dir / "activity.log"
3165
+ if _has_marker(target):
3166
+ return 0
3167
+ records = _activity_records(security_dir)
3168
+ note = (f"# Previous timestamps converted from UTC to {zone.key}; "
3169
+ "VERIFIED brand and UUID values are redacted.")
3170
+ _write_dated(target, records, zone, note)
3171
+ return len(records)
3172
+
3173
+
3174
+ def _migrate_addresses(private_dir: Path, zone: ZoneInfo) -> int:
3175
+ target = private_dir / "addresses.log"
3176
+ if _has_marker(target):
3177
+ return 0
3178
+
3179
+ records: list[Record] = []
3180
+ candidates = [private_dir / "player-ips.log"]
3181
+ # The old real-IP login file is another copy of information in the IP map.
3182
+ # Only use it to fill a missing account/address pair; keep all sightings
3183
+ # from player-ips.log as the canonical private history.
3184
+ seen: set[tuple[str, str]] = set()
3185
+
3186
+ for line_index, line in enumerate(candidates[0].read_text(encoding="utf-8", errors="replace").splitlines()
3187
+ if candidates[0].exists() else []):
3188
+ match = LEGACY_STAMP.match(line)
3189
+ if not match:
3190
+ continue
3191
+ rest = match.group(2).split(" | ")
3192
+ if len(rest) < 3:
3193
+ continue
3194
+ name, ip, source = rest[0], rest[1], rest[2]
3195
+ source = source.removeprefix("source=")
3196
+ seen.add((name, ip))
3197
+ records.append(Record(_legacy_epoch(match.group(1)), line_index,
3198
+ f"IP | {name} | {ip} | source={source}"))
3199
+
3200
+ private_logins = private_dir / "logins-real-ips.log"
3201
+ if private_logins.exists():
3202
+ for line_index, line in enumerate(private_logins.read_text(encoding="utf-8", errors="replace").splitlines(),
3203
+ start=len(records)):
3204
+ match = LEGACY_STAMP.match(line)
3205
+ if not match:
3206
+ continue
3207
+ rest = match.group(2).split(" | ")
3208
+ if len(rest) < 4 or rest[0] != "LOGIN":
3209
+ continue
3210
+ name, ip = rest[1], rest[2]
3211
+ if ip in {"", "unknown", "hidden"} or (name, ip) in seen:
3212
+ continue
3213
+ seen.add((name, ip))
3214
+ records.append(Record(_legacy_epoch(match.group(1)), line_index,
3215
+ f"IP | {name} | {ip} | source=legacy-login"))
3216
+
3217
+ records.sort(key=lambda row: (row.epoch, row.order))
3218
+ note = f"# Private address history; previous timestamps converted from UTC to {zone.key}."
3219
+ _write_dated(target, records, zone, note)
3220
+ return len(records)
3221
+
3222
+
3223
+ def migrate(security_dir: Path, private_dir: Path, zone_name: str) -> tuple[int, int, list[Path]]:
3224
+ try:
3225
+ zone = ZoneInfo(zone_name)
3226
+ except ZoneInfoNotFoundError as exc:
3227
+ raise SystemExit(f"unknown timezone {zone_name!r}; install tzdata") from exc
3228
+ security_dir.mkdir(parents=True, exist_ok=True)
3229
+ private_dir.mkdir(parents=True, exist_ok=True)
3230
+
3231
+ # Read ownership evidence before any legacy inputs are removed. The old
3232
+ # private auth log remains available for other players, but a verified
3233
+ # owner's legacy credentials are never copied into the new bucket log.
3234
+ verified_names = _verified_names(security_dir, private_dir)
3235
+ activity_count = _migrate_activity(security_dir, zone)
3236
+ _migrate_append_log(private_dir / "auth.log", zone, _mask_verified_auth(verified_names))
3237
+ address_count = _migrate_addresses(private_dir, zone)
3238
+
3239
+ # These were duplicate views of the same login/check/IP data. The new
3240
+ # per-directory sync uses --delete so these also disappear from the bucket.
3241
+ legacy_paths = [
3242
+ security_dir / name for name in (
3243
+ "logins.log", "commands.log", "client-checks.log", "shared-ips.txt",
3244
+ "ip-report.log", "logger-status.log", "proxy-peers.txt",
3245
+ )
3246
+ ] + [
3247
+ private_dir / name for name in (
3248
+ "player-ips.log", "ip-report-private.log", "logins-real-ips.log",
3249
+ "shared-ips-private.txt",
3250
+ )
3251
+ ]
3252
+ removed = []
3253
+ for path in legacy_paths:
3254
+ try:
3255
+ path.unlink()
3256
+ removed.append(path)
3257
+ except FileNotFoundError:
3258
+ pass
3259
+ return activity_count, address_count, removed
3260
+
3261
+
3262
+ def main(argv: list[str] | None = None) -> int:
3263
+ parser = argparse.ArgumentParser(description=__doc__)
3264
+ parser.add_argument("security_dir", type=Path)
3265
+ parser.add_argument("private_dir", type=Path)
3266
+ parser.add_argument("--timezone", default="America/New_York")
3267
+ args = parser.parse_args(argv)
3268
+ activity_count, address_count, removed = migrate(args.security_dir, args.private_dir, args.timezone)
3269
+ print(f"log-migrate: activity_rows={activity_count} address_rows={address_count} "
3270
+ f"legacy_files_removed={len(removed)} timezone={args.timezone}", flush=True)
3271
+ return 0
3272
+
3273
+
3274
+ if __name__ == "__main__":
3275
+ sys.exit(main())
3276
+ LOG_MIGRATOR_PY_EOF
3277
+ }
3278
+ ensure_log_migrator_py() {
3279
+ [ -s "$LOG_MIGRATOR_PY" ] || write_log_migrator_py
3280
+ }
3281
+ # <<< embedded log_migrate.py <<<
3282
+
3283
+
3284
+ # Bucket sync, staging copies and log parsing compete with Paper for the
3285
+ # container's CPU and disk. Run their heavyweight subprocesses at lower
3286
+ # scheduling priority where the container allows it. This reduces contention,
3287
+ # but it does not impose a CPU cap or guarantee a particular TPS/lag outcome;
3288
+ # measure a live Space before claiming a gameplay improvement. Probe ionice and
3289
+ # retain nice as a fallback when I/O priority is unavailable.
3290
  BG_PRIORITY=()
3291
  if command -v ionice >/dev/null 2>&1 && ionice -c3 true >/dev/null 2>&1; then
3292
  BG_PRIORITY=(nice -n 19 ionice -c3)
 
3394
  }
3395
 
3396
  hf_restore_saves() {
3397
+ local out rc
3398
  echo " Restoring game data..."
3399
+ out=$("${BG_PRIORITY[@]}" hf buckets sync "${HF_BUCKET_HANDLE}/game-data" "$BACKEND_DIR" 2>&1); rc=$?
3400
+ printf '%s\n' "$out" | tail -5
3401
+ [ $rc -eq 0 ] || echo " [BUCKET] restore returned $rc; starting with whatever data is available"
3402
  for dir in $SAVE_DIRS; do
3403
  [ -e "$BACKEND_DIR/$dir" ] && echo " Found: $dir"
3404
  done
3405
  }
3406
 
3407
+ bucket_sync_lock() {
3408
+ mkdir -p "$(dirname "$BUCKET_SYNC_LOCK")" 2>/dev/null || return 1
3409
+ exec 8>>"$BUCKET_SYNC_LOCK"
3410
+ flock -x 8
3411
+ }
3412
+
3413
+ bucket_sync_unlock() {
3414
+ flock -u 8 2>/dev/null || true
3415
+ exec 8>&-
3416
+ }
3417
+
3418
+ write_console_snapshot() { # $1 = destination file
3419
+ local out="$1" tmp captured
3420
+ mkdir -p "$(dirname "$out")" 2>/dev/null
3421
+ tmp="${out}.tmp"
3422
+ captured=$(now_eastern)
3423
+ {
3424
+ echo "Server console snapshot"
3425
+ echo "Captured: $captured (America/New_York; 12-hour ET)"
3426
+ echo "Player events are in security-logs/activity.log."
3427
+ if [ -f /tmp/paper.log ]; then
3428
+ echo ""
3429
+ echo "==================== PAPER (last ${CONSOLE_LOG_LINES} lines) ===================="
3430
+ "${BG_PRIORITY[@]}" tail -n "$CONSOLE_LOG_LINES" /tmp/paper.log 2>/dev/null \
3431
+ | mask_console_tail | sed 's/^/[PAPER] /'
3432
+ fi
3433
+ if [ -f /tmp/bungee.log ]; then
3434
+ echo ""
3435
+ echo "==================== BUNGEE (last ${CONSOLE_LOG_LINES} lines) ===================="
3436
+ "${BG_PRIORITY[@]}" tail -n "$CONSOLE_LOG_LINES" /tmp/bungee.log 2>/dev/null \
3437
+ | mask_console_tail | sed 's/^/[BUNGEE] /'
3438
+ fi
3439
+ } > "$tmp"
3440
+ mv "$tmp" "$out"
3441
+ }
3442
+
3443
+ # A full world snapshot is the only sync that walks the entire game-data tree.
3444
+ # It runs at low CPU/I/O priority and, by default, only every ten minutes. Log
3445
+ # reports are not regenerated here and this loop cannot overlap the log sync.
3446
  hf_push_saves() {
3447
+ local STAGING="$FULL_STAGING" item STARTED TOOK rc
 
3448
  STARTED=$(date +%s)
3449
+ bucket_sync_lock || { echo "[SYNC] FAIL $(now_eastern) - could not acquire bucket lock"; return 1; }
3450
+ "${BG_PRIORITY[@]}" rm -rf "$STAGING" && mkdir -p "$STAGING"
3451
  for item in $SAVE_DIRS; do
3452
+ # The current console snapshot is generated below; do not copy an old
3453
+ # paper.log/bungee.log pair from a previous Space instance.
3454
+ [ "$item" = logs ] && continue
3455
  if [ -e "$BACKEND_DIR/$item" ]; then
3456
  mkdir -p "$STAGING/$(dirname "$item")"
3457
  "${BG_PRIORITY[@]}" cp -a "$BACKEND_DIR/$item" "$STAGING/$item"
3458
  fi
3459
  done
3460
+ mkdir -p "$STAGING/logs"
3461
+ if [ "$SYNC_CONSOLE_LOGS" = true ]; then
3462
+ write_console_snapshot "$STAGING/logs/console.log"
3463
+ fi
3464
  if bucket_sync_dir "$STAGING" "${HF_BUCKET_HANDLE}/game-data" --delete; then
3465
  TOOK=$(($(date +%s) - STARTED))
3466
+ echo "[SYNC] OK $(now_eastern) via ${BUCKET_VIA:-?} (took ${TOOK}s)"
3467
+ rc=0
3468
  else
3469
  TOOK=$(($(date +%s) - STARTED))
3470
+ echo "[SYNC] FAIL $(now_eastern) - ${BUCKET_ERROR:-unknown error} (took ${TOOK}s)"
3471
+ rc=1
3472
  fi
3473
+ "${BG_PRIORITY[@]}" rm -rf "$STAGING"
3474
+ bucket_sync_unlock
3475
+ return "$rc"
3476
  }
3477
 
3478
+ # Log uploads are scoped to their own bucket prefixes. The old implementation
3479
+ # synced the whole game-data tree every minute (including all world regions),
3480
+ # and ran concurrently with the full backup; that duplicated file walking and
3481
+ # caused the large CPU bursts. The three small prefix syncs are serialized with
3482
+ # the world snapshot and prune obsolete duplicate log files safely.
3483
  hf_push_logs() {
3484
+ local STAGING="$LOG_STAGING" STARTED TOOK rc failed=0 files
3485
+ STARTED=$(date +%s)
3486
+ bucket_sync_lock || { echo "[LOGSYNC] FAIL $(now_eastern) - could not acquire bucket lock"; return 1; }
3487
  flush_pending_auth
3488
  report_shared_ips
3489
+ write_logger_status 2>/dev/null
3490
+ "${BG_PRIORITY[@]}" rm -rf "$STAGING" && mkdir -p "$STAGING/security-logs" "$STAGING/private-logs" "$STAGING/logs"
3491
+ [ -d "$SEC_DIR" ] && "${BG_PRIORITY[@]}" cp -a "$SEC_DIR/." "$STAGING/security-logs/"
 
 
3492
  if [ "$SYNC_PRIVATE_LOGS" = true ] && [ -d "$PRIV_DIR" ]; then
3493
+ "${BG_PRIORITY[@]}" cp -a "$PRIV_DIR/." "$STAGING/private-logs/"
3494
  fi
3495
  if [ "$SYNC_CONSOLE_LOGS" = true ]; then
3496
+ write_console_snapshot "$STAGING/logs/console.log"
 
 
 
 
3497
  fi
3498
+ files=$(cd "$STAGING" 2>/dev/null && find . -type f -printf '%P(%s) ' 2>/dev/null | sort)
3499
+
3500
+ bucket_sync_dir "$STAGING/security-logs" "${HF_BUCKET_HANDLE}/game-data/security-logs" --delete || failed=1
3501
+ # When disabled, sync an empty prefix to remove previously uploaded private
3502
+ # passwords/IPs rather than leaving sensitive stale copies in the bucket.
3503
+ bucket_sync_dir "$STAGING/private-logs" "${HF_BUCKET_HANDLE}/game-data/private-logs" --delete || failed=1
3504
+ # An empty directory intentionally removes stale paper.log/bungee.log copies.
3505
+ bucket_sync_dir "$STAGING/logs" "${HF_BUCKET_HANDLE}/game-data/logs" --delete || failed=1
3506
+
3507
+ TOOK=$(($(date +%s) - STARTED))
3508
+ if [ "$failed" -eq 0 ]; then
3509
+ echo "[LOGSYNC] OK $(now_eastern) via ${BUCKET_VIA:-?} (took ${TOOK}s)"
3510
+ echo " $(printf '%s' "$files")"
3511
+ rc=0
3512
  else
3513
+ echo "[LOGSYNC] FAIL $(now_eastern) - ${BUCKET_ERROR:-one or more log prefixes failed} (took ${TOOK}s)"
3514
+ rc=1
3515
  fi
3516
+ "${BG_PRIORITY[@]}" rm -rf "$STAGING"
3517
+ bucket_sync_unlock
3518
+ return "$rc"
3519
  }
3520
 
3521
  hf_sync_loop() {
3522
+ renice -n 19 -p "$BASHPID" >/dev/null 2>&1 || true
3523
  while true; do
3524
  sleep "$SYNC_INTERVAL"
3525
  hf_push_saves
 
3527
  }
3528
 
3529
  log_sync_loop() {
3530
+ renice -n 19 -p "$BASHPID" >/dev/null 2>&1 || true
3531
  while true; do
3532
  hf_push_logs
3533
  sleep "$LOG_SYNC_INTERVAL"
 
3543
  bucket_write_probe || true
3544
  hf_restore_saves
3545
  mkdir -p "$SEC_DIR" "$PRIV_DIR"
3546
+ ensure_log_migrator_py
3547
+ python3 "$LOG_MIGRATOR_PY" "$SEC_DIR" "$PRIV_DIR" --timezone "$TZ"
3548
+ touch "$ACTIVITY_LOG" "$AUTH_LOG"
3549
+ restore_ip_map
3550
  : > "$ONLINE_STATE"
3551
  echo ""
3552
 
 
3891
  else
3892
  echo " bucket uploads: FAILING - see the [BUCKET] lines above"
3893
  fi
3894
+ echo " security-logs/{activity.log,addresses.txt,status.txt}"
 
3895
  [ "$SYNC_PRIVATE_LOGS" = true ] && \
3896
+ echo " private-logs/{auth.log,addresses.log,addresses.txt}"
3897
+ [ "$SYNC_CONSOLE_LOGS" = true ] && \
3898
+ echo " logs/console.log (masked Paper + Bungee snapshot)"
3899
  if [ "$VERIFIED_CLIENT_CONFIGURED" = true ]; then
3900
  echo " Verified client: $VERIFIED_CLIENT_BRAND (uuid $VERIFIED_CLIENT_UUID)"
3901
  echo " pair from: $VERIFIED_CLIENT_SOURCE$([ "$VERIFIED_CLIENT_SOURCE" = environment ] && echo ' (Space secrets override the built-in pair)')"
 
3904
  echo " the Space's Variables and secrets (nobody is marked as you)"
3905
  fi
3906
  echo " everybody may join (ENFORCE_VERIFIED_CLIENT=$ENFORCE_VERIFIED_CLIENT); the"
3907
+ echo " verified marker is retained; IP and brand/UUID are hidden from synced logs"
3908
  echo " every brand ever committed to the repo (Eaglercraft[VER], EaglercraftX[V2],"
3909
  echo " the stock one) is refused - it cannot make anybody 'verified' any more"
3910
  echo " real client IPs: $(forward_ip_setting 2>/dev/null)"
 
3992
  fi
3993
 
3994
  if ! kill -0 $BACKEND_PID 2>/dev/null; then
3995
+ echo "[$(now_eastern)] Paper crashed — restarting..."
3996
  hf_push_saves
3997
  IDLE_MODE=false
3998
  start_paper
 
4011
  fi
4012
 
4013
  if ! kill -0 $BUNGEE_PID 2>/dev/null; then
4014
+ echo "[$(now_eastern)] BungeeCord crashed — restarting..."
4015
  patch_eagler_port
4016
  start_bungee
4017
  fi
 
4022
  fi
4023
 
4024
  if [ -z "${LOGSYNC_PID:-}" ] || ! kill -0 "$LOGSYNC_PID" 2>/dev/null; then
4025
+ echo "[$(now_eastern)] Log sync died — restarting..."
4026
  log_sync_loop &
4027
  LOGSYNC_PID=$!
4028
  fi
 
4033
  fi
4034
 
4035
  if ! kill -0 "$SECLOG_PID" 2>/dev/null; then
4036
+ echo "[$(now_eastern)] Security logger died — restarting..."
4037
  start_security_logger
4038
  fi
4039
 
 
4055
  CURRENT_LINE=$(wc -l < /tmp/paper.log 2>/dev/null || echo 0)
4056
  if [ "$CURRENT_LINE" -gt "$LAST_LOG_LINE" ]; then
4057
  NEW_ERRORS=$(tail -n +"$((LAST_LOG_LINE + 1))" /tmp/paper.log | grep -c "ERROR\|SEVERE" || echo 0)
4058
+ [ "$NEW_ERRORS" -gt 0 ] && echo "[$(now_eastern)] $NEW_ERRORS errors" && \
4059
  tail -n +"$((LAST_LOG_LINE + 1))" /tmp/paper.log | grep "ERROR\|SEVERE" | tail -3
4060
  LAST_LOG_LINE=$CURRENT_LINE
4061
  fi
 
4068
  # Truncate in place so Java and the security logger keep working
4069
  tail -1000 "$LF" > "${LF}.old"
4070
  : > "$LF"
4071
+ echo "[$(now_eastern)] Trimmed $(basename $LF)"
4072
  fi
4073
  done
4074
  LAST_LOG_LINE=$(wc -l < /tmp/paper.log 2>/dev/null || echo 0)