mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 23:00:19 +03:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
382a5cc696 | ||
|
|
f7b024a74a |
No files matched your search
Vendored
+3
-2
@@ -128,11 +128,13 @@ declare module '@vue/runtime-core' {
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
MongoObjectidConverter: typeof import('./src/tools/mongo-objectid-converter/mongo-objectid-converter.vue')['default']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDatePicker: typeof import('naive-ui')['NDatePicker']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NForm: typeof import('naive-ui')['NForm']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
@@ -186,7 +188,6 @@ declare module '@vue/runtime-core' {
|
||||
UserAgentResultCards: typeof import('./src/tools/user-agent-parser/user-agent-result-cards.vue')['default']
|
||||
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
|
||||
WifiQrCodeGenerator: typeof import('./src/tools/wifi-qr-code-generator/wifi-qr-code-generator.vue')['default']
|
||||
WpaPskGenerator: typeof import('./src/tools/wpa-psk-generator/wpa-psk-generator.vue')['default']
|
||||
XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default']
|
||||
XmlToJson: typeof import('./src/tools/xml-to-json/xml-to-json.vue')['default']
|
||||
YamlToJson: typeof import('./src/tools/yaml-to-json-converter/yaml-to-json.vue')['default']
|
||||
|
||||
+3
-15
@@ -2,12 +2,12 @@ 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 emailNormalizer } from './email-normalizer';
|
||||
import { tool as wpaPskGenerator } from './wpa-psk-generator';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as mongoObjectidConverter } from './mongo-objectid-converter';
|
||||
import { tool as xmlToJson } from './xml-to-json';
|
||||
import { tool as jsonToXml } from './json-to-xml';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
@@ -89,20 +89,7 @@ import { tool as yamlViewer } from './yaml-viewer';
|
||||
export const toolsByCategory: ToolCategory[] = [
|
||||
{
|
||||
name: 'Crypto',
|
||||
components: [
|
||||
tokenGenerator,
|
||||
hashText,
|
||||
bcrypt,
|
||||
uuidGenerator,
|
||||
ulidGenerator,
|
||||
cypher,
|
||||
bip39,
|
||||
hmacGenerator,
|
||||
rsaKeyPairGenerator,
|
||||
passwordStrengthAnalyser,
|
||||
pdfSignatureChecker,
|
||||
wpaPskGenerator,
|
||||
],
|
||||
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
|
||||
},
|
||||
{
|
||||
name: 'Converter',
|
||||
@@ -168,6 +155,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
xmlFormatter,
|
||||
yamlViewer,
|
||||
emailNormalizer,
|
||||
mongoObjectidConverter,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Database } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'MongoDB ObjectId Converter',
|
||||
path: '/mongo-objectid-converter',
|
||||
description: 'Convert between MongoDB ObjectId and internal timestamp',
|
||||
keywords: ['mongo', 'objectid', 'converter', 'timestamp'],
|
||||
component: () => import('./mongo-objectid-converter.vue'),
|
||||
icon: Database,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { dateFromObjectId, generateMongoFilter, objectIdFromDate, objectIdSyntaxFromDate } from './mongo-objectid-converter.service';
|
||||
|
||||
describe('mongo-objectid-converter', () => {
|
||||
describe('objectIdFromDate', () => {
|
||||
it('convert a Date to ObjectId', () => {
|
||||
expect(objectIdFromDate(new Date(Date.UTC(2024, 0, 1)))).to.eql('659200800000000000000000');
|
||||
expect(objectIdFromDate(new Date(Date.UTC(2024, 0, 1, 12, 12, 12)))).to.eql('6592ac1c0000000000000000');
|
||||
});
|
||||
});
|
||||
describe('objectIdSyntaxFromDate', () => {
|
||||
it('convert a Date to ObjectId', () => {
|
||||
expect(objectIdSyntaxFromDate(new Date(Date.UTC(2024, 0, 1)))).to.eql('ObjectId("659200800000000000000000")');
|
||||
});
|
||||
});
|
||||
describe('dateFromObjectId', () => {
|
||||
it('convert an ObjectId to Date', () => {
|
||||
expect(dateFromObjectId('659200800000000000000000')).to.eql(new Date(Date.UTC(2024, 0, 1)));
|
||||
expect(dateFromObjectId('6592ac1c0000000000000000')).to.eql(new Date(Date.UTC(2024, 0, 1, 12, 12, 12)));
|
||||
});
|
||||
});
|
||||
describe('generateMongoFilter', () => {
|
||||
it('convert a date to mongo query', () => {
|
||||
expect(generateMongoFilter({
|
||||
date: new Date(Date.UTC(2024, 0, 1, 12, 12, 12)),
|
||||
tableName: 'comments',
|
||||
})).to.eql('db.comments.find({_id: {$gt: ObjectId("6592ac1c0000000000000000")}})');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
export function objectIdFromDate(date: Date) {
|
||||
return `${Math.floor(date.getTime() / 1000).toString(16)}0000000000000000`;
|
||||
};
|
||||
|
||||
export function objectIdSyntaxFromDate(date: Date) {
|
||||
return `ObjectId("${objectIdFromDate(date)}")`;
|
||||
};
|
||||
|
||||
export function generateMongoFilter(
|
||||
{
|
||||
tableName, date, operator = 'gt',
|
||||
}:
|
||||
{
|
||||
tableName: string
|
||||
date: Date
|
||||
operator?: 'gt' | 'lt'
|
||||
}) {
|
||||
return `db.${tableName}.find({_id: {$${operator}: ObjectId("${objectIdFromDate(date)}")}})`;
|
||||
}
|
||||
|
||||
export function dateFromObjectId(objectId: string) {
|
||||
return new Date(Number.parseInt(objectId.substring(0, 8), 16) * 1000);
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
<script setup lang="ts">
|
||||
import { dateFromObjectId, generateMongoFilter, objectIdFromDate, objectIdSyntaxFromDate } from './mongo-objectid-converter.service';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
const objectIdInput = ref(objectIdFromDate(new Date()));
|
||||
const dateOutput = computed(() =>
|
||||
withDefaultOnError(() => dateFromObjectId(objectIdInput.value), 'Invalid ObjectId'),
|
||||
);
|
||||
|
||||
const dateInput = ref(Date.now());
|
||||
const dateValue = computed(() => new Date(dateInput.value));
|
||||
const tableName = ref('tbl');
|
||||
const objectIdOutput = computed(() =>
|
||||
withDefaultOnError(() => objectIdFromDate(dateValue.value), 'Invalid Date'),
|
||||
);
|
||||
const objectIdSyntaxOutput = computed(() =>
|
||||
withDefaultOnError(() => objectIdSyntaxFromDate(dateValue.value), 'Invalid Date'),
|
||||
);
|
||||
const objectIdQueryOutput = computed(() =>
|
||||
withDefaultOnError(() => generateMongoFilter({ date: dateValue.value, tableName: tableName.value }), 'Invalid Date'),
|
||||
);
|
||||
const objectIdUTCDate = computed(() =>
|
||||
dateValue.value.toISOString(),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card :title="`ObjectId to Date (${currentTimeZone})`">
|
||||
<c-input-text
|
||||
v-model:value="objectIdInput"
|
||||
placeholder="Put your ObjectId here..."
|
||||
label="ObjectId to encode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<textarea-copyable
|
||||
:value="dateOutput instanceof Date ? dateOutput.toLocaleString(undefined, { timeZoneName: 'short' }) : dateOutput"
|
||||
/>
|
||||
<textarea-copyable
|
||||
:value="dateOutput instanceof Date ? dateOutput.toISOString() : dateOutput"
|
||||
/>
|
||||
</c-card>
|
||||
|
||||
<c-card :title="`Date to ObjectId (${currentTimeZone})`">
|
||||
<n-form-item label="Date and time" label-placement="left" mb-2 flex-1>
|
||||
<n-date-picker v-model:value="dateInput" type="datetime" />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="tableName"
|
||||
placeholder="Put your Table Name here..."
|
||||
label="Table Name"
|
||||
label-position="left"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<textarea-copyable :value="objectIdUTCDate" />
|
||||
<textarea-copyable :value="objectIdOutput" />
|
||||
<textarea-copyable :value="objectIdSyntaxOutput" />
|
||||
<textarea-copyable :value="objectIdQueryOutput" />
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Wifi } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'WPA PSK generator',
|
||||
path: '/wpa-psk-generator',
|
||||
description: 'WPA Pre-shared Key Generator to convert a WPA passphrase and SSID to the 256-bit pre-shared ("raw") key',
|
||||
keywords: ['wpa', 'psk', 'pre', 'shared', 'key', 'ssid', 'passphrase', 'generator'],
|
||||
component: () => import('./wpa-psk-generator.vue'),
|
||||
icon: Wifi,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { generateWpaPskRawKey } from './wpa-psk-generator.service';
|
||||
|
||||
describe('wpa-psk-generator', () => {
|
||||
it('generateWpaPskRawKey should generate raw key', () => {
|
||||
expect(generateWpaPskRawKey('test', 'test')).to.deep.eq({
|
||||
passphrase: 'test',
|
||||
psk: 'd630c5513becfd3952432bd7fcf098b7a40907f3214cf43551f1b8cfda873ecc',
|
||||
ssid: 'test',
|
||||
});
|
||||
expect(generateWpaPskRawKey('test', 'test')?.psk).toHaveLength(256 / 8 * 2);
|
||||
});
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
import CryptoJS from 'crypto-js';
|
||||
import pbkdf2 from 'crypto-js/pbkdf2';
|
||||
|
||||
export function generateWpaPskRawKey(ssid: string, passphrase: string) {
|
||||
const psk = pbkdf2(passphrase, ssid, {
|
||||
keySize: 256 / 32,
|
||||
iterations: 4096,
|
||||
hasher: CryptoJS.algo.SHA1,
|
||||
}).toString(CryptoJS.enc.Hex);
|
||||
return {
|
||||
ssid,
|
||||
passphrase,
|
||||
psk,
|
||||
};
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { generateWpaPskRawKey } from './wpa-psk-generator.service';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const ssid = ref('');
|
||||
const passphrase = ref('');
|
||||
|
||||
const wpaPSKRawKey = ref('');
|
||||
function computeRawKey() {
|
||||
try {
|
||||
wpaPSKRawKey.value = generateWpaPskRawKey(ssid.value, passphrase.value)?.psk;
|
||||
}
|
||||
catch (e: any) {
|
||||
wpaPSKRawKey.value = e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
const ssidValidation = useValidation({
|
||||
source: ssid,
|
||||
rules: [
|
||||
{
|
||||
validator: v => v !== '',
|
||||
message: 'SSID must not be empty.',
|
||||
},
|
||||
],
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="max-width: 600px;">
|
||||
<c-card title="Wifi Infos" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="ssid"
|
||||
label="SSID"
|
||||
label-position="left"
|
||||
placeholder="Put your SSID here..."
|
||||
:validation="ssidValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="passphrase"
|
||||
label="Passphrase"
|
||||
label-position="left"
|
||||
placeholder="Put your Passphrase here..."
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<n-button @click="computeRawKey()">Compute</n-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card title="WPA PSK Raw Key (256 bits)">
|
||||
<TextareaCopyable :value="wpaPSKRawKey" />
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user