设计建议:通过 HTTP 向守护进程发送信号

发布于 2024-10-11 20:51:13 字数 701 浏览 1 评论 0原文

我在 Ubuntu 上使用 Apache。我有一个 Perl 脚本,它基本上读取目录的文件名,然后重写文本文件,然后向守护进程发送信号。如何通过网页尽可能安全地完成此操作?

实际上我可以在下面的代码中运行一个简化的cgi,但如果我删除注释则不行。我正在寻找考虑以下任何问题的建议:

  • 使用 HTTP 请求?
  • 代码中显示的目录的 Apache 文件权限如何?
  • htaccess 是否足以启用用户/通行证访问 cgi?
  • 我应该使用数据库而不是写入文件并运行 cron 查询数据库并授予写入和发送信号的权限吗?
  • 向网络服务器授予尽可能少的权限。
  • 我应该设置 VPN 吗?


#!/usr/bin/perl -wT
use strict;
use CGI;
#@fileList = </home/user/*>; #read a directory listing
my $query = CGI->new();

print $query->header( "text/html" ),
$query->p( "FirstFileNameInArray" ),
#$query->p( $fileList[0] ), #output the first file in directory
$query->end_html;

I'm using Apache on Ubuntu. I have a Perl script which basically read the files names of a directory, then rewrites a text file, then sends a signal to a daemon. How can this be done, as secure as possible through a web-page?

Actually I can run a simplified cgi in the code below, but not if I remove the comments. I'm looking for advise considering any of:

  • Using HTTP Requests?
  • How about Apache file permissions on the directory shown in code?
  • Is htaccess enough to enable user/pass access to the cgi?
  • Should I use a database instead of writing to a file and run a cron querying the db with permission granted to write and send the signal?
  • Granting as less permissions as possible to the webserver.
  • Should I set a VPN?

#!/usr/bin/perl -wT
use strict;
use CGI;
#@fileList = </home/user/*>; #read a directory listing
my $query = CGI->new();

print $query->header( "text/html" ),
$query->p( "FirstFileNameInArray" ),
#$query->p( $fileList[0] ), #output the first file in directory
$query->end_html;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花落人断肠 2024-10-18 20:51:13

据推测,您从注释行中收到的错误是尝试读取 /home/user 目录时权限被拒绝。解决这个问题的方法是(惊讶,惊讶)让 apache 用户 [1] 读取该目录。可以通过三种主要方法来执行此操作:

  1. 在大多数环境中,有
    确实没有充分的理由隐藏所有
    用户家中的文件名
    目录,这样你就可以使
    使用 chmod 可以读取目录
    a+r /home/user
    。除非你有一个
    阻止的具体原因
    广大民众从了解
    用户的文件名
    主目录,我倾向于
    推荐这种方法。

  2. 如果你想多一点
    限制它,你可以
    /home/user 更改为由
    apache用户所属组
    到(或将 apache 用户添加到
    目前拥有的组
    /home/user) 然后设置
    /home/user 可供群组读取。
    这将使所有人都可以访问
    该团体的成员,但不是
    普通大众。

  3. 如果您需要标准
    文件系统权限应用于
    网页访问,你可以看看
    配置 suexec 以便
    个人请求可以接受
    除以下用户外的其他用户的权限
    阿帕奇用户。这通常是
    拥有该代码的用户
    正在运行以处理请求
    (例如,在这种情况下,用户
    拥有您的目录列表脚本),
    但是,如果您使用的是基于 htaccess 的
    身份验证,也许可以
    配置suexec来决定
    接受哪个用户的权限
    基于您登录的用户身份。
    (我自己避免使用 suexec ,所以我不是
    100% 确定是否可以做到这一点并且
    不知道该怎么做
    它可以。)

[1] ...我的意思是 apache 运行的用户;根据您的系统配置,该用户可能被命名为“apache”、“httpd”、“nobody”、“www-data”或其他名称。

Presumably, the error you're getting from the commented lines is a permission denied when trying to read the /home/user directory. The way to fix this is (surprise, surprise) to give the apache user[1] to read that directory. There are three primary approaches to doing this:

  1. In most environments, there's
    really no good reason to hide all
    filenames within a user's home
    directory, so you could make the
    directory world-readable with chmod
    a+r /home/user
    . Unless you have a
    specific reason to prevent the
    general public from knowing the
    names of the files in the user's
    home directory, I'd tend to
    recommend this approach.

  2. If you want to be a bit more
    restrictive about it, you could
    change /home/user to be owned by a
    group which the apache user belongs
    to (or add the apache user to the
    group that currently owns
    /home/user) and then set
    /home/user to be group-readable.
    This will make it accessible to all
    members of that group, but not the
    general public.

  3. If you need to have standard
    filesystem permissions applied to
    web access, you can look at
    configuring suexec so that
    individual requests can take on
    permissions of users other than the
    apache user. This is normally the
    user who owns the code which is
    being run to handle the request
    (e.g., in this case, the user who
    owns your directory-listing script),
    but, if you're using htaccess-based
    authentication, it may be possible
    to configure suexec to decide
    which user's permissions to take on
    based on what user you log in as.
    (I avoid suexec myself, so I'm not
    100% certain if this can be done and
    have no idea how to go about it if
    it can.)

[1] ...by which I mean the user that apache is running as; depending on your system config, this user may be named "apache", "httpd", "nobody", "www-data", or something else entirely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文