source: ogServer-Git/src/client.c @ b6b1040

Last change on this file since b6b1040 was b6b1040, checked in by Jose M. Guisado <jguisado@…>, 3 years ago

#1065 client: add support for ogclient win state

ogClient can be run in windows mode, enabling connection with ogServer
when running on a Windows machine.

Don't expect the same payload in windows mode as a in live or virtual.
Client in windows mode does not send partition setup information, only
the status/state. (same case for linux mode)

  • Property mode set to 100644
File size: 18.5 KB
Line 
1/*
2 * Copyright (C) 2020-2021 Soleta Networks <info@soleta.eu>
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Affero General Public License as published by the
6 * Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 */
9
10#include "ogAdmServer.h"
11#include "cfg.h"
12#include "dbi.h"
13#include "utils.h"
14#include "list.h"
15#include "rest.h"
16#include "json.h"
17#include "schedule.h"
18#include <syslog.h>
19#include <sys/ioctl.h>
20#include <ifaddrs.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <fcntl.h>
24#include <jansson.h>
25#include <time.h>
26
27static int og_resp_probe(struct og_client *cli, json_t *data)
28{
29        const char *status = NULL;
30        const char *key;
31        uint32_t speed;
32        json_t *value;
33        int err = 0;
34
35        if (json_typeof(data) != JSON_OBJECT)
36                return -1;
37
38        json_object_foreach(data, key, value) {
39                if (!strcmp(key, "status")) {
40                        err = og_json_parse_string(value, &status);
41                        if (err < 0)
42                                return err;
43                } else if (!strcmp(key, "speed")) {
44                        err = og_json_parse_uint(value, &speed);
45                        if (err < 0)
46                                return err;
47                        cli->speed = speed;
48                }
49        }
50
51        if (!strcmp(status, "BSY"))
52                cli->status = OG_CLIENT_STATUS_BUSY;
53        else if (!strcmp(status, "OPG"))
54                cli->status = OG_CLIENT_STATUS_OGLIVE;
55        else if (!strcmp(status, "VDI"))
56                cli->status = OG_CLIENT_STATUS_VIRTUAL;
57
58        return status ? 0 : -1;
59}
60
61static int og_resp_shell_run(struct og_client *cli, json_t *data)
62{
63        const char *output = NULL;
64        char filename[4096];
65        const char *key;
66        json_t *value;
67        int err = -1;
68        FILE *file;
69
70        if (json_typeof(data) != JSON_OBJECT)
71                return -1;
72
73        json_object_foreach(data, key, value) {
74                if (!strcmp(key, "out")) {
75                        err = og_json_parse_string(value, &output);
76                        if (err < 0)
77                                return err;
78                }
79        }
80
81        if (!output) {
82                syslog(LOG_ERR, "%s:%d: malformed json response\n",
83                       __FILE__, __LINE__);
84                return -1;
85        }
86
87        sprintf(filename, "/tmp/_Seconsola_%s", inet_ntoa(cli->addr.sin_addr));
88        file = fopen(filename, "wt");
89        if (!file) {
90                syslog(LOG_ERR, "cannot open file %s: %s\n",
91                       filename, strerror(errno));
92                return -1;
93        }
94
95        fprintf(file, "%s", output);
96        fclose(file);
97
98        return 0;
99}
100
101struct og_computer_legacy  {
102        char center[OG_DB_INT_MAXLEN + 1];
103        char id[OG_DB_INT_MAXLEN + 1];
104        char hardware[8192];
105};
106
107static int og_resp_hardware(json_t *data, struct og_client *cli)
108{
109        struct og_computer_legacy legacy = {};
110        struct og_computer computer = {};
111        const char *hardware = NULL;
112        struct og_dbi *dbi;
113        const char *key;
114        json_t *value;
115        int err = 0;
116        bool res;
117
118        if (json_typeof(data) != JSON_OBJECT)
119                return -1;
120
121        json_object_foreach(data, key, value) {
122                if (!strcmp(key, "hardware")) {
123                        err = og_json_parse_string(value, &hardware);
124                        if (err < 0)
125                                return -1;
126                }
127        }
128
129        if (!hardware) {
130                syslog(LOG_ERR, "malformed response json\n");
131                return -1;
132        }
133
134        dbi = og_dbi_open(&ogconfig.db);
135        if (!dbi) {
136                syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
137                       __func__, __LINE__);
138                return -1;
139        }
140
141        err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr);
142        if (err < 0) {
143                og_dbi_close(dbi);
144                return -1;
145        }
146
147        snprintf(legacy.center, sizeof(legacy.center), "%d", computer.center);
148        snprintf(legacy.id, sizeof(legacy.id), "%d", computer.id);
149        snprintf(legacy.hardware, sizeof(legacy.hardware), "%s", hardware);
150
151        res = actualizaHardware(dbi, legacy.hardware, legacy.id, computer.name,
152                                legacy.center);
153        og_dbi_close(dbi);
154
155        if (!res) {
156                syslog(LOG_ERR, "Problem updating client configuration\n");
157                return -1;
158        }
159
160        return 0;
161}
162
163struct og_software_legacy {
164        char software[8192];
165        char center[OG_DB_INT_MAXLEN + 1];
166        char part[OG_DB_SMALLINT_MAXLEN + 1];
167        char id[OG_DB_INT_MAXLEN + 1];
168};
169
170static int og_resp_software(json_t *data, struct og_client *cli)
171{
172        struct og_software_legacy legacy = {};
173        struct og_computer computer = {};
174        const char *partition = NULL;
175        const char *software = NULL;
176        struct og_dbi *dbi;
177        const char *key;
178        json_t *value;
179        int err = 0;
180        bool res;
181
182        if (json_typeof(data) != JSON_OBJECT)
183                return -1;
184
185        json_object_foreach(data, key, value) {
186                if (!strcmp(key, "software"))
187                        err = og_json_parse_string(value, &software);
188                else if (!strcmp(key, "partition"))
189                        err = og_json_parse_string(value, &partition);
190
191                if (err < 0)
192                        return -1;
193        }
194
195        if (!software || !partition) {
196                syslog(LOG_ERR, "malformed response json\n");
197                return -1;
198        }
199
200        dbi = og_dbi_open(&ogconfig.db);
201        if (!dbi) {
202                syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
203                       __func__, __LINE__);
204                return -1;
205        }
206
207        err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr);
208        if (err < 0) {
209                og_dbi_close(dbi);
210                return -1;
211        }
212
213        snprintf(legacy.software, sizeof(legacy.software), "%s", software);
214        snprintf(legacy.part, sizeof(legacy.part), "%s", partition);
215        snprintf(legacy.id, sizeof(legacy.id), "%d", computer.id);
216        snprintf(legacy.center, sizeof(legacy.center), "%d", computer.center);
217
218        res = actualizaSoftware(dbi, legacy.software, legacy.part, legacy.id,
219                                computer.name, legacy.center);
220        og_dbi_close(dbi);
221
222        if (!res) {
223                syslog(LOG_ERR, "Problem updating client configuration\n");
224                return -1;
225        }
226
227        return 0;
228}
229
230#define OG_PARAMS_RESP_REFRESH  (OG_PARAM_PART_DISK |           \
231                                 OG_PARAM_PART_NUMBER |         \
232                                 OG_PARAM_PART_CODE |           \
233                                 OG_PARAM_PART_FILESYSTEM |     \
234                                 OG_PARAM_PART_OS |             \
235                                 OG_PARAM_PART_SIZE |           \
236                                 OG_PARAM_PART_USED_SIZE)
237
238static int og_json_parse_partition_array(json_t *value,
239                                         struct og_partition *partitions)
240{
241        json_t *element;
242        int i, err;
243
244        if (json_typeof(value) != JSON_ARRAY)
245                return -1;
246
247        for (i = 0; i < json_array_size(value) && i < OG_PARTITION_MAX; i++) {
248                element = json_array_get(value, i);
249
250                err = og_json_parse_partition(element, &partitions[i],
251                                              OG_PARAMS_RESP_REFRESH);
252                if (err < 0)
253                        return err;
254        }
255
256        return 0;
257}
258
259static int og_dbi_queue_autorun(uint32_t computer_id, uint32_t proc_id)
260{
261        struct og_task dummy_task = {
262                .scope          = computer_id,
263                .type_scope     = AMBITO_ORDENADORES,
264                .procedure_id   = proc_id,
265        };
266        struct og_dbi *dbi;
267
268        dbi = og_dbi_open(&ogconfig.db);
269        if (!dbi) {
270                syslog(LOG_ERR, "cannot open connection database "
271                                "(%s:%d)\n", __func__, __LINE__);
272                return -1;
273        }
274        if (og_dbi_queue_procedure(dbi, &dummy_task)) {
275                og_dbi_close(dbi);
276                return -1;
277        }
278        og_dbi_close(dbi);
279
280        return 0;
281}
282
283static int og_resp_refresh(json_t *data, struct og_client *cli)
284{
285        struct og_partition partitions[OG_PARTITION_MAX] = {};
286        struct og_partition disks[OG_DISK_MAX] = {};
287        const char *serial_number = NULL;
288        struct og_computer computer = {};
289        const char *status = NULL;
290        char cfg[4096] = {};
291        struct og_dbi *dbi;
292        const char *key;
293        unsigned int i;
294        json_t *value;
295        int err = 0;
296        bool res;
297
298        if (json_typeof(data) != JSON_OBJECT)
299                return -1;
300
301        json_object_foreach(data, key, value) {
302                if (!strcmp(key, "disk_setup")) {
303                        err = og_json_parse_partition_array(value, disks);
304                } else if (!strcmp(key, "partition_setup")) {
305                        err = og_json_parse_partition_array(value, partitions);
306                } else if (!strcmp(key, "serial_number")) {
307                        err = og_json_parse_string(value, &serial_number);
308                } else if (!strcmp(key, "status")) {
309                        err = og_json_parse_string(value, &status);
310                }
311
312                if (err < 0)
313                        return err;
314        }
315
316        if (status) {
317                if (!strncmp(status, "LINUX", strlen("LINUX"))) {
318                        cli->status = OG_CLIENT_STATUS_LINUX;
319                } else if (!strncmp(status, "WIN", strlen("WIN"))) {
320                        cli->status = OG_CLIENT_STATUS_WIN;
321                }
322                return 0;
323        }
324
325        if (strlen(serial_number) > 0)
326                snprintf(cfg, sizeof(cfg), "ser=%s\n", serial_number);
327
328        for (i = 0; i < OG_DISK_MAX; i++) {
329                if (!disks[i].disk || !disks[i].number ||
330                    !disks[i].code || !disks[i].filesystem ||
331                    !disks[i].os || !disks[i].size ||
332                    !disks[i].used_size)
333                        continue;
334
335                snprintf(cfg + strlen(cfg), sizeof(cfg) - strlen(cfg),
336                         "disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\tdtype=%s\n",
337                         disks[i].disk, disks[i].number,
338                         disks[i].code, disks[i].filesystem,
339                         disks[i].os, disks[i].size,
340                         disks[i].used_size, disks[i].disk_type);
341        }
342
343        for (i = 0; i < OG_PARTITION_MAX; i++) {
344                if (!partitions[i].disk || !partitions[i].number ||
345                    !partitions[i].code || !partitions[i].filesystem ||
346                    !partitions[i].os || !partitions[i].size ||
347                    !partitions[i].used_size)
348                        continue;
349
350                snprintf(cfg + strlen(cfg), sizeof(cfg) - strlen(cfg),
351                         "disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\n",
352                         partitions[i].disk, partitions[i].number,
353                         partitions[i].code, partitions[i].filesystem,
354                         partitions[i].os, partitions[i].size,
355                         partitions[i].used_size);
356        }
357
358        dbi = og_dbi_open(&ogconfig.db);
359        if (!dbi) {
360                syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
361                                  __func__, __LINE__);
362                return -1;
363        }
364
365        err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr);
366        if (err < 0) {
367                og_dbi_close(dbi);
368                return -1;
369        }
370
371        res = actualizaConfiguracion(dbi, cfg, computer.id);
372        og_dbi_close(dbi);
373
374        if (!res) {
375                syslog(LOG_ERR, "Problem updating client configuration\n");
376                return -1;
377        }
378
379        if (!cli->autorun && computer.procedure_id) {
380                cli->autorun = true;
381
382                if (og_dbi_queue_autorun(computer.id, computer.procedure_id))
383                        return -1;
384        }
385
386        return 0;
387}
388
389static int update_image_info(struct og_dbi *dbi, const char *image_id,
390                             const char *clonator, const char *compressor,
391                             const char *filesystem, const uint64_t datasize)
392{
393        const char *msglog;
394        dbi_result result;
395
396        result = dbi_conn_queryf(dbi->conn,
397                "UPDATE imagenes"
398                "   SET clonator='%s', compressor='%s',"
399                "       filesystem='%s', datasize=%lld"
400                " WHERE idimagen=%s", clonator, compressor, filesystem,
401                datasize, image_id);
402
403        if (!result) {
404                dbi_conn_error(dbi->conn, &msglog);
405                syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
406                       __func__, __LINE__, msglog);
407                return -1;
408        }
409        dbi_result_free(result);
410
411        return 0;
412}
413
414static int og_resp_image_create(json_t *data, struct og_client *cli)
415{
416        struct og_software_legacy soft_legacy;
417        struct og_image_legacy img_legacy;
418        struct og_computer computer = {};
419        const char *compressor = NULL;
420        const char *filesystem = NULL;
421        const char *partition = NULL;
422        const char *software = NULL;
423        const char *image_id = NULL;
424        const char *clonator = NULL;
425        const char *disk = NULL;
426        const char *code = NULL;
427        const char *name = NULL;
428        const char *repo = NULL;
429        uint64_t datasize = 0;
430        struct og_dbi *dbi;
431        const char *key;
432        json_t *value;
433        int err = 0;
434        bool res;
435
436        if (json_typeof(data) != JSON_OBJECT)
437                return -1;
438
439        json_object_foreach(data, key, value) {
440                if (!strcmp(key, "software"))
441                        err = og_json_parse_string(value, &software);
442                else if (!strcmp(key, "partition"))
443                        err = og_json_parse_string(value, &partition);
444                else if (!strcmp(key, "disk"))
445                        err = og_json_parse_string(value, &disk);
446                else if (!strcmp(key, "code"))
447                        err = og_json_parse_string(value, &code);
448                else if (!strcmp(key, "id"))
449                        err = og_json_parse_string(value, &image_id);
450                else if (!strcmp(key, "name"))
451                        err = og_json_parse_string(value, &name);
452                else if (!strcmp(key, "repository"))
453                        err = og_json_parse_string(value, &repo);
454                else if (!strcmp(key, "clonator"))
455                        err = og_json_parse_string(value, &clonator);
456                else if (!strcmp(key, "compressor"))
457                        err = og_json_parse_string(value, &compressor);
458                else if (!strcmp(key, "filesystem"))
459                        err = og_json_parse_string(value, &filesystem);
460                else if (!strcmp(key, "datasize"))
461                        err = og_json_parse_uint64(value, &datasize);
462
463                if (err < 0)
464                        return err;
465        }
466
467        if (!software || !partition || !disk || !code || !image_id || !name ||
468            !repo || !clonator || !compressor || !filesystem || !datasize) {
469                syslog(LOG_ERR, "malformed response json\n");
470                return -1;
471        }
472
473        dbi = og_dbi_open(&ogconfig.db);
474        if (!dbi) {
475                syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
476                       __func__, __LINE__);
477                return -1;
478        }
479
480        err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr);
481        if (err < 0) {
482                og_dbi_close(dbi);
483                return -1;
484        }
485
486        snprintf(soft_legacy.center, sizeof(soft_legacy.center), "%d",
487                 computer.center);
488        snprintf(soft_legacy.software, sizeof(soft_legacy.software), "%s",
489                 software);
490        snprintf(img_legacy.image_id, sizeof(img_legacy.image_id), "%s",
491                 image_id);
492        snprintf(soft_legacy.id, sizeof(soft_legacy.id), "%d", computer.id);
493        snprintf(img_legacy.part, sizeof(img_legacy.part), "%s", partition);
494        snprintf(img_legacy.disk, sizeof(img_legacy.disk), "%s", disk);
495        snprintf(img_legacy.code, sizeof(img_legacy.code), "%s", code);
496        snprintf(img_legacy.name, sizeof(img_legacy.name), "%s", name);
497        snprintf(img_legacy.repo, sizeof(img_legacy.repo), "%s", repo);
498
499        res = actualizaSoftware(dbi,
500                                soft_legacy.software,
501                                img_legacy.part,
502                                soft_legacy.id,
503                                computer.name,
504                                soft_legacy.center);
505        if (!res) {
506                og_dbi_close(dbi);
507                syslog(LOG_ERR, "Problem updating client configuration\n");
508                return -1;
509        }
510
511        res = actualizaCreacionImagen(dbi,
512                                      img_legacy.image_id,
513                                      img_legacy.disk,
514                                      img_legacy.part,
515                                      img_legacy.code,
516                                      img_legacy.repo,
517                                      soft_legacy.id);
518        if (!res) {
519                og_dbi_close(dbi);
520                syslog(LOG_ERR, "Problem updating client configuration\n");
521                return -1;
522        }
523
524        res = update_image_info(dbi, image_id, clonator, compressor,
525                                filesystem, datasize);
526        og_dbi_close(dbi);
527
528        if (res) {
529                syslog(LOG_ERR, "Problem updating image info\n");
530                return -1;
531        }
532
533        return 0;
534}
535
536static int og_resp_image_restore(json_t *data, struct og_client *cli)
537{
538        struct og_software_legacy soft_legacy;
539        struct og_image_legacy img_legacy;
540        struct og_computer computer = {};
541        const char *partition = NULL;
542        const char *image_id = NULL;
543        const char *disk = NULL;
544        dbi_result query_result;
545        struct og_dbi *dbi;
546        const char *key;
547        json_t *value;
548        int err = 0;
549        bool res;
550
551        if (json_typeof(data) != JSON_OBJECT)
552                return -1;
553
554        json_object_foreach(data, key, value) {
555                if (!strcmp(key, "partition"))
556                        err = og_json_parse_string(value, &partition);
557                else if (!strcmp(key, "disk"))
558                        err = og_json_parse_string(value, &disk);
559                else if (!strcmp(key, "image_id"))
560                        err = og_json_parse_string(value, &image_id);
561
562                if (err < 0)
563                        return err;
564        }
565
566        if (!partition || !disk || !image_id) {
567                syslog(LOG_ERR, "malformed response json\n");
568                return -1;
569        }
570
571        dbi = og_dbi_open(&ogconfig.db);
572        if (!dbi) {
573                syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
574                       __func__, __LINE__);
575                return -1;
576        }
577
578        query_result = dbi_conn_queryf(dbi->conn,
579                                       "SELECT idperfilsoft FROM imagenes "
580                                       " WHERE idimagen='%s'",
581                                       image_id);
582        if (!query_result) {
583                og_dbi_close(dbi);
584                syslog(LOG_ERR, "failed to query database\n");
585                return -1;
586        }
587        if (!dbi_result_next_row(query_result)) {
588                dbi_result_free(query_result);
589                og_dbi_close(dbi);
590                syslog(LOG_ERR, "software profile does not exist in database\n");
591                return -1;
592        }
593        snprintf(img_legacy.software_id, sizeof(img_legacy.software_id),
594                 "%d", dbi_result_get_uint(query_result, "idperfilsoft"));
595        dbi_result_free(query_result);
596
597        err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr);
598        if (err < 0) {
599                og_dbi_close(dbi);
600                return -1;
601        }
602
603        snprintf(img_legacy.image_id, sizeof(img_legacy.image_id), "%s",
604                 image_id);
605        snprintf(img_legacy.part, sizeof(img_legacy.part), "%s", partition);
606        snprintf(img_legacy.disk, sizeof(img_legacy.disk), "%s", disk);
607        snprintf(soft_legacy.id, sizeof(soft_legacy.id), "%d", computer.id);
608
609        res = actualizaRestauracionImagen(dbi,
610                                          img_legacy.image_id,
611                                          img_legacy.disk,
612                                          img_legacy.part,
613                                          soft_legacy.id,
614                                          img_legacy.software_id);
615        og_dbi_close(dbi);
616
617        if (!res) {
618                syslog(LOG_ERR, "Problem updating client configuration\n");
619                return -1;
620        }
621
622        return 0;
623}
624
625static int og_agent_http_response_code(const char *buf)
626{
627        if (!strncmp(buf, "HTTP/1.0 200 OK", strlen("HTTP/1.0 200 OK"))) {
628                return 200;
629        } else if (!strncmp(buf, "HTTP/1.0 202 Accepted",
630                            strlen("HTTP/1.0 202 Accepted"))) {
631                return 202;
632        } else if (!strncmp(buf, "HTTP/1.0 400 Bad Request",
633                            strlen("HTTP/1.0 400 Bad Request"))) {
634                return 400;
635        } else if (!strncmp(buf, "HTTP/1.0 500 Internal Server Error",
636                            strlen("HTTP/1.0 500 Internal Server Error"))) {
637                return 500;
638        } else if (!strncmp(buf, "HTTP/1.0 503 Service Unavailable",
639                            strlen("HTTP/1.0 503 Service Unavailable"))) {
640                return 503;
641        }
642
643        return -1;
644}
645
646int og_agent_state_process_response(struct og_client *cli)
647{
648        int ret, err = -1, code;
649        json_error_t json_err;
650        bool success;
651        json_t *root;
652        char *body;
653
654        code = og_agent_http_response_code(cli->buf);
655        switch (code) {
656        case 200:
657                ret = 0;
658                success = true;
659                break;
660        case 202:
661                ret = 1;
662                success = true;
663                break;
664        case 400:
665                ret = -1;
666                success = false;
667                syslog(LOG_ERR, "Client %s:%hu reports malformed HTTP request from server\n",
668                       inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
669                break;
670        case 500:
671                ret = 0;
672                success = false;
673                cli->last_cmd = OG_CMD_UNSPEC;
674                syslog(LOG_ERR, "Client %s:%hu reports failure to process command\n",
675                       inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
676                /* ... cancel pending actions related to this task for this client here */
677                break;
678        case 503:
679                ret = 1;
680                success = false;
681                syslog(LOG_ERR, "Client %s:%hu is busy to process command\n",
682                       inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
683                break;
684        default:
685                ret = -1;
686                success = false;
687                syslog(LOG_ERR, "Client %s:%hu reports unknown HTTP response code\n",
688                       inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
689                break;
690        }
691
692        if (code != 200) {
693                og_dbi_update_action(cli->last_cmd_id, success);
694                cli->last_cmd_id = 0;
695                return ret;
696        }
697
698        if (!cli->content_length) {
699                og_dbi_update_action(cli->last_cmd_id, true);
700                cli->last_cmd_id = 0;
701                cli->last_cmd = OG_CMD_UNSPEC;
702                return 0;
703        }
704
705        body = strstr(cli->buf, "\r\n\r\n") + 4;
706
707        root = json_loads(body, 0, &json_err);
708        if (!root) {
709                syslog(LOG_ERR, "%s:%d: malformed json line %d: %s\n",
710                       __FILE__, __LINE__, json_err.line, json_err.text);
711                return -1;
712        }
713
714        switch (cli->last_cmd) {
715        case OG_CMD_PROBE:
716                err = og_resp_probe(cli, root);
717                break;
718        case OG_CMD_SHELL_RUN:
719                err = og_resp_shell_run(cli, root);
720                break;
721        case OG_CMD_HARDWARE:
722                err = og_resp_hardware(root, cli);
723                break;
724        case OG_CMD_SOFTWARE:
725                err = og_resp_software(root, cli);
726                break;
727        case OG_CMD_REFRESH:
728                err = og_resp_refresh(root, cli);
729                break;
730        case OG_CMD_SETUP:
731                err = og_resp_refresh(root, cli);
732                break;
733        case OG_CMD_IMAGE_CREATE:
734                err = og_resp_image_create(root, cli);
735                break;
736        case OG_CMD_IMAGE_RESTORE:
737                err = og_resp_image_restore(root, cli);
738                break;
739        default:
740                err = -1;
741                break;
742        }
743
744        json_decref(root);
745
746        if (err < 0) {
747                err = 0;
748                success = false;
749                /* ... cancel pending actions related to this task for this client here */
750        }
751
752        og_dbi_update_action(cli->last_cmd_id, success);
753        cli->last_cmd_id = 0;
754        cli->last_cmd = OG_CMD_UNSPEC;
755
756        return err;
757}
Note: See TracBrowser for help on using the repository browser.