Check ip range for public/private view.
This commit is contained in:
@@ -9,6 +9,8 @@ import type {
|
||||
ServiceGroupConfig
|
||||
} from '$lib/config';
|
||||
|
||||
import * as ipRangeCheck from 'ip-range-check';
|
||||
|
||||
const requiredService: Required<ServiceConfig> = {
|
||||
title: '',
|
||||
subtitle: '',
|
||||
@@ -19,7 +21,7 @@ const requiredService: Required<ServiceConfig> = {
|
||||
target: '',
|
||||
type: '',
|
||||
tag: '',
|
||||
keywords: [],
|
||||
keywords: []
|
||||
};
|
||||
|
||||
const requiredServiceGroup: Required<ServiceGroupConfig> = {
|
||||
@@ -82,9 +84,8 @@ function merge<Type extends SPOJO>(a: Type, b: SPOJO): Type {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
export function mergeConfig(a: Config, b: SPOJO): Config {
|
||||
return merge<Config>(a,b);
|
||||
return merge<Config>(a, b);
|
||||
}
|
||||
|
||||
const defaultLightConfig: ColorConfig = {};
|
||||
@@ -132,7 +133,7 @@ export const defaultConfig: Config = {
|
||||
|
||||
function strip<Type extends SPOJO>(toStrip: Type, reference: Type): Type {
|
||||
const res: Type = { ...toStrip };
|
||||
if ( reference == undefined ) {
|
||||
if (reference == undefined) {
|
||||
return res;
|
||||
}
|
||||
const referenceNames = Object.entries(reference).map(([key, value]) => key);
|
||||
@@ -157,7 +158,6 @@ function strip<Type extends SPOJO>(toStrip: Type, reference: Type): Type {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// it is a child object, we strip it further
|
||||
const childReference: SPOJO = reference[key] as SPOJO;
|
||||
(res as SPOJO)[key] = strip(value as SPOJO, childReference);
|
||||
@@ -173,6 +173,7 @@ export function stripPrivateFields(config: Config): Config {
|
||||
if (config?.colors?.light != undefined) {
|
||||
res.colors.light = config.colors.light;
|
||||
}
|
||||
res.f;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -215,3 +216,15 @@ export function watchDymamicConfig() {
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
export function clientAddressIsPrivate(clientAddress: string, config: Config): boolean {
|
||||
const ranges: string[] = (config.privateIPs as string[]) || [
|
||||
'192.168.0.0/16',
|
||||
'100.64.0.0/10',
|
||||
'::1',
|
||||
'127.0.0.1',
|
||||
'10.0.0.0/8'
|
||||
];
|
||||
|
||||
return ipRangeCheck.default(clientAddress, ranges);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user