Files
VoxVera/src/README.md
2025-06-17 18:52:41 -04:00

3.9 KiB

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

  1. Update your package list:

    sudo apt update
    
  2. Install Node.js and npm:

    sudo apt install nodejs npm -y
    
  3. Verify the installation:

    node -v
    npm -v
    

Install Required Tools

  1. Install Terser:

    npm install -g terser
    
  2. Install html-minifier-terser:

    npm install -g html-minifier-terser
    

Script Usage

Running the Script

  1. Save the script as obfuscate.sh.
  2. Make the script executable:
    chmod +x obfuscate.sh
    
  3. 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:

  1. Install VSCode:

  2. Open your project in VSCode:

    code /path/to/your/project
    
  3. Edit the script by clicking on the obfuscate.sh file in the file explorer.

  4. Run the script within the VSCode terminal:

    • Open the terminal in VSCode: View > Terminal.
    • Run the script:
      ./obfuscate.sh
      

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 existing filled PDF form
./create_flyer.sh --from-pdf path/to/form.pdf

By default the script updates src/config.json. 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.