Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Sep 20, 2024
1 parent 8ebe41b commit 3be9acc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions include/ntop_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#define ZMQ_FLAG_IS_COMPRESSED 2 << 1

#define LOGIN_URL "/lua/login.lua"
#define INDEX_URL "/lua/index.lua"
#define LOCALE_URL "/lua/locale.lua"
#define LOGOUT_URL "/lua/ntopng_logout.lua"
#define CAPTIVE_PORTAL_URL "/lua/captive_portal.lua"
Expand Down
14 changes: 11 additions & 3 deletions src/HTTPserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,11 +1502,19 @@ static int handle_lua_request(struct mg_connection *conn) {
* already used */
snprintf(path, sizeof(path), "%s/scripts/%s", ntop->get_scripts_dir(),
request_info->uri + 9);
else
else {
char* default_landing_page;

if(ntop->getPrefs()->getHttpIndexPage())
default_landing_page = ntop->getPrefs()->getHttpIndexPage();
else
default_landing_page = (char*)INDEX_URL;

snprintf(path, sizeof(path), "%s%s%s", httpserver->get_scripts_dir(),
Utils::getURL(len == 1 ? (char *)ntop->getPrefs()->getHttpIndexPage() : request_info->uri, uri, sizeof(uri)),
Utils::getURL(len == 1 ? default_landing_page : request_info->uri, uri, sizeof(uri)),
len > 1 && request_info->uri[len - 1] == '/' ? (char *)"index.lua" : (char *)"");

}

if (strlen(path) > 4 && strncmp(&path[strlen(path) - 4], ".lua", 4))
snprintf(&path[strlen(path)], sizeof(path) - strlen(path) - 1, "%s",
(char *)".lua");
Expand Down
39 changes: 19 additions & 20 deletions src/Prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Prefs::Prefs(Ntop *_ntop) {
config_file_path = ndpi_proto_path = NULL;
http_port = CONST_DEFAULT_NTOP_PORT;
http_prefix = strdup("");
http_index_page = strdup("/lua/index.lua");
http_index_page = strdup(INDEX_URL);
instance_name = NULL;
categorization_enabled = false, enable_users_login = true;
categorization_key = NULL, zmq_encryption_pwd = NULL;
Expand Down Expand Up @@ -888,10 +888,11 @@ static TsDriver str2TsDriver(const char *driver) {

void Prefs::reloadPrefsFromRedis() {
char *aux = NULL;
// sets to the default value in redis if no key is found
char *tmp = NULL;

// sets to the default value in redis if no key is found
#ifdef PREFS_RELOAD_DEBUG
ntop->getTrace()->traceEvent(TRACE_DEBUG,
"A preference has changed, reloading...");
ntop->getTrace()->traceEvent(TRACE_DEBUG, "A preference has changed, reloading...");
#endif

enable_auto_logout_at_runtime = getDefaultPrefsValue(
Expand Down Expand Up @@ -1028,26 +1029,24 @@ void Prefs::reloadPrefsFromRedis() {
if(message_broker_url) free(message_broker_url);
message_broker_url = aux;

char *tmp = NULL;
getDefaultStringPrefsValue(CONST_PREFS_MESSAGE_BROKER, &tmp, DEFAULT_MESSAGE_BROKER);
if (message_broker) free(message_broker);
message_broker = tmp;
char *tmp2 = NULL;
getDefaultStringPrefsValue(CONST_PREFS_HTTP_INDEX_PAGE, &tmp2, DEFAULT_HTTP_INDEX_PAGE);

getDefaultStringPrefsValue(CONST_PREFS_HTTP_INDEX_PAGE, &tmp, DEFAULT_HTTP_INDEX_PAGE);
if (http_index_page) free(http_index_page);
http_index_page = tmp2;


global_dns_forging_enabled =
getDefaultBoolPrefsValue(CONST_PREFS_GLOBAL_DNS_FORGING_ENABLED, false);
enable_client_x509_auth =
getDefaultBoolPrefsValue(CONST_PREFS_CLIENT_X509_AUTH, false);
emit_flow_alerts =
getDefaultBoolPrefsValue(CONST_PREFS_EMIT_FLOW_ALERTS, true);
emit_host_alerts =
getDefaultBoolPrefsValue(CONST_PREFS_EMIT_HOST_ALERTS, true);
tls_quic_hostnaming =
getDefaultBoolPrefsValue(CONST_PREFS_TLS_QUIC_HOSTNAMING, false);

if(tmp[0] == '\0') {
free(tmp);
tmp = strdup(INDEX_URL);
}
http_index_page = tmp;

global_dns_forging_enabled = getDefaultBoolPrefsValue(CONST_PREFS_GLOBAL_DNS_FORGING_ENABLED, false);
enable_client_x509_auth = getDefaultBoolPrefsValue(CONST_PREFS_CLIENT_X509_AUTH, false);
emit_flow_alerts = getDefaultBoolPrefsValue(CONST_PREFS_EMIT_FLOW_ALERTS, true);
emit_host_alerts = getDefaultBoolPrefsValue(CONST_PREFS_EMIT_HOST_ALERTS, true);
tls_quic_hostnaming = getDefaultBoolPrefsValue(CONST_PREFS_TLS_QUIC_HOSTNAMING, false);

/* Used for stats */
collect_blacklist_stats = getDefaultBoolPrefsValue(CONST_PREFS_COLLECT_BLACKLISTSTATS, false);
Expand Down

0 comments on commit 3be9acc

Please sign in to comment.