secubox-openwrt/package/secubox/luci-app-secubox-p2p/htdocs/luci-static/resources/view/secubox-p2p/peers.js
CyberMind-FR 2b913d5005 feat(p2p): Add SecuBox P2P Hub packages and Services Registry
- Add secubox-p2p backend package:
  - UCI configuration for P2P settings, DNS federation, WireGuard mesh, HAProxy
  - RPCD handler for peer management, service discovery, mesh configuration
  - Init script and main P2P manager daemon

- Add luci-app-secubox-p2p frontend package:
  - Main hub view with master control, network matrix visualization
  - Peers management with discovery and manual add
  - Services view showing local and shared services
  - Mesh network configuration (DNS, WireGuard, HAProxy)
  - Settings for P2P and registry configuration

- Add Services Registry view to luci-app-secubox
- Add listProfiles/applyProfile to secubox-admin API
- Fix P2P ACL permissions
- Remove old hub.js from luci-app-secubox (moved to dedicated package)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 19:46:28 +01:00

93 lines
2.8 KiB
JavaScript

'use strict';
'require view';
'require ui';
'require secubox-p2p/api as P2PAPI';
return view.extend({
peers: [],
load: function() {
var self = this;
return P2PAPI.getPeers().then(function(result) {
self.peers = result.peers || [];
return {};
}).catch(function() { return {}; });
},
render: function() {
var self = this;
return E('div', { 'class': 'cbi-map' }, [
E('h2', {}, 'P2P Peers'),
E('div', { 'class': 'cbi-section' }, [
E('div', { 'style': 'margin-bottom: 1em;' }, [
E('button', { 'class': 'cbi-button cbi-button-action', 'click': function() { self.discoverPeers(); } }, 'Discover Peers'),
E('button', { 'class': 'cbi-button', 'style': 'margin-left: 0.5em;', 'click': function() { self.addPeerManually(); } }, 'Add Peer')
]),
E('table', { 'class': 'table' }, [
E('tr', { 'class': 'tr table-titles' }, [
E('th', { 'class': 'th' }, 'Name'),
E('th', { 'class': 'th' }, 'Address'),
E('th', { 'class': 'th' }, 'Status'),
E('th', { 'class': 'th' }, 'Actions')
])
].concat(this.peers.map(function(peer) {
return E('tr', { 'class': 'tr' }, [
E('td', { 'class': 'td' }, peer.name || peer.id),
E('td', { 'class': 'td' }, peer.address || 'Unknown'),
E('td', { 'class': 'td' }, E('span', { 'style': 'color: ' + (peer.status === 'online' ? 'green' : 'red') }, peer.status || 'unknown')),
E('td', { 'class': 'td' }, [
E('button', { 'class': 'cbi-button cbi-button-remove', 'click': function() { self.removePeer(peer.id); } }, 'Remove')
])
]);
})))
])
]);
},
discoverPeers: function() {
var self = this;
ui.addNotification(null, E('p', 'Discovering peers...'), 'info');
P2PAPI.discover(5).then(function() {
window.location.reload();
});
},
addPeerManually: function() {
var self = this;
ui.showModal('Add Peer', [
E('div', {}, [
E('label', {}, 'Address: '),
E('input', { 'type': 'text', 'id': 'new-peer-addr', 'class': 'cbi-input-text' }),
E('br', {}), E('br', {}),
E('label', {}, 'Name: '),
E('input', { 'type': 'text', 'id': 'new-peer-name', 'class': 'cbi-input-text' })
]),
E('div', { 'class': 'right', 'style': 'margin-top: 1em;' }, [
E('button', { 'class': 'cbi-button', 'click': ui.hideModal }, 'Cancel'),
E('button', { 'class': 'cbi-button cbi-button-positive', 'click': function() {
var addr = document.getElementById('new-peer-addr').value;
var name = document.getElementById('new-peer-name').value;
if (addr) {
P2PAPI.addPeer(addr, name).then(function() {
ui.hideModal();
window.location.reload();
});
}
} }, 'Add')
])
]);
},
removePeer: function(peerId) {
if (confirm('Remove this peer?')) {
P2PAPI.removePeer(peerId).then(function() {
window.location.reload();
});
}
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});