Welcome! Log In Create A New Profile

Advanced

Control a dockstar from a web browser

Posted by bilbo 
Control a dockstar from a web browser
December 20, 2010 10:20AM
Hi All,
After a little bit of time writing some PHP, I managed to get a rough script working that lets you run shell commands on a dockstar from any web browser. It only requires that you install Lighttpd and php-cgi (together they use less than 10mb of RAM when running).

I use it for running simple commands (backups and such) from another computer on my network without having to login through SSH. However, the same code could be adapted to control a specific application on the dockstar from a webpage, without having to actually type commmands.
If anyone is interested, I can post the code. Is it possible to attach files in this forum?

Thanks!
Re: Control a dockstar from a web browser
December 20, 2010 10:57AM
Interesting. Can you posted it so others can try? If the code is not too long, you can simply insert it in line and formatted it as "formatted code". Or you can attach the file but I have never use this feature before.
Re: Control a dockstar from a web browser
December 20, 2010 03:40PM
I have included a zip of my /var/www directory, and listed the three files needed for this setup to work. (You will also need a standard Lighttpd install, and to setup php-cgi as described here: http://www.cyberciti.biz/tips/lighttpd-php-fastcgi-configuration.html).
File 1: /var/www/remoteshell.html:

<html>

	<head>		

		<script type="text/javascript" src="scripts/prototype.js"></script>

		<script>



			function sendRequest() {

			$('show').innerHTML+= "root@debian# " + $F('name') + "<br />";

				new Ajax.Request("test.php", 

					{ 

					method: 'post', 

					postBody: 'name='+ $F('name'),

					onComplete: showResponse 

					});

			document.test.name.value= "";		

				}



			function showResponse(req){

				$('show').innerHTML+= req.responseText + "<br />";

			}

		</script>

	</head>



	<body><h1>Remote Terminal Client</h1>

	<font color="white">

	<pre><div id="show" style="background-color:black;width:75%;"></div></pre></font>

		<form name="test" id="test" onsubmit="return false;">

			<input type="text" name="name" id="name" >

			<input type="submit" value="Run" onClick="sendRequest()">

		</form>

		

		

	</body>



</html>
File 2: /var/www/test.php:
<?php

	echo shell_exec($_POST["name"]);

?>
File 3: /var/www/scripts/prototype.js:
Download latest version of the prototype framework from http://prototypejs.org/download and place it in the scripts subdirectory.

I hope you find this useful!
Attachments:
open | download - varwww.zip (37.8 KB)
Re: Control a dockstar from a web browser
December 20, 2010 05:50PM
Could you make it a little easier for me.
I got the:
apt-get install lighttpd

And I downloaded your files and put them in the right folder.

But the other stuff I'm confused about.
Do we have to install php-cgi? and how? is there an apt-get install we should do for it, and could you spell it out for us.

If the other stuff was stuff you went to site and downloaded, is it in your download because I'm not sure ?

Thanks for showing us how to do this, and I'm trying to do it, but still a little confused.

In your download I see prototype.js , remoteshell.;html and test.php. In your cut and paste , we don't have to make those files or do anything with them right? Was that made before your "download" file for us?

update
When I go to dockstar webpage I do see the files.

I type on remote and I get 403 -Forbibben

On "remoteshell.html I get page that says Remote Terminal Client and next line blank with "run".
And click run and I get pop up with
root@debian
403- Forbidden



Edited 2 time(s). Last edit at 12/20/2010 05:59PM by rgtaa.
Re: Control a dockstar from a web browser
December 21, 2010 12:22PM
@rgtaa:
I think you need
apt-get install lighttpd php5-cgi php5-xcache
lighty-enable-mod fastcgi fastcgi-php
(I'm skipping the auth/ssl/webdav parts here I was actually doing but I think these are the essentials.)

HTH
Heinz



Edited 1 time(s). Last edit at 12/21/2010 12:30PM by hkramski.
Re: Control a dockstar from a web browser
December 21, 2010 01:19PM
Thanks for the apt-get stuff

The first line of stuff I apt-get install

And the second line stuff I just put as is and it gives:
# lighty-enable-mod fastcgi fastcgi-php
Available modules: auth accesslog cgi fastcgi no-www proxy rrdtool simple-vhost ssi ssl status userdir fastcgi-php debian-doc
Already enabled modules: cgi
Enabling fastcgi: ok
Enabling fastcgi-php: ok
Run /etc/init.d/lighttpd force-reload to enable changes

Then I just put in
/etc/init.d/lighttpd force-reload

And it restarts the program and it works.

At at this point I only see programs /files in that one directory.
root@debian# cd /root

root@debian# dir
index.lighttpd.html  remoteshell.html  scripts	test.php

root@debian# cd ..

root@debian# dir
index.lighttpd.html  remoteshell.html  scripts	test.php

root@debian# cd /root/

root@debian# dir
index.lighttpd.html  remoteshell.html  scripts	test.php



Edited 3 time(s). Last edit at 12/21/2010 01:31PM by rgtaa.
Re: Control a dockstar from a web browser
December 21, 2010 06:15PM
Yes. I resolved that problem by running lighttpd as root. The issue with this, however, is that if anyone else has access to your dockstar over the network, (LAN or WAN), they have complete root access to your dockstar. If, however, your network is protected and you are sure that your dockstar is not accessible outside your LAN, then this is a fine solution.
d1dd1
Re: Control a dockstar from a web browser
December 23, 2010 05:13AM
You could also install webmin.

There is a web console and / or remote shell

Install:

http://www.webmin.com/deb.html

Module:
http://doxfer.webmin.com/Webmin/CommandShell#The_Command_Shell_module
Re: Control a dockstar from a web browser
December 23, 2010 09:46AM
+1 on d1dd1's webmin recommendation... it's a very handy tool!!!

- Ray
Re: Control a dockstar from a web browser
December 23, 2010 10:45AM
While I also use and endorse webmin's capabilities, another option is readily available to execute commands on a remote host.

ssh user@hostname command

Set up ssh keys so there is no interactive authentication required, alias your command to something simple, control it from a desktop icon if you wish.

man ssh
man ssh-keygen
alias is a bash built in command. For example;

alias rebootdockstar='ssh root@192.168.0.128 shutdown -r now'

creates the alias, and then typing rebootdockstar [enter] executes it.

HTH, Jim
Re: Control a dockstar from a web browser
December 26, 2010 01:16PM
Quick attempt at a one liner ssh pubkey howto...

Run the following bash one-liner from the Linux box you want to ssh from. Replace "dockstar" with the hostname or IP address of your dockstar:
if [ ! -e ~/.ssh/id_dsa.pub ]; then ssh-keygen -t dsa -f ~/.ssh/id_dsa -N '' && ssh-add -D && ssh-add; fi; ssh -o "StrictHostKeyChecking no" root@dockstar "if [ ! -e ~/.ssh/id_dsa ]; then ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ''; fi; cat - >> ~/.ssh/authorized_keys" < ~/.ssh/id_dsa.pub
After that you should be able to run commands without passwords as Jim suggested:
ssh root@dockstar df -hT

-PG
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: