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

这是我要做的事情:</ p>

我有一个vServer 运行不同的游戏服务器,语音服务器,机器人等。由于我们社区中有一些管理员不知道如何通过命令行处理服务器,我想创建一个基本上通过按钮点击执行一些命令的web界面并显示什么 服务器会回答。
几乎一切都运行正常,我使用PHP执行shell_exec()函数的命令,但我遇到了一个问题:www-data用户没有执行某些命令所需的权限。 我搜索了一些解决方案,现在我知道以root身份运行Apache并不聪明,所以我正在寻找另一种解决方案... </ p>

任何知道“美丽”方式的人 解决这个问题? 我需要说我几乎是这些东西的初学者,所以请不要期待太多的知识:p </ p>

提前致谢并亲切问候:)</ p> \ n </ div>

展开原文

原文

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. 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. 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...

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

Thanks in advance and kind regards :)

1个回答



一种可能的解决方案可以将您要运行的所有命令保存在数据库表中,然后创建在crontab中运行的PHP脚本 作为根。 此PHP脚本应具有运行system_exec的权限。 </ p>

步骤为
1)在数据库表中保存命令=&gt; “ls / etc / var / log /”
2)PHP脚本 /var/www/html/read_commands.php </ code>(从表中读取所有命令并使用system_exec执行)然后删除命令 。 \ NEX。 </ p>

  $ command_from_table =“ls / etc / var / log /”; 
system_exec($ command_from_table);
//从表中删除命令。
</ code> </ pre>

3)将/var/www/html/read_commands.php添加到crontab -e。</ p>

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

nn

这可以给你一个想法,但有很多方法,这可以用一些 对apache的许可但是违反了安全性。 </ p>

此外,您需要确保用户无法插入关键命令,例如 rm -rf / </ code> lol </ p>
</ div>

展开原文

原文

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. This PHP script should have permission to run 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. 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.

* * * * * 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.

Also you need to make sure the user can't insert critical commands like rm -rf / lol

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问