Unverified Commit 30546d2e authored by liuzheng's avatar liuzheng Committed by liuzheng712

fix: update

parent 00ee9f1e
......@@ -4,7 +4,7 @@
*ngIf="system =='linux'">
</app-element-term>
<app-element-guacamole
[token]="token"
[target]="target"
[index]="0"
*ngIf="system=='windows'">
</app-element-guacamole>
import {Component, OnInit} from '@angular/core';
import {AppService} from '../app.service';
import {AppService, HttpService, LocalStorageService} from '../app.service';
import {DataStore} from '../globals';
import * as jQuery from 'jquery/dist/jquery.min.js';
......@@ -11,8 +11,15 @@ import * as jQuery from 'jquery/dist/jquery.min.js';
export class ConnectPageComponent implements OnInit {
token: string;
system: string;
authToken: string;
userid: string;
target: string;
base: string;
time: number;
constructor(private _appService: AppService) {
constructor(private _appService: AppService,
private _http: HttpService,
private _localStorage: LocalStorageService) {
DataStore.NavShow = false;
}
......@@ -22,6 +29,61 @@ export class ConnectPageComponent implements OnInit {
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);
this.time = 0;
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.time = this.time + 1;
}
);
} else {
this.time = this.time + 1;
}
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.time = this.time + 1;
}
}
);
} else {
this.time = this.time + 1;
}
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.time = this.time + 1;
}
});
} else {
this.time = this.time + 1;
}
setTimeout(() => {
if (this.time === 3) {
if (this.authToken && this.base) {
this.target = document.location.origin + '/guacamole/#/client/' + this.base +
'?asset_token=jumpserver&token=' + this.authToken;
}
}
},
50
);
}
}
}
......@@ -14,13 +14,10 @@ import {NavList} from '../../ControlPage/control/control.component';
export class ElementGuacamoleComponent implements OnInit {
@Input() host: any;
@Input() userid: any;
@Input() token: string;
@Input() target: string;
@Input() index: number;
target: string;
@ViewChild('rdp') el: ElementRef;
authToken: string;
base: string;
time: number;
constructor(private sanitizer: DomSanitizer,
private _http: HttpService,
......@@ -31,62 +28,7 @@ export class ElementGuacamoleComponent implements OnInit {
ngOnInit() {
// /guacamole/api/tokens will redirect to http://guacamole/api/tokens
if (this.token) {
this.userid = this._localStorage.get('user-' + this.token);
this.authToken = this._localStorage.get('authToken-' + this.token);
this.base = this._localStorage.get('base-' + this.token);
this.time = 0;
if (!this.userid) {
this._http.get_user_id_from_token(this.token)
.subscribe(
data => {
this._localStorage.set('user-' + this.token, data['user']);
this.time = this.time + 1;
}
);
} else {
this.time = this.time + 1;
}
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.time = this.time + 1;
}
}
);
} else {
this.time = this.time + 1;
}
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.time = this.time + 1;
}
});
} else {
this.time = this.time + 1;
}
setTimeout(() => {
if (this.time === 3) {
if (this.authToken && this.base) {
this.target = document.location.origin + '/guacamole/#/client/' + this.base +
'?asset_token=jumpserver&token=' + this.authToken;
} else {
window.location.reload();
}
}
},
50
);
} else {
if (!this.target) {
const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver');
if (environment.production) {
if (DataStore.guacamole_token) {
......
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