From: james Date: Wed, 8 Nov 2006 06:54:20 +0000 (+0000) Subject: Added time_ascii, time_duration, and time_unix X-Git-Tag: v2.1_rc2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a783c40067ed2ac692c9d9c68ee01a7d568900b6;p=thirdparty%2Fopenvpn.git Added time_ascii, time_duration, and time_unix environmental variables for plugins and callback scripts. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@1440 e7ae566f-a301-0410-adde-c780ea21d3b5 --- diff --git a/misc.c b/misc.c index ed3960caa..161b9e40a 100644 --- a/misc.c +++ b/misc.c @@ -863,6 +863,14 @@ setenv_int (struct env_set *es, const char *name, int value) setenv_str (es, name, buf); } +void +setenv_unsigned (struct env_set *es, const char *name, unsigned int value) +{ + char buf[64]; + openvpn_snprintf (buf, sizeof(buf), "%u", value); + setenv_str (es, name, buf); +} + void setenv_str (struct env_set *es, const char *name, const char *value) { diff --git a/misc.h b/misc.h index b57185b26..fa13dafef 100644 --- a/misc.h +++ b/misc.h @@ -160,6 +160,7 @@ void setenv_str_ex (struct env_set *es, void setenv_counter (struct env_set *es, const char *name, counter_type value); void setenv_int (struct env_set *es, const char *name, int value); +void setenv_unsigned (struct env_set *es, const char *name, unsigned int value); void setenv_str (struct env_set *es, const char *name, const char *value); void setenv_str_safe (struct env_set *es, const char *name, const char *value); void setenv_del (struct env_set *es, const char *name); diff --git a/multi.c b/multi.c index 45ca7d1b0..ee74a4679 100644 --- a/multi.c +++ b/multi.c @@ -407,6 +407,9 @@ multi_client_disconnect_setenv (struct multi_context *m, setenv_counter (mi->context.c2.es, "bytes_received", mi->context.c2.link_read_bytes); setenv_counter (mi->context.c2.es, "bytes_sent", mi->context.c2.link_write_bytes); + /* setenv connection duration */ + const unsigned int duration = (unsigned int) now - mi->created; + setenv_unsigned (mi->context.c2.es, "time_duration", duration); } static void @@ -1274,6 +1277,31 @@ multi_client_connect_post_plugin (struct multi_context *m, #endif +static void +multi_client_connect_setenv (struct multi_context *m, + struct multi_instance *mi) +{ + struct gc_arena gc = gc_new (); + + /* setenv incoming cert common name for script */ + setenv_str (mi->context.c2.es, "common_name", tls_common_name (mi->context.c2.tls_multi, true)); + + /* setenv client real IP address */ + setenv_trusted (mi->context.c2.es, get_link_socket_info (&mi->context)); + + /* setenv client virtual IP address */ + multi_set_virtual_addr_env (m, mi); + + /* setenv connection time */ + { + const char *created_ascii = time_string (mi->created, 0, false, &gc); + setenv_str (mi->context.c2.es, "time_ascii", created_ascii); + setenv_unsigned (mi->context.c2.es, "time_unix", (unsigned int)mi->created); + } + + gc_free (&gc); +} + /* * Called as soon as the SSL/TLS connection authenticates. * @@ -1365,14 +1393,8 @@ multi_connection_established (struct multi_context *m, struct multi_instance *mi */ multi_select_virtual_addr (m, mi); - /* setenv incoming cert common name for script */ - setenv_str (mi->context.c2.es, "common_name", tls_common_name (mi->context.c2.tls_multi, true)); - - /* setenv client real IP address */ - setenv_trusted (mi->context.c2.es, get_link_socket_info (&mi->context)); - - /* setenv client virtual IP address */ - multi_set_virtual_addr_env (m, mi); + /* do --client-connect setenvs */ + multi_client_connect_setenv (m, mi); #ifdef ENABLE_PLUGIN /* diff --git a/openvpn.8 b/openvpn.8 index 69ee88e5a..48ae43053 100644 --- a/openvpn.8 +++ b/openvpn.8 @@ -5080,6 +5080,30 @@ or (unknown signal). This variable is set just prior to down script execution. .\"********************************************************* .TP +.B time_ascii +Client connection timestamp, formatted as a human-readable +time string. +Set prior to execution of the +.B --client-connect +script. +.\"********************************************************* +.TP +.B time_duration +The duration (in seconds) of the client session which is now +disconnecting. +Set prior to execution of the +.B --client-disconnect +script. +.\"********************************************************* +.TP +.B time_unix +Client connection timestamp, formatted as a unix integer +date/time value. +Set prior to execution of the +.B --client-connect +script. +.\"********************************************************* +.TP .B tls_id_{n} A series of certificate fields from the remote peer, where