Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

Nearly there with parameters but...

Hi guys.
You brilliant kind geniuses have nearly done this for me, and Im nearly there with a question i posted earlier.

Ill recap.

From a command line, I can run the following perl script successfully.....

----------------------------------------------------------------------------------------------------------
perl e:\datacenterlisting.pl --server "serverA" --datacenter "dcname" --username "domain\username" --password "password"'

------------------------------------------------------------------------------------------------------------
The above works fine....and at the command line, i enclose all options in double quotes.

You guys have helped me code the following php page, so that i can enter in whatever server, datacenter, username, and password i like in textboxes.
Then these values become the options for the perl script.

I have placed an echo command in the following php page to show you what the current perl script command line is when executed through the php page. The only problem it looks like, is that the username option, which I enter as domain\username, becomes domain\\username when executed. So a double backslash is inserted, when it should remain as one backslash, that is, domain\username.

So what it should be is:

perl e:\datacenterlisting.pl --server "serverA" --datacenter "dcname" --username "domain\username" --password "password"'

when on echoing this through php, it is...
                                                                                                               |<-double backslash problem->|
perl e:\datacenterlisting.pl --server "serverA" --datacenter "dcname" --username "domain\\username" --password "password"'


Here is the code guys.....
Really appreciate your help on this...

------------------------------------------------------------------------------------------------------------- test.php
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
Server: <input type="text" name="server" value="<?php echo htmlspecialchars(@$_POST['server']); ?>" /><br/>
Datacenter: <input type="text" name="datacenter" value="<?php echo htmlspecialchars($_POST['datacenter']); ?>" /><br/>
Username: <input type="text" name="username" value="<?php echo htmlspecialchars(@$_POST['username']); ?>" /><br/>
Password: <input type="password" name="password" /><br/> <input type="submit" value="show listing" /> </form> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') {  $shellStr = sprintf(
   'perl e:\datacenterlisting.pl --server "%s" --datacenter "%s" --username "%s" --password "%s"'
  , $_POST['server'],$_POST['datacenter']
  , $_POST['username']
  , $_POST['password']
  );
  echo 'Results:<pre>'.htmlspecialchars(shell_exec($shellStr)).'</pre>';
 echo $_POST['datacenter'];
echo '<br>';
echo $shellStr;
}
?>
------------------------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Simon336697

ASKER

Hi mp,

Ill try this..

Will this remove all backslashes though?

Because I need to enter in the textbox:

Username:   domain\username

Then when I submit, the echo out should be:

perl e:\datacenterlisting.pl --server "serverA" --datacenter "dcname" --username "domain\username" --password "password"'

That is, to RETAIN the backslash, but DONT add a second backslash.

mp that works!!!!!

Thanks so much mp!
Working code is..............................

----------------------------------------------------------------------------------------- testing.php

<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
Server: <input type="text" name="server" value="<?php echo htmlspecialchars(@$_POST['server']); ?>" /><br/>
Datacenter: <input type="text" name="datacenter" value="<?php echo htmlspecialchars($_POST['datacenter']); ?>" /><br/>
Username: <input type="text" name="username" value="<?php echo htmlspecialchars(@$_POST['username']); ?>" /><br/>
Password: <input type="password" name="password" /><br/> <input type="submit" value="show listing" /> </form> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') {  $shellStr = sprintf(
   'perl e:\datacenterlisting.pl --server "%s" --datacenter "%s" --username "%s" --password "%s"'
  , $_POST['server'],$_POST['datacenter']
  , stripslashes($_POST['username']);
  , $_POST['password']
  );
  echo 'Results:<pre>'.htmlspecialchars(shell_exec($shellStr)).'</pre>';
 echo $_POST['datacenter'];
echo '<br>';
echo $shellStr;
}
?>

-------------------------------------------------------------------------------------------------