diff --git a/README.md b/README.md index 74b2ffbd..1968fb26 100644 --- a/README.md +++ b/README.md @@ -344,6 +344,7 @@ netmask zzz.zzz.zzz.zzz = Network mask of the switch port x name xxx = Name xxx the port number x port z 1g = Set 1g speed for port z igmp on/off = Turn IGMP on or off +session xxxx = Web session timeout in seconds (default 200) ``` [To be continue] diff --git a/cmd_parser.c b/cmd_parser.c index 5a3a3d60..e6decbeb 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -41,6 +41,8 @@ extern __xdata struct flash_region_t flash_region; extern __xdata char passwd[21]; +extern __xdata uint16_t session_timeout; + extern __xdata struct dhcp_state dhcp_state; __xdata uint8_t vlan_names[VLAN_NAMES_SIZE]; @@ -1593,6 +1595,25 @@ void parse_syslog(void) } } +void parse_session(void) +{ + if (cmd_words_len >= 2) { + /* atoi_short() returns zero for no digits and for a value past + * 65535; a zero-second timeout is not useful either, so both + * tests are needed. */ + if (!atoi_short(cmd_words_b[1]) || !atoi_results_short) { + print_string("Must be 1-65535 s\n"); + return; + } + session_timeout = atoi_results_short; + } + /* Also the confirmation after setting: one message for both. */ + print_string("Session timeout: "); + itoa_short(session_timeout); + print_string(" s\n"); +} + + // Parse command into words // cmd_words_len contains the number of words found. // cmd_words_b[] contains only start of a word offset. @@ -1895,6 +1916,8 @@ void cmd_parser(void) __banked } } else if (cmd_compare(0, "ingress")) { parse_ingress(); + } else if (cmd_compare(0, "session")) { + parse_session(); } else { print_string("Unknown command\n"); diff --git a/html/app.js b/html/app.js index 0a50b322..4bcb5c73 100644 --- a/html/app.js +++ b/html/app.js @@ -427,6 +427,7 @@ var CONF_CMDS=[ /^ip\s+(\d{1,3}\.){3}\d{1,3}$/,/^ip\s+dhcp$/, /^gw\s+(\d{1,3}\.){3}\d{1,3}$/,/^netmask\s+(\d{1,3}\.){3}\d{1,3}$/, /^syslog\s+(on|off)$/,/^syslog\s+ip\s+(\d{1,3}\.){3}\d{1,3}$/,/^syslog\s+port\s+\d{1,5}$/, + /^session\s+\d{1,5}$/, /^passwd\s+\S+$/,/^hostname\s+\S{1,23}$/, /^vlan\s+\d{1,4}\s+d$/,/^vlan\s+\d{1,4}\s+mgmt$/, /^vlan\s+\d{1,4}(\s+[a-zA-Z]\w*)?(\s+\d{1,2}t?)+$/, @@ -1612,7 +1613,7 @@ tabHooks.system={enter:sysLoad}; var CONF_OVERWRITE=[ /^ip\b/,/^gw\b/,/^netmask\b/,/^hostname\b/, - /^syslog\s+ip\b/,/^syslog\s+port\b/,/^passwd\b/, + /^syslog\s+ip\b/,/^syslog\s+port\b/,/^passwd\b/,/^session\b/, /^vlan\s+\d{1,4}\s+mgmt$/,/^vlan\s+\d{1,4}(?!\s+mgmt\b)/, /^pvid\s+\d{1,2}\b/,/^ingress\b/, /^port\s+\d{1,2}(?!\s+name\b)/,/^port\s+\d{1,2}\s+name\b/, diff --git a/httpd/httpd.c b/httpd/httpd.c index f87de897..41a3fc65 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -12,7 +12,11 @@ #include "debug.h" #define SESSION_ID_LENGTH 12 -#define SESSION_TIMEOUT 200 +#define SESSION_TIMEOUT_DEFAULT 200 + +/* Seconds of inactivity after which a session cookie stops validating. + * Configurable with the "session" command, see cmd_parser.c. */ +__xdata uint16_t session_timeout = SESSION_TIMEOUT_DEFAULT; #define CMARK_S 6 @@ -341,7 +345,7 @@ __xdata uint8_t *scan_header(__xdata uint8_t * __xdata p) read_reg_timer(&now); if (session) { - if (now - last_session_use > SESSION_TIMEOUT) { + if (now - last_session_use > session_timeout) { dbg_string("Session expired\n"); } else { if (is_word_x(session, session_id)) {