Unverified Commit fed8a11a authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #140 from jumpserver/dev

Dev
parents d0802946 c583d387
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
<ul id="remoteAppsTree" class="ztree"> <ul id="remoteAppsTree" class="ztree">
</ul> </ul>
<ul id="DBAppsTree" class="ztree">
</ul>
</div> </div>
......
...@@ -42,6 +42,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -42,6 +42,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
expandNodes: any; expandNodes: any;
assetsTree: any; assetsTree: any;
remoteAppsTree: any; remoteAppsTree: any;
DBAppsTree: any;
isShowRMenu = false; isShowRMenu = false;
rightClickSelectNode: any; rightClickSelectNode: any;
hasLoginTo = false; hasLoginTo = false;
...@@ -127,7 +128,20 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -127,7 +128,20 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
this.remoteAppsTree.destroy(); this.remoteAppsTree.destroy();
this.initRemoteAppsTree(); this.initRemoteAppsTree();
} }
refreshDBAppsTree() {
this.DBAppsTree.destroy();
this.initDBAppsTree();
}
onDBAppsTreeNodeClick(event, treeId, treeNode, clickFlag) {
if (treeNode.isParent) {
this.DBAppsTree.expandNode(treeNode);
} else {
this._http.getUserProfile().subscribe();
this.connectAsset(treeNode);
}
}
onRemoteAppsNodeClick(event, treeId, treeNode, clickFlag) { onRemoteAppsNodeClick(event, treeId, treeNode, clickFlag) {
if (treeNode.isParent) { if (treeNode.isParent) {
this.remoteAppsTree.expandNode(treeNode); this.remoteAppsTree.expandNode(treeNode);
...@@ -156,17 +170,37 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -156,17 +170,37 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
} }
); );
} }
initDBAppsTree() {
const setting = Object.assign({}, this.setting);
setting['callback'] = {
onClick: this.onDBAppsTreeNodeClick.bind(this),
onRightClick: this.onRightClick.bind(this)
};
this._http.getMyGrantedDBApps().subscribe(
resp => {
if (resp.length === 1) {
return;
}
const tree = $.fn.zTree.init($('#DBAppsTree'), setting, resp);
this.DBAppsTree = tree;
this.rootNodeAddDom(tree, () => {
this.refreshDBAppsTree();
});
}
);
}
initTree() { initTree() {
this.initAssetsTree(); this.initAssetsTree();
this.initRemoteAppsTree(); this.initRemoteAppsTree();
this.initDBAppsTree();
} }
connectAsset(node: TreeNode) { connectAsset(node: TreeNode) {
const evt = new ConnectEvt(node, 'asset'); const evt = new ConnectEvt(node, 'asset');
connectEvt.next(evt); connectEvt.next(evt);
} }
rootNodeAddDom(ztree, callback) { rootNodeAddDom(ztree, callback) {
const tId = ztree.setting.treeId + '_tree_refresh'; const tId = ztree.setting.treeId + '_tree_refresh';
const refreshIcon = '<a id=' + tId + ' class="tree-refresh">' + const refreshIcon = '<a id=' + tId + ' class="tree-refresh">' +
......
...@@ -83,6 +83,9 @@ export class ElementConnectComponent implements OnInit, OnDestroy { ...@@ -83,6 +83,9 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
case 'remote_app': case 'remote_app':
this.connectRemoteApp(node); this.connectRemoteApp(node);
break; break;
case 'database_app':
this.connectDatabaseApp(node);
break;
default: default:
alert('Unknown type: ' + node.meta.type); alert('Unknown type: ' + node.meta.type);
} }
...@@ -100,6 +103,18 @@ export class ElementConnectComponent implements OnInit, OnDestroy { ...@@ -100,6 +103,18 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
} }
} }
async connectDatabaseApp(node: TreeNode) {
this._logger.debug('Connect remote app: ', node.id);
const systemUsers = await this._http.getMyDatabaseAppSystemUsers(node.id).toPromise();
let sysUser = await this.selectLoginSystemUsers(systemUsers);
sysUser = await this.manualSetUserAuthLoginIfNeed(sysUser);
if (sysUser && sysUser.id) {
this.loginDatabaseApp(node, sysUser);
} else {
alert('该主机没有授权系统用户');
}
}
selectLoginSystemUsers(systemUsers: Array<SystemUser>): Promise<SystemUser> { selectLoginSystemUsers(systemUsers: Array<SystemUser>): Promise<SystemUser> {
const systemUserMaxPriority = this.filterMaxPrioritySystemUsers(systemUsers); const systemUserMaxPriority = this.filterMaxPrioritySystemUsers(systemUsers);
let user: SystemUser; let user: SystemUser;
...@@ -184,6 +199,20 @@ export class ElementConnectComponent implements OnInit, OnDestroy { ...@@ -184,6 +199,20 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
this.onNewView.emit(view); this.onNewView.emit(view);
} }
} }
loginDatabaseApp(node: TreeNode, user: SystemUser) {
if (node) {
const view = new View();
view.host = node;
view.nick = node.name;
view.connected = true;
view.editable = false;
view.closed = false;
view.DatabaseApp = node.id;
view.user = user;
view.type = 'database';
this.onNewView.emit(view);
}
}
connectFileManager(node: TreeNode) { connectFileManager(node: TreeNode) {
const host = node.meta.asset as Asset; const host = node.meta.asset as Asset;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
[view]="view" [view]="view"
[host]="view.host" [host]="view.host"
[sysUser]="view.user" [sysUser]="view.user"
*ngIf="view.type=='ssh'" *ngIf="view.type=='ssh' || view.type=='database'"
> >
</elements-ssh-term> </elements-ssh-term>
<elements-guacamole <elements-guacamole
......
...@@ -34,7 +34,7 @@ export class ElementSshTermComponent implements OnInit, OnDestroy { ...@@ -34,7 +34,7 @@ export class ElementSshTermComponent implements OnInit, OnDestroy {
this.ws = sock; this.ws = sock;
this.connectHost(); this.connectHost();
}); });
this.view.type = 'ssh'; // this.view.type = 'ssh';
} }
newTerm() { newTerm() {
...@@ -74,7 +74,8 @@ export class ElementSshTermComponent implements OnInit, OnDestroy { ...@@ -74,7 +74,8 @@ export class ElementSshTermComponent implements OnInit, OnDestroy {
uuid: this.host.id, uuid: this.host.id,
userid: this.sysUser.id, userid: this.sysUser.id,
secret: this.secret, secret: this.secret,
size: [this.term.cols, this.term.rows] size: [this.term.cols, this.term.rows],
type: this.view.type
}; };
this.ws.emit('host', data); this.ws.emit('host', data);
} }
......
...@@ -116,6 +116,7 @@ export class View { ...@@ -116,6 +116,7 @@ export class View {
room: string; room: string;
Rdp: any; Rdp: any;
Term: any; Term: any;
DatabaseApp: string;
} }
export class ViewAction { export class ViewAction {
......
...@@ -99,11 +99,24 @@ export class HttpService { ...@@ -99,11 +99,24 @@ export class HttpService {
return this.http.get<Array<TreeNode>>(url); return this.http.get<Array<TreeNode>>(url);
} }
getMyGrantedDBApps(id?: string) {
let url = '/api/v1/perms/user/database-apps/tree/';
if (id) {
url += `?id=${id}&only=1`;
}
return this.http.get<Array<TreeNode>>(url);
}
getMyRemoteAppSystemUsers(remoteAppId: string) { getMyRemoteAppSystemUsers(remoteAppId: string) {
const url = `/api/v1/perms/users/remote-apps/${remoteAppId}/system-users/`; const url = `/api/v1/perms/users/remote-apps/${remoteAppId}/system-users/`;
return this.http.get<Array<SystemUser>>(url); return this.http.get<Array<SystemUser>>(url);
} }
getMyDatabaseAppSystemUsers(DatabaseAppId: string) {
const url = `/api/v1/perms/users/database-apps/${DatabaseAppId}/system-users/`;
return this.http.get<Array<SystemUser>>(url);
}
getMyAssetSystemUsers(assetId: string) { getMyAssetSystemUsers(assetId: string) {
const url = `/api/v1/perms/users/assets/${assetId}/system-users/`; const url = `/api/v1/perms/users/assets/${assetId}/system-users/`;
return this.http.get<Array<SystemUser>>(url); return this.http.get<Array<SystemUser>>(url);
...@@ -122,12 +135,10 @@ export class HttpService { ...@@ -122,12 +135,10 @@ export class HttpService {
return this.delete(url); return this.delete(url);
} }
} }
getFavoriteAssets() { getFavoriteAssets() {
const url = '/api/v1/assets/favorite-assets/'; const url = '/api/v1/assets/favorite-assets/';
return this.http.get<Array<any>>(url); return this.http.get<Array<any>>(url);
} }
getGuacamoleToken(user_id: string, authToken: string) { getGuacamoleToken(user_id: string, authToken: string) {
const body = new HttpParams() const body = new HttpParams()
.set('username', user_id) .set('username', user_id)
......
...@@ -2,5 +2,5 @@ export const environment = { ...@@ -2,5 +2,5 @@ export const environment = {
production: true production: true
}; };
// export const version = '1.3.0-{{BUILD_NUMBER}} GPLv2.'; // export const version = '1.3.0-{{BUILD_NUMBER}} GPLv2.';
export const version = '1.5.5-101 GPLv2.'; export const version = '1.5.6-101 GPLv2.';
// export const version = '1.4.1-{{BUILD_NUMBER}} GPLv2.'; // export const version = '1.4.1-{{BUILD_NUMBER}} GPLv2.';
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