Hi everyone hope u can help.
The following command I can run from a command line no problem at all.
--------------------------
----------
----------
----------
----------
----------
----------
------ From a command line:
C:\wamp\www>perl datacenterlisting.pl --server "serverA" --datacenter "datacenterA" --username "domain\userA" --password "password"
What the output returns from above is the following.................
..........
..........
.. Output:
Hosts found:
1: hostA
2: hostB
3: hostC
etc etc
VM's found:
1: machineAvm
2: machineBvm
2: machineBvm
3: machineCvm
4: machineDvm
etc etc
--------------------------
-------- End of output.
What Im trying to do is to execute the command from a web page using php and perl.
I have ActiveState Perl and PHP 5, and my current web page layout is as follows...........
--------------------------
----------
----------
----------
----------
----------
----------
- Test.php
VC Server: _________________
Datacenter/s: DatacenterA [ ] DatacenterB [ ] DatacenterC [ ]
Username: _____________________
Password: _____________________
<Show Listing button>
--------------------------
----------
----------
-- Comments about Test.php
In the above, I do the following on the page...
- I enter in a server name in the 'VC Server' textbox
- I select what datacenters I want to run the perl script against by checking the radio buttons next to Datacenter/s:
- I enter in the username in the format: <somain>\<username>
- I enter in a password.
- Then I click on the Show Listing submit button.
This then executes a perl command (the same one that I previously did from a command line), and takes the POSTED values from the form as parameters to pass to this perl command.
When I do this, all Im getting at the moment, is just the following output when doing this through a php page....
--------------------------
----------
----------
----------
----------
- Current output through Test.php
DatacenterA
perl c:\datacenterlisting.pl --server "serverA" --datacenter "DatacenterA" --username "domainusername" --password "password"
As you can see from the above, the output is just displaying the command, but not returning any results.
Part of the problem seems to be the username "domainusername".
I submitted this as domain\username, but as you can see from above, it says "domainusername" with no backslash.
Even if I enter 2 backslashes, the output "looks" correct, as the following shows, but im not getting any results returned in the page, other than...
perl c:\datacenterlisting.pl --server "serverA" --datacenter "DatacenterA" --username "domain\username" --password "password"
instead of what I require, which would be something like.......
perl c:\datacenterlisting.pl --server "serverA" --datacenter "DatacenterA" --username "domain\username" --password "password"
Hosts found:
1: hostA
2: hostB
3: hostC
etc etc
VM's found:
1: machineAvm
2: machineBvm
2: machineBvm
3: machineCvm
4: machineDvm
etc etc
--------------------------
-------- End of output.
Guys here is my current code.
If you could kindly help me find out why the script is not executing like it is at a command line, and returning results, Id be most appreciative :>)
--------------------------
----------
----------
----------
----------
----------
----------
----------
--- Test.php
<form method="post" action="<?php echo htmlspecialchars($_SERVER[
'PHP_SELF'
]);?>">
<b>VC Server:</b>
<input type="text" name="server" value="<?php echo htmlspecialchars(@$_POST['
server']);
?>" /><br/><br>
<div style="background:silver; margin-top:5px; border:solid 1px black;"> <b>Datacenter/s:</b>
datacenterA: <input type="checkbox" name="chkdc[]" value="datacenterA">
datacenterB: <input type="checkbox" name="chkdc[]" value="datacenterB">
datacenterC: <input type="checkbox" name="chkdc[]" value="datacenterC">
</div><br>
Username: <input type="text" name="username" value="<?php echo htmlspecialchars(@$_POST['
username']
); ?>" /><br/>
Password: <input type="password" name="password" /><br/> <input type="submit" name="Submit" value="show listing" />
<?php
if($_SERVER['REQUEST_METHO
D'] == 'POST' && strval($_POST['Submit'])==
"show listing") {
$dataCenter=$_POST['chkdc'
];
foreach($dataCenter as $k => $v)
{
$shellStr = sprintf(
'perl c:\datacenterlisting.pl --server "%s" --datacenter "%s" --username "%s" --password "%s"',
$_POST['server'],$v,
stripslashes($_POST['usern
ame']),
$_POST['password']
);
echo 'Results:<pre>'.htmlspecia
lchars(she
ll_exec($s
hellStr)).
'</pre>';
echo $v;
echo '<br>';
echo $shellStr;
}
echo " <input type='submit' name='refresh' value='Refresh' />";
}
?>
</form>
--------------------------
----------
----------
----------
----------
----------
----------
-------
Start Free Trial