Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions src/app/elements/connect/connect.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
import {connectEvt} from '@app/globals';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { connectEvt } from '@app/globals';
import {
AlertService,
AppService,
Expand All @@ -10,18 +10,17 @@ import {
SettingService,
ViewService
} from '@app/services';
import {Account, Asset, ConnectData, ConnectionToken, View} from '@app/model';
import {launchLocalApp} from '@app/utils/common';
import {ElementConnectDialogComponent} from '@app/elements/connect/connect-dialog/connect-dialog.component';
import {NzModalService} from 'ng-zorro-antd/modal';
import {ElementDownloadDialogComponent} from './download-dialog/download-dialog.component';
import {firstValueFrom} from 'rxjs';

import { Account, Asset, ConnectData, ConnectionToken, View } from '@app/model';
import { launchLocalApp } from '@app/utils/common';
import { ElementConnectDialogComponent } from '@app/elements/connect/connect-dialog/connect-dialog.component';
import { NzModalService } from 'ng-zorro-antd/modal';
import { ElementDownloadDialogComponent } from './download-dialog/download-dialog.component';
import { firstValueFrom } from 'rxjs';

@Component({
standalone: false,
selector: 'elements-connect',
templateUrl: 'connect.component.html',
templateUrl: 'connect.component.html'
})
export class ElementConnectComponent implements OnInit, OnDestroy {
@Output() onNewView: EventEmitter<View> = new EventEmitter<View>();
Expand All @@ -32,17 +31,17 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
accounts: Array<Account>;
preConnectData: ConnectData;

constructor(private _appSvc: AppService,
private _alert: AlertService,
private _dialog: NzModalService,
private _logger: LogService,
private _http: HttpService,
private _connectTokenSvc: ConnectTokenService,
private _i18n: I18nService,
private _settingSvc: SettingService,
public viewSrv: ViewService,
) {
}
constructor(
private _appSvc: AppService,
private _alert: AlertService,
private _dialog: NzModalService,
private _logger: LogService,
private _http: HttpService,
private _connectTokenSvc: ConnectTokenService,
private _i18n: I18nService,
private _settingSvc: SettingService,
public viewSrv: ViewService
) {}

ngOnInit(): void {
this.subscribeConnectEvent();
Expand Down Expand Up @@ -87,7 +86,7 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
const idObject = {};
const idList = id.split('&');
for (const element of idList) {
idObject[element.split('=')[0]] = (element.split('=')[1]);
idObject[element.split('=')[0]] = element.split('=')[1];
}
return idObject;
}
Expand Down Expand Up @@ -123,7 +122,9 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
*/
async connectAsset(asset: Asset, splitConnect = false) {
if (!asset) {
const msg = this._i18n.instant('Asset not found or You have no permission to access it, please refresh asset tree');
const msg = this._i18n.instant(
'Asset not found or You have no permission to access it, please refresh asset tree'
);
const title = await this._i18n.instant('Permission expired');
await this._alert.error(msg, title);
return;
Expand Down Expand Up @@ -153,13 +154,6 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
return;
}

// if (connToken.protocol === 'k8s') {
// const url = `${window.location.protocol}//${window.location.host}/luna/k8s/${connToken.id}?asset=${asset.id}`;
// window.open(url);
// return;
// console.log('k8s', this.viewSrv)
// }

// 分屏连接
if (splitConnect) {
return this.currentWebSubView(asset, connectInfo, connToken);
Expand All @@ -177,7 +171,11 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
}

if (connectInfo.downloadRDP) {
return this._http.downloadRDPFile(connToken, this._settingSvc.setting, connectInfo.connectOption);
return this._http.downloadRDPFile(
connToken,
this._settingSvc.setting,
connectInfo.connectOption
);
} else if (connectMethod.type === 'native') {
this.callLocalClient(connToken).then();
} else if (connectMethod.type === 'applet' && appletConnectMethod === 'client') {
Expand All @@ -192,25 +190,25 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
if (connToken.connect_options.token_reusable) {
await this._connectTokenSvc.setReusable(connToken, true).toPromise();
}
const response = await firstValueFrom(this._http.getLocalClientUrl(connToken, this._settingSvc.setting));
const response = await firstValueFrom(
this._http.getLocalClientUrl(connToken, this._settingSvc.setting)
);
const url = response['url'];
launchLocalApp(url, () => {
const downLoadStatus = localStorage.getItem('hasDownLoadApp');
if (downLoadStatus !== '1') {
this._dialog.create({
nzTitle: this._i18n.instant('DownloadClient'),
nzContent: ElementDownloadDialogComponent,
nzOnOk: (cmp => cmp.onConfirm()),
nzOnCancel: (cmp => cmp.onCancel()),
nzOnOk: cmp => cmp.onConfirm(),
nzOnCancel: cmp => cmp.onCancel()
});
}
});
}


createWebView(asset: Asset, connectInfo: any, connToken: ConnectionToken) {
const view = new View(asset, connectInfo, connToken, 'node');
console.log('createWebView', view);
this.onNewView.emit(view);
}

Expand All @@ -224,6 +222,7 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
this._logger.debug('No account or node');
return false;
}

if (!preData.autoLogin) {
this._logger.debug('Not auto login');
return false;
Expand All @@ -237,16 +236,20 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
const account = accounts.find(item => {
return item.alias === preAccount.alias;
});

if (!account) {
this._logger.debug('Account may be not valid');
return false;
}

// 验证登录信息
const preAuth = preData.manualAuthInfo;

if (!account.has_secret && (!preAuth || !preAuth.secret)) {
this._logger.debug('Account no manual auth');
return false;
}

// 验证连接方式
const connectMethods = this._appSvc.getProtocolConnectMethods(preData.protocol.name);
if (!connectMethods) {
Expand Down Expand Up @@ -286,7 +289,7 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
nzCentered: true,
nzClassName: 'connect-dialog',
nzWrapClassName: 'connect-dialog-wrap',
nzFooter: null,
nzFooter: null
});

return new Promise<ConnectData>(resolve => {
Expand Down
75 changes: 41 additions & 34 deletions src/app/services/app.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {Injectable} from '@angular/core';
import {Router} from '@angular/router';
import {CookieService} from 'ngx-cookie-service';
import {environment} from '@src/environments/environment';
import {DataStore, User} from '@app/globals';
import {HttpService} from './http';
import {LocalStorageService, LogService} from './share';
import {SettingService} from '@app/services/setting';
import {Account, Asset, AuthInfo, ConnectData, Endpoint, Organization, View} from '@app/model';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { CookieService } from 'ngx-cookie-service';
import { environment } from '@src/environments/environment';
import { DataStore, User } from '@app/globals';
import { HttpService } from './http';
import { LocalStorageService, LogService } from './share';
import { SettingService } from '@app/services/setting';
import { Account, Asset, AuthInfo, ConnectData, Endpoint, Organization, View } from '@app/model';
import * as CryptoJS from 'crypto-js';
import {OrganizationService} from './organization';
import {I18nService} from '@app/services/i18n';
import { OrganizationService } from './organization';
import { I18nService } from '@app/services/i18n';

declare function unescape(s: string): string;

Expand All @@ -34,14 +34,16 @@ export class AppService {
private newLoginHasOpen = false; // 避免多次打开新登录页
private checkSecond = 120;

constructor(private _http: HttpService,
private _router: Router,
private _cookie: CookieService,
private _i18n: I18nService,
private _logger: LogService,
private _settingSvc: SettingService,
private _localStorage: LocalStorageService,
private _orgSvc: OrganizationService) {
constructor(
private _http: HttpService,
private _router: Router,
private _cookie: CookieService,
private _i18n: I18nService,
private _logger: LogService,
private _settingSvc: SettingService,
private _localStorage: LocalStorageService,
private _orgSvc: OrganizationService
) {
this.setLogLevel();
this.setOrgFromQueryString();
this.checkLogin();
Expand All @@ -62,7 +64,7 @@ export class AppService {
setOrgFromQueryString() {
const oid = this.getQueryString('oid');
if (oid) {
const currentOrg: Organization = {id: oid, name: ''};
const currentOrg: Organization = { id: oid, name: '' };
this._orgSvc.switchOrg(currentOrg);
}
}
Expand Down Expand Up @@ -127,9 +129,9 @@ export class AppService {

getErrorMsg(status: string) {
const messages = {
'unauthorized': 'LoginExpireMsg',
'badrequest': 'Bad request. The server does not understand the syntax of the request',
'error': 'The server encountered an error while trying to process the request'
unauthorized: 'LoginExpireMsg',
badrequest: 'Bad request. The server does not understand the syntax of the request',
error: 'The server encountered an error while trying to process the request'
};
return messages[status];
}
Expand Down Expand Up @@ -168,7 +170,6 @@ export class AppService {

this._http.getUserProfile().then(
user => {
console.log('User is: ', user);
this._orgSvc.setWorkbenchOrgs(user['workbench_orgs']);
Object.assign(User, user);
User.logined = true;
Expand All @@ -182,7 +183,7 @@ export class AppService {
gotoLogin();
}
// this._router.navigate(['login']);
},
}
);
}

Expand Down Expand Up @@ -237,17 +238,17 @@ export class AppService {
}

setPreConnectData(asset: Asset, connectData: ConnectData) {
const {account, protocol, connectMethod, manualAuthInfo, connectOption} = connectData;
const { account, protocol, connectMethod, manualAuthInfo, connectOption } = connectData;
const key = `JMS_PRE_${asset.id}`;

const saveData = {
account: {alias: account.alias, username: account.username, has_secret: account.has_secret},
connectMethod: {value: connectMethod.value},
protocol: {name: protocol.name},
account: { alias: account.alias, username: account.username, has_secret: account.has_secret },
connectMethod: { value: connectMethod.value },
protocol: { name: protocol.name },
downloadRDP: connectData.downloadRDP,
autoLogin: connectData.autoLogin,
connectOption,
direct: connectData.direct,
direct: connectData.direct
};
this.setAccountLocalAuth(asset, account, manualAuthInfo);
this._localStorage.set(key, saveData);
Expand Down Expand Up @@ -330,7 +331,13 @@ export class AppService {

setAccountLocalAuth(asset: Asset, account: Account, auth: AuthInfo) {
const assetId = asset.id;
const newAuth = Object.assign({alias: account.alias, username: account.username}, auth);
const newAuth = Object.assign({ alias: account.alias, username: account.username }, auth);

// 如果 auth.alias 是 undefined,保持使用 account.alias
if (auth.alias === undefined && account.alias !== undefined) {
newAuth.alias = account.alias;
}

if (!auth.secret || !auth.rememberAuth) {
newAuth.secret = '';
} else {
Expand All @@ -340,7 +347,7 @@ export class AppService {
let auths = this.getAccountLocalAuth(assetId, false);
const localKey = `JMS_MA_${assetId}`;

auths = auths.filter((item) => item.username !== newAuth.username);
auths = auths.filter(item => item.username !== newAuth.username);
auths.splice(0, 0, newAuth);
this._localStorage.set(localKey, auths);
}
Expand All @@ -355,7 +362,7 @@ export class AppService {
if (protocol === 'http') {
protocol = window.location.protocol.replace(':', '');
}
const data = {'assetId': '', 'sessionId': '', 'token': ''};
const data = { assetId: '', sessionId: '', token: '' };
if (view.connectToken) {
data['token'] = view.connectToken.id;
} else {
Expand All @@ -369,7 +376,7 @@ export class AppService {
}
}
const res = this._http.getSmartEndpoint(data, protocol);
res.catch((err) => {
res.catch(err => {
alert(err.error.detail);
});
return res;
Expand Down