mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
+2
-1
@@ -5,7 +5,8 @@
|
||||
pihole-FTL
|
||||
|
||||
# Versioning files (generated by Makefile)
|
||||
version*
|
||||
version.h
|
||||
version~
|
||||
|
||||
# CMake files
|
||||
/cmake-build-debug/
|
||||
|
||||
@@ -17,7 +17,7 @@ DNSMASQ_OPTS = -DHAVE_DNSSEC -DHAVE_DNSSEC_STATIC -DHAVE_IDN
|
||||
FTL_DEPS = *.h database/*.h api/*.h version.h
|
||||
FTL_DB_OBJ = database/common.o database/query-table.o database/network-table.o database/gravity-db.o database/database-thread.o \
|
||||
database/sqlite3-ext.o database/message-table.o
|
||||
FTL_API_OBJ = api/http.o api/ftl.o api/stats.o api/dns.o
|
||||
FTL_API_OBJ = api/http.o api/ftl.o api/stats.o api/dns.o api/version.o
|
||||
FTL_OBJ = $(FTL_DB_OBJ) $(FTL_API_OBJ) main.o memory.o log.o daemon.o datastructure.o signals.o files.o setupVars.o args.o gc.o config.o dnsmasq_interface.o resolve.o regex.o shmem.o capabilities.o overTime.o timers.o vector.o
|
||||
|
||||
DNSMASQ_DEPS = config.h dhcp-protocol.h dns-protocol.h radv-protocol.h dhcp6-protocol.h dnsmasq.h ip6addr.h metrics.h ../dnsmasq_interface.h
|
||||
|
||||
@@ -128,4 +128,7 @@ extern pthread_t DBthread;
|
||||
extern pthread_t GCthread;
|
||||
extern pthread_t DNSclientthread;
|
||||
|
||||
// Intentionally ignore result of function declared warn_unused_result
|
||||
#define igr(x) {__typeof__(x) __attribute__((unused)) d=(x);}
|
||||
|
||||
#endif // FTL_H
|
||||
|
||||
@@ -41,4 +41,7 @@ int api_dns_blacklist(struct mg_connection *conn);
|
||||
int api_dns_blacklist_exact(struct mg_connection *conn);
|
||||
int api_dns_blacklist_regex(struct mg_connection *conn);
|
||||
|
||||
// Version method
|
||||
int api_version(struct mg_connection *conn);
|
||||
|
||||
#endif // API_H
|
||||
|
||||
@@ -156,6 +156,11 @@ static int api_handler(struct mg_connection *conn, void *ignored)
|
||||
{
|
||||
ret = api_stats_recentblocked(conn);
|
||||
}
|
||||
/******************************** api/version ****************************/
|
||||
else if(strcasecmp("/api/version", request->local_uri) == 0)
|
||||
{
|
||||
ret = api_version(conn);
|
||||
}
|
||||
/******************************** not found ******************************/
|
||||
/* else
|
||||
{
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* 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 "api.h"
|
||||
// get_FTL_version()
|
||||
#include "log.h"
|
||||
#include "version.h"
|
||||
|
||||
int api_version(struct mg_connection *conn)
|
||||
{
|
||||
cJSON *json = JSON_NEW_OBJ();
|
||||
|
||||
cJSON *api = JSON_NEW_OBJ();
|
||||
JSON_OBJ_REF_STR(api, "branch", "none");
|
||||
JSON_OBJ_REF_STR(api, "hash", "none");
|
||||
JSON_OBJ_REF_STR(api, "tag", "none");
|
||||
JSON_OBJ_ADD_ITEM(json, "api", api);
|
||||
|
||||
FILE* file;
|
||||
char coreversion[256] = "N/A";
|
||||
char 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";
|
||||
if((file = fopen("/etc/pihole/localbranches", "r")) != NULL)
|
||||
{
|
||||
igr(fscanf(file, "%255s %255s", corebranch, webbranch));
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
cJSON *ftl = JSON_NEW_OBJ();
|
||||
JSON_OBJ_REF_STR(ftl, "branch", GIT_BRANCH);
|
||||
JSON_OBJ_REF_STR(ftl, "hash", GIT_HASH);
|
||||
char *version = get_FTL_version();
|
||||
JSON_OBJ_COPY_STR(ftl, "tag", version);
|
||||
JSON_OBJ_ADD_ITEM(json, "ftl", ftl);
|
||||
free(version);
|
||||
|
||||
JSON_SENT_OBJECT(json);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ void log_FTL_version(const bool crashreport)
|
||||
}
|
||||
|
||||
static char *FTLversion = NULL;
|
||||
const char __attribute__ ((malloc)) *get_FTL_version(void)
|
||||
char __attribute__ ((malloc)) *get_FTL_version(void)
|
||||
{
|
||||
// Obtain FTL version if not already determined
|
||||
if(FTLversion == NULL)
|
||||
|
||||
@@ -17,7 +17,7 @@ void open_FTL_log(const bool test);
|
||||
void logg(const char* format, ...) __attribute__ ((format (gnu_printf, 1, 2)));
|
||||
void log_counter_info(void);
|
||||
void format_memory_size(char *prefix, unsigned long long int bytes, double *formated);
|
||||
const char *get_FTL_version(void) __attribute__ ((malloc));
|
||||
char *get_FTL_version(void) __attribute__ ((malloc));
|
||||
void log_FTL_version(bool crashreport);
|
||||
void get_timestr(char *timestring, const time_t timein);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user