mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
httpd: make the session timeout configurable
The session timeout was a compile-time constant (200 s), so changing it meant rebuilding the firmware. Make it a variable that keeps the same default and add a "session <seconds>" command, so it can be set from the console or from the startup configuration like the other settings. Measured on KP_9000_9XHML_X_V3_1: ROM +180 bytes (BANK1 +17, BANK2 +161) and xdata +2 bytes; the internal RAM map is unchanged.
This commit is contained in:
1 parent
2f005d2993
commit
f0b311fc43
4 files changed
+32
-3
No files matched your search
@@ -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 x name xxx = Name xxx the port number x
|
||||||
port z 1g = Set 1g speed for port z
|
port z 1g = Set 1g speed for port z
|
||||||
igmp on/off = Turn IGMP on or off
|
igmp on/off = Turn IGMP on or off
|
||||||
|
session xxxx = Web session timeout in seconds (default 200)
|
||||||
```
|
```
|
||||||
[To be continue]
|
[To be continue]
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ extern __xdata struct flash_region_t flash_region;
|
|||||||
|
|
||||||
extern __xdata char passwd[21];
|
extern __xdata char passwd[21];
|
||||||
|
|
||||||
|
extern __xdata uint16_t session_timeout;
|
||||||
|
|
||||||
extern __xdata struct dhcp_state dhcp_state;
|
extern __xdata struct dhcp_state dhcp_state;
|
||||||
|
|
||||||
__xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
__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
|
// Parse command into words
|
||||||
// cmd_words_len contains the number of words found.
|
// cmd_words_len contains the number of words found.
|
||||||
// cmd_words_b[] contains only start of a word offset.
|
// 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")) {
|
} else if (cmd_compare(0, "ingress")) {
|
||||||
parse_ingress();
|
parse_ingress();
|
||||||
|
} else if (cmd_compare(0, "session")) {
|
||||||
|
parse_session();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print_string("Unknown command\n");
|
print_string("Unknown command\n");
|
||||||
|
|||||||
+2
-1
@@ -427,6 +427,7 @@ var CONF_CMDS=[
|
|||||||
/^ip\s+(\d{1,3}\.){3}\d{1,3}$/,/^ip\s+dhcp$/,
|
/^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}$/,
|
/^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}$/,
|
/^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}$/,
|
/^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+d$/,/^vlan\s+\d{1,4}\s+mgmt$/,
|
||||||
/^vlan\s+\d{1,4}(\s+[a-zA-Z]\w*)?(\s+\d{1,2}t?)+$/,
|
/^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=[
|
var CONF_OVERWRITE=[
|
||||||
/^ip\b/,/^gw\b/,/^netmask\b/,/^hostname\b/,
|
/^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)/,
|
/^vlan\s+\d{1,4}\s+mgmt$/,/^vlan\s+\d{1,4}(?!\s+mgmt\b)/,
|
||||||
/^pvid\s+\d{1,2}\b/,/^ingress\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/,
|
/^port\s+\d{1,2}(?!\s+name\b)/,/^port\s+\d{1,2}\s+name\b/,
|
||||||
|
|||||||
+6
-2
@@ -12,7 +12,11 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define SESSION_ID_LENGTH 12
|
#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
|
#define CMARK_S 6
|
||||||
|
|
||||||
@@ -341,7 +345,7 @@ __xdata uint8_t *scan_header(__xdata uint8_t * __xdata p)
|
|||||||
read_reg_timer(&now);
|
read_reg_timer(&now);
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
if (now - last_session_use > SESSION_TIMEOUT) {
|
if (now - last_session_use > session_timeout) {
|
||||||
dbg_string("Session expired\n");
|
dbg_string("Session expired\n");
|
||||||
} else {
|
} else {
|
||||||
if (is_word_x(session, session_id)) {
|
if (is_word_x(session, session_id)) {
|
||||||
|
|||||||
Reference in new issue
Block a user