shell 中的 cURL 与 knockd 对比

shell 中的 cURL 与 knockd 对比

我想使用 curl 来控制 IPcam 的功能。这在 shell (/bin/sh) 中运行良好,但在 knockd 中调用时失败。我正在 QNAP NAS (Busybox Linux) 上尝试此操作。

我使用的脚本是:

#!/bin/sh
cd /share/Marc/.scripts
curl -v --upload-file /share/CACHEDEV1_DATA/Marc/.scripts/on.txt --user admin:xxxxx --digest http://192.168.178.28/PSIA/Custom/SelfExt/Event/triggers/VMD-1

它产生以下输出(通过管道传输到文件进行调试):

<!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error: Access Denied! Authorization required.</p>
</body>
</html>

当从 shell 调用 curl 时,我得到:

* About to connect() to 192.168.178.28 port 80 (#0)
*   Trying 192.168.178.28...   
[...]
connected
* Connected to 192.168.178.28 (192.168.178.28) port 80 (#0)
* Server auth using Digest with user 'admin'
> PUT /PSIA/Custom/SelfExt/Event/triggers/VMD-1 HTTP/1.1
> User-Agent: curl/7.21.0 (arm-openwrt-linux-gnu) libcurl/7.21.0 OpenSSL/1.0.0s zlib/1.2.7 libidn/1.9
> Host: 192.168.178.28
> Accept: */*
> Content-Length: 0
> Expect: 100-continue
> 
< HTTP/1.1 401 Unauthorized
< Date: Tue, 17 Nov 2015 07:03:21 GMT
< Server: App-webs/
< Content-Length: 218
< Content-Type: text/html
< Connection: keep-alive
< Keep-Alive: timeout=60, max=99
< WWW-Authenticate: Digest realm="TV-IP320PI",nonce="ZjY1MWVmNThiNzY0YmVmOTEwMzFiY2E0YmZhNzQwNzZmMjBjMzNmNmU0OGQ0ZjczMzZiMzZkNGMxOWZlM2QxNTo6MTQ0MTQ3OTU6VFYtSVAzMjBQSQ=="
< 
* Ignoring the response-body
{ [data not shown]
[...]
Connection #0 to host 192.168.178.28 left intact
* Issue another request to this URL: 'http://192.168.178.28/PSIA/Custom/SelfExt/Event/triggers/VMD-1'
* Re-using existing connection! (#0) with host 192.168.178.28
* Connected to 192.168.178.28 (192.168.178.28) port 80 (#0)
* Server auth using Digest with user 'admin'
> PUT /PSIA/Custom/SelfExt/Event/triggers/VMD-1 HTTP/1.1
> Authorization: Digest username="admin", realm="TV-IP320PI", nonce="ZjY1MWVmNThiNzY0YmVmOTEwMzFiY2E0YmZhNzQwNzZmMjBjMzNmNmU0OGQ0ZjczMzZiMzZkNGMxOWZlM2QxNTo6MTQ0MTQ3OTU6VFYtSVAzMjBQSQ==", uri="/PSIA/Custom/SelfExt/Event/triggers/VMD-1", response="1e4ca05ee7ac23230232de3a611bb7b3"
> User-Agent: curl/7.21.0 (arm-openwrt-linux-gnu) libcurl/7.21.0 OpenSSL/1.0.0s zlib/1.2.7 libidn/1.9
> Host: 192.168.178.28
> Accept: */*
> Content-Length: 470
> Expect: 100-continue
> 
[...]
< HTTP/1.1 200 OK
< Date: Tue, 17 Nov 2015 07:03:22 GMT
< Server: App-webs/
< Connection: close
< Content-Length: 242
< Content-Type: application/xml
< 
{ [data not shown]
[...]
Closing connection #0

不知何故,当从 knockd 调用时,curl 似乎会过早停止。knockd.conf 是:

[EnableOutdoors]
        sequence    = x,y
        seq_timeout = 5
        command     = /share/CACHEDEV1_DATA/Marc/.scripts/enableOutdoors.sh
        tcpflags    = syn

为什么 curl 的行为不同?我也尝试在脚本中包含在 shell 中设置的所有导出enableOutdoors.sh,但这没有帮助。

答案1

由于我不知道的原因,NAS 上有两个 curl 实例。(可能是操作系统更新引入的一个?)不知何故,环境变量的导出不起作用。在脚本中明确调用“正确的” curl 解决了这个问题。

# /sbin/curl -V 
curl 7.21.0 (arm-openwrt-linux-gnu) libcurl/7.21.0 OpenSSL/1.0.0s zlib/1.2.7 libidn/1.9
Protocols: dict file ftp ftps http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz 

# /share/CACHEDEV1_DATA/.qpkg/Entware/bin/curl -V
curl 7.43.0 (arm-openwrt-linux-gnueabi) libcurl/7.43.0 OpenSSL/1.0.2d zlib/1.2.8
Protocols: file ftp ftps http https imap imaps pop3 pop3s rtsp smtp smtps tftp 
Features: IPv6 Largefile SSL libz 

相关内容