register.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  3. $username = escapeshellarg(trim($_POST['username'])); // Sanitize input
  4. $password = escapeshellarg(trim($_POST['password'])); // Sanitize input
  5. $captcha = strtolower(trim($_POST['captcha'])); // Normalize input
  6. // Correct answer to the CAPTCHA question
  7. $correct_answer = 'XXXXXXXX'; // Same as the background color in index.php
  8. // Check CAPTCHA answer
  9. if ($captcha !== $correct_answer) {
  10. echo "Incorrect CAPTCHA answer. Please try again.";
  11. exit;
  12. }
  13. // Command to register the user using prosodyctl
  14. $command = "sudo /usr/bin/prosodyctl register $username xmpp.glamour.ovh $password"; // Update domain
  15. // Execute the command
  16. $output = array();
  17. $return_var = 0; // Variable to capture the command exit status
  18. exec($command, $output, $return_var);
  19. // Check if registration was successful
  20. if ($return_var === 0) {
  21. echo "Registration successful!";
  22. } else {
  23. echo "Registration failed: " . implode("\n", $output);
  24. }
  25. } else {
  26. echo "Invalid request method.";
  27. }
  28. ?>