diff --git a/app/api/auth/login/route.ts b/app/api/auth/login/route.ts index c99e67e..4b14788 100644 --- a/app/api/auth/login/route.ts +++ b/app/api/auth/login/route.ts @@ -52,7 +52,7 @@ export async function POST(request: NextRequest) { const response = NextResponse.json({ success: true, username: user.username }); response.cookies.set('auth_token', newToken, { httpOnly: true, - secure: process.env.NODE_ENV === 'production', + secure: false, sameSite: 'lax', maxAge: 60 * 60 * 24 * 7, path: '/' diff --git a/app/api/auth/register/route.ts b/app/api/auth/register/route.ts index a206c9f..e31fefb 100644 --- a/app/api/auth/register/route.ts +++ b/app/api/auth/register/route.ts @@ -68,7 +68,7 @@ export async function POST(request: NextRequest) { const response = NextResponse.json({ success: true, username }); response.cookies.set('auth_token', token, { httpOnly: true, - secure: process.env.NODE_ENV === 'production', + secure: false, sameSite: 'lax', maxAge: 60 * 60 * 24 * 7, path: '/' diff --git a/port_forwarding.sh b/port_forwarding.sh new file mode 100755 index 0000000..12cdbba --- /dev/null +++ b/port_forwarding.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +REMOTE_HOST="47.120.74.73" +REMOTE_PORT="30000" +LOCAL_PORT="3000" +SSH_PORT="22" +SSH_PASSWORD="MyPassword2+" +PID_FILE="/tmp/ssh_tunnel.pid" +LOG_FILE="/tmp/ssh_tunnel.log" + +start_tunnel() { + if [ -f "$PID_FILE" ]; then + OLD_PID=$(cat "$PID_FILE") + if kill -0 "$OLD_PID" 2>/dev/null; then + echo "SSH隧道已在运行 (PID: $OLD_PID)" + return + fi + rm -f "$PID_FILE" + fi + + echo "正在启动SSH反向隧道..." + sshpass -p "$SSH_PASSWORD" ssh -N -g -R "0.0.0.0:$REMOTE_PORT":localhost:"$LOCAL_PORT" -p "$SSH_PORT" -o "ServerAliveInterval=60" -o "ServerAliveCountMax=3" root@"$REMOTE_HOST" > "$LOG_FILE" 2>&1 & + SSH_PID=$! + echo "$SSH_PID" > "$PID_FILE" + sleep 2 + + if kill -0 "$SSH_PID" 2>/dev/null; then + echo "SSH隧道已启动 (本地3000 -> 远程$REMOTE_PORT)" + else + echo "启动失败,查看日志: cat $LOG_FILE" + rm -f "$PID_FILE" + fi +} + +stop_tunnel() { + if [ -f "$PID_FILE" ]; then + PID=$(cat "$PID_FILE") + if kill -0 "$PID" 2>/dev/null; then + kill "$PID" + rm -f "$PID_FILE" + echo "SSH隧道已停止" + else + rm -f "$PID_FILE" + echo "隧道未运行" + fi + else + echo "未找到PID文件,尝试直接终止" + pkill -f "ssh -N -R $REMOTE_PORT:localhost:$LOCAL_PORT" + fi +} + +status_tunnel() { + if [ -f "$PID_FILE" ]; then + PID=$(cat "$PID_FILE") + if kill -0 "$PID" 2>/dev/null; then + echo "SSH隧道正在运行 (PID: $PID)" + return + fi + fi + echo "SSH隧道未运行" + echo "尝试检测进程..." + if pgrep -f "ssh -N -R $REMOTE_PORT" > /dev/null; then + echo "发现隧道进程,但无PID文件" + fi +} + +case "$1" in + start) start_tunnel ;; + stop) stop_tunnel ;; + status) status_tunnel ;; + *) echo "Usage: $0 {start|stop|status}" ;; +esac