Get info from my router VIA SSH CLI from a php page - php

All,
I'm fairly new to php (simple forms and hello world stuff)
I'm trying to create a page that when loaded will go out grab some text information from a SSH session on my router parse it out and display it
The general idea would be
connect to (ip address, port)
send line (loginuser + Password)
send line (su to root + password)
send line (command)
receive text from command (string X)
parse x and display stats as html on page
I've seen a few tutorials on how to install libraries from ubuntu but my host is godaddy so i wont have access to install anything in that manner (i only have simple ftp access)
I'm looking for a simple simple simple ssh client and hopefully a small example on how to use it (send commands and retrieve text)
Thanks if you can help

Ok, just for learning purposes, you can shell_exec on your box to connect to remote host with ssh, run a command and return response, evaluate and make some nice stats:
shell_exec("ssh user#yourhost.com run_your_command");
http://www.php.net/manual/en/function.shell-exec.php
I would use phpseclib (http://phpseclib.sourceforge.net/), a pure PHP SSH implementation, or if is available on your host use SSH2 extension. http://www.php.net/manual/en/function.ssh2-exec.php

PHP is not the right tool in my opinion, you can achieve better results with expect and some bash stuff.
expect is a good tool for command line activities. Try to have a look

Related

How to get network traffic info and display it in PHP

i have server ubuntu . I want to show network traffic upload & download in php .
A command is in the terminal for monitoring traffic: enter link description here
How can I use command nload -mon php.
Like this :
i have no idia about it
The simplest solution is:
to call this function in PHP file via exec().
to parse the output from this function and prepare the markup to present those values (total input/output) on the page.
Better solutions depend on how often this info should be retrieved and how pretty it should be rendered in the browser.
It compiles php to apache and apache simply does not access network uses. There are several ways for this;
1-) shell_exec;
In ubuntu you can prepare a console command that will output the network data as json, then you can run this console command in ubuntu using shell_exec in php.
2-) third part programming;
For example, you can develop scripts on platforms such as python, node js, etc. and access network usage. Again, with the software you have developed, you can instantly print the network usages to the database. In another option, you can access network information with software such as phton and show them on socket, and you can get data from php with socket. Finally, you can develop an api for this on pyhton.

Windows Prompt read and send text by COM port

I need a program to send and receive some text by a COM port. I would like to launch this by a exec command (command line).
I tried to view if Hyperterminal or putty can be used by command line but i can not find a solution.
This would be a workaround to send and receive text by a PHP webserver, I'm going to use the php exec function to run it.
I published two tiny command line applications called SerialSend and ComPrinter on my blog, which send and receive text via serial port. I'm not sure if they'll do exactly what you need since one only sends and the other only receives, but maybe you can get them to do what you want. They're completely free, you can download binary or sourcecode (they're really easy to compile), and they're both really easy to use.
Here are the links:
SerialSend web page
ComPrinter web page

Use a PHP to send out a command to a perl script on multiple servers using PHP, MySQL, Perl, and SSH

Well. I have a large basis on which to go. I just dont know how to go about it. using the exec() function. But I think I'd really just need help doing a remote SSH. The rest I already sorta understand
I have a perl script on 5 servers that need to be updated, and the best way to automate this is from the admin panel on a remote server.
The php file needs to collect the servers ips, username, passwords + the .pl's directory from a MySQL while also sending the post data that was just sent, and then send that data via SSH (from each variable) with the command to execute the remote perl script with the post data (from the php file) as an argument.
Basically: PHP(+post data) -> SQL(gets table info) -> perl -> (SSH -> perl)[repeat until no more servers are left to update]
The faster and simpler it does this, the better. If any steps can be removed to speed it up, then great, unless it makes it less secure.
I really do not get how to do much of this, as I'm still trying to learn Perl and SQL
You can setup ssh password-less authentication between your servers, have your scripts setup and tested in the same path on different servers, and in your PHP script write
for($hostname in $hosts)
system("ssh $hostname -c 'perl /path/to/my/script.pl'")
Or you could setup public/private key identity files and do:
for($hostname in $hosts)
system("ssh $hostname -i ~/.ssh/identity_file -c 'perl /path/to/my/script.pl'")

How can I use svn+ssh in a PHP script?

