Laravel send SSH command - php

I'm working on a Laravel app and would need to send a SSH command to a remote server from my webapp. I know envoy can be used to this but this is not a good solution for me as envoy allows only to send a predefined command to a predefined list of servers.
In my case, I need to send a SSH command to a remote server when clicking on a button in my webapp to the IP address of a remote server that can be found on a label in the webapp.
Any suggestions?

I think it is always a good idea to stick to the language standard library if it provides the functionality you need. Please have a look at: http://php.net/manual/en/function.ssh2-exec.php

Related

How to run php websoket server file(server.php) on google cloud server oR AWS

I have setup my php websocket application on google cloud and i have test it using cloud shell and putty terminal after running my server.php file but i want to run this file permanently so I am unable to do this.So please help me about it.
We can talk about two options:
The App Engine for standard or flex, but the websockets has limitations for php.
The second option is Compute Engine, we have to prepare the environment (apache), and assign the Public IP.
Please check the next links:
https://cloud.google.com/community/tutorials/setting-up-lamp
http://socketo.me/docs/hello-world

Secure Linux Server Setup To Run Scripts via PHP exec()?

I'd like to run a script (phantomJS) via php exec() or shell_exec(). Everything is working fine on my development system.
I've installed phantomJS on my production server, and have run it successfully from the terminal after logging in via SSH.
But when I run it from PHP via exec() or shell_exec(), I get messages saying:
GLIBCXX_3.xx not found
GLIBC_2.xx not found
The support team at the web hosting provider is saying they don't know how to enable the server to access the script and still maintain security:
We're not familiar with the specifics of it, so we'll either have to
go through with disabling the chroot, but as our supervisor mentioned
this will allow all accounts on the server to account with each other
which is what the chroot prevents.
You can have your own system administrators look at the setup as you
do have root access, and see if they can devise a workaround, but on
our end this is the only thing we can suggest.
They are running CentOS, which is a 64-bit Linux OS.
I have very good experience with this web host up to this time, so I'm hoping there's a way to address this without changing hosts.
I have full root access to the account, so I can configure it in any way necessary.
Can anyone make some suggestions about how I might configure my production server to access phantomJS while maintaining a secure server?
UPDATE
Apparently my app is in a "chrooted environment" without full root access to GLIB on the server. The web host is saying there will be a lack of security if my php user is given full root access.
You have to remove your PhantomJS system call and create an API layer or a service that subscribes an MQ queue and then integrate it with PHP to avoid several problems, including the chroot limitation.

PHP project: Telnet connection to Nokia Equipements(MSS) with PHP and data interaction with database throught telnet

As part of my graduation project, I have to make a web application that connects to a Nokia proprietary equipment.
This is the architecture of my project.
Is it possible to do this project with to language PHP: Can I connect to the equipment with php throught telnet
and for the hand "1" Can the database through php interact with the equipment with telnet
Just to know I had never developed any thing in php, even with developing web applications.
Thank you in advance
There is a PHP telnet library available you can use that.Refer the link below http://www.geckotribe.com/php-telnet/
The short answer is no, You cannot have a Web application in PHP connection to telnet. The reason being the server that runs in front (Apache/nginx) calls the PHP script every time there is a request and has a default timeout period. So the telnet connection would be blocking for your webpage.
Now from what i understand is that you are trying to build a PHP application and you want some telnet connection to render/store in database. The correct way from my point of view to do this would be to make two applications, One is your PHP website and the other can be a wrapper around telnet server. The telnet application would run as a service unlike Php app because u need to maintain the connection. As far as the fetching the telnet data into php app/ dbs there could be many method. I am listing some of them for you.
Process pipes in php to interact with telnet app
Make a wrapper web service around telnet and use curl in php to fetch info
[Recommended if you want it in dbs] Directly add content from the telnet app into the database.
The above answer is if you only want to use PHP to make the app. If thats not the case have a look at GNU microhttpd server, That can be used to do what you are trying with much more control

Possible to connect to Remote Desktop with PHP?

I've got a few servers that I'd like to connect to every so often to run a program. However, to make it easier, I'd like to make a PHP script connect to each of them via remote desktop and run each of them. Is this possible? If so, where should I start? An example would be lovely.
In theory you could implement a PHP script that could communicate with a server in the RDP protocol, but I certainly wouldn't want to try to build a script that can do anything meaningful, as RDP is built to expose a remote machine's user interface to the connected client and PHP is built first and foremost to manipulate text.
If you want a PHP script to remotely control another computer, then SSH is a far more sensible option, as PHP could easily connect to the remote cmputer's CLI and issue commands to the server via shell commands, which are textual and therefore easily generated with PHP.
On the other hand, interfacing with the remote computer with RDP would be extremely difficult. Just think about clicking on an icon to get a directory listing for a start. You'd first have to determine where the mouse pointer is, whether the icon you want to click is visible and if so where its bounding box is relative to the mouse pointer. You'd then have to issue commands to move the mouse pointer to within the bounding box, then check that the mouse pointer is in the right place (a local or other remote user might be moving the mouse around) and then issue a pair of clicks with a short delay between them.
That's going to be a lot harder than issuing "cd C:\Program Files\" followed by "dir", for example.
No PHP cannot use RDP to connect to the server. They can use SSH or FTP or a socket to a listening port.
What you are asking is kinda crazy!!! =)
Edit:
Since you insist on doing it here is what you need:
[MS-RDPBCGR]: Remote Desktop Protocol: Basic Connectivity and Graphics Remoting Specification
[MS-RDPCR2]: Remote Desktop Protocol: Composited Remoting V2 Specification
[MS-RDPEA]: Remote Desktop Protocol: Audio Output Virtual Channel Extension
[MS-RDPEAI]: Remote Desktop Protocol: Audio Input Redirection Virtual Channel Extension
[MS-RDPECLIP]: Remote Desktop Protocol: Clipboard Virtual Channel Extension
[MS-RDPEDC]: Remote Desktop Protocol: Desktop Composition Virtual Channel Extension
[MS-RDPEDYC]: Remote Desktop Protocol: Dynamic Channel Virtual Channel Extension
[MS-RDPEFS]: Remote Desktop Protocol: File System Virtual Channel Extension
[MS-RDPEGDI]: Remote Desktop Protocol: Graphics Device Interface (GDI) Acceleration Extensions
[MS-RDPELE]: Remote Desktop Protocol: Licensing Extension
[MS-RDPEMC]: Remote Desktop Protocol: Multiparty Virtual Channel Extension
[MS-RDPEPC]: Remote Desktop Protocol: Print Virtual Channel Extension
[MS-RDPEPNP]: Remote Desktop Protocol: Plug and Play Devices Virtual Channel Extension
[MS-RDPEPS]: Remote Desktop Protocol: Session Selection Extension
[MS-RDPERP]: Remote Desktop Protocol: Remote Programs Virtual Channel Extension
[MS-RDPESC]: Remote Desktop Protocol: Smart Card Virtual Channel Extension
[MS-RDPESP]: Remote Desktop Protocol: Serial and Parallel Port Virtual Channel Extension
[MS-RDPEUSB]: Remote Desktop Protocol: USB Devices Virtual Channel Extension
[MS-RDPEV]: Remote Desktop Protocol: Video Redirection Virtual Channel Extension
[MS-RDPEXPS]: Remote Desktop Protocol: XML Paper Specification (XPS) Print Virtual Channel Extension
[MS-RDPNSC]: Remote Desktop Protocol: NSCodec Extension
[MS-RDPRFX]: Remote Desktop Protocol: RemoteFX Codec Extension
You can find all those here: http://msdn.microsoft.com/en-us/library/cc216513(v=PROT.10).aspx
With this documentation you can determine the feasibilty of your project.
I am using
rdesktop -u username -p password 192.168.1.131 -g 1024x640
in linux,
where 192.168.1.131 is the destination ip
and 1024x640 is the window size.
Also you can use
rdesktop -u username -p password 192.168.1.131 -f
for full screen.
Don't forget to replace the username and password with your details.
I think it be best if the servers were running a service that you could connect to. For example they could be running a web service (e.g. php if that's your desired language). You could then connect to that web address through port 80 which could run the applications. Of course you have security concerns, but you should be able to configure them so that they only accept requests from certain IPs. Alternatively you could make the script password-protected
The reason ppl are not recommending RDP to do this is because RDP has no API to do even remotely what you actually want.
The easiest way to do this while somehow staying within your requirements, is to install one of the software linked below on the host machines. Then you would need an API to connect:
This: http://www.codeproject.com/KB/system/remoteexec.aspx. In PHP all you would need is something as simple as exec("rexec 123.21.61.12 notepad.exe "\fileserver1\test file.txt") (you can modify it to accept a key for a bit of security)
TeamViewer (free): http://www.teamviewer.com/en/products/remotecontrol.aspx Then you would use TeamViewer WebConnect to connect to via PHP
OpenVPN (open source) Not sure if there is an API that comes with it but I wouldn't be surprised
Log me in (same as above)
Install WAMP on the hosts and then have php run the commands on them. So it would be something like php to php where ur client would call something like curl(127.0.0.1/?key=loooong&command=blah) and the server would run exec("passed command")
vmware Esxi uses such a ui page but not with PERL application, After reading the answers it seems a real challenge. I'm working on such a thing for my web based hosts access. If I get something done, I'll be happy to share with you.
https://labs.vmware.com/flings/esxi-embedded-host-client
Honestly, you're best bet would be C#. This probably isn't what you want to hear, but it's extremely trivial to make an rdp client in that language.
If you're allowed to create a user that has access to the logs. I'd make something that would run when the user is connected. The program would upload the logs to a unix server that has FTP access.
Then even if you can't write a one click solution in C# you could at least just login manually wait for the upload to be done then log out.
Why not running a perl script from a cronjob or execute the programs with the backquotes?
If all you want to do is to connect to your many servers and run the same program, you could do a one-time upload of a php execute script to all your servers that should exec() a command from input data (most likely from $_POST or $_GET). You then write a local script, which will send the command string to run your program to all the exec scripts on all your servers, so essentially typing the command to run whatever program you need will execute the command on every server.
Obviously you'll need to require authentication for your exec script so nobody can abuse your servers. Of cause, this whole thing wouldn't be suitable if the program you're running requires much interaction (you did say you wanted to run a program, which implies you want to execute it and leave it to do it's own thing)
Why not use FTP for what you need?
then generate and execute files with simple commands microsoft.
I think it would be better to set up daemon/service on server to which you want connect and communicate with it via TCP. In this case, you are free to implement any protocol you want.

Execute local application via PHP from server

My company has an internal Linux server running PHP with an application that displays client specific information, such as SSH connection info, etc. Is there a way to have the server invoke a command on a local machine via PHP? For example, the server displays a link with SSH connection information, such as c:\putty.exe -ssh someone#192.168.1.100 -pw MyPassword`. The user - on a windows machine - clicks the link and Putty fires up with all the connection information.
I believe Flash's fscommand has the capabilities I'm looking for, although I would much prefer to use PHP, if at all possible.
PHP is a server side technology and as such does not have any control over the client. You'll have to use a client side tech like flash or if it's IE only, ActiveX
Only way to things like this is mount your resource on server machine. To do that you have to have a server that will be visible for server and able to host your files.

Categories