Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » All Things Unix » running a shell script via cgi web interface
Search Topic:
Uniqs:
818
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
FreeBSD traffic shaping - finding the right scheduler »
« I guess permissions are important.  
page: 1 · 2
AuthorAll Replies
-


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..

1 edit
reply to nwrickert
Re: running a shell script via cgi web interface

said by nwrickert See Profile :

The above however did not work...
You should be using
echo "$input" > /tmp/router.txt
The quoting prevents reparsing of "$input".

If you just want to write all of stdin to a file, then
cat - > /tmp/router.txt
should accomplish that.
Sure why not...when in doubt quotes won't hurt eh? :)

oh and btw a much better way of doing what I did above is this:

My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
·AT&T U-Verse
·AT&T Midwest

reply to Dennis
The above however did not work...
You should be using
echo "$input" > /tmp/router.txt
The quoting prevents reparsing of "$input".

If you just want to write all of stdin to a file, then
cat - > /tmp/router.txt
should accomplish that.
--
AT&T dsl; Westell 327w modem/router; openSuSE 11.0; firefox 3.0.10


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..
reply to Dennis
woo hoo....successs. I was able to import a text file as a variable in a test script (not at my work computer right now)


--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..
reply to Dennis
If only there was some way for me to read that text file back into a variable....


The above however did not work....:(

--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..

3 edits
reply to LarryWall
well I tried changing the variables, but got these errors

/usr/local/apache/dennis.sh: -n: is not an identifier
[Tue Jun 2 16:07:20 2009] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: /usr/local/apache/dennis.sh

tried to echo it out into a test file but no joy so the syntax must be off


update:
I did just get this to work....


--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


LarryWall

@no-ptr.set

reply to Sir Meowmix III
You also want to make sure you do input validation on user-supplied data. Something like:

die unless ($input =~ m/[a-z0-9/i);

The above is PERL that only allows alpha-numeric characters. Nothing like OS command injection to get your web server 0wned.

pablo2525

join:2003-06-23
·TekSavvy Solutions..

reply to Dennis
Howdy,

Ugh, my writing wasn't especially clear. I'm sorry. Let me try again.

In /etc/apache2/vhosts.d, my `conf' file has the above entry. In my case, I created a random file named `hostname`.conf baseed on `vhost.template'

My distribution is openSUSE but I figure the above is true in most (all?) apache installations. Of course the root pathing may be different.

I hope the above helps.

Cheers,
--
pablo
openSUSE 11.0;KDE
ISP: TekSavvy DSL; backhauled via a 6KM wireless link


Sir Meowmix III

reply to Dennis
s/and it's delimited with a QUERY_STRING/and it's not delimited with a QUERY_STRING/g


Sir Meowmix III



reply to Dennis
Dennis - Glad to help, please post a picture (kidding) ;)

I've not done CGI in a VERY long time, so you might want to do some testing to ensure that $HTTP_POST only contains the content of the POST itself and it's delimited with a QUERY_STRING style syntax. Ideally, your new code would be similar to below, assuming additional parsing of $HTTP_POST isn't necessary:



Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..
reply to Sir Meowmix III
said by Sir Meowmix III :

$HTTP_POST is arbitrary, it was a declared variable from the 'read' statement I posted earlier. If you're going to use $HTTP_POST be sure to use the 'read' statement as well.
Ok, you mean to make sure I use it in the shell script...right?

I should have mentioned that I know nothing earlier I'm trying to learn but really I'm trying to learn to run before walking....
--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


Sir Meowmix III

reply to Dennis
$HTTP_POST is arbitrary, it was a declared variable from the 'read' statement I posted earlier. If you're going to use $HTTP_POST be sure to use the 'read' statement as well.


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..

2 edits
reply to nwrickert
said by nwrickert See Profile :

Those touches in the beginning....never happen.
That's probably because "$1" is undefined.
....ok well so if that's the case then if the touches are indeed happening, there must be frament files in the /tmp directory...


so yeah, ok.....the variable must not be passing. So $1 is just a cli variable, and $HTTP_POST would be necessary in its stead.

I'll try that and see what happens.

--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
reply to Dennis
Those touches in the beginning....never happen.
That's probably because "$1" is undefined.
--
AT&T dsl; Westell 327w modem/router; openSuSE 11.0; firefox 3.0.10


Sir Meowmix III

reply to Dennis
Something like:


Where $HTTP_POST needs to be used instead of $1 in your code.


Sir Meowmix III



reply to Dennis
I think the issue is that the value you're passing via HTTP post is not inserted into $1, like it would be if it were called from the CLI.

You need to accept the HTTP POST in a different way.

quote:
For forms that use METHOD="POST", CGI specifications say that the data is passed to the script or program in the standard input stream (stdin), and the length (in bytes, i.e. characters) of the data is passed in an environment variable called CONTENT_LENGTH.
So you need to read from STDIN, assign it to a variable, and use it instead of $1. See »www.tcl.tk/man/aolserver3.0/cgi-ch4.htm


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..
reply to pablo2525
said by pablo2525 See Profile :

I made the following modification to my `vhosts.d' `conf' file:
I don't have a "vhosts.d" file...only a httpd.conf one which seems to have something similar

--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!


Dennis
Premium,Mod
join:2001-01-26
Algonquin, IL
·AT&T Yahoo

Host:
Chicago
Users Find Hot Deals
Users find Hot Dea..
Requests for Hot D..
Home Repair & Impr..

1 edit
reply to Sir Meowmix III
well, here is the jist of the code...at least the part I am having problems with. I have to remove some bits of it since it's for work and all...

here's teh cgi:

and here is the shell script called dennis.sh


Those touches in the beginning....never happen. I works just fine when I do it from the cli of course...but not via apache. I originally added them in order try and fix this problem but tit seems they don't. And of course the $1 is the variable I'm passing.

When I have it use a pre-existing file (which won't work for me, was only for testing) then this is the ownership I get.

--
My Blog. Because I desperately need the acknowledgement of others.

Visit the Judd Family website to see my kids!

pablo2525

join:2003-06-23
·TekSavvy Solutions..

reply to Dennis
I'm running `sh' scripts as CGI's without any issue.

I made the following modification to my `vhosts.d' `conf' file:

apache code:
        ...
AddHandler cgi-script sh
</Directory>

and my shell scripts have to end with `.sh' To get around having to parse input, I symlink to the actual script as follows: base name + _ + switch

The shell script itself tears $0 apart to find out the switch to use.

Cheers,

--
pablo
openSUSE 11.0;KDE
ISP: TekSavvy DSL; backhauled via a 6KM wireless link


Sir Meowmix III

@windstream.net

reply to Dennis
I believe that 'nobody' should be able to write to /tmp without issue, would you mind sharing the code here? I'm assuming it's written in Bash?

How are you handling, in the code, the HTTP POST/GET? How are you sure it's working correctly, are you able to echo it back and see it? Are you correctly reading the CGI input from stdin?


nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
·AT&T U-Verse
·AT&T Midwest

reply to Dennis
I am not aware of any problem with that. I'm pretty sure I am using some shell scripts for cgi, though I don't recall whether they write to files.

Do your web server logs provide any useful information?
--
AT&T dsl; Westell 327w modem/router; openSuSE 11.0; firefox 3.0.10
Forums » Tech and Talk » OS and Software » All Things UnixFreeBSD traffic shaping - finding the right scheduler »
« I guess permissions are important.  
page: 1 · 2


Tuesday, 01-Dec 20:32:25 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10 years online! © 1999-2009 dslreports.com.
page compression OFF
Most commented news this week
· [123] Comcast Releasing Promised Usage Meter
· [67] Baltimore To Ban Lazy Cable Installs
· [55] Broadband Killed The Game Console
· [46] Rogers Unveils The ISP Dream Model
· [39] Rural Carriers Quickly Embracing Fiber
· [35] Charter Exits Chapter 11
· [33] AT&T Top Lobbyist Cicconi Has His Feelings Hurt
· [30] ACTA: Global Three Strikes
· [30] Latest Consumer Reports Survey Not Kind To AT&T
· [24] Midcontinent Socked With Easement Lawsuit
Most people now reading
· IMG 1.7 (IMG Updates and Discussion) [Verizon FIOS TV]
· [Internet] Gaming problem for "Heroes of Newerth" ( New bell Upd [Bell Canada]
· Windows 7 boot manager editing questions [Microsoft Help]
· Am I the only one that loves to work in IT? [No, I Will Not Fix Your #@$!! Computer]
· [Phish] email from CDC "personal vaccination profile" [Spam, Scam and Phishbusters]
· [Newsgroups] Newzleech down? [Filesharing Software]
· Why Criminals (Hackers) Must Not Be Rewarded [Security]
· Considering Leaving Vonage, who should I Consider? [VOIP Tech Chat]
· Ooma changing features [VOIP Tech Chat]
· Data Usage Meter Launched [Comcast HSI]