Skip to content

Commit 80bdff3

Browse files
Clean start option add, hidden API remove (CleanStart), start namespace errors fix
1 parent 62ec466 commit 80bdff3

6 files changed

Lines changed: 50 additions & 19 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"printableName": "Cache Web Terminal",
66
"description": "Web-based terminal emulator for Caché administering.",
77
"author": "ZitRo",
8-
"version": "4.0.0-beta.13",
8+
"version": "4.0.0-beta.14",
99
"gaID": "UA-83005064-2",
1010
"releaseNumber": 26,
1111
"scripts": {

readme.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ To embed WebTerminal to any other web application, you can use `<iframe>` tag.
9393
Example:
9494

9595
```html
96-
<iframe id="terminal" src="http://127.0.0.1:57772/terminal/?NS=SAMPLES"></iframe>
96+
<iframe id="terminal" src="http://127.0.0.1:57772/terminal/?ns=SAMPLES&clean=1"></iframe>
9797
```
9898

99-
Note that terminal URL may include optional `NS` GET parameter, which specifies namespace
100-
where WebTerminal's session will start.
99+
Note that terminal URL may include optional GET parameters, which are the next:
100+
101+
+ `ns=USER` Namespace to open terminal in. If the logged user has no access to this namespace,
102+
the error message will appear and no namespace changes will occur.
103+
+ `clean` Start the WebTerminal without any additional information printed. It is not recommended to
104+
use this option if you are using terminal as a stand-alone tool (for everyday use), as you can miss
105+
important updates.
101106

102107
To use WebTerminal's API, you need to get WebTerminal instance first. Use iframe's
103108
`onTerminalInit` function to get it.

src/client/js/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,17 @@ function initialize () {
101101
terminal = new Terminal();
102102

103103
output.printLine(text);
104-
let ns = urlParams["NS"] || urlParams["ns"] || config.get("defaultNamespace");
105-
get("auth" + (ns ? `?NS=${ encodeURIComponent(ns) }` : ""), (obj) => {
104+
let ns = urlParams["NS"] || urlParams["ns"] || config.get("defaultNamespace"),
105+
urlPs = location.search.match(/ns=[^&]*/i) === null
106+
? location.search === ""
107+
? ns
108+
? `?ns=${ encodeURIComponent(ns) }`
109+
: ""
110+
: location.search + (ns ? `&ns=${ encodeURIComponent(ns) }` : "")
111+
: ns
112+
? location.search.replace(/ns=[^&]*/i, `ns=${ encodeURIComponent(ns) }`)
113+
: location.search;
114+
get("auth" + urlPs, (obj) => {
106115
if (!obj.key) {
107116
output.printLine(locale.get(`unSerRes`), JSON.stringify(obj));
108117
return;

src/client/js/localization/dictionary.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,9 @@ export default {
344344
"unLogOut": {
345345
en: "Your browser is too old or too weird to support log out functionality. Please, restart the browser manually.",
346346
ru: "Ваш браузер слишком странный или старый, и он не поддерживает функциональность выхода. Пожалуйста, перезапустите браузер вручную."
347+
},
348+
"unNS": {
349+
en: "Unable to change namespace to %s.",
350+
ru: "Не получается поменять область на %s."
347351
}
348352
};

src/cls/WebTerminal/Engine.cls

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ Method ExecuteSQL(query As %String = "") As %Status
8686
quit $$$OK
8787
}
8888

89-
/// This method holds process and expects only one package from
90-
/// the client - it includes authorization key.
89+
/// This method performs the authorization and login to WebTerminal.
90+
/// It returns a list with data (see Router.Auth method), which is used then to set up the
91+
/// initial values for the client.
9192
Method RequireAuthorization() As %List
9293
{
9394
set data = ..GetMessage(..#AuthorizationTimeout)
@@ -115,10 +116,13 @@ Method RequireAuthorization() As %List
115116
set username = $LISTGET(list, 1)
116117
set namespace = $LISTGET(list, 3)
117118
set ns = $Namespace
119+
118120
znspace "%SYS"
119121
do ##class(Security.Users).Get(username, .userProps)
120122
znspace ns
121123

124+
set namespace = $case(namespace, "":userProps("NameSpace"), :namespace)
125+
122126
if ($get(userProps("Routine")) '= "") {
123127
set ..StartupRoutine = userProps("Routine")
124128
}
@@ -127,14 +131,14 @@ Method RequireAuthorization() As %List
127131
return $LB("User " _ username _ " is not enabled in the system")
128132
}
129133

130-
set namespace = $case(namespace, "":userProps("NameSpace"), :namespace)
134+
set $LIST(list, 3) = namespace
131135
set loginStatus = $System.Security.Login(username)
132136

133137
if (loginStatus '= 1) {
134138
return $LB($System.Status.GetErrorText(loginStatus))
135139
}
136140

137-
return $LB("", namespace)
141+
return $LB("", list)
138142
}
139143

140144
/// See WebTerminal.Handlers
@@ -190,12 +194,13 @@ loopEnd
190194

191195
/// This method sends basic login info to the user. Use this method to set client variables
192196
/// during the WebTerminal initialization.
193-
Method SendLoginInfo()
197+
/// <parameter>authList</parameter> See Router.Auth method.
198+
Method SendLoginInfo(authList As %List)
194199
{
195200
set obj = ##class(%ZEN.proxyObject).%New()
196201
set obj.username = $USERNAME
197202
set obj.name = $get(^WebTerminal("Name"))
198-
set obj.cleanStart = $data(^WebTerminal("CleanStart"))
203+
set obj.cleanStart = $ListGet(authList, 4)
199204
set obj.system = $SYSTEM
200205
set obj.firstLaunch = ($get(^WebTerminal("FirstLaunch"), 1) '= 0)
201206
set obj.InstanceGUID = ##class(%SYS.System).InstanceGUID()
@@ -207,15 +212,22 @@ Method SendLoginInfo()
207212
/// Triggered when new connection established.
208213
Method Server() As %Status
209214
{
210-
set authRes = ..RequireAuthorization() // $LB("", $Namespace)
215+
set authRes = ..RequireAuthorization()
211216
set authMessage = $ListGet(authRes, 1)
212217
if (authMessage = "") {
213-
set namespace = $ListGet(authRes, 2)
214-
if (namespace '= "") {
215-
try { znspace namespace } catch (e) { }
218+
set authList = $ListGet(authRes, 2) // see Router.Auth method
219+
set namespace = $ListGet(authList, 3)
220+
if (namespace '= "") && (namespace '= $Namespace) {
221+
try {
222+
znspace namespace
223+
} catch (e) {
224+
do ..Send("oLocalized",
225+
$Char(27) _ "[31m%unNS(" _ namespace _ ")"_ $Char(27) _ "[0m" _ $Char(13,10)
226+
)
227+
}
216228
}
217229
set ..CurrentNamespace = $Namespace
218-
do ..SendLoginInfo()
230+
do ..SendLoginInfo(authList)
219231
do ..ClientLoop()
220232
do ..Send("oLocalized", "%wsNormalClose"_$C(13,10))
221233
} else {

src/cls/WebTerminal/Router.cls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ ClassMethod WriteStatic(type As %String, ContentType As %String = "") [ Private
3737
ClassMethod Auth() As %Status
3838
{
3939
set cookie = $System.Encryption.Base64Encode(%session.Key)
40-
set ^WebTerminal("AuthUser", cookie) = $LB(
40+
set ^WebTerminal("AuthUser", cookie) = $LB( // authList
4141
$Username, // username
4242
$Horolog, // granting ticket date
43-
$Get(%request.Data("NS", 1))
43+
$Get(%request.Data("ns", 1), $Get(%request.Data("NS", 1))),
44+
$Get(%request.Data("clean", 1), 0) '= 0
4445
)
4546
write "{""key"":""" _ cookie _ """}"
4647
return $$$OK

0 commit comments

Comments
 (0)