HTML/CSS/JS Obfuscation Script
This repository contains a simple Bash script to obfuscate and minify a single HTML file that contains embedded CSS and JavaScript. The script takes an index-master.html
file as input and produces an index.html
file as output.
Prerequisites
- Debian/Ubuntu: This script is designed to work on Debian-based systems.
- Node.js: Terser and html-minifier-terser require Node.js to be installed.
- qrencode: Generates the QR codes used in the flyers.
Install Node.js and npm on Debian
-
Update your package list:
sudo apt update
-
Install Node.js and npm:
sudo apt install nodejs npm -y
-
Verify the installation:
node -v npm -v
Install Additional Packages
The helper scripts rely on a few system utilities:
sudo apt install -y jq qrencode imagemagick poppler-utils
Install Required Tools
Install the Node-based tools used by the obfuscation scripts:
npm install -g javascript-obfuscator html-minifier-terser
You can also run ../setup.sh
from the repository root to install all
prerequisites automatically.
Script Usage
Running the Script
- Save the script as
obfuscate.sh
. - Make the script executable:
chmod +x obfuscate.sh
- Run the script:
./obfuscate.sh
Script Details
- Input File: The script takes
index-master.html
as the input file. - Output File: The script outputs the obfuscated and minified version as
index.html
. - Error Handling: The script checks if
index-master.html
exists before proceeding. If the file does not exist, it will exit with an error message. - Terser and HTML-Minifier-Terser: The script first uses Terser to obfuscate any embedded JavaScript, then minifies the entire HTML file, including embedded CSS and JavaScript.
Script Example
#!/bin/bash
# Input and output file names
input_file="index-master.html"
output_file="index.html"
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Input file $input_file does not exist."
exit 1
fi
# Obfuscate embedded JavaScript using terser
terser_output=$(mktemp)
terser --compress --mangle -- "$input_file" > "$terser_output"
# Minify HTML, including the embedded CSS and the obfuscated JavaScript
html-minifier-terser \
--collapse-whitespace \
--minify-css true \
--minify-js true \
--remove-comments \
--remove-empty-attributes \
--output "$output_file" \
"$terser_output"
# Clean up temporary file
rm "$terser_output"
echo "Obfuscation and minification complete. Output saved as $output_file."
Editing the Script in Visual Studio Code (VSCode)
If you prefer to use Visual Studio Code to edit and run this script:
-
Install VSCode:
- Follow the official Visual Studio Code installation guide for Debian-based systems.
-
Open your project in VSCode:
code /path/to/your/project
-
Edit the script by clicking on the
obfuscate.sh
file in the file explorer. -
Run the script within the VSCode terminal:
- Open the terminal in VSCode:
View > Terminal
. - Run the script:
./obfuscate.sh
- Open the terminal in VSCode:
Creating and Hosting a Flyer
The create_flyer.sh
script automates filling config.json
, building the HTML files, and copying everything into a new directory under host/
.
Usage
# interactive mode
./create_flyer.sh
# use an alternate config file
./create_flyer.sh -c path/to/custom.json
# use an existing filled PDF form
./create_flyer.sh --from-pdf path/to/form.pdf
By default the script updates src/config.json
. Use the -c
option to specify a different file. After answering the prompts (or extracting from the PDF), index.html
and nostr.html
are generated and copied along with the QR code images and PDFs. The files end up in host/<subdomain>
which can be served statically.
QR codes are built automatically during this process. After the configuration is updated, create_flyer.sh
calls generate_qr.sh
to read the URLs from config.json
and produce qrcode-content.png
and qrcode-tear-offs.png
.