Skip to content

Commit 41675f7

Browse files
IMPORTANT: security/authorization changes, cache user privileges add
1 parent 6b27bc7 commit 41675f7

File tree

5 files changed

+68
-19
lines changed

5 files changed

+68
-19
lines changed

%WebTerminal/Engine.cls.xml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
<Class name="%WebTerminal.Engine">
44
<Description>
55
This class represents the core of web terminal.
6-
All operations with opened WebSocket placed here.
7-
CLASS USES GLOBAL ^|"%SYS"|%WebTerminal.AuthKey for client
8-
authorization.</Description>
6+
All operations with opened WebSocket placed here.</Description>
97
<Super>%CSP.WebSocket,%Library.Routine</Super>
108
<TimeCreated>63047,60359.445979</TimeCreated>
119

@@ -83,6 +81,10 @@ Last joined client id</Description>
8381
<InitialExpression>$c(7)</InitialExpression>
8482
</Property>
8583

84+
<Parameter name="ConstServerActionExecuteStack">
85+
<Expression>$c(8)</Expression>
86+
</Parameter>
87+
8688
<Property name="ConstClientEnterClearIO">
8789
<Type>%Char</Type>
8890
<InitialExpression>$c(1)</InitialExpression>
@@ -128,6 +130,11 @@ Last joined client id</Description>
128130
<InitialExpression>$c(9)</InitialExpression>
129131
</Property>
130132

133+
<Property name="ConstClientLoginInfo">
134+
<Type>%Char</Type>
135+
<InitialExpression>$c(10)</InitialExpression>
136+
</Property>
137+
131138
<Property name="CurrentNamespace">
132139
<Type>%String</Type>
133140
</Property>
@@ -686,12 +693,14 @@ Ends clear I/O mode</Description>
686693
</Method>
687694

