Commit Graph

40 Commits (2465ef25b741dfc39df343e550e88fd0b61a6460)

Author SHA1 Message Date
Jose M. Guisado 2465ef25b7 #1065 Add event datagram socket
ogClient can receive events via a datagram socket opened at 55885.
This socket is only opened when in windows or linux mode, for
event reporting from within the system.

Events reported this way are sent back to ogServer via a 103 Early
Hints HTTP message. Information regarding the event is sent in the
response's payload.
2021-11-29 12:58:13 +01:00
Jose M. Guisado 6ddc1da7ca #1065 Fix windows not reattempting refused connections
Windows does not report a refused connection the same way as Linux.
Unsuccesful connect socket will be kept in the exceptfds, and won't
be in the readable nor writable fds. The socket in this state will
have SO_ERROR set to ECONNREFUSED.

On the other hand, Linux does not use exceptfds for such case.
2021-11-23 12:46:31 +01:00
Jose M. Guisado 2dbcd18c06 #1065 revisit config_path initialization
If current platform is Linux (either live, virtual or linux) expect
/opt/opengnsys/ogclient/cfg/ to contain ogclient.json.

If current platform is not Linux then we fallback to current directory.
2021-11-18 16:31:36 +01:00
Jose M. Guisado f9511932ad #1065 Add windows mode
Add agent mode for windows platform.

Subprocess module for shell/run is cross-platform an no change was
needed. The subprocess will run with the same privilege as its parent,
ogclient.

TODO: Provide a windows installer. As of now,  an administrator
needs to install python and required libraries for this mode to be
usable.
2021-11-18 13:50:16 +01:00
Jose M. Guisado 2d3d31bf61 #1065 src: add linux mode
ogClient can run in "linux" mode. In addition to live or virtual.
Serves as a substitute to the legacy ogagent, which has not received any
updates since 2020/07/23.

Linux mode initially supports remote reboot and poweroff. Requires
updated ogServer with the Linux ogclient state.

ogClient can be set up to run in linux mode by specifying it in
ogclient.json:

{
	"opengnsys": {
		"ip": "192.168.56.10",
		"port": 8889,
		"log": "DEBUG",
		"mode": "linux",
	...
}
2021-11-15 13:37:40 +01:00
OpenGnSys Support Team e549bd819e #1056 stop thread if connection with server is lost
Abort command if the connection with the server is lost.

Otherwise, a race condition that leaves ogServer and ogClient
out-of-sync might occur:

1. ogClient is busy running a command (on the worker thread), for example,
   image/restore.
2. ogServer is stopped OR ogClient loses connection with ogServer (due to
   transient network problem).
3. ogClient reconnects and ogServer sends a refresh command.
4. ogClient worker thread finishes and it sends a reply to image/restore.
5. ogServer gets confused because it expects a reply to the refresh
   command, not the old image/restore.
2021-11-11 13:12:45 +01:00
OpenGnSys Support Team 082079ad78 #1056 stop request processing on connection closure
If server closes the connection, close the socket, reconnect and stop
processing. self.connect() already cleans up the internal state, including the
socket state.
2021-07-15 13:08:51 +02:00
OpenGnSys Support Team c61964fa85 #1056 add cleanup method and use it
add method to clean up interval socket state and use it
2021-07-15 13:08:43 +02:00
Javier Sánchez Parra 7940887068 #1000 Fix HTTP request header length parsing
OgClient miscalculates the body size of the request.

ogServer delimits HTTP headers with "\r\n\r\n" to comply with RFC 2616.
But ogClient searches for the first "\r\n" delimiter, hence, ogClient
stops at the first HTTP header field instead of at the end of the header.
Hence, it incorrectly assumes the body starts after the first "\r\n".

This commit updates ogClient to search for the "\r\n\r\n" delimiter.

Example:

POST /shell/run HTTP/1.1\r\n <-- ogClient considers body starts here (WRONG!)
Content-Length: 952\r\n
Content-Type: application/json\r\n
\r\n                         <-- Here is where the body starts
{"json-body":...}
2021-07-13 14:07:57 +02:00
OpenGnSys Support Team cb9edc8d95 ogClient is AGPLv3+
Update license header in files.
2021-05-14 00:19:28 +02:00
OpenGnSys Support Team 8b959c8be9 #980 Broken TCP connection times out after 120 seconds through keepalive
Enable TCP keepalive to detect if the ogServer is gone (hard reset). If no reply
after 120 seconds, then release the connection to the server.
2021-04-23 00:34:39 +02:00
Javier Sánchez Parra 36b5064970 #1000 Fix ogClient HTTP length handling
Irina reports that "Partition assistant"/"Asistente de particionado" is
not working. This is happening because ogClient is not reading the full
data ogServer sends when the entire HTTP PDU is larger than 1024.
However, ogClient should read the whole message, reading until read data
length is greater or equal to "Content-Length" header value.

ogClient fails to obtain "Content-Length" value because is looking for
"content-length", be aware of the case sensitivity. It also needs to
take into account the header length because read data length also
includes headers.

This patch updates ogClient to:

1) look for "Content-Length instead of "content-length".

2) compare read date length with content length plus headers
   length.
2020-08-25 10:55:45 +02:00
Javier Sánchez Parra 0593119352 #999 Fix ogClient session command
Disconnect gracefully from ogServer after booting OS, the script to start the
OS calls kexec, so everything is gone after it. For Windows, this results in a
reboot.

This commit also improves the disconnect function to make sure the
disconnection is synchronous.
2020-08-21 18:39:35 +02:00
Roberto Hueso Gómez 1377aceec2 Rename 'linux' mode to 'live' mode
'linux' represents ogLive mode that is the reason for the rename.
2020-06-05 14:55:10 +02:00
Roberto Hueso Gómez d7b7b0b175 Delete ogConfig.py
This file is only used for its OG_PATH variable, this variable is now in
ogClient.
2020-06-05 13:08:00 +02:00
OpenGnSys Support Team 5f874030f5 remove platform check 2020-05-13 17:01:20 +02:00
Roberto Hueso Gómez 38b6d77561 Switch config file to json
This patch makes configuration parsing easier as well as making the full
configuration available in many subclasses.
2020-05-13 14:10:01 +02:00
Roberto Hueso Gómez 7ccc498014 Use samba for create and restore virtual partitions
This requires to configure user and password for samba repositories.
2020-04-17 15:50:35 +02:00
OpenGnSys Support Team 439e5db7b7 wait for 1 second if connection is refused 2020-04-14 12:05:15 +02:00
Roberto Hueso Gomez 8a927a352d Sleep 1 second to avoid high CPU load 2020-04-14 11:48:13 +02:00
Roberto Hueso Gomez d6c5f2443a Avoid connection status infinite print loop
This patch avoids infinite writting of connection status messages to the log.
2020-04-14 11:31:22 +02:00
Roberto Hueso Gomez 4f03c31f85 Add mode selection for ogClient 2020-04-08 13:31:45 +02:00
OpenGnSys Support Team a85c113ee7 Rename operation to method
As defined by the HTTP standard.
2020-02-26 17:58:15 +01:00
Alvaro Neira Ayuso 8fc251eff3 (Clean-Up) Rename HTTPParser to restRequest 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 05b1088827 Include License header 2020-01-19 19:50:44 +01:00
Roberto Hueso Gómez 3c450b0d81 Fix ogClient socket.error typo 2020-01-19 19:50:44 +01:00
Roberto Hueso gomez 0c5cbee301 Change ogClient.py encoding from dos to unix 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 2fa8aa4ff7 Add session command to init the opengnsys session
ogAdmClient has a support for initializing the session in the machine. This new
command allows the new ogClient to execute the same script to init the session.
The arguments will be received from the server as a json message. Format:

{ "disk" : "0", "partition" : "1"}
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso e20daf639d Add shell run and output commands
Opengnsys needs a support to execute commands on the machine. This patch adds
the support for executing two new commands "shell/run" and "shell/output". The
first one, give us the support for executing a command in the machine and keep
save in a queue the output. The second one, give us the support for sending the
output from the command executed.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso dfc97ffedb Merge ogRest and ogProcess to have only one class 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 77906be87f Include disconnect and send function on client side
To disconnect the socket or send a message we use in different parts of the code
the attribute socket which is declared inside of the client. This way will
create us important problem in the future if we want to change the behavior in
our client sockets. This patch adds two new methods inside the client and we
can use them in other classes giving us the easy way to send messages and
disconnect the client.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 694bc492a2 Add ogRest class to generate API Rest Responses
This class now, allow us to generate API Rest responses. In the future, the idea
is to complete this class with get and post messages if it's needed.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 7548870a92 Port program to Python 3
Python 2.7 will be deprecated in January of 2020. So, we need to have the program
with a supported api.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 72e93be46f Remove unneeded logs 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 2d72f00d95 Send bad request when the APIRest operation is not supported
Our program sends always the HTTP message:

HTTP/1.0 200 OK

but if the operation sent is not supported, we are sending the same correct
message. This patch add the support to check if the message is supported.

If the message is not supported, we are going to send:
 HTTP/1.0 400 Bad request\r\n\r\n
Otherwise, in operations supported:
 HTTP/1.0 200 OK
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 9eabc7f9a8 Execute socket loop on run socket function
Ported code from main function to a client function for clearing the main loop.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso ebd640a9c5 Add ogProcess and ogOperation for linux
Thoses new classes allows us to process and execute commands from server side
sent using HTTP format.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso bfdeae840c Add HTTP parser support
The new OpenGnsys support to communicate server and client side will be
HTTP. This new class allows us the support for parsing all the message received
from the server in HTTP format.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 076e15bb29 Modify Client state to use enum
During our connections, we are using states to control the Client Socket. We
defined using global variables. In case that we modify this global variable,
we need to change it in serveral parts of the code.

Using enums and declaring a new class, we can redefine the values or create new
states without changing the same code in differents python files.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 29fe301ec8 Create new ogClient
This commit init the new ogClient. The new ogClient has support for configuring
and for connecting with the ogAdminServer.
2020-01-19 19:50:44 +01:00