PHP:安装USB设备 [英] PHP: mount USB device

查看:183
本文介绍了PHP:安装USB设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一分钱OS服务器的GUI的PHP脚本。出于测试目的,我已经设置了Apache作为本地主机。美分OS不自动连接的USB设备。在PHP中我需要检查是否有USB设备插入,然后将其安装并列出用户的文件内容。这是在bash非常简单,但我无法使其在PHP工作。我曾与两个执行exec()了shell_exec()与无济于事功能发挥各地。我曾尝试命令手动两种即:

I am writing a PHP script for the GUI of a Cent OS server. For testing purposes I have set up the Apache as localhost. Cent OS does not automount a connected USB device. In PHP I need to check if a USB device is plugged in then mount it and list the file content for the user. This is quite simple in bash, however I am unable to make it work in PHP. I have played around with both the exec() and the shell_exec() functions with no avail. I have tried the commands both manually i.e.:

shell_exec("sudo mount /dev/sdb1 /mnt");

,并通过bash脚本:

and through a bash script:

exec("./mountlist.sh");

有没有在PHP中的功能,我可以打电话,会做同样的事情,还是我失去了与 EXEC东西了shell_exec 功能。这两个功能在外壳做工精细。由于坐骑是我包括须藤在bash脚本根命令。

Is there a function in PHP I can call that will do the same thing, or am I missing something with the exec and shell_exec functions. Both functions work fine in the shell. Since mount is a root command I included sudo in the bash script.

推荐答案

您可以从PHP脚本中没有须藤 - 有没有办法在sudo的密码键入

You can't sudo from inside a PHP script - there is no way to type in the sudo password.

您可以创建一个shell脚本,并使用粘滞位有它运行作为根用户

You could create a shell script and use the STICKY bit to have it run as the root user

http://www.dba-oracle.com/linux/sticky_bit.htm

这就是passwd命令如何编写通过,即使您运行它作为一个正常的所有​​者是root密码文件。

That's how the passwd command can write to the password file owned by root even though you are running it as a normal user.

此外 - 你能给网络用户权限挂载/卸载文件系统(把他加为大多数系统上的保险丝组),但是那是更加开放式的,如果你的网络服务器遭到黑客攻击相当危险的,所以我会去与shell脚本和粘位你的目的。

Also - you could grant the web user permission to mount/unmount file systems (add him to the fuse group on most systems), but that's more open-ended and rather dangerous if your web server gets hacked, so I would go with shell scripts and sticky bits for your purposes.

这篇关于PHP:安装USB设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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