LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-03-2011, 05:05 PM   #1
mzh
Member
 
Registered: Apr 2011
Location: Copenhagen
Posts: 71

Rep: Reputation: 0
Script runs local-- now over the web


Dear all
At our university server, I patched together a script (lets call it connect.py) that kind of glues together a series of calls to different other programs (the first one is in Python2.X, the second is a binary so I use os.system('/path/to/program input.pot') to start it, and the last is in Python3.X). It kind of seems to work well now when working under my user account, where the script has the permissions to call the programs, because I installed them.
Now, when I want to start the connect script by pressing a submit button in an HTML form, naturally I start running into trouble. Now its no longer my user who is calling, but the server (Apache) with very limited rights. In the progress of writing the connect.py script, I had to do quite some environment adjustment so the various Python modules could be imported.

What is the easiest way to get the script started from an HTML form? I guess it would not be good practice to start extending the PATH variables of Apache, would it?

Last edited by mzh; 05-03-2011 at 05:06 PM.
 
Old 05-04-2011, 10:16 AM   #2
jason_not
Member
 
Registered: Aug 2010
Location: Beaverton, Oregon, USA
Distribution: Pfsense, Ubuntu, Centos, Fedora, Redhat, Scientfic, MacOS
Posts: 76

Rep: Reputation: 19
Hello,

I can't tell you exactly what you need to do. I can tell you a couple of important things to remember when programming for the web:

First:
the script will run as the user that the apache server runs as. This is because it is the apache server that starts up the script when you press submit.

Second:
Even if you were able to login as the apache user, the interactive environment is likely different from that under apache. Look for a python function that acts like phpinfo(). This php function dumps out the php environment, so you can see exactly how things are configured.

Likely, you just need to find what changes are necessary to make your script run in a limited environment.

I hope this helps...

--jason
 
Old 05-05-2011, 04:13 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by mzh View Post
At our university server, I patched together a script (..). It kind of seems to work well now when working under my user account, where the script has the permissions to call the programs, because I installed them. Now, when I want to start the connect script by pressing a submit button in an HTML form, naturally I start running into trouble. Now its no longer my user who is calling, but the server (Apache) with very limited rights. In the progress of writing the connect.py script, I had to do quite some environment adjustment so the various Python modules could be imported. What is the easiest way to get the script started from an HTML form? I guess it would not be good practice to start extending the PATH variables of Apache, would it?
First of all do regard separation of privilege as a Good Thing (and not something Evil ;-p). And as far as "important things to remember when programming for the web" are concerned the more important issue is validating user input or rather: rejecting requests that (un)intentionally do not conform to specs instead of correcting them (bad) or assuming they're all good (even worse). Apache has a way to execute commands as a different UID than that of the web server user (suexec) and so has PHP (suPHP). For any other command you can use a custom CGI script which routes the request to your "connect.py" script through a 'sudo' CmndAlias.
 
Old 05-05-2011, 05:04 AM   #4
mzh
Member
 
Registered: Apr 2011
Location: Copenhagen
Posts: 71

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
Apache has a way to execute commands as a different UID than that of the web server user (suexec) and so has PHP (suPHP). For any other command you can use a custom CGI script which routes the request to your "connect.py" script through a 'sudo' CmndAlias.
Thanks for the hints so far guys.

@unSpawn: this sounds pretty much like something that would help me. I noticed what you said about precautions, and I'm definitely not ignoring them. At the moment though, I need to find a way of getting this running, that has the highest priority.
I was reading suexec is something people rather not tend to encourage using, as far as i remember correctly, its not in the default installation of apache.. could you maybe elaborate what it is that you mean with routing the script to sudo cmndalias? Does this mean Apache would temporarily switch its ID in order to execute the script?
 
Old 05-05-2011, 06:03 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by mzh View Post
I noticed what you said about precautions, and I'm definitely not ignoring them. At the moment though, I need to find a way of getting this running, that has the highest priority.
OK but adding security as an afterthought, by itself not that unusual in fast-paced development environments, is a Bad Thing.


Quote:
Originally Posted by mzh View Post
I was reading suexec is something people rather not tend to encourage using, as far as i remember correctly, its not in the default installation of apache..
Note I only gave suexec as an example of the method. It being installed by default depends on the distribution. For me (running Centos) suexec comes standard with the httpd package. The problem with suexec is it requires root ownership and the setuid bit to be set. And yes, introducing setXid binaries is not a security best practice.


Quote:
Originally Posted by mzh View Post
could you maybe elaborate what it is that you mean with routing the script to sudo cmndalias? Does this mean Apache would temporarily switch its ID in order to execute the script?
"Pushing a button" in a HTML page means passing a HTTP request to a CGI script. This CGI script executes (as the web server UID) a "/usr/bin/sudo /path/to/connect.py ${ANY_SANE_ARGS_HERE}" command. The "/path/to/connect.py ${ANY_SANE_ARGS_HERE}" corresponds with a "/path/to/connect.py" Cmnd_Alias in /etc/sudoers allowing the web server UID to run that command as your user.
 
Old 05-06-2011, 04:14 PM   #6
mzh
Member
 
Registered: Apr 2011
Location: Copenhagen
Posts: 71

Original Poster
Rep: Reputation: 0
thanks for the feedback, very helpful.
I worked around the whole issue now in a rather different way though, what i did is I installed the required program under the apache account, so it naturally has access to it.
What I am wondering now is to figure out how I can adjust the PATH variable of Apache, so it can run the program from any directory.
The httpd.conf looks something like this
Code:
SetEnv PATH $PATH:/var/www/programs/vmd
but it does not seem to include this path, i.e. the path /var/www/progams/vmd is not printed when I echo $PATH (as apache2 user).
What can I do?
 
Old 05-06-2011, 05:24 PM   #7
jason_not
Member
 
Registered: Aug 2010
Location: Beaverton, Oregon, USA
Distribution: Pfsense, Ubuntu, Centos, Fedora, Redhat, Scientfic, MacOS
Posts: 76

Rep: Reputation: 19
Hello,

When you login as the apache user, the http.conf file is not being read. This file is only read when apache is being started up.

I recommend you create a php script that calls phpinfo(). That will display most of apache's environment back to you.

Create the DocumentRoot/phpinfo.php file with the following contents:

Quote:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>
Then you should be able to go to the url http://<hostip>/phpinfo.php
 
Old 05-07-2011, 02:59 AM   #8
mzh
Member
 
Registered: Apr 2011
Location: Copenhagen
Posts: 71

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jason_not View Post
Hello,

When you login as the apache user, the http.conf file is not being read. This file is only read when apache is being started up.
that would also be fine, since i can just restart apache, but even after restarting it didn't seem to know about the new path. Still I would like to ask, what would be the correct way of adjusting the path variable. Did i miss something below?
@jason: I'll be seeing what i get out from that, thanks for the hint.
OK, i checked out the information from phpinfo(). What appears strange to me is that when I echo $PATH as www-data (in the shell), i get the following output:
Code:
sh-3.1$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
Other when I issue phpinfo():
Code:
PATH 	/usr/local/bin:/usr/bin:/bin
how come so?

Anyway, still i would like to know how I can edit the $PATH variable of Apache correctly.

Last edited by mzh; 05-07-2011 at 11:49 AM.
 
Old 11-30-2011, 10:14 PM   #9
sathish2018
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Rep: Reputation: 0
nice one
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
Simple PHP script fails on local web server Azul Rondo Programming 2 08-08-2009 03:10 AM
wpa_supplicant runs from rc.local script - is this the best way __spc__ Linux - Wireless Networking 2 09-05-2008 02:32 PM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM
Local webserver -- How to deny all client install their local web server--Please help b:z Linux - Networking 13 04-16-2005 07:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration