2018-03-02 05:44:29 +01:00
|
|
|
import { UriMatchType } from "../../enums/uriMatchType";
|
|
|
|
|
|
|
|
import { View } from "./view";
|
|
|
|
|
|
|
|
import { LoginUri } from "../domain/loginUri";
|
|
|
|
|
2018-04-23 19:03:47 +02:00
|
|
|
import { Utils } from "../../misc/utils";
|
2018-04-19 20:40:42 +02:00
|
|
|
|
2018-11-02 13:39:09 +01:00
|
|
|
const CanLaunchWhitelist = [
|
|
|
|
"https://",
|
|
|
|
"http://",
|
|
|
|
"ssh://",
|
|
|
|
"ftp://",
|
|
|
|
"sftp://",
|
|
|
|
"irc://",
|
2019-02-14 15:07:20 +01:00
|
|
|
"vnc://",
|
2020-09-24 15:56:59 +02:00
|
|
|
// https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-uri
|
|
|
|
"rdp://", // Legacy RDP URI scheme
|
|
|
|
"ms-rd:", // Preferred RDP URI scheme
|
2018-11-02 13:39:09 +01:00
|
|
|
"chrome://",
|
2019-04-17 05:32:02 +02:00
|
|
|
"iosapp://",
|
|
|
|
"androidapp://",
|
2018-11-02 13:39:09 +01:00
|
|
|
];
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
export class LoginUriView implements View {
|
|
|
|
match: UriMatchType = null;
|
2021-12-16 13:36:21 +01:00
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
// tslint:disable
|
2019-01-25 15:30:21 +01:00
|
|
|
private _uri: string = null;
|
|
|
|
private _domain: string = null;
|
|
|
|
private _hostname: string = null;
|
2020-07-14 17:02:07 +02:00
|
|
|
private _host: string = null;
|
2019-01-25 15:30:21 +01:00
|
|
|
private _canLaunch: boolean = null;
|
2018-03-02 05:44:29 +01:00
|
|
|
// tslint:enable
|
2021-12-16 13:36:21 +01:00
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
constructor(u?: LoginUri) {
|
|
|
|
if (!u) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.match = u.match;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
get uri(): string {
|
|
|
|
return this._uri;
|
|
|
|
}
|
|
|
|
set uri(value: string) {
|
|
|
|
this._uri = value;
|
|
|
|
this._domain = null;
|
2018-11-02 18:03:00 +01:00
|
|
|
this._canLaunch = null;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
get domain(): string {
|
|
|
|
if (this._domain == null && this.uri != null) {
|
2018-10-14 04:21:54 +02:00
|
|
|
this._domain = Utils.getDomain(this.uri);
|
|
|
|
if (this._domain === "") {
|
2018-03-02 05:44:29 +01:00
|
|
|
this._domain = null;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 04:21:54 +02:00
|
|
|
return this._domain;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get hostname(): string {
|
|
|
|
if (this.match === UriMatchType.RegularExpression) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-19 20:40:42 +02:00
|
|
|
if (this._hostname == null && this.uri != null) {
|
2020-07-14 17:02:07 +02:00
|
|
|
this._hostname = Utils.getHostname(this.uri);
|
2018-04-19 20:40:42 +02:00
|
|
|
if (this._hostname === "") {
|
|
|
|
this._hostname = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 17:02:07 +02:00
|
|
|
return this._hostname;
|
|
|
|
}
|
|
|
|
|
2018-04-19 20:40:42 +02:00
|
|
|
get host(): string {
|
|
|
|
if (this.match === UriMatchType.RegularExpression) {
|
|
|
|
return null;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
2020-07-14 17:02:07 +02:00
|
|
|
if (this._host == null && this.uri != null) {
|
|
|
|
this._host = Utils.getHost(this.uri);
|
|
|
|
if (this._host === "") {
|
|
|
|
this._host = null;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2020-07-14 17:02:07 +02:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
return this._host;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
get hostnameOrUri(): string {
|
2019-01-07 16:33:13 +01:00
|
|
|
return this.hostname != null ? this.hostname : this.uri;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 16:33:13 +01:00
|
|
|
get hostOrUri(): string {
|
|
|
|
return this.host != null ? this.host : this.uri;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
get isWebsite(): boolean {
|
2021-12-16 13:36:21 +01:00
|
|
|
return (
|
2019-01-07 16:33:13 +01:00
|
|
|
this.uri != null &&
|
|
|
|
(this.uri.indexOf("http://") === 0 ||
|
|
|
|
this.uri.indexOf("https://") === 0 ||
|
|
|
|
(this.uri.indexOf("://") < 0 && Utils.tldEndingRegex.test(this.uri)))
|
|
|
|
);
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
get canLaunch(): boolean {
|
2018-11-02 18:03:00 +01:00
|
|
|
if (this._canLaunch != null) {
|
|
|
|
return this._canLaunch;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
2019-02-08 14:03:12 +01:00
|
|
|
if (this.uri != null && this.match !== UriMatchType.RegularExpression) {
|
2019-01-07 16:33:13 +01:00
|
|
|
const uri = this.launchUri;
|
2018-11-02 18:03:00 +01:00
|
|
|
for (let i = 0; i < CanLaunchWhitelist.length; i++) {
|
2019-01-07 16:33:13 +01:00
|
|
|
if (uri.indexOf(CanLaunchWhitelist[i]) === 0) {
|
2018-11-02 18:03:00 +01:00
|
|
|
this._canLaunch = true;
|
|
|
|
return this._canLaunch;
|
2018-11-02 13:39:09 +01:00
|
|
|
}
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
2019-01-07 16:33:13 +01:00
|
|
|
}
|
2018-11-02 18:03:00 +01:00
|
|
|
this._canLaunch = false;
|
|
|
|
return this._canLaunch;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 16:33:13 +01:00
|
|
|
get launchUri(): string {
|
|
|
|
return this.uri.indexOf("://") < 0 && Utils.tldEndingRegex.test(this.uri)
|
|
|
|
? "http://" + this.uri
|
|
|
|
: this.uri;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|