#!/bin/php
<?php
function help() {
print "\r\n** Syntax error - You must supply all of the following options:\r\n\r\n";
print " h <host> The hostname or IP address for the Netonix\r\n";
print " n <portnumber> The port number that you wish to alter\r\n";
print " v <value> The value for the PoE, off, 24V, 24VH, 48V, 48VH\r\n";
print " u <username> The username to use for logging in\r\n";
print " p <password> The Password used to log into the switch\r\n";
print "\r\n";
exit(1);
}
$options = getopt("h:u:p:n:v:");
if((!isset($options['h'])) || (!isset($options['u'])) || (!isset($options['p'])) || (!isset($options['n'])) || (!isset($options['v']))) {
help();
}else{
$host = ($options['h']);
$username = ($options['u']);
$password = ($options['p']);
$port = ($options['n']);
$poe = ($options['v']);
}
print "Setting PoE to $poe on port $port of $host\r\n";
// Setup the SSH connection
$connection = ssh2_connect($host);
ssh2_auth_password($connection, $username, $password);
$shell=ssh2_shell($connection, 'switch');
fwrite( $shell, 'conf'.PHP_EOL);
fwrite( $shell, 'interface port '.$port.PHP_EOL);
fwrite( $shell, 'poe '.$poe.PHP_EOL);
fwrite( $shell, 'exit'.PHP_EOL);
fwrite( $shell, 'exit'.PHP_EOL);
sleep(1); // wait for the confirm prompt
fwrite( $shell, PHP_EOL); // send ENTER to confirm
fwrite( $shell, 'exit'.PHP_EOL); // exit the CLI which will terminate the SSH session
// Turn on blocking so it doesn't disconnect between multiple commands
stream_set_blocking($shell, true);
// Display any output
echo 'Output: '.stream_get_contents($shell)."\r\n";
// Close the connection
fclose($shell);
?>