Commit 0e3a18f9 authored by ibuler's avatar ibuler

[Update] 修复无法无密码连接remote app

parent 8ee3124e
......@@ -58,31 +58,31 @@ export class HttpService {
return this.http.options(url, options);
}
report_browser() {
reportBrowser() {
return this.http.post('/api/browser', JSON.stringify(Browser));
}
check_login(user: any) {
checkLogin(user: any) {
return this.http.post('/api/checklogin', user);
}
get_user_profile() {
getUserProfile() {
return this.http.get('/api/users/v1/profile/');
}
get_my_granted_nodes() {
getMyGrantedNodes() {
return this.http.get<Array<Node>>('/api/perms/v1/user/nodes-assets/tree/?cache_policy=1');
}
get_my_granted_remote_apps() {
getMyGrantedRemoteApps() {
return this.http.get<Array<Node>>('/api/perms/v1/user/remote-apps/tree/');
}
refresh_my_granted_nodes() {
refreshMyGrantedNodes() {
return this.http.get<Array<Node>>('/api/perms/v1/user/nodes-assets/tree/?cache_policy=2');
}
get_guacamole_token(user_id: string, authToken: string) {
getGuacamoleToken(user_id: string, authToken: string) {
const body = new HttpParams()
.set('username', user_id)
.set('password', 'jumpserver')
......@@ -100,18 +100,17 @@ export class HttpService {
{headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')});
}
guacamole_add_asset(user_id: string, asset_id: string, system_user_id: string, system_user_username?: string, system_user_password?: string) {
guacamoleAddAsset(userId: string, assetId: string, systemUserId: string, systemUserUsername?: string, systemUserPassword?: string) {
let params = new HttpParams()
.set('user_id', user_id)
.set('asset_id', asset_id)
.set('system_user_id', system_user_id)
.set('user_id', userId)
.set('asset_id', assetId)
.set('system_user_id', systemUserId)
.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);
if (systemUserUsername && systemUserPassword) {
systemUserUsername = btoa(systemUserUsername);
systemUserPassword = btoa(systemUserPassword);
body = body.set('username', systemUserUsername).set('password', systemUserPassword);
}
const solution = localStorage.getItem('rdpSolution') || 'Auto';
if (solution !== 'Auto') {
......@@ -130,17 +129,16 @@ export class HttpService {
);
}
guacamole_add_remote_app(user_id: string, remote_app_id: string, system_user_username?: string, system_user_password?: string) {
guacamoleAddRemoteApp(userId: string, remoteAppId: string, systemUserUsername?: string, systemUserPassword?: string) {
let params = new HttpParams()
.set('user_id', user_id)
.set('remote_app_id', remote_app_id)
.set('user_id', userId)
.set('remote_app_id', remoteAppId)
.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);
if (systemUserUsername && systemUserPassword) {
systemUserUsername = btoa(systemUserUsername);
systemUserPassword = btoa(systemUserPassword);
body = body.set('username', systemUserUsername).set('password', systemUserPassword);
}
const solution = localStorage.getItem('rdpSolution') || 'Auto';
if (solution !== 'Auto') {
......@@ -159,7 +157,7 @@ export class HttpService {
);
}
guacamole_token_add_asset(assetToken: string, token: string) {
guacamoleTokenAddAsset(assetToken: string, token: string) {
let params = new HttpParams()
.set('asset_token', assetToken)
.set('token', token);
......@@ -184,7 +182,7 @@ export class HttpService {
return this.http.get('/api/search', {params: params});
}
get_replay(token: string) {
getReplay(token: string) {
return this.http.get('/api/terminal/v1/sessions/' + token + '/replay');
}
......@@ -192,11 +190,11 @@ export class HttpService {
// return this.http.get('/api/terminal/v2/sessions/' + token + '/replay');
// }
get_replay_data(src: string) {
getReplayData(src: string) {
return this.http.get(src);
}
get_user_id_from_token(token: string) {
getUserIdFromToken(token: string) {
const params = new HttpParams()
.set('user-only', '1')
.set('token', token);
......@@ -299,10 +297,10 @@ export class AppService implements OnInit {
this._logger.level = 0;
}
if (environment.production) {
// if (environment.production) {
this._logger.level = 2;
this.checklogin();
}
// }
if (this._cookie.get('lang')) {
this.lang = this._cookie.get('lang');
......@@ -345,7 +343,7 @@ export class AppService implements OnInit {
}
// jQuery('angular2').show();
} else {
this._http.get_user_profile()
this._http.getUserProfile()
.subscribe(
data => {
User.id = data['id'];
......@@ -373,18 +371,6 @@ export class AppService implements OnInit {
document.location.pathname + document.location.search;
// this._router.navigate(['login']);
},
// () => {
// if (User.logined) {
// if (document.location.pathname === '/login') {
// this._router.navigate(['']);
// } else {
// this._router.navigate([document.location.pathname]);
// }
// } else {
// this._router.navigate(['login']);
// }
// jQuery('angular2').show();
// }
);
}
}
......@@ -395,7 +381,7 @@ export class AppService implements OnInit {
}
browser() {
this._http.report_browser();
this._http.reportBrowser();
}
getQueryString(name) {
......@@ -406,124 +392,6 @@ export class AppService implements OnInit {
}
return null;
}
//
//
// HideLeft() {
// DataStore.leftbarhide = true;
//
// DataStore.Nav.map(function (value, i) {
// for (var ii in value['children']) {
// if (DataStore.Nav[i]['children'][ii]['id'] === 'HideLeftManager') {
// DataStore.Nav[i]['children'][ii] = {
// 'id': 'ShowLeftManager',
// 'click': 'ShowLeft',
// 'name': 'Show left manager'
// };
// }
// }
// });
//
// }
//
// ShowLeft() {
// DataStore.leftbarhide = false;
//
// DataStore.Nav.map(function (value, i) {
// for (var ii in value['children']) {
// if (DataStore.Nav[i]['children'][ii]['id'] === 'ShowLeftManager') {
// DataStore.Nav[i]['children'][ii] = {
// 'id': 'HideLeftManager',
// 'click': 'HideLeft',
// 'name': 'Hide left manager'
// };
// }
// }
// });
//
//
// }
//
// setMyinfo(user:User) {
// // Update data store
// this._dataStore.user = user;
// this._logger.log("service.ts:AppService,setMyinfo");
// this._logger.debug(user);
// // Push the new list of todos into the Observable stream
// // this._dataObserver.next(user);
// // this.myinfo$ = new Observable(observer => this._dataObserver = observer).share()
// }
//
// getMyinfo() {
// this._logger.log('service.ts:AppService,getMyinfo');
// return this.http.get('/api/userprofile')
// .map(res => res.json())
// .subscribe(response => {
// DataStore.user = response;
// // this._logger.warn(this._dataStore.user);
// // this._logger.warn(DataStore.user)
// });
// }
//
// getUser(id: string) {
// this._logger.log('service.ts:AppService,getUser');
// return this.http.get('/api/userprofile')
// .map(res => res.json());
// }
//
// gettest() {
// this._logger.log('service.ts:AppService,gettest');
// this.http.get('/api/userprofile')
// .map(res => res.json())
// .subscribe(res => {
// return res;
// });
// }
//
// getGrouplist() {
// this._logger.log('service.ts:AppService,getGrouplist');
// return this.http.get('/api/grouplist')
// .map(res => res.json());
// }
//
// getUserlist(id: string) {
// this._logger.log('service.ts:AppService,getUserlist');
// if (id)
// return this.http.get('/api/userlist/' + id)
// .map(res => res.json());
// else
// return this.http.get('/api/userlist')
// .map(res => res.json());
// }
//
// delGroup(id) {
//
// }
//
//
// copy() {
// var clipboard = new Clipboard('#Copy');
//
// clipboard.on('success', function (e) {
// console.info('Action:', e.action);
// console.info('Text:', e.text);
// console.info('Trigger:', e.trigger);
//
// e.clearSelection();
// });
// console.log('ffff');
// console.log(window.getSelection().toString());
//
// var copy = new Clipboard('#Copy', {
// text: function () {
// return window.getSelection().toString();
// }
// });
// copy.on('success', function (e) {
// layer.alert('Lucky Copyed!');
// });
//
// }
}
@Injectable()
......
......@@ -51,7 +51,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
const zTreeObj = $.fn.zTree.getZTreeObj('ztree');
zTreeObj.expandNode(treeNode);
} else {
this._http.get_user_profile().subscribe();
this._http.getUserProfile().subscribe();
this.Connect(treeNode);
}
}
......@@ -66,7 +66,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
getGrantedAssetsNodes() {
this._http.get_my_granted_nodes()
this._http.getMyGrantedNodes()
.subscribe(response => {
this.Data = [...response, ...this.Data];
this.draw();
......@@ -74,7 +74,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
refreshGrantedAssetsNodes() {
this._http.refresh_my_granted_nodes()
this._http.refreshMyGrantedNodes()
.subscribe(response => {
this.Data = [...response, ...this.Data];
this.draw();
......@@ -82,7 +82,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
getGrantedRemoteApps() {
this._http.get_my_granted_remote_apps()
this._http.getMyGrantedRemoteApps()
.subscribe(response => {
if (response.length > 1) {
this.Data = [...this.Data, ...response];
......@@ -209,35 +209,35 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
connectAsset(node) {
const system_users = node.meta.system_users;
const systemUsers = node.meta.system_users;
const host = node.meta.asset;
let user: any;
if (system_users.length > 1) {
user = this.checkPriority(system_users);
if (systemUsers.length > 1) {
user = this.checkPriority(systemUsers);
if (user) {
this.login(host, user);
return this.manualSetUserAuthLoginIfNeed(host, user, this.login);
} else {
const dialogRef = this._dialog.open(AssetTreeDialogComponent, {
height: '200px',
width: '300px',
data: {users: system_users}
data: {users: systemUsers}
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
for (const i of system_users) {
for (const i of systemUsers) {
if (i.id.toString() === result.toString()) {
user = i;
break;
}
}
this.login(host, user);
return this.manualSetUserAuthLoginIfNeed(host, user, this.login);
}
});
}
} else if (system_users.length === 1) {
user = system_users[0];
this.login(host, user);
} else if (systemUsers.length === 1) {
user = systemUsers[0];
this.manualSetUserAuthLoginIfNeed(host, user, this.login);
} else {
alert('该主机没有授权登录用户');
}
......@@ -245,14 +245,11 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
connectRemoteApp(node) {
const user = node.meta.user;
return this.loginRemoteApp(node, user);
return this.manualSetUserAuthLoginIfNeed(node, user, this.loginRemoteApp);
}
loginRemoteApp(node, user) {
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) {
NavList.List[id].nick = node.name;
NavList.List[id].connected = true;
......@@ -288,28 +285,32 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this.Connect(host);
}
manualSetUserAuthLogin(host, user, callback) {
manualSetUserAuthLoginIfNeed(host, user, callback) {
if (user.login_mode !== 'manual') {
return callback(host, user);
}
user = Object.assign({}, user);
const dialogRef = this._dialog.open(ManualPasswordDialogComponent, {
height: '250px',
width: '400px',
width: '500px',
data: {username: user.username}
});
dialogRef.afterClosed().subscribe(result => {
if (!result) {
return;
}
if (result.skip) {
return callback(host, user);
}
user.username = btoa(result.username);
user.password = btoa(result.password);
user.username = result.username;
user.password = result.password;
return callback(host, user);
});
}
login(host, user) {
const id = NavList.List.length - 1;
if (user.login_mode === 'manual' && !user.password && user.protocol === 'rdp') {
return this.manualSetUserAuthLogin(host, user, this.login);
}
if (user) {
NavList.List[id].nick = host.hostname;
NavList.List[id].connected = true;
......@@ -460,6 +461,16 @@ export class ManualPasswordDialogComponent implements OnInit {
}
onSkip() {
this.data.skip = true;
this.dialogRef.close(this.data);
}
onSkipAll() {
this.data.skipAll = true;
this.dialogRef.close(this.data);
}
onNoClick() {
this.dialogRef.close();
}
......
......@@ -11,6 +11,7 @@
</mat-form-field>
<div style="float: right">
<button mat-raised-button (click)="onSkip()" >{{"Skip"|trans}}</button>
<button mat-raised-button (click)="onNoClick()" >{{"Cancel"|trans}}</button>
<button mat-raised-button color="primary" [type]="'submit'" [mat-dialog-close]="data" >{{"Confirm"|trans}}</button>
</div>
......
......@@ -13,7 +13,7 @@ import {ElementIframeComponent} from './iframe/iframe.component';
import {ElementDialogAlertComponent} from './dialog/dialog.service';
import {ElementGuacamoleComponent} from './guacamole/guacamole.component';
import {ElementSshTermComponent} from './ssh-term/ssh-term.component';
import {AssetTreeDialogComponent, ElementAssetTreeComponent, ManualPasswordDialogComponent} from './asset-tree/asset-tree.component';
import {ElementAssetTreeComponent, AssetTreeDialogComponent, ManualPasswordDialogComponent} from './asset-tree/asset-tree.component';
import {RDPSolutionDialogComponent, FontDialogComponent} from './nav/nav.component';
export const ElementComponents = [
......
<!--<iframe #rdp [src]="trust('https://inews.gtimg.com/newsapp_bt/0/3460971429/1000')" width="100%" height="100%" (mouseenter)="active()"></iframe>-->
<iframe *ngIf="target" #rdp [src]="trust(target)" width="100%" height="100%" (mouseenter)="active()"></iframe>
<iframe #rdpRef *ngIf="target" [src]="trust(target)" width="100%" height="100%" (mouseenter)="active()"></iframe>
......@@ -17,7 +17,7 @@ export class ElementGuacamoleComponent implements OnInit {
@Input() remoteAppId: string;
@Input() target: string;
@Input() index: number;
@ViewChild('rdp') el: ElementRef;
@ViewChild('rdpRef') el: ElementRef;
registered = false;
constructor(private sanitizer: DomSanitizer,
......@@ -29,15 +29,17 @@ export class ElementGuacamoleComponent implements OnInit {
registerHost() {
let action: any;
if (this.remoteAppId) {
action = this._http.guacamole_add_remote_app(User.id, this.remoteAppId, this.sysUser.username, this.sysUser.password);
action = this._http.guacamoleAddRemoteApp(User.id, this.remoteAppId, this.sysUser.username, this.sysUser.password);
} else {
action = this._http.guacamole_add_asset(User.id, this.host.id, this.sysUser.id, this.sysUser.username, this.sysUser.password);
action = this._http.guacamoleAddAsset(User.id, this.host.id, this.sysUser.id, this.sysUser.username, this.sysUser.password);
}
action.subscribe(
data => {
const base = data.result;
this.target = document.location.origin + '/guacamole/#/client/' + base + '?token=' + DataStore.guacamole_token;
NavList.List[this.index].Rdp = this.el.nativeElement;
setTimeout(() => {
NavList.List[this.index].Rdp = this.el.nativeElement;
}, 500);
},
error => {
if (!this.registered) {
......@@ -52,7 +54,7 @@ export class ElementGuacamoleComponent implements OnInit {
const now = new Date();
const nowTime = now.getTime() / 1000;
this.registered = true;
this._http.get_guacamole_token(User.id, '').subscribe(
this._http.getGuacamoleToken(User.id, '').subscribe(
data => {
// /guacamole/client will redirect to http://guacamole/#/client
DataStore.guacamole_token = data['authToken'];
......
......@@ -33,7 +33,7 @@ export class PagesConnectComponent implements OnInit {
jQuery('body').css('background-color', '#1f1b1b');
if (this.system === 'windows') {
if (!this.userid) {
this._http.get_user_id_from_token(this.token)
this._http.getUserIdFromToken(this.token)
.subscribe(
data => {
this._localStorage.set('user-' + this.token, data['user']);
......@@ -49,7 +49,7 @@ export class PagesConnectComponent implements OnInit {
getAuthToken() {
if (!this.authToken) {
this._http.get_guacamole_token(this.userid, this.token).subscribe(
this._http.getGuacamoleToken(this.userid, this.token).subscribe(
data => {
if (data['authToken']) {
this._localStorage.set('authToken-' + this.token, data['authToken']);
......@@ -65,7 +65,7 @@ export class PagesConnectComponent implements OnInit {
getBase() {
if (!this.base) {
this._http.guacamole_token_add_asset(this.token, this.authToken).subscribe(
this._http.guacamoleTokenAddAsset(this.token, this.authToken).subscribe(
data => {
if (data['result']) {
this._localStorage.set('base-' + this.token, data['result']);
......
......@@ -16,4 +16,3 @@
<p> Version <strong>{{version}}</strong></p>
</div>
</div>
<!--<elements-server-menu></elements-server-menu>-->
......@@ -44,7 +44,7 @@ export class PagesLoginComponent implements OnInit {
DataStore.error['login'] = '';
this._logger.log(User);
if (User.username.length > 0 && User.password.length > 6 && User.password.length < 100) {
this._http.check_login(JSON.stringify(User))
this._http.checkLogin(JSON.stringify(User))
.subscribe(
data => {
User.logined = data['logined'];
......
......@@ -86,7 +86,7 @@ export class JsonComponent implements OnInit {
}
});
if (this.replay.src !== 'READY') {
this._http.get_replay_data(this.replay.src)
this._http.getReplayData(this.replay.src)
.subscribe(
data => {
this.replayData = data;
......
......@@ -24,7 +24,7 @@ export class PagesReplayComponent implements OnInit {
.subscribe(params => {
token = params['token'];
});
this._http.get_replay(token)
this._http.getReplay(token)
.subscribe(
data => {
this.replay.type = data['type'];
......
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