Apache2 - 作为pi用户问题执行Python脚本 [英] Apache2 - execute Python scripts as pi user problem

查看:90
本文介绍了Apache2 - 作为pi用户问题执行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对Apache2有疑问。它不执行包含sudo命令的Python脚本。从终端(作为pi用户)运行时,这些脚本工作正常。



Apache2也运行pi用户。

对ps aux的响应| grep apache2命令:

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脚本对每个用户都是可执行的:



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:



/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'





任何提示可能出错?



我尝试了什么:



我试图修改/ etc / sudoers文件,但它没带任何结果



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

推荐答案

它不起作用,因为sudo是交互式的。它会要求您提供一个密码,您的网站无法输入。



我不知道您是如何启动命令的,所以我怀疑你正在启动像sudo command 这样的命令?



您可以尝试将命令改为echo password | sudo 命令



警告!! 运行要求SUDO的命令提供您的网站代码,以及其中的任何错误和安全问题,超级用户许可在服务器上做任何事情,包括破坏它。



您还要输入密码在你的网站上有清晰的文字。




没有足够大的字体大小来强调你编写的安全风险有多大这样做是你的网站。
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.


这篇关于Apache2 - 作为pi用户问题执行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