fix: 踢下线同时禁用账号防重连,禁止管理员踢自己

- handler/vpn.go: KickUserClient 踢线后设置 status=0 并失效所有会话,
  阻止客户端自动重连;新增自检,目标为当前管理员时返回 400
- AdminView.vue: handleKick 调用 API 前自检,自己则提示去修改密码
- zh.ts/en.ts: 新增 cannotKickSelf,更新 confirmKick 提示含禁用账号
This commit is contained in:
2026-07-10 13:33:04 +08:00
parent f94aa3c4ac
commit f6a1fb6288
4 changed files with 21 additions and 7 deletions
+2 -1
View File
@@ -150,8 +150,9 @@ export default {
selectUserAndIp: 'Please select a user and fill in at least one IP address',
confirmDeleteReservation: 'Delete this reservation?',
kick: 'Kick',
confirmKick: 'Disconnect all VPN connections for user {username}?',
confirmKick: 'Disconnect all VPN connections for user {username} and disable their account?',
kickFailed: 'Failed to kick user',
cannotKickSelf: 'Cannot kick yourself. To disconnect your own devices, please change your password.',
},
footer: {
lastCommit: 'Last commit',
+2 -1
View File
@@ -149,8 +149,9 @@ export default {
selectUserAndIp: '请选择用户并至少填写一个 IP 地址',
confirmDeleteReservation: '确认删除该预留?',
kick: '踢下线',
confirmKick: '确定要断开用户 {username} 的所有 VPN 连接吗?',
confirmKick: '确定要断开用户 {username} 的所有 VPN 连接并禁用其账号吗?',
kickFailed: '踢下线失败',
cannotKickSelf: '不能踢自己下线,如需断开自己的设备请修改密码',
},
footer: {
lastCommit: '最后提交',
+5 -1
View File
@@ -83,8 +83,12 @@ async function fetchVpnStatus() {
}
async function handleKick(userId: number, username: string) {
if (!confirm(t('vpn.confirmKick', { username }))) return
kickError.value = ''
if (userId === authStore.user?.id) {
kickError.value = t('vpn.cannotKickSelf')
return
}
if (!confirm(t('vpn.confirmKick', { username }))) return
try {
const res = await fetch(`/api/admin/vpn/clients/${userId}`, {
method: 'DELETE',
+12 -4
View File
@@ -421,11 +421,19 @@ func KickUserClient(c *gin.Context) {
return
}
if vpn.VPN == nil || !vpn.VPN.Running() {
c.JSON(http.StatusOK, gin.H{"message": "VPN 服务未运行", "kicked": 0})
currentUserID, _ := c.Get("user_id")
if uint(id) == currentUserID.(uint) {
c.JSON(http.StatusBadRequest, gin.H{"error": "不能踢自己下线,如需断开自己的设备请修改密码"})
return
}
n := vpn.VPN.KickUser(uint(id))
c.JSON(http.StatusOK, gin.H{"message": "已断开用户连接", "kicked": n})
n := 0
if vpn.VPN != nil && vpn.VPN.Running() {
n = vpn.VPN.KickUser(uint(id))
}
db.DB.Model(&user).Update("status", 0)
db.DB.Model(&model.Session{}).Where("user_id = ?", id).Update("invalid", true)
c.JSON(http.StatusOK, gin.H{"message": "已断开用户连接并禁用账号", "kicked": n})
}