drcmg28484 2013-03-01 21:45
浏览 59

使用PHP(Apache)以某些命令的root权限启动linux应用程序

I am running several instance of Node and all of them run on different ports.

I need a way to be able to kill a particular instance of Node based on the port it is running (kill node instance binded to port n).

From my terminal I can easily do a "fuser -k xxxx/tcp" xxxx being the port.

The thing is, that is because I have the authorisation to do so. My question is: I want to be able to have a PHP file that closes the node instance running on port n and it can be opened by anyone. How to do this without opening huge security holes?

Thank you!

  • 写回答

2条回答 默认 最新

  • douren6874 2013-03-01 21:57
    关注

    The best way to do this would be to have php write the port number to a file, then have a cron script run as root (or whatever user it needs to be) and read the port number(s) from that file. The cron script should have some sort of safety measures in there as well, such as not stopping whatever is running on port 80 or not a node process at all.

    edit: for a bit more security, you could require the port number to be prefixed by a "password" that would require you to input. Then the cron script would verify it's prefixed by that password (or hash it and compare the hash would be even better)

    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计一个单管共射放大电路
  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架