Run system command in perl cgi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run system command in perl cgi
# 8  
Old 03-19-2009
That's the capture of me logging in to www-data and performing a sudo command:
Quote:
Debian:~# su www-data
Debian:/root$ sudo -u vboxuser '/usr/bin/VBoxManage showvminfo pfsense' | grep '^State:'

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for www-data:
That's where the story ends. I never gave a password to www-data, so I don't know what to enter. I also edited /etc/sudoers the way I posted earlier which should keep www-data away from any password hassle, but nothing works as expected...
# 9  
Old 03-19-2009
I don't remember the sudoers file format correctly. Sometimes its simply a syntax issue.

Also if you can afford to do it, set/change the password for www-data and then retry. Do you still get the prompt?

If you add a similar NOPASSWD entry for another user and then do sudo what happens?

You may also want to check sudo documentation for any clues on how it treats accounts which don't have password set.
# 10  
Old 03-20-2009
Well, I would exclude a syntax error, since in the sudoers file is the following example:
Quote:
# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL
I first tried to add this line to just make the www-data user free of anything:
Quote:
www-data ALL=NOPASSWD: ALL
After that didn't work, I activated the example line in the file and made www-data member of the group sudo. That didn't work either...

Next try was setting a password for www-data. Still the password request, but at least now I was able to enter the password I set and got this line:
Quote:
Sorry, user www-data is not allowed to execute '/usr/bin/VBoxManage list vms' as vboxuser on Debian.localdomain.
Next try was to add the same entry for another user and try with that one. Same thing as with www-data. No difference at all.

Last point you proposed is of no use anymore, since it doesn't even work with passwords enabled.

But all your proposals made me do some steps that gave me some clues. Smilie At one point I got the message posted in the last quote which made me think. The sentence implies, that it's only a problem of sudoing to this specific account. I then took some further reading and thinking and came to the conclusion, that sudo is normally a tool to gain root access, not access to another user. But I found something interesting in the sudoers manpage. Added this line to the sudoers file:
Quote:
www-data ALL=(vboxuser) ALL
This line specifies that www-data can run any commands as the other user. This took me a step further since from now on I was able to run the command after I entered the password specified earlier on.
After reading the manpage some more, I even found out what had to be done to get rid of the password prompt:
Quote:
Defaults:www-data !authenticate
This line in the sudoers file made the deal.

But still, I'm stuck with a last problem. I can run commands as my desired user without entering a password, but the command fails with an errorcode that is somehow related to rights. I somehow got the feeling, that it needs to read some files it doesn't have the right permissions when run from sudo. I also checked by logging into the desired account and running the command and all performs well. Since I have the "ALL" statement in /etc/sudoers, the problem can't be another program that is called, it's got to be some file. Any ideas on how I could find out which file or get sudo grant the vboxuser privileges for everything to www-data?
# 11  
Old 03-21-2009
Thought it would be some groups problem, since the sudoers manpage I read online said something about specifying a group when performing sudo. Turns out this seems to be an old version and this option does not exist anymore. Read the current manpage directly from the command line and it states that sudo performs any command with the groups the target user is in.

So groups can not be the problem and I have got to keep searching...
# 12  
Old 03-21-2009
Wow, that things have to be this complicated! Smilie But i finally got to where I wanted to be.

The work did a little option "-H" when running the command. This option specifies to set the home directory environment variable to the one of the target user and it seems that somehow the command I wanted to perform relies on the home directory to be set right.

Thanks very much to everybody for the lots of help. You got me lots of ideas I would have never had by myself... Smilie
# 13  
Old 05-27-2009
www-data does not get login rights as default to protect from using it as an ssh login. You would have to look at the man page for "moduser" or use a gui user admin tool to change that.

It is of course doing that for security reasons and changing the setting is unadvisable if your connected to the internet.

Can't you "chown" the executable to the www-data user or chmod 777 [exe] the file so it is runnable by all users, this would be more secure as it would affect only that exe and you evidently want a cgi script to have access to it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run command through html+cgi in bash

Hi everyone, I want to kill process through the web, so I create html page with single bottom that run kill command in shell script with CGI. Here is html code: <td><form METHOD="GET" action="http://IP:port/cgi_bin/script.cgi" > <input type="submit" value= "Submit" > <INPUT name="q"... (7 Replies)
Discussion started by: indeed_1
7 Replies

2. Shell Programming and Scripting

Perl system() to run a script

Hello, I'm trying to run "csso" (minify css) in a CGI script from the web panel. That is not working: Returns error 0; my $cmd = qq`csso stylesheet.css > stylesheet.min.css`; system($cmd); But that is working: my $cmd = qq`echo 'blabla' > stylesheet.min.css`; system($cmd); I'm... (12 Replies)
Discussion started by: madispuk
12 Replies

3. Shell Programming and Scripting

CGI Perl : while loop in CGI perl

Hi Team, I am trying to connect to database(succeeded ) and print the records on the browser using while loop. But the elements of array are not displayed instead while loop is displayed directly. Instead of the below I can embed html statements in print but I am looking for the below style as I... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Shell Programming and Scripting

Perl CGI : unable to download the excel sheet from perl cgi page

Hi All, I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet. I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet. print "<center><table... (2 Replies)
Discussion started by: scriptscript
2 Replies

5. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

6. Shell Programming and Scripting

Better way to run this perl command

i'm working with files that are huge in size. over 3GB. and i need to do a lot of pattern matching. I need a way to grep for what i want, using a tool that is available across most unix systems. i initially was gungho about grep, but not all capablities of grep are available on all OSes. so... (10 Replies)
Discussion started by: SkySmart
10 Replies

7. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

8. Shell Programming and Scripting

Run SCP in backgroung using Perl CGI

Hi I am Run Perl CGI Script. In which i am running SCP Command. But I want that command to be run into background and exit the script. But Still Web page waiting for Finish the script. I m doing like : system ("scp -r machinename:/path/to/file/for/copy/ /path/for/ destination/directory/ &");... (3 Replies)
Discussion started by: Navrattan Bansa
3 Replies

9. Shell Programming and Scripting

How to execute remote ssh command - Perl and CGI

Hi, I am having nightmare issue-ing remote ssh command from a CGI perl script. It just won't run on debug message: It says permission denied. Can I even do this? as the apache server running under DAEMON account probably can't execute it? Is this the case of what's going on? Here is my... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

10. Shell Programming and Scripting

Perl run system command

Can perl execute a system command similar to the C function System()? Thanks. Gregg (1 Reply)
Discussion started by: gdboling
1 Replies
Login or Register to Ask a Question