简体   繁体   English

如何通过Web访问处理命令行权限

[英]How to handle command line permissions via web access

Here is was I am trying to do: 这是我正在尝试做的事情:

I have a vServer, running different game servers, voice servers, bots etc. As we have some admins in our community who don't know how to handle the servers via command line I want to create a webinterface which basically executes some commands through button clicks and shows what the server would answer. 我有一个vServer,运行着不同的游戏服务器,语音服务器,机器人等。由于我们社区中有一些不知道如何通过命令行处理服务器的管理员,我想创建一个基本上通过按钮执行一些命令的网络界面单击并显示服务器将回答的内容。 Almost everything is working fine, I used PHP to execute commands with shell_exec() function, but I ran into a problem: the www-data user does not have the needed permissions to execute some commands. 几乎一切都工作正常,我使用PHP使用shell_exec()函数执行命令,但是遇到一个问题:www数据用户没有执行某些命令所需的权限。 I googled for some solutions and now I know that it would not be intelligent to run Apache as root, so I am searching for another solution... 我用谷歌搜索了一些解决方案,现在我知道以root身份运行Apache是​​不明智的,所以我正在寻找另一个解决方案...

Anyone who knows a "beautiful" way to solve this? 有谁知道解决这个问题的“美丽”方法? I need to say that I am pretty much a beginner with these things, so please don't expect to much knowledge :p 我需要说的是,我几乎是这些东西的初学者,所以请不要期望太多的知识:p

Thanks in advance and kind regards :) 在此先感谢您,以及亲切的问候:

One possible solution could have all the commands that you want to run saved in a database table, then create a PHP script running in the crontab as root. 一种可能的解决方案是将要运行的所有命令保存在数据库表中,然后创建一个以root身份在crontab中运行的PHP脚本。 This PHP script should have permission to run system_exec. 此PHP脚本应具有运行system_exec的权限。

The steps are 1) Save commands in the database table => "ls /etc/var/log/" 2) PHP script /var/www/html/read_commands.php (read all the commands from the table and execute with system_exec) and then delete the command. 步骤是1)将命令保存在数据库表=>“ ls / etc / var / log /” 2)PHP脚本/var/www/html/read_commands.php (从表中读取所有命令并使用system_exec执行)然后删除命令。 Ex. 例如

$command_from_table="ls /etc/var/log/";
system_exec($command_from_table);
//delete the command from the table.

3) Add /var/www/html/read_commands.php to the crontab -e. 3)将/var/www/html/read_commands.php添加到crontab -e。

* * * * * sudo /var/www/html/read_commands.php

This can give you one idea, but there are many approaches to this, this can be done with some permission for apache but is a breach of security. 这可以给您一个构想,但是有很多方法,可以通过一定的Apache许可来完成,但这违反了安全性。

Also you need to make sure the user can't insert critical commands like rm -rf / lol 另外,您还需要确保用户不能插入诸如rm -rf / lol之类的关键命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM