1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {Component, OnInit} from '@angular/core';
import {AppService, HttpService, LocalStorageService} from '../app.service';
import {DataStore} from '../globals';
import * as jQuery from 'jquery/dist/jquery.min.js';
@Component({
selector: 'app-connect-page',
templateUrl: './connect-page.component.html',
styleUrls: ['./connect-page.component.scss']
})
export class ConnectPageComponent implements OnInit {
token: string;
system: string;
authToken: string;
userid: string;
target: string;
base: string;
constructor(private _appService: AppService,
private _http: HttpService,
private _localStorage: LocalStorageService) {
DataStore.NavShow = false;
}
ngOnInit() {
this.system = this._appService.getQueryString('system');
this.token = this._appService.getQueryString('token');
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();
}
}
}