source: admin/WebConsole/rest/ogagent.php @ d8f592d

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 d8f592d was 29bc749, checked in by ramon <ramongomez@…>, 9 years ago

#708: Eliminar parámetro error en las respuestas JSON por ser redundante (el código HTTP de la respuesta indica si se produce o no un error).

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

  • Property mode set to 100644
File size: 2.9 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                jsonResponse(200, $response);
26        } catch (Exception $e) {
27                // Comunication error.
28                $response["message"] = $e->getMessage();
29                jsonResponse(400, $response);
30        }
31    }
32);
33
34// OGAgent notifies that its service is stopped on client.
35$app->post('/ogagent/stopped',
36    function() use ($app) {
37
38        try {
39                // Reading POST parameters in JSON format.
40                $input = json_decode($app->request()->getBody());
41                $ip = htmlspecialchars($input->ip);
42                $mac = htmlspecialchars($input->mac);
43                // May check that client is included in the server database?
44                // Default processing: log activity.
45                file_put_contents(LOG_FILE, date(DATE_RSS).": OGAgent stopped: ip=$ip, mac=$mac.\n", FILE_APPEND);
46                // Response.
47                jsonResponse(200, $response);
48        } catch (Exception $e) {
49                // Comunication error.
50                $response["message"] = $e->getMessage();
51                jsonResponse(400, $response);
52        }
53    }
54);
55
56// OGAgent notifies that an user logs in.
57$app->post('/ogagent/loggedin',
58    function() use ($app) {
59
60        try {
61                // Reading POST parameters in JSON format.
62                $input = json_decode($app->request()->getBody());
63                $ip = htmlspecialchars($input->ip);
64                $user = htmlspecialchars($input->user);
65                // May check that client is included in the server database?
66                // Default processing: log activity.
67                file_put_contents(LOG_FILE, date(DATE_RSS).": User logged in: ip=$ip, user=$user.\n", FILE_APPEND);
68                // Response.
69                jsonResponse(200, $response);
70        } catch (Exception $e) {
71                // Comunication error.
72                $response["message"] = $e->getMessage();
73                jsonResponse(400, $response);
74        }
75    }
76);
77
78// OGAgent notifies that an user logs out.
79$app->post('/ogagent/loggedout',
80    function() use ($app) {
81
82        try {
83                // Reading POST parameters in JSON format.
84                $input = json_decode($app->request()->getBody());
85                $ip = htmlspecialchars($input->ip);
86                $user = htmlspecialchars($input->user);
87                // May check that client is included in the server database?
88                // Default processing: log activity.
89                file_put_contents(LOG_FILE, date(DATE_RSS).": User logged out: ip=$ip, user=$user.\n", FILE_APPEND);
90                // Response.
91                jsonResponse(200, $response);
92        } catch (Exception $e) {
93                // Comunication error.
94                $response["message"] = $e->getMessage();
95                jsonResponse(400, $response);
96        }
97    }
98);
99
100?>
101
Note: See TracBrowser for help on using the repository browser.