Skip to content

Commit b8e8c1a

Browse files
committed
Fix spliceFileLines trailing newline, guard memory div-by-zero, WG allowed_ips as UCI list
1 parent 03721a5 commit b8e8c1a

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

moci/js/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ export class OpenWrtCore {
718718
if (lines.length && lines[lines.length - 1] === '') lines.pop();
719719
lines.push(newLine);
720720
}
721-
return lines.join('\n') + (raw.endsWith('\n') ? '' : '\n');
721+
const result = lines.join('\n');
722+
return result.endsWith('\n') ? result : result + '\n';
722723
}
723724

724725
resetModal(modalId) {

moci/js/modules/dashboard.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ export default class DashboardModule {
3232
if (hostnameEl) hostnameEl.textContent = boardInfo.hostname || 'OpenWrt';
3333
if (uptimeEl) uptimeEl.textContent = this.core.formatUptime(systemInfo.uptime);
3434

35-
const memPercent = (
36-
((systemInfo.memory.total - systemInfo.memory.free) / systemInfo.memory.total) *
37-
100
38-
).toFixed(0);
35+
const memTotal = systemInfo.memory.total || 1;
36+
const memPercent = (((memTotal - systemInfo.memory.free) / memTotal) * 100).toFixed(0);
3937
if (memoryEl) memoryEl.textContent = this.core.formatMemory(systemInfo.memory);
4038
if (memoryBarEl) memoryBarEl.style.width = memPercent + '%';
4139
}

moci/js/modules/network.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,11 @@ export default class NetworkModule {
878878

879879
saveWgPeer() {
880880
const ifaceName = document.getElementById('wg-interface').value || 'wg0';
881+
const allowedIpsRaw = document.getElementById('edit-wg-peer-allowed-ips')?.value || '';
882+
const allowed_ips = allowedIpsRaw
883+
.split(/[,\s]+/)
884+
.map(s => s.trim())
885+
.filter(Boolean);
881886
this.core.uciSave({
882887
config: 'network',
883888
uciType: `wireguard_${ifaceName}`,
@@ -886,10 +891,10 @@ export default class NetworkModule {
886891
fieldMap: {
887892
'edit-wg-peer-name': 'description',
888893
'edit-wg-peer-public-key': 'public_key',
889-
'edit-wg-peer-allowed-ips': 'allowed_ips',
890894
'edit-wg-peer-keepalive': 'persistent_keepalive',
891895
'edit-wg-peer-preshared-key': 'preshared_key'
892896
},
897+
defaults: { allowed_ips },
893898
reloadFn: () => this.loadVPN(),
894899
successMsg: 'WireGuard peer saved'
895900
});

0 commit comments

Comments
 (0)