Commit 25ba0d20 authored by zheng liu's avatar zheng liu

Merged in dev (pull request #66)

feat: support new guacamole plugin
parents f4742776 ab420fbc
......@@ -70,17 +70,26 @@ export class HttpService {
return this.http.get<Array<HostGroup>>('/api/perms/v1/user/nodes-assets/');
}
get_guacamole_token(username: string, assetID: string, systemUserID: string) {
get_guacamole_token(username: string) {
const body = new HttpParams()
.set('username', username)
.set('password', 'jumpserver')
.set('asset_id', assetID)
.set('system_user_id', systemUserID);
.set('password', 'jumpserver');
return this.http.post('/guacamole/api/tokens',
body.toString(),
{headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')});
}
guacamole_add_asset(user_id: string, asset_id: string, system_user_id: string) {
const body = new HttpParams()
.set('user_id', user_id)
.set('asset_id', asset_id)
.set('system_user_id', system_user_id)
.set('token', DataStore.guacamole_token);
return this.http.post('/guacamole/api/session/ext/jumpserver/asset/add',
body.toString(),
{headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')});
}
search(q: string) {
return this.http.get('/api/search?q=' + q);
}
......
......@@ -29,14 +29,29 @@ export class ElementGuacamoleComponent implements OnInit {
const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver');
if (environment.production) {
if (DataStore.guacamole_token) {
this.target = document.location.origin + '/guacamole/#/client/' + base + '?token=' + DataStore.guacamole_token;
this._http.guacamole_add_asset(User.id, this.host.id, this.userid).subscribe(
data => {
this.target = document.location.origin + '/guacamole/#/client/' + base + '?token=' + DataStore.guacamole_token;
},
error2 => {
this._logger.error(error2);
}
);
} else {
this._http.get_guacamole_token(User.name, this.host.id, this.userid).subscribe(
this._http.get_guacamole_token(User.id).subscribe(
data => {
// /guacamole/client will redirect to http://guacamole/#/client
this.target = document.location.origin +
'/guacamole/#/client/' + base + '?token=' + data['authToken'];
DataStore.guacamole_token = data['authToken'];
this._http.guacamole_add_asset(User.id, this.host.id, this.userid).subscribe(
data2 => {
this.target = document.location.origin + '/guacamole/#/client/' + base + '?token=' + DataStore.guacamole_token;
},
error2 => {
this._logger.error(error2);
}
);
// '/guacamole/#/client/' + base + '?token=' + data['authToken'];
},
error2 => {
this._logger.error(error2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment