ub007 Posted August 30, 2008 Share Posted August 30, 2008 Hello, This is my first post and hope i wont be disappointed . I have setup an intranet of 10 machines(all running Ubuntu). I use ssh from command line to administer this n/w & to run scripts on each of them.I just thought about creating a browser interface to do this job so that someone else could easily do the same in a user friendly convenient way.In doing so I would be providing a layer of abstraction to the new user.I'm not thinking bout security at the moment!."After an hour of googling,i think PHP could do the job. In a nutshell -a browser interface under Apache web server that would connect to any of the machines in the intranet (as selected by the user). -the connection would be via ssh To give a more clearer picture: At the end of it,i would like to have an interface on machine A,say with 9 PCs listed on the GUI.I select machine 3-the click connects to machine 3 from machine A via ssh.I would then have say eg-'buttons' for 3 tasks...select task 1 and it would run a perl script which resides on machine 3.....so on... Could anyone tell me how to go about accomplishing this.....I have little programming knowledge but trying to work on it,Could anyone tell me how to go about accomplishing this.....I have little programming knowledge but trying to work on it,heres what i did so far.... created a form admin.php <html> <head><title>ClientForm</title></head> <body> <h1>hi:</h1> <form action="admin_action.php" method="GET"> servername: <input type="text" name="name" /><br /> Password: <input type="password" name="pword" /><br /> <input type="submit" value="GO" /> </form> </body> </html> then in another file admin_action.php,put in this code <html> <title>ClientTerminal</title> <body> <p>You entered:</p> <?php $servername = $_GET['name']; $password = $_GET['pword']; //echo "<p>servername= " . $servername . "</p>"; //echo "<p>Password = " . $password . "</p>"; if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); // log in at server1.example.com on port 22 if(!($con = ssh2_connect($servername, 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "root", $password)) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...\n"; // execute a command $stream = ssh2_exec($con, 'ps ax'); $output = stream_get_contents($stream); } } ?> </body> </html> Now i access http://localhost/admin.php server name:ubuntu.surey.com password:******* click the GO button Result: okay: logged in... I assume the ssh is working fine:thumbsup: but the rest of it is not....how do i get this code to execute the command Cheers David Link to comment https://forums.phpfreaks.com/topic/122037-web-interface-to-run-scriptscommands-on-remote-pcs-usin-sshposted-sat-aug-30/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.