unificar-endpoints #41

Merged
nserrano merged 5 commits from unificar-endpoints into main 2025-06-23 12:39:53 +02:00
11 changed files with 54 additions and 23 deletions

View File

@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [6.0.0] - 2025-06-19
### Changed
- Changed the names of some endpoints for consistency between oglive and OS
- Changed label in the windows installer
## [5.9.0] - 2025-06-16
### Added

View File

@ -1,3 +1,10 @@
ogagent (6.0.0-1) stable; urgency=medium
* Unify API methods for poweroff, reboot and run script
* Change label in the windows installer
-- OpenGnsys developers <info@opengnsys.es> Fri, 20 Jun 2025 10:03:15 +0200
ogagent (5.9.0-1) stable; urgency=medium
* Add changes for oggit

View File

@ -1 +1 @@
5.9.0
6.0.0

View File

@ -7,7 +7,7 @@ port=8000
#path=test_modules/server,more_modules/server
# Remote OpenGnsys Service
remote=https://192.168.2.1/opengnsys/rest
remote=https://192.168.2.1:8443/opengnsys/rest
# Alternate OpenGnsys Service (comment out to enable this option)
#altremote=https://10.0.2.2/opengnsys/rest

View File

@ -209,7 +209,7 @@ class REST(object):
r.raise_for_status()
ct = r.headers['Content-Type']
if 'application/json' != ct:
if len(ct) < 16 or 'application/json' != ct[0:16]:
raise Exception (f'response content-type is not "application/json" but "{ct}"')
r = json.loads(r.content) # Using instead of r.json() to make compatible with old requests lib versions
except requests.exceptions.RequestException as e:

View File

@ -165,6 +165,9 @@ class ClientProcessor(threading.Thread):
logger.debug('Got invalid message from request: {}, state: {}'.format(buf, state))
except socket.error as e:
# If no data is present, no problem at all, pass to check messages
if '[WinError 10054]' in str(e):
## windows: client disconnected
self.running = False
pass
except Exception as e:
tb = traceback.format_exc()

View File

@ -39,6 +39,7 @@ from opengnsys.log import logger
from opengnsys.linux.daemon import Daemon
import os
import sys
import signal
import json
@ -71,6 +72,13 @@ class OGAgentSvc(Daemon, CommonService):
# example
try:
while self.isAlive:
client_died=False
if os.path.exists ('/tmp/ogagentuser_died'):
os.unlink ('/tmp/ogagentuser_died')
client_died=True
if client_died:
self.notifyLogout (b'')
# In milliseconds, will break
self.doWait(1000)
except (KeyboardInterrupt, SystemExit) as e:

View File

@ -112,7 +112,7 @@ class OpenGnSysWorker(ServerWorker):
"iph": self.interface.ip,
"timestamp": int (time.time()),
}
logger.debug (f'about to send ping ({body})')
#logger.debug (f'about to send ping ({body})')
self.REST.sendMessage ('clients/status/webhook', body)
def onActivation(self):
@ -308,7 +308,7 @@ class OpenGnSysWorker(ServerWorker):
@execution_level('halt')
@check_secret
def process_reboot(self, path, get_params, post_params, server):
def process_Reiniciar(self, path, get_params, post_params, server):
"""
Launches a system reboot operation
:param path:
@ -327,7 +327,7 @@ class OpenGnSysWorker(ServerWorker):
@execution_level('halt')
@check_secret
def process_poweroff(self, path, get_params, post_params, server):
def process_Apagar(self, path, get_params, post_params, server):
"""
Launches a system power off operation
:param path:
@ -347,7 +347,7 @@ class OpenGnSysWorker(ServerWorker):
@execution_level('full')
@check_secret
def process_script(self, path, get_params, post_params, server):
def process_EjecutarScript(self, path, get_params, post_params, server):
"""
Processes an script execution (script should be encoded in base64)
:param path:
@ -358,7 +358,14 @@ class OpenGnSysWorker(ServerWorker):
"""
logger.debug('Processing script request')
# Decoding script
script = urllib.parse.unquote(base64.b64decode(post_params.get('script')).decode('utf-8'))
param_script = post_params.get('script')
if not param_script:
return {'op': 'error', 'err': 'Required parameter "script" is missing or empty'}
try:
b64decoded = base64.b64decode (param_script)
except Exception as e:
return {'op': 'error', 'err': f'Failed to decode base64: {e}'}
script = urllib.parse.unquote (b64decoded.decode ('utf-8'))
logger.debug('received script "{}"'.format(script))
if post_params.get('client', 'false') == 'false':

