-
Notifications
You must be signed in to change notification settings - Fork 3
/
html_session.tbs
130 lines (112 loc) · 4.41 KB
/
html_session.tbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
include "global.tbh"
'------------------------------------------------------------------------------
public dim html_login_message as html_login_messages
public dim session as string(SESSION_LEN)
public dim pass as ok_ng
dim login_compare_result as login_comparison_codes
'==============================================================================
public sub html_session_init()
html_login_message = HLM_NONE
session=""
pass = NG
end sub
'------------------------------------------------------------------------------
public sub html_login()
if pass = OK then
if login_compare_result<>LC_WILL_REJECT_HIGHER_IN_PROGRESS and login_compare_result<>LC_WILL_REJECT_SAME_IN_PROGRESS then
callback_html_session_login()
login(CMD_MODE_HTTP,session,sock.num)
end if
pass = NG
end if
end sub
'------------------------------------------------------------------------------
public function html_login_verify(print_redir as no_yes, refresh_timeout as no_yes) as ok_ng
'Check if there are currently logged user by varifing the session ID.
dim sSessionID as string(SESSION_LEN)
sSessionID = get_http_argument(sock.httprqstring,"session=")
if login_mode<>CMD_MODE_HTTP then
html_login_message=HLM_NOT_LOGGED_IN
if print_redir = YES then sock_setsend("onload = IndexPage()")
html_login_verify = NG
exit function
end if
if sSessionID <> login_data then
html_login_message = HLM_INVALID_SESSION
if print_redir = YES then sock_setsend("onload = IndexPage()")
html_login_verify = NG
exit function
end if
html_login_verify = OK
if refresh_timeout=YES then
login_timeout_reset()
end if
end function
'------------------------------------------------------------------------------
public function password_verify as ok_ng
'Check the password. If the password is correct, proceed to the next page (home.html), otherwise, redirect back to index page
dim pw as string(6)
dim entered_pw as string(6)
dim temp, sSessionID as string(SESSION_LEN)
dim stg_status as en_stg_status_codes
dim i as byte
entered_pw = get_http_argument(sock.httprqstring,"pw=")
stg_status = stg_sg("PW",0,pw,EN_STG_GET)
sSessionID = ""
'here, the function checks an http argument call "logout" if it is equal to yes, meaning instead of
'login, the user is logging out.
if entered_pw = pw then
'generating session id
temp = random(SESSION_LEN)
for i = 1 to SESSION_LEN
sSessionID = sSessionID + str(asc( mid(temp,i,1)) mod 9)
next i
login_compare_result=compare_logins(CMD_MODE_HTTP,sSessionID,sock.num)
password_verify = OK
else
'invalid password
password_verify=NG
end if
session = sSessionID
end function
'------------------------------------------------------------------------------
public sub login_action(pass_varified as ok_ng)
if pass_varified = NG then
sock_setsend("onload='IndexPage()'") 'redirect back to index page
html_login_message = HLM_INVALID_PASSWORD
else
select case login_compare_result
case LC_WILL_ACCEPT, LC_WILL_ACCEPT_REPEATED_LOGIN:
sock_setsend("onload ='HomePage()'") 'proceed to the setup page
case LC_WILL_ACCEPT_LOWER_IN_PROGRESS:
sock_setsend("onload='Redirect()'") 'redirect back to index page
case LC_WILL_REJECT_HIGHER_IN_PROGRESS, LC_WILL_REJECT_SAME_IN_PROGRESS:
html_login_message=HLM_PRIORITY_REJECTED
sock_setsend("onload='IndexPage()'") 'redirect back to index page
end select
end if
end sub
'------------------------------------------------------------------------------
public sub print_login_state
'check current login (error) message and print the error msg on the index.html accordingly
select case html_login_message
case HLM_LOGGED_OUT:
sock_setsend(HTML_LOGGED_OUT)
case HLM_INVALID_PASSWORD:
sock_setsend(HTML_INVALID_LOGIN)
case HLM_INVALID_SESSION:
sock_setsend(HTML_INVALID_SESSION)
case HLM_PRIORITY_REJECTED:
sock_setsend(HTML_NO_PRIORITY)
case HLM_NOT_LOGGED_IN
sock_setsend(HTML_NOT_LOGGED_IN)
end select
html_login_message = HLM_NONE
end sub
'------------------------------------------------------------------------------
public sub html_print_session
'get the session number from URL and add it to the html page as an input, so it would be passed on.
dim s as string
s = get_http_argument(sock.httprqstring,"session=")
sock_setsend("<input type = 'hidden' name = 'session' value = '"+s+"'>")
end sub