@lethevimlet/sshift 0.4.0 → 0.5.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/README.md +1 -0
- package/example.config.json +1 -0
- package/package.json +1 -1
- package/src/server/endpoints/rest/auth.js +87 -0
- package/src/server/endpoints/rest/config.js +10 -10
- package/src/server/endpoints/rest/index.js +4 -5
- package/src/server/index.js +72 -11
- package/src/server/utils/config.js +54 -2
- package/src/webapp/css/style.css +95 -0
- package/src/webapp/icons/apple-touch-icon.png +0 -0
- package/src/webapp/icons/favicon-16x16.png +0 -0
- package/src/webapp/icons/favicon-32x32.png +0 -0
- package/src/webapp/icons/icon-128x128.png +0 -0
- package/src/webapp/icons/icon-144x144.png +0 -0
- package/src/webapp/icons/icon-152x152.png +0 -0
- package/src/webapp/icons/icon-192x192.png +0 -0
- package/src/webapp/icons/icon-384x384.png +0 -0
- package/src/webapp/icons/icon-512x512.png +0 -0
- package/src/webapp/icons/icon-72x72.png +0 -0
- package/src/webapp/icons/icon-96x96.png +0 -0
- package/src/webapp/index.html +89 -1
- package/src/webapp/js/app.js +293 -3
- package/src/webapp/manifest.json +54 -0
- package/src/webapp/sw.js +55 -0
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ A modern, responsive web-based SSH and SFTP terminal client built with Node.js,
|
|
|
22
22
|
- 📁 **SFTP Browser** - File manager interface with upload/download
|
|
23
23
|
- 🗂️ **Tabbed Interface** - Multiple concurrent sessions
|
|
24
24
|
- 🔖 **Bookmarks** - Save connection details for quick access
|
|
25
|
+
- 🔒 **Password Protection** - Optional password lock for app access
|
|
25
26
|
- ⌨️ **Mobile-Friendly** - Special keys popup for mobile devices
|
|
26
27
|
- 🎨 **Modern UI** - GitHub-inspired dark theme, fully responsive
|
|
27
28
|
|
package/example.config.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const { isPasswordSet, verifyPassword, setPassword, removePassword } = require('../../utils/config');
|
|
2
|
+
|
|
3
|
+
const authTokens = new Map();
|
|
4
|
+
const TOKEN_TTL = 24 * 60 * 60 * 1000;
|
|
5
|
+
|
|
6
|
+
function generateToken() {
|
|
7
|
+
const crypto = require('crypto');
|
|
8
|
+
return crypto.randomBytes(32).toString('hex');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function cleanExpiredTokens() {
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
for (const [token, expiry] of authTokens) {
|
|
14
|
+
if (expiry < now) authTokens.delete(token);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function registerAuthEndpoints(app, io) {
|
|
19
|
+
app.get('/api/auth/status', (req, res) => {
|
|
20
|
+
res.json({ passwordEnabled: isPasswordSet() });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.post('/api/auth/login', (req, res) => {
|
|
24
|
+
const { password } = req.body;
|
|
25
|
+
if (!isPasswordSet()) {
|
|
26
|
+
return res.json({ success: true, authenticated: true });
|
|
27
|
+
}
|
|
28
|
+
if (!password) {
|
|
29
|
+
return res.status(400).json({ error: 'Password required' });
|
|
30
|
+
}
|
|
31
|
+
if (!verifyPassword(password)) {
|
|
32
|
+
return res.status(401).json({ error: 'Invalid password' });
|
|
33
|
+
}
|
|
34
|
+
const token = generateToken();
|
|
35
|
+
authTokens.set(token, Date.now() + TOKEN_TTL);
|
|
36
|
+
cleanExpiredTokens();
|
|
37
|
+
res.json({ success: true, token });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
app.post('/api/auth/set-password', (req, res) => {
|
|
41
|
+
const { currentPassword, newPassword } = req.body;
|
|
42
|
+
if (isPasswordSet()) {
|
|
43
|
+
if (!currentPassword || !verifyPassword(currentPassword)) {
|
|
44
|
+
return res.status(401).json({ error: 'Current password is incorrect' });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!newPassword || newPassword.length < 1) {
|
|
48
|
+
return res.status(400).json({ error: 'Password cannot be empty' });
|
|
49
|
+
}
|
|
50
|
+
const result = setPassword(newPassword);
|
|
51
|
+
if (result) {
|
|
52
|
+
res.json({ success: true });
|
|
53
|
+
} else {
|
|
54
|
+
res.status(500).json({ error: 'Failed to save password' });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
app.post('/api/auth/remove-password', (req, res) => {
|
|
59
|
+
const { currentPassword } = req.body;
|
|
60
|
+
if (!isPasswordSet()) {
|
|
61
|
+
return res.json({ success: true });
|
|
62
|
+
}
|
|
63
|
+
if (!currentPassword || !verifyPassword(currentPassword)) {
|
|
64
|
+
return res.status(401).json({ error: 'Current password is incorrect' });
|
|
65
|
+
}
|
|
66
|
+
const result = removePassword();
|
|
67
|
+
if (result) {
|
|
68
|
+
res.json({ success: true });
|
|
69
|
+
} else {
|
|
70
|
+
res.status(500).json({ error: 'Failed to remove password' });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isValidAuthToken(token) {
|
|
76
|
+
if (!token) return false;
|
|
77
|
+
cleanExpiredTokens();
|
|
78
|
+
const expiry = authTokens.get(token);
|
|
79
|
+
if (!expiry) return false;
|
|
80
|
+
if (expiry < Date.now()) {
|
|
81
|
+
authTokens.delete(token);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = { registerAuthEndpoints, isValidAuthToken };
|
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
const { loadConfig, saveConfig } = require('../../utils/config');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const AUTH_WHITELIST = [
|
|
8
|
+
'/api/auth/status',
|
|
9
|
+
'/api/auth/login'
|
|
10
|
+
];
|
|
11
|
+
|
|
12
12
|
function registerConfigEndpoints(app, io) {
|
|
13
|
-
// API: Get config (for sticky sessions and SSH keepalive)
|
|
14
13
|
app.get('/api/config', (req, res) => {
|
|
15
14
|
const config = loadConfig();
|
|
16
15
|
res.json({
|
|
17
|
-
sticky: config.sticky !== false,
|
|
18
|
-
takeControlDefault: config.takeControlDefault !== false,
|
|
16
|
+
sticky: config.sticky !== false,
|
|
17
|
+
takeControlDefault: config.takeControlDefault !== false,
|
|
19
18
|
sshKeepaliveInterval: config.sshKeepaliveInterval || 10000,
|
|
20
19
|
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000,
|
|
21
|
-
mobileKeysBarEnabled: config.mobileKeysBarEnabled !== false,
|
|
22
|
-
layouts: config.layouts || null
|
|
20
|
+
mobileKeysBarEnabled: config.mobileKeysBarEnabled !== false,
|
|
21
|
+
layouts: config.layouts || null,
|
|
22
|
+
passwordEnabled: !!config.passwordHash
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
|
|
@@ -9,13 +9,10 @@ const { registerFolderEndpoints } = require('./folders');
|
|
|
9
9
|
const { registerSessionsEndpoints } = require('./sessions');
|
|
10
10
|
const { registerSystemEndpoints } = require('./system');
|
|
11
11
|
const { registerUtilsEndpoints } = require('./utils');
|
|
12
|
+
const { registerAuthEndpoints, isValidAuthToken } = require('./auth');
|
|
12
13
|
|
|
13
|
-
/**
|
|
14
|
-
* Register all REST endpoints
|
|
15
|
-
* @param {Object} app - Express app
|
|
16
|
-
* @param {Object} io - Socket.IO instance
|
|
17
|
-
*/
|
|
18
14
|
function registerAllRestEndpoints(app, io) {
|
|
15
|
+
registerAuthEndpoints(app, io);
|
|
19
16
|
registerBookmarkEndpoints(app, io);
|
|
20
17
|
registerConfigEndpoints(app, io);
|
|
21
18
|
registerFolderEndpoints(app, io);
|
|
@@ -31,5 +28,7 @@ module.exports = {
|
|
|
31
28
|
registerSessionsEndpoints,
|
|
32
29
|
registerSystemEndpoints,
|
|
33
30
|
registerUtilsEndpoints,
|
|
31
|
+
registerAuthEndpoints,
|
|
32
|
+
isValidAuthToken,
|
|
34
33
|
registerAllRestEndpoints
|
|
35
34
|
};
|
package/src/server/index.js
CHANGED
|
@@ -12,12 +12,13 @@ require('./utils/env-loader');
|
|
|
12
12
|
const express = require('express');
|
|
13
13
|
const http = require('http');
|
|
14
14
|
const https = require('https');
|
|
15
|
+
const fs = require('fs');
|
|
15
16
|
const path = require('path');
|
|
16
17
|
const socketIO = require('socket.io');
|
|
17
18
|
const selfsigned = require('selfsigned');
|
|
18
19
|
|
|
19
20
|
// Import utilities
|
|
20
|
-
const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps } = require('./utils/config');
|
|
21
|
+
const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getDataDir, isPasswordSet } = require('./utils/config');
|
|
21
22
|
|
|
22
23
|
// Import services
|
|
23
24
|
const { sshManager, sftpManager } = require('./services');
|
|
@@ -25,8 +26,49 @@ const { sshManager, sftpManager } = require('./services');
|
|
|
25
26
|
// Import endpoints
|
|
26
27
|
const { rest, ws } = require('./endpoints');
|
|
27
28
|
|
|
29
|
+
const SSL_CERT_FILE = 'ssl-cert.pem';
|
|
30
|
+
const SSL_KEY_FILE = 'ssl-key.pem';
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
33
|
+
* Get SSL credentials, reusing persisted certificates if available.
|
|
34
|
+
* Generates new self-signed certificates only if no persisted ones exist.
|
|
35
|
+
* @returns {Promise<Object>} Certificate and private key
|
|
36
|
+
*/
|
|
37
|
+
async function getSSLCredentials() {
|
|
38
|
+
const dataDir = getDataDir();
|
|
39
|
+
const certPath = path.join(dataDir, SSL_CERT_FILE);
|
|
40
|
+
const keyPath = path.join(dataDir, SSL_KEY_FILE);
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(certPath) && fs.existsSync(keyPath)) {
|
|
43
|
+
console.log('[HTTPS] Reusing persisted SSL certificate from', dataDir);
|
|
44
|
+
try {
|
|
45
|
+
return {
|
|
46
|
+
cert: fs.readFileSync(certPath, 'utf8'),
|
|
47
|
+
key: fs.readFileSync(keyPath, 'utf8')
|
|
48
|
+
};
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.warn('[HTTPS] Failed to read persisted certificate, regenerating:', err.message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const creds = await generateSelfSignedCert();
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
if (!fs.existsSync(dataDir)) {
|
|
58
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
fs.writeFileSync(certPath, creds.cert, { mode: 0o600 });
|
|
61
|
+
fs.writeFileSync(keyPath, creds.key, { mode: 0o600 });
|
|
62
|
+
console.log('[HTTPS] SSL certificate persisted to', dataDir);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.warn('[HTTPS] Failed to persist certificate:', err.message);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return creds;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generate self-signed SSL certificates using selfsigned package (pure JS, no OpenSSL dependency)
|
|
30
72
|
* @returns {Promise<Object>} Certificate and private key
|
|
31
73
|
*/
|
|
32
74
|
async function generateSelfSignedCert() {
|
|
@@ -34,11 +76,9 @@ async function generateSelfSignedCert() {
|
|
|
34
76
|
|
|
35
77
|
const os = require('os');
|
|
36
78
|
|
|
37
|
-
// Get local IP addresses for SAN
|
|
38
79
|
const interfaces = os.networkInterfaces();
|
|
39
80
|
const localIPs = ['127.0.0.1'];
|
|
40
81
|
|
|
41
|
-
// Extract all IPv4 addresses from network interfaces
|
|
42
82
|
Object.values(interfaces).forEach(iface => {
|
|
43
83
|
iface.forEach(addr => {
|
|
44
84
|
if (addr.family === 'IPv4' && !addr.internal) {
|
|
@@ -47,12 +87,10 @@ async function generateSelfSignedCert() {
|
|
|
47
87
|
});
|
|
48
88
|
});
|
|
49
89
|
|
|
50
|
-
// Get hostname
|
|
51
90
|
const hostname = os.hostname() || 'localhost';
|
|
52
91
|
|
|
53
92
|
console.log('[HTTPS] Certificate will be valid for:', localIPs.join(', '), 'and hostname:', hostname);
|
|
54
93
|
|
|
55
|
-
// Build Subject Alternative Names
|
|
56
94
|
const altNames = [
|
|
57
95
|
{ type: 2, value: 'localhost' },
|
|
58
96
|
{ type: 2, value: hostname },
|
|
@@ -97,7 +135,7 @@ async function initializeServer() {
|
|
|
97
135
|
|
|
98
136
|
if (enableHttps) {
|
|
99
137
|
try {
|
|
100
|
-
sslCredentials = await
|
|
138
|
+
sslCredentials = await getSSLCredentials();
|
|
101
139
|
server = https.createServer({
|
|
102
140
|
key: sslCredentials.key,
|
|
103
141
|
cert: sslCredentials.cert
|
|
@@ -117,10 +155,16 @@ async function initializeServer() {
|
|
|
117
155
|
origin: "*",
|
|
118
156
|
methods: ["GET", "POST"]
|
|
119
157
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
158
|
+
pingTimeout: 60000,
|
|
159
|
+
pingInterval: 25000
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Socket.IO auth middleware
|
|
163
|
+
io.use((socket, next) => {
|
|
164
|
+
if (!isPasswordSet()) return next();
|
|
165
|
+
const token = socket.handshake.auth.token || socket.handshake.query.token;
|
|
166
|
+
if (isValidAuthToken(token)) return next();
|
|
167
|
+
next(new Error('Authentication required'));
|
|
124
168
|
});
|
|
125
169
|
|
|
126
170
|
// Set the socket.io instance for services that need it
|
|
@@ -129,6 +173,23 @@ async function initializeServer() {
|
|
|
129
173
|
// Middleware
|
|
130
174
|
app.use(express.json());
|
|
131
175
|
|
|
176
|
+
// Auth middleware - block API endpoints when password is set
|
|
177
|
+
const { isValidAuthToken } = require('./endpoints/rest/auth');
|
|
178
|
+
const AUTH_WHITELIST = ['/auth/status', '/auth/login'];
|
|
179
|
+
|
|
180
|
+
app.use('/api', (req, res, next) => {
|
|
181
|
+
if (AUTH_WHITELIST.some(p => req.path === p)) return next();
|
|
182
|
+
if (!isPasswordSet()) return next();
|
|
183
|
+
const token = req.headers.authorization?.replace('Bearer ', '') || req.query.token;
|
|
184
|
+
if (isValidAuthToken(token)) return next();
|
|
185
|
+
res.status(401).json({ error: 'Authentication required' });
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
app.use((req, res, next) => {
|
|
189
|
+
if (req.path.startsWith('/api/') || req.path.startsWith('/socket.io/')) return next();
|
|
190
|
+
next();
|
|
191
|
+
});
|
|
192
|
+
|
|
132
193
|
// Serve static files from the webapp directory
|
|
133
194
|
const webappPath = path.join(__dirname, '../webapp');
|
|
134
195
|
app.use(express.static(webappPath));
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const os = require('os');
|
|
9
|
+
const crypto = require('crypto');
|
|
9
10
|
|
|
10
11
|
// Get user's home directory
|
|
11
12
|
const HOME_DIR = os.homedir();
|
|
@@ -39,7 +40,8 @@ const defaultConfig = {
|
|
|
39
40
|
sshKeepaliveInterval: 15000,
|
|
40
41
|
sshKeepaliveCountMax: 500,
|
|
41
42
|
bookmarks: [],
|
|
42
|
-
folders: []
|
|
43
|
+
folders: [],
|
|
44
|
+
passwordHash: null
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
/**
|
|
@@ -220,6 +222,50 @@ function getEnableHttps() {
|
|
|
220
222
|
return config.enableHttps !== false; // Default to true
|
|
221
223
|
}
|
|
222
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Get the data directory for persistent storage (SSL certs, etc.)
|
|
227
|
+
* Searches the same paths as config to find a writable data directory.
|
|
228
|
+
* @returns {string} Path to data directory
|
|
229
|
+
*/
|
|
230
|
+
function getDataDir() {
|
|
231
|
+
const configPath = getConfigPath();
|
|
232
|
+
const configDir = path.dirname(configPath);
|
|
233
|
+
|
|
234
|
+
// If config is in a .env subdirectory, use parent
|
|
235
|
+
if (path.basename(configDir) === '.env') {
|
|
236
|
+
return path.dirname(configDir);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return configDir;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function hashPassword(password) {
|
|
243
|
+
return crypto.createHash('sha3-256').update(password).digest('hex');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function isPasswordSet() {
|
|
247
|
+
const config = loadConfig();
|
|
248
|
+
return !!config.passwordHash;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function verifyPassword(password) {
|
|
252
|
+
const config = loadConfig();
|
|
253
|
+
if (!config.passwordHash) return true;
|
|
254
|
+
return hashPassword(password) === config.passwordHash;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function setPassword(password) {
|
|
258
|
+
const config = loadConfig();
|
|
259
|
+
config.passwordHash = hashPassword(password);
|
|
260
|
+
return saveConfig(config);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function removePassword() {
|
|
264
|
+
const config = loadConfig();
|
|
265
|
+
config.passwordHash = null;
|
|
266
|
+
return saveConfig(config);
|
|
267
|
+
}
|
|
268
|
+
|
|
223
269
|
module.exports = {
|
|
224
270
|
defaultConfig,
|
|
225
271
|
ensureConfig,
|
|
@@ -233,5 +279,11 @@ module.exports = {
|
|
|
233
279
|
getTakeControlDefault,
|
|
234
280
|
getMobileKeysBarEnabled,
|
|
235
281
|
getLayouts,
|
|
236
|
-
getEnableHttps
|
|
282
|
+
getEnableHttps,
|
|
283
|
+
getDataDir,
|
|
284
|
+
hashPassword,
|
|
285
|
+
isPasswordSet,
|
|
286
|
+
verifyPassword,
|
|
287
|
+
setPassword,
|
|
288
|
+
removePassword
|
|
237
289
|
};
|
package/src/webapp/css/style.css
CHANGED
|
@@ -4517,4 +4517,99 @@ body.dragging-tabs .tabs-container {
|
|
|
4517
4517
|
|
|
4518
4518
|
[data-theme="light"] .mobile-menu-btn i {
|
|
4519
4519
|
color: #656d76;
|
|
4520
|
+
}
|
|
4521
|
+
|
|
4522
|
+
/* Lock Screen */
|
|
4523
|
+
.lock-screen {
|
|
4524
|
+
position: fixed;
|
|
4525
|
+
top: 0;
|
|
4526
|
+
left: 0;
|
|
4527
|
+
width: 100%;
|
|
4528
|
+
height: 100%;
|
|
4529
|
+
background: var(--bg-primary);
|
|
4530
|
+
z-index: 100000;
|
|
4531
|
+
display: flex;
|
|
4532
|
+
align-items: center;
|
|
4533
|
+
justify-content: center;
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4536
|
+
.lock-screen-content {
|
|
4537
|
+
text-align: center;
|
|
4538
|
+
width: 100%;
|
|
4539
|
+
max-width: 360px;
|
|
4540
|
+
padding: 40px 24px;
|
|
4541
|
+
}
|
|
4542
|
+
|
|
4543
|
+
.lock-screen-icon {
|
|
4544
|
+
font-size: 48px;
|
|
4545
|
+
color: var(--accent-primary);
|
|
4546
|
+
margin-bottom: 16px;
|
|
4547
|
+
}
|
|
4548
|
+
|
|
4549
|
+
.lock-screen-title {
|
|
4550
|
+
font-size: 32px;
|
|
4551
|
+
font-weight: 700;
|
|
4552
|
+
color: var(--text-primary);
|
|
4553
|
+
margin: 0 0 4px;
|
|
4554
|
+
}
|
|
4555
|
+
|
|
4556
|
+
.lock-screen-subtitle {
|
|
4557
|
+
font-size: 14px;
|
|
4558
|
+
color: var(--text-secondary);
|
|
4559
|
+
margin: 0 0 32px;
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
.lock-screen-form {
|
|
4563
|
+
display: flex;
|
|
4564
|
+
flex-direction: column;
|
|
4565
|
+
gap: 12px;
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4568
|
+
.lock-screen-input {
|
|
4569
|
+
width: 100%;
|
|
4570
|
+
padding: 10px 14px;
|
|
4571
|
+
background: var(--bg-secondary);
|
|
4572
|
+
border: 1px solid var(--border-color);
|
|
4573
|
+
border-radius: var(--radius-md);
|
|
4574
|
+
color: var(--text-primary);
|
|
4575
|
+
font-size: 14px;
|
|
4576
|
+
font-family: var(--font-sans);
|
|
4577
|
+
outline: none;
|
|
4578
|
+
box-sizing: border-box;
|
|
4579
|
+
transition: border-color var(--transition-fast);
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
.lock-screen-input:focus {
|
|
4583
|
+
border-color: var(--accent-primary);
|
|
4584
|
+
}
|
|
4585
|
+
|
|
4586
|
+
.lock-screen-submit {
|
|
4587
|
+
width: 100%;
|
|
4588
|
+
padding: 10px 16px;
|
|
4589
|
+
font-size: 14px;
|
|
4590
|
+
}
|
|
4591
|
+
|
|
4592
|
+
.lock-screen-error {
|
|
4593
|
+
color: var(--accent-danger);
|
|
4594
|
+
font-size: 13px;
|
|
4595
|
+
margin-top: 8px;
|
|
4596
|
+
}
|
|
4597
|
+
|
|
4598
|
+
/* Password disclaimer */
|
|
4599
|
+
.password-disclaimer {
|
|
4600
|
+
background: rgba(210, 153, 34, 0.1);
|
|
4601
|
+
border: 1px solid rgba(210, 153, 34, 0.3);
|
|
4602
|
+
border-radius: var(--radius-sm);
|
|
4603
|
+
padding: 8px 10px;
|
|
4604
|
+
margin-top: 4px;
|
|
4605
|
+
font-size: 12px;
|
|
4606
|
+
color: var(--accent-warning);
|
|
4607
|
+
}
|
|
4608
|
+
|
|
4609
|
+
.password-disclaimer i {
|
|
4610
|
+
margin-right: 4px;
|
|
4611
|
+
}
|
|
4612
|
+
|
|
4613
|
+
.password-disclaimer strong {
|
|
4614
|
+
color: var(--accent-warning);
|
|
4520
4615
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/webapp/index.html
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, interactive-widget=resizes-content">
|
|
6
6
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:;">
|
|
7
|
+
<meta name="theme-color" content="#1a1b26">
|
|
8
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
9
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
10
|
+
<meta name="apple-mobile-web-app-title" content="SSHIFT">
|
|
11
|
+
<link rel="manifest" href="/manifest.json">
|
|
12
|
+
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
|
|
13
|
+
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">
|
|
14
|
+
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">
|
|
7
15
|
<title>SSHIFT - SSH & SFTP Terminal Client</title>
|
|
8
16
|
<!-- Local resources for offline support -->
|
|
9
17
|
<link rel="stylesheet" href="/libs/xterm/xterm.css">
|
|
@@ -12,6 +20,24 @@
|
|
|
12
20
|
<script src="/libs/lucide/lucide.min.js"></script>
|
|
13
21
|
</head>
|
|
14
22
|
<body>
|
|
23
|
+
<!-- Lock Screen Overlay (shown by default, hidden by JS if no password) -->
|
|
24
|
+
<div class="lock-screen" id="lockScreen">
|
|
25
|
+
<div class="lock-screen-content">
|
|
26
|
+
<div class="lock-screen-icon">
|
|
27
|
+
<i class="fas fa-spinner fa-spin"></i>
|
|
28
|
+
</div>
|
|
29
|
+
<h2 class="lock-screen-title">SSHIFT</h2>
|
|
30
|
+
<p class="lock-screen-subtitle" id="lockScreenSubtitle">Loading...</p>
|
|
31
|
+
<form id="lockScreenForm" class="lock-screen-form" style="display: none;">
|
|
32
|
+
<input type="password" id="lockScreenPassword" class="lock-screen-input" placeholder="Enter password" autocomplete="current-password" autofocus>
|
|
33
|
+
<button type="submit" class="btn btn-primary lock-screen-submit">
|
|
34
|
+
<i class="fas fa-sign-in-alt"></i> Unlock
|
|
35
|
+
</button>
|
|
36
|
+
</form>
|
|
37
|
+
<p class="lock-screen-error" id="lockScreenError" style="display: none;"></p>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
15
41
|
<div class="app-container">
|
|
16
42
|
<!-- Header -->
|
|
17
43
|
<header class="header">
|
|
@@ -792,6 +818,26 @@
|
|
|
792
818
|
</div>
|
|
793
819
|
</div>
|
|
794
820
|
|
|
821
|
+
<!-- Password Protection -->
|
|
822
|
+
<div class="setting-group">
|
|
823
|
+
<div class="setting-item">
|
|
824
|
+
<label class="setting-label">
|
|
825
|
+
<i class="fas fa-lock"></i> Password Protection
|
|
826
|
+
</label>
|
|
827
|
+
<div class="setting-description">
|
|
828
|
+
Require a password to access the application. When enabled, all endpoints are blocked until the correct password is provided.
|
|
829
|
+
</div>
|
|
830
|
+
<div class="setting-description password-disclaimer">
|
|
831
|
+
<i class="fas fa-exclamation-triangle"></i> <strong>Disclaimer:</strong> This is a basic access restriction, not a substitute for proper authentication. If you expose sshift to a public network, you should use additional security measures such as a reverse proxy with authentication, a VPN, or firewall rules.
|
|
832
|
+
</div>
|
|
833
|
+
<div class="setting-control">
|
|
834
|
+
<button class="btn btn-secondary" id="togglePasswordBtn">
|
|
835
|
+
<i class="fas fa-lock-open"></i> <span id="togglePasswordLabel">Enable Password</span>
|
|
836
|
+
</button>
|
|
837
|
+
</div>
|
|
838
|
+
</div>
|
|
839
|
+
</div>
|
|
840
|
+
|
|
795
841
|
<!-- Manage Sessions -->
|
|
796
842
|
<div class="setting-group">
|
|
797
843
|
<div class="setting-item">
|
|
@@ -809,7 +855,11 @@
|
|
|
809
855
|
</div>
|
|
810
856
|
</div>
|
|
811
857
|
</div>
|
|
812
|
-
<div class="modal-footer">
|
|
858
|
+
<div class="modal-footer" style="justify-content: space-between;">
|
|
859
|
+
<button class="btn btn-danger" id="logoutBtn" style="display: none;">
|
|
860
|
+
<i class="fas fa-sign-out-alt"></i> Logout
|
|
861
|
+
</button>
|
|
862
|
+
<div style="flex:1;"></div>
|
|
813
863
|
<button class="btn" id="cancelSettings">Cancel</button>
|
|
814
864
|
<button class="btn btn-primary" id="saveSettings">
|
|
815
865
|
<i class="fas fa-save"></i> Save
|
|
@@ -844,6 +894,37 @@
|
|
|
844
894
|
</div>
|
|
845
895
|
</div>
|
|
846
896
|
|
|
897
|
+
<!-- Password Modal -->
|
|
898
|
+
<div class="modal" id="passwordModal">
|
|
899
|
+
<div class="modal-content modal-sm">
|
|
900
|
+
<div class="modal-header">
|
|
901
|
+
<h2 id="passwordModalTitle"><i class="fas fa-lock"></i> Enter Password</h2>
|
|
902
|
+
<button class="modal-close" id="closePasswordModal">
|
|
903
|
+
<i class="fas fa-times"></i>
|
|
904
|
+
</button>
|
|
905
|
+
</div>
|
|
906
|
+
<div class="modal-body">
|
|
907
|
+
<div class="setting-group">
|
|
908
|
+
<div class="setting-item" style="flex-direction: column; align-items: stretch;">
|
|
909
|
+
<label class="setting-label" id="passwordModalLabel">Password</label>
|
|
910
|
+
<input type="password" id="passwordModalInput" class="setting-input" placeholder="Enter password" autocomplete="off" style="width:100%; margin-top:8px;">
|
|
911
|
+
<div id="confirmPasswordGroup" style="display: none; margin-top: 12px;">
|
|
912
|
+
<label class="setting-label" style="margin-bottom: 8px;">Confirm Password</label>
|
|
913
|
+
<input type="password" id="passwordModalConfirmInput" class="setting-input" placeholder="Confirm password" autocomplete="off" style="width:100%;">
|
|
914
|
+
</div>
|
|
915
|
+
</div>
|
|
916
|
+
</div>
|
|
917
|
+
<p class="password-modal-error" id="passwordModalError" style="display: none; color: var(--accent-danger); font-size: 13px; margin-top: 8px;"></p>
|
|
918
|
+
</div>
|
|
919
|
+
<div class="modal-footer">
|
|
920
|
+
<button class="btn" id="passwordModalCancel">Cancel</button>
|
|
921
|
+
<button class="btn btn-primary" id="passwordModalSubmit">
|
|
922
|
+
<i class="fas fa-check"></i> Confirm
|
|
923
|
+
</button>
|
|
924
|
+
</div>
|
|
925
|
+
</div>
|
|
926
|
+
</div>
|
|
927
|
+
|
|
847
928
|
<!-- Mobile Keys Bar -->
|
|
848
929
|
<div class="mobile-keys-bar" id="mobileKeysBar">
|
|
849
930
|
<div class="mobile-keys-row">
|
|
@@ -1027,5 +1108,12 @@
|
|
|
1027
1108
|
|
|
1028
1109
|
<script src="/socket.io/socket.io.js"></script>
|
|
1029
1110
|
<script src="/js/app.js"></script>
|
|
1111
|
+
<script>
|
|
1112
|
+
if ('serviceWorker' in navigator) {
|
|
1113
|
+
window.addEventListener('load', () => {
|
|
1114
|
+
navigator.serviceWorker.register('/sw.js').catch(() => {});
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
</script>
|
|
1030
1118
|
</body>
|
|
1031
1119
|
</html>
|
package/src/webapp/js/app.js
CHANGED
|
@@ -3,11 +3,13 @@ class SSHIFTClient {
|
|
|
3
3
|
constructor() {
|
|
4
4
|
console.log('[SSHIFT] Initializing client...');
|
|
5
5
|
try {
|
|
6
|
+
const authToken = localStorage.getItem('sshift_auth_token');
|
|
6
7
|
this.socket = io({
|
|
7
8
|
transports: ['websocket', 'polling'],
|
|
8
9
|
reconnection: true,
|
|
9
10
|
reconnectionAttempts: 5,
|
|
10
|
-
reconnectionDelay: 1000
|
|
11
|
+
reconnectionDelay: 1000,
|
|
12
|
+
auth: authToken ? { token: authToken } : {}
|
|
11
13
|
});
|
|
12
14
|
console.log('[SSHIFT] Socket created');
|
|
13
15
|
} catch (e) {
|
|
@@ -48,6 +50,24 @@ class SSHIFTClient {
|
|
|
48
50
|
this.altPressed = false; // Track Alt key state
|
|
49
51
|
this.currentKeyboardHeight = 0; // Track actual keyboard height for positioning
|
|
50
52
|
|
|
53
|
+
// Password protection state
|
|
54
|
+
this.passwordEnabled = false;
|
|
55
|
+
this.authToken = localStorage.getItem('sshift_auth_token') || null;
|
|
56
|
+
|
|
57
|
+
this._origFetch = window.fetch.bind(window);
|
|
58
|
+
window.fetch = (url, options = {}) => {
|
|
59
|
+
if (typeof url === 'string' && url.startsWith('/api/') && this.authToken) {
|
|
60
|
+
if (!options.headers) options.headers = {};
|
|
61
|
+
if (!(options.headers instanceof Headers)) {
|
|
62
|
+
options.headers = { ...options.headers };
|
|
63
|
+
}
|
|
64
|
+
if (typeof options.headers === 'object' && !options.headers['Authorization']) {
|
|
65
|
+
options.headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return this._origFetch(url, options);
|
|
69
|
+
};
|
|
70
|
+
|
|
51
71
|
// Terminal font size (for pinch-to-zoom on mobile)
|
|
52
72
|
this.terminalFontSize = 14; // Default font size
|
|
53
73
|
this.minFontSize = 8; // Minimum font size
|
|
@@ -99,6 +119,7 @@ class SSHIFTClient {
|
|
|
99
119
|
this.sshKeepaliveCountMax = config.sshKeepaliveCountMax || 1000;
|
|
100
120
|
// Load mobile keys bar setting
|
|
101
121
|
this.mobileKeysBarEnabled = config.mobileKeysBarEnabled !== undefined ? config.mobileKeysBarEnabled : true;
|
|
122
|
+
this.passwordEnabled = config.passwordEnabled || false;
|
|
102
123
|
console.log('[SSHIFT] Loaded from server - Sticky:', this.sticky ? 'enabled' : 'disabled',
|
|
103
124
|
'Take Control Default:', this.takeControlDefault ? 'enabled' : 'disabled',
|
|
104
125
|
'Keepalive Interval:', this.sshKeepaliveInterval,
|
|
@@ -114,6 +135,241 @@ class SSHIFTClient {
|
|
|
114
135
|
}
|
|
115
136
|
}
|
|
116
137
|
|
|
138
|
+
async checkAuthStatus() {
|
|
139
|
+
const lockScreen = document.getElementById('lockScreen');
|
|
140
|
+
const lockScreenForm = document.getElementById('lockScreenForm');
|
|
141
|
+
const lockScreenSubtitle = document.getElementById('lockScreenSubtitle');
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
const response = await this._origFetch('/api/auth/status');
|
|
145
|
+
const data = await response.json();
|
|
146
|
+
this.passwordEnabled = data.passwordEnabled;
|
|
147
|
+
|
|
148
|
+
if (!this.passwordEnabled) {
|
|
149
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const storedToken = localStorage.getItem('sshift_auth_token');
|
|
154
|
+
if (storedToken) {
|
|
155
|
+
try {
|
|
156
|
+
const verifyResp = await this._origFetch('/api/config', {
|
|
157
|
+
headers: { 'Authorization': `Bearer ${storedToken}` }
|
|
158
|
+
});
|
|
159
|
+
if (verifyResp.ok) {
|
|
160
|
+
this.authToken = storedToken;
|
|
161
|
+
this.updateSocketAuth();
|
|
162
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {}
|
|
166
|
+
localStorage.removeItem('sshift_auth_token');
|
|
167
|
+
this.authToken = null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
await this.showLockScreen();
|
|
171
|
+
} catch (err) {
|
|
172
|
+
console.error('[SSHIFT] Failed to check auth status:', err);
|
|
173
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
showLockScreen() {
|
|
178
|
+
return new Promise((resolve) => {
|
|
179
|
+
const lockScreen = document.getElementById('lockScreen');
|
|
180
|
+
const lockScreenForm = document.getElementById('lockScreenForm');
|
|
181
|
+
const lockScreenPassword = document.getElementById('lockScreenPassword');
|
|
182
|
+
const lockScreenError = document.getElementById('lockScreenError');
|
|
183
|
+
const lockScreenSubtitle = document.getElementById('lockScreenSubtitle');
|
|
184
|
+
const lockScreenIcon = lockScreen ? lockScreen.querySelector('.lock-screen-icon i') : null;
|
|
185
|
+
|
|
186
|
+
if (lockScreen) lockScreen.style.display = 'flex';
|
|
187
|
+
if (lockScreenIcon) lockScreenIcon.className = 'fas fa-lock';
|
|
188
|
+
if (lockScreenSubtitle) lockScreenSubtitle.textContent = 'Password Required';
|
|
189
|
+
if (lockScreenForm) lockScreenForm.style.display = 'flex';
|
|
190
|
+
if (lockScreenError) lockScreenError.style.display = 'none';
|
|
191
|
+
if (lockScreenPassword) {
|
|
192
|
+
lockScreenPassword.value = '';
|
|
193
|
+
lockScreenPassword.focus();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const submitHandler = async (e) => {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
const password = lockScreenPassword.value;
|
|
199
|
+
if (!password) return;
|
|
200
|
+
|
|
201
|
+
lockScreenError.style.display = 'none';
|
|
202
|
+
try {
|
|
203
|
+
const resp = await this._origFetch('/api/auth/login', {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
headers: { 'Content-Type': 'application/json' },
|
|
206
|
+
body: JSON.stringify({ password })
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (resp.ok) {
|
|
210
|
+
const data = await resp.json();
|
|
211
|
+
this.authToken = data.token;
|
|
212
|
+
localStorage.setItem('sshift_auth_token', data.token);
|
|
213
|
+
this.updateSocketAuth();
|
|
214
|
+
lockScreen.style.display = 'none';
|
|
215
|
+
this.passwordEnabled = true;
|
|
216
|
+
lockScreenForm.removeEventListener('submit', submitHandler);
|
|
217
|
+
resolve();
|
|
218
|
+
} else {
|
|
219
|
+
const data = await resp.json();
|
|
220
|
+
lockScreenError.textContent = data.error || 'Invalid password';
|
|
221
|
+
lockScreenError.style.display = 'block';
|
|
222
|
+
lockScreenPassword.value = '';
|
|
223
|
+
lockScreenPassword.focus();
|
|
224
|
+
}
|
|
225
|
+
} catch (err) {
|
|
226
|
+
lockScreenError.textContent = 'Connection error';
|
|
227
|
+
lockScreenError.style.display = 'block';
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
lockScreenForm.addEventListener('submit', submitHandler);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
updateSocketAuth() {
|
|
236
|
+
if (this.socket && this.authToken) {
|
|
237
|
+
this.socket.auth = { token: this.authToken };
|
|
238
|
+
this.socket.disconnect().connect();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async togglePasswordProtection() {
|
|
243
|
+
if (this.passwordEnabled) {
|
|
244
|
+
this._showPasswordModal({
|
|
245
|
+
title: 'Disable Password Protection',
|
|
246
|
+
label: 'Enter current password',
|
|
247
|
+
confirmText: 'Disable',
|
|
248
|
+
requireConfirm: false
|
|
249
|
+
}, async (password) => {
|
|
250
|
+
try {
|
|
251
|
+
const resp = await fetch('/api/auth/remove-password', {
|
|
252
|
+
method: 'POST',
|
|
253
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': this.authToken ? `Bearer ${this.authToken}` : '' },
|
|
254
|
+
body: JSON.stringify({ currentPassword: password })
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
if (resp.ok) {
|
|
258
|
+
localStorage.removeItem('sshift_auth_token');
|
|
259
|
+
location.reload();
|
|
260
|
+
} else {
|
|
261
|
+
const data = await resp.json();
|
|
262
|
+
this.showToast(data.error || 'Failed to disable password', 'error');
|
|
263
|
+
}
|
|
264
|
+
} catch (err) {
|
|
265
|
+
this.showToast('Failed to disable password', 'error');
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
this._showPasswordModal({
|
|
270
|
+
title: 'Enable Password Protection',
|
|
271
|
+
label: 'Set a password',
|
|
272
|
+
confirmText: 'Enable',
|
|
273
|
+
requireConfirm: true
|
|
274
|
+
}, async (password) => {
|
|
275
|
+
try {
|
|
276
|
+
const resp = await fetch('/api/auth/set-password', {
|
|
277
|
+
method: 'POST',
|
|
278
|
+
headers: { 'Content-Type': 'application/json' },
|
|
279
|
+
body: JSON.stringify({ newPassword: password })
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
if (resp.ok) {
|
|
283
|
+
location.reload();
|
|
284
|
+
} else {
|
|
285
|
+
const data = await resp.json();
|
|
286
|
+
this.showToast(data.error || 'Failed to enable password', 'error');
|
|
287
|
+
}
|
|
288
|
+
} catch (err) {
|
|
289
|
+
this.showToast('Failed to enable password', 'error');
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
_showPasswordModal(options, onSubmit) {
|
|
296
|
+
const modal = document.getElementById('passwordModal');
|
|
297
|
+
const title = document.getElementById('passwordModalTitle');
|
|
298
|
+
const label = document.getElementById('passwordModalLabel');
|
|
299
|
+
const input = document.getElementById('passwordModalInput');
|
|
300
|
+
const confirmInput = document.getElementById('passwordModalConfirmInput');
|
|
301
|
+
const confirmGroup = document.getElementById('confirmPasswordGroup');
|
|
302
|
+
const errorEl = document.getElementById('passwordModalError');
|
|
303
|
+
const submitBtn = document.getElementById('passwordModalSubmit');
|
|
304
|
+
const cancelBtn = document.getElementById('passwordModalCancel');
|
|
305
|
+
const closeBtn = document.getElementById('closePasswordModal');
|
|
306
|
+
|
|
307
|
+
title.innerHTML = `<i class="fas fa-lock"></i> ${options.title}`;
|
|
308
|
+
label.textContent = options.label;
|
|
309
|
+
submitBtn.innerHTML = `<i class="fas fa-check"></i> ${options.confirmText}`;
|
|
310
|
+
input.value = '';
|
|
311
|
+
confirmInput.value = '';
|
|
312
|
+
errorEl.style.display = 'none';
|
|
313
|
+
|
|
314
|
+
if (options.requireConfirm) {
|
|
315
|
+
confirmGroup.style.display = 'block';
|
|
316
|
+
} else {
|
|
317
|
+
confirmGroup.style.display = 'none';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const cleanup = () => {
|
|
321
|
+
this.closeModal('passwordModal');
|
|
322
|
+
submitBtn.removeEventListener('click', handleSubmit);
|
|
323
|
+
cancelBtn.removeEventListener('click', handleCancel);
|
|
324
|
+
closeBtn.removeEventListener('click', handleCancel);
|
|
325
|
+
modal.removeEventListener('click', handleBackdrop);
|
|
326
|
+
input.removeEventListener('keydown', handleKeydown);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const handleSubmit = async () => {
|
|
330
|
+
const password = input.value;
|
|
331
|
+
if (!password) {
|
|
332
|
+
errorEl.textContent = 'Password cannot be empty';
|
|
333
|
+
errorEl.style.display = 'block';
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (options.requireConfirm && password !== confirmInput.value) {
|
|
337
|
+
errorEl.textContent = 'Passwords do not match';
|
|
338
|
+
errorEl.style.display = 'block';
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
cleanup();
|
|
342
|
+
await onSubmit(password);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const handleCancel = () => cleanup();
|
|
346
|
+
const handleBackdrop = (e) => { if (e.target === modal) cleanup(); };
|
|
347
|
+
const handleKeydown = (e) => { if (e.key === 'Enter') handleSubmit(); };
|
|
348
|
+
|
|
349
|
+
submitBtn.addEventListener('click', handleSubmit);
|
|
350
|
+
cancelBtn.addEventListener('click', handleCancel);
|
|
351
|
+
closeBtn.addEventListener('click', handleCancel);
|
|
352
|
+
modal.addEventListener('click', handleBackdrop);
|
|
353
|
+
input.addEventListener('keydown', handleKeydown);
|
|
354
|
+
|
|
355
|
+
this.openModal('passwordModal');
|
|
356
|
+
setTimeout(() => input.focus(), 100);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
updatePasswordToggleUI() {
|
|
360
|
+
const btn = document.getElementById('togglePasswordBtn');
|
|
361
|
+
const label = document.getElementById('togglePasswordLabel');
|
|
362
|
+
if (btn && label) {
|
|
363
|
+
if (this.passwordEnabled) {
|
|
364
|
+
btn.querySelector('i').className = 'fas fa-lock';
|
|
365
|
+
label.textContent = 'Disable Password';
|
|
366
|
+
} else {
|
|
367
|
+
btn.querySelector('i').className = 'fas fa-lock-open';
|
|
368
|
+
label.textContent = 'Enable Password';
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
117
373
|
// Update sticky checkbox to reflect loaded value
|
|
118
374
|
updateStickyCheckbox() {
|
|
119
375
|
const stickyToggle = document.getElementById('stickyToggle');
|
|
@@ -1913,6 +2169,8 @@ class SSHIFTClient {
|
|
|
1913
2169
|
async init() {
|
|
1914
2170
|
console.log('[SSHIFT] Setting up listeners...');
|
|
1915
2171
|
|
|
2172
|
+
await this.checkAuthStatus();
|
|
2173
|
+
|
|
1916
2174
|
// Fix mobile viewport height issues
|
|
1917
2175
|
this.fixMobileViewport();
|
|
1918
2176
|
|
|
@@ -2837,7 +3095,13 @@ class SSHIFTClient {
|
|
|
2837
3095
|
|
|
2838
3096
|
this.socket.on('connect_error', (error) => {
|
|
2839
3097
|
console.error('[SSHIFT] Connection error:', error);
|
|
2840
|
-
|
|
3098
|
+
if (error.message === 'Authentication required') {
|
|
3099
|
+
this.authToken = null;
|
|
3100
|
+
localStorage.removeItem('sshift_auth_token');
|
|
3101
|
+
this.showLockScreen();
|
|
3102
|
+
} else {
|
|
3103
|
+
this.showToast('Connection error: ' + error.message, 'error');
|
|
3104
|
+
}
|
|
2841
3105
|
});
|
|
2842
3106
|
|
|
2843
3107
|
// Handle receiving open tabs from server (for cross-tab sync)
|
|
@@ -3582,6 +3846,9 @@ class SSHIFTClient {
|
|
|
3582
3846
|
// Initialize settings modal handlers
|
|
3583
3847
|
this.initSettingsModalHandlers();
|
|
3584
3848
|
|
|
3849
|
+
// Initialize password toggle
|
|
3850
|
+
this.initPasswordToggle();
|
|
3851
|
+
|
|
3585
3852
|
// Initialize sessions modal handlers
|
|
3586
3853
|
this.initSessionsModalHandlers();
|
|
3587
3854
|
|
|
@@ -3902,6 +4169,9 @@ class SSHIFTClient {
|
|
|
3902
4169
|
mobileKeysBarToggle.checked = this.mobileKeysBarEnabled;
|
|
3903
4170
|
}
|
|
3904
4171
|
|
|
4172
|
+
// Update password toggle button state
|
|
4173
|
+
this.updatePasswordToggleUI();
|
|
4174
|
+
|
|
3905
4175
|
this.openModal('settingsModal');
|
|
3906
4176
|
}
|
|
3907
4177
|
|
|
@@ -4123,6 +4393,24 @@ class SSHIFTClient {
|
|
|
4123
4393
|
}
|
|
4124
4394
|
}
|
|
4125
4395
|
|
|
4396
|
+
initPasswordToggle() {
|
|
4397
|
+
const toggleBtn = document.getElementById('togglePasswordBtn');
|
|
4398
|
+
if (toggleBtn) {
|
|
4399
|
+
toggleBtn.addEventListener('click', () => {
|
|
4400
|
+
this.togglePasswordProtection();
|
|
4401
|
+
});
|
|
4402
|
+
}
|
|
4403
|
+
const logoutBtn = document.getElementById('logoutBtn');
|
|
4404
|
+
if (logoutBtn) {
|
|
4405
|
+
if (this.passwordEnabled) logoutBtn.style.display = '';
|
|
4406
|
+
logoutBtn.addEventListener('click', () => {
|
|
4407
|
+
localStorage.removeItem('sshift_auth_token');
|
|
4408
|
+
location.reload();
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4411
|
+
this.updatePasswordToggleUI();
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4126
4414
|
initSessionsModalHandlers() {
|
|
4127
4415
|
// Close button
|
|
4128
4416
|
const closeBtn = document.getElementById('closeManageSessionsModal');
|
|
@@ -4562,9 +4850,11 @@ class SSHIFTClient {
|
|
|
4562
4850
|
localStorage.setItem('mobileKeysBarEnabled', JSON.stringify(this.mobileKeysBarEnabled));
|
|
4563
4851
|
|
|
4564
4852
|
// Save to server config
|
|
4853
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
4854
|
+
if (this.authToken) headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
4565
4855
|
fetch('/api/config', {
|
|
4566
4856
|
method: 'POST',
|
|
4567
|
-
headers
|
|
4857
|
+
headers,
|
|
4568
4858
|
body: JSON.stringify({
|
|
4569
4859
|
sticky: this.sticky,
|
|
4570
4860
|
takeControlDefault: this.takeControlDefault,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "SSHIFT - SSH & SFTP Terminal Client",
|
|
3
|
+
"short_name": "SSHIFT",
|
|
4
|
+
"description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
|
|
5
|
+
"start_url": "/",
|
|
6
|
+
"display": "standalone",
|
|
7
|
+
"background_color": "#1a1b26",
|
|
8
|
+
"theme_color": "#1a1b26",
|
|
9
|
+
"orientation": "any",
|
|
10
|
+
"scope": "/",
|
|
11
|
+
"icons": [
|
|
12
|
+
{
|
|
13
|
+
"src": "/icons/icon-72x72.png",
|
|
14
|
+
"sizes": "72x72",
|
|
15
|
+
"type": "image/png"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"src": "/icons/icon-96x96.png",
|
|
19
|
+
"sizes": "96x96",
|
|
20
|
+
"type": "image/png"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"src": "/icons/icon-128x128.png",
|
|
24
|
+
"sizes": "128x128",
|
|
25
|
+
"type": "image/png"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"src": "/icons/icon-144x144.png",
|
|
29
|
+
"sizes": "144x144",
|
|
30
|
+
"type": "image/png"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"src": "/icons/icon-152x152.png",
|
|
34
|
+
"sizes": "152x152",
|
|
35
|
+
"type": "image/png"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"src": "/icons/icon-192x192.png",
|
|
39
|
+
"sizes": "192x192",
|
|
40
|
+
"type": "image/png"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"src": "/icons/icon-384x384.png",
|
|
44
|
+
"sizes": "384x384",
|
|
45
|
+
"type": "image/png"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"src": "/icons/icon-512x512.png",
|
|
49
|
+
"sizes": "512x512",
|
|
50
|
+
"type": "image/png",
|
|
51
|
+
"purpose": "any maskable"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
package/src/webapp/sw.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const CACHE_NAME = 'sshift-v1';
|
|
2
|
+
|
|
3
|
+
const PRECACHE_URLS = [
|
|
4
|
+
'/',
|
|
5
|
+
'/index.html',
|
|
6
|
+
'/css/style.css',
|
|
7
|
+
'/libs/xterm/xterm.css',
|
|
8
|
+
'/libs/font-awesome/css/all.min.css',
|
|
9
|
+
'/libs/lucide/lucide.min.js',
|
|
10
|
+
'/manifest.json'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
self.addEventListener('install', (event) => {
|
|
14
|
+
event.waitUntil(
|
|
15
|
+
caches.open(CACHE_NAME).then((cache) => cache.addAll(PRECACHE_URLS))
|
|
16
|
+
);
|
|
17
|
+
self.skipWaiting();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
self.addEventListener('activate', (event) => {
|
|
21
|
+
event.waitUntil(
|
|
22
|
+
caches.keys().then((cacheNames) =>
|
|
23
|
+
Promise.all(
|
|
24
|
+
cacheNames
|
|
25
|
+
.filter((name) => name !== CACHE_NAME)
|
|
26
|
+
.map((name) => caches.delete(name))
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
self.clients.claim();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
self.addEventListener('fetch', (event) => {
|
|
34
|
+
if (event.request.method !== 'GET') return;
|
|
35
|
+
|
|
36
|
+
const url = new URL(event.request.url);
|
|
37
|
+
|
|
38
|
+
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
39
|
+
if (url.pathname.startsWith('/socket.io/')) return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
event.respondWith(
|
|
43
|
+
caches.match(event.request).then((cached) => {
|
|
44
|
+
const fetched = fetch(event.request).then((response) => {
|
|
45
|
+
if (response && response.status === 200 && response.type === 'basic') {
|
|
46
|
+
const clone = response.clone();
|
|
47
|
+
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
|
48
|
+
}
|
|
49
|
+
return response;
|
|
50
|
+
}).catch(() => cached);
|
|
51
|
+
|
|
52
|
+
return cached || fetched;
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
});
|