@lethevimlet/sshift 0.9.1 → 0.9.3
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/package.json +1 -1
- package/src/server/endpoints/rest/index.js +3 -0
- package/src/server/endpoints/rest/plugins.js +91 -0
- package/src/server/endpoints/rest/system.js +2 -2
- package/src/server/plugins/plugin-manager.js +69 -0
- package/src/webapp/css/style.css +75 -0
- package/src/webapp/index.html +8 -0
- package/src/webapp/js/app.js +85 -0
- package/src/webapp/libs/fonts/JetBrainsMono-Regular.woff2 +0 -0
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
const { registerBookmarkEndpoints } = require('./bookmarks');
|
|
7
7
|
const { registerConfigEndpoints } = require('./config');
|
|
8
8
|
const { registerFolderEndpoints } = require('./folders');
|
|
9
|
+
const { registerPluginEndpoints } = require('./plugins');
|
|
9
10
|
const { registerSessionsEndpoints } = require('./sessions');
|
|
10
11
|
const { registerSystemEndpoints } = require('./system');
|
|
11
12
|
const { registerUtilsEndpoints } = require('./utils');
|
|
@@ -16,6 +17,7 @@ function registerAllRestEndpoints(app, io) {
|
|
|
16
17
|
registerBookmarkEndpoints(app, io);
|
|
17
18
|
registerConfigEndpoints(app, io);
|
|
18
19
|
registerFolderEndpoints(app, io);
|
|
20
|
+
registerPluginEndpoints(app, io);
|
|
19
21
|
registerSessionsEndpoints(app, io);
|
|
20
22
|
registerSystemEndpoints(app, io);
|
|
21
23
|
registerUtilsEndpoints(app, io);
|
|
@@ -25,6 +27,7 @@ module.exports = {
|
|
|
25
27
|
registerBookmarkEndpoints,
|
|
26
28
|
registerConfigEndpoints,
|
|
27
29
|
registerFolderEndpoints,
|
|
30
|
+
registerPluginEndpoints,
|
|
28
31
|
registerSessionsEndpoints,
|
|
29
32
|
registerSystemEndpoints,
|
|
30
33
|
registerUtilsEndpoints,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin REST endpoints
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const { loadConfig, saveConfig } = require('../../utils/config');
|
|
8
|
+
const pluginManager = require('../../plugins/plugin-manager');
|
|
9
|
+
|
|
10
|
+
function registerPluginEndpoints(app, io) {
|
|
11
|
+
app.get('/api/plugins', (req, res) => {
|
|
12
|
+
try {
|
|
13
|
+
const discovered = pluginManager.discoverPlugins();
|
|
14
|
+
const config = loadConfig();
|
|
15
|
+
const configuredPlugins = config.plugins || [];
|
|
16
|
+
|
|
17
|
+
const plugins = discovered.map(plugin => {
|
|
18
|
+
const existing = configuredPlugins.find(p => p.name === plugin.name);
|
|
19
|
+
return {
|
|
20
|
+
name: plugin.name,
|
|
21
|
+
description: plugin.description,
|
|
22
|
+
enabled: existing ? existing.enabled !== false : true,
|
|
23
|
+
config: existing ? (existing.config || {}) : {},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const configuredNames = new Set(configuredPlugins.map(p => p.name));
|
|
28
|
+
const extraPlugins = configuredPlugins
|
|
29
|
+
.filter(p => !discovered.find(d => d.name === p.name))
|
|
30
|
+
.map(p => ({
|
|
31
|
+
name: p.name,
|
|
32
|
+
description: 'Plugin not found in plugins directory',
|
|
33
|
+
enabled: p.enabled !== false,
|
|
34
|
+
config: p.config || {},
|
|
35
|
+
missing: true,
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
res.json([...plugins, ...extraPlugins]);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error('[PLUGINS] Error listing plugins:', err);
|
|
41
|
+
res.status(500).json({ error: 'Failed to list plugins' });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
app.post('/api/plugins', (req, res) => {
|
|
46
|
+
try {
|
|
47
|
+
const { name, enabled } = req.body;
|
|
48
|
+
|
|
49
|
+
if (!name) {
|
|
50
|
+
return res.status(400).json({ error: 'Plugin name is required' });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const discovered = pluginManager.discoverPlugins();
|
|
54
|
+
const pluginExists = discovered.some(p => p.name === name);
|
|
55
|
+
if (!pluginExists) {
|
|
56
|
+
return res.status(404).json({ error: 'Plugin not found' });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const config = loadConfig();
|
|
60
|
+
if (!config.plugins) {
|
|
61
|
+
config.plugins = [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const existingIndex = config.plugins.findIndex(p => p.name === name);
|
|
65
|
+
if (existingIndex >= 0) {
|
|
66
|
+
config.plugins[existingIndex].enabled = enabled;
|
|
67
|
+
} else {
|
|
68
|
+
config.plugins.push({ name, enabled, config: {} });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const saved = saveConfig(config);
|
|
72
|
+
if (!saved) {
|
|
73
|
+
return res.status(500).json({ error: 'Failed to save config' });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const reloadedConfig = loadConfig();
|
|
77
|
+
pluginManager.reload(reloadedConfig);
|
|
78
|
+
|
|
79
|
+
res.json({
|
|
80
|
+
success: true,
|
|
81
|
+
name,
|
|
82
|
+
enabled,
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error('[PLUGINS] Error updating plugin:', err);
|
|
86
|
+
res.status(500).json({ error: 'Failed to update plugin' });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { registerPluginEndpoints };
|
|
@@ -140,9 +140,9 @@ function registerSystemEndpoints(app, io) {
|
|
|
140
140
|
// Determine the install script based on platform
|
|
141
141
|
let installScript;
|
|
142
142
|
if (platform === 'win32') {
|
|
143
|
-
installScript = path.join(__dirname, '../../../../install.ps1');
|
|
143
|
+
installScript = path.join(__dirname, '../../../../sshift-install.ps1');
|
|
144
144
|
} else {
|
|
145
|
-
installScript = path.join(__dirname, '../../../../install.sh');
|
|
145
|
+
installScript = path.join(__dirname, '../../../../sshift-install.sh');
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
// Check if install script exists
|
|
@@ -41,6 +41,67 @@ class PluginManager {
|
|
|
41
41
|
this.flashingSessions = new Map(); // sessionId -> options
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
discoverPlugins() {
|
|
45
|
+
const builtinDir = path.join(__dirname, '..', '..', '..', 'plugins');
|
|
46
|
+
const discovered = [];
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync(builtinDir)) {
|
|
49
|
+
const entries = fs.readdirSync(builtinDir, { withFileTypes: true });
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (!entry.isDirectory()) continue;
|
|
52
|
+
const pluginDir = path.join(builtinDir, entry.name);
|
|
53
|
+
const indexFile = path.join(pluginDir, 'index.js');
|
|
54
|
+
const pkgFile = path.join(pluginDir, 'package.json');
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(indexFile)) continue;
|
|
57
|
+
|
|
58
|
+
let description = '';
|
|
59
|
+
if (fs.existsSync(pkgFile)) {
|
|
60
|
+
try {
|
|
61
|
+
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
|
|
62
|
+
description = pkg.description || '';
|
|
63
|
+
} catch (e) { /* ignore */ }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
discovered.push({
|
|
67
|
+
name: entry.name,
|
|
68
|
+
description,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return discovered;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
reload(config) {
|
|
77
|
+
this.config = config;
|
|
78
|
+
|
|
79
|
+
for (const hookFns of Object.values(this.hooks)) {
|
|
80
|
+
hookFns.length = 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const [name, pluginEntry] of this.plugins.entries()) {
|
|
84
|
+
const instance = pluginEntry.instance;
|
|
85
|
+
if (instance && typeof instance.onSessionDisconnect === 'function') {
|
|
86
|
+
for (const sessionId of this._lineBuffers.keys()) {
|
|
87
|
+
try { instance.onSessionDisconnect(sessionId); } catch (e) { /* ignore */ }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.plugins.clear();
|
|
93
|
+
this._lineBuffers.clear();
|
|
94
|
+
this.flashingSessions.clear();
|
|
95
|
+
|
|
96
|
+
if (this.io) {
|
|
97
|
+
for (const [, socket] of this.io.sockets.sockets) {
|
|
98
|
+
this.syncFlashState(socket);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this._loadPlugins();
|
|
103
|
+
}
|
|
104
|
+
|
|
44
105
|
init({ io, sshManager, tabManager, config }) {
|
|
45
106
|
this.io = io;
|
|
46
107
|
this.sshManager = sshManager;
|
|
@@ -61,6 +122,14 @@ class PluginManager {
|
|
|
61
122
|
}
|
|
62
123
|
}
|
|
63
124
|
|
|
125
|
+
getPluginDir(name) {
|
|
126
|
+
const localDir = path.join(__dirname, name);
|
|
127
|
+
const builtinDir = path.join(__dirname, '..', '..', '..', 'plugins', name);
|
|
128
|
+
if (fs.existsSync(path.join(localDir, 'index.js'))) return localDir;
|
|
129
|
+
if (fs.existsSync(path.join(builtinDir, 'index.js'))) return builtinDir;
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
64
133
|
_loadPlugin(pluginConfig) {
|
|
65
134
|
const { name } = pluginConfig;
|
|
66
135
|
|
package/src/webapp/css/style.css
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
@font-face {
|
|
2
|
+
font-family: 'JetBrains Mono';
|
|
3
|
+
font-style: normal;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
font-display: swap;
|
|
6
|
+
src: url('/libs/fonts/JetBrainsMono-Regular.woff2') format('woff2');
|
|
7
|
+
}
|
|
8
|
+
|
|
1
9
|
/* CSS Variables - Modern Dark Theme with Reddish-Fuchsia Accent */
|
|
2
10
|
:root {
|
|
3
11
|
--bg-primary: #0d1117;
|
|
@@ -3521,6 +3529,73 @@ body.dragging-tabs .tabs-container {
|
|
|
3521
3529
|
transform: translateX(20px);
|
|
3522
3530
|
}
|
|
3523
3531
|
|
|
3532
|
+
.setting-group-title {
|
|
3533
|
+
display: flex;
|
|
3534
|
+
align-items: center;
|
|
3535
|
+
gap: 8px;
|
|
3536
|
+
font-size: 14px;
|
|
3537
|
+
font-weight: 600;
|
|
3538
|
+
color: var(--text-primary);
|
|
3539
|
+
margin-bottom: 12px;
|
|
3540
|
+
}
|
|
3541
|
+
|
|
3542
|
+
.setting-group-title i {
|
|
3543
|
+
color: var(--accent-primary);
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
.plugins-list {
|
|
3547
|
+
display: flex;
|
|
3548
|
+
flex-direction: column;
|
|
3549
|
+
gap: 10px;
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
.plugins-loading {
|
|
3553
|
+
color: var(--text-secondary);
|
|
3554
|
+
font-size: 13px;
|
|
3555
|
+
padding: 8px 0;
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
.plugin-card {
|
|
3559
|
+
display: flex;
|
|
3560
|
+
align-items: center;
|
|
3561
|
+
justify-content: space-between;
|
|
3562
|
+
padding: 12px 16px;
|
|
3563
|
+
background: var(--bg-secondary);
|
|
3564
|
+
border: 1px solid var(--border-color);
|
|
3565
|
+
border-radius: 8px;
|
|
3566
|
+
gap: 12px;
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
.plugin-card.missing {
|
|
3570
|
+
opacity: 0.55;
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
.plugin-card-info {
|
|
3574
|
+
display: flex;
|
|
3575
|
+
flex-direction: column;
|
|
3576
|
+
gap: 2px;
|
|
3577
|
+
min-width: 0;
|
|
3578
|
+
flex: 1;
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
.plugin-card-name {
|
|
3582
|
+
font-weight: 600;
|
|
3583
|
+
font-size: 14px;
|
|
3584
|
+
color: var(--text-primary);
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
.plugin-card-description {
|
|
3588
|
+
font-size: 12px;
|
|
3589
|
+
color: var(--text-secondary);
|
|
3590
|
+
line-height: 1.4;
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
.plugin-card-missing {
|
|
3594
|
+
font-size: 11px;
|
|
3595
|
+
color: var(--accent-danger, #f85149);
|
|
3596
|
+
margin-top: 2px;
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3524
3599
|
/* Mobile Keys Bar */
|
|
3525
3600
|
.mobile-keys-bar {
|
|
3526
3601
|
display: none;
|
package/src/webapp/index.html
CHANGED
|
@@ -854,6 +854,14 @@
|
|
|
854
854
|
</div>
|
|
855
855
|
</div>
|
|
856
856
|
</div>
|
|
857
|
+
|
|
858
|
+
<!-- Plugins -->
|
|
859
|
+
<div class="setting-group">
|
|
860
|
+
<h3 class="setting-group-title"><i class="fas fa-puzzle-piece"></i> Plugins</h3>
|
|
861
|
+
<div id="pluginsList" class="plugins-list">
|
|
862
|
+
<div class="plugins-loading">Loading plugins...</div>
|
|
863
|
+
</div>
|
|
864
|
+
</div>
|
|
857
865
|
</div>
|
|
858
866
|
<div class="modal-footer" style="justify-content: space-between;">
|
|
859
867
|
<button class="btn btn-danger" id="logoutBtn" style="display: none;">
|
package/src/webapp/js/app.js
CHANGED
|
@@ -4259,6 +4259,9 @@ class SSHIFTClient {
|
|
|
4259
4259
|
// Update password toggle button state
|
|
4260
4260
|
this.updatePasswordToggleUI();
|
|
4261
4261
|
|
|
4262
|
+
// Load plugins
|
|
4263
|
+
this.loadPlugins();
|
|
4264
|
+
|
|
4262
4265
|
this.openModal('settingsModal');
|
|
4263
4266
|
}
|
|
4264
4267
|
|
|
@@ -4981,6 +4984,88 @@ class SSHIFTClient {
|
|
|
4981
4984
|
});
|
|
4982
4985
|
}
|
|
4983
4986
|
|
|
4987
|
+
async loadPlugins() {
|
|
4988
|
+
const pluginsList = document.getElementById('pluginsList');
|
|
4989
|
+
if (!pluginsList) return;
|
|
4990
|
+
|
|
4991
|
+
pluginsList.innerHTML = '<div class="plugins-loading">Loading plugins...</div>';
|
|
4992
|
+
|
|
4993
|
+
try {
|
|
4994
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
4995
|
+
if (this.authToken) headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
4996
|
+
const response = await fetch('/api/plugins', { headers });
|
|
4997
|
+
|
|
4998
|
+
if (!response.ok) {
|
|
4999
|
+
pluginsList.innerHTML = '<div class="plugins-loading">Failed to load plugins</div>';
|
|
5000
|
+
return;
|
|
5001
|
+
}
|
|
5002
|
+
|
|
5003
|
+
const plugins = await response.json();
|
|
5004
|
+
|
|
5005
|
+
if (plugins.length === 0) {
|
|
5006
|
+
pluginsList.innerHTML = '<div class="plugins-loading">No plugins available</div>';
|
|
5007
|
+
return;
|
|
5008
|
+
}
|
|
5009
|
+
|
|
5010
|
+
pluginsList.innerHTML = plugins.map(plugin => {
|
|
5011
|
+
const name = this.escapeHtml(plugin.name);
|
|
5012
|
+
const description = this.escapeHtml(plugin.description || '');
|
|
5013
|
+
const isMissing = plugin.missing === true;
|
|
5014
|
+
const missingClass = isMissing ? ' missing' : '';
|
|
5015
|
+
const missingHtml = isMissing ? '<div class="plugin-card-missing"><i class="fas fa-exclamation-triangle"></i> Plugin directory not found</div>' : '';
|
|
5016
|
+
|
|
5017
|
+
return `
|
|
5018
|
+
<div class="plugin-card${missingClass}" data-plugin="${name}">
|
|
5019
|
+
<div class="plugin-card-info">
|
|
5020
|
+
<div class="plugin-card-name">${name}</div>
|
|
5021
|
+
${description ? `<div class="plugin-card-description">${description}</div>` : ''}
|
|
5022
|
+
${missingHtml}
|
|
5023
|
+
</div>
|
|
5024
|
+
<label class="toggle-switch">
|
|
5025
|
+
<input type="checkbox" class="plugin-toggle" data-plugin="${name}" ${plugin.enabled ? 'checked' : ''} ${isMissing ? 'disabled' : ''}>
|
|
5026
|
+
<span class="toggle-slider"></span>
|
|
5027
|
+
</label>
|
|
5028
|
+
</div>
|
|
5029
|
+
`;
|
|
5030
|
+
}).join('');
|
|
5031
|
+
|
|
5032
|
+
pluginsList.querySelectorAll('.plugin-toggle').forEach(toggle => {
|
|
5033
|
+
toggle.addEventListener('change', (e) => {
|
|
5034
|
+
const pluginName = e.target.dataset.plugin;
|
|
5035
|
+
const enabled = e.target.checked;
|
|
5036
|
+
this.togglePlugin(pluginName, enabled, e.target);
|
|
5037
|
+
});
|
|
5038
|
+
});
|
|
5039
|
+
} catch (err) {
|
|
5040
|
+
console.error('[SSHIFT] Error loading plugins:', err);
|
|
5041
|
+
pluginsList.innerHTML = '<div class="plugins-loading">Failed to load plugins</div>';
|
|
5042
|
+
}
|
|
5043
|
+
}
|
|
5044
|
+
|
|
5045
|
+
async togglePlugin(name, enabled, toggleEl) {
|
|
5046
|
+
try {
|
|
5047
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
5048
|
+
if (this.authToken) headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
5049
|
+
const response = await fetch('/api/plugins', {
|
|
5050
|
+
method: 'POST',
|
|
5051
|
+
headers,
|
|
5052
|
+
body: JSON.stringify({ name, enabled })
|
|
5053
|
+
});
|
|
5054
|
+
|
|
5055
|
+
if (!response.ok) {
|
|
5056
|
+
toggleEl.checked = !enabled;
|
|
5057
|
+
this.showToast('Failed to update plugin', 'error');
|
|
5058
|
+
return;
|
|
5059
|
+
}
|
|
5060
|
+
|
|
5061
|
+
this.showToast(`Plugin "${name}" ${enabled ? 'enabled' : 'disabled'}`, 'success');
|
|
5062
|
+
} catch (err) {
|
|
5063
|
+
console.error('[SSHIFT] Error toggling plugin:', err);
|
|
5064
|
+
toggleEl.checked = !enabled;
|
|
5065
|
+
this.showToast('Failed to update plugin', 'error');
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
5068
|
+
|
|
4984
5069
|
saveTerminalColorSettings() {
|
|
4985
5070
|
// Save settings for current theme
|
|
4986
5071
|
const themeKey = this.theme; // 'dark' or 'light'
|
|
Binary file
|