Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
luna
Commits
cf63e0c9
Commit
cf63e0c9
authored
Sep 16, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改选择系统用户和remote app登陆
parent
8ff84f5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
59 deletions
+81
-59
app.service.ts
src/app/app.service.ts
+7
-1
connect.component.ts
src/app/elements/connect/connect.component.ts
+71
-56
guacamole.component.ts
src/app/elements/guacamole/guacamole.component.ts
+3
-2
No files found.
src/app/app.service.ts
View file @
cf63e0c9
...
...
@@ -86,6 +86,11 @@ export class HttpService {
return
this
.
http
.
get
<
Array
<
TreeNode
>>
(
url
);
}
getMyRemoteAppSystemUsers
(
remoteAppId
:
string
)
{
const
url
=
`/api/v1/perms/users/remote-apps/
${
remoteAppId
}
/system-users/`
;
return
this
.
http
.
get
<
Array
<
SystemUser
>>
(
url
);
}
getMyAssetSystemUsers
(
assetId
:
string
)
{
const
url
=
`/api/v1/perms/users/assets/
${
assetId
}
/system-users/`
;
return
this
.
http
.
get
<
Array
<
SystemUser
>>
(
url
);
...
...
@@ -138,10 +143,11 @@ export class HttpService {
);
}
guacamoleAddRemoteApp
(
userId
:
string
,
remoteAppId
:
string
,
systemUserUsername
?:
string
,
systemUserPassword
?:
string
)
{
guacamoleAddRemoteApp
(
userId
:
string
,
remoteAppId
:
string
,
sys
UserId
:
string
,
sys
temUserUsername
?:
string
,
systemUserPassword
?:
string
)
{
let
params
=
new
HttpParams
()
.
set
(
'user_id'
,
userId
)
.
set
(
'remote_app_id'
,
remoteAppId
)
.
set
(
'system_user_id'
,
sysUserId
)
.
set
(
'token'
,
DataStore
.
guacamoleToken
);
let
body
=
new
HttpParams
();
if
(
systemUserUsername
&&
systemUserPassword
)
{
...
...
src/app/elements/connect/connect.component.ts
View file @
cf63e0c9
import
{
Component
,
OnInit
,
Output
,
Inject
,
OnDestroy
,
EventEmitter
}
from
'@angular/core'
;
import
{
Observable
,
Subject
}
from
'rxjs'
;
import
'rxjs/add/operator/toPromise'
;
import
{
connectEvt
}
from
'@app/globals'
;
import
{
AppService
,
HttpService
,
LogService
,
NavService
}
from
'@app/app.service'
;
import
{
MAT_DIALOG_DATA
,
MatDialog
,
MatDialogRef
}
from
'@angular/material'
;
...
...
@@ -7,6 +9,7 @@ import {ActivatedRoute} from '@angular/router';
import
{
SystemUser
,
TreeNode
,
Asset
}
from
'@app/model'
;
import
{
View
}
from
'@app/model'
;
@
Component
({
selector
:
'elements-connect'
,
templateUrl
:
'./connect.component.html'
,
...
...
@@ -70,45 +73,87 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
}
}
connectAsset
(
node
:
TreeNode
)
{
async
connectAsset
(
node
:
TreeNode
)
{
const
host
=
node
.
meta
.
asset
as
Asset
;
this
.
_http
.
getMyAssetSystemUsers
(
host
.
id
).
subscribe
(
systemUsers
=>
{
let
user
:
SystemUser
;
if
(
systemUsers
.
length
>
1
)
{
// 检查系统用户优先级,获取最高优先级的
user
=
this
.
checkPriority
(
systemUsers
);
if
(
user
)
{
return
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
loginAsset
.
bind
(
this
));
}
const
systemUsers
=
await
this
.
_http
.
getMyAssetSystemUsers
(
host
.
id
).
toPromise
();
let
sysUser
=
await
this
.
selectLoginSystemUsers
(
systemUsers
);
sysUser
=
await
this
.
manualSetUserAuthLoginIfNeed
(
sysUser
);
if
(
sysUser
&&
sysUser
.
id
)
{
this
.
loginAsset
(
host
,
sysUser
);
}
else
{
alert
(
'该主机没有授权系统用户'
);
}
}
selectLoginSystemUsers
(
systemUsers
:
Array
<
SystemUser
>
):
Promise
<
SystemUser
>
{
const
systemUserMaxPriority
=
this
.
filterMaxPrioritySystemUsers
(
systemUsers
);
let
user
:
SystemUser
;
if
(
systemUsers
.
length
>
1
)
{
return
new
Promise
<
SystemUser
>
(
resolve
=>
{
const
dialogRef
=
this
.
_dialog
.
open
(
AssetTreeDialogComponent
,
{
height
:
'200px'
,
width
:
'300px'
,
data
:
{
users
:
systemUser
s
}
data
:
{
users
:
systemUser
MaxPriority
}
});
dialogRef
.
afterClosed
().
subscribe
(
result
=>
{
if
(
result
)
{
for
(
const
i
of
systemUser
s
)
{
for
(
const
i
of
systemUser
MaxPriority
)
{
if
(
i
.
id
.
toString
()
===
result
.
toString
())
{
user
=
i
;
break
;
resolve
(
user
)
;
}
}
return
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
loginAsset
.
bind
(
this
));
}
return
null
;
});
}
else
if
(
systemUsers
.
length
===
1
)
{
user
=
systemUsers
[
0
];
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
loginAsset
.
bind
(
this
));
}
else
{
alert
(
'该主机没有授权登录用户'
);
}
});
}
else
if
(
systemUserMaxPriority
.
length
===
1
)
{
user
=
systemUserMaxPriority
[
0
];
return
Promise
.
resolve
(
user
);
}
else
{
return
Promise
.
resolve
(
null
);
}
}
manualSetUserAuthLoginIfNeed
(
user
:
SystemUser
):
Promise
<
SystemUser
>
{
if
(
!
user
||
user
.
login_mode
!==
'manual'
||
user
.
protocol
!==
'rdp'
||
this
.
_navSrv
.
skipAllManualPassword
)
{
return
Promise
.
resolve
(
user
);
}
user
=
Object
.
assign
({},
user
);
return
new
Promise
(
resolve
=>
{
const
dialogRef
=
this
.
_dialog
.
open
(
ManualPasswordDialogComponent
,
{
height
:
'250px'
,
width
:
'500px'
,
data
:
{
username
:
user
.
username
}
});
dialogRef
.
afterClosed
().
subscribe
(
result
=>
{
if
(
!
result
)
{
return
resolve
(
null
);
}
if
(
result
.
skip
)
{
return
resolve
(
user
);
}
user
.
username
=
result
.
username
;
user
.
password
=
result
.
password
;
return
resolve
(
user
);
});
});
}
connectRemoteApp
(
node
:
TreeNode
)
{
const
user
=
node
.
meta
.
user
as
SystemUser
;
return
this
.
manualSetUserAuthLoginIfNeed
(
node
,
user
,
this
.
loginRemoteApp
.
bind
(
this
));
async
connectRemoteApp
(
node
:
TreeNode
)
{
this
.
_logger
.
debug
(
'Connect remote app: '
,
node
.
id
);
const
systemUsers
=
await
this
.
_http
.
getMyRemoteAppSystemUsers
(
node
.
id
).
toPromise
();
let
sysUser
=
await
this
.
selectLoginSystemUsers
(
systemUsers
);
sysUser
=
await
this
.
manualSetUserAuthLoginIfNeed
(
sysUser
);
if
(
sysUser
&&
sysUser
.
id
)
{
return
this
.
loginRemoteApp
(
node
,
sysUser
);
}
else
{
alert
(
'该应用没有授权系统用户'
);
}
}
loginRemoteApp
(
node
:
TreeNode
,
user
:
SystemUser
)
{
...
...
@@ -144,28 +189,6 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
this
.
Connect
(
node
);
}
manualSetUserAuthLoginIfNeed
(
node
:
any
,
user
:
SystemUser
,
callback
)
{
if
(
user
.
login_mode
!==
'manual'
||
user
.
protocol
!==
'rdp'
||
this
.
_navSrv
.
skipAllManualPassword
)
{
return
callback
(
node
,
user
);
}
user
=
Object
.
assign
({},
user
);
const
dialogRef
=
this
.
_dialog
.
open
(
ManualPasswordDialogComponent
,
{
height
:
'250px'
,
width
:
'500px'
,
data
:
{
username
:
user
.
username
}
});
dialogRef
.
afterClosed
().
subscribe
(
result
=>
{
if
(
!
result
)
{
return
;
}
if
(
result
.
skip
)
{
return
callback
(
node
,
user
);
}
user
.
username
=
result
.
username
;
user
.
password
=
result
.
password
;
return
callback
(
node
,
user
);
});
}
loginAsset
(
host
:
Asset
,
user
:
SystemUser
)
{
if
(
user
)
{
...
...
@@ -185,18 +208,10 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
}
}
checkPriority
(
sysUsers
:
Array
<
SystemUser
>
)
{
let
priority
=
-
1
;
let
user
:
any
;
for
(
const
u
of
sysUsers
)
{
if
(
u
.
priority
>
priority
)
{
user
=
u
;
priority
=
u
.
priority
;
}
else
if
(
u
.
priority
===
priority
)
{
return
null
;
}
}
return
user
;
filterMaxPrioritySystemUsers
(
sysUsers
:
Array
<
SystemUser
>
):
Array
<
SystemUser
>
{
const
priorityAll
:
Array
<
number
>
=
sysUsers
.
map
(
s
=>
s
.
priority
);
const
maxPriority
=
Math
.
max
(...
priorityAll
);
return
sysUsers
.
filter
(
s
=>
s
.
priority
===
maxPriority
);
}
}
...
...
src/app/elements/guacamole/guacamole.component.ts
View file @
cf63e0c9
...
...
@@ -28,8 +28,9 @@ export class ElementGuacamoleComponent implements OnInit {
registerHost
()
{
let
action
:
any
;
console
.
log
(
this
.
sysUser
);
if
(
this
.
remoteAppId
)
{
action
=
this
.
_http
.
guacamoleAddRemoteApp
(
User
.
id
,
this
.
remoteAppId
,
this
.
sysUser
.
username
,
this
.
sysUser
.
password
);
action
=
this
.
_http
.
guacamoleAddRemoteApp
(
User
.
id
,
this
.
remoteAppId
,
this
.
sysUser
.
id
,
this
.
sysUser
.
username
,
this
.
sysUser
.
password
);
}
else
{
action
=
this
.
_http
.
guacamoleAddAsset
(
User
.
id
,
this
.
host
.
id
,
this
.
sysUser
.
id
,
this
.
sysUser
.
username
,
this
.
sysUser
.
password
);
}
...
...
@@ -51,7 +52,7 @@ export class ElementGuacamoleComponent implements OnInit {
const
now
=
new
Date
();
const
nowTime
=
now
.
getTime
()
/
1000
;
this
.
registered
=
true
;
this
.
_logger
.
debug
(
'Userid is'
,
User
.
id
);
this
.
_logger
.
debug
(
'User
id is'
,
User
.
id
);
this
.
_http
.
getGuacamoleToken
(
User
.
id
,
''
).
subscribe
(
data
=>
{
// /guacamole/client will redirect to http://guacamole/#/client
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment