diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 1aaf6008..124d98e5 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -13,16 +13,15 @@ set(sources api.c auth.c dns.c - ftl.c config.c network.c history.c + info.c list.c logs.c queries.c stats_database.c stats.c - version.c ) add_library(api OBJECT ${sources}) diff --git a/src/api/api.c b/src/api/api.c index 08c10c2a..d037d174 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -40,9 +40,10 @@ static struct { { "/api/domains", "/{type}/{kind}/{domain}", api_list, { false, 0 }, true, HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_DELETE }, { "/api/groups", "/{name}", api_list, { false, 0 }, true, HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_DELETE }, { "/api/lists", "/{list}", api_list, { false, 0 }, true, HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_DELETE }, - { "/api/ftl/client", "", api_ftl_client, { false, 0 }, false, HTTP_GET }, - { "/api/ftl/sysinfo", "", api_ftl_sysinfo, { false, 0 }, true, HTTP_GET }, - { "/api/ftl/dbinfo", "", api_ftl_dbinfo, { false, 0 }, true, HTTP_GET }, + { "/api/info/client", "", api_info_client, { false, 0 }, false, HTTP_GET }, + { "/api/info/system", "", api_info_system, { false, 0 }, true, HTTP_GET }, + { "/api/info/database", "", api_info_database, { false, 0 }, true, HTTP_GET }, + { "/api/info/version", "", api_info_version, { false, 0 }, true, HTTP_GET }, { "/api/logs/dnsmasq", "", api_logs, { false, FIFO_DNSMASQ }, true, HTTP_GET }, { "/api/logs/ftl", "", api_logs, { false, FIFO_FTL }, true, HTTP_GET }, { "/api/logs/http", "", api_logs, { false, FIFO_CIVETWEB }, true, HTTP_GET }, @@ -64,7 +65,6 @@ static struct { { "/api/stats/database/summary", "", api_stats_database_summary, { false, 0 }, true, HTTP_GET }, { "/api/stats/database/query_types", "", api_stats_database_query_types, { false, 0 }, true, HTTP_GET }, { "/api/stats/database/upstreams", "", api_stats_database_upstreams, { false, 0 }, true, HTTP_GET }, - { "/api/version", "", api_version, { false, 0 }, true, HTTP_GET }, { "/api/auth", "", api_auth, { false, 0 }, false, HTTP_GET | HTTP_POST | HTTP_DELETE }, { "/api/config/_topics", "", api_config_topics, { false, 0 }, true, HTTP_GET }, { "/api/config", "", api_config, { false, 0 }, true, HTTP_GET | HTTP_PATCH }, diff --git a/src/api/api.h b/src/api/api.h index 3fb5e982..942702f6 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -45,12 +45,11 @@ int api_stats_database_summary(struct ftl_conn *api); int api_stats_database_query_types(struct ftl_conn *api); int api_stats_database_upstreams(struct ftl_conn *api); -// FTL methods -int api_ftl_client(struct ftl_conn *api); -int api_ftl_dbinfo(struct ftl_conn *api); -int api_ftl_sysinfo(struct ftl_conn *api); -int get_ftl_obj(struct ftl_conn *api, cJSON *ftl, const bool is_locked); -int get_system_obj(struct ftl_conn *api, cJSON *system); +// Info methods +int api_info_client(struct ftl_conn *api); +int api_info_database(struct ftl_conn *api); +int api_info_system(struct ftl_conn *api); +int api_info_version(struct ftl_conn *api); // Config methods int api_config(struct ftl_conn *api); @@ -72,9 +71,6 @@ int api_dns_cache(struct ftl_conn *api); int api_list(struct ftl_conn *api); int api_group(struct ftl_conn *api); -// Version method -int api_version(struct ftl_conn *api); - // Auth method int check_client_auth(struct ftl_conn *api); int api_auth(struct ftl_conn *api); diff --git a/src/api/docs/content/specs/ftl.yaml b/src/api/docs/content/specs/info.yaml similarity index 71% rename from src/api/docs/content/specs/ftl.yaml rename to src/api/docs/content/specs/info.yaml index 28062f07..c153f6c3 100644 --- a/src/api/docs/content/specs/ftl.yaml +++ b/src/api/docs/content/specs/info.yaml @@ -17,10 +17,10 @@ components: application/json: schema: allOf: - - $ref: 'ftl.yaml#/components/schemas/client/remote_addr' - - $ref: 'ftl.yaml#/components/schemas/client/http_version' - - $ref: 'ftl.yaml#/components/schemas/client/method' - - $ref: 'ftl.yaml#/components/schemas/client/headers' + - $ref: 'info.yaml#/components/schemas/client/remote_addr' + - $ref: 'info.yaml#/components/schemas/client/http_version' + - $ref: 'info.yaml#/components/schemas/client/method' + - $ref: 'info.yaml#/components/schemas/client/headers' logs: dns: get: @@ -37,7 +37,7 @@ components: The expected behavior for an immediate re-request of a log line with the same ID is an empty response. As soon as the next message arrived, this will be included in your request and `nextID` is incremented by one. parameters: - - $ref: 'ftl.yaml#/components/parameters/logs/dns/nextID' + - $ref: 'info.yaml#/components/parameters/logs/dns/nextID' responses: '200': description: OK @@ -45,15 +45,15 @@ components: application/json: schema: allOf: - - $ref: 'ftl.yaml#/components/schemas/logs/dns/log' - - $ref: 'ftl.yaml#/components/schemas/logs/dns/nextID' + - $ref: 'info.yaml#/components/schemas/logs/dns/log' + - $ref: 'info.yaml#/components/schemas/logs/dns/nextID' '401': description: Unauthorized content: application/json: schema: $ref: 'common.yaml#/components/errors/unauthorized' - sysinfo: + system: get: summary: Get info about various system parameters tags: @@ -68,15 +68,15 @@ components: application/json: schema: allOf: - - $ref: 'ftl.yaml#/components/schemas/system' - - $ref: 'ftl.yaml#/components/schemas/ftl' + - $ref: 'info.yaml#/components/schemas/system' + - $ref: 'info.yaml#/components/schemas/ftl' '401': description: Unauthorized content: application/json: schema: $ref: 'common.yaml#/components/errors/unauthorized' - dbinfo: + database: get: summary: Get info about long-term database tags: @@ -91,7 +91,22 @@ components: application/json: schema: allOf: - - $ref: 'ftl.yaml#/components/schemas/database' + - $ref: 'info.yaml#/components/schemas/database' + version: + get: + summary: Get Pi-hole version + tags: + - "FTL information" + operationId: "get_version" + description: | + Request versions of the individual Pi-hole components + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'info.yaml#/components/schemas/version' schemas: client: remote_addr: @@ -439,6 +454,133 @@ components: type: string description: Version of embedded SQLite3 engine example: "3.34.0" + version: + type: object + properties: + version: + type: object + properties: + core: + type: object + properties: + local: + type: object + properties: + branch: + type: string + nullable: true + description: Local Pi-hole Core branch + example: "development" + version: + type: string + nullable: true + description: Local Pi-hole Core version + example: "v6.1" + hash: + type: string + nullable: true + description: Local Pi-hole Core hash + example: "955e36a9" + remote: + type: object + properties: + version: + type: string + nullable: true + description: Remote (Github) Pi-hole Core version + example: "v6.1" + hash: + type: string + nullable: true + description: Remote (Github) Pi-hole Core hash + example: "955e36a9" + web: + type: object + properties: + local: + type: object + properties: + branch: + type: string + nullable: true + description: Local Pi-hole Web branch + example: "devel" + version: + type: string + nullable: true + description: Local Pi-hole Web version + example: "v6.1" + hash: + type: string + nullable: true + description: Local Pi-hole Web hash + example: "f69f7e88" + remote: + type: object + properties: + version: + type: string + nullable: true + description: Remote (Github) Pi-hole Web version + example: "v6.1" + hash: + type: string + nullable: true + description: Remote (Github) Pi-hole Web hash + example: "f69f7e88" + ftl: + type: object + properties: + local: + type: object + properties: + branch: + type: string + nullable: true + description: Local Pi-hole FTL branch + example: "development" + version: + type: string + nullable: true + description: Local Pi-hole FTL version + example: "v6.1" + hash: + type: string + nullable: true + description: Local Pi-hole FTL hash + example: "64441ed6-dirty" + date: + type: string + nullable: true + description: Build time of your local Pi-hole FTL + example: "2023-01-09 20:25:24 +0100" + remote: + type: object + properties: + version: + type: string + nullable: true + description: Remote (Github) Pi-hole FTL version + example: "v6.1" + hash: + type: string + nullable: true + description: Remote (Github) Pi-hole FTL hash + example: "64441ed6" + docker: + type: object + properties: + local: + type: string + nullable: true + description: Local Pi-hole Docker image version (`null` if not running in Docker) + example: "v6.1" + remote: + type: string + nullable: true + description: Remote (Docker Hub) Pi-hole Docker image version (`null` if not running in Docker) + example: "v6.1" + parameters: logs: diff --git a/src/api/docs/content/specs/main.yaml b/src/api/docs/content/specs/main.yaml index d058f5c1..23be5939 100644 --- a/src/api/docs/content/specs/main.yaml +++ b/src/api/docs/content/specs/main.yaml @@ -134,14 +134,17 @@ paths: /lists: $ref: 'lists.yaml#/components/paths/direct' - /ftl/client: - $ref: 'ftl.yaml#/components/paths/client' + /info/client: + $ref: 'info.yaml#/components/paths/client' - /ftl/sysinfo: - $ref: 'ftl.yaml#/components/paths/sysinfo' + /info/system: + $ref: 'info.yaml#/components/paths/system' - /ftl/dbinfo: - $ref: 'ftl.yaml#/components/paths/dbinfo' + /info/database: + $ref: 'info.yaml#/components/paths/database' + + /info/version: + $ref: 'info.yaml#/components/paths/version' /logs/dnsmasq: $ref: 'logs.yaml#/components/paths/logs/dnsmasq' @@ -179,9 +182,6 @@ paths: /network/interfaces: $ref: 'network.yaml#/components/paths/interfaces' - /version: - $ref: 'version.yaml#/components/paths/version' - components: securitySchemes: sidHeader: diff --git a/src/api/docs/content/specs/version.yaml b/src/api/docs/content/specs/version.yaml deleted file mode 100644 index 3fdbd557..00000000 --- a/src/api/docs/content/specs/version.yaml +++ /dev/null @@ -1,146 +0,0 @@ -openapi: 3.0.2 -components: - paths: - version: - get: - summary: Get Pi-hole version - tags: - - "FTL information" - operationId: "get_version" - description: | - Request versions of the individual Pi-hole components - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: 'version.yaml#/components/schemas/version' - - schemas: - version: - type: object - properties: - version: - type: object - properties: - core: - type: object - properties: - local: - type: object - properties: - branch: - type: string - nullable: true - description: Local Pi-hole Core branch - example: "development" - version: - type: string - nullable: true - description: Local Pi-hole Core version - example: "v6.1" - hash: - type: string - nullable: true - description: Local Pi-hole Core hash - example: "955e36a9" - remote: - type: object - properties: - version: - type: string - nullable: true - description: Remote (Github) Pi-hole Core version - example: "v6.1" - hash: - type: string - nullable: true - description: Remote (Github) Pi-hole Core hash - example: "955e36a9" - web: - type: object - properties: - local: - type: object - properties: - branch: - type: string - nullable: true - description: Local Pi-hole Web branch - example: "devel" - version: - type: string - nullable: true - description: Local Pi-hole Web version - example: "v6.1" - hash: - type: string - nullable: true - description: Local Pi-hole Web hash - example: "f69f7e88" - remote: - type: object - properties: - version: - type: string - nullable: true - description: Remote (Github) Pi-hole Web version - example: "v6.1" - hash: - type: string - nullable: true - description: Remote (Github) Pi-hole Web hash - example: "f69f7e88" - ftl: - type: object - properties: - local: - type: object - properties: - branch: - type: string - nullable: true - description: Local Pi-hole FTL branch - example: "development" - version: - type: string - nullable: true - description: Local Pi-hole FTL version - example: "v6.1" - hash: - type: string - nullable: true - description: Local Pi-hole FTL hash - example: "64441ed6-dirty" - date: - type: string - nullable: true - description: Build time of your local Pi-hole FTL - example: "2023-01-09 20:25:24 +0100" - remote: - type: object - properties: - version: - type: string - nullable: true - description: Remote (Github) Pi-hole FTL version - example: "v6.1" - hash: - type: string - nullable: true - description: Remote (Github) Pi-hole FTL hash - example: "64441ed6" - docker: - type: object - properties: - local: - type: string - nullable: true - description: Local Pi-hole Docker image version (`null` if not running in Docker) - example: "v6.1" - remote: - type: string - nullable: true - description: Remote (Docker Hub) Pi-hole Docker image version (`null` if not running in Docker) - example: "v6.1" diff --git a/src/api/ftl.c b/src/api/info.c similarity index 73% rename from src/api/ftl.c rename to src/api/info.c index 75ecb2e4..651cd224 100644 --- a/src/api/ftl.c +++ b/src/api/info.c @@ -37,7 +37,15 @@ // getProcessMemory() #include "procps.h" -int api_ftl_client(struct ftl_conn *api) +// get_FTL_version() +#include "log.h" +#include "version.h" +// prase_line() +#include "files.h" + +#define VERSIONS_FILE "/etc/pihole/versions" + +int api_info_client(struct ftl_conn *api) { cJSON *json = JSON_NEW_OBJECT(); // Add client's IP address @@ -64,7 +72,7 @@ int api_ftl_client(struct ftl_conn *api) JSON_SEND_OBJECT(json); } -int api_ftl_dbinfo(struct ftl_conn *api) +int api_info_database(struct ftl_conn *api) { cJSON *json = JSON_NEW_OBJECT(); @@ -198,7 +206,7 @@ static int read_temp_sensor(struct ftl_conn *api, return 0; } -int get_system_obj(struct ftl_conn *api, cJSON *system) +static int get_system_obj(struct ftl_conn *api, cJSON *system) { const int nprocs = get_nprocs(); struct sysinfo info; @@ -347,7 +355,7 @@ int get_system_obj(struct ftl_conn *api, cJSON *system) return 0; } -int get_ftl_obj(struct ftl_conn *api, cJSON *ftl, const bool is_locked) +static int get_ftl_obj(struct ftl_conn *api, cJSON *ftl, const bool is_locked) { cJSON *database = JSON_NEW_OBJECT(); @@ -408,7 +416,7 @@ int get_ftl_obj(struct ftl_conn *api, cJSON *ftl, const bool is_locked) return 0; } -int api_ftl_sysinfo(struct ftl_conn *api) +int api_info_system(struct ftl_conn *api) { cJSON *json = JSON_NEW_OBJECT(); @@ -429,3 +437,120 @@ int api_ftl_sysinfo(struct ftl_conn *api) JSON_ADD_ITEM_TO_OBJECT(json, "ftl", ftl); JSON_SEND_OBJECT(json); } + +int api_info_version(struct ftl_conn *api) +{ + char *line = NULL; + size_t len = 0; + ssize_t read; + char *key, *value; + cJSON *core_local = JSON_NEW_OBJECT(); + cJSON *web_local = JSON_NEW_OBJECT(); + cJSON *ftl_local = JSON_NEW_OBJECT(); + cJSON *core_remote = JSON_NEW_OBJECT(); + cJSON *web_remote = JSON_NEW_OBJECT(); + cJSON *ftl_remote = JSON_NEW_OBJECT(); + cJSON *docker = JSON_NEW_OBJECT(); + + FILE *fp = fopen(VERSIONS_FILE, "r"); + if(!fp) + return send_json_error(api, 500, + "internal_error", + "Failed to read " VERSIONS_FILE, + NULL); + + // Loop over KEY=VALUE parts in the versions file + while((read = getline(&line, &len, fp)) != -1) + { + if (parse_line(line, &key, &value)) + continue; + + if(strcmp(key, "CORE_BRANCH") == 0) + JSON_COPY_STR_TO_OBJECT(core_local, "branch", value); + else if(strcmp(key, "WEB_BRANCH") == 0) + JSON_COPY_STR_TO_OBJECT(web_local, "branch", value); + // Added below from the running FTL binary itself + //else if(strcmp(key, "FTL_BRANCH") == 0) + // JSON_COPY_STR_TO_OBJECT(ftl_local, "branch", value); + else if(strcmp(key, "CORE_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(core_local, "version", value); + else if(strcmp(key, "WEB_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(web_local, "version", value); + // Added below from the running FTL binary itself + //else if(strcmp(key, "FTL_VERSION") == 0) + // JSON_COPY_STR_TO_OBJECT(ftl_local, "version", value); + else if(strcmp(key, "GITHUB_CORE_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(core_remote, "version", value); + else if(strcmp(key, "GITHUB_WEB_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(web_remote, "version", value); + else if(strcmp(key, "GITHUB_FTL_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(ftl_remote, "version", value); + else if(strcmp(key, "CORE_HASH") == 0) + JSON_COPY_STR_TO_OBJECT(core_local, "hash", value); + else if(strcmp(key, "WEB_HASH") == 0) + JSON_COPY_STR_TO_OBJECT(web_local, "hash", value); + else if(strcmp(key, "FTL_HASH") == 0) + JSON_COPY_STR_TO_OBJECT(ftl_local, "hash", value); + else if(strcmp(key, "GITHUB_CORE_HASH") == 0) + JSON_COPY_STR_TO_OBJECT(core_remote, "hash", value); + else if(strcmp(key, "GITHUB_WEB_HASH") == 0) + JSON_COPY_STR_TO_OBJECT(web_remote, "hash", value); + else if(strcmp(key, "GITHUB_FTL_HASH") == 0) + JSON_COPY_STR_TO_OBJECT(ftl_remote, "hash", value); + else if(strcmp(key, "DOCKER_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(docker, "local", value); + else if(strcmp(key, "GITHUB_DOCKER_VERSION") == 0) + JSON_COPY_STR_TO_OBJECT(docker, "remote", value); + } + + // Free allocated memory and release file pointer + free(line); + fclose(fp); + + // Add remaining properties to ftl object + JSON_REF_STR_IN_OBJECT(ftl_local, "branch", GIT_BRANCH); + JSON_REF_STR_IN_OBJECT(ftl_local, "version", get_FTL_version()); + JSON_REF_STR_IN_OBJECT(ftl_local, "date", GIT_DATE); + + cJSON *version = JSON_NEW_OBJECT(); + + cJSON *core = JSON_NEW_OBJECT(); + JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "branch"); + JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "version"); + JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "hash"); + JSON_ADD_ITEM_TO_OBJECT(core, "local", core_local); + JSON_ADD_NULL_IF_NOT_EXISTS(core_remote, "version"); + JSON_ADD_NULL_IF_NOT_EXISTS(core_remote, "hash"); + JSON_ADD_ITEM_TO_OBJECT(core, "remote", core_remote); + JSON_ADD_ITEM_TO_OBJECT(version, "core", core); + + cJSON *web = JSON_NEW_OBJECT(); + JSON_ADD_NULL_IF_NOT_EXISTS(web_local, "branch"); + JSON_ADD_NULL_IF_NOT_EXISTS(web_local, "version"); + JSON_ADD_NULL_IF_NOT_EXISTS(web_local, "hash"); + JSON_ADD_ITEM_TO_OBJECT(web, "local", web_local); + JSON_ADD_NULL_IF_NOT_EXISTS(web_remote, "version"); + JSON_ADD_NULL_IF_NOT_EXISTS(web_remote, "hash"); + JSON_ADD_ITEM_TO_OBJECT(web, "remote", web_remote); + JSON_ADD_ITEM_TO_OBJECT(version, "web", web); + + cJSON *ftl = JSON_NEW_OBJECT(); + JSON_ADD_ITEM_TO_OBJECT(ftl, "local", ftl_local); + JSON_ADD_NULL_IF_NOT_EXISTS(ftl_local, "branch"); + JSON_ADD_NULL_IF_NOT_EXISTS(ftl_local, "version"); + JSON_ADD_NULL_IF_NOT_EXISTS(ftl_local, "hash"); + JSON_ADD_ITEM_TO_OBJECT(ftl, "remote", ftl_remote); + JSON_ADD_NULL_IF_NOT_EXISTS(ftl_remote, "version"); + JSON_ADD_NULL_IF_NOT_EXISTS(ftl_remote, "hash"); + JSON_ADD_ITEM_TO_OBJECT(version, "ftl", ftl); + + // Add nulls to docker if we didn't find any version + JSON_ADD_NULL_IF_NOT_EXISTS(docker, "local"); + JSON_ADD_NULL_IF_NOT_EXISTS(docker, "remote"); + JSON_ADD_ITEM_TO_OBJECT(version, "docker", docker); + + // Send reply + cJSON *json = JSON_NEW_OBJECT(); + JSON_ADD_ITEM_TO_OBJECT(json, "version", version); + JSON_SEND_OBJECT(json); +} diff --git a/src/api/version.c b/src/api/version.c deleted file mode 100644 index 726bae8f..00000000 --- a/src/api/version.c +++ /dev/null @@ -1,138 +0,0 @@ -/* Pi-hole: A black hole for Internet advertisements -* (c) 2019 Pi-hole, LLC (https://pi-hole.net) -* Network-wide ad blocking via your own hardware. -* -* FTL Engine -* API Implementation /api/version -* -* This file is copyright under the latest version of the EUPL. -* Please see LICENSE file for your rights under this license. */ - -#include "FTL.h" -#include "webserver/http-common.h" -#include "webserver/json_macros.h" -#include "api.h" -// get_FTL_version() -#include "log.h" -#include "version.h" -// prase_line() -#include "files.h" - -#define VERSIONS_FILE "/etc/pihole/versions" - -int api_version(struct ftl_conn *api) -{ - char *line = NULL; - size_t len = 0; - ssize_t read; - char *key, *value; - cJSON *core_local = JSON_NEW_OBJECT(); - cJSON *web_local = JSON_NEW_OBJECT(); - cJSON *ftl_local = JSON_NEW_OBJECT(); - cJSON *core_remote = JSON_NEW_OBJECT(); - cJSON *web_remote = JSON_NEW_OBJECT(); - cJSON *ftl_remote = JSON_NEW_OBJECT(); - cJSON *docker = JSON_NEW_OBJECT(); - - FILE *fp = fopen(VERSIONS_FILE, "r"); - if(!fp) - return send_json_error(api, 500, - "internal_error", - "Failed to read " VERSIONS_FILE, - NULL); - - // Loop over KEY=VALUE parts in the versions file - while((read = getline(&line, &len, fp)) != -1) - { - if (parse_line(line, &key, &value)) - continue; - - if(strcmp(key, "CORE_BRANCH") == 0) - JSON_COPY_STR_TO_OBJECT(core_local, "branch", value); - else if(strcmp(key, "WEB_BRANCH") == 0) - JSON_COPY_STR_TO_OBJECT(web_local, "branch", value); - // Added below from the running FTL binary itself - //else if(strcmp(key, "FTL_BRANCH") == 0) - // JSON_COPY_STR_TO_OBJECT(ftl_local, "branch", value); - else if(strcmp(key, "CORE_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(core_local, "version", value); - else if(strcmp(key, "WEB_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(web_local, "version", value); - // Added below from the running FTL binary itself - //else if(strcmp(key, "FTL_VERSION") == 0) - // JSON_COPY_STR_TO_OBJECT(ftl_local, "version", value); - else if(strcmp(key, "GITHUB_CORE_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(core_remote, "version", value); - else if(strcmp(key, "GITHUB_WEB_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(web_remote, "version", value); - else if(strcmp(key, "GITHUB_FTL_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(ftl_remote, "version", value); - else if(strcmp(key, "CORE_HASH") == 0) - JSON_COPY_STR_TO_OBJECT(core_local, "hash", value); - else if(strcmp(key, "WEB_HASH") == 0) - JSON_COPY_STR_TO_OBJECT(web_local, "hash", value); - else if(strcmp(key, "FTL_HASH") == 0) - JSON_COPY_STR_TO_OBJECT(ftl_local, "hash", value); - else if(strcmp(key, "GITHUB_CORE_HASH") == 0) - JSON_COPY_STR_TO_OBJECT(core_remote, "hash", value); - else if(strcmp(key, "GITHUB_WEB_HASH") == 0) - JSON_COPY_STR_TO_OBJECT(web_remote, "hash", value); - else if(strcmp(key, "GITHUB_FTL_HASH") == 0) - JSON_COPY_STR_TO_OBJECT(ftl_remote, "hash", value); - else if(strcmp(key, "DOCKER_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(docker, "local", value); - else if(strcmp(key, "GITHUB_DOCKER_VERSION") == 0) - JSON_COPY_STR_TO_OBJECT(docker, "remote", value); - } - - // Free allocated memory and release file pointer - free(line); - fclose(fp); - - // Add remaining properties to ftl object - JSON_REF_STR_IN_OBJECT(ftl_local, "branch", GIT_BRANCH); - JSON_REF_STR_IN_OBJECT(ftl_local, "version", get_FTL_version()); - JSON_REF_STR_IN_OBJECT(ftl_local, "date", GIT_DATE); - - cJSON *version = JSON_NEW_OBJECT(); - - cJSON *core = JSON_NEW_OBJECT(); - JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "branch"); - JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "version"); - JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "hash"); - JSON_ADD_ITEM_TO_OBJECT(core, "local", core_local); - JSON_ADD_NULL_IF_NOT_EXISTS(core_remote, "version"); - JSON_ADD_NULL_IF_NOT_EXISTS(core_remote, "hash"); - JSON_ADD_ITEM_TO_OBJECT(core, "remote", core_remote); - JSON_ADD_ITEM_TO_OBJECT(version, "core", core); - - cJSON *web = JSON_NEW_OBJECT(); - JSON_ADD_NULL_IF_NOT_EXISTS(web_local, "branch"); - JSON_ADD_NULL_IF_NOT_EXISTS(web_local, "version"); - JSON_ADD_NULL_IF_NOT_EXISTS(web_local, "hash"); - JSON_ADD_ITEM_TO_OBJECT(web, "local", web_local); - JSON_ADD_NULL_IF_NOT_EXISTS(web_remote, "version"); - JSON_ADD_NULL_IF_NOT_EXISTS(web_remote, "hash"); - JSON_ADD_ITEM_TO_OBJECT(web, "remote", web_remote); - JSON_ADD_ITEM_TO_OBJECT(version, "web", web); - - cJSON *ftl = JSON_NEW_OBJECT(); - JSON_ADD_ITEM_TO_OBJECT(ftl, "local", ftl_local); - JSON_ADD_NULL_IF_NOT_EXISTS(ftl_local, "branch"); - JSON_ADD_NULL_IF_NOT_EXISTS(ftl_local, "version"); - JSON_ADD_NULL_IF_NOT_EXISTS(ftl_local, "hash"); - JSON_ADD_ITEM_TO_OBJECT(ftl, "remote", ftl_remote); - JSON_ADD_NULL_IF_NOT_EXISTS(ftl_remote, "version"); - JSON_ADD_NULL_IF_NOT_EXISTS(ftl_remote, "hash"); - JSON_ADD_ITEM_TO_OBJECT(version, "ftl", ftl); - - // Add nulls to docker if we didn't find any version - JSON_ADD_NULL_IF_NOT_EXISTS(docker, "local"); - JSON_ADD_NULL_IF_NOT_EXISTS(docker, "remote"); - JSON_ADD_ITEM_TO_OBJECT(version, "docker", docker); - - // Send reply - cJSON *json = JSON_NEW_OBJECT(); - JSON_ADD_ITEM_TO_OBJECT(json, "version", version); - JSON_SEND_OBJECT(json); -} \ No newline at end of file