View File

@ -198,16 +198,6 @@ class CommonService(object):
Invoked to wait a bit
CAN be OVERRIDDEN
"""
client_died=False
if os.path.exists ('/windows/temp/ogagentuser_died'):
os.unlink ('/windows/temp/ogagentuser_died')
client_died=True
elif os.path.exists ('/tmp/ogagentuser_died'):
os.unlink ('/tmp/ogagentuser_died')
client_died=True
if client_died:
self.notifyLogout (b'')
time.sleep(float(miliseconds) / 1000)
def notifyStop(self):

View File

@ -106,6 +106,13 @@ class OGAgentSvc(win32serviceutil.ServiceFramework, CommonService):
# *********************
try:
while self.isAlive:
client_died=False
if os.path.exists ('/windows/temp/ogagentuser_died'):
os.unlink ('/windows/temp/ogagentuser_died')
client_died=True
if client_died:
self.notifyLogout (b'')
# Pumps & processes any waiting messages
pythoncom.PumpWaitingMessages()
win32event.WaitForSingleObject(self.hWaitStop, 1000)

View File

@ -217,7 +217,7 @@ FunctionEnd
Function GetParameters
${GetOptions} $CMDLINE "/server" $SERVERIP_VALUE
${If} $SERVERIP_VALUE == ""
StrCpy $SERVERIP_VALUE "192.168.2.10"
StrCpy $SERVERIP_VALUE "192.168.2.1:8443"
${EndIf}
FunctionEnd
@ -226,10 +226,12 @@ LangString PARAMS_TITLE ${LANG_ENGLISH} "Setup parameters"
LangString PARAMS_TITLE ${LANG_SPANISH} "Parametros de configuracion"
LangString PARAMS_TITLE ${LANG_FRENCH} "Parametres de configuration"
LangString PARAMS_TITLE ${LANG_GERMAN} "Setup-Parameter"
LangString SERVER_LABEL ${LANG_ENGLISH} "OpenGnsys Server IP Address"
LangString SERVER_LABEL ${LANG_SPANISH} "Direccion IP del Servidor OpenGnsys"
LangString SERVER_LABEL ${LANG_FRENCH} "Adresse IP du Serveur OpenGnsys"
LangString SERVER_LABEL ${LANG_GERMAN} "OpenGnsys-Server-IP-Adresse"
LangString SERVER_LABEL ${LANG_ENGLISH} "OpenGnsys Server IP Address and port (eg. 192.168.98.99:8443)"
LangString SERVER_LABEL ${LANG_SPANISH} "Direccion IP y puerto del Servidor OpenGnsys (p. ej. 192.168.98.99:8443)"
LangString SERVER_LABEL ${LANG_FRENCH} "Adresse IP et port du Serveur OpenGnsys (ex. 192.168.98.99:8443)"
LangString SERVER_LABEL ${LANG_GERMAN} "OpenGnsys Server IP-Adresse und Port (z. B. 192.168.98.99:8443)"
LangString ^UninstallLink ${LANG_ENGLISH} "Uninstall $(^Name)"
LangString ^UninstallLink ${LANG_SPANISH} "Desinstalar $(^Name)"
LangString ^UninstallLink ${LANG_FRENCH} "D<>sinstaller $(^Name)"