<?php if (!function_exists ("ssh2_connect")) die ("function ssh2_connect doesn't exist"); if(!($con = ssh2_connect("localhost", 22))){ echo "fail: unable to establish connection\n"; } else { // if(!ssh2_auth_password($con, "root", $_GET["password"])) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...\n"; // if (!($stream = ssh2_exec($con, "poweroff" ))) { echo "fail: unable to execute command\n"; } else { // collect returning data from command stream_set_blocking ($stream, true); $data = ""; while ($buf = fread ($stream,4096)) { $data .= $buf; } fclose ($stream); echo $data; } } } ?>
Source: https://habr.com/ru/post/151526/
All Articles