i can't figure out how i should access the repository from a CakePHP project called fredistrano (you can do CakePHP deploys with a web 2.0 interface). i have fredistrano in my web broadcasting directory on a shared unix web server. when i use tortoisesvn from my laptop, i have to use svn+ssh://username#domain.com/svnpath/trunk/. i tried using the same thing in fredistrano, but i keep getting the svn command error "svn: Network connection closed unexpectedly". i copied and pasted the command: svn export --non-interactive --username myusername --password mypwd svn+ssh://myusername#mydomain.com/home/myusername/svn/mydomain.com/trunk tmpDir 2>&1 into my SSH terminal connected to the shared server and i get a prompt for a password, which i believe is actual a prompt for the SSH password and not the SVN password (see this post). fredistrano is failing because it can't deal w/ the SSH password prompt. i noticed in the fredistrano documentation that the example uses http://ipaddress/svn/test for the SVN URL. i copied my svn to my web broadcasting direrctory and tried this but get a connection refused error. my shared hosting provider is pretty strict and i doubt that i can use that. is there a way i can get svn+ssh to work w/ a PHP script like this (fredistrano is just using shell_exec() to execute svn commands)? is there a way i can get just get svn, http, or https working (or any other method that i don't know about)?
I am interested in this problem, too, and I hope that I'm close to the solution.
I haven't tried to put it into work in my application due to the lack of time and other high-priority tasks, but I guess that it should look something like this:
shell_exec(svn something svn+ssh://...)
$response = trim(fgets(STDIN))
[then check if the response contains password prompt text]
fwrite(STDOUT, 'yourpassword');
[analyze the next response and see if SVN has returned the requested information - log, info, whatever]
"svn: Network connection closed unexpectedly" most probably means that your host has restricted/forbidden access to other hosts. This might imply using sockets at all (SVN, HTTP, etc.) or maybe only non-HTTP. In this case you should try setting up your SVN server to allow HTTP requests (e.g. using mod_dav_svn for Apache).
This is only a guess - see my comment to your question.
How do you authenticate from your dev machine to the svn-server? You might be using a key to authenticate (Do you have putty pageant running?)
maybe check out the Subversion PHP Module (1.0.3) instead of wrapping shell_exec; it requires building from source, with phpize, ./configure and make (just built it against PHP 5.6 and Subversion 1.9.5)... while the Apache Module mod_dav (Subversion via HTTP/HTTPS) is not required for version control, rather an optional method of accessing the repository.

Executing PHP script based on Outlook rule

I am getting daily data dump via e-mail, which is being processed by Access (based on the Outlook rule, VBA is extracting the attachment and running Access procedures, so I get a report).
As data dump is getting bigger and bigger, and having in mind that Access is run locally which consumes my resources, I want to set up a PHP/MySQL server to make it more efficient.
The first challenge I face is how to connect Outlook rule with PHP execution? (as I will have Outlook set up on the Windows based machine, with apache/mysql set up (WAMP))
Anyone can share some insights on how to start PHP execution from Outlook?
Thanks for the help!
Srdjan
If you have an existing setup using Access and VBA, and you just need a better database behind it, could you not just use MySQL without PHP and use the MySQL ODBC driver instead of the Access connection you are using at the moment (assuming you are currently using ODBC to connect to the access database)
This way you wouldn't even have to have mysql running locally if the hit is too high on your local machine and it should be pretty straightforward in that you shouldn't have to make to many changes to your vba code.
Of course, whether this will do it depends on what else is going on in your access db
If not you could try using php and using the PHP Command Line Interface (CLI) which you should be able to call as an external executable from Outlook. Just pass php.exe the name of the php script you want to run
UPDATE:
I am not a VBA expert by any means but it looks like the shell function would let you run the PHP CLI from within VBA
Shell("path/to/php.exe phpscript.php")
http://msdn.microsoft.com/en-us/library/xe736fyk(VS.71).aspx
Of course this will only work if you can get to php.exe on the wamp machine (ie is a local machine or you have network access to the appropriate folder)
Alternatively, if the Wamp server is to be a separate machine then you could trigger the php script to be run by calling a url. I think the XMLHTTP object will do this for you
Dim xmh As Object
Set xmh = CreateObject("MSXML2.XMLHTTP")
xmh.Open "GET", "http://urlofphpserver/script.php", False
xmh.Send

Categories