688695
<Method name="ParseError">
696+
<Description>
697+
This method transforms error </Description>
689698
<ClassMethod>1</ClassMethod>
690699
<FormalSpec>string:%String</FormalSpec>
691700
<ReturnType>%String</ReturnType>
692701
<Implementation><![CDATA[
693702
set string = $REPLACE($REPLACE(string, ">", "<"), ".Engine.", "<")
694-
quit "An error occured: " _ $PIECE(string, "<", 2) _
703+
quit "ERROR: " _ $PIECE(string, "<", 2) _
695704
$EXTRACT($PIECE(string, "<", 4), 2, *)
696705
]]></Implementation>
697706
</Method>
@@ -732,15 +741,38 @@ This method holds process and expects only one package from
732741
the client - it includes authorization key.</Description>
733742
<ReturnType>%Status</ReturnType>
734743
<Implementation><![CDATA[
735-
set key = ..Read(,.status,..#authorizationTimeout) // wait for package
736-
set realKey = ..GetAuthKey() // remember current auth key
737-
do ..GenerateAuthKey() // generate new auth key
738-
739-
if (key = realKey) {
740-
quit $$$OK
741-
}
744+
set authKey = ..Read(,.status,..#authorizationTimeout) // wait for package
745+
set ok = $$$NOTOK
746+
747+
/*
748+
* Find given CSPSessionCookie in session list. If found, grant access
749+
*/
750+
SET key = $ORDER(^%cspSession(""))
751+
WHILE (key '= "") {
752+
set lb = $GET(^%cspSession(key))
753+
if (lb '= "") {
754+
if ($LISTGET(lb, 8) = authKey) {
755+
756+
// setup privileges
757+
ZNSPACE $LISTGET(lb, 7) // namespace
758+
759+
set user = $LISTGET($LISTGET(lb, 16), 1) // user
760+
set loginStatus = ##class(%SYSTEM.Security).Login($LISTGET($LISTGET(lb, 16), 1))
761+
if ($$$ISOK(loginStatus)) {
762+
do ..SendData(user,..ConstClientLoginInfo)
763+
} else {
764+
do ..SendData("!",..ConstClientLoginInfo)
765+
}
766+
767+
set ok = loginStatus
768+
BREAK
769+
770+
}
771+
}
772+
SET key = $ORDER(^%cspSession(key))
773+
}
742774
743-
quit $$$NOTOK
775+
quit ok
744776
]]></Implementation>
745777
</Method>
746778

@@ -859,7 +891,7 @@ New connection established</Description>
859891
do ..SendData("1", ..ConstClientAuthorizationStatus)
860892
do ..SendData(..CurrentNamespace, ..ConstClientChangeNamespace)
861893
862-
use $io::("^" _ ..InitialZName)
894+
use $io::("^" _ ..InitialZName) // switch to routine
863895
do ..ClientLoop()
864896
865897
} else {

csp/webTerminal/index.csp.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
</div>
137137
<script type="text/javascript" id="startup">
138138
try {
139-
application.authorizationKey = "#(##Class(%WebTerminal.Engine).GetAuthKey())#";
139+
application.authorizationKey = "#(%session.CSPSessionCookie)#";
140140
application.initialize();
141141
} catch (e) {
142142
alert("Unable to initialize terminal: check console output.");

csp/webTerminal/js/application.js.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
var application = new function() {
88
9-
var version = "0.9.9 beta"; // link to language.js
9+
var version = "0.9.9.5 beta"; // link to language.js
1010
this.debug = false; // remove for release
1111
this.debugUrlPart = "172.27.25.133:57772"; // in-debug mode
1212

csp/webTerminal/js/language.js.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var lang = new function() {
2929
0: parser.highlightHTML("/help"),
3030
1: parser.highlightHTML("/tip"),
3131
2: parser.highlightHTML("/connect"),
32-
3: "0.9.9 beta",
32+
3: "0.9.9.5 beta",
3333
4: 1,
3434
5: parser.highlightHTML("set test = 12"),
3535
6: parser.highlightHTML("write test"),
@@ -743,6 +743,14 @@ var lang = new function() {
743743
77: {
744744
en: "Caché WEB Terminal",
745745
ru: "WEB-терминал Caché"
746+
},
747+
78: {
748+
en: "Logged as",
749+
ru: "Вход выполнен для"
750+
},
751+
79: {
752+
en: "Login failed.",
753+
ru: "Вход не выполнен."
746754
}
747755
};
748756

csp/webTerminal/js/terminal.js.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
* 7 ECHO (body) Read char
3333
* 8 Authorization status (body: 1/0)
3434
* 9 Watch (body: name)
35-
*
36-
* Clear I/O mode
35+
* 10 LoginInfo (body: user logged in)
36+
*
37+
* Clear I/O mode
3738
* In this mode terminal client will listen for data from server and output any data as it is, without any action
3839
* identifiers. The same with terminal: any data sent to server won't include any identifiers.
3940
*
@@ -71,7 +72,8 @@ var terminal = new function() {
7172
READ_STRING: String.fromCharCode(6), // reads string - removes namespace like in common terminal
7273
READ_CHARACTER: String.fromCharCode(7), // reads character - removes namespace like in common terminal
7374
AUTHORIZATION_STATUS: String.fromCharCode(8), // alerts client about authorization success. Holds 1/0
74-
WATCH: String.fromCharCode(9) // start watching
75+
WATCH: String.fromCharCode(9), // start watching
76+
LOGIN_INFO: String.fromCharCode(10)
7577
};
7678
7779
/**
@@ -319,6 +321,13 @@ var terminal = new function() {
319321
case terminal.clientActions.WATCH: {
320322
terminal.watches.watch(data.trim());
321323
} break;
324+
case terminal.clientActions.LOGIN_INFO: {
325+
if (data.charAt(0) === "!") {
326+
terminal.output.write(lang.get(79) + " " + data.substr(1));
327+
} else if (!settings.get_cleanStartup()) {
328+
terminal.output.write(lang.get(78) + " " + data);
329+
}
330+
} break;
322331
default: {
323332
log.write("Unrecognised action from server.");
324333
terminal.output.write(data);

0 commit comments

Comments
 (0)