source: admin/WebConsole/rest/ogagent.php @ 83b9c80

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 83b9c80 was b1735a7, checked in by ramon <ramongomez@…>, 9 years ago

#718 #730: Incluir rutas REST que atienden las peticiones push del nuevo OGAgent y actualización de la ubicación del fichero para registrarlas.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4837 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 3.2 KB
Line 
1<?php
2
3// OpenGnsys REST routes for OGAgent communications.
4// Author: Ramón M. Gómez
5// Date:   2015-09-04
6// Warning: authentication/authorisation not included.
7
8
9// OGAgent sessions log file.
10define('LOG_FILE', '/opt/opengnsys/log/ogagent.log');
11
12// OGAgent notifies that its service is started on client.
13$app->post('/ogagent/started',
14    function() use ($app) {
15
16        try {
17                // Reading POST parameters in JSON format.
18                $input = json_decode($app->request()->getBody());
19                $ip = htmlspecialchars($input->ip);
20                $mac = htmlspecialchars($input->mac);
21                // May check that client is included in the server database?
22                // Default processing: log activity.
23                file_put_contents(LOG_FILE, date(DATE_RSS).": OGAgent started: ip=$ip, mac=$mac.\n", FILE_APPEND);
24                // Response.
25                $response["error"] = false;
26                jsonResponse(200, $response);
27        } catch (Exception $e) {
28                // Comunication error.
29                $response["error"] = true;
30                $response["message"] = $e->getMessage();
31                jsonResponse(400, $response);
32        }
33    }
34);
35
36// OGAgent notifies that its service is stopped on client.
37$app->post('/ogagent/stopped',
38    function() use ($app) {
39
40        try {
41                // Reading POST parameters in JSON format.
42                $input = json_decode($app->request()->getBody());
43                $ip = htmlspecialchars($input->ip);
44                $mac = htmlspecialchars($input->mac);
45                // May check that client is included in the server database?
46                // Default processing: log activity.
47                file_put_contents(LOG_FILE, date(DATE_RSS).": OGAgent stopped: ip=$ip, mac=$mac.\n", FILE_APPEND);
48                // Response.
49                $response["error"] = false;
50                jsonResponse(200, $response);
51        } catch (Exception $e) {
52                // Comunication error.
53                $response["error"] = true;
54                $response["message"] = $e->getMessage();
55                jsonResponse(400, $response);
56        }
57    }
58);
59
60// OGAgent notifies that an user logs in.
61$app->post('/ogagent/loggedin',
62    function() use ($app) {
63
64        try {
65                // Reading POST parameters in JSON format.
66                $input = json_decode($app->request()->getBody());
67                $ip = htmlspecialchars($input->ip);
68                $user = htmlspecialchars($input->user);
69                // May check that client is included in the server database?
70                // Default processing: log activity.
71                file_put_contents(LOG_FILE, date(DATE_RSS).": User logged in: ip=$ip, user=$user.\n", FILE_APPEND);
72                // Response.
73                $response["error"] = false;
74                jsonResponse(200, $response);
75        } catch (Exception $e) {
76                // Comunication error.
77                $response["error"] = true;
78                $response["message"] = $e->getMessage();
79                jsonResponse(400, $response);
80        }
81    }
82);
83
84// OGAgent notifies that an user logs out.
85$app->post('/ogagent/loggedout',
86    function() use ($app) {
87
88        try {
89                // Reading POST parameters in JSON format.
90                $input = json_decode($app->request()->getBody());
91                $ip = htmlspecialchars($input->ip);
92                $user = htmlspecialchars($input->user);
93                // May check that client is included in the server database?
94                // Default processing: log activity.
95                file_put_contents(LOG_FILE, date(DATE_RSS).": User logged out: ip=$ip, user=$user.\n", FILE_APPEND);
96                // Response.
97                $response["error"] = false;
98                jsonResponse(200, $response);
99        } catch (Exception $e) {
100                // Comunication error.
101                $response["error"] = true;
102                $response["message"] = $e->getMessage();
103                jsonResponse(400, $response);
104        }
105    }
106);
107
108?>
109
Note: See TracBrowser for help on using the repository browser.