Php 使用apache筛选器拒绝权限

Php 使用apache筛选器拒绝权限,php,apache,selinux,Php,Apache,Selinux,我在Centos7(SELinux)上使用ApacheHTTPD,并试图创建一个输出过滤器来修改所有提供的html页面。我已经浏览了一些关于如何创建它们的教程,但在开始编写代码之前,我一直在第一步上结结巴巴 目前我的httpd.conf中有这个 ExtFilterDefine portal_header mode=output intype=text/html cmd="/var/www/root/main/portal/portal.php" SetOutputFilter portal_he

我在Centos7(SELinux)上使用ApacheHTTPD,并试图创建一个输出过滤器来修改所有提供的html页面。我已经浏览了一些关于如何创建它们的教程,但在开始编写代码之前,我一直在第一步上结结巴巴

目前我的httpd.conf中有这个

ExtFilterDefine portal_header mode=output intype=text/html cmd="/var/www/root/main/portal/portal.php"
SetOutputFilter portal_header
为了指出我的问题,我暂时删除了文件/var/www/root/main/portal/portal.php中的所有实际代码,现在看起来是这样的

#!/usr/bin/php
<php?
  /* test */
?>
我至少有

  • 将文件权限更改为777
  • 已验证php位于/usr/bin/php,并由apache group拥有适当的权限
  • 试图为httpd.conf中的目录添加和删除ScriptAlias和/或SetHander cgi脚本
  • 尝试使用完全空的脚本文件
但以上这些都没有任何效果。唯一的变化是,当我故意拼写错误的文件名,我得到了“没有这样的文件或目录”的错误

有人知道我应该怎么做才能让这一切顺利吗?目前,我很高兴看到脚本甚至什么都不做,如果它没有崩溃的话,只是在之后添加了一些功能


更新:我能够指出SELinux策略的问题,因为在禁用它们(setEnforce0)后,错误消失了。因此,目前我正试图找出应该如何修改策略。

在尝试改进简单的sed filter命令时,我遇到了类似的问题。 根据文档,应该可以使用像sed这样的命令作为过滤器,实际上它可以:

以下过滤器适用于我,并将全局链接替换为本地链接,以便我可以使用docker图像和现有站点的数据

# Filter configuration
# mod_ext_filter directive to define a filter which
# replaces text in the response
#
ExtFilterDefine fixtext mode=output intype=text/html \
    cmd="/bin/sed s#http://ceur.ws.org#http://capri:8880#g"

<Location "/">
    # core directive to cause the fixtext filter to
    # be run on output
    SetOutputFilter fixtext
</Location>
我收到了错误消息:

AH01458: couldn't create child process to run `/root/bin/filter.sh'
AH01467: can't initialise output filter fixtext: aborting
这是你提出问题的最初原因

现在,我也在寻找更好的解决方案,并尝试:

cmd="/bin/bash /root/bin/filter.sh" 
假设凶手可能是凶手。有趣的是,我得到:

AH01461: apr_file_write(child input), len 0
AH01468: ef_unified_filter() failed
这就是为什么我已经发布了这个答案,希望我能很快找到一个合适的解决方案,或者其他人能够提供帮助,因为这个问答环节越来越长了

有关源代码,请参阅

我假设apr_proc_create不能使用shebang调用脚本。所以我的解决办法是

  • 直接调用命令
  • 切换到awk
  • 正在使用apache filter.conf

    # Filter configuration
    # mod_ext_filter directive to define a filter which
    # replaces text in the response
    #
    ExtFilterDefine fixtext mode=output intype=text/html \
        cmd="/usr/bin/awk -f /var/www/filter.awk"
    
    <Location "/">
        # core directive to cause the fixtext filter to
        # be run on output
        SetOutputFilter fixtext
    </Location>
    
    /root/bin/filters.sh

    #!/bin/bash
    # WF 2020-06-02
    # filter all html output thru this script
    port=8880
    host=capri
    # substitute all hard links in CEUR-WS with a local link
    /bin/sed s#http://ceur.ws.org#http://$host:$port#g
    # try out this filter with
    # cat /var/www/html/index.html | /root/bin/filter.sh | grep capri
    

    通过谷歌搜索错误,可以找到统一资源定位器,看看问题是否与这里描述的类似。
    # Filter configuration
    # mod_ext_filter directive to define a filter which
    # replaces text in the response
    #
    ExtFilterDefine fixtext mode=output intype=text/html \
        cmd="/usr/bin/awk -f /var/www/filter.awk"
    
    <Location "/">
        # core directive to cause the fixtext filter to
        # be run on output
        SetOutputFilter fixtext
    </Location>
    
    # WF 2020-06-03
    #
    # filter HTML output thru this awk script to fix global links to local ones
    #
    # you might want to try out this filter from the command line with
    # cat /var/www/html/index.html | awk -f filter.awk 
    #
    # setup the  replacement
    BEGIN {
      port=8880
      host="capri"
      sourceServer="http://ceur-ws.org" 
      targetServer=sprintf("http://%s:%s",host,port) 
    }
    # for each line
    {
      # get the line
      line=$0
      # replace any sourceServer reference with the targetServer reference
      gsub(sourceServer,targetServer,line)
      # output the modified line
      print line 
    }
    
    #!/bin/bash
    # WF 2020-06-02
    # filter all html output thru this script
    port=8880
    host=capri
    # substitute all hard links in CEUR-WS with a local link
    /bin/sed s#http://ceur.ws.org#http://$host:$port#g
    # try out this filter with
    # cat /var/www/html/index.html | /root/bin/filter.sh | grep capri