<?
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'NOT AUTHORIZED';
    exit;
} else {
    if ($_SERVER['PHP_AUTH_USER']=="admin2" && $_SERVER['PHP_AUTH_PW']=="atixpbx2606")
		{
		
$switch="X";		
$hab=$_GET["hab"];
if ($hab>100 && $hab<110) { $switch="192.168.3.221"; $puerto=$hab-100; }
if ($hab>200 && $hab<210) { $switch="192.168.3.221"; $puerto=($hab-200)+10; }
if ($hab>300 && $hab<310) { $switch="192.168.3.223"; $puerto=$hab-300; }
if ($hab>400 && $hab<410) { $switch="192.168.3.223"; $puerto=($hab-400)+10; }
if ($hab>500 && $hab<510) { $switch="192.168.3.225"; $puerto=$hab-500; }
if ($hab>600 && $hab<610) { $switch="192.168.3.225"; $puerto=($hab-600)+10; }

if ($switch!="X")
	{
	$connection = ssh2_connect($switch, 22); 
ssh2_auth_password($connection,"cisco","sapoop23");
$stdio_stream = ssh2_shell($connection); 
fwrite($stdio_stream,"configure terminal\n"); 
sleep(1); 
fwrite($stdio_stream,"interface fe".$puerto."\n"); 
sleep(1); 
fwrite($stdio_stream,"power inline never\n"); 
sleep(10); 
fwrite($stdio_stream,"power inline auto\n"); 
sleep(1); 
fwrite($stdio_stream,"end\n"); 
sleep(1); 
fwrite($stdio_stream,"exit\n"); 
sleep(1); 
$output=stream_get_contents($stdio_stream);
$output=str_replace("\n", "<br>", $output);
echo $output;
	}
		}
		}
?>