Click here to Skip to main content
14,163,580 members
Rate this:
 
Please Sign up or sign in to vote.
Hi,
i've problem with Apache2. It is not executing Python Scripts which includes "sudo" command. Those scripts are working fine while running from terminal (as a "pi" user).

Apache2 is running also "pi" user.
Response for ps aux | grep apache2 command:
root       409  0.0  0.4   7544  3824 ?        Ss   18:48   0:00 /usr/sbin/apache2 -k start
pi         410  0.0  0.3   7292  3036 ?        S    18:48   0:00 /usr/sbin/apache2 -k start
pi         411  0.0  0.4 231032  3872 ?        Sl   18:48   0:01 /usr/sbin/apache2 -k start
pi         412  0.0  0.4 231032  3872 ?        Sl   18:48   0:01 /usr/sbin/apache2 -k start
pi        1920  0.0  0.0   4372   556 pts/0    S+   20:17   0:00 grep --color=auto apache2


Python scripts are executable for every user:
-rwxrwxr-x  1 pi pi 1251 Aug 27 16:46 checkDisks.py
-rwxrwxr-x  1 pi pi 1650 Aug 30 05:52 checkDownload.py
-rwxrwxr-x  1 pi pi 1969 Aug 10 08:38 checkUSB.py
-rwxrwxr-x  1 pi pi  725 Aug 27 13:31 createUSB.py
drwxrwxr-x  3 pi pi 4096 Aug 30 05:14 current
-rwxrwxrwx  1 pi pi  522 Aug 27 20:25 deleteFiles.py
-rwxrwxrwx  1 pi pi  627 Aug  9 08:33 downloadLatest.py
drwxrwxr-x 34 pi pi 4096 Jul 31 15:42 dss-testautomation
drwxrwxr-x  7 pi pi 4096 May  3 14:46 dss-update-tester
-rw--w----  1 pi pi   28 Aug 27 19:53 nohup.out
-rwxrwxrwx  1 pi pi 1214 Aug 27 20:41 prepareSpace.py
drwxrwxr-x  3 pi pi 4096 May  3 11:02 testserver
-rw-rw-r--  1 pi pi  104 Aug  9 16:19 USB_lock
-rwxrwxrwx  1 pi pi 2187 Aug 20 14:29 usbOFF.py
-rwxrwxrwx  1 pi pi 3334 Aug 30 18:47 usbON.py
drwxrwxr-x  5 pi pi 4096 May  3 14:39 webpy_server


/var/log/apache2.error.log:
[Thu Aug 30 06:25:04.010021 2018] [mpm_event:notice] [pid 421:tid 1996357632] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 06:25:04.010214 2018] [core:notice] [pid 421:tid 1996357632] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 06:29:27.351568 2018] [mpm_event:notice] [pid 421:tid 1996357632] AH00491: caught SIGTERM, shutting down
[Thu Aug 30 06:29:30.780150 2018] [mpm_event:notice] [pid 425:tid 1996349440] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 06:29:30.782850 2018] [core:notice] [pid 425:tid 1996349440] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 07:11:05.987870 2018] [mpm_event:notice] [pid 425:tid 1996349440] AH00491: caught SIGTERM, shutting down
[Thu Aug 30 07:11:09.764342 2018] [mpm_event:notice] [pid 407:tid 1996001280] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 07:11:09.766669 2018] [core:notice] [pid 407:tid 1996001280] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 07:14:13.321922 2018] [mpm_event:notice] [pid 407:tid 1996001280] AH00491: caught SIGTERM, shutting down
[Thu Aug 30 07:14:16.745765 2018] [mpm_event:notice] [pid 412:tid 1996087296] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 07:14:16.747934 2018] [core:notice] [pid 412:tid 1996087296] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 07:20:01.962704 2018] [mpm_event:notice] [pid 412:tid 1996087296] AH00491: caught SIGTERM, shutting down
[Thu Aug 30 07:20:05.697280 2018] [mpm_event:notice] [pid 410:tid 1995591680] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 07:20:05.699445 2018] [core:notice] [pid 410:tid 1995591680] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 08:48:14.215742 2018] [mpm_event:notice] [pid 410:tid 1995591680] AH00491: caught SIGTERM, shutting down
[Thu Aug 30 08:48:17.779856 2018] [mpm_event:notice] [pid 407:tid 1996382208] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 08:48:17.782313 2018] [core:notice] [pid 407:tid 1996382208] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 09:56:42.876253 2018] [mpm_event:notice] [pid 411:tid 1995579392] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 09:56:42.879043 2018] [core:notice] [pid 411:tid 1995579392] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 30 18:48:30.844159 2018] [mpm_event:notice] [pid 411:tid 1995579392] AH00491: caught SIGTERM, shutting down
[Thu Aug 30 18:48:34.752957 2018] [mpm_event:notice] [pid 409:tid 1996111872] AH00489: Apache/2.4.25 (Raspbian) configured -- resuming normal operations
[Thu Aug 30 18:48:34.755767 2018] [core:notice] [pid 409:tid 1996111872] AH00094: Command line: '/usr/sbin/apache2'


Any tips what can be wrong?

What I have tried:

I've tried to modify a /etc/sudoers file, but it didn't bring any result
Posted
Updated 30-Aug-18 20:38pm
Comments
MateoGlowinski 31-Aug-18 6:10am
   
The response for "echo $SHELL" command executed by Apache2 was "\n".

The result for "mount" command is different while executing from terminal and different while executing from Apache2.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It doesn't work because sudo is interactive. It'll ask for a password which your website will not be able to "type in".

I don't know how you're launching the command, so I suspect you're launching a command like "sudo command"?

You can try changing the command to "echo password | sudo command".

WARNING!! RUNNING COMMANDS THAT REQUIRE SUDO GIVES YOUR WEBSITE CODE, AND ANY BUGS AND SECURITY PROBLEMS IN IT, SUPER USER PERMISSIONS TO DO ANYTHING ON THE SERVER, INCLUDING DESTROYING IT.

YOU ARE ALSO PUTTING THE PASSWORD TO SUCH IN CLEAR TEXT IN YOUR WEBSITE.


There isn't a font size large enough to emphasize how big of a security risk you are coding into your web site by doing this.
   
v2
Comments
MateoGlowinski 31-Aug-18 3:56am
   
You are right, i'm executing sudo mount XXXX YYYY and sudo umount YYYY.

I tried changing the command to "echo password | sudo command", still not working.
Response on this command was "\n", but USB Device is still not mounted.

Thank you for warning, but i'm aware of that. RP3 will be only used in my internal net:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190518.1 | Last Updated 31 Aug 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100