Skip to content

Commit b6e285d

Browse files
committed
Add ip trigger
1 parent 118249a commit b6e285d

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

src/mod_redirectionio.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static const char *redirectionio_set_scheme(cmd_parms *cmd, void *cfg, const cha
3636
static const char *redirectionio_set_show_rule_ids(cmd_parms *cmd, void *cfg, const char *arg);
3737
static const char *redirectionio_set_server(cmd_parms *cmd, void *dc, int argc, char *const argv[]);
3838
static const char *redirectionio_set_header(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2);
39+
static const char *redirectionio_set_trusted_proxies(cmd_parms *cmd, void *cfg, const char *arg);
3940
static void redirectionio_apache_log_callback(const char* log_str, const void* data, short level);
4041
static apr_status_t redirectionio_atoi(const char *line, apr_size_t len);
4142

@@ -47,6 +48,7 @@ static const command_rec redirectionio_directives[] = {
4748
AP_INIT_TAKE1("redirectionioScheme", redirectionio_set_scheme, NULL, OR_ALL, "Force scheme to use when matching request"),
4849
AP_INIT_TAKE1("redirectionioRuleIdsHeader", redirectionio_set_show_rule_ids, NULL, OR_ALL, "Show rule ids used on response header"),
4950
AP_INIT_TAKE2("redirectionioSetHeader", redirectionio_set_header, NULL, OR_ALL, "Add header to match in redirectionio request"),
51+
AP_INIT_TAKE1("redirectionioTrustedProxies", redirectionio_set_trusted_proxies, NULL, OR_ALL, "Trusted proxies to filter client ip"),
5052
{ NULL }
5153
};
5254

@@ -509,6 +511,7 @@ static void *create_redirectionio_dir_conf(apr_pool_t *pool, char *context) {
509511
config->pool = pool;
510512
config->show_rule_ids = -1;
511513
config->headers_set = NULL;
514+
config->trusted_proxies = NULL;
512515
}
513516

514517
return config;
@@ -578,6 +581,12 @@ static void *merge_redirectionio_dir_conf(apr_pool_t *pool, void *parent, void *
578581
conf->server.timeout = conf_current->server.timeout;
579582
}
580583

584+
if (conf_current->trusted_proxies == NULL) {
585+
conf->trusted_proxies = conf_parent->trusted_proxies;
586+
} else {
587+
conf->trusted_proxies = conf_current->trusted_proxies;
588+
}
589+
581590
conf->pool = pool;
582591
conf->connection_pool = NULL;
583592

@@ -829,6 +838,16 @@ static const char *redirectionio_set_header(cmd_parms *cmd, void *cfg, const cha
829838
return NULL;
830839
}
831840

841+
static const char *redirectionio_set_trusted_proxies(cmd_parms *cmd, void *cfg, const char *arg) {
842+
redirectionio_config *conf = (redirectionio_config*)cfg;
843+
844+
if (conf) {
845+
conf->trusted_proxies = (struct REDIRECTIONIO_TrustedProxies *) redirectionio_trusted_proxies_create(arg);
846+
}
847+
848+
return NULL;
849+
}
850+
832851
static void redirectionio_apache_log_callback(const char* log_str, const void* data, short level) {
833852
if (level <= 1) {
834853
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, (request_rec *)data, "mod_redirectionio api error: %s", log_str);

src/mod_redirectionio.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ typedef struct {
5353
} redirectionio_server;
5454

5555
typedef struct {
56-
const char* project_key;
57-
const char* scheme;
58-
redirectionio_server server;
59-
int enable;
60-
int enable_logs;
61-
int show_rule_ids;
62-
apr_reslist_t *connection_pool;
63-
apr_pool_t *pool;
64-
apr_table_t *headers_set;
56+
const char* project_key;
57+
const char* scheme;
58+
redirectionio_server server;
59+
int enable;
60+
int enable_logs;
61+
int show_rule_ids;
62+
apr_reslist_t *connection_pool;
63+
apr_pool_t *pool;
64+
apr_table_t *headers_set;
65+
struct REDIRECTIONIO_TrustedProxies *trusted_proxies;
6566
} redirectionio_config;
6667

6768
typedef struct {

src/redirectionio_protocol.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ apr_status_t redirectionio_protocol_match(redirectionio_connection *conn, redire
9090
return APR_EGENERAL;
9191
}
9292

93+
redirectionio_request_set_remote_addr(ctx->request, r->connection->client_ip, config->trusted_proxies);
94+
9395
apr_pool_pre_cleanup_register(r->pool, ctx->request, redirectionio_request_cleanup);
9496

9597
// Serialize request

0 commit comments

Comments
 (0)