Improve /api/version endpoint.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2020-06-17 19:20:06 +02:00
parent 822f8c6a28
commit b5e965e248
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
1 changed files with 8 additions and 9 deletions

View File

@ -21,40 +21,39 @@ int api_version(struct mg_connection *conn)
cJSON *json = JSON_NEW_OBJ();
FILE* file;
char coreversion[256] = "N/A";
char webversion[256] = "N/A";
char coreversion[256] = "N/A", webversion[256] = "N/A";
if((file = fopen("/etc/pihole/localversions", "r")) != NULL)
{
igr(fscanf(file, "%255s %255s", coreversion, webversion));
fclose(file);
}
char corebranch[256] = "N/A";
char webbranch[256] = "N/A";
char corebranch[256] = "N/A", webbranch[256] = "N/A";
if((file = fopen("/etc/pihole/localbranches", "r")) != NULL)
{
igr(fscanf(file, "%255s %255s", corebranch, webbranch));
fclose(file);
}
// Build web object
cJSON *web = JSON_NEW_OBJ();
JSON_OBJ_REF_STR(web, "branch", webbranch);
JSON_OBJ_REF_STR(web, "hash", "none");
JSON_OBJ_REF_STR(web, "tag", webversion);
JSON_OBJ_ADD_ITEM(json, "web", web);
// Build core object
cJSON *core = JSON_NEW_OBJ();
JSON_OBJ_REF_STR(core, "branch", corebranch);
JSON_OBJ_REF_STR(core, "hash", "none");
JSON_OBJ_REF_STR(core, "tag", coreversion);
JSON_OBJ_ADD_ITEM(json, "core", core);
// Build ftl object
cJSON *ftl = JSON_NEW_OBJ();
JSON_OBJ_REF_STR(ftl, "branch", GIT_BRANCH);
JSON_OBJ_REF_STR(ftl, "hash", GIT_HASH);
JSON_OBJ_REF_STR(ftl, "date", GIT_DATE);
char *version = get_FTL_version();
const char *version = get_FTL_version();
JSON_OBJ_REF_STR(ftl, "tag", version);
JSON_OBJ_REF_STR(ftl, "date", GIT_DATE);
JSON_OBJ_ADD_ITEM(json, "ftl", ftl);
// Send reply
JSON_SEND_OBJECT(json);
}