custom cgi script broken since v24-RC3 ?

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
eweri
DD-WRT User


Joined: 29 Dec 2007
Posts: 58

PostPosted: Sat Dec 29, 2007 1:54    Post subject: custom cgi script broken since v24-RC3 ? Reply with quote
Hello!

I want to watch my system.log with the web-browser so I put a file called log.sh into /tmp/www/user/ and point my browser at http://my.routers.ip/user/log.sh - with V23 and v24-RC2 I got my system.log in my browser. I do not know exactly since which v24-build this stopped working, but at least since v24-RC4 it does not work any more.

If I tried to open the page in my browser it tells me something about "the server disconnected unexpectedly ..."
If i login via ssh and run the script by hand it works. For example:
cd /tmp/www/user
./log.sh > test.html
Now point my browser to http://my.routers.ip/user/test.html and it works (obviously now it is static content, but the output of log.sh must be right or test.html should not be displayed either)

Did the handling of custom cgi scripts changed or should i file a bug?

Bye,
eweri
Sponsor
dcraw101
DD-WRT Novice


Joined: 18 Jan 2008
Posts: 4

PostPosted: Fri Jan 18, 2008 17:02    Post subject: Reply with quote
Were you ever able to resolve this. I too would like to add some custom cgi scripts? Do you think it is a mime type issue? Do the scripts need to be in a cgi-bin folder?
eweri
DD-WRT User


Joined: 29 Dec 2007
Posts: 58

PostPosted: Sun Jun 01, 2008 23:01    Post subject: Reply with quote
dcraw101 wrote:
Were you ever able to resolve this. I too would like to add some custom cgi scripts? Do you think it is a mime type issue? Do the scripts need to be in a cgi-bin folder?


Right! I just found out that the scripts work without problems when they are put into /tmp/www/cgi-bin (or /jffs/www/cgi-bin) Found it at the wiki in a sidenote :-(

Is this change documented anywhere?

Bye,
eweri
eweri
DD-WRT User


Joined: 29 Dec 2007
Posts: 58

PostPosted: Sat Aug 23, 2008 19:38    Post subject: Reply with quote
eweri wrote:

Right! I just found out that the scripts work without problems when they are put into /tmp/www/cgi-bin (or /jffs/www/cgi-bin) Found it at the wiki in a sidenote :-(

Is this change documented anywhere?

Bye,
eweri


Well, maybe I am stupid but since the update to V24sp1 the above does not work anymore Crying or Very sad
eweri
DD-WRT User


Joined: 29 Dec 2007
Posts: 58

PostPosted: Sat Aug 23, 2008 20:06    Post subject: Reply with quote
eweri wrote:

Well, maybe I am stupid but since the update to V24sp1 the above does not work anymore Crying or Very sad


Oh no - i am stupid - now it works - I do not know what I have done wrong before but I just set things up again with the scripts in /tmp/www/cgi-bin/ and everything works fine again. Very Happy

I am sorry for the noise i made Embarassed

Bye,
eweri
redsky
DD-WRT User


Joined: 31 Mar 2008
Posts: 59

PostPosted: Thu Oct 23, 2008 14:36    Post subject: Reply with quote
what exactly did you do? what's the firmware? does it need to be in cgi-bin folder? Can it have other extension, than .cgi? I can't make my script run!
CaScAdE
DD-WRT Guru


Joined: 18 Jun 2006
Posts: 1110
Location: Kiel (54.4247,10.1721)

PostPosted: Thu Oct 23, 2008 15:49    Post subject: Reply with quote
Shellscripts with .sh will work in folder /tmp/www/cgi-bin as well...

example would be:
Code:
#!/bin/sh
echo '<HTML><HEAD><TITLE>Custom Script Test</TITLE></HEAD>'
echo '<BODY>'
nvram get router_name
echo ' sample custom script:<br>'

NOW=`date +%s`

echo "Unix-Time here on this device is ${NOW}. Nothing usefull...<br>"
echo "Just a test..."


save this as
/tmp/www/cgi-bin/custom.sh
and make it executable:
chmod +x /tmp/www/cgi-bin/custom.sh
and point your browser to it:
http://ROUTER.IP.HERE/user/cgi-bin/custom.sh

and you should see the generated output...

This is tested with
DD-WRT v24-sp2 (10/22/08) mega - build 10564M NEWD Eko

_________________
DD-WRT F.A.Q.

Webcam Kiel
redsky
DD-WRT User


Joined: 31 Mar 2008
Posts: 59

PostPosted: Thu Oct 23, 2008 15:58    Post subject: Reply with quote
thank you for your reply. I don't know what happened exactly, may be the syntax of my test.cgi file was incorrect. but now it works. two questions:
1. can I pass parameters in URL like: /cgi-bin/test.cgi?param=1
I tried running the same script with parameters set and I got an error.
2. can I execute the script outside /cgi-bin/ folder?
3. can I rename my sh. script into .php file? How do I add the new content-type for it? I don't need a php interpreter.
well, still, if I can't pass parameters to script - the later two questions are irrelevant.
CaScAdE
DD-WRT Guru


Joined: 18 Jun 2006
Posts: 1110
Location: Kiel (54.4247,10.1721)

PostPosted: Thu Oct 23, 2008 16:17    Post subject: Reply with quote
redsky wrote:
1. can I pass parameters in URL like: /cgi-bin/test.cgi?param=1


i am afraid no get is working. i looked in the source to see how fetchif does this, but fetchif is hardcoded in the http-daemon...
did not try post-request on custom script though...
look at httpd/modules/broadcom.c and check out do_apply_cgi...

redsky wrote:
2. can I execute the script outside /cgi-bin/ folder?


If you call them inside a script that is in the /cgi-bin/ folder you can.

redsky wrote:
3. can I rename my sh. script into .php file? How do I add the new content-type for it? I don't need a php interpreter.
well, still, if I can't pass parameters to script - the later two questions are irrelevant.


wouldn't php be a little too overbloated? what do you want to do?

_________________
DD-WRT F.A.Q.

Webcam Kiel
redsky
DD-WRT User


Joined: 31 Mar 2008
Posts: 59

PostPosted: Thu Oct 23, 2008 16:27    Post subject: Reply with quote
okay. I have got a phone with CID function which makes a hardcoded request to http://klicktel.det/gigasetpb/1.0/search.php and passes the CID number in the URL string.
Using /etc/hosts I can point the phone to my router instead of klicktel.de.
Now I want to put a sh script in the corresponding folder, called srcipt.php, which should parse the URL and re-request it to my own server in the internet, get a response from it and resend it back to the phone.
http://www.dd-wrt.com/phpBB2/viewtopic.php?p=220552#220552
these are the results of my experiments. That was me who just tried post request and it worked fine. Thank you for the hint and the link to the source code.
As far as I got I won't achieve the result with this firmware.
CaScAdE
DD-WRT Guru


Joined: 18 Jun 2006
Posts: 1110
Location: Kiel (54.4247,10.1721)

PostPosted: Thu Oct 23, 2008 17:36    Post subject: Reply with quote
if it is "your server", do you have access to the httpd-config? (apache would be cool)

so you could modify /etc/hosts to resolv the domain to the ip of your server, setup a virtual host that will listen to that domain name and does the stuff for you...

That's how i would handle it :)

2nd way would be to set the normal webif to a port !=80 and install a small other httpd that can handle get-queries...
add a index-page that sends header location to the new ip and you can still type in the ip of your router to manage but the get-requests would get handled...


or start a feature request... query strings in custom script could be handy for some more people Smile
can't be that much to do...

_________________
DD-WRT F.A.Q.

Webcam Kiel
redsky
DD-WRT User


Joined: 31 Mar 2008
Posts: 59

PostPosted: Thu Oct 23, 2008 19:07    Post subject: Reply with quote
If it were really mine - there would be no problem at all. It's a virtual hosting provider that runs the server, so I can't set it up as a default site.
As for the second option - I am not sure that my router has enough space for installing other httpd. May be you could give me a hint where to look for some sort of tutorials?
How do I start a feature request? Besides, it may affect the router's security, so probably the developers won't do anything like that.
eweri
DD-WRT User


Joined: 29 Dec 2007
Posts: 58

PostPosted: Mon Jul 27, 2009 21:24    Post subject: Reply with quote
And once again I am running DD-WRT v24-sp2 (07/22/09) mega - build 12548M NEWD Eko
and I can not use my log.sh any more :-(

If I try it within a shell the scripts work, but not in the browser. Static-pages at the same location work.

Any idea what is happening here?

Bye,
eweri
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Jul 27, 2009 22:00    Post subject: Reply with quote
I haven't read these posts in detail but I'm sure my reverse-proxy solution can be of help here....
The reverse proxy can optionally rewrite the http headers.

I have asterisk running and if I access http://192.168.10.1/user/cgi-bin/asterisk I get a webpage where I can config and view my asterisk.

The shell-script is /opt/etc/asterisk.sh and using a symbolic link in: /tmp/www/cgi-bin makes it work

Code:
mkdir -p /tmp/www/cgi-bin
ln -s /opt/etc/asterisk.sh /tmp/www/cgi-bin/asterisk

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
phuzi0n
DD-WRT Guru


Joined: 10 Oct 2006
Posts: 10141

PostPosted: Tue Jul 28, 2009 0:26    Post subject: Reply with quote
Does your script still work frater? I tried a quick test and it seems to have been broken by the security fix.
_________________
Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum