dongxu7408
2015-02-06 10:18
浏览 56
已采纳

从php代码安装debian驱动器

I've been at this for two days now and haven't been able to find any way (good or bad) of doing that to work.

I have to be able of dynamically mounting drives over network from my website's pages (that part is inevitable).

I have no problems doing it directly on the console with the following command

mount -t cifs //IP-REMOTE-MACHINE/Folder -o username=username,password=password /mnt/share

Obviously trying to just do a shell_exec() of this command wouldn't work with no root rights.

I tried to shell_exec() a script in which I would switch to root user (via su or sudo mycommand) but both of them wouldn't work (never been able to succeed in doing a script who would automatically switch my user to root even with the root pwd hard coded (even if that feels an extremely bad idea I could have accepted that atm).

After that I tried to use pmountbut never found a way to access to a remote shared file (don't think it's even possible but I may have missed something here?)

All that is running on a Debian machine with apache2.

图片转代码服务由CSDN问答提供 功能建议

我已经在这里呆了两天而且找不到任何办法(好的或坏的) 这样做是为了工作。

我必须能够从我的网站页面动态地通过网络安装驱动器(这部分是不可避免的)。

使用以下命令直接在控制台上执行此操作时没有问题

  mount -t cifs // IP-REMOTE-MACHINE  / Folder -o username = username,password = password / mnt / share 
   
 
 

显然只是想做一个 shell_exec() 命令无法使用root权限。

我尝试 shell_exec()一个脚本,我将切换到root用户(通过su或sudo mycommand) )但是它们都不起作用(从来没有能够成功地做一个脚本,即使用root pwd硬编码也会自动将我的用户切换到root用户(即使我认为这是一个非常糟糕的主意我可以接受那个atm) 。

之后我尝试使用 pmount 但从未找到过访问远程共享文件的方法(不要认为它甚至可能,但我可能有 错过了什么?)

所有在apache2上使用apache2运行的。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanpao4522 2015-02-06 10:25
    已采纳

    I have a wild idea...

    You could set a cron to run as root that checks for mount commands from your script. The script would simply set a mount command to be processed, and when the cron gets to it, runs the mount, marks the command as processed, and writes to a log file which you could then display.

    点赞 打赏 评论
  • dongweizhen2009 2015-02-06 10:27

    It's not safe to run sudo commands with www-data (the user for web servers in Debian).

    But if you want to run sudo [command] in a php script, you must add the user www-data in sudoers: http://www.pendrivelinux.com/how-to-add-a-user-to-the-sudoers-list/

    And then you can exec: sudo mount ...

    EDIT: It's safer to add in visudo:

    www-data ALL= NOPASSWD: /bin/mount
    

    To allow www-data to use only sudo /bin/mount

    点赞 打赏 评论

相关推荐 更多相似问题