<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = escapeshellarg(trim($_POST['username'])); // Sanitize input
    $password = escapeshellarg(trim($_POST['password'])); // Sanitize input
    $captcha = strtolower(trim($_POST['captcha'])); // Normalize input
    
    // Correct answer to the CAPTCHA question
    $correct_answer = 'XXXXXXXX'; // Same as the background color in index.php

    // Check CAPTCHA answer
    if ($captcha !== $correct_answer) {
        echo "Incorrect CAPTCHA answer. Please try again.";
        exit;
    }

    // Command to register the user using prosodyctl
    $command = "sudo /usr/bin/prosodyctl register $username xmpp.glamour.ovh $password"; // Update domain

    // Execute the command
    $output = array();
    $return_var = 0; // Variable to capture the command exit status

    exec($command, $output, $return_var);

    // Check if registration was successful
    if ($return_var === 0) {
        echo "Registration successful!";
    } else {
        echo "Registration failed: " . implode("\n", $output);
    }
} else {
    echo "Invalid request method.";
}
?>

