@lethevimlet/sshift 1.9.0 → 1.9.2
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/system.js +89 -69
- package/src/webapp/index.html +9 -3
- package/src/webapp/js/app.js +25 -3
package/package.json
CHANGED
|
@@ -3,11 +3,92 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const fs = require('fs');
|
|
6
|
+
const https = require('https');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const { getDataDir, getCertPath, getKeyPath, getConfigPath } = require('../../utils/config');
|
|
8
9
|
|
|
9
10
|
const { SSL_CERT_FILE, SSL_KEY_FILE, SSL_CA_CERT_FILE } = require('../../utils/certs');
|
|
10
11
|
const UPDATE_MARKER_FILE = '.updating';
|
|
12
|
+
const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
13
|
+
|
|
14
|
+
function fetchJson(options, request = https.request) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const req = request(options, (response) => {
|
|
17
|
+
let body = '';
|
|
18
|
+
|
|
19
|
+
response.on('data', (chunk) => {
|
|
20
|
+
body += chunk;
|
|
21
|
+
if (body.length > 1024 * 1024) {
|
|
22
|
+
req.destroy(new Error('Update metadata response is too large'));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
response.on('end', () => {
|
|
26
|
+
if (response.statusCode !== 200) {
|
|
27
|
+
reject(new Error(`${options.hostname} returned ${response.statusCode}`));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
resolve(JSON.parse(body));
|
|
33
|
+
} catch (error) {
|
|
34
|
+
reject(new Error(`Invalid JSON from ${options.hostname}: ${error.message}`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
req.on('error', reject);
|
|
40
|
+
req.setTimeout(10000, () => req.destroy(new Error(`${options.hostname} request timed out`)));
|
|
41
|
+
req.end();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getLatestPublishedVersion(request = https.request) {
|
|
46
|
+
try {
|
|
47
|
+
const npmPackage = await fetchJson({
|
|
48
|
+
hostname: 'registry.npmjs.org',
|
|
49
|
+
path: '/%40lethevimlet%2Fsshift/latest',
|
|
50
|
+
method: 'GET',
|
|
51
|
+
headers: {
|
|
52
|
+
'User-Agent': 'sshift-update-checker',
|
|
53
|
+
'Accept': 'application/json'
|
|
54
|
+
}
|
|
55
|
+
}, request);
|
|
56
|
+
|
|
57
|
+
if (!VERSION_PATTERN.test(npmPackage.version)) {
|
|
58
|
+
throw new Error('npm returned an invalid version');
|
|
59
|
+
}
|
|
60
|
+
return npmPackage.version;
|
|
61
|
+
} catch (npmError) {
|
|
62
|
+
console.warn('[UPDATE] npm version check failed, trying GitHub:', npmError.message);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const githubResponse = await fetchJson({
|
|
66
|
+
hostname: 'api.github.com',
|
|
67
|
+
path: '/repos/lethevimlet/sshift/contents/package.json',
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers: {
|
|
70
|
+
'User-Agent': 'sshift-update-checker',
|
|
71
|
+
'Accept': 'application/vnd.github.v3+json'
|
|
72
|
+
}
|
|
73
|
+
}, request);
|
|
74
|
+
const content = Buffer.from(githubResponse.content, 'base64').toString('utf8');
|
|
75
|
+
const githubVersion = JSON.parse(content).version;
|
|
76
|
+
if (!VERSION_PATTERN.test(githubVersion)) {
|
|
77
|
+
throw new Error('GitHub returned an invalid version');
|
|
78
|
+
}
|
|
79
|
+
return githubVersion;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function compareVersions(v1, v2) {
|
|
83
|
+
const parts1 = v1.split('.').map(Number);
|
|
84
|
+
const parts2 = v2.split('.').map(Number);
|
|
85
|
+
|
|
86
|
+
for (let i = 0; i < 3; i++) {
|
|
87
|
+
if (parts1[i] < parts2[i]) return -1;
|
|
88
|
+
if (parts1[i] > parts2[i]) return 1;
|
|
89
|
+
}
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
11
92
|
|
|
12
93
|
/**
|
|
13
94
|
* Register system endpoints
|
|
@@ -61,78 +142,18 @@ function registerSystemEndpoints(app, io) {
|
|
|
61
142
|
// API: Check for updates
|
|
62
143
|
app.get('/api/check-update', async (req, res) => {
|
|
63
144
|
try {
|
|
64
|
-
const https = require('https');
|
|
65
|
-
|
|
66
145
|
// Get local version
|
|
67
146
|
const packagePath = path.join(__dirname, '../../../../package.json');
|
|
68
147
|
const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
69
148
|
const localVersion = packageData.version;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'User-Agent': 'sshift-update-checker',
|
|
78
|
-
'Accept': 'application/vnd.github.v3+json'
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const githubRequest = https.request(options, (githubResponse) => {
|
|
83
|
-
let data = '';
|
|
84
|
-
|
|
85
|
-
githubResponse.on('data', (chunk) => {
|
|
86
|
-
data += chunk;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
githubResponse.on('end', () => {
|
|
90
|
-
try {
|
|
91
|
-
if (githubResponse.statusCode !== 200) {
|
|
92
|
-
console.error('GitHub API error:', githubResponse.statusCode, data);
|
|
93
|
-
res.status(500).json({ error: 'Failed to check for updates' });
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const response = JSON.parse(data);
|
|
98
|
-
const content = Buffer.from(response.content, 'base64').toString('utf8');
|
|
99
|
-
const remotePackage = JSON.parse(content);
|
|
100
|
-
const remoteVersion = remotePackage.version;
|
|
101
|
-
|
|
102
|
-
// Compare versions
|
|
103
|
-
const compareVersions = (v1, v2) => {
|
|
104
|
-
const parts1 = v1.split('.').map(Number);
|
|
105
|
-
const parts2 = v2.split('.').map(Number);
|
|
106
|
-
|
|
107
|
-
for (let i = 0; i < 3; i++) {
|
|
108
|
-
if (parts1[i] < parts2[i]) return -1;
|
|
109
|
-
if (parts1[i] > parts2[i]) return 1;
|
|
110
|
-
}
|
|
111
|
-
return 0;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const comparison = compareVersions(localVersion, remoteVersion);
|
|
115
|
-
const updateAvailable = comparison < 0;
|
|
116
|
-
|
|
117
|
-
res.json({
|
|
118
|
-
localVersion,
|
|
119
|
-
remoteVersion,
|
|
120
|
-
updateAvailable,
|
|
121
|
-
checkedAt: new Date().toISOString()
|
|
122
|
-
});
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.error('Error parsing GitHub response:', err);
|
|
125
|
-
res.status(500).json({ error: 'Failed to parse update information' });
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
githubRequest.on('error', (err) => {
|
|
131
|
-
console.error('Error checking for updates:', err);
|
|
132
|
-
res.status(500).json({ error: 'Failed to check for updates' });
|
|
149
|
+
const remoteVersion = await getLatestPublishedVersion();
|
|
150
|
+
|
|
151
|
+
res.json({
|
|
152
|
+
localVersion,
|
|
153
|
+
remoteVersion,
|
|
154
|
+
updateAvailable: compareVersions(localVersion, remoteVersion) < 0,
|
|
155
|
+
checkedAt: new Date().toISOString()
|
|
133
156
|
});
|
|
134
|
-
|
|
135
|
-
githubRequest.end();
|
|
136
157
|
} catch (err) {
|
|
137
158
|
console.error('Error in check-update:', err);
|
|
138
159
|
res.status(500).json({ error: 'Failed to check for updates' });
|
|
@@ -258,7 +279,6 @@ function registerSystemEndpoints(app, io) {
|
|
|
258
279
|
let targetVersion = 'latest';
|
|
259
280
|
const currentPkg = require('../../../../package.json');
|
|
260
281
|
try {
|
|
261
|
-
const https = require('https');
|
|
262
282
|
const githubVersion = await new Promise((resolve, reject) => {
|
|
263
283
|
const opts = {
|
|
264
284
|
hostname: 'api.github.com',
|
|
@@ -691,4 +711,4 @@ fi
|
|
|
691
711
|
});
|
|
692
712
|
}
|
|
693
713
|
|
|
694
|
-
module.exports = { registerSystemEndpoints };
|
|
714
|
+
module.exports = { compareVersions, getLatestPublishedVersion, registerSystemEndpoints };
|
package/src/webapp/index.html
CHANGED
|
@@ -1315,9 +1315,15 @@
|
|
|
1315
1315
|
<div id="customCertWarning" class="sw-custom-cert-warning" style="display: none; margin-top: 8px;">
|
|
1316
1316
|
<i class="fas fa-exclamation-circle"></i> A custom certificate is configured. Download the certificate from your administrator.
|
|
1317
1317
|
</div>
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1318
|
+
<button class="btn btn-secondary" id="downloadCertBtn" style="margin-top: 8px;">
|
|
1319
|
+
<i class="fas fa-download"></i> Download CA Certificate
|
|
1320
|
+
</button>
|
|
1321
|
+
<a class="btn btn-secondary" id="acceptCertBtn" href="/api/version" target="_blank" rel="noopener noreferrer" style="margin-top: 8px;">
|
|
1322
|
+
<i class="fas fa-external-link-alt"></i> Re-accept Certificate
|
|
1323
|
+
</a>
|
|
1324
|
+
<div class="setting-description" style="margin-top: 8px;">
|
|
1325
|
+
If the app loaded but API requests fail, open this link, choose <strong>Advanced → Proceed</strong>, then return and reload SSHIFT. This exception is temporary; installing the CA is optional but permanent.
|
|
1326
|
+
</div>
|
|
1321
1327
|
</div>
|
|
1322
1328
|
</div>
|
|
1323
1329
|
</div>
|
package/src/webapp/js/app.js
CHANGED
|
@@ -81,6 +81,7 @@ class SSHIFTClient {
|
|
|
81
81
|
this.passwordEnabled = false;
|
|
82
82
|
this.bookmarkEncryptionEnabled = false;
|
|
83
83
|
this.authToken = localStorage.getItem('sshift_auth_token') || null;
|
|
84
|
+
this._certificateAcceptanceRequired = false;
|
|
84
85
|
|
|
85
86
|
this._origFetch = window.fetch.bind(window);
|
|
86
87
|
window.fetch = (url, options = {}) => {
|
|
@@ -7061,7 +7062,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7061
7062
|
const swStatusContainer = document.getElementById('swStatusContainer');
|
|
7062
7063
|
|
|
7063
7064
|
let swStatus = window._swStatus;
|
|
7064
|
-
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
|
|
7065
|
+
if (!this._certificateAcceptanceRequired && navigator.serviceWorker && navigator.serviceWorker.controller) {
|
|
7065
7066
|
swStatus = 'active';
|
|
7066
7067
|
window._swStatus = 'active';
|
|
7067
7068
|
}
|
|
@@ -7090,7 +7091,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7090
7091
|
'<li><i class="fas fa-times"></i> Installable as app (PWA)</li>' +
|
|
7091
7092
|
'<li><i class="fas fa-times"></i> Clipboard API access</li>' +
|
|
7092
7093
|
'</ul>' +
|
|
7093
|
-
'<p class="sw-hint">
|
|
7094
|
+
'<p class="sw-hint">Re-accept the certificate to continue without installing it, or trust the local CA to enable all features.</p>';
|
|
7094
7095
|
} else if (swStatus === 'redundant') {
|
|
7095
7096
|
swStatusContainer.classList.add('sw-status-failed');
|
|
7096
7097
|
swStatusIcon.innerHTML = '<i class="fas fa-exclamation-triangle"></i>';
|
|
@@ -7126,6 +7127,22 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7126
7127
|
this.openModal('securityInfoModal');
|
|
7127
7128
|
}
|
|
7128
7129
|
|
|
7130
|
+
handleApiFetchError(err) {
|
|
7131
|
+
const swError = String(window._swError || '').toLowerCase();
|
|
7132
|
+
const certificateFailure = window.location.protocol === 'https:' &&
|
|
7133
|
+
err instanceof TypeError &&
|
|
7134
|
+
window._swStatus === 'failed' &&
|
|
7135
|
+
(swError.includes('ssl') || swError.includes('certificate'));
|
|
7136
|
+
|
|
7137
|
+
if (!certificateFailure) return false;
|
|
7138
|
+
|
|
7139
|
+
this._certificateAcceptanceRequired = true;
|
|
7140
|
+
window._swError = 'The browser no longer accepts this HTTPS certificate. Re-accept it to continue, or install the local CA for permanent trust.';
|
|
7141
|
+
this.showToast('HTTPS certificate approval required', 'error');
|
|
7142
|
+
this.openSecurityInfoDialog();
|
|
7143
|
+
return true;
|
|
7144
|
+
}
|
|
7145
|
+
|
|
7129
7146
|
// Debug Info Dialog
|
|
7130
7147
|
initDebugInfoDialog() {
|
|
7131
7148
|
const showBtn = document.getElementById('showDebugInfoBtn');
|
|
@@ -13131,7 +13148,9 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13131
13148
|
throw new Error('Failed to save bookmark');
|
|
13132
13149
|
}
|
|
13133
13150
|
} catch (err) {
|
|
13134
|
-
this.
|
|
13151
|
+
if (!this.handleApiFetchError(err)) {
|
|
13152
|
+
this.showToast(err.message, 'error');
|
|
13153
|
+
}
|
|
13135
13154
|
}
|
|
13136
13155
|
}
|
|
13137
13156
|
|
|
@@ -13914,6 +13933,9 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13914
13933
|
this.showToast('You are running the latest version', 'success');
|
|
13915
13934
|
}
|
|
13916
13935
|
}
|
|
13936
|
+
} else {
|
|
13937
|
+
const error = await response.json().catch(() => ({}));
|
|
13938
|
+
throw new Error(error.error || `Update check failed with status ${response.status}`);
|
|
13917
13939
|
}
|
|
13918
13940
|
} catch (error) {
|
|
13919
13941
|
console.error('Failed to check for updates:', error);
|