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

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler