Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #499 from safing/improvments/remove-security-setting
Browse files Browse the repository at this point in the history
Improvments/remove security setting
  • Loading branch information
dhaavi authored Dec 1, 2023
2 parents fec1ae6 + a38e413 commit b418dee
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 285 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
import { ComponentPortal } from '@angular/cdk/portal';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Injectable, InjectionToken, Injector } from '@angular/core';
import { Injectable, InjectionToken, Injector, isDevMode } from '@angular/core';
import { interval, PartialObserver, Subject } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { IndicatorComponent } from './indicator';
Expand Down Expand Up @@ -213,41 +213,64 @@ export class ActionIndicatorService {
return '';
}

/**
* @deprecated use the version without a typo ...
*/
getErrorMessgae(resp: HttpResponse<ArrayBuffer | string> | HttpErrorResponse | Error): string {
return this.getErrorMessage(resp)
}

/**
* Parses a HTTP or HTTP Error response and returns a
* message that can be displayed to the user.
*/
getErrorMessgae(resp: HttpResponse<ArrayBuffer | string> | HttpErrorResponse | Error): string {
let msg = '';
let body: string | null = null;
getErrorMessage(resp: HttpResponse<ArrayBuffer | string> | HttpErrorResponse | Error): string {
try {
let msg = '';
let body: string | null = null;

if (resp instanceof Error) {
return resp.message;
}
if (typeof resp === 'string') {
return resp
}

if (resp instanceof Error) {
return resp.message;
}

if (resp instanceof HttpErrorResponse) {
// A client-side or network error occured.
if (resp.error instanceof Error) {
body = resp.error.message;
if (resp instanceof HttpErrorResponse) {
// A client-side or network error occured.
if (resp.error instanceof Error) {
body = resp.error.message;
} else {
body = this.stringifyBody(resp.error);
}
} else {
body = this.stringifyBody(resp.error);
body = this.stringifyBody(resp.body);
}
} else {
body = this.stringifyBody(resp.body);
}

const ct = resp.headers.get('content-type') || '';
if (/application\/json/.test(ct)) {
if (!!body) {
msg = body;
if (resp instanceof HttpResponse) {
const ct = resp.headers.get('content-type') || '';
if (/application\/json/.test(ct)) {
if (!!body) {
msg = body;
}
} else if (/text\/plain/.test(ct)) {
msg = body;
}
// Make the first letter uppercase
if (!!msg) {
msg = msg[0].toLocaleUpperCase() + msg.slice(1)
}
return msg;
}
} else if (/text\/plain/.test(ct)) {
msg = body;
}
// Make the first letter uppercase
if (!!msg) {
msg = msg[0].toLocaleUpperCase() + msg.slice(1)

console.error(`Unexpected error type`, resp)

return `Unknown error: ${resp}`

} catch (err: any) {
console.error(err)
return `Unknown error: ${resp}`
}
return msg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ export class BasicSettingComponent<S extends BaseSetting<any, any>> implements C
// from security-settings to booleans.
//
// In order to not mess and hide an actual portmaster issue
// we only convert v to a boolean if it's a number value.
// we only convert v to a boolean if it's a number value and marked as a security setting.
// In all other cases we don't mangle it.
//
// TODO(ppacher): Remove in v1.5
// TODO(ppacher): Remove in v1.8?
// BOM
if (this.setting?.OptType === OptionType.Bool) {
if (this.setting?.OptType === OptionType.Bool && this.setting?.Annotations[WellKnown.DisplayHint] === ExternalOptionHint.SecurityLevel) {
if (typeof v === 'number') {
(v as any) = !!v
(v as any) = v === 7;
}
}
// EOM
Expand Down
3 changes: 0 additions & 3 deletions modules/portmaster/src/app/shared/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { RuleListItemComponent } from './rule-list/list-item';
import { RuleListComponent } from './rule-list/rule-list';
import { SafePipe } from './safe.pipe';
import { SecuritySettingComponent } from './security-setting/security-setting';
import { ExportDialogComponent } from './export-dialog/export-dialog.component';
import { ImportDialogComponent } from './import-dialog/import-dialog.component';
import { SfngAppIconModule } from '../app-icon';
Expand Down Expand Up @@ -57,7 +56,6 @@ import { SfngAppIconModule } from '../app-icon';
OrderedListItemComponent,
RuleListComponent,
RuleListItemComponent,
SecuritySettingComponent,
ConfigSettingsViewComponent,
GenericSettingComponent,
SafePipe,
Expand All @@ -71,7 +69,6 @@ import { SfngAppIconModule } from '../app-icon';
OrderedListItemComponent,
RuleListComponent,
RuleListItemComponent,
SecuritySettingComponent,
ConfigSettingsViewComponent,
GenericSettingComponent,
SafePipe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ <h1 class="text-sm font-light m-0">
{{ dialogRef.data.type === "setting" ? "Settings" : "Profile" }} Export
</h1>

<svg
role="img"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 384 512"
class="w-3 h-3 text-secondary hover:text-primary cursor-pointer"
(click)="dialogRef.close()"
>
<path
fill="currentColor"
d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"
></path>
<svg role="img" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"
class="w-3 h-3 text-secondary hover:text-primary cursor-pointer" (click)="dialogRef.close()">
<path fill="currentColor"
d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z">
</path>
</svg>
</header>

<markdown lineNumbers [data]="content" emoji></markdown>
<markdown lineNumbers [data]="content" emoji class="overflow-auto"></markdown>

<div class="flex flex-row justify-end gap-2 items-center">
<button (click)="copyToClipboard()">Copy To Clipboard</button>
<button (click)="download()">Save</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ export interface ExportConfig {
@Component({
templateUrl: './export-dialog.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
styles: [
`
:host {
@apply flex flex-col gap-2 overflow-hidden;
min-height: 24rem;
min-width: 24rem;
max-height: 40rem;
max-width: 40rem;
}
`,
],
})
export class ExportDialogComponent implements OnInit {
readonly dialogRef: SfngDialogRef<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
'hidden': selectMode && !userConfigured
}">

<input class="absolute -left-5 my-auto" type="checkbox" *ngIf="selectMode && userConfigured" [(ngModel)]="selected" (ngModelChange)="selectedChange.next($event)">
<input class="absolute -left-5 my-auto" type="checkbox" *ngIf="selectMode && userConfigured" [(ngModel)]="selected"
(ngModelChange)="selectedChange.next($event)">

<div class="flex flex-col flex-grow">
<div class="flex flex-row items-center justify-start space-x-2 w-fit" *ngIf="showHeader">
Expand Down Expand Up @@ -95,11 +96,6 @@ <h3 [innerHTML]="setting?.Name | safe:'html'" class="mb-0 name"></h3>

<!-- Actual settings input -->
<ng-container [ngSwitch]="externalOptType(setting)">
<!-- Security Level Switches -->
<app-security-setting *ngSwitchCase="optionHint.SecurityLevel" [disabled]="disabled"
class="w-full mt-2 xl:mt-0 xl:w-auto" [onOffMode]="(networkRatingEnabled$ | async) === false" [setting]="_setting"
[ngModel]="_currentValue" (ngModelChange)="updateValue($event, true)">
</app-security-setting>

<!-- Rule lists -->
<ng-container *ngSwitchCase="optionHint.EndpointList">
Expand Down Expand Up @@ -205,4 +201,4 @@ <h1>{{ _setting?.Name }}</h1>

<markdown emoji [data]="_setting?.Help" class="flex-grow block overflow-auto"></markdown>
</div>
</ng-template>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export class GenericSettingComponent<S extends BaseSetting<any, any>> implements
this._defaultValue = val;
this.updateActualValue();
}

get defaultValue() {
// Return cached value.
if (this._defaultValue !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ <h1 class="m-0 text-sm font-light">

<span class="text-xs font-light">Please paste the "Export Content" or use "Choose File" to select one from
your hard disk.</span>
<pre tabindex="0" class="block flex-grow w-full rounded border border-gray-500 language-yaml" #codeBlock id="yaml"
contenteditable="true" (blur)="onBlur()" (mouseleave)="onBlur()" (paste)="onPaste($event)"></pre>

<pre tabindex="0" class="block flex-grow w-full rounded border border-gray-500 language-yaml overflow-auto outline-none"
#codeBlock id="yaml" contenteditable="true" (blur)="onBlur()" (mouseleave)="onBlur()" (paste)="onPaste($event)"></pre>

<fieldset class="p-2 text-xs font-light bg-gray-400 rounded border border-gray-500 border-solid">
<legend class="px-2 py-1 m-0 text-xs w-fit">Configuration</legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ImportConfig {
styles: [
`
:host {
@apply flex flex-col gap-2;
@apply flex flex-col gap-2 overflow-hidden;
min-height: 24rem;
min-width: 24rem;
max-height: 40rem;
Expand Down
1 change: 0 additions & 1 deletion modules/portmaster/src/app/shared/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export * from './filter-lists';
export * from './generic-setting';
export * from './ordererd-list';
export * from './rule-list';
export * from './security-setting';
export * from './safe.pipe';

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b418dee

Please sign in to comment.