I am writing a PHP script where I take input from user like server IP and one more input.
After this is available, I make ssh call to the server and execute some command. I want to show the output on the web page but i gets error as 500 (server error).
Here is my main script where i get input from user:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Centos Health Checker</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="login-form">
<form method="post" action="redirectPage.php">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="IP" placeholder="System IP" required /></td>
</tr>
<tr>
<td><input type="text" name="Component" placeholder="Component" required /></td>
</tr>
<tr>
<td><button type="submit" name="submit">Check System</button></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
Here is my landing page:
<?php
function Connect()
{
include('/home/as5714/php_data/Net/SSH2.php');
$IP1 = $_POST['IP'];
$Component1 = $_POST['Component'];
$ssh = new Net_SSH2($IP1);
if (!$ssh->login('centos', 'centos')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
}
if(isset($_POST['submit']))
{
Connect();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $IP1; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="left">
<label>cleartuts</label>
</div>
<div id="right">
<div id="content">
Cennecting to ' <?php echo $IP1; ?> and Data is : <?php echo $data2; ?> <a href="homePage.php">Go Back</a>
</div>
</div>
</div>
</body>
</html>
I am getting server error(500) while using above php code.
Please note that I am working on vim editor on a linux server for the script and do not have any logs available. Also, If I just run the program to do ssh connection and execution of command in server directly (php 123.php), I get proper data on console.
Please help.