Compare commits

..
11 changed files with 736 additions and 421 deletions

No files matched your search

+3 -7
View File
@@ -103,6 +103,7 @@ declare module '@vue/runtime-core' {
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
IpIncludeExclude: typeof import('./src/tools/ip-include-exclude/ip-include-exclude.vue')['default']
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
@@ -130,23 +131,19 @@ declare module '@vue/runtime-core' {
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDatePicker: typeof import('naive-ui')['NDatePicker']
NDivider: typeof import('naive-ui')['NDivider']
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NInput: typeof import('naive-ui')['NInput']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
NSwitch: typeof import('naive-ui')['NSwitch']
NTable: typeof import('naive-ui')['NTable']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
@@ -177,7 +174,6 @@ declare module '@vue/runtime-core' {
TextToBinary: typeof import('./src/tools/text-to-binary/text-to-binary.vue')['default']
TextToNatoAlphabet: typeof import('./src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue')['default']
TextToUnicode: typeof import('./src/tools/text-to-unicode/text-to-unicode.vue')['default']
TimezoneConverter: typeof import('./src/tools/timezone-converter/timezone-converter.vue')['default']
TokenDisplay: typeof import('./src/tools/otp-code-generator-and-validator/token-display.vue')['default']
'TokenGenerator.tool': typeof import('./src/tools/token-generator/token-generator.tool.vue')['default']
TomlToJson: typeof import('./src/tools/toml-to-json/toml-to-json.vue')['default']
+2 -2
View File
@@ -54,9 +54,9 @@
"@vueuse/router": "^10.0.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"cidr-tools": "^11.0.2",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"countries-and-timezones": "^3.6.0",
"country-code-lookup": "^0.1.0",
"cron-validator": "^1.3.1",
"cronstrue": "^2.26.0",
@@ -68,10 +68,10 @@
"figlet": "^1.7.0",
"figue": "^1.2.0",
"fuse.js": "^6.6.2",
"get-timezone-offset": "^1.0.5",
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"ip-matching": "^2.1.2",
"js-base64": "^3.7.6",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
+517 -253
View File
File diff suppressed because it is too large. Load diff
+10 -3
View File
@@ -1,6 +1,7 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as ipIncludeExclude } from './ip-include-exclude';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
@@ -9,7 +10,6 @@ import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as xmlToJson } from './xml-to-json';
import { tool as jsonToXml } from './json-to-xml';
import { tool as timezoneConverter } from './timezone-converter';
import { tool as regexTester } from './regex-tester';
import { tool as regexMemo } from './regex-memo';
import { tool as markdownToHtml } from './markdown-to-html';
@@ -98,7 +98,6 @@ export const toolsByCategory: ToolCategory[] = [
name: 'Converter',
components: [
dateTimeConverter,
timezoneConverter,
baseConverter,
romanNumeralConverter,
base64StringConverter,
@@ -166,7 +165,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
ipv4RangeExpander,
ipIncludeExclude,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
],
},
{
name: 'Math',
+12
View File
@@ -0,0 +1,12 @@
import { UnfoldMoreOutlined } from '@vicons/material';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'IP Subnets Exclude Calculator',
path: '/ip-include-exclude',
description: 'Substract a disallowed IP Ranges/Mask/CIDR list from an allowed IP Ranges/Mask/CIDR list',
keywords: ['ip', 'allowed', 'disallowed', 'include', 'exclude', 'subnet', 'cidr'],
component: () => import('./ip-include-exclude.vue'),
icon: UnfoldMoreOutlined,
createdAt: new Date('2024-08-15'),
});
@@ -0,0 +1,63 @@
import { describe, expect, it } from 'vitest';
import { substractCIDRs } from './ip-include-exclude.service';
describe('ip-include-exclude', () => {
describe('substractCIDRs', () => {
it('should return error on invalid values', () => {
expect(substractCIDRs({ allowedRanges: '192.168.0.', disallowedRanges: '' })).to.deep.eq({ // NOSONAR
allowedCIDRs: [],
allowedSubnets: [],
disallowedSubnets: [],
error: 'Error: Invalid IP (range/subnetwork)',
});
});
it('should return correct substractions and subnets', () => {
expect(substractCIDRs({ allowedRanges: '192.168.3.0/24', disallowedRanges: '' })).to.deep.eq({ // NOSONAR
allowedCIDRs: ['192.168.3.0/24'], // NOSONAR
allowedSubnets: [{ cidr: '192.168.3.0/24', end: '192.168.3.255', start: '192.168.3.0' }], // NOSONAR
disallowedSubnets: [],
error: '',
});
expect(substractCIDRs({ allowedRanges: '192.168.2.0/24', disallowedRanges: '192.168.2.1' })).to.deep.eq({ // NOSONAR
allowedCIDRs: ['192.168.2.0/32', // NOSONAR
'192.168.2.2/31', // NOSONAR
'192.168.2.4/30', // NOSONAR
'192.168.2.8/29', // NOSONAR
'192.168.2.16/28', // NOSONAR
'192.168.2.32/27', // NOSONAR
'192.168.2.64/26', // NOSONAR
'192.168.2.128/25'], // NOSONAR
allowedSubnets: [
{ cidr: '192.168.2.0/24', end: '192.168.2.255', start: '192.168.2.0' }, // NOSONAR
],
disallowedSubnets: [
{ cidr: '192.168.2.1/32', end: '192.168.2.1', start: '192.168.2.1' }, // NOSONAR
],
error: '',
});
expect(substractCIDRs({ allowedRanges: '192.168.12.0/24', disallowedRanges: '192.168.12.1-192.168.12.10, 192.168.12.34' })).to.deep.eq({ // NOSONAR
allowedCIDRs: ['192.168.12.0/32', // NOSONAR
'192.168.12.11/32', // NOSONAR
'192.168.12.12/30', // NOSONAR
'192.168.12.16/28', // NOSONAR
'192.168.12.32/31', // NOSONAR
'192.168.12.35/32', // NOSONAR
'192.168.12.36/30', // NOSONAR
'192.168.12.40/29', // NOSONAR
'192.168.12.48/28', // NOSONAR
'192.168.12.64/26', // NOSONAR
'192.168.12.128/25'], // NOSONAR
allowedSubnets: [{ cidr: '192.168.12.0/24', end: '192.168.12.255', start: '192.168.12.0' }], // NOSONAR
disallowedSubnets: [
{ cidr: '192.168.12.1/32', end: '192.168.12.1', start: '192.168.12.1' }, // NOSONAR
{ cidr: '192.168.12.2/31', end: '192.168.12.3', start: '192.168.12.2' }, // NOSONAR
{ cidr: '192.168.12.4/30', end: '192.168.12.7', start: '192.168.12.4' }, // NOSONAR
{ cidr: '192.168.12.8/31', end: '192.168.12.9', start: '192.168.12.8' }, // NOSONAR
{ cidr: '192.168.12.10/32', end: '192.168.12.10', start: '192.168.12.10' }, // NOSONAR
{ cidr: '192.168.12.34/32', end: '192.168.12.34', start: '192.168.12.34' }, // NOSONAR
],
error: '',
});
});
});
});
@@ -0,0 +1,49 @@
import type { IPMask } from 'ip-matching';
import { getMatch } from 'ip-matching';
import { excludeCidr } from 'cidr-tools';
function convertToCIDR(mask: IPMask) {
const subnet = mask.convertToSubnet();
if (!subnet) {
return { cidr: mask.toString(), start: '', end: '' };
}
return {
cidr: subnet.toString(),
start: subnet.getFirst().toString(),
end: subnet.getLast().toString(),
};
}
export function substractCIDRs(
{ allowedRanges, disallowedRanges }:
{
allowedRanges: string
disallowedRanges: string
}) {
try {
const allowedRangesMatchMasks = allowedRanges.split(/\s*[,;|]+\s*/g) // NOSONAR
.filter(range => range)
.flatMap(range => getMatch(range)?.convertToMasks() || []);
const disallowedRangesMatchMasks = disallowedRanges.split(/\s*[,;|]+\s*/g) // NOSONAR
.filter(range => range)
.flatMap(range => getMatch(range)?.convertToMasks() || []);
const allowedSubnets = allowedRangesMatchMasks.map(convertToCIDR);
const disallowedSubnets = disallowedRangesMatchMasks.map(convertToCIDR);
return {
error: '',
allowedSubnets,
disallowedSubnets,
allowedCIDRs: excludeCidr(allowedSubnets.map(net => net.cidr), disallowedSubnets.map(net => net.cidr)),
};
}
catch (e: any) {
return {
error: e.toString(),
allowedSubnets: [],
disallowedSubnets: [],
allowedCIDRs: [],
};
}
}
@@ -0,0 +1,80 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core';
import { substractCIDRs } from './ip-include-exclude.service';
import SpanCopyable from '@/components/SpanCopyable.vue';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const allowedRanges = useStorage('ip-inc-exc:allow', '192.168.0.1/24'); // NOSONAR
const disallowedRanges = useStorage('ip-inc-exc:disallow', '192.168.0.6'); // NOSONAR
const result = computed(() => substractCIDRs({
allowedRanges: allowedRanges.value, disallowedRanges: disallowedRanges.value,
}));
</script>
<template>
<div>
<c-input-text
v-model:value="allowedRanges"
label="AllowedIPs (IPv4/6 CIDR/Range/Mask/Wildcard)"
placeholder="An IPv4/6 CIDR/Range/Mask/Wildcard..."
mb-4
/>
<c-input-text
v-model:value="disallowedRanges"
label="DisallowedIPs (IPv4/6 CIDR/Range/Mask/Wildcard)"
placeholder="An IPv4/6 CIDR/Range/Mask/Wildcard..."
mb-4
/>
<n-divider />
<c-alert v-if="result.error">
{{ result.error }}
</c-alert>
<div v-if="!result.error">
<n-form-item label="Final AllowedIPs:">
<TextareaCopyable :value="result.allowedCIDRs.join(', ')" />
</n-form-item>
<n-divider />
<c-card title="Allowed Subnets">
<n-table>
<tbody>
<tr v-for="{ cidr, start, end } in result.allowedSubnets" :key="cidr">
<td font-bold>
<SpanCopyable :value="cidr" />
</td>
<td>
<SpanCopyable :value="start" />
</td>
<td>
<SpanCopyable :value="end" />
</td>
</tr>
</tbody>
</n-table>
</c-card>
<c-card title="Disallowed Subnets">
<n-table>
<tbody>
<tr v-for="{ cidr, start, end } in result.disallowedSubnets" :key="cidr">
<td font-bold>
<SpanCopyable :value="cidr" />
</td>
<td>
<SpanCopyable :value="start" />
</td>
<td>
<SpanCopyable :value="end" />
</td>
</tr>
</tbody>
</n-table>
</c-card>
</div>
</div>
</template>
-3
View File
@@ -1,3 +0,0 @@
declare module "get-timezone-offset" {
export default function(timeZoneName: string, date: Date);
}
-12
View File
@@ -1,12 +0,0 @@
import { CalendarTime } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Timezone Converter',
path: '/timezone-converter',
description: 'Convert Date-Time from a timezone to others and get timezone vs countries infos',
keywords: ['timezone', 'tz', 'date', 'time', 'country', 'converter'],
component: () => import('./timezone-converter.vue'),
icon: CalendarTime,
createdAt: new Date('2024-08-15'),
});
@@ -1,141 +0,0 @@
<script setup lang="ts">
import ctz from 'countries-and-timezones';
import getTimezoneOffset from 'get-timezone-offset';
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const allTimezones = Object.values(ctz.getAllTimezones()).map(tz => ({
value: tz.name,
label: `${tz.name === browserTimezone ? 'Browser TZ - ' : ''}${tz.name} (${tz.utcOffset === tz.dstOffset ? tz.utcOffsetStr : `${tz.utcOffsetStr}/${tz.dstOffsetStr}`})`,
}));
function convertMinsToHrsMins(minutes: number) {
const h = String(Math.floor(minutes / 60)).padStart(2, '0');
const m = String(minutes % 60).padStart(2, '0');
return `${h}:${m}`;
}
const otherTimezones = useStorage<{ name: string }[]>('timezone-conv:zones', [{ name: 'Etc/GMT' }]);
const currentTimezone = useStorage<string>('timezone-conv:current', browserTimezone);
const use24HourTimeFormat = useStorage<boolean>('timezone-conv:24h', true);
const format = computed(() => use24HourTimeFormat.value ? 'yyyy-MM-dd HH:mm:ss' : 'yyyy-MM-dd hh:mm:ss a');
const timePickerProps = computed(() => use24HourTimeFormat.value ? ({ use12Hours: false }) : ({ use12Hours: true }));
const now = Date.now();
const currentDatetimeRange = ref<[number, number]>([now, now]);
const currentTimezoneOffset = computed(() => {
return convertMinsToHrsMins(-getTimezoneOffset(currentTimezone.value, new Date(currentDatetimeRange.value[0])));
});
function convertToTimezone(tz: string, timestamp: number) {
return new Date(
timestamp
+ getTimezoneOffset(currentTimezone.value, new Date()) * 60 * 1000
- getTimezoneOffset(browserTimezone, new Date()) * 60 * 1000,
).toLocaleString(undefined,
{ timeZone: tz, timeZoneName: undefined, hour12: !use24HourTimeFormat.value });
}
const tzToCountriesInput = ref(browserTimezone);
const tzToCountriesOutput = computed(() => ctz.getCountriesForTimezone(tzToCountriesInput.value));
const allCountries = Object.values(ctz.getAllCountries()).map(c => ({
value: c.id,
label: `${c.name} (${c.id})`,
}));
const countryToTimezonesInput = ref('FR');
const countryToTimezonesOutput = computed(() => ctz.getTimezonesForCountry(countryToTimezonesInput.value));
</script>
<template>
<div>
<c-card title="Timezones Date-Time Converter" mb-2>
<c-select
v-model:value="currentTimezone"
label="Timezone"
label-position="left"
searchable
:options="allTimezones"
mb-2
/>
<n-form-item label="Date/time interval to convert:" label-placement="top">
<n-date-picker
:key="format"
v-model:value="currentDatetimeRange"
type="datetimerange"
:format="format"
:time-picker-props="timePickerProps"
mb-2
w-full
/>
</n-form-item>
<n-space justify="space-evenly">
<n-form-item label="Current Timezone Offset:" label-placement="left">
<n-input :value="currentTimezoneOffset" readonly style="width:5em" />
</n-form-item>
<n-form-item label="Use 24 hour time format" label-placement="left">
<n-switch v-model:value="use24HourTimeFormat" />
</n-form-item>
</n-space>
<c-card title="Date-Time in other timezones">
<n-dynamic-input
v-model:value="otherTimezones"
show-sort-button
:on-create="() => ({ name: browserTimezone })"
>
<template #default="{ value }">
<div flex flex-wrap items-center gap-1>
<n-select
v-model:value="value.name"
filterable
placeholder="Please select a timezone"
:options="allTimezones"
w-full
/>
<div w-full flex items-baseline gap-1>
<n-input style="min-width: 49%" readonly :value="convertToTimezone(value.name, currentDatetimeRange[0])" />
<n-input style="min-width: 49%" readonly :value="convertToTimezone(value.name, currentDatetimeRange[1])" />
</div>
</div>
</template>
</n-dynamic-input>
</c-card>
</c-card>
<c-card title="Country to Timezones" mb-2>
<c-select
v-model:value="countryToTimezonesInput"
label="Country"
label-position="left"
searchable
:options="allCountries"
/>
<n-divider />
<ul>
<li v-for="(tz, ix) in countryToTimezonesOutput" :key="ix">
{{ tz.name }} ({{ tz.countries.join(', ') }}): UTC= {{ tz.utcOffsetStr }}, DST= {{ tz.dstOffsetStr }}
</li>
</ul>
</c-card>
<c-card title="Timezones to Countries" mb-2>
<c-select
v-model:value="tzToCountriesInput"
label="Timezone"
label-position="left"
searchable
:options="allTimezones"
/>
<n-divider />
<ul>
<li v-for="(country, ix) in tzToCountriesOutput" :key="ix">
{{ country.name }} ({{ country.id }}): {{ country.timezones.join(', ') }}
</li>
</ul>
</c-card>
</div>
</template>