summaryrefslogtreecommitdiff
path: root/src/sp_utils.c
diff options
context:
space:
mode:
authorjvoisin2020-07-04 17:56:03 +0200
committerjvoisin2020-07-04 17:56:03 +0200
commit08f21d8b878b6c1490e6d6bb3d44aa640a88e9ca (patch)
tree0b4b55a5c8d24d05408bf02bd244e78c130ba87d /src/sp_utils.c
parent6c7ad0c1dfcf324828be4153b86a808b35995820 (diff)
Factorize how snuffleupagus gets client's ip addr
Diffstat (limited to 'src/sp_utils.c')
-rw-r--r--src/sp_utils.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c
index 40cf44e..1bd37fe 100644
--- a/src/sp_utils.c
+++ b/src/sp_utils.c
@@ -7,6 +7,21 @@ bool sp_zend_string_equals(const zend_string* s1, const zend_string* s2) {
7 !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1)); 7 !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
8} 8}
9 9
10static const char* default_ipaddr = "0.0.0.0";
11const char* get_ipaddr() {
12 const char* client_ip = getenv("REMOTE_ADDR");
13 if (client_ip) {
14 return client_ip;
15 }
16
17 const char* fwd_ip = getenv("HTTP_X_FORWARDED_FOR");
18 if (fwd_ip) {
19 return fwd_ip;
20 }
21
22 return default_ipaddr;
23}
24
10void sp_log_msg(char const* feature, int type, const char* fmt, ...) { 25void sp_log_msg(char const* feature, int type, const char* fmt, ...) {
11 char* msg; 26 char* msg;
12 va_list args; 27 va_list args;
@@ -15,10 +30,7 @@ void sp_log_msg(char const* feature, int type, const char* fmt, ...) {
15 vspprintf(&msg, 0, fmt, args); 30 vspprintf(&msg, 0, fmt, args);
16 va_end(args); 31 va_end(args);
17 32
18 const char *client_ip = getenv("REMOTE_ADDR"); 33 const char* client_ip = get_ipaddr();
19 if (!client_ip) {
20 client_ip = "0.0.0.0";
21 }
22 switch (SNUFFLEUPAGUS_G(config).log_media) { 34 switch (SNUFFLEUPAGUS_G(config).log_media) {
23 case SP_SYSLOG: 35 case SP_SYSLOG:
24 openlog(PHP_SNUFFLEUPAGUS_EXTNAME, LOG_PID, LOG_AUTH); 36 openlog(PHP_SNUFFLEUPAGUS_EXTNAME, LOG_PID, LOG_AUTH);