Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Locale;
import java.util.Map;

public interface Session {

void refreshLastActiveTime();

LocalDateTime getLastActiveTime();

boolean canUpload();

boolean canDownload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jumpserver.chen.framework.session.controller.impl;

import lombok.extern.slf4j.Slf4j;
import org.jumpserver.chen.framework.session.SessionManager;
import org.jumpserver.chen.framework.session.controller.Controller;
import org.jumpserver.chen.framework.session.controller.dialog.Dialog;
import org.jumpserver.chen.framework.session.controller.message.Message;
Expand Down Expand Up @@ -40,11 +41,20 @@ public void handlePacket(Packet packet) {
case "dialog_event":
this.onDialogEvent((String) packet.getData());
break;
case "input_active":
this.refreshLastActiveTime();
break;
default:
break;
}
}


private void refreshLastActiveTime() {
var session = SessionManager.getCurrentSession();
session.refreshLastActiveTime();
}

@Override
public void sendFile(String fileKey) {
this.packetIO.sendPacket("download", fileKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -57,13 +58,21 @@ public class BaseSession implements Session {

private boolean enableAutoComplete = true;

@Getter
private LocalDateTime lastActiveTime;


public BaseSession(Datasource datasource, String remoteAddr) {
this.datasource = datasource;
this.remoteAddr = remoteAddr;
}


@Override
public void refreshLastActiveTime() {
this.lastActiveTime = LocalDateTime.now();
}

@Override
public boolean canUpload() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public class JMSSession extends BaseSession {
private final long expireTime;


private LocalDateTime lastActiveTime;

private LocalDateTime maxSessionEndTime;
private int maxSessionEndHours;
private LocalDateTime dynamicEndTime;
Expand Down Expand Up @@ -205,7 +203,7 @@ private void recordLifecycle(ServiceOuterClass.SessionLifecycleLogRequest.EventT
}

private void startWaitIdleTime() {
this.lastActiveTime = LocalDateTime.now();
this.refreshLastActiveTime();

var token = SessionManager.getContextToken();

Expand All @@ -224,7 +222,7 @@ private void startWaitIdleTime() {
return;
}

if (Math.abs(Duration.between(LocalDateTime.now(), this.lastActiveTime).toMinutes()) > this.maxIdleTimeDelta) {
if (Math.abs(Duration.between(LocalDateTime.now(), this.getLastActiveTime()).toMinutes()) > this.maxIdleTimeDelta) {
this.close("OverMaxIdleTimeError", "idle_disconnect", this.maxIdleTimeDelta);
return;
}
Expand Down Expand Up @@ -310,7 +308,7 @@ private void closeGateway() {
@Override
public SQLQueryResult withAudit(String command, QueryAuditFunction queryAuditFunction) throws SQLException, CommandRejectException {
synchronized (this) {
this.lastActiveTime = LocalDateTime.now();
this.refreshLastActiveTime();
}
if (this.locked) {
throw new CommandRejectException(MessageUtils.get("SessionLockedError"));
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/bus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Vue from 'vue'

export const bus = new Vue()
15 changes: 14 additions & 1 deletion frontend/src/components/Controller/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
v-if="dialogOptions.body && dialogOptions.bodyType==='html'"
v-html="dialogOptions.body"
/>
<div v-else v-text="dialogOptions.body" />
<div v-else v-text="dialogOptions.body"/>

<span v-if="dialogOptions && dialogOptions.buttons" slot="footer" class="dialog-footer" style="text-align: center">
<el-button
Expand All @@ -27,6 +27,7 @@
import { getUrlParams } from '@/utils/field'
import { LunaEvent, MESSAGES } from '@/utils/luna'
import { index } from '@/request'
import { bus } from '@/bus'

export default {
name: 'Controller',
Expand All @@ -49,8 +50,20 @@ export default {
this.lunaEvent.init()
this.auth()
this.handleRenewLunaSession()
this.handleInputActive()
},
methods: {
handleInputActive() {
bus.$on('input-active', () => {
this.lunaEvent.sendEventToLuna(MESSAGES.INPUT_ACTIVE)
})

this.lunaEvent.setInputActiveHandler(() => {
console.log('receive other window input active message')
this.sendPacket('input_active')
})
},

handleRenewLunaSession() {
const lunaEvent = this.lunaEvent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import 'codemirror/addon/edit/matchbrackets.js'
import { getHints } from '@/api/resource'
import SelectSnippetDialog from '@/components/Main/Explore/QueryConsole/SelectSnippetDialog.vue'
import SaveSnippetDialog from '@/components/Main/Explore/QueryConsole/SaveSnippetDialog.vue'
import { bus } from '@/bus'

const formatterMap = {
'clickhouse': 'sql',
Expand Down Expand Up @@ -283,6 +284,9 @@ export default {
this.cm = cm
},
onCmChange(cm, change) {
// 向 luna 发送事件
bus.$emit('input-active')

const { text, origin } = change[0]
if (origin === '+input' && text[0].trim()) {
if (this.autoComplete) {
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/utils/luna.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const MESSAGES = {
CLOSE: 'CLOSE',
CONNECTED: 'CONNECTED',
KEYEVENT: 'KEYEVENT',
MOUSEEVENT: 'MOUSEEVENT'
MOUSEEVENT: 'MOUSEEVENT',
INPUT_ACTIVE: 'INPUT_ACTIVE'
}

export class LunaEvent {
Expand All @@ -25,9 +26,16 @@ export class LunaEvent {
this.origin = event.origin
this.sendEventToLuna(MESSAGES.PONG)
break
case MESSAGES.INPUT_ACTIVE:
this.inputActiveHandler && this.inputActiveHandler()
break
}
}

setInputActiveHandler(func) {
this.inputActiveHandler = func
}

sendEventToLuna(name, data) {
data == null && (data = '')
if (this.lunaId != null) {
Expand Down