funguse Posted August 14, 2007 Share Posted August 14, 2007 Hey, I'm currently working on the intranet site for our company and i've been asked to create a site where the status of our unix server is been displayed. at the moment all admins have their own logon using AIX (v4) and using the command topas to display the idle and other info. what i want to do is create we php script that connects to the server using a logon and executing the topas command. i then want to display the idle process (but tahts not that importaint. i'll get to that when i'm able to connect to the server (if thats possbile lol) Quote Link to comment Share on other sites More sharing options...
dbo Posted August 14, 2007 Share Posted August 14, 2007 Is the server in question also the webserver? Quote Link to comment Share on other sites More sharing options...
funguse Posted August 14, 2007 Author Share Posted August 14, 2007 no its not Quote Link to comment Share on other sites More sharing options...
trq Posted August 14, 2007 Share Posted August 14, 2007 What exactly is your question? I don't see one in your post. Quote Link to comment Share on other sites More sharing options...
funguse Posted August 14, 2007 Author Share Posted August 14, 2007 sorry, my question is, how can i connect to the unix server with a specific username and password via a php script (if thats possible at all) and if you can how can you execute certain commands and getting the info back to the intranet server. Quote Link to comment Share on other sites More sharing options...
funguse Posted August 15, 2007 Author Share Posted August 15, 2007 any one know how to help me out? Quote Link to comment Share on other sites More sharing options...
trq Posted August 15, 2007 Share Posted August 15, 2007 As I said, take a look at the ssh extension. Quote Link to comment Share on other sites More sharing options...
funguse Posted August 23, 2007 Author Share Posted August 23, 2007 ok here is an update. to test if i can connect to my server via ssh2 im just running this little script but every time i open the file.php my cpu usage goes to 50% (taskmanager says httpd.exe) even when i close the window, when i run it again it goes to 100%. what am i doing wrong? ip of server, username and password are all correct <?php echo "line 1"; $connection = ssh2_connect('ip', 23); echo "line 2"; ssh2_auth_password($connection, 'user', 'pass'); echo "line 3"; $stream = ssh2_exec($connection, 'cd /data/msoft'); echo "line 4"; echo $stream; ?> the error message im getting is: Warning: ssh2_connect() [function.ssh2-connect]: Unable to connect to 172.19.1.38 on port 22 in C:\www\webroot\test\test.php on line 2 Warning: ssh2_connect() [function.ssh2-connect]: Unable to connect to 172.19.1.38 in C:\www\webroot\test\test.php on line 2 Fatal error: Maximum execution time of 30 seconds exceeded in C:\www\webroot\test\test.php on line 2 Quote Link to comment Share on other sites More sharing options...
thryb Posted August 23, 2007 Share Posted August 23, 2007 Silly question but are you sure your sshd is running ? Did you try connecting with a real ssh client ? Quote Link to comment Share on other sites More sharing options...
funguse Posted August 23, 2007 Author Share Posted August 23, 2007 ah ok.. i just used putty.exe using ssh and it said connection refused, however i can log on using the telnet. so i take it i have to rule out the ssh side and use telnet instead? i found something at www.geckotribe.com/php-telnet/ if any one has any experience with that? looks like what i want. gonan give it a go thanks Quote Link to comment Share on other sites More sharing options...
Malcerous Posted August 23, 2007 Share Posted August 23, 2007 What I would do and am somewhat doing right now with perl is. 1.) Write a PERL script or BASH script that will run TOPAS and pipe resuts to a file. The problem with TOPAS is kind of messy because every time it refreshes it will write a new section.(It will be very hard to parse) - I would find out what you want to identify and display: uptime, processes, diskspace, etc etc - Write a bash script that pipes the results to a file every minute and ftp/sftp the file to you webserver. Schedule using a cron job. - Write a php webpage that will parse the files from the server. - Everytime they refresh the page after 1 minute the status will be updated. This would be minimal on resources for all servers and pretty easy to do. You can even add javascript to the page to refresh every minute. I hope that this helps. Quote Link to comment Share on other sites More sharing options...
funguse Posted August 24, 2007 Author Share Posted August 24, 2007 yes thanks i'll have a look. never used perl or bash so its new waters for me but never said no to a challange Quote Link to comment Share on other sites More sharing options...
funguse Posted August 24, 2007 Author Share Posted August 24, 2007 ok i think i've managed to get at least something with telnet (see code and images) i want to get the value next to idle but dont quite know how i can do that. and also the value does not display on the output (image 2). any one know y that is? image 1 image 2 <?php $username='root'; $password='sibi123'; $header1=( chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01). chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50). chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34). chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45). chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0) ); $header2=( chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21) ); $fp=pfsockopen("172.19.1.38",23); fputs($fp,$header1); sleep(1); fputs($fp,$header2); sleep(1); fputs($fp,"$username\r"); sleep(1); fputs($fp,"$password\r"); sleep(1); fputs($fp,"\r"); sleep(3); fputs($fp,"\r"); sleep(3); fputs($fp,"q \r"); sleep(3); fputs($fp,"topas \r"); sleep(1); $output=fread($fp,128); $stat=socket_get_status($fp); $output.=fread($fp, $stat["unread_bytes"]); $output = explode("\n", $output); unset($output['0']); $output = implode("\n", $output); $output = str_replace("\n", "<br>", $output); echo $output; fclose($fp); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.