[mod_verto] auth-expires

This commit is contained in:
Anthony Minessale 2021-02-03 21:18:07 +00:00 committed by Andrey Volk
parent 6a893d4990
commit 79110fc719
2 changed files with 30 additions and 1 deletions

View File

@ -1056,7 +1056,9 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
} else {
switch_xml_t x_param, x_params;
const char *use_passwd = NULL, *verto_context = NULL, *verto_dialplan = NULL;
time_t now = switch_epoch_time_now(NULL);
jsock->logintime = now;
jsock->id = switch_core_strdup(jsock->pool, id);
jsock->domain = switch_core_strdup(jsock->pool, domain);
jsock->uid = switch_core_sprintf(jsock->pool, "%s@%s", id, domain);
@ -1103,6 +1105,18 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
switch_event_add_header_string(jsock->vars, SWITCH_STACK_BOTTOM, var, val);
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, var, val);
switch_mutex_unlock(jsock->flag_mutex);
if (!strcmp(var, "login-expires")) {
uint32_t tmp = atol(val);
if (tmp > now) {
jsock->exptime = tmp;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Login expire time for %s set to %ld seconds\n", jsock->uid, tmp - now);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid expire time for %s. Defaulting to 300 sec\n", jsock->uid);
jsock->exptime = now + 300;
}
}
}
}
@ -1950,11 +1964,21 @@ static void client_run(jsock_t *jsock)
while(jsock->profile->running) {
int pflags, poll_time = 50;
time_t now;
if (!jsock->ws) { die("%s Setup Error\n", jsock->name); }
pflags = kws_wait_sock(jsock->ws, poll_time, KS_POLL_READ);
if (jsock->exptime) {
now = switch_epoch_time_now(NULL);
if (now >= jsock->exptime) {
die("%s Authentication Expired\n", jsock->uid);
}
}
if (jsock->drop) { die("%s Dropping Connection\n", jsock->name); }
if (pflags < 0 && (errno != EINTR)) { die_errnof("%s POLL FAILED with %d", jsock->name, pflags); }
if (pflags == 0) {/* socket poll timeout */ jsock_check_event_queue(jsock); idle += poll_time;} else {idle = 0;}
@ -4403,6 +4427,10 @@ static switch_bool_t login_func(const char *method, cJSON *params, jsock_t *jsoc
*response = cJSON_CreateObject();
cJSON_AddItemToObject(*response, "message", cJSON_CreateString("logged in"));
if (jsock->exptime) {
cJSON_AddItemToObject(*response, "auth-expires", cJSON_CreateNumber(jsock->exptime));
}
switch_mutex_lock(jsock->flag_mutex);
if ((var = switch_event_get_header(jsock->vars, "moderator")) && switch_true(var)) {
cJSON_AddItemToObject(*response, "moderator", cJSON_CreateTrue());

View File

@ -140,7 +140,8 @@ struct jsock_s {
char remote_host[256];
int remote_port;
int family;
time_t exptime;
time_t logintime;
struct verto_profile_s *profile;
switch_thread_rwlock_t *rwlock;