douci1196 2018-09-21 23:06
浏览 51

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

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条回答

  • duanmen2189 2018-09-21 23:32
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择