Unverified Commit 8ee3124e authored by 老广's avatar 老广 Committed by GitHub

[Update] remote app可以填写密码 (#97)

parent c6b443be
...@@ -106,11 +106,12 @@ export class HttpService { ...@@ -106,11 +106,12 @@ export class HttpService {
.set('asset_id', asset_id) .set('asset_id', asset_id)
.set('system_user_id', system_user_id) .set('system_user_id', system_user_id)
.set('token', DataStore.guacamole_token); .set('token', DataStore.guacamole_token);
let body = new HttpParams();
if (system_user_username) { if (system_user_username) {
params = params.set('username', system_user_username); body = body.set('username', system_user_username);
} }
if (system_user_password) { if (system_user_password) {
params = params.set('password', system_user_password); body = body.set('password', system_user_password);
} }
const solution = localStorage.getItem('rdpSolution') || 'Auto'; const solution = localStorage.getItem('rdpSolution') || 'Auto';
if (solution !== 'Auto') { if (solution !== 'Auto') {
...@@ -119,8 +120,9 @@ export class HttpService { ...@@ -119,8 +120,9 @@ export class HttpService {
params = params.set('width', width).set('height', height); params = params.set('width', width).set('height', height);
} }
return this.http.get<GuacObjAddResp>( return this.http.post<GuacObjAddResp>(
'/guacamole/api/session/ext/jumpserver/asset/add', '/guacamole/api/session/ext/jumpserver/asset/add',
body.toString(),
{ {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'), headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),
params: params params: params
...@@ -128,11 +130,18 @@ export class HttpService { ...@@ -128,11 +130,18 @@ export class HttpService {
); );
} }
guacamole_add_remote_app(user_id: string, remote_app_id: string) { guacamole_add_remote_app(user_id: string, remote_app_id: string, system_user_username?: string, system_user_password?: string) {
let params = new HttpParams() let params = new HttpParams()
.set('user_id', user_id) .set('user_id', user_id)
.set('remote_app_id', remote_app_id) .set('remote_app_id', remote_app_id)
.set('token', DataStore.guacamole_token); .set('token', DataStore.guacamole_token);
let body = new HttpParams();
if (system_user_username) {
body = body.set('username', system_user_username);
}
if (system_user_password) {
body = body.set('password', system_user_password);
}
const solution = localStorage.getItem('rdpSolution') || 'Auto'; const solution = localStorage.getItem('rdpSolution') || 'Auto';
if (solution !== 'Auto') { if (solution !== 'Auto') {
const width = solution.split('x')[0]; const width = solution.split('x')[0];
...@@ -140,8 +149,9 @@ export class HttpService { ...@@ -140,8 +149,9 @@ export class HttpService {
params = params.set('width', width).set('height', height); params = params.set('width', width).set('height', height);
} }
return this.http.get<GuacObjAddResp>( return this.http.post<GuacObjAddResp>(
'/guacamole/api/session/ext/jumpserver/remote-app/add', '/guacamole/api/session/ext/jumpserver/remote-app/add',
body.toString(),
{ {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'), headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),
params: params params: params
......
...@@ -5,6 +5,7 @@ import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material'; ...@@ -5,6 +5,7 @@ import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material';
import {FormControl, Validators} from '@angular/forms'; import {FormControl, Validators} from '@angular/forms';
import {BehaviorSubject} from 'rxjs/BehaviorSubject'; import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {ActivatedRoute} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import * as jQuery from 'jquery/dist/jquery.min';
declare var $: any; declare var $: any;
...@@ -60,16 +61,16 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -60,16 +61,16 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
public _logger: LogService, public _logger: LogService,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private _http: HttpService private _http: HttpService
) { ) {
this.searchEvt$ = new BehaviorSubject<string>(this.query); this.searchEvt$ = new BehaviorSubject<string>(this.query);
} }
getGrantedAssetsNodes() { getGrantedAssetsNodes() {
this._http.get_my_granted_nodes() this._http.get_my_granted_nodes()
.subscribe(response => { .subscribe(response => {
this.Data = [...response, ...this.Data]; this.Data = [...response, ...this.Data];
this.draw(); this.draw();
}); });
} }
refreshGrantedAssetsNodes() { refreshGrantedAssetsNodes() {
...@@ -87,7 +88,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -87,7 +88,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this.Data = [...this.Data, ...response]; this.Data = [...this.Data, ...response];
this.draw(); this.draw();
} }
}); });
} }
ngOnInit() { ngOnInit() {
...@@ -126,16 +127,16 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -126,16 +127,16 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}); });
this.activatedRoute.queryParams.subscribe(params => { this.activatedRoute.queryParams.subscribe(params => {
const login_to = params['login_to']; const login_to = params['login_to'];
if (login_to && !this.hasLoginTo) { if (login_to && !this.hasLoginTo) {
this.Data.forEach(t => { this.Data.forEach(t => {
if (login_to === t.id && t.isParent === false) { if (login_to === t.id && t.isParent === false) {
this.hasLoginTo = true; this.hasLoginTo = true;
this.Connect(t); this.Connect(t);
return; return;
} }
}); });
} }
}); });
} }
...@@ -146,7 +147,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -146,7 +147,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
$rootNodeRef.after(refreshIcon); $rootNodeRef.after(refreshIcon);
const refreshIconRef = $('#tree-refresh'); const refreshIconRef = $('#tree-refresh');
refreshIconRef.bind('click', function () { refreshIconRef.bind('click', function () {
callback(); callback();
}); });
} }
...@@ -165,7 +166,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -165,7 +166,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
onRightClick(event, treeId, treeNode) { onRightClick(event, treeId, treeNode) {
if (!treeNode || treeNode.isParent ) { if (!treeNode || treeNode.isParent) {
return null; return null;
} }
const host = treeNode.meta.asset; const host = treeNode.meta.asset;
...@@ -175,10 +176,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -175,10 +176,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
protocols.push(host.protocol); protocols.push(host.protocol);
} }
for (let i = 0; i < protocols.length; i++) { for (let i = 0; i < protocols.length; i++) {
const protocol = protocols[i]; const protocol = protocols[i];
if (protocol && protocol.startsWith('ssh')) { if (protocol && protocol.startsWith('ssh')) {
findSSHProtocol = true; findSSHProtocol = true;
} }
} }
if (!findSSHProtocol) { if (!findSSHProtocol) {
alert('Windows 请使用Ctrl+Shift+Alt呼出侧边栏上传下载'); alert('Windows 请使用Ctrl+Shift+Alt呼出侧边栏上传下载');
...@@ -193,7 +194,20 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -193,7 +194,20 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this.rightClickSelectNode = treeNode; this.rightClickSelectNode = treeNode;
} }
} }
Connect(node) {
switch (node.meta.type) {
case 'asset':
this.connectAsset(node);
break;
case 'remote_app':
this.connectRemoteApp(node);
break;
default:
alert('Unknown type: ' + node.meta.type);
}
}
connectAsset(node) { connectAsset(node) {
const system_users = node.meta.system_users; const system_users = node.meta.system_users;
const host = node.meta.asset; const host = node.meta.asset;
...@@ -230,30 +244,26 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -230,30 +244,26 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
connectRemoteApp(node) { connectRemoteApp(node) {
const user = node.meta.user;
return this.loginRemoteApp(node, user);
}
loginRemoteApp(node, user) {
const id = NavList.List.length - 1; const id = NavList.List.length - 1;
if (user.login_mode === 'manual' && !user.password && user.protocol === 'rdp') {
return this.manualSetUserAuthLogin(node, user, this.loginRemoteApp);
}
if (node) { if (node) {
NavList.List[id].nick = node.name; NavList.List[id].nick = node.name;
NavList.List[id].connected = true; NavList.List[id].connected = true;
NavList.List[id].edit = false; NavList.List[id].edit = false;
NavList.List[id].closed = false; NavList.List[id].closed = false;
NavList.List[id].remoteApp = node.id; NavList.List[id].remoteApp = node.id;
NavList.List[id].user = user;
NavList.List[id].type = 'rdp'; NavList.List[id].type = 'rdp';
NavList.List.push(new View()); NavList.List.push(new View());
NavList.Active = id; NavList.Active = id;
} jQuery('.tabs').animate({'scrollLeft': 150 * id}, 400);
this._logger.debug(NavList);
}
Connect(node) {
switch (node.meta.type) {
case 'asset':
this.connectAsset(node);
break;
case 'remote_app':
this.connectRemoteApp(node);
break;
default:
alert('Unknown type: ' + node.meta.type);
} }
} }
...@@ -269,8 +279,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -269,8 +279,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
NavList.List[id].type = 'sftp'; NavList.List[id].type = 'sftp';
NavList.List.push(new View()); NavList.List.push(new View());
NavList.Active = id; NavList.Active = id;
jQuery('.tabs').animate({'scrollLeft': 150 * id}, 400);
} }
this._logger.debug(NavList);
} }
connectTerminal() { connectTerminal() {
...@@ -278,7 +288,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -278,7 +288,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this.Connect(host); this.Connect(host);
} }
manualSetUserAuthLogin(host, user) { manualSetUserAuthLogin(host, user, callback) {
user = Object.assign({}, user); user = Object.assign({}, user);
const dialogRef = this._dialog.open(ManualPasswordDialogComponent, { const dialogRef = this._dialog.open(ManualPasswordDialogComponent, {
height: '250px', height: '250px',
...@@ -287,20 +297,18 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -287,20 +297,18 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (!result) { if (!result) {
return; return callback(host, user);
} }
user.username = btoa(result.username); user.username = btoa(result.username);
user.password = btoa(result.password); user.password = btoa(result.password);
return this.login(host, user); return callback(host, user);
}); });
} }
login(host, user) { login(host, user) {
const id = NavList.List.length - 1; const id = NavList.List.length - 1;
this._logger.debug(NavList);
this._logger.debug(host);
if (user.login_mode === 'manual' && !user.password && user.protocol === 'rdp') { if (user.login_mode === 'manual' && !user.password && user.protocol === 'rdp') {
return this.manualSetUserAuthLogin(host, user); return this.manualSetUserAuthLogin(host, user, this.login);
} }
if (user) { if (user) {
NavList.List[id].nick = host.hostname; NavList.List[id].nick = host.hostname;
...@@ -316,8 +324,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -316,8 +324,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
NavList.List.push(new View()); NavList.List.push(new View());
NavList.Active = id; NavList.Active = id;
jQuery('.tabs').animate({'scrollLeft': 150 * id}, 400);
} }
this._logger.debug(NavList);
} }
checkPriority(sysUsers) { checkPriority(sysUsers) {
...@@ -384,7 +392,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -384,7 +392,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
_keywords = _keywords.toLowerCase(); _keywords = _keywords.toLowerCase();
let shouldShow = []; let shouldShow = [];
const matchedNodes = zTreeObj.getNodesByFilter(function(node) { const matchedNodes = zTreeObj.getNodesByFilter(function (node) {
if (node.meta.type === 'asset') { if (node.meta.type === 'asset') {
const host = node.meta.asset; const host = node.meta.asset;
return host.hostname.toLowerCase().indexOf(_keywords) !== -1 || host.ip.indexOf(_keywords) !== -1; return host.hostname.toLowerCase().indexOf(_keywords) !== -1 || host.ip.indexOf(_keywords) !== -1;
...@@ -393,18 +401,18 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -393,18 +401,18 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
}); });
matchedNodes.forEach((node) => { matchedNodes.forEach((node) => {
const parents = this.recurseParent(node); const parents = this.recurseParent(node);
const children = this.recurseChildren(node); const children = this.recurseChildren(node);
shouldShow = [...shouldShow, ...parents, ...children, node]; shouldShow = [...shouldShow, ...parents, ...children, node];
}); });
this.hiddenNodes = nodes; this.hiddenNodes = nodes;
this.expandNodes = shouldShow; this.expandNodes = shouldShow;
zTreeObj.hideNodes(nodes); zTreeObj.hideNodes(nodes);
zTreeObj.showNodes(shouldShow); zTreeObj.showNodes(shouldShow);
shouldShow.forEach((node) => { shouldShow.forEach((node) => {
if (node.isParent) { if (node.isParent) {
zTreeObj.expandNode(node, true); zTreeObj.expandNode(node, true);
} }
}); });
// zTreeObj.expandAll(true); // zTreeObj.expandAll(true);
} }
......
...@@ -29,7 +29,7 @@ export class ElementGuacamoleComponent implements OnInit { ...@@ -29,7 +29,7 @@ export class ElementGuacamoleComponent implements OnInit {
registerHost() { registerHost() {
let action: any; let action: any;
if (this.remoteAppId) { if (this.remoteAppId) {
action = this._http.guacamole_add_remote_app(User.id, this.remoteAppId); action = this._http.guacamole_add_remote_app(User.id, this.remoteAppId, this.sysUser.username, this.sysUser.password);
} else { } else {
action = this._http.guacamole_add_asset(User.id, this.host.id, this.sysUser.id, this.sysUser.username, this.sysUser.password); action = this._http.guacamole_add_asset(User.id, this.host.id, this.sysUser.id, this.sysUser.username, this.sysUser.password);
} }
......
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