#!/bin/bash
# Lead Capture API for Shared Hosting
# Place this in your bin/ or api/ directory

# Database credentials - UPDATE THESE
DB_HOST="localhost"
DB_NAME="your_database"
DB_USER="your_username"
DB_PASS="your_password"

# Simple lead capture handler
handle_lead_capture() {
    # Read POST data
    read -r name email company details
    
    # Insert into database (using mysql command line)
    mysql -h"$DB_HOST" -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" << EOF
INSERT INTO leads (name, email, company, notes, source) 
VALUES ('$name', '$email', '$company', '$details', 'system-audit');
EOF
    
    # Return success response
    echo '{"status": "success", "message": "Lead captured!"}'
}

# Check if called via web
if [[ "${REQUEST_METHOD}" == "POST" ]]; then
    handle_lead_capture
else
    echo '{"status": "error", "message": "Method not allowed"}'
fi