简体   繁体   English

配置 Apache 以将哈希字符作为 QUERY_STRING 的一部分传递给 CGI 脚本

[英]Configure Apache to pass the hash character to CGI scripts as part of QUERY_STRING

I am working on emulating an embedded device that is being controlled via HTML commands.我正在模拟通过 HTML 命令控制的嵌入式设备。 The controller issues URLs such as控制器发出 URL,例如

http://192.168.0.10/cgi-bin/aw_cam?cmd=QFT&res=1

And these affect the device in specific ways.这些以特定方式影响设备。 My goal is to make an emulator of the device so I need to capture and handle all such requests.我的目标是制作设备模拟器,因此我需要捕获和处理所有此类请求。 I have successfully configured Apache to call my scripts and I can get access to the "cmd=QFT&res=1" control string by reading the value of QUERY_STRING.我已成功配置 Apache 以调用我的脚本,并且可以通过读取 QUERY_STRING 的值来访问“cmd=QFT&res=1”控制字符串。 I am using Apache 2.4.18 on Ubuntu 16.04.5.我在 Ubuntu 16.04.5 上使用 Apache 2.4.18。 The scripts are written in C++.这些脚本是用 C++ 编写的。

The problem I am running into is that some of the commands issued by the controller are of the following form:我遇到的问题是控制器发出的一些命令的形式如下:

http://192.168.0.10/cgi-bin/aw_ptz?cmd=#P80&res=1
http://192.168.0.10/cgi-bin/aw_ptz?cmd=#T50&res=1  

For whatever reason, whoever designed the command structure decided to use the # character as part of the command.无论出于何种原因,设计命令结构的人都决定使用 # 字符作为命令的一部分。 But since the '#' delimits the fragment part of the URL, the information after it never makes it to my script, which only receives "cmd="但是由于“#”分隔了 URL 的片段部分,因此它之后的信息永远不会进入我的脚本,它只接收“cmd=”

Is there any way to force Apache to pass the entire string after the ?有没有办法强制 Apache 在 ? 之后传递整个字符串? to my scripts?到我的脚本? I cannot change the client or the protocol, only the server side.我无法更改客户端或协议,只能更改服务器端。

Edit: The apache log shows the entire URL (see portion of log file below), so even though # is supposed to be a fragment delimiter, it makes it into the log file at least but not the cgi script.编辑:apache 日志显示了整个 URL(请参阅下面的日志文件部分),因此即使 # 应该是片段分隔符,它也至少将其放入日志文件中,但不会将其放入 cgi 脚本中。

192.168.0.9 - - [27/Jan/2019:00:21:10 +0000] "GET /cgi-bin/aw_ptz?cmd=#P53&res=1 HTTP/1.0" 200 151 "-" "-"
192.168.0.9 - - [27/Jan/2019:00:21:11 +0000] "GET /cgi-bin/aw_ptz?cmd=#P66&res=1 HTTP/1.0" 200 151 "-" "-"
192.168.0.9 - - [27/Jan/2019:00:21:11 +0000] "GET /cgi-bin/aw_ptz?cmd=#P99&res=1 HTTP/1.0" 200 151 "-" "-"
192.168.0.9 - - [27/Jan/2019:00:21:11 +0000] "GET /cgi-bin/aw_ptz?cmd=#P76&res=1 HTTP/1.0" 200 151 "-" "-"

This seems to work:这似乎有效:

RewriteCond %{THE_REQUEST} \s(.*)#(.*)\s
RewriteRule ^ http://localhost:8000%1#%2 [P,NE]
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/

(I had python simple http server listening on localhost:8000 to verify if hash was passed correctly (我让 python 简单的 http 服务器监听 localhost:8000 以验证哈希是否正确传递

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM