@danieltmn/openbridge 0.5.2 → 0.6.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/CHANGELOG.md +15 -0
- package/README.md +18 -0
- package/package.json +1 -1
- package/src/cli.js +97 -0
- package/src/web/assets/app.js +87 -0
- package/src/web/templates/chat.html +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@ Todos los cambios relevantes de OpenBridge. Formato basado en
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/es-ES/1.1.0/) y
|
|
5
5
|
[Versionado Semantico](https://semver.org/lang/es/).
|
|
6
6
|
|
|
7
|
+
## [0.6.0] - 2026-09-14
|
|
8
|
+
|
|
9
|
+
### Agregado
|
|
10
|
+
|
|
11
|
+
- **Hub PHP** para correr la app en un hosting (cPanel) con URL fija, sin tunel
|
|
12
|
+
(`php/app` + `scripts/build-php-hub.mjs`; comparte el frontend con el hub Node).
|
|
13
|
+
Auth multiusuario con scrypt compatible con Node (usa `sodium`; si falta, scrypt
|
|
14
|
+
puro en PHP), roles, cookie de sesion firmada, rate limit y CSP.
|
|
15
|
+
- **Emparejamiento por codigo** (`openbridge pair <url>`): la PC muestra un codigo,
|
|
16
|
+
el usuario lo ingresa en la web (Dispositivos) y la PC recibe su **token propio**
|
|
17
|
+
y revocable. Cada usuario ve solo sus PCs; el admin, todas.
|
|
18
|
+
- Comando `openbridge pair` y vista **Dispositivos** en la web (solo en el hub PHP,
|
|
19
|
+
gateada por `features.pairing`).
|
|
20
|
+
- `docs/DEPLOY-PHP.md`: guia de despliegue del hub PHP.
|
|
21
|
+
|
|
7
22
|
## [0.5.2] - 2026-09-14
|
|
8
23
|
|
|
9
24
|
### Corregido
|
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ iniciar sesión** una vez; los chats, carpetas, túnel y push se conservan.
|
|
|
91
91
|
| `openbridge logs` | Logs (`--follow`, `--server`, `--bridge`) |
|
|
92
92
|
| `openbridge bridge` | Corre **solo** el puente (`--api --token --id --name`) |
|
|
93
93
|
| `openbridge join` | Vincula esta PC como puente de un hub (`<url> --token --id --name`) |
|
|
94
|
+
| `openbridge pair` | Empareja esta PC con un **hub PHP** por código (`<url> [--id --name]`) |
|
|
94
95
|
| `openbridge import` | Trae `data/` de OpenConex (`<data-dir> [--force]`) |
|
|
95
96
|
| `openbridge reset` | Borra chats/datos (`--session <id>`, `--yes`) |
|
|
96
97
|
| `openbridge autostart` | Arranque automático (`install`/`remove`) |
|
|
@@ -144,6 +145,23 @@ Ejemplo concreto:
|
|
|
144
145
|
El puente remoto solo necesita salida a internet hacia el hub; no abre puertos ni
|
|
145
146
|
túnel propio. Para que arranque solo en cada PC: `openbridge autostart install`.
|
|
146
147
|
|
|
148
|
+
## Hub en hosting PHP (URL fija, sin túnel)
|
|
149
|
+
|
|
150
|
+
Además del hub Node, OpenBridge puede correr su hub en un **hosting PHP** (cPanel),
|
|
151
|
+
igual que OpenConex, y dejar que cada PC corra solo el puente:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
[Celular] --HTTPS--> openbridge.tamnora.com (hub PHP) --> [PC] openbridge pair
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- Web siempre arriba, **URL fija** y PWA/Web Push estables; sin túneles ni puertos.
|
|
158
|
+
- Cada PC se vincula con un **código**: en la PC `openbridge pair <url>` muestra un
|
|
159
|
+
código y en la web lo ingresás en **Dispositivos -> Agregar PC**. Cada PC queda
|
|
160
|
+
con su **token propio** (revocable); cada usuario ve solo sus PCs (el admin, todas).
|
|
161
|
+
- El frontend es el mismo del hub Node (se copia, no se duplica).
|
|
162
|
+
|
|
163
|
+
Guía completa (requisitos, build, subida y emparejamiento): [`docs/DEPLOY-PHP.md`](docs/DEPLOY-PHP.md).
|
|
164
|
+
|
|
147
165
|
## Túnel y URL estable
|
|
148
166
|
|
|
149
167
|
Proveedores (`--tunnel` o `openbridge tunnel <prov>`): `tunnelmole` (gratis, sin
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -750,6 +750,101 @@ async function cmdJoin(argv) {
|
|
|
750
750
|
return cmdBridge([]);
|
|
751
751
|
}
|
|
752
752
|
|
|
753
|
+
// ---------------------------------------------------------------------------
|
|
754
|
+
// pair: empareja esta PC con un hub PHP por codigo (device code). La PC pide
|
|
755
|
+
// un codigo, el usuario lo tipea en la web (Dispositivos -> Agregar PC) y la PC
|
|
756
|
+
// recibe su token propio. Necesita un hub PHP (openbridge.tamnora.com).
|
|
757
|
+
// ---------------------------------------------------------------------------
|
|
758
|
+
async function pairApi(apiUrl, action, body) {
|
|
759
|
+
const res = await fetch(apiUrl + '?action=' + action, {
|
|
760
|
+
method: 'POST',
|
|
761
|
+
headers: { 'Content-Type': 'application/json' },
|
|
762
|
+
body: JSON.stringify(body || {}),
|
|
763
|
+
});
|
|
764
|
+
let json = null;
|
|
765
|
+
try { json = await res.json(); } catch (e) { json = null; }
|
|
766
|
+
if (!json) throw new Error('respuesta invalida del hub (HTTP ' + res.status + ')');
|
|
767
|
+
return json;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
async function cmdPair(argv) {
|
|
771
|
+
const { flags, _ } = parseArgs(argv);
|
|
772
|
+
const url = String(_[0] || flags.hub || flags.api || '').trim();
|
|
773
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
774
|
+
console.error('Uso: openbridge pair <url-del-hub> [--id <pc>] [--name "<nombre>"] [--no-start]');
|
|
775
|
+
console.error('Ej.: openbridge pair https://openbridge.tamnora.com --name "PC 1"');
|
|
776
|
+
return 1;
|
|
777
|
+
}
|
|
778
|
+
paths.ensureDirs();
|
|
779
|
+
const cfg = config.readBridge();
|
|
780
|
+
const apiUrl = hubApiUrl(url);
|
|
781
|
+
const bridgeId = sanitizeId(flags.id || cfg.bridgeId || os.hostname());
|
|
782
|
+
const bridgeName = (typeof flags.name === 'string' && flags.name.trim())
|
|
783
|
+
? flags.name.trim().slice(0, 40)
|
|
784
|
+
: (cfg.bridgeName || bridgeId);
|
|
785
|
+
|
|
786
|
+
let start;
|
|
787
|
+
try {
|
|
788
|
+
start = await pairApi(apiUrl, 'bridge_pair_start', { bridge_id: bridgeId, bridge_name: bridgeName });
|
|
789
|
+
} catch (e) {
|
|
790
|
+
console.error('No pude iniciar el emparejamiento: ' + e.message);
|
|
791
|
+
return 1;
|
|
792
|
+
}
|
|
793
|
+
if (!start.ok) {
|
|
794
|
+
console.error('El hub rechazo el emparejamiento: ' + (start.error || 'error'));
|
|
795
|
+
return 1;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const verify = start.verify_url || url;
|
|
799
|
+
console.log('Para vincular esta PC a tu cuenta:');
|
|
800
|
+
console.log(' 1. Abri ' + verify + ' y logueate.');
|
|
801
|
+
console.log(' 2. Anda a Dispositivos -> Agregar PC.');
|
|
802
|
+
console.log(' 3. Ingresa el codigo: ' + start.user_code);
|
|
803
|
+
console.log('');
|
|
804
|
+
console.log('Esperando aprobacion (vence en ' + Math.round((parseInt(start.expires_in, 10) || 600) / 60) + ' min)...');
|
|
805
|
+
|
|
806
|
+
const deadline = Date.now() + (parseInt(start.expires_in, 10) || 600) * 1000;
|
|
807
|
+
let token = '';
|
|
808
|
+
let finalId = bridgeId;
|
|
809
|
+
while (Date.now() < deadline) {
|
|
810
|
+
await new Promise((r) => setTimeout(r, 2500));
|
|
811
|
+
let p;
|
|
812
|
+
try {
|
|
813
|
+
p = await pairApi(apiUrl, 'bridge_pair_poll', { device_code: start.device_code });
|
|
814
|
+
} catch (e) {
|
|
815
|
+
process.stdout.write('.');
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
if (p.status === 'approved' && p.bridge_token) {
|
|
819
|
+
token = p.bridge_token;
|
|
820
|
+
finalId = p.bridge_id || bridgeId;
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
if (p.status === 'expired' || p.status === 'unknown') {
|
|
824
|
+
console.error('\nEl codigo vencio. Volve a correr: openbridge pair ' + url);
|
|
825
|
+
return 1;
|
|
826
|
+
}
|
|
827
|
+
process.stdout.write('.');
|
|
828
|
+
}
|
|
829
|
+
if (!token) {
|
|
830
|
+
console.error('\nSe agoto el tiempo. Volve a correr: openbridge pair ' + url);
|
|
831
|
+
return 1;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
cfg.apiUrl = apiUrl;
|
|
835
|
+
cfg.apiToken = token;
|
|
836
|
+
cfg.bridgeId = finalId;
|
|
837
|
+
cfg.bridgeName = bridgeName;
|
|
838
|
+
config.writeBridge(cfg);
|
|
839
|
+
console.log('\nPC emparejada: ' + finalId + ' (' + bridgeName + ')');
|
|
840
|
+
if (flags['no-start']) {
|
|
841
|
+
console.log('Arrancala con: openbridge bridge');
|
|
842
|
+
return 0;
|
|
843
|
+
}
|
|
844
|
+
console.log('Arrancando el puente (Ctrl+C para salir)...');
|
|
845
|
+
return cmdBridge([]);
|
|
846
|
+
}
|
|
847
|
+
|
|
753
848
|
// ---------------------------------------------------------------------------
|
|
754
849
|
// import / reset (datos)
|
|
755
850
|
// ---------------------------------------------------------------------------
|
|
@@ -1109,6 +1204,7 @@ function usage() {
|
|
|
1109
1204
|
console.log(' logs Ultimas lineas de los logs (--follow --server --bridge)');
|
|
1110
1205
|
console.log(' bridge Corre solo el puente (--api --token --id --name)');
|
|
1111
1206
|
console.log(' join Vincula esta PC como puente de un hub (<url> --token --id --name)');
|
|
1207
|
+
console.log(' pair Empareja esta PC con un hub PHP por codigo (<url> [--id --name])');
|
|
1112
1208
|
console.log(' import Trae data/ de OpenConex (<data-dir> [--force])');
|
|
1113
1209
|
console.log(' reset Borra todos los chats/datos (--session <id> --yes)');
|
|
1114
1210
|
console.log(' autostart Instala/quita el arranque automatico (install|remove)');
|
|
@@ -1144,6 +1240,7 @@ async function main(argv) {
|
|
|
1144
1240
|
case 'logs': return cmdLogs(args.slice(1));
|
|
1145
1241
|
case 'bridge': return cmdBridge(args.slice(1));
|
|
1146
1242
|
case 'join': return cmdJoin(args.slice(1));
|
|
1243
|
+
case 'pair': return cmdPair(args.slice(1));
|
|
1147
1244
|
case 'import': return cmdImport(args.slice(1));
|
|
1148
1245
|
case 'reset': return cmdReset(args.slice(1));
|
|
1149
1246
|
case 'autostart': return cmdAutostart(args.slice(1));
|
package/src/web/assets/app.js
CHANGED
|
@@ -67,6 +67,7 @@ var els = {
|
|
|
67
67
|
viewProcs: document.getElementById('viewProcs'),
|
|
68
68
|
viewChanges: document.getElementById('viewChanges'),
|
|
69
69
|
viewMcp: document.getElementById('viewMcp'),
|
|
70
|
+
viewDevices: document.getElementById('viewDevices'),
|
|
70
71
|
themeColor: document.getElementById('themeColor'),
|
|
71
72
|
themeLink: document.getElementById('themeStylesheet'),
|
|
72
73
|
statusbar: document.getElementById('statusbar'),
|
|
@@ -146,6 +147,7 @@ var state = {
|
|
|
146
147
|
catVer: '',
|
|
147
148
|
bridges: [], // resumen de puentes registrados [{id,name,online,busy_session}]
|
|
148
149
|
activeBridge: '', // puente seleccionado en el sidebar (id)
|
|
150
|
+
features: {}, // capacidades del hub (p. ej. {pairing:true} en el hub PHP)
|
|
149
151
|
isSending: false,
|
|
150
152
|
pendingImage: null,
|
|
151
153
|
messages: [],
|
|
@@ -431,6 +433,11 @@ async function refreshBridgeData() {
|
|
|
431
433
|
// Aplica la respuesta de bootstrap (o de un refresh tras cambio de puente).
|
|
432
434
|
function applyBootPayload(data) {
|
|
433
435
|
if (!data || !data.ok) return;
|
|
436
|
+
if (data.features) {
|
|
437
|
+
state.features = data.features;
|
|
438
|
+
var devBtn = document.querySelector('#sidebar .utilities button[data-view="devices"]');
|
|
439
|
+
if (devBtn) devBtn.style.display = state.features.pairing ? '' : 'none';
|
|
440
|
+
}
|
|
434
441
|
var newB = Array.isArray(data.bridges) ? data.bridges : null;
|
|
435
442
|
if (newB && newB.length) {
|
|
436
443
|
// El puente activo guardado puede no existir (o ser el legacy '' tras
|
|
@@ -1011,6 +1018,7 @@ function showView(name) {
|
|
|
1011
1018
|
els.viewProcs.style.display = 'none';
|
|
1012
1019
|
els.viewChanges.style.display = 'none';
|
|
1013
1020
|
els.viewMcp.style.display = 'none';
|
|
1021
|
+
if (els.viewDevices) els.viewDevices.style.display = 'none';
|
|
1014
1022
|
|
|
1015
1023
|
if (name !== 'procs') stopProcView();
|
|
1016
1024
|
|
|
@@ -1089,6 +1097,12 @@ function showView(name) {
|
|
|
1089
1097
|
els.sendForm.style.display = 'none';
|
|
1090
1098
|
els.btnCmds.style.display = 'none';
|
|
1091
1099
|
renderMcpView();
|
|
1100
|
+
} else if (name === 'devices') {
|
|
1101
|
+
els.viewDevices.style.display = '';
|
|
1102
|
+
els.btnBack.style.display = 'none';
|
|
1103
|
+
els.sendForm.style.display = 'none';
|
|
1104
|
+
els.btnCmds.style.display = 'none';
|
|
1105
|
+
renderDevicesView();
|
|
1092
1106
|
}
|
|
1093
1107
|
|
|
1094
1108
|
if (els.fabNew) els.fabNew.classList.toggle('show', name === 'home');
|
|
@@ -3062,6 +3076,79 @@ async function loadMcp() {
|
|
|
3062
3076
|
+ esc(output || 'No hay servidores MCP configurados.') + '</pre>';
|
|
3063
3077
|
}
|
|
3064
3078
|
|
|
3079
|
+
// ---------------------------------------------------------------------------
|
|
3080
|
+
// Vista Dispositivos: PCs emparejadas a la cuenta (solo hub PHP). El usuario
|
|
3081
|
+
// corre `openbridge pair <url>` en su PC, ve un codigo y lo ingresa aca.
|
|
3082
|
+
// ---------------------------------------------------------------------------
|
|
3083
|
+
function renderDevicesView() {
|
|
3084
|
+
els.hTitle.textContent = 'dispositivos';
|
|
3085
|
+
els.hSub.textContent = 'tus PCs emparejadas';
|
|
3086
|
+
loadDevices();
|
|
3087
|
+
}
|
|
3088
|
+
|
|
3089
|
+
async function loadDevices() {
|
|
3090
|
+
if (!els.viewDevices) return;
|
|
3091
|
+
var head = '<div class="view-head"><h2>mis PCs</h2>'
|
|
3092
|
+
+ '<div class="view-sub">emparejadas a tu cuenta</div></div>';
|
|
3093
|
+
var res = await api('api.php?action=bridges');
|
|
3094
|
+
if (!res.ok) {
|
|
3095
|
+
els.viewDevices.innerHTML = head + '<div class="placeholder">' + esc(res.error || 'no se pudo consultar') + '</div>';
|
|
3096
|
+
return;
|
|
3097
|
+
}
|
|
3098
|
+
els.viewDevices.innerHTML = head
|
|
3099
|
+
+ '<div class="dev-add">'
|
|
3100
|
+
+ '<input type="text" id="devCode" placeholder="codigo (ej: ABCD-EFGH)" autocomplete="off" spellcheck="false">'
|
|
3101
|
+
+ '<button type="button" class="linkbtn" id="devAdd">agregar PC</button>'
|
|
3102
|
+
+ '</div>'
|
|
3103
|
+
+ '<div class="view-sub">En tu PC: <code>openbridge pair ' + esc(location.origin) + '</code> y te muestra un codigo. Ingresalo aca.</div>'
|
|
3104
|
+
+ '<div id="devList"></div>';
|
|
3105
|
+
var input = document.getElementById('devCode');
|
|
3106
|
+
var btn = document.getElementById('devAdd');
|
|
3107
|
+
if (btn) btn.addEventListener('click', function () { addDevice(input.value); });
|
|
3108
|
+
if (input) input.addEventListener('keydown', function (e) { if (e.key === 'Enter') addDevice(input.value); });
|
|
3109
|
+
renderDeviceList(res.bridges || []);
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3112
|
+
function renderDeviceList(list) {
|
|
3113
|
+
var box = document.getElementById('devList');
|
|
3114
|
+
if (!box) return;
|
|
3115
|
+
if (!list.length) {
|
|
3116
|
+
box.innerHTML = '<div class="placeholder">Todavia no emparejaste ninguna PC.</div>';
|
|
3117
|
+
return;
|
|
3118
|
+
}
|
|
3119
|
+
var html = '';
|
|
3120
|
+
for (var i = 0; i < list.length; i++) {
|
|
3121
|
+
var b = list[i];
|
|
3122
|
+
html += '<div class="device"><span class="dot"' + (b.online ? '' : ' style="background:var(--muted)"') + '></span>'
|
|
3123
|
+
+ '<b>' + esc(b.name) + '</b><span class="dnote">' + esc(b.id) + '</span>'
|
|
3124
|
+
+ '<button type="button" class="linkbtn" data-revoke="' + esc(b.id) + '">desvincular</button></div>';
|
|
3125
|
+
}
|
|
3126
|
+
box.innerHTML = html;
|
|
3127
|
+
var btns = box.querySelectorAll('[data-revoke]');
|
|
3128
|
+
for (var j = 0; j < btns.length; j++) {
|
|
3129
|
+
btns[j].addEventListener('click', function () { revokeDevice(this.getAttribute('data-revoke')); });
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
async function addDevice(code) {
|
|
3134
|
+
code = (code || '').trim();
|
|
3135
|
+
if (!code) return;
|
|
3136
|
+
var res = await fetch('api.php?action=bridge_pair_approve', apiCsrf('POST', { user_code: code }))
|
|
3137
|
+
.then(function (r) { return r.json(); })
|
|
3138
|
+
.catch(function () { return { ok: false, error: 'network' }; });
|
|
3139
|
+
if (!res.ok) { alert(res.error || 'no se pudo emparejar'); return; }
|
|
3140
|
+
loadDevices();
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
async function revokeDevice(id) {
|
|
3144
|
+
if (!window.confirm('Desvincular la PC "' + id + '"?')) return;
|
|
3145
|
+
var res = await fetch('api.php?action=bridge_revoke', apiCsrf('POST', { id: id }))
|
|
3146
|
+
.then(function (r) { return r.json(); })
|
|
3147
|
+
.catch(function () { return { ok: false, error: 'network' }; });
|
|
3148
|
+
if (!res.ok) { alert(res.error || 'no se pudo desvincular'); return; }
|
|
3149
|
+
loadDevices();
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3065
3152
|
function chgStatusClass(st) {
|
|
3066
3153
|
if (st === '??' || st === 'A') return 'add';
|
|
3067
3154
|
if (st.indexOf('D') >= 0) return 'del';
|
|
@@ -378,6 +378,14 @@
|
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
/* ----- Tab de procesos (dev servers de la sesión activa) ----- */
|
|
381
|
+
#viewDevices .dev-add { display: flex; gap: 8px; margin: 10px 0; }
|
|
382
|
+
#viewDevices .dev-add input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; }
|
|
383
|
+
#viewDevices .dev-add input:focus { border-color: var(--accent); outline: none; }
|
|
384
|
+
#viewDevices .device { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--panel); }
|
|
385
|
+
#viewDevices .device .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok, #22c55e); flex-shrink: 0; }
|
|
386
|
+
#viewDevices .device .dnote { color: var(--muted); font-size: 11.5px; }
|
|
387
|
+
#viewDevices .device .linkbtn { margin-left: auto; }
|
|
388
|
+
#viewDevices code { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-size: 11.5px; }
|
|
381
389
|
#viewProcs .pp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
|
|
382
390
|
#viewProcs .pp-head b { font-size: 16px; font-weight: 600; }
|
|
383
391
|
#viewProcs .pp-head b::before { content: "❯ "; color: var(--mine); }
|
|
@@ -1204,6 +1212,7 @@
|
|
|
1204
1212
|
<button data-view="procs" type="button" title="Procesos de la sesión">procs</button>
|
|
1205
1213
|
<button data-view="changes" type="button" title="Cambios del proyecto (git)">cambios</button>
|
|
1206
1214
|
<button data-view="mcp" type="button" title="Servidores MCP de opencode">mcp</button>
|
|
1215
|
+
<button data-view="devices" type="button" title="PCs emparejadas a tu cuenta" style="display:none">dispositivos</button>
|
|
1207
1216
|
</div>
|
|
1208
1217
|
<div class="footer">
|
|
1209
1218
|
<div class="row" id="bridgeStatusRow">
|
|
@@ -1287,6 +1296,7 @@
|
|
|
1287
1296
|
<div id="viewProcs" class="view" style="display:none"></div>
|
|
1288
1297
|
<div id="viewChanges" class="view" style="display:none"></div>
|
|
1289
1298
|
<div id="viewMcp" class="view" style="display:none"></div>
|
|
1299
|
+
<div id="viewDevices" class="view" style="display:none"></div>
|
|
1290
1300
|
|
|
1291
1301
|
<footer id="statusbar">
|
|
1292
1302
|
<span class="dot" id="sbDot"></span>
|