Archived

This topic is now archived and is closed to further replies.

W4RP3D

dd-wrt - executing cgi scripts from web browser

6 posts in this topic

Hi guys, It been a very long time since i last posted but i was inspired by the jasager project to see what else the fon can do.

My idea is to control an ardiuno from a fon using my iphone. So far i have to fon running dd-wrt briged with my router so that once i connect to the network i can also access the fon. And by echoing to the serial port (echo "data" > /dev/tts/0) i can send data to the adriuno. A little diagram makes more sense:

planbcf.jpg

I then created little cgi scripts to send the data e.g:

#!/bin/sh
echo "data" > /dev/tts/0

By following this guide http://www.dd-wrt.com/wiki/index.php/WEB_server I managed to be able to access html files from the iphone browser. Great i thought now i can link to the scripts which ran fine when i telnet in. Unfortuantly they dont execute from the webserver

The script is saved to /jffs/cgi-bin, and the webserver points to /jffs (httpd -p 81 -h /jffs). And i believe it should be execeted when i browse to "router_ip:81/cgi-bin/script.cgi". Ive also tryed saving it to usr/temp/www/cgi-bin but that doesnt seem to work either.

I could really do with some help.

Thanks W4rp3d

Edit: Wrong url for picture

0

Share this post


Link to post
Share on other sites

Don't CGI scripts usually require a POST of some data to execute the script and not a GET of the url itself? Are you passing commands or data to the script with the GET request(instead of just navigating to the script)?

Might be of some use: http://httpd.apache.org/docs/2.0/howto/cgi.html

When saving the file, did you make it executable?

0

Share this post


Link to post
Share on other sites

According to the link you posted you can just navaigate to the URL:

If you open your favorite browser and tell it to get the address

http://www.example.com/cgi-bin/first.pl

or wherever you put your file, you will see the one line Hello, World. appear in your browser window. It's not very exciting, but once you get that working, you'll have a good chance of getting just about anything working.

I would like to pass data to it, but i thought it would be easyer just running seperate scripts for each command sent to the ardiuno. Yer I did make it an executable (chmod +x filename).

0

Share this post


Link to post
Share on other sites

You coudl try "chmod a+x" to give all users executable access, not just root. That way, anyone who opens the file, via browser or whatever should have rights to execute it. +X I think is just the user you are signed in with, but coming in from the browser side, you are in the "users" side I believe. Not 100% sure how that all works from an embedded device, but worth a shot.

Part of what I was saying is that it has to be able to take a POST as well I believe.

But it's still not working!

There are four basic things that you may see in your browser when you try to access your CGI program from the web:

The output of your CGI program

Great! That means everything worked fine. If the output is correct, but the browser is not processing it correctly, make sure you have the correct Content-Type set in your CGI program.

The source code of your CGI program or a "POST Method Not Allowed" message

That means that you have not properly configured Apache to process your CGI program. Reread the section on configuring Apache and try to find what you missed.

A message starting with "Forbidden"

That means that there is a permissions problem. Check the Apache error log and the section below on file permissions.

A message saying "Internal Server Error"

If you check the Apache error log, you will probably find that it says "Premature end of script headers", possibly along with an error message generated by your CGI program. In this case, you will want to check each of the below sections to see what might be preventing your CGI program from emitting the proper HTTP headers.

File permissions

Remember that the server does not run as you. That is, when the server starts up, it is running with the permissions of an unprivileged user - usually nobody, or www - and so it will need extra permissions to execute files that are owned by you. Usually, the way to give a file sufficient permissions to be executed by nobody is to give everyone execute permission on the file:

chmod a+x first.pl

Also, if your program reads from, or writes to, any other files, those files will need to have the correct permissions to permit this.

0

Share this post


Link to post
Share on other sites

How about using PHP's exec() function? (when everything else fails)

0

Share this post


Link to post
Share on other sites
How about using PHP's exec() function? (when everything else fails)

My orginal plan was to use PHP but ddwrt doesnt support it, the cgi scripts not executing seem to be a bug in the newest versons of the firmware. It seems there are a lot of them. Im gonna try openwrt instead, its a bit harder to configure it to be a bridge but nevermind. Thanks guys

0

Share this post


Link to post
Share on other sites