mirror of
https://github.com/netdata/netdata.git
synced 2025-05-06 02:00:18 +00:00

* SSL implementation for Netdata * Upload of fixes asked by @paulkatsoulakis and @cakrit * Fix local computer * Adding openssl to webserver * fixing.. * HTTPS almost there * Codacity * HTTPS day 3 * HTTPS without Bio step 1 * HTTPS without Bio step 2 * HTTPS without Bio step 3 * HTTPS without Bio step 4 * HTTPS without Bio step 5 * HTTPS without Bio step 6 * HTTPS without Bio step 7 * HTTPS without Bio step 8 * HTTPS without Bio step 9 * HTTPS without Bio step 10 * SSL on streaming 1 * Daily pull * HTTPS without Bio step 11 * HTTPS without Bio step 12 * HTTPS without Bio step 13 * HTTPS without Bio step 14 * SSL_Interception change documentation * HTTPS without Bio step 15 * HTTPS without Bio step 16 * SSL_Interception fix codacity * SSL_Interception fix doc * SSL_Interception comments * SSL_Interception fixing problems! * SSL_Interception killing bugs * SSL_Interception changing parameter * SSL_Implementation documentation and script * SSL_Implementation multiple fixes * SSL_Implementation installer and cipher * SSL_Implementation Redirect 301 * SSL_Implementation webserver doc and install-or-update.sh * SSL_Implementation error 00000001:lib(0):func(0):reason(1) * SSL_Implementation web server doc * SSL_Implementation SEGFAULT on Fedora * SSL_Implementation fix ^SSL=force|optional * SSL_Implementation Redirect and Ciphers * SSL_Implementation race condition 1 * SSL_Implementation Fix Location * SSL_Implementation Fix Location 2 * SSL_Implementation Fix stream * SSL_Implementation Fix stream 2 * SSL_Implementation Fix stream 3 * SSL_Implementation last problems! * SSL_Implementation adjusts to commit! * SSL_Implementation documentation permission! * SSL_Implementation documentation permission 2! * SSL_Implementation documentation permission 3!
140 lines
4.7 KiB
C
140 lines
4.7 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#define WEB_SERVER_INTERNALS 1
|
|
#include "web_server.h"
|
|
|
|
WEB_SERVER_MODE web_server_mode = WEB_SERVER_MODE_STATIC_THREADED;
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
WEB_SERVER_MODE web_server_mode_id(const char *mode) {
|
|
if(!strcmp(mode, "none"))
|
|
return WEB_SERVER_MODE_NONE;
|
|
else
|
|
return WEB_SERVER_MODE_STATIC_THREADED;
|
|
|
|
}
|
|
|
|
const char *web_server_mode_name(WEB_SERVER_MODE id) {
|
|
switch(id) {
|
|
case WEB_SERVER_MODE_NONE:
|
|
return "none";
|
|
default:
|
|
case WEB_SERVER_MODE_STATIC_THREADED:
|
|
return "static-threaded";
|
|
}
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
// API sockets
|
|
|
|
LISTEN_SOCKETS api_sockets = {
|
|
.config = &netdata_config,
|
|
.config_section = CONFIG_SECTION_WEB,
|
|
.default_bind_to = "*",
|
|
.default_port = API_LISTEN_PORT,
|
|
.backlog = API_LISTEN_BACKLOG
|
|
};
|
|
|
|
void debug_sockets() {
|
|
BUFFER *wb = buffer_create(256 * sizeof(char));
|
|
int i;
|
|
|
|
for(i = 0 ; i < (int)api_sockets.opened ; i++) {
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_NOCHECK)?"NONE ":"");
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_DASHBOARD)?"dashboard ":"");
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_REGISTRY)?"registry ":"");
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_BADGE)?"badges ":"");
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_MGMT)?"management ":"");
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_STREAMING)?"streaming ":"");
|
|
buffer_strcat(wb, (api_sockets.fds_acl_flags[i] & WEB_CLIENT_ACL_NETDATACONF)?"netdata.conf ":"");
|
|
debug(D_WEB_CLIENT, "Socket fd %d name '%s' acl_flags: %s",
|
|
i,
|
|
api_sockets.fds_names[i],
|
|
buffer_tostring(wb));
|
|
buffer_reset(wb);
|
|
}
|
|
buffer_free(wb);
|
|
}
|
|
|
|
void api_listen_sockets_setup(void) {
|
|
int socks = listen_sockets_setup(&api_sockets);
|
|
|
|
if(!socks)
|
|
fatal("LISTENER: Cannot listen on any API socket. Exiting...");
|
|
|
|
if(unlikely(debug_flags & D_WEB_CLIENT))
|
|
debug_sockets();
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
// access lists
|
|
|
|
SIMPLE_PATTERN *web_allow_connections_from = NULL;
|
|
|
|
// WEB_CLIENT_ACL
|
|
SIMPLE_PATTERN *web_allow_dashboard_from = NULL;
|
|
SIMPLE_PATTERN *web_allow_registry_from = NULL;
|
|
SIMPLE_PATTERN *web_allow_badges_from = NULL;
|
|
SIMPLE_PATTERN *web_allow_mgmt_from = NULL;
|
|
SIMPLE_PATTERN *web_allow_streaming_from = NULL;
|
|
SIMPLE_PATTERN *web_allow_netdataconf_from = NULL;
|
|
|
|
void web_client_update_acl_matches(struct web_client *w) {
|
|
w->acl = WEB_CLIENT_ACL_NONE;
|
|
|
|
if(!web_allow_dashboard_from || simple_pattern_matches(web_allow_dashboard_from, w->client_ip))
|
|
w->acl |= WEB_CLIENT_ACL_DASHBOARD;
|
|
|
|
if(!web_allow_registry_from || simple_pattern_matches(web_allow_registry_from, w->client_ip))
|
|
w->acl |= WEB_CLIENT_ACL_REGISTRY;
|
|
|
|
if(!web_allow_badges_from || simple_pattern_matches(web_allow_badges_from, w->client_ip))
|
|
w->acl |= WEB_CLIENT_ACL_BADGE;
|
|
|
|
if(!web_allow_mgmt_from || simple_pattern_matches(web_allow_mgmt_from, w->client_ip))
|
|
w->acl |= WEB_CLIENT_ACL_MGMT;
|
|
|
|
if(!web_allow_streaming_from || simple_pattern_matches(web_allow_streaming_from, w->client_ip))
|
|
w->acl |= WEB_CLIENT_ACL_STREAMING;
|
|
|
|
if(!web_allow_netdataconf_from || simple_pattern_matches(web_allow_netdataconf_from, w->client_ip))
|
|
w->acl |= WEB_CLIENT_ACL_NETDATACONF;
|
|
|
|
w->acl &= w->port_acl;
|
|
}
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
void web_server_log_connection(struct web_client *w, const char *msg) {
|
|
log_access("%llu: %d '[%s]:%s' '%s'", w->id, gettid(), w->client_ip, w->client_port, msg);
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
void web_client_initialize_connection(struct web_client *w) {
|
|
int flag = 1;
|
|
|
|
if(unlikely(web_client_check_tcp(w) && setsockopt(w->ifd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) != 0))
|
|
debug(D_WEB_CLIENT, "%llu: failed to enable TCP_NODELAY on socket fd %d.", w->id, w->ifd);
|
|
|
|
flag = 1;
|
|
if(unlikely(setsockopt(w->ifd, SOL_SOCKET, SO_KEEPALIVE, (char *) &flag, sizeof(int)) != 0))
|
|
debug(D_WEB_CLIENT, "%llu: failed to enable SO_KEEPALIVE on socket fd %d.", w->id, w->ifd);
|
|
|
|
web_client_update_acl_matches(w);
|
|
|
|
w->origin[0] = '*'; w->origin[1] = '\0';
|
|
w->cookie1[0] = '\0'; w->cookie2[0] = '\0';
|
|
freez(w->user_agent); w->user_agent = NULL;
|
|
|
|
web_client_enable_wait_receive(w);
|
|
|
|
web_server_log_connection(w, "CONNECTED");
|
|
|
|
web_client_cache_verify(0);
|
|
}
|