1
0
mirror of https://github.com/dkmstr/openuds-gui.git synced 2024-10-26 08:55:23 +03:00
This commit is contained in:
Adolfo Gómez García 2022-10-13 18:36:47 +02:00
parent 9253646d4e
commit f7c4a1c465
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
4 changed files with 83 additions and 11 deletions

9
.hintrc Normal file
View File

@ -0,0 +1,9 @@
{
"extends": [
"development"
],
"hints": {
"axe/forms": "off",
"axe/text-alternatives": "off"
}
}

View File

@ -7,7 +7,8 @@ declare const django: any;
export enum DialogType {
alert = 0,
yesno = 1
yesno = 1,
credentials = 2,
}
export interface ModalData {
@ -16,6 +17,8 @@ export interface ModalData {
autoclose?: number;
checkClose?: Observable<boolean>;
type: DialogType;
username?: string;
domain?: string;
}
@Component({

View File

@ -29,4 +29,14 @@ export class UDSGuiService {
return dialogRef.componentInstance.yesno;
}
askCredentials(username: string, domain: string) {
const width = window.innerWidth < 800 ? '80%' : '40%';
const dialogRef = this.dialog.open(ModalComponent, {
width,
data: { title: 'Credentials', body: 'Please enter your credentials', type: DialogType.credentials, username, domain },
});
return dialogRef.componentInstance.subscription;
}
}

View File

@ -169,29 +169,79 @@ export class Plugin {
if (data.url) {
observer.next(true);
observer.complete(); // Notify window to close...
// Extract if credentials modal is requested
let username = '';
let domain = '';
let askCredentials = false;
if (data.url.indexOf('&creds=') !== -1) {
askCredentials = true;
// Extract username and domain "&creds=username@domain"
const creds = data.url.split('&creds=')[1];
if (creds.indexOf('@') !== -1) {
username = creds.split('@')[0];
domain = creds.split('@')[1];
} else {
username = creds;
}
// Remove credentials from url
data.url = data.url.split('&creds=')[0];
}
let wnd = 'global';
let location = data.url;
// check if on same window or not
if (data.url.indexOf('o_s_w=') !== -1) {
const osw = /(.*)&o_s_w=.*/.exec(data.url);
window.location.href = osw[1];
wnd = 'same';
location = osw[1];
//window.location.href = osw[1];
} else {
// If the url contains "o_n_w", will open the url on a new window ALWAYS
let name = 'global';
if (data.url.indexOf('o_n_w=') !== -1) {
// Extract window name from o_n_w parameter if present
const onw = /(.*)&o_n_w=([a-zA-Z0-9._-]*)/.exec(
data.url
);
if (onw) {
name = onw[2];
data.url = onw[1];
wnd = onw[2];
location = onw[1];
}
}
if (Plugin.transportsWindow[name]) {
Plugin.transportsWindow[name].close();
}
const openWindow = () => {
if (wnd === 'same') {
window.location.href = location;
} else {
if (Plugin.transportsWindow[wnd]) {
Plugin.transportsWindow[wnd].close();
}
Plugin.transportsWindow[wnd] = window.open(
data.url,
'uds_trans_' + wnd
);
}
Plugin.transportsWindow[name] = window.open(
data.url,
'uds_trans_' + name
);
};
// If credentials required, ask for them
if (askCredentials) {
this.api.gui
.askCredentials(
username,
domain
)
.subscribe((data) => {
if (data) {
// Credentials provided, add them to url
location += '&creds=' + data.username;
if (data.domain) {
location += '@' + data.domain;
}
openWindow();
}
});
}
} else if (!data.running) {
observer.next(true);