@lethevimlet/sshift 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1146 -0
- package/example.config.json +162 -0
- package/package.json +74 -0
- package/src/server/endpoints/index.js +12 -0
- package/src/server/endpoints/rest/bookmarks.js +106 -0
- package/src/server/endpoints/rest/config.js +65 -0
- package/src/server/endpoints/rest/folders.js +127 -0
- package/src/server/endpoints/rest/index.js +32 -0
- package/src/server/endpoints/rest/sessions.js +113 -0
- package/src/server/endpoints/rest/system.js +211 -0
- package/src/server/endpoints/ws/index.js +46 -0
- package/src/server/endpoints/ws/layout.js +43 -0
- package/src/server/endpoints/ws/sftp.js +156 -0
- package/src/server/endpoints/ws/ssh.js +180 -0
- package/src/server/endpoints/ws/tabs.js +211 -0
- package/src/server/index.js +127 -0
- package/src/server/services/index.js +12 -0
- package/src/server/services/sftp-manager.js +266 -0
- package/src/server/services/ssh-manager.js +527 -0
- package/src/server/utils/config.js +171 -0
- package/src/server/utils/env-loader.js +29 -0
- package/src/server/utils/index.js +14 -0
- package/src/server/utils/tab-manager.js +266 -0
- package/src/webapp/css/style.css +3819 -0
- package/src/webapp/index.html +1008 -0
- package/src/webapp/js/app.js +8308 -0
- package/src/webapp/layouts.json +128 -0
- package/src/webapp/libs/font-awesome/css/all.min.css +9 -0
- package/src/webapp/libs/font-awesome/webfonts/fa-brands-400.ttf +0 -0
- package/src/webapp/libs/font-awesome/webfonts/fa-brands-400.woff2 +0 -0
- package/src/webapp/libs/font-awesome/webfonts/fa-regular-400.ttf +0 -0
- package/src/webapp/libs/font-awesome/webfonts/fa-regular-400.woff2 +0 -0
- package/src/webapp/libs/font-awesome/webfonts/fa-solid-900.ttf +0 -0
- package/src/webapp/libs/font-awesome/webfonts/fa-solid-900.woff2 +0 -0
- package/src/webapp/libs/lucide/lucide.min.js +12 -0
- package/src/webapp/libs/xterm/xterm-addon-fit.js +2 -0
- package/src/webapp/libs/xterm/xterm-addon-search.js +2 -0
- package/src/webapp/libs/xterm/xterm-addon-serialize.js +2 -0
- package/src/webapp/libs/xterm/xterm-addon-web-links.js +2 -0
- package/src/webapp/libs/xterm/xterm.css +209 -0
- package/src/webapp/libs/xterm/xterm.js +2 -0
- package/sshift +269 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
{
|
|
2
|
+
"port": 8022,
|
|
3
|
+
"devPort": 3000,
|
|
4
|
+
"bind": "0.0.0.0",
|
|
5
|
+
"sticky": true,
|
|
6
|
+
"sshKeepaliveInterval": 15000,
|
|
7
|
+
"sshKeepaliveCountMax": 500,
|
|
8
|
+
"bookmarks": [
|
|
9
|
+
{
|
|
10
|
+
"id": "example1",
|
|
11
|
+
"name": "Example SSH Server",
|
|
12
|
+
"host": "example.com",
|
|
13
|
+
"port": 22,
|
|
14
|
+
"username": "your_username",
|
|
15
|
+
"type": "ssh",
|
|
16
|
+
"folderId": null
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "example2",
|
|
20
|
+
"name": "Example SFTP Server",
|
|
21
|
+
"host": "sftp.example.com",
|
|
22
|
+
"port": 22,
|
|
23
|
+
"username": "your_username",
|
|
24
|
+
"type": "sftp",
|
|
25
|
+
"folderId": "folder1"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"folders": [
|
|
29
|
+
{
|
|
30
|
+
"id": "folder1",
|
|
31
|
+
"name": "Work Servers",
|
|
32
|
+
"icon": "briefcase",
|
|
33
|
+
"expanded": true
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"id": "folder2",
|
|
37
|
+
"name": "Personal",
|
|
38
|
+
"icon": "home",
|
|
39
|
+
"expanded": true
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"folderOrder": ["folder1", "folder2"],
|
|
43
|
+
"bookmarkOrder": ["example1", "example2"],
|
|
44
|
+
"layouts": [
|
|
45
|
+
{
|
|
46
|
+
"id": "single",
|
|
47
|
+
"name": "Single",
|
|
48
|
+
"icon": "square",
|
|
49
|
+
"columns": [
|
|
50
|
+
{
|
|
51
|
+
"width": "100%",
|
|
52
|
+
"rows": [
|
|
53
|
+
{
|
|
54
|
+
"height": "100%"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "2-columns",
|
|
62
|
+
"name": "2 Columns",
|
|
63
|
+
"icon": "columns",
|
|
64
|
+
"columns": [
|
|
65
|
+
{
|
|
66
|
+
"width": "50%",
|
|
67
|
+
"rows": [
|
|
68
|
+
{
|
|
69
|
+
"height": "100%"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"width": "50%",
|
|
75
|
+
"rows": [
|
|
76
|
+
{
|
|
77
|
+
"height": "100%"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "3-columns",
|
|
85
|
+
"name": "3 Columns",
|
|
86
|
+
"icon": "grip-lines-vertical",
|
|
87
|
+
"columns": [
|
|
88
|
+
{
|
|
89
|
+
"width": "33.33%",
|
|
90
|
+
"rows": [
|
|
91
|
+
{
|
|
92
|
+
"height": "100%"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"width": "33.33%",
|
|
98
|
+
"rows": [
|
|
99
|
+
{
|
|
100
|
+
"height": "100%"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"width": "33.34%",
|
|
106
|
+
"rows": [
|
|
107
|
+
{
|
|
108
|
+
"height": "100%"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"id": "1-column-2-rows",
|
|
116
|
+
"name": "1 Column 2 Rows",
|
|
117
|
+
"icon": "grip-lines",
|
|
118
|
+
"columns": [
|
|
119
|
+
{
|
|
120
|
+
"width": "100%",
|
|
121
|
+
"rows": [
|
|
122
|
+
{
|
|
123
|
+
"height": "50%"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"height": "50%"
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"id": "cross",
|
|
134
|
+
"name": "Cross",
|
|
135
|
+
"icon": "th-large",
|
|
136
|
+
"columns": [
|
|
137
|
+
{
|
|
138
|
+
"width": "50%",
|
|
139
|
+
"rows": [
|
|
140
|
+
{
|
|
141
|
+
"height": "50%"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"height": "50%"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"width": "50%",
|
|
150
|
+
"rows": [
|
|
151
|
+
{
|
|
152
|
+
"height": "50%"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"height": "50%"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lethevimlet/sshift",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
|
|
5
|
+
"main": "src/server/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sshift": "./sshift"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node sshift",
|
|
11
|
+
"dev": "NODE_ENV=development node sshift",
|
|
12
|
+
"test": "jest --forceExit --runInBand",
|
|
13
|
+
"test:watch": "jest --watch",
|
|
14
|
+
"test:coverage": "jest --coverage --forceExit --runInBand",
|
|
15
|
+
"test:unit": "jest --testPathPatterns='src/tests/unit' --forceExit",
|
|
16
|
+
"test:integration": "jest --testPathPatterns='src/tests/integration' --forceExit",
|
|
17
|
+
"test:e2e": "jest --testPathPatterns='src/tests/e2e' --forceExit --runInBand",
|
|
18
|
+
"test:browser": "jest --testPathPatterns='src/tests/browser' --forceExit --runInBand",
|
|
19
|
+
"prepublishOnly": "echo 'Publishing to npm...'"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@xterm/addon-serialize": "^0.14.0",
|
|
23
|
+
"@xterm/headless": "^6.0.0",
|
|
24
|
+
"dotenv": "^17.4.0",
|
|
25
|
+
"express": "^4.18.2",
|
|
26
|
+
"lucide": "^1.7.0",
|
|
27
|
+
"socket.io": "^4.7.2",
|
|
28
|
+
"ssh2": "^1.15.0",
|
|
29
|
+
"uuid": "^9.0.0"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"ssh",
|
|
33
|
+
"sftp",
|
|
34
|
+
"terminal",
|
|
35
|
+
"web",
|
|
36
|
+
"xterm",
|
|
37
|
+
"web-terminal",
|
|
38
|
+
"ssh-client",
|
|
39
|
+
"sftp-client",
|
|
40
|
+
"browser-terminal"
|
|
41
|
+
],
|
|
42
|
+
"author": "lethevimlet",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/lethevimlet/sshift.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/lethevimlet/sshift/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/lethevimlet/sshift#readme",
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=20.0.0"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"sshift",
|
|
61
|
+
"src/server/",
|
|
62
|
+
"src/webapp/",
|
|
63
|
+
"example.config.json",
|
|
64
|
+
"README.md",
|
|
65
|
+
"LICENSE"
|
|
66
|
+
],
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@types/jest": "^30.0.0",
|
|
69
|
+
"jest": "^30.3.0",
|
|
70
|
+
"puppeteer": "^24.40.0",
|
|
71
|
+
"socket.io-client": "^4.8.3",
|
|
72
|
+
"ts-jest": "^29.4.9"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bookmark REST endpoints
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { loadConfig, saveConfig } = require('../../utils/config');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Register bookmark endpoints
|
|
9
|
+
* @param {Object} app - Express app
|
|
10
|
+
* @param {Object} io - Socket.IO instance
|
|
11
|
+
*/
|
|
12
|
+
function registerBookmarkEndpoints(app, io) {
|
|
13
|
+
// API: Get bookmarks
|
|
14
|
+
app.get('/api/bookmarks', (req, res) => {
|
|
15
|
+
const config = loadConfig();
|
|
16
|
+
res.json(config.bookmarks);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// API: Add bookmark
|
|
20
|
+
app.post('/api/bookmarks', (req, res) => {
|
|
21
|
+
const config = loadConfig();
|
|
22
|
+
const bookmark = {
|
|
23
|
+
id: Date.now().toString(),
|
|
24
|
+
name: req.body.name,
|
|
25
|
+
type: req.body.type || 'ssh'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Add type-specific fields
|
|
29
|
+
if (req.body.type === 'url') {
|
|
30
|
+
bookmark.url = req.body.url;
|
|
31
|
+
} else {
|
|
32
|
+
bookmark.host = req.body.host;
|
|
33
|
+
bookmark.port = req.body.port || 22;
|
|
34
|
+
bookmark.username = req.body.username;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Add optional fields
|
|
38
|
+
if (req.body.password) bookmark.password = req.body.password;
|
|
39
|
+
if (req.body.privateKey) bookmark.privateKey = req.body.privateKey;
|
|
40
|
+
if (req.body.passphrase) bookmark.passphrase = req.body.passphrase;
|
|
41
|
+
if (req.body.folderId) bookmark.folderId = req.body.folderId;
|
|
42
|
+
|
|
43
|
+
config.bookmarks.push(bookmark);
|
|
44
|
+
if (saveConfig(config)) {
|
|
45
|
+
// Broadcast to all clients
|
|
46
|
+
io.emit('bookmark-added', bookmark);
|
|
47
|
+
res.json(bookmark);
|
|
48
|
+
} else {
|
|
49
|
+
res.status(500).json({ error: 'Failed to save bookmark' });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// API: Delete bookmark
|
|
54
|
+
app.delete('/api/bookmarks/:id', (req, res) => {
|
|
55
|
+
const config = loadConfig();
|
|
56
|
+
config.bookmarks = config.bookmarks.filter(b => b.id !== req.params.id);
|
|
57
|
+
if (saveConfig(config)) {
|
|
58
|
+
// Broadcast to all clients
|
|
59
|
+
io.emit('bookmark-deleted', { id: req.params.id });
|
|
60
|
+
res.json({ success: true });
|
|
61
|
+
} else {
|
|
62
|
+
res.status(500).json({ error: 'Failed to delete bookmark' });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// API: Update bookmark
|
|
67
|
+
app.put('/api/bookmarks/:id', (req, res) => {
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
const index = config.bookmarks.findIndex(b => b.id === req.params.id);
|
|
70
|
+
if (index !== -1) {
|
|
71
|
+
config.bookmarks[index] = {
|
|
72
|
+
...config.bookmarks[index],
|
|
73
|
+
...req.body,
|
|
74
|
+
id: req.params.id
|
|
75
|
+
};
|
|
76
|
+
if (saveConfig(config)) {
|
|
77
|
+
// Broadcast to all clients
|
|
78
|
+
io.emit('bookmark-updated', config.bookmarks[index]);
|
|
79
|
+
res.json(config.bookmarks[index]);
|
|
80
|
+
} else {
|
|
81
|
+
res.status(500).json({ error: 'Failed to update bookmark' });
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
res.status(404).json({ error: 'Bookmark not found' });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// API: Save bookmark order
|
|
89
|
+
app.post('/api/bookmarks/order', (req, res) => {
|
|
90
|
+
const config = loadConfig();
|
|
91
|
+
config.bookmarkOrder = req.body.order;
|
|
92
|
+
if (saveConfig(config)) {
|
|
93
|
+
res.json({ success: true });
|
|
94
|
+
} else {
|
|
95
|
+
res.status(500).json({ error: 'Failed to save bookmark order' });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// API: Get bookmark order
|
|
100
|
+
app.get('/api/bookmarks/order', (req, res) => {
|
|
101
|
+
const config = loadConfig();
|
|
102
|
+
res.json(config.bookmarkOrder || []);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = { registerBookmarkEndpoints };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config REST endpoints
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { loadConfig, saveConfig } = require('../../utils/config');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Register config endpoints
|
|
9
|
+
* @param {Object} app - Express app
|
|
10
|
+
* @param {Object} io - Socket.IO instance
|
|
11
|
+
*/
|
|
12
|
+
function registerConfigEndpoints(app, io) {
|
|
13
|
+
// API: Get config (for sticky sessions and SSH keepalive)
|
|
14
|
+
app.get('/api/config', (req, res) => {
|
|
15
|
+
const config = loadConfig();
|
|
16
|
+
res.json({
|
|
17
|
+
sticky: config.sticky !== false, // Default to true
|
|
18
|
+
takeControlDefault: config.takeControlDefault !== false, // Default to true
|
|
19
|
+
sshKeepaliveInterval: config.sshKeepaliveInterval || 10000,
|
|
20
|
+
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000,
|
|
21
|
+
mobileKeysBarEnabled: config.mobileKeysBarEnabled !== false, // Default to true
|
|
22
|
+
layouts: config.layouts || null // Include layouts if defined in config
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// API: Update config
|
|
27
|
+
app.post('/api/config', (req, res) => {
|
|
28
|
+
const config = loadConfig();
|
|
29
|
+
|
|
30
|
+
// Update sticky setting if provided
|
|
31
|
+
if (req.body.hasOwnProperty('sticky')) {
|
|
32
|
+
config.sticky = req.body.sticky;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Update takeControlDefault setting if provided
|
|
36
|
+
if (req.body.hasOwnProperty('takeControlDefault')) {
|
|
37
|
+
config.takeControlDefault = req.body.takeControlDefault;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Update SSH keepalive settings if provided
|
|
41
|
+
if (req.body.hasOwnProperty('sshKeepaliveInterval')) {
|
|
42
|
+
config.sshKeepaliveInterval = parseInt(req.body.sshKeepaliveInterval) || 10000;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (req.body.hasOwnProperty('sshKeepaliveCountMax')) {
|
|
46
|
+
config.sshKeepaliveCountMax = parseInt(req.body.sshKeepaliveCountMax) || 1000;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Save config
|
|
50
|
+
const saved = saveConfig(config);
|
|
51
|
+
if (saved) {
|
|
52
|
+
res.json({
|
|
53
|
+
success: true,
|
|
54
|
+
sticky: config.sticky !== false,
|
|
55
|
+
takeControlDefault: config.takeControlDefault !== false,
|
|
56
|
+
sshKeepaliveInterval: config.sshKeepaliveInterval || 10000,
|
|
57
|
+
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
res.status(500).json({ error: 'Failed to save config' });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { registerConfigEndpoints };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folder REST endpoints
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { loadConfig, saveConfig } = require('../../utils/config');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Register folder endpoints
|
|
9
|
+
* @param {Object} app - Express app
|
|
10
|
+
* @param {Object} io - Socket.IO instance
|
|
11
|
+
*/
|
|
12
|
+
function registerFolderEndpoints(app, io) {
|
|
13
|
+
// API: Get folders
|
|
14
|
+
app.get('/api/folders', (req, res) => {
|
|
15
|
+
const config = loadConfig();
|
|
16
|
+
res.json(config.folders || []);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// API: Add folder
|
|
20
|
+
app.post('/api/folders', (req, res) => {
|
|
21
|
+
const config = loadConfig();
|
|
22
|
+
const folder = {
|
|
23
|
+
id: Date.now().toString(),
|
|
24
|
+
name: req.body.name,
|
|
25
|
+
icon: req.body.icon || 'folder',
|
|
26
|
+
expanded: true
|
|
27
|
+
};
|
|
28
|
+
if (!config.folders) {
|
|
29
|
+
config.folders = [];
|
|
30
|
+
}
|
|
31
|
+
config.folders.push(folder);
|
|
32
|
+
if (saveConfig(config)) {
|
|
33
|
+
// Broadcast to all clients
|
|
34
|
+
io.emit('folder-added', folder);
|
|
35
|
+
res.json(folder);
|
|
36
|
+
} else {
|
|
37
|
+
res.status(500).json({ error: 'Failed to save folder' });
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// API: Update folder
|
|
42
|
+
app.put('/api/folders/:id', (req, res) => {
|
|
43
|
+
const config = loadConfig();
|
|
44
|
+
if (!config.folders) {
|
|
45
|
+
config.folders = [];
|
|
46
|
+
}
|
|
47
|
+
const index = config.folders.findIndex(f => f.id === req.params.id);
|
|
48
|
+
if (index !== -1) {
|
|
49
|
+
config.folders[index] = {
|
|
50
|
+
...config.folders[index],
|
|
51
|
+
...req.body,
|
|
52
|
+
id: req.params.id
|
|
53
|
+
};
|
|
54
|
+
if (saveConfig(config)) {
|
|
55
|
+
// Broadcast to all clients
|
|
56
|
+
io.emit('folder-updated', config.folders[index]);
|
|
57
|
+
res.json(config.folders[index]);
|
|
58
|
+
} else {
|
|
59
|
+
res.status(500).json({ error: 'Failed to update folder' });
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
res.status(404).json({ error: 'Folder not found' });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// API: Delete folder
|
|
67
|
+
app.delete('/api/folders/:id', (req, res) => {
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
if (!config.folders) {
|
|
70
|
+
config.folders = [];
|
|
71
|
+
}
|
|
72
|
+
config.folders = config.folders.filter(f => f.id !== req.params.id);
|
|
73
|
+
// Move bookmarks from deleted folder to root (no folderId)
|
|
74
|
+
config.bookmarks = config.bookmarks.map(b => {
|
|
75
|
+
if (b.folderId === req.params.id) {
|
|
76
|
+
const { folderId, ...rest } = b;
|
|
77
|
+
return rest;
|
|
78
|
+
}
|
|
79
|
+
return b;
|
|
80
|
+
});
|
|
81
|
+
if (saveConfig(config)) {
|
|
82
|
+
// Broadcast to all clients
|
|
83
|
+
io.emit('folder-deleted', { id: req.params.id });
|
|
84
|
+
res.json({ success: true });
|
|
85
|
+
} else {
|
|
86
|
+
res.status(500).json({ error: 'Failed to delete folder' });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// API: Save folder order
|
|
91
|
+
app.post('/api/folders/order', (req, res) => {
|
|
92
|
+
const config = loadConfig();
|
|
93
|
+
config.folderOrder = req.body.order;
|
|
94
|
+
if (saveConfig(config)) {
|
|
95
|
+
res.json({ success: true });
|
|
96
|
+
} else {
|
|
97
|
+
res.status(500).json({ error: 'Failed to save folder order' });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// API: Get folder order
|
|
102
|
+
app.get('/api/folders/order', (req, res) => {
|
|
103
|
+
const config = loadConfig();
|
|
104
|
+
res.json(config.folderOrder || []);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// API: Save folder expanded states
|
|
108
|
+
app.post('/api/folders/expanded', (req, res) => {
|
|
109
|
+
const config = loadConfig();
|
|
110
|
+
config.folderExpandedStates = req.body.states;
|
|
111
|
+
if (saveConfig(config)) {
|
|
112
|
+
// Broadcast to all clients
|
|
113
|
+
io.emit('folder-expanded-states', { states: req.body.states });
|
|
114
|
+
res.json({ success: true });
|
|
115
|
+
} else {
|
|
116
|
+
res.status(500).json({ error: 'Failed to save folder expanded states' });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// API: Get folder expanded states
|
|
121
|
+
app.get('/api/folders/expanded', (req, res) => {
|
|
122
|
+
const config = loadConfig();
|
|
123
|
+
res.json(config.folderExpandedStates || {});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = { registerFolderEndpoints };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REST endpoints module index
|
|
3
|
+
* Re-exports all REST endpoint modules
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { registerBookmarkEndpoints } = require('./bookmarks');
|
|
7
|
+
const { registerConfigEndpoints } = require('./config');
|
|
8
|
+
const { registerFolderEndpoints } = require('./folders');
|
|
9
|
+
const { registerSessionsEndpoints } = require('./sessions');
|
|
10
|
+
const { registerSystemEndpoints } = require('./system');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Register all REST endpoints
|
|
14
|
+
* @param {Object} app - Express app
|
|
15
|
+
* @param {Object} io - Socket.IO instance
|
|
16
|
+
*/
|
|
17
|
+
function registerAllRestEndpoints(app, io) {
|
|
18
|
+
registerBookmarkEndpoints(app, io);
|
|
19
|
+
registerConfigEndpoints(app, io);
|
|
20
|
+
registerFolderEndpoints(app, io);
|
|
21
|
+
registerSessionsEndpoints(app, io);
|
|
22
|
+
registerSystemEndpoints(app, io);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
registerBookmarkEndpoints,
|
|
27
|
+
registerConfigEndpoints,
|
|
28
|
+
registerFolderEndpoints,
|
|
29
|
+
registerSessionsEndpoints,
|
|
30
|
+
registerSystemEndpoints,
|
|
31
|
+
registerAllRestEndpoints
|
|
32
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sessions REST endpoints
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { getOpenTabs, removeTab, getTabOrder } = require('../../utils/tab-manager');
|
|
6
|
+
const { sshManager, sftpManager } = require('../../services');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Register sessions endpoints
|
|
10
|
+
* @param {Object} app - Express app
|
|
11
|
+
* @param {Object} io - Socket.IO instance
|
|
12
|
+
*/
|
|
13
|
+
function registerSessionsEndpoints(app, io) {
|
|
14
|
+
// API: Get active sessions
|
|
15
|
+
app.get('/api/sessions', (req, res) => {
|
|
16
|
+
const sessions = [];
|
|
17
|
+
const openTabs = getOpenTabs();
|
|
18
|
+
|
|
19
|
+
// Get SSH sessions from ssh-manager
|
|
20
|
+
const sshSessions = sshManager.getActiveSessions();
|
|
21
|
+
for (const [sessionId, session] of sshSessions) {
|
|
22
|
+
const tab = openTabs.get(sessionId);
|
|
23
|
+
sessions.push({
|
|
24
|
+
id: sessionId,
|
|
25
|
+
type: 'ssh',
|
|
26
|
+
name: tab?.name || session.host || 'Unknown',
|
|
27
|
+
host: session.host,
|
|
28
|
+
port: session.port,
|
|
29
|
+
username: session.username,
|
|
30
|
+
connectedAt: session.connectedAt,
|
|
31
|
+
activeSockets: tab?.activeSockets?.size || 0,
|
|
32
|
+
controllerSocket: session.controllerSocket
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Get SFTP sessions from sftp-manager
|
|
37
|
+
const sftpSessions = sftpManager.getActiveSessions();
|
|
38
|
+
for (const [sessionId, session] of sftpSessions) {
|
|
39
|
+
const tab = openTabs.get(sessionId);
|
|
40
|
+
sessions.push({
|
|
41
|
+
id: sessionId,
|
|
42
|
+
type: 'sftp',
|
|
43
|
+
name: tab?.name || session.host || 'Unknown',
|
|
44
|
+
host: session.host,
|
|
45
|
+
port: session.port,
|
|
46
|
+
username: session.username,
|
|
47
|
+
connectedAt: session.connectedAt,
|
|
48
|
+
activeSockets: tab?.activeSockets?.size || 0
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
res.json(sessions);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// API: Close a specific session
|
|
56
|
+
app.delete('/api/sessions/:id', (req, res) => {
|
|
57
|
+
const sessionId = req.params.id;
|
|
58
|
+
const openTabs = getOpenTabs();
|
|
59
|
+
const tab = openTabs.get(sessionId);
|
|
60
|
+
|
|
61
|
+
if (!tab) {
|
|
62
|
+
return res.status(404).json({ error: 'Session not found' });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log('[API] Force closing session:', sessionId);
|
|
66
|
+
|
|
67
|
+
// Disconnect the session
|
|
68
|
+
if (tab.type === 'ssh') {
|
|
69
|
+
sshManager.disconnect(sessionId);
|
|
70
|
+
} else if (tab.type === 'sftp') {
|
|
71
|
+
sftpManager.disconnect(sessionId);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Remove from openTabs
|
|
75
|
+
removeTab(sessionId);
|
|
76
|
+
|
|
77
|
+
// Broadcast to all clients that the session was closed
|
|
78
|
+
io.emit('tab-closed', { sessionId });
|
|
79
|
+
|
|
80
|
+
res.json({ success: true, sessionId });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// API: Close all sessions
|
|
84
|
+
app.post('/api/sessions/close-all', (req, res) => {
|
|
85
|
+
console.log('[API] Force closing all sessions');
|
|
86
|
+
|
|
87
|
+
const closedSessions = [];
|
|
88
|
+
const openTabs = getOpenTabs();
|
|
89
|
+
|
|
90
|
+
for (const [sessionId, tab] of openTabs) {
|
|
91
|
+
// Disconnect the session
|
|
92
|
+
if (tab.type === 'ssh') {
|
|
93
|
+
sshManager.disconnect(sessionId);
|
|
94
|
+
} else if (tab.type === 'sftp') {
|
|
95
|
+
sftpManager.disconnect(sessionId);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
closedSessions.push(sessionId);
|
|
99
|
+
|
|
100
|
+
// Broadcast to all clients
|
|
101
|
+
io.emit('tab-closed', { sessionId });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Clear all tabs - need to iterate and remove
|
|
105
|
+
for (const sessionId of closedSessions) {
|
|
106
|
+
removeTab(sessionId);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
res.json({ success: true, closedCount: closedSessions.length });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = { registerSessionsEndpoints };
|