0

I'm trying to get POST variables into my $ssh->exec The post variables are not being used in the command.I want $domain and $password to be used within the adduser as below.

I'm running this on a centos 7 server php 7.3 I can echo out variable but i can' t it to be used in the command.

I can echo out $domain and also $password.

An example post was

username:adada.com and Password:passwordwe3

This command with the strings entered worked fine.

set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/html/phpsec');
include ('Net/SSH2.php');
$ssh = new Net_SSH2('hostname');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}

$domain = $_POST['domain'];
$password = $_POST['password'];

echo $ssh->exec('adduser $domain -m -p $password -d /var/www/shared/$domain/public_html');
echo $ssh->exec('su $domain');
echo $ssh->exec('pwd');
die();

The error from the form is as follows. adduser: invalid user name '/var/www/shared//public_html' /root

neubert
  • 15,947
  • 24
  • 120
  • 212
James
  • 43
  • 1
  • 5

1 Answers1

0
echo $ssh->exec('adduser $domain -m -p $password -d /var/www/shared/$domain/public_html');
echo $ssh->exec('su $domain');

You're using single quotes when you should be using double quotes. Try this:

echo $ssh->exec("adduser $domain -m -p $password -d /var/www/shared/$domain/public_html");
echo $ssh->exec("su $domain");

Also, passing those variables through escapeshellarg is probably a good idea.

neubert
  • 15,947
  • 24
  • 120
  • 212
  • Thank you for explaining this. It worked! I'm still very much learning and trying to run before walking! Thanks again for your time and help. I'll check out escapeshellarg now. :) – James May 23 '19 at 03:27