1
0
mirror of https://github.com/dkmstr/openuds-gui.git synced 2025-03-11 04:58:21 +03:00

it's been a hard's day night'

This commit is contained in:
Adolfo Gómez García 2018-08-31 09:17:57 +02:00
parent 42d44b3389
commit 69eac69a55
7 changed files with 188 additions and 10 deletions

View File

@ -19,6 +19,16 @@
"changeOrigin": true,
"logLevel": "info"
},
"/enable": {
"target": {
"host": "172.27.0.1",
"protocol": "http:",
"port": 8000
},
"secure": false,
"changeOrigin": true,
"logLevel": "info"
},
"/i18n": {
"target": {
"host": "172.27.0.1",

110
src/app/helpers/plugin.ts Normal file
View File

@ -0,0 +1,110 @@
import { UdsApiService } from '../uds-api.service';
/**
* Plugin manipulation class
*/
enum BrowserType {
chrome = 0,
safari,
ie,
firefox
}
export class Plugin {
static transportsWindow: Window = null;
browser: BrowserType;
constructor(private api: UdsApiService) {
const ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') !== -1) {
if (ua.indexOf('chrome') !== -1) {
this.browser = BrowserType.chrome;
} else {
this.browser = BrowserType.safari;
}
} else if (ua.indexOf('msie ') !== -1 || ua.indexOf('trident/') !== -1) {
this.browser = BrowserType.ie;
} else {
this.browser = BrowserType.firefox;
}
}
private launchChrome(url: string) {
}
private launchFirefox(url: string): boolean {
let elem = document.getElementById('hiddenUdsLauncherIFrame');
if (elem === null) {
const i = document.createElement('div');
i.id = 'testID';
i.innerHTML = '<iframe id="hiddenUdsLauncherIFrame" src="about:blank" style="display:none"></iframe>';
document.body.appendChild(i);
elem = document.getElementById('hiddenUdsLauncherIFrame');
}
console.log('Launching ', url);
try {
(<any>elem).contentWindow.location.href = url;
} catch (e) {
if (e.name === 'NS_ERROR_UNKNOWN_PROTOCOL') {
return false;
}
}
return true;
}
private launchSafari(url: string): boolean {
return false;
}
private launchIe(url: string): boolean {
return false;
}
private doLaunch(url: string) {
switch (this.browser) {
case BrowserType.chrome:
this.launchChrome(url);
break;
case BrowserType.firefox:
this.launchFirefox(url);
break;
case BrowserType.ie:
this.launchIe(url);
break;
case BrowserType.safari:
this.launchSafari(url);
break;
default:
window.location.href = url;
break;
}
}
launchURL(url: string): void {
if (url.substring(0, 7) === 'udsa://') {
const params = url.split('//')[1].split('/');
this.api.enabler(params[0], params[1]).subscribe(data => {
if (data.error !== undefined && data.error !== '') {
// TODO: show the error correctly
alert(data.error);
} else {
if (window.location.protocol === 'https:') {
// Ensures that protocol is https also for plugin, fixing if needed UDS provided info
data.url = data.url.replace('uds://', 'udss://');
}
if (this.api.config.bypassPluginDetection === false) {
this.doLaunch(data.url);
} else {
window.location.href = data.url;
}
}
});
} else {
// Transport is http transport
if (Plugin.transportsWindow !== null) {
Plugin.transportsWindow.close();
}
Plugin.transportsWindow = window.open(url, 'uds_transport_window');
}
}
}

View File

@ -22,9 +22,7 @@ export class LoginComponent implements OnInit {
// adapt form to post the correct values the correct way
this.visible = true;
const form = <HTMLFormElement>document.getElementById('loginform');
if (form.action.slice(-1) !== '/') {
form.action += '/';
}
form.action = this.api.config.urls.login;
const input = (<HTMLInputElement>document.getElementById('token'));
input.name = this.api.config.csrf_field;
input.value = this.api.config.csrf;

View File

@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { UdsApiService } from '../uds-api.service';
import { Router } from '@angular/router';
import { JSONServicesInformation } from '../types/services';
import { Plugin } from '../helpers/plugin';
@Component({
selector: 'uds-services',
@ -10,8 +11,10 @@ import { JSONServicesInformation } from '../types/services';
})
export class ServicesComponent implements OnInit {
servicesInformation: JSONServicesInformation;
plugin: Plugin;
constructor(private api: UdsApiService, private router: Router) {
this.plugin = new Plugin(api);
}
ngOnInit() {
@ -19,9 +22,21 @@ export class ServicesComponent implements OnInit {
if (!this.api.user.isLogged) {
this.router.navigate(['login']);
}
this.api.getServices().subscribe((result: JSONServicesInformation) => {
this.api.getServicesInformation().subscribe((result: JSONServicesInformation) => {
this.servicesInformation = result;
console.log(this.servicesInformation.services[0]);
console.log(result);
// If autorun, and there is only one service, launch it
if (this.servicesInformation.autorun && this.servicesInformation.services.length === 1) {
if (!this.servicesInformation.services[0].maintenance) {
this.api.executeCustomJSForServiceLaunch();
// Launch url
this.plugin.launchURL(this.servicesInformation.services[0].transports[0].link);
} else {
// TODO: inform that the service is in maintenance and cannot be run
alert(django.gettext('Service is in maintenance and cannot be executed'));
}
}
this.plugin.launchURL(this.servicesInformation.services[0].transports[0].link);
});
}

View File

@ -21,9 +21,12 @@ export interface UDSUrls {
readonly customAuth: string;
readonly services: string;
readonly admin: string;
readonly enabler: string;
}
export interface UDSConfig {
version: string;
version_stamp: string;
language: string;
available_languages: Lang[];
authenticators: Authenticator[];
@ -31,6 +34,7 @@ export interface UDSConfig {
csrf_field: string;
csrf: string;
urls: UDSUrls;
bypassPluginDetection: boolean;
}
export interface Downloadable {

View File

@ -41,3 +41,8 @@ export interface JSONServicesInformation {
services: JSONService[];
transports: string;
}
export interface JSONEnabledService {
url: string;
error: string;
}

View File

@ -2,28 +2,64 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { User, UDSConfig, Downloadable } from './types/config';
import { Observable } from 'rxjs';
import { JSONServicesInformation, JSONEnabledService } from './types/services';
@Injectable()
export class UdsApiService {
readonly user: User;
transportsWindow: Window;
constructor(private http: HttpClient) {
this.user = new User(udsData.profile);
}
this.transportsWindow = null;
}
/**
* Gets configuration data from uds.js file
*/
get config(): UDSConfig {
return udsData.config;
}
/**
* Gets plugins list
*/
get plugins(): Downloadable[] {
return udsData.plugins;
}
getAuthCustomHtml(authId) {
return this.http.get(this.config.urls.customAuth + authId, {responseType: 'text'});
enabler(serviceId: string, transportId: string) {
const enabler = this.config.urls.enabler.replace('param1', serviceId).replace('param2', transportId);
return this.http.get<JSONEnabledService>(enabler);
}
getServices() {
return this.http.get(this.config.urls.services);
/**
* Gets services information
*/
getServicesInformation(): Observable<JSONServicesInformation> {
return this.http.get<JSONServicesInformation>(this.config.urls.services);
}
/**
* Executes custom javascript for service launch if it is available
*/
executeCustomJSForServiceLaunch(): void {
// Executes a defined JS on launch servic event if defined
// this is in fact a hook
if (udsData.customJSForServiceLaunch !== undefined) {
// tslint:disable-next-line:no-eval
eval(udsData.customJSForServiceLaunch);
}
}
/**
* Gets auth custom html code
* @param authId if of the authenticator
* @returns Observable
*/
getAuthCustomHtml(authId: string) {
return this.http.get(this.config.urls.customAuth + authId, { responseType: 'text' });
}
}