IVIEM TOOL - Server endpoints for worker (upload to cPanel)

Step 1 - Upload & extract:
- Upload this ZIP to cPanel File Manager (e.g., public_html/tool_api/) and extract.

Step 2 - Configure:
- Open tool_config.php in File Manager (Code Editor).
- Set DB credentials: host, user, pass, name.
- Set worker_token to a long random string (same used by worker processes).
- Generate encryption_key: run `php -r "echo base64_encode(random_bytes(32));"` locally and paste it.

Step 3 - Database migration:
- Open phpMyAdmin, select your app database, run database_migration.sql (paste and execute).
- Ensure 'jobs' table now has columns: email, encrypted_password, api_key, updated_at.
- Add job rows with 'email' and encrypted_password (see next step to encrypt).

Step 4 - Encrypt passwords for jobs:
- Use this sample PHP snippet locally to produce encrypted value to store in jobs.encrypted_password:

<?php
require 'db_tool.php'; // ensure tool_config.php has ENCRYPTION_KEY set
$plain = 'PASSWORD_HERE';
$blob = encrypt_password($plain, $ENCRYPTION_KEY);
echo $blob; // store this value in jobs.encrypted_password
?>

Step 5 - Test endpoints:
- Test new_job.php from terminal (replace token):
  curl -H "X-Worker-Token: YOUR_TOKEN" https://yourdomain.com/tool_api/new_job.php
- Test submit_key.php:
  curl -X POST -H "X-Worker-Token: YOUR_TOKEN" -H "Content-Type: application/json" \
    -d '{"job_id":1,"api_key":"SAMPLE"}' https://yourdomain.com/tool_api/submit_key.php

Security:
- Move tool_config.php outside public_html if possible.
- Protect tool_api folder via .htaccess or cPanel Directory Privacy if you want extra protection.

When ready, reply NEXT to continue with worker install steps on your laptop/VPS.
