wsjtx relay

pull/49/head
accius 2 days ago
parent 35b0daa2d1
commit 88216daac0

@ -4178,6 +4178,134 @@ app.post('/api/wsjtx/relay', (req, res) => {
res.json({ ok: true, processed, timestamp: Date.now() });
});
// API endpoint: download pre-configured relay agent script
// Embeds relay.js + server URL + relay key into a one-file launcher
app.get('/api/wsjtx/relay/download/:platform', (req, res) => {
if (!WSJTX_RELAY_KEY) {
return res.status(503).json({ error: 'Relay not configured — set WSJTX_RELAY_KEY in .env' });
}
const platform = req.params.platform; // 'linux', 'mac', or 'windows'
const relayJsPath = path.join(__dirname, 'wsjtx-relay', 'relay.js');
let relayJs;
try {
relayJs = fs.readFileSync(relayJsPath, 'utf8');
} catch (e) {
return res.status(500).json({ error: 'relay.js not found on server' });
}
// Detect server URL from request
const proto = req.headers['x-forwarded-proto'] || req.protocol || 'http';
const host = req.headers['x-forwarded-host'] || req.headers.host;
const serverURL = proto + '://' + host;
if (platform === 'linux' || platform === 'mac') {
// Build bash script with relay.js embedded as heredoc
const lines = [
'#!/bin/bash',
'# OpenHamClock WSJT-X Relay — Auto-configured',
'# Generated by ' + serverURL,
'#',
'# Usage: bash ' + (platform === 'mac' ? 'start-relay.command' : 'start-relay.sh'),
'# Stop: Ctrl+C',
'# Requires: Node.js 14+ (https://nodejs.org)',
'#',
'# In WSJT-X: Settings > Reporting > UDP Server',
'# Address: 127.0.0.1 Port: 2237',
'',
'set -e',
'',
'# Check for Node.js',
'if ! command -v node &> /dev/null; then',
' echo ""',
' echo "Node.js is not installed."',
' echo "Install from https://nodejs.org (LTS recommended)"',
' echo ""',
' echo "Quick install:"',
' echo " Ubuntu/Debian: sudo apt install nodejs"',
' echo " Mac (Homebrew): brew install node"',
' echo " Fedora: sudo dnf install nodejs"',
' echo ""',
' exit 1',
'fi',
'',
'# Write relay agent to temp file',
'RELAY_FILE=$(mktemp /tmp/ohc-relay-XXXXXX.js)',
'trap "rm -f $RELAY_FILE" EXIT',
'',
"cat > \"$RELAY_FILE\" << 'OPENHAMCLOCK_RELAY_EOF'",
relayJs,
'OPENHAMCLOCK_RELAY_EOF',
'',
'# Run relay',
'exec node "$RELAY_FILE" \\',
' --url "' + serverURL + '" \\',
' --key "' + WSJTX_RELAY_KEY + '"',
];
const script = lines.join('\n') + '\n';
const filename = platform === 'mac' ? 'start-relay.command' : 'start-relay.sh';
res.setHeader('Content-Type', 'application/x-sh');
res.setHeader('Content-Disposition', 'attachment; filename="' + filename + '"');
return res.send(script);
} else if (platform === 'windows') {
// Build PowerShell script with relay.js embedded
const escapedJs = relayJs.replace(/'/g, "''");
const lines = [
'# OpenHamClock WSJT-X Relay - Auto-configured',
'# Generated by ' + serverURL,
'# Right-click > "Run with PowerShell" or run from terminal',
'# Requires: Node.js 14+ (https://nodejs.org)',
'#',
'# In WSJT-X: Settings > Reporting > UDP Server',
'# Address: 127.0.0.1 Port: 2237',
'',
'# Check for Node.js',
'try {',
' $nv = (node -v 2>$null)',
' if (-not $nv) { throw "missing" }',
' Write-Host "Found Node.js $nv" -ForegroundColor Green',
'} catch {',
' Write-Host "Node.js is not installed." -ForegroundColor Red',
' Write-Host "Download from https://nodejs.org (LTS version)" -ForegroundColor Yellow',
' Read-Host "Press Enter to exit"',
' exit 1',
'}',
'',
'# Write relay agent to temp file',
'$relayFile = Join-Path $env:TEMP "ohc-relay.js"',
'',
"$relayCode = @'",
escapedJs,
"'@",
'',
'$relayCode | Out-File -FilePath $relayFile -Encoding UTF8',
'',
'Write-Host "Starting WSJT-X relay agent..." -ForegroundColor Cyan',
'Write-Host "Press Ctrl+C to stop" -ForegroundColor DarkGray',
'Write-Host ""',
'',
'# Run relay',
'try {',
' node $relayFile --url "' + serverURL + '" --key "' + WSJTX_RELAY_KEY + '"',
'} finally {',
' Remove-Item $relayFile -ErrorAction SilentlyContinue',
'}',
];
const script = lines.join('\r\n') + '\r\n';
res.setHeader('Content-Type', 'application/x-powershell');
res.setHeader('Content-Disposition', 'attachment; filename="start-relay.ps1"');
return res.send(script);
} else {
return res.status(400).json({ error: 'Invalid platform. Use: linux, mac, or windows' });
}
});
// ============================================
// CATCH-ALL FOR SPA
// ============================================

@ -347,14 +347,33 @@ const PSKReporterPanel = ({
}}>
<div style={{ fontSize: '12px' }}>Waiting for WSJT-X...</div>
{wsjtxRelayEnabled ? (
<div style={{ fontSize: '10px', opacity: 0.6, lineHeight: 1.5 }}>
<span style={{ color: '#a78bfa' }}>Relay mode</span> run the relay agent locally:
<br />
<code style={{ background: 'rgba(167,139,250,0.15)', padding: '1px 4px', borderRadius: '2px', fontSize: '9px' }}>
node relay.js --url {'{this server}'} --key {'{key}'}
</code>
<br />
<span style={{ fontSize: '9px' }}>See wsjtx-relay/README.md</span>
<div style={{ fontSize: '10px', opacity: 0.8, lineHeight: 1.6 }}>
<div style={{ marginBottom: '8px' }}>
Download the relay agent for your PC:
</div>
<div style={{ display: 'flex', gap: '4px', justifyContent: 'center', flexWrap: 'wrap' }}>
<a href="/api/wsjtx/relay/download/linux"
style={{
padding: '4px 10px', borderRadius: '4px', fontSize: '10px', fontWeight: '600',
background: 'rgba(167,139,250,0.2)', border: '1px solid #a78bfa55',
color: '#a78bfa', textDecoration: 'none', cursor: 'pointer',
}}>🐧 Linux</a>
<a href="/api/wsjtx/relay/download/mac"
style={{
padding: '4px 10px', borderRadius: '4px', fontSize: '10px', fontWeight: '600',
background: 'rgba(167,139,250,0.2)', border: '1px solid #a78bfa55',
color: '#a78bfa', textDecoration: 'none', cursor: 'pointer',
}}>🍎 Mac</a>
<a href="/api/wsjtx/relay/download/windows"
style={{
padding: '4px 10px', borderRadius: '4px', fontSize: '10px', fontWeight: '600',
background: 'rgba(167,139,250,0.2)', border: '1px solid #a78bfa55',
color: '#a78bfa', textDecoration: 'none', cursor: 'pointer',
}}>🪟 Windows</a>
</div>
<div style={{ fontSize: '9px', opacity: 0.5, marginTop: '6px' }}>
Requires Node.js · Run the script, then start WSJT-X
</div>
</div>
) : (
<div style={{ fontSize: '10px', opacity: 0.6, lineHeight: 1.5 }}>

Loading…
Cancel
Save

Powered by TurnKey Linux.