I am trying to programmatically control a Netonix WISP switch ( https://www.netonix.com/wisp-switch/ws-8-150-dc.html ) at a remote location.
Specifically I want to be able to turn PoE on selected ports on and off under certain circumstances from an AWS EC2 instance.
But I am not having much luck doing it with B4J.
I've made an earlier probe on this subject in the forums here:
https://www.b4x.com/android/forum/threads/sshj-ssh-scp-sftp-for-java.88615/page-2#post-586467
But I am reluctantly coming to the conclusion that it might not be easy or even possible to do with B4J alone.
After much digging around I have found PHP code here:
https://forum.netonix.com/viewtopic.php?f=8&t=2657&p=18570&hilit=php+poe#p18579
that looks like it could be adapted to do what I want:
My untrained eye sees statements like ssh2_shell in this PHP that I haven't seen in any other environment so maybe PHP is unavoidable?
However, I have never touched PHP in my life and would prefer not to at this point.
I would be interested in any suggestions, guidance, pointers etc of how to proceed.
Thanks in anticipation...
Specifically I want to be able to turn PoE on selected ports on and off under certain circumstances from an AWS EC2 instance.
But I am not having much luck doing it with B4J.
I've made an earlier probe on this subject in the forums here:
https://www.b4x.com/android/forum/threads/sshj-ssh-scp-sftp-for-java.88615/page-2#post-586467
But I am reluctantly coming to the conclusion that it might not be easy or even possible to do with B4J alone.
After much digging around I have found PHP code here:
https://forum.netonix.com/viewtopic.php?f=8&t=2657&p=18570&hilit=php+poe#p18579
that looks like it could be adapted to do what I want:
B4X:
#!/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);
?>
My untrained eye sees statements like ssh2_shell in this PHP that I haven't seen in any other environment so maybe PHP is unavoidable?
However, I have never touched PHP in my life and would prefer not to at this point.
I would be interested in any suggestions, guidance, pointers etc of how to proceed.
Thanks in anticipation...