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
d5acdb9b
Commit
d5acdb9b
authored
Mar 13, 2018
by
zheng liu
Browse files
Options
Browse Files
Download
Plain Diff
Merged in master (pull request #89)
Master
parents
cc52e24f
6e71d866
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
30 deletions
+101
-30
app.service.ts
src/app/app.service.ts
+28
-8
connect-page.component.html
src/app/connect-page/connect-page.component.html
+2
-2
connect-page.component.ts
src/app/connect-page/connect-page.component.ts
+67
-2
guacamole.component.ts
src/app/elements/guacamole/guacamole.component.ts
+4
-18
No files found.
src/app/app.service.ts
View file @
d5acdb9b
...
@@ -70,10 +70,19 @@ export class HttpService {
...
@@ -70,10 +70,19 @@ export class HttpService {
return
this
.
http
.
get
<
Array
<
HostGroup
>>
(
'/api/perms/v1/user/nodes-assets/'
);
return
this
.
http
.
get
<
Array
<
HostGroup
>>
(
'/api/perms/v1/user/nodes-assets/'
);
}
}
get_guacamole_token
(
user_id
:
string
)
{
get_guacamole_token
(
user_id
:
string
,
authToken
:
string
)
{
const
body
=
new
HttpParams
()
const
body
=
new
HttpParams
()
.
set
(
'username'
,
user_id
)
.
set
(
'username'
,
user_id
)
.
set
(
'password'
,
'jumpserver'
);
.
set
(
'password'
,
'jumpserver'
)
.
set
(
'asset_token'
,
authToken
);
// {
// "authToken": "xxxxxxx",
// "username": "xxxxxx",
// "dataSource": "jumpserver",
// "availableDataSources":[
// "jumpserver"
// ]
// }
return
this
.
http
.
post
(
'/guacamole/api/tokens'
,
return
this
.
http
.
post
(
'/guacamole/api/tokens'
,
body
.
toString
(),
body
.
toString
(),
{
headers
:
new
HttpHeaders
().
set
(
'Content-Type'
,
'application/x-www-form-urlencoded'
)});
{
headers
:
new
HttpHeaders
().
set
(
'Content-Type'
,
'application/x-www-form-urlencoded'
)});
...
@@ -94,12 +103,12 @@ export class HttpService {
...
@@ -94,12 +103,12 @@ export class HttpService {
);
);
}
}
guacamole_token_add_asset
(
token
:
string
)
{
guacamole_token_add_asset
(
assetToken
:
string
,
token
:
string
)
{
const
params
=
new
HttpParams
()
const
params
=
new
HttpParams
()
.
set
(
'asset_token'
,
t
oken
)
.
set
(
'asset_token'
,
assetT
oken
)
.
set
(
'token'
,
DataStore
.
guacamole_
token
);
.
set
(
'token'
,
token
);
return
this
.
http
.
get
(
return
this
.
http
.
get
(
'/guacamole/api/
session/
ext/jumpserver/asset/token/add'
,
'/guacamole/api/ext/jumpserver/asset/token/add'
,
{
{
headers
:
new
HttpHeaders
().
set
(
'Content-Type'
,
'application/x-www-form-urlencoded'
),
headers
:
new
HttpHeaders
().
set
(
'Content-Type'
,
'application/x-www-form-urlencoded'
),
params
:
params
params
:
params
...
@@ -117,6 +126,14 @@ export class HttpService {
...
@@ -117,6 +126,14 @@ export class HttpService {
return
this
.
http
.
get
(
'/api/terminal/v1/sessions/'
+
token
+
'/replay'
);
return
this
.
http
.
get
(
'/api/terminal/v1/sessions/'
+
token
+
'/replay'
);
}
}
get_user_id_from_token
(
token
:
string
)
{
const
params
=
new
HttpParams
()
.
set
(
'user-only'
,
'1'
)
.
set
(
'token'
,
token
);
return
this
.
http
.
get
(
'/api/users/v1/connection-token/'
,
{
params
:
params
});
}
}
}
@
Injectable
()
@
Injectable
()
...
@@ -256,8 +273,9 @@ export class AppService implements OnInit {
...
@@ -256,8 +273,9 @@ export class AppService implements OnInit {
this
.
_router
.
navigate
([
document
.
location
.
pathname
]);
this
.
_router
.
navigate
([
document
.
location
.
pathname
]);
}
}
// jQuery('angular2').show();
// jQuery('angular2').show();
}
else
if
(
document
.
location
.
pathname
===
'/luna/connect'
)
{
User
.
logined
=
true
;
}
else
{
}
else
{
// this.browser();
this
.
_http
.
get_user_profile
()
this
.
_http
.
get_user_profile
()
.
subscribe
(
.
subscribe
(
data
=>
{
data
=>
{
...
@@ -277,11 +295,13 @@ export class AppService implements OnInit {
...
@@ -277,11 +295,13 @@ export class AppService implements OnInit {
}
}
User
.
logined
=
data
[
'logined'
];
User
.
logined
=
data
[
'logined'
];
this
.
_logger
.
debug
(
User
);
this
.
_logger
.
debug
(
User
);
this
.
_localStorage
.
set
(
'user'
,
data
[
'id'
]);
},
},
err
=>
{
err
=>
{
// this._logger.error(err);
// this._logger.error(err);
User
.
logined
=
false
;
User
.
logined
=
false
;
window
.
location
.
href
=
document
.
location
.
origin
+
'/users/login?next='
+
document
.
location
.
pathname
;
window
.
location
.
href
=
document
.
location
.
origin
+
'/users/login?next='
+
document
.
location
.
pathname
+
document
.
location
.
search
;
// this._router.navigate(['login']);
// this._router.navigate(['login']);
},
},
// () => {
// () => {
...
...
src/app/connect-page/connect-page.component.html
View file @
d5acdb9b
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
*
ngIf=
"system =='linux'"
>
*
ngIf=
"system =='linux'"
>
</app-element-term>
</app-element-term>
<app-element-guacamole
<app-element-guacamole
[
t
oken
]="
token
"
[
t
arget
]="
target
"
[
index
]="
0
"
[
index
]="
0
"
*
ngIf=
"system=='windows'"
>
*
ngIf=
"system=='windows'
&& target
"
>
</app-element-guacamole>
</app-element-guacamole>
src/app/connect-page/connect-page.component.ts
View file @
d5acdb9b
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
AppService
}
from
'../app.service'
;
import
{
AppService
,
HttpService
,
LocalStorageService
}
from
'../app.service'
;
import
{
DataStore
}
from
'../globals'
;
import
{
DataStore
}
from
'../globals'
;
import
*
as
jQuery
from
'jquery/dist/jquery.min.js'
;
import
*
as
jQuery
from
'jquery/dist/jquery.min.js'
;
...
@@ -11,8 +11,14 @@ import * as jQuery from 'jquery/dist/jquery.min.js';
...
@@ -11,8 +11,14 @@ import * as jQuery from 'jquery/dist/jquery.min.js';
export
class
ConnectPageComponent
implements
OnInit
{
export
class
ConnectPageComponent
implements
OnInit
{
token
:
string
;
token
:
string
;
system
:
string
;
system
:
string
;
authToken
:
string
;
userid
:
string
;
target
:
string
;
base
:
string
;
constructor
(
private
_appService
:
AppService
)
{
constructor
(
private
_appService
:
AppService
,
private
_http
:
HttpService
,
private
_localStorage
:
LocalStorageService
)
{
DataStore
.
NavShow
=
false
;
DataStore
.
NavShow
=
false
;
}
}
...
@@ -22,6 +28,65 @@ export class ConnectPageComponent implements OnInit {
...
@@ -22,6 +28,65 @@ export class ConnectPageComponent implements OnInit {
jQuery
(
'body'
).
css
(
'background-color'
,
'black'
);
jQuery
(
'body'
).
css
(
'background-color'
,
'black'
);
this
.
userid
=
this
.
_localStorage
.
get
(
'user-'
+
this
.
token
);
this
.
authToken
=
this
.
_localStorage
.
get
(
'authToken-'
+
this
.
token
);
this
.
base
=
this
.
_localStorage
.
get
(
'base-'
+
this
.
token
);
if
(
this
.
system
===
'windows'
)
{
if
(
!
this
.
userid
)
{
this
.
_http
.
get_user_id_from_token
(
this
.
token
)
.
subscribe
(
data
=>
{
this
.
_localStorage
.
set
(
'user-'
+
this
.
token
,
data
[
'user'
]);
this
.
userid
=
data
[
'user'
];
this
.
getAuthToken
();
}
);
}
else
{
this
.
getAuthToken
();
}
}
}
getAuthToken
()
{
if
(
!
this
.
authToken
)
{
this
.
_http
.
get_guacamole_token
(
this
.
userid
,
this
.
token
).
subscribe
(
data
=>
{
if
(
data
[
'authToken'
])
{
this
.
_localStorage
.
set
(
'authToken-'
+
this
.
token
,
data
[
'authToken'
]);
this
.
authToken
=
data
[
'authToken'
];
this
.
getBase
();
}
}
);
}
else
{
this
.
getBase
();
}
}
getBase
()
{
if
(
!
this
.
base
)
{
this
.
_http
.
guacamole_token_add_asset
(
this
.
token
,
this
.
authToken
).
subscribe
(
data
=>
{
if
(
data
[
'result'
])
{
this
.
_localStorage
.
set
(
'base-'
+
this
.
token
,
data
[
'result'
]);
this
.
base
=
data
[
'result'
];
this
.
setWinTarget
();
}
});
}
else
{
this
.
setWinTarget
();
}
}
setWinTarget
()
{
if
(
this
.
base
&&
this
.
authToken
)
{
this
.
target
=
document
.
location
.
origin
+
'/guacamole/#/client/'
+
this
.
base
+
'?asset_token=jumpserver&token='
+
this
.
authToken
;
}
else
{
window
.
location
.
reload
();
}
}
}
}
}
src/app/elements/guacamole/guacamole.component.ts
View file @
d5acdb9b
...
@@ -14,11 +14,11 @@ import {NavList} from '../../ControlPage/control/control.component';
...
@@ -14,11 +14,11 @@ import {NavList} from '../../ControlPage/control/control.component';
export
class
ElementGuacamoleComponent
implements
OnInit
{
export
class
ElementGuacamoleComponent
implements
OnInit
{
@
Input
()
host
:
any
;
@
Input
()
host
:
any
;
@
Input
()
userid
:
any
;
@
Input
()
userid
:
any
;
@
Input
()
t
oken
:
string
;
@
Input
()
t
arget
:
string
;
@
Input
()
index
:
number
;
@
Input
()
index
:
number
;
target
:
string
;
@
ViewChild
(
'rdp'
)
el
:
ElementRef
;
@
ViewChild
(
'rdp'
)
el
:
ElementRef
;
constructor
(
private
sanitizer
:
DomSanitizer
,
constructor
(
private
sanitizer
:
DomSanitizer
,
private
_http
:
HttpService
,
private
_http
:
HttpService
,
private
_cookie
:
CookieService
,
private
_cookie
:
CookieService
,
...
@@ -27,20 +27,7 @@ export class ElementGuacamoleComponent implements OnInit {
...
@@ -27,20 +27,7 @@ export class ElementGuacamoleComponent implements OnInit {
ngOnInit
()
{
ngOnInit
()
{
// /guacamole/api/tokens will redirect to http://guacamole/api/tokens
// /guacamole/api/tokens will redirect to http://guacamole/api/tokens
if
(
this
.
token
)
{
if
(
!
this
.
target
)
{
this
.
_http
.
get_guacamole_token
(
User
.
id
).
subscribe
(
data
=>
{
DataStore
.
guacamole_token
=
data
[
'authToken'
];
this
.
_http
.
guacamole_token_add_asset
(
this
.
token
).
subscribe
(
_
=>
{
this
.
target
=
document
.
location
.
origin
+
'/guacamole/#/client/'
+
data
[
'result'
]
+
'?token='
+
DataStore
.
guacamole_token
;
},
error2
=>
{
this
.
_logger
.
error
(
error2
);
}
);
});
}
else
{
const
base
=
window
.
btoa
(
this
.
host
.
id
+
'
\
0'
+
'c'
+
'
\
0'
+
'jumpserver'
);
const
base
=
window
.
btoa
(
this
.
host
.
id
+
'
\
0'
+
'c'
+
'
\
0'
+
'jumpserver'
);
if
(
environment
.
production
)
{
if
(
environment
.
production
)
{
if
(
DataStore
.
guacamole_token
)
{
if
(
DataStore
.
guacamole_token
)
{
...
@@ -53,7 +40,7 @@ export class ElementGuacamoleComponent implements OnInit {
...
@@ -53,7 +40,7 @@ export class ElementGuacamoleComponent implements OnInit {
}
}
);
);
}
else
{
}
else
{
this
.
_http
.
get_guacamole_token
(
User
.
id
).
subscribe
(
this
.
_http
.
get_guacamole_token
(
User
.
id
,
''
).
subscribe
(
data
=>
{
data
=>
{
// /guacamole/client will redirect to http://guacamole/#/client
// /guacamole/client will redirect to http://guacamole/#/client
DataStore
.
guacamole_token
=
data
[
'authToken'
];
DataStore
.
guacamole_token
=
data
[
'authToken'
];
...
@@ -66,7 +53,6 @@ export class ElementGuacamoleComponent implements OnInit {
...
@@ -66,7 +53,6 @@ export class ElementGuacamoleComponent implements OnInit {
this
.
_logger
.
error
(
error2
);
this
.
_logger
.
error
(
error2
);
}
}
);
);
// '/guacamole/#/client/' + base + '?token=' + data['authToken'];
},
},
error2
=>
{
error2
=>
{
this
.
_logger
.
error
(
error2
);
this
.
_logger
.
error
(
error2
);
...
...
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