Relax rate limits, reduce SSH warning noise, add step logging helpers
This commit is contained in:
1 parent
7f3ef08e7e
commit
27d87b3d31
4 files changed
+68
-15
No files matched your search
+10
-10
@@ -41,7 +41,7 @@ def register_api_routes(app, services, settings):
|
|||||||
limiter = Limiter(
|
limiter = Limiter(
|
||||||
app=app,
|
app=app,
|
||||||
key_func=get_remote_address,
|
key_func=get_remote_address,
|
||||||
default_limits=["200 per day", "50 per hour"],
|
default_limits=["2000 per day", "500 per hour"],
|
||||||
storage_uri="memory://",
|
storage_uri="memory://",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -53,7 +53,7 @@ def register_api_routes(app, services, settings):
|
|||||||
# Server actions
|
# Server actions
|
||||||
@app.route('/server/action', methods=['POST'])
|
@app.route('/server/action', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("10 per hour")
|
@limiter.limit("500 per hour")
|
||||||
def server_action():
|
def server_action():
|
||||||
deployment = request.form.get('deployment', '')
|
deployment = request.form.get('deployment', '')
|
||||||
action = request.form.get('action', '')
|
action = request.form.get('action', '')
|
||||||
@@ -104,7 +104,7 @@ def register_api_routes(app, services, settings):
|
|||||||
|
|
||||||
@app.route('/server/battlegroup/action', methods=['POST'])
|
@app.route('/server/battlegroup/action', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("10 per hour")
|
@limiter.limit("500 per hour")
|
||||||
def battlegroup_action():
|
def battlegroup_action():
|
||||||
action = request.form.get('action', '')
|
action = request.form.get('action', '')
|
||||||
if action not in ('start', 'stop', 'restart'):
|
if action not in ('start', 'stop', 'restart'):
|
||||||
@@ -115,7 +115,7 @@ def register_api_routes(app, services, settings):
|
|||||||
|
|
||||||
@app.route('/server/battlegroup/update', methods=['POST'])
|
@app.route('/server/battlegroup/update', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("5 per hour")
|
@limiter.limit("1000 per hour")
|
||||||
def battlegroup_update():
|
def battlegroup_update():
|
||||||
bg_script = settings['kubernetes']['battlegroup_script']
|
bg_script = settings['kubernetes']['battlegroup_script']
|
||||||
out, err, rc = ssh.run(f'{bg_script} update', timeout=600)
|
out, err, rc = ssh.run(f'{bg_script} update', timeout=600)
|
||||||
@@ -186,7 +186,7 @@ def register_api_routes(app, services, settings):
|
|||||||
|
|
||||||
@app.route('/server/firewall/block', methods=['POST'])
|
@app.route('/server/firewall/block', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("10 per hour")
|
@limiter.limit("500 per hour")
|
||||||
def firewall_block():
|
def firewall_block():
|
||||||
port = request.form.get('port', type=int)
|
port = request.form.get('port', type=int)
|
||||||
bgd_port = _get_bgd_nodeport()
|
bgd_port = _get_bgd_nodeport()
|
||||||
@@ -232,7 +232,7 @@ def register_api_routes(app, services, settings):
|
|||||||
|
|
||||||
@app.route('/server/firewall/unblock', methods=['POST'])
|
@app.route('/server/firewall/unblock', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("10 per hour")
|
@limiter.limit("500 per hour")
|
||||||
def firewall_unblock():
|
def firewall_unblock():
|
||||||
port = request.form.get('port', type=int)
|
port = request.form.get('port', type=int)
|
||||||
bgd_port = _get_bgd_nodeport()
|
bgd_port = _get_bgd_nodeport()
|
||||||
@@ -340,7 +340,7 @@ def register_api_routes(app, services, settings):
|
|||||||
# Ban management
|
# Ban management
|
||||||
@app.route('/api/ban_player', methods=['POST'])
|
@app.route('/api/ban_player', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("5 per hour")
|
@limiter.limit("1000 per hour")
|
||||||
def api_ban_player():
|
def api_ban_player():
|
||||||
try:
|
try:
|
||||||
player_id = request.form.get('player_id', type=int)
|
player_id = request.form.get('player_id', type=int)
|
||||||
@@ -403,7 +403,7 @@ def register_api_routes(app, services, settings):
|
|||||||
|
|
||||||
@app.route('/api/unban_player', methods=['POST'])
|
@app.route('/api/unban_player', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("5 per hour")
|
@limiter.limit("1000 per hour")
|
||||||
def api_unban_player():
|
def api_unban_player():
|
||||||
try:
|
try:
|
||||||
player_id = request.form.get('player_id', type=int)
|
player_id = request.form.get('player_id', type=int)
|
||||||
@@ -429,7 +429,7 @@ def register_api_routes(app, services, settings):
|
|||||||
|
|
||||||
@app.route('/api/kick_player', methods=['POST'])
|
@app.route('/api/kick_player', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("10 per hour")
|
@limiter.limit("500 per hour")
|
||||||
def api_kick_player():
|
def api_kick_player():
|
||||||
try:
|
try:
|
||||||
player_id = request.form.get('player_id', type=int)
|
player_id = request.form.get('player_id', type=int)
|
||||||
@@ -444,7 +444,7 @@ def register_api_routes(app, services, settings):
|
|||||||
# Vitals editing
|
# Vitals editing
|
||||||
@app.route('/api/edit_vitals', methods=['POST'])
|
@app.route('/api/edit_vitals', methods=['POST'])
|
||||||
@auth_req
|
@auth_req
|
||||||
@limiter.limit("10 per hour")
|
@limiter.limit("500 per hour")
|
||||||
def api_edit_vitals():
|
def api_edit_vitals():
|
||||||
try:
|
try:
|
||||||
pawn_id = request.form.get('pawn_id', type=int)
|
pawn_id = request.form.get('pawn_id', type=int)
|
||||||
|
|||||||
@@ -107,14 +107,14 @@ class ChatService:
|
|||||||
logger.warning("Cannot catch up - no text-router pod found")
|
logger.warning("Cannot catch up - no text-router pod found")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
logger.info(f"Attempting to catch up chat from pod: {pod_name}")
|
logger.debug(f"Attempting to catch up chat from pod: {pod_name}")
|
||||||
|
|
||||||
# Get pod logs first, then filter locally
|
# Get pod logs first, then filter locally
|
||||||
log_cmd = f"sudo kubectl logs -n {namespace} {pod_name} --tail=2000 2>/dev/null"
|
log_cmd = f"sudo kubectl logs -n {namespace} {pod_name} --tail=2000 2>/dev/null"
|
||||||
out, err, rc = self.ssh.run(log_cmd, timeout=30)
|
out, err, rc = self.ssh.run(log_cmd, timeout=30)
|
||||||
|
|
||||||
if rc != 0 or not out:
|
if rc != 0 or not out:
|
||||||
logger.warning(f"Cannot catch up - failed to get pod logs: {err}")
|
logger.debug(f"Cannot catch up - failed to get pod logs (rc={rc})")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Filter for chat messages locally
|
# Filter for chat messages locally
|
||||||
|
|||||||
+2
-1
@@ -85,7 +85,8 @@ class SSHService:
|
|||||||
err = stderr.read().decode('utf-8', errors='replace')
|
err = stderr.read().decode('utf-8', errors='replace')
|
||||||
rc = stdout.channel.recv_exit_status()
|
rc = stdout.channel.recv_exit_status()
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
logger.warning("SSH command failed (rc=%d): %s", rc, err[:200])
|
cmd_short = command[:80] + '...' if len(command) > 80 else command
|
||||||
|
logger.warning("SSH command failed (rc=%d): cmd=%s err=%s", rc, cmd_short, err[:100] if err else 'none')
|
||||||
return out, err, rc
|
return out, err, rc
|
||||||
except paramiko.SSHException as e:
|
except paramiko.SSHException as e:
|
||||||
logger.error("SSH command error: %s", e)
|
logger.error("SSH command error: %s", e)
|
||||||
|
|||||||
+54
-2
@@ -160,6 +160,57 @@ function Start-LogSession {
|
|||||||
return $sessionFile
|
return $sessionFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Write-Step {
|
||||||
|
param([string]$Name, [string]$Category = "general")
|
||||||
|
if (-not $global:StepCounter) { $global:StepCounter = @{} }
|
||||||
|
if (-not $global:StepCounter[$Category]) { $global:StepCounter[$Category] = 0 }
|
||||||
|
$global:StepCounter[$Category]++
|
||||||
|
$num = $global:StepCounter[$Category]
|
||||||
|
Write-Log -Message "[$num] $Name" -Level "INFO" -Category $Category
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Success {
|
||||||
|
param([string]$Message, [string]$Category = "general")
|
||||||
|
Write-Log -Message $Message -Level "INFO" -Category $Category
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-DebugLog {
|
||||||
|
param([string]$Message, [string]$Category = "general")
|
||||||
|
Write-Log -Message $Message -Level "DEBUG" -Category $Category
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Sep {
|
||||||
|
param([string]$Title, [string]$Category = "general")
|
||||||
|
$sep = "-" * 55
|
||||||
|
$msg = if ($Title) { "$Title $sep" } else { $sep }
|
||||||
|
$logFile = Join-Path $LauncherLogDir "$Category\$LogDate.log"
|
||||||
|
if (-not (Test-Path (Split-Path $logFile))) {
|
||||||
|
New-Item -ItemType Directory -Path (Split-Path $logFile) -Force | Out-Null
|
||||||
|
}
|
||||||
|
Add-Content -Path $logFile -Value $msg -Encoding UTF8
|
||||||
|
Write-Host $msg -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
|
||||||
|
$Script:LogIndent = 0
|
||||||
|
|
||||||
|
function Push-Indent {
|
||||||
|
$Script:LogIndent++
|
||||||
|
}
|
||||||
|
|
||||||
|
function Pop-Indent {
|
||||||
|
$Script:LogIndent = [Math]::Max(0, $Script:LogIndent - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-LogStyled {
|
||||||
|
param(
|
||||||
|
[string]$Message,
|
||||||
|
[string]$Level = "INFO",
|
||||||
|
[string]$Category = "general"
|
||||||
|
)
|
||||||
|
$prefix = if ($Script:LogIndent -gt 0) { " " * $Script:LogIndent } else { "" }
|
||||||
|
Write-Log -Message "$prefix$Message" -Level $Level -Category $Category
|
||||||
|
}
|
||||||
|
|
||||||
# ── Log Rotation & Cleanup ────────────────────────────────────────────
|
# ── Log Rotation & Cleanup ────────────────────────────────────────────
|
||||||
# Prevents logs from growing unbounded.
|
# Prevents logs from growing unbounded.
|
||||||
# - Deletes log files older than $LogRetentionDays
|
# - Deletes log files older than $LogRetentionDays
|
||||||
@@ -1803,8 +1854,8 @@ print(json.dumps(s))
|
|||||||
Write-Host "============================================================" -ForegroundColor Cyan
|
Write-Host "============================================================" -ForegroundColor Cyan
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
Write-Log -Message "Dashboard launch started" -Category "general"
|
Write-Sep -Title "Dashboard Launch" -Category "general"
|
||||||
Write-Log -Message "Server: $ServerHost, User: $SSHUser" -Category "ssh"
|
Write-Log -Message "Server: $ServerHost, User: $SSHUser" -Category "general"
|
||||||
Write-Log -Message "Ports: DB=$LocalPort, Director=$DirectorPort, Dashboard=$DashboardPort" -Category "general"
|
Write-Log -Message "Ports: DB=$LocalPort, Director=$DirectorPort, Dashboard=$DashboardPort" -Category "general"
|
||||||
Write-Log -Message "Namespace: $Namespace" -Category "k8s"
|
Write-Log -Message "Namespace: $Namespace" -Category "k8s"
|
||||||
|
|
||||||
@@ -1819,6 +1870,7 @@ print(json.dumps(s))
|
|||||||
Start-Sleep 1
|
Start-Sleep 1
|
||||||
|
|
||||||
# [1/4] SSH Tunnel
|
# [1/4] SSH Tunnel
|
||||||
|
Write-Step -Name "SSH Tunnel" -Category "ssh"
|
||||||
Write-Host "[1/4] Starting SSH tunnel (localhost:$LocalPort -> VM)..." -ForegroundColor Yellow
|
Write-Host "[1/4] Starting SSH tunnel (localhost:$LocalPort -> VM)..." -ForegroundColor Yellow
|
||||||
Write-Log -Message "Starting SSH tunnel to ${SSHUser}@${ServerHost}" -Category "ssh"
|
Write-Log -Message "Starting SSH tunnel to ${SSHUser}@${ServerHost}" -Category "ssh"
|
||||||
$sshArgs = @(
|
$sshArgs = @(
|
||||||
|
|||||||
Reference in new issue
Block a user