Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
d9b1683a
Commit
d9b1683a
authored
13 years ago
by
echicken
Browse files
Options
Downloads
Patches
Plain Diff
Store user's session key in data/user/####.session.
parent
a69e9bab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/webInit.ssjs
+34
-8
34 additions, 8 deletions
exec/load/webInit.ssjs
with
34 additions
and
8 deletions
exec/load/webInit.ssjs
+
34
−
8
View file @
d9b1683a
...
@@ -11,6 +11,7 @@ f.open("r");
...
@@ -11,6 +11,7 @@ f.open("r");
var
webIni
=
f
.
iniGetObject
();
var
webIni
=
f
.
iniGetObject
();
f
.
close
();
f
.
close
();
// Returns a string of random characters 'length' characters long
function
randomString
(
length
)
{
function
randomString
(
length
)
{
var
chars
=
'
0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz
'
.
split
(
''
);
var
chars
=
'
0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz
'
.
split
(
''
);
var
str
=
''
;
var
str
=
''
;
...
@@ -18,22 +19,47 @@ function randomString(length) {
...
@@ -18,22 +19,47 @@ function randomString(length) {
return
str
;
return
str
;
}
}
// Returns an unopened file object representing the user's .session file
function
getSessionKeyFile
(
userNumber
)
{
var
sessionKeyFile
=
userNumber
;
while
(
sessionKeyFile
.
length
<
4
)
sessionKeyFile
=
"
0
"
+
sessionKeyFile
;
sessionKeyFile
+=
"
.session
"
;
var
f
=
new
File
(
system
.
data_dir
+
"
user/
"
+
sessionKeyFile
);
return
f
;
}
if
(
http_request
.
query
.
hasOwnProperty
(
'
username
'
)
&&
http_request
.
query
.
hasOwnProperty
(
'
password
'
))
{
if
(
http_request
.
query
.
hasOwnProperty
(
'
username
'
)
&&
http_request
.
query
.
hasOwnProperty
(
'
password
'
))
{
var
sessionKey
=
randomString
(
30
);
// user.note seems to truncate at 30
// Script was (we'll assume) called from the login form. Attempt to authenticate the user.
var
sessionKey
=
randomString
(
512
);
// Arbitrary length, can be shorter, have seen problems with longer.
var
UID
=
system
.
matchuser
(
http_request
.
query
.
username
);
var
UID
=
system
.
matchuser
(
http_request
.
query
.
username
);
var
u
=
new
User
(
UID
);
var
u
=
new
User
(
UID
);
if
(
u
&&
http_request
.
query
.
password
.
toString
().
toUpperCase
()
==
u
.
security
.
password
.
toUpperCase
())
{
if
(
u
&&
http_request
.
query
.
password
.
toString
().
toUpperCase
()
==
u
.
security
.
password
.
toUpperCase
())
{
set_cookie
(
'
synchronet
'
,
UID
+
'
,
'
+
sessionKey
,
time
()
+
webIni
.
sessionTimeout
,
system
.
inet_addr
,
"
/
"
);
// The supplied username was valid, and the supplied password is correct. Create a cookie, log the user in and populate their .session file.
login
(
u
.
alias
,
u
.
security
.
password
);
set_cookie
(
'
synchronet
'
,
UID
+
'
,
'
+
sessionKey
,
time
()
+
webIni
.
sessionTimeout
,
system
.
inet_addr
,
"
/
"
);
u
.
note
=
sessionKey
;
login
(
u
.
alias
,
u
.
security
.
password
);
var
f
=
getSessionKeyFile
(
user
.
number
.
toString
());
if
(
f
.
open
(
"
w
"
))
{
// If this fails, the user will only be logged in for the duration of this page load.
f
.
write
(
sessionKey
);
f
.
close
();
}
}
}
}
else
if
(
http_request
.
header
.
hasOwnProperty
(
'
cookie
'
)
&&
http_request
.
header
.
cookie
.
match
(
/synchronet
\=\d
+,
\w
+/
)
!=
null
&&
!
http_request
.
query
.
hasOwnProperty
(
'
logout
'
))
{
}
else
if
(
http_request
.
header
.
hasOwnProperty
(
'
cookie
'
)
&&
http_request
.
header
.
cookie
.
match
(
/synchronet
\=\d
+,
\w
+/
)
!=
null
&&
!
http_request
.
query
.
hasOwnProperty
(
'
logout
'
))
{
// A 'synchronet' cookie exists and matches our '<user.number>,<sessionKey>' format.
var
cookie
=
http_request
.
header
.
cookie
.
toString
().
match
(
/
\d
+,
\w
+/
)[
0
].
split
(
'
,
'
);
var
cookie
=
http_request
.
header
.
cookie
.
toString
().
match
(
/
\d
+,
\w
+/
)[
0
].
split
(
'
,
'
);
var
u
=
new
User
(
cookie
[
0
]);
var
u
=
new
User
(
cookie
[
0
]);
if
(
u
&&
u
.
note
==
cookie
[
1
].
toString
())
{
var
sessionKey
=
false
;
set_cookie
(
'
synchronet
'
,
u
.
number
+
'
,
'
+
cookie
[
1
],
time
()
+
webIni
.
sessionTimeout
,
system
.
inet_addr
,
"
/
"
);
var
f
=
getSessionKeyFile
(
u
.
number
.
toString
());
login
(
u
.
alias
,
u
.
security
.
password
);
if
(
f
.
exists
)
{
u
.
note
=
cookie
[
1
];
f
.
open
(
"
r
"
);
sessionKey
=
f
.
read
();
f
.
close
();
}
// If the user was not valid, 'f' should not have existed, and sessionKey will evaluate false.
if
(
u
&&
sessionKey
&&
sessionKey
==
cookie
[
1
].
toString
())
{
// The user specified in the cookie exists, and the sessionKey from the cookie matches that on file. Update the cookie's expiration and log the user in.
set_cookie
(
'
synchronet
'
,
u
.
number
+
'
,
'
+
cookie
[
1
],
time
()
+
webIni
.
sessionTimeout
,
system
.
inet_addr
,
"
/
"
);
login
(
u
.
alias
,
u
.
security
.
password
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment