Allow changing Hysteria UDP port when 443 is already in use.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1701,6 +1701,11 @@ class Socks5SettingsRequest(BaseModel):
|
||||
password: Optional[str] = None
|
||||
|
||||
|
||||
class HysteriaSettingsRequest(BaseModel):
|
||||
protocol: str = 'hysteria'
|
||||
port: Optional[int] = None
|
||||
|
||||
|
||||
class ProtocolRequest(BaseModel):
|
||||
protocol: str = 'awg'
|
||||
|
||||
@@ -2963,6 +2968,70 @@ async def api_socks5_update_credentials(request: Request, server_id: int, req: S
|
||||
return JSONResponse({'error': str(e)}, status_code=500)
|
||||
|
||||
|
||||
@app.get('/api/servers/{server_id}/hysteria/settings', tags=["Protocols"])
|
||||
async def api_hysteria_get_settings(request: Request, server_id: int, protocol: str = 'hysteria'):
|
||||
"""Return current Hysteria domain/port for the settings modal."""
|
||||
if not _check_admin(request):
|
||||
return JSONResponse({'error': 'Forbidden'}, status_code=403)
|
||||
try:
|
||||
data = load_data()
|
||||
if server_id >= len(data['servers']):
|
||||
return JSONResponse({'error': 'Server not found'}, status_code=404)
|
||||
if not is_valid_protocol(protocol) or protocol_base(protocol) != 'hysteria':
|
||||
return JSONResponse({'error': 'Invalid protocol'}, status_code=400)
|
||||
server = data['servers'][server_id]
|
||||
ssh = get_ssh(server)
|
||||
ssh.connect()
|
||||
manager = get_protocol_manager(ssh, protocol)
|
||||
settings = manager.get_settings()
|
||||
ssh.disconnect()
|
||||
saved = (server.get('protocols') or {}).get(protocol) or {}
|
||||
if not settings.get('port') and saved.get('port'):
|
||||
settings['port'] = int(saved['port'])
|
||||
return {'status': 'success', **settings}
|
||||
except Exception as e:
|
||||
logger.exception("Error reading Hysteria settings")
|
||||
return JSONResponse({'error': str(e)}, status_code=500)
|
||||
|
||||
|
||||
@app.post('/api/servers/{server_id}/hysteria/settings', tags=["Protocols"])
|
||||
async def api_hysteria_update_settings(request: Request, server_id: int, req: HysteriaSettingsRequest):
|
||||
"""Change Hysteria UDP listen port and recreate the container."""
|
||||
if not _check_admin(request):
|
||||
return JSONResponse({'error': 'Forbidden'}, status_code=403)
|
||||
try:
|
||||
data = load_data()
|
||||
if server_id >= len(data['servers']):
|
||||
return JSONResponse({'error': 'Server not found'}, status_code=404)
|
||||
protocol = req.protocol if is_valid_protocol(req.protocol) and protocol_base(req.protocol) == 'hysteria' else 'hysteria'
|
||||
server = data['servers'][server_id]
|
||||
ssh = get_ssh(server)
|
||||
ssh.connect()
|
||||
manager = get_protocol_manager(ssh, protocol)
|
||||
result = manager.update_settings(port=req.port)
|
||||
ssh.disconnect()
|
||||
if result.get('status') == 'error':
|
||||
return JSONResponse(
|
||||
{'error': result.get('message') or 'Failed to update settings', **{k: v for k, v in result.items() if k != 'status'}},
|
||||
status_code=400,
|
||||
)
|
||||
if result.get('port'):
|
||||
srv_proto = server.setdefault('protocols', {}).setdefault(protocol, {})
|
||||
srv_proto['port'] = str(result['port'])
|
||||
srv_proto['installed'] = True
|
||||
srv_proto['base_protocol'] = protocol_base(protocol)
|
||||
srv_proto['instance'] = protocol_instance(protocol)
|
||||
srv_proto['display_name'] = protocol_display_name(protocol)
|
||||
srv_proto['container_name'] = protocol_container_name(protocol)
|
||||
if result.get('domain'):
|
||||
srv_proto['domain'] = result['domain']
|
||||
save_data(data)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.exception("Error updating Hysteria settings")
|
||||
return JSONResponse({'error': str(e)}, status_code=500)
|
||||
|
||||
|
||||
@app.post('/api/servers/{server_id}/uninstall', tags=["Protocols"])
|
||||
async def api_uninstall_protocol(request: Request, server_id: int, req: ProtocolRequest):
|
||||
if not _check_admin(request):
|
||||
|
||||
Reference in New Issue
Block a user