0

I want to know how can I execute a command which requires entering password after it, using php form.

I am sending the username using a form on a website. This example is my php code for removing user from Redis and it is working. Rm_user is an executable written in C++.

<?php

$email=$_GET['email']; 

$command = sprintf("./rm_user %s", $email);

if ($email != null) {
$output = shell_exec($command);
}
echo "$output";
?>

What is want to know is, how can I edit this script to add admin to the apache2 server, using htpasswd. The command line for it is:

sudo htpasswd /etc/apache2/.htpasswd username

It wouldn't be a big deal if it doesn't require to enter the password afterwards. But after that command you are prompted to enter the password. So, is it possible to do this the way I am doing it, or should I consider other options?

Mirakurun
  • 4,859
  • 5
  • 16
  • 32

1 Answers1

1

Have you tried sudo htpasswd -b /etc/apache2/.htpasswd username password?

Mads Marquart
  • 490
  • 1
  • 7
  • 15
  • 1
    Yeah I did, I solved it the same day, but I forgot to answer it. I accepted your answer for future reference. – Mirakurun Jun 07 '16 at 11:39