mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/pdf-encrypt' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
b1fc3fe9d4
7 files changed
+317
-1
No files matched your search
@@ -4,6 +4,8 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ['@antfu', './.eslintrc-auto-import.json', '@unocss'],
|
||||
|
||||
ignorePatterns: ['src/libs/*'],
|
||||
|
||||
rules: {
|
||||
'curly': ['error', 'all'],
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ dev ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ dev ]
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
config: |
|
||||
paths-ignore:
|
||||
- src/libs
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
@@ -74,6 +74,7 @@
|
||||
"@types/arr-diff": "^4.0.3",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@types/pdfjs-dist": "^2.10.378",
|
||||
"@types/emscripten": "^1.39.10",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -173,6 +174,7 @@
|
||||
"pinia": "^2.0.34",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"qpdf-wasm-esm-embedded": "^1.1.1",
|
||||
"qrcode": "^1.5.1",
|
||||
"randexp": "^0.5.3",
|
||||
"regex": "^4.3.3",
|
||||
|
||||
Generated
+17
-1
@@ -80,6 +80,9 @@ dependencies:
|
||||
'@types/arr-diff':
|
||||
specifier: ^4.0.3
|
||||
version: 4.0.3
|
||||
'@types/emscripten':
|
||||
specifier: ^1.39.10
|
||||
version: 1.39.13
|
||||
'@types/figlet':
|
||||
specifier: ^1.5.8
|
||||
version: 1.5.8
|
||||
@@ -374,6 +377,9 @@ dependencies:
|
||||
pretty-ms:
|
||||
specifier: ^9.1.0
|
||||
version: 9.1.0
|
||||
qpdf-wasm-esm-embedded:
|
||||
specifier: ^1.1.1
|
||||
version: 1.1.1
|
||||
qrcode:
|
||||
specifier: ^1.5.1
|
||||
version: 1.5.1
|
||||
@@ -4139,6 +4145,10 @@ packages:
|
||||
'@types/trusted-types': 2.0.3
|
||||
dev: true
|
||||
|
||||
/@types/emscripten@1.39.13:
|
||||
resolution: {integrity: sha512-cFq+fO/isvhvmuP/+Sl4K4jtU6E23DoivtbO4r50e3odaxAiVdbfSYRDdJ4gCdxx+3aRjhphS5ZMwIH4hFy/Cw==}
|
||||
dev: false
|
||||
|
||||
/@types/estree@0.0.39:
|
||||
resolution: {integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==}
|
||||
dev: true
|
||||
@@ -5289,7 +5299,7 @@ packages:
|
||||
/@vueuse/shared@10.0.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
|
||||
dependencies:
|
||||
vue-demi: 0.14.10(vue@3.3.4)
|
||||
vue-demi: 0.14.5(vue@3.3.4)
|
||||
transitivePeerDependencies:
|
||||
- '@vue/composition-api'
|
||||
- vue
|
||||
@@ -10814,6 +10824,12 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/qpdf-wasm-esm-embedded@1.1.1:
|
||||
resolution: {integrity: sha512-e6Pb8jRw+VflZQvsS+eOfYF9BqjubvTBnxJc44LhI1btg2WYNKE5/lGMmzWZ2gd9YrdWByf8IdNZw6S7+7t27w==}
|
||||
dependencies:
|
||||
'@types/emscripten': 1.39.13
|
||||
dev: false
|
||||
|
||||
/qrcode@1.5.1:
|
||||
resolution: {integrity: sha512-nS8NJ1Z3md8uTjKtP+SGGhfqmTCs5flU/xR623oI0JX+Wepz9R8UrRVCTBTJm3qGw3rH6jJ6MUHjkDx15cxSSg==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
|
||||
@@ -145,6 +145,7 @@ import { tool as uuidGenerator } from './uuid-generator';
|
||||
import { tool as macAddressLookup } from './mac-address-lookup';
|
||||
import { tool as xmlFormatter } from './xml-formatter';
|
||||
import { tool as dockerComposeToDockerRunConverter } from './docker-compose-to-docker-run-converter';
|
||||
import { tool as pdfEncrypt } from './pdf-encrypt';
|
||||
import { tool as yamlViewer } from './yaml-viewer';
|
||||
import { tool as barcodeReader } from './barcode-reader';
|
||||
import { tool as barcodeGenerator } from './barcode-generator';
|
||||
@@ -170,6 +171,9 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
certificateKeyParser,
|
||||
passwordStrengthAnalyser,
|
||||
pdfSignatureChecker,
|
||||
passwordStrengthAnalyser,
|
||||
pdfSignatureChecker,
|
||||
pdfEncrypt,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Lock } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Pdf Encrypt',
|
||||
path: '/pdf-encrypt',
|
||||
description: 'Encrypt and add protection to a PDF File',
|
||||
keywords: ['pdf', 'encrypt'],
|
||||
component: () => import('./pdf-encrypt.vue'),
|
||||
icon: Lock,
|
||||
createdAt: new Date('2024-01-09'),
|
||||
});
|
||||
@@ -0,0 +1,208 @@
|
||||
<script setup lang="ts">
|
||||
import { Base64 } from 'js-base64';
|
||||
import createQPDFModule from 'qpdf-wasm-esm-embedded';
|
||||
import { useDownloadFileFromBase64Refs } from '@/composable/downloadBase64';
|
||||
|
||||
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
|
||||
const file = ref<File | null>(null);
|
||||
|
||||
const restrictAccessibility = useStorage('pdf-encrypt:accessibility', false);
|
||||
const restrictAnnotate = useStorage('pdf-encrypt:annotate', false);
|
||||
const restrictAssemble = useStorage('pdf-encrypt:assemble', false);
|
||||
const restrictExtract = useStorage('pdf-encrypt:extract', false);
|
||||
const restrictForm = useStorage('pdf-encrypt:form', false);
|
||||
const restrictModifyOther = useStorage('pdf-encrypt:modoth', false);
|
||||
const clearTextMetadata = useStorage('pdf-encrypt:clearmeta', false);
|
||||
const restrictModify = useStorage('pdf-encrypt:mod', 'all');
|
||||
const restrictPrint = useStorage('pdf-encrypt:print', 'full');
|
||||
const userPassword = ref('');
|
||||
const ownerPassword = ref('');
|
||||
|
||||
const base64OutputPDF = ref('');
|
||||
const logs = ref<string[]>([]);
|
||||
const fileName = ref('');
|
||||
const fileExtension = ref('pdf');
|
||||
const { download } = useDownloadFileFromBase64Refs(
|
||||
{
|
||||
source: base64OutputPDF,
|
||||
filename: fileName,
|
||||
extension: fileExtension,
|
||||
});
|
||||
|
||||
function onFileUploaded(uploadedFile: File) {
|
||||
file.value = uploadedFile;
|
||||
fileName.value = `encrypted_${file.value.name}`;
|
||||
}
|
||||
|
||||
async function onProcessClicked() {
|
||||
if (!file.value) {
|
||||
return;
|
||||
}
|
||||
const fileBuffer = await file.value.arrayBuffer();
|
||||
|
||||
status.value = 'processing';
|
||||
try {
|
||||
const options = [
|
||||
'--verbose',
|
||||
'--encrypt',
|
||||
];
|
||||
options.push(`${userPassword.value}`);
|
||||
options.push(`${ownerPassword.value}`);
|
||||
options.push('128');
|
||||
options.push('--use-aes=y');
|
||||
options.push(`--accessibility=${(restrictAccessibility.value ? 'n' : 'y')}`);
|
||||
options.push(`--annotate=${(restrictAnnotate.value ? 'n' : 'y')}`);
|
||||
options.push(`--assemble=${(restrictAssemble.value ? 'n' : 'y')}`);
|
||||
options.push(`--extract=${(restrictExtract.value ? 'n' : 'y')}`);
|
||||
options.push(`--form=${(restrictForm.value ? 'n' : 'y')}`);
|
||||
options.push(`--modify-other=${(restrictModifyOther.value ? 'n' : 'y')}`);
|
||||
options.push(`--modify=${(restrictModify.value)}`);
|
||||
options.push(`--print=${(restrictPrint.value)}`);
|
||||
if (clearTextMetadata.value) {
|
||||
options.push('--cleartext-metadata');
|
||||
}
|
||||
options.push('--');
|
||||
options.push('in.pdf');
|
||||
options.push('out.pdf');
|
||||
const outPdfBuffer = await callMainWithInOutPdf(fileBuffer,
|
||||
options, 0);
|
||||
base64OutputPDF.value = `data:application/pdf;base64,${Base64.fromUint8Array(outPdfBuffer)}`;
|
||||
status.value = 'done';
|
||||
|
||||
download();
|
||||
}
|
||||
catch (e) {
|
||||
status.value = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
async function callMainWithInOutPdf(data: ArrayBuffer, args: string[], expected_exitcode: number) {
|
||||
logs.value = [];
|
||||
const mod = await createQPDFModule({
|
||||
print(text: string) {
|
||||
logs.value.push(text);
|
||||
},
|
||||
printErr(text: string) {
|
||||
logs.value.push(text);
|
||||
},
|
||||
});
|
||||
mod.FS.writeFile('in.pdf', new Uint8Array(data));
|
||||
const ret = mod.callMain(args);
|
||||
if (expected_exitcode !== ret) {
|
||||
throw new Error('Process run failed');
|
||||
}
|
||||
return mod.FS.readFile('out.pdf');
|
||||
}
|
||||
|
||||
const printRestrictionOptions = [{ value: 'none', label: 'Disallow printing' },
|
||||
{ value: 'low', label: 'Allow only low-resolution printing' },
|
||||
{ value: 'full', label: 'Allow full printing' },
|
||||
];
|
||||
const modificationRestrictionOptions = [
|
||||
{ value: 'none', label: 'Allow no modifications' },
|
||||
{ value: 'assembly', label: 'Allow document assembly only' },
|
||||
{ value: 'form', label: 'Allow document assembly only + filling in form fields and signing' },
|
||||
{ value: 'annotate', label: 'Allow document assembly only + filling in form fields and signing + commenting and modifying forms' },
|
||||
{ value: 'all', label: 'Allow full document modification' },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div style="flex: 0 0 100%">
|
||||
<div mx-auto max-w-600px>
|
||||
<c-file-upload
|
||||
title="Drag and drop a PDF file here, or click to select a file"
|
||||
accept=".pdf"
|
||||
@file-upload="onFileUploaded"
|
||||
/>
|
||||
<div mt-2 text-center>
|
||||
<strong>Output file:</strong> {{ fileName }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-card title="Permissions" mb-3 mt-3>
|
||||
<n-space>
|
||||
<n-checkbox v-model:checked="restrictAccessibility">
|
||||
Restrict accessibility (usually ignored)
|
||||
</n-checkbox>
|
||||
<n-checkbox v-model:checked="restrictAnnotate">
|
||||
Restrict commenting/filling form fields
|
||||
</n-checkbox>
|
||||
<n-checkbox v-model:checked="restrictAssemble">
|
||||
Restrict document assembly
|
||||
</n-checkbox>
|
||||
<n-checkbox v-model:checked="restrictExtract">
|
||||
Restrict text/graphic extraction
|
||||
</n-checkbox>
|
||||
<n-checkbox v-model:checked="restrictForm">
|
||||
Restrict filling form fields
|
||||
</n-checkbox>
|
||||
<n-checkbox v-model:checked="restrictModifyOther">
|
||||
Restrict other modifications
|
||||
</n-checkbox>
|
||||
<n-checkbox v-model:checked="clearTextMetadata">
|
||||
Prevent encryption of metadata
|
||||
</n-checkbox>
|
||||
</n-space>
|
||||
<c-select
|
||||
v-model:value="restrictModify"
|
||||
:options="modificationRestrictionOptions"
|
||||
label="Control modify access by level"
|
||||
mt-3
|
||||
/>
|
||||
<c-select
|
||||
v-model:value="restrictPrint"
|
||||
:options="printRestrictionOptions"
|
||||
label="Control printing access"
|
||||
mt-3
|
||||
/>
|
||||
</c-card>
|
||||
<n-form-item
|
||||
label="Owner password:"
|
||||
label-placement="left"
|
||||
mb-1
|
||||
>
|
||||
<n-input
|
||||
:value="ownerPassword"
|
||||
type="password"
|
||||
placeholder="Owner password (optional)"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item
|
||||
label="User password:"
|
||||
label-placement="left"
|
||||
mb-1
|
||||
>
|
||||
<n-input
|
||||
:value="userPassword"
|
||||
type="password"
|
||||
placeholder="User password (optional)"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<div mt-3 flex justify-center>
|
||||
<c-button :disabled="!file" @click="onProcessClicked()">
|
||||
Encrypt PDF
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div mt-3 flex justify-center>
|
||||
<c-alert v-if="status === 'error'" type="error">
|
||||
An error occured processing {{ fileName }}
|
||||
</c-alert>
|
||||
<n-spin
|
||||
v-if="status === 'processing'"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<c-card title="Logs">
|
||||
<pre>{{ logs.join('\n') }}</pre>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user