Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS-Discovery and read only ONVIF support #13

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitmodules
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
[submodule "src/ftpd/pure-ftpd"]
path = src/ftpd/pure-ftpd
url = https://github.com/jedisct1/pure-ftpd.git

2 changes: 1 addition & 1 deletion src/busybox/.config
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ CONFIG_FEATURE_HTTPD_CGI=y
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
# CONFIG_FEATURE_HTTPD_ERROR_PAGES is not set
# CONFIG_FEATURE_HTTPD_PROXY is not set
# CONFIG_FEATURE_HTTPD_GZIP is not set
CONFIG_FEATURE_HTTPD_GZIP=y
CONFIG_IFCONFIG=y
CONFIG_FEATURE_IFCONFIG_STATUS=y
CONFIG_FEATURE_IFCONFIG_SLIP=y
Expand Down
14 changes: 14 additions & 0 deletions src/busybox/httpd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- busybox/networking/httpd.c 2019-02-08 20:24:33.917338666 +0100
+++ new/yi-hack-v4/src/busybox/busybox/networking/httpd.c 2019-02-06 16:33:46.582275044 +0100
@@ -2430,9 +2430,9 @@
tptr = urlcopy + 1; /* skip first '/' */

#if ENABLE_FEATURE_HTTPD_CGI
- if (is_prefixed_with(tptr, "cgi-bin/")) {
+ if (is_prefixed_with(tptr, "onvif/") || is_prefixed_with(tptr, "cgi-bin/")) {
if (tptr[8] == '\0') {
- /* protect listing "cgi-bin/" */
+ /* protect listing "onvif/" and "cgi-bin/" */
send_headers_and_exit(HTTP_FORBIDDEN);
}
send_cgi_and_exit(urlcopy, urlcopy, prequest, length, cookie, content_type);
3 changes: 3 additions & 0 deletions src/busybox/init.busybox
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ git reset --hard || exit 1

cp ../.config ./ || exit 1

cd $SCRIPT_DIR
patch -p0 < httpd.patch

1 change: 1 addition & 0 deletions src/static/static/home/yi-hack-v4/etc/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ DROPBEAR=yes
FTPD=yes
PROXYCHAINSNG=no
CHECK_UPDATES=yes
WSD=yes
4 changes: 4 additions & 0 deletions src/static/static/home/yi-hack-v4/script/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ if [[ $(get_config DROPBEAR) == "yes" ]] ; then
dropbear -R
fi

if [[ $(get_config WSD) == "yes" ]] ; then
wsdiscovery wlan0 $(cat /home/app/.camver)
fi

# First run on startup, then every hour via crond
$YI_HACK_PREFIX/script/check_update.sh

Expand Down
18 changes: 18 additions & 0 deletions src/wsdiscovery/compile.wsdiscovery
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

echo "Building the WebService Discovery server..."
cd wsdiscovery
make clean
make

mkdir -p ../_install
cp wsdiscovery ../_install

mkdir -p ../_install/www/onvif
echo "Copying the onvif folder..."
cp ./onvif/* ../_install/www/onvif

echo "Compilation succeeded."
6 changes: 6 additions & 0 deletions src/wsdiscovery/init.wsdiscovery
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

rm -rf ./_install
7 changes: 7 additions & 0 deletions src/wsdiscovery/install.wsdiscovery
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

rsync -a ./_install/wsdiscovery ../../build/home/yi-hack-v4/bin/
rsync -a ./_install/www/* ../../build/home/yi-hack-v4/www/
1 change: 1 addition & 0 deletions src/wsdiscovery/wsdiscovery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wsdiscovery
11 changes: 11 additions & 0 deletions src/wsdiscovery/wsdiscovery/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CC=arm-hisiv300-linux-gcc
STRIP=arm-hisiv300-linux-strip

all: wsdiscovery

wsdiscovery: wsdiscovery.c
$(CC) -Os -o wsdiscovery wsdiscovery.c
$(STRIP) wsdiscovery

clean:
rm -f wsdiscovery
259 changes: 259 additions & 0 deletions src/wsdiscovery/wsdiscovery/onvif/device_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
#!/bin/sh
POST_STRING=$(cat)
printf "Content-type: application/soap+xml\r\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tt=\"http://www.onvif.org/ver10/schema\" xmlns:tds=\"http://www.onvif.org/ver10/device/wsdl\" xmlns:ter=\"http://www.onvif.org/ver10/error\" xmlns:xs=\"http://www.w3.org/2000/10/XMLSchema\"><env:Body>"

case $POST_STRING in
*GetSystemDateAndTime*)
printf "<tds:GetSystemDateAndTimeResponse>
<tds:SystemDateAndTime>
<tt:DateTimeType>NTP</tt:DateTimeType>
<tt:DaylightSavings>true</tt:DaylightSavings>
<tt:TimeZone>
<tt:TZ>%s</tt:TZ>
</tt:TimeZone>
<tt:UTCDateTime>
<tt:Time>
<tt:Hour>%i</tt:Hour>
<tt:Minute>%i</tt:Minute>
<tt:Second>%i</tt:Second>
</tt:Time>
<tt:Date>
<tt:Year>%i</tt:Year>
<tt:Month>%i</tt:Month>
<tt:Day>%i</tt:Day>
</tt:Date>
</tt:UTCDateTime>
</tds:SystemDateAndTime>
</tds:GetSystemDateAndTimeResponse>" "(UTC)" $(date +"%H") $(date +"%M") $(date +"%S") $(date +"%Y") $(date +"%m") $(date +"%d")
;;

*GetDeviceInformation*)
printf "<tds:GetDeviceInformationResponse>
<tds:Manufacturer>%s</tds:Manufacturer>
<tds:Model>%s</tds:Model>
<tds:FirmwareVersion>%s</tds:FirmwareVersion>
<tds:SerialNumber>%s</tds:SerialNumber>
<tds:HardwareId>%s</tds:HardwareId>
</tds:GetDeviceInformationResponse>" "YI Technology" $(cat /home/app/.camver) $(cat /home/app/.appver) $(ifconfig | awk '/HWaddr/{print substr($5,1)}') $(grep -e Hardware /proc/cpuinfo | awk '{print $3}')
;;

*GetScopes*)
printf "<tds:GetScopesResponse>
<tds:Scopes>
<tt:ScopeDef>Fixed</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/type/video_encoder</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef>Fixed</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/type/Network_Video_Transmitter</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef>Configurable</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/name/%s</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef>Fixed</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/type/video_analytics</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef>Fixed</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/hardware/%s</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef>Configurable</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/location/</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef>Fixed</tt:ScopeDef>
<tt:ScopeItem>onvif://www.onvif.org/type/ptz</tt:ScopeItem>
</tds:Scopes>
</tds:GetScopesResponse>" $(cat /home/app/.camver) $(grep -e Hardware /proc/cpuinfo | awk '{print $3}')
;;

*GetNetworkInterfaces*)
printf "<tds:GetNetworkInterfacesResponse>
<tds:NetworkInterfaces token=\"wlan0\">
<tt:Enabled>true</tt:Enabled>
<tt:Info>
<tt:Name>wlan0</tt:Name>
<tt:HwAddress>%s</tt:HwAddress>
<tt:MTU>1500</tt:MTU>
</tt:Info>
<tt:IPv4>
<tt:Enabled>true</tt:Enabled>
<tt:Config>
<tt:Manual>
<tt:Address>%s</tt:Address>
<tt:PrefixLength>24</tt:PrefixLength>
</tt:Manual>
<tt:DHCP>true</tt:DHCP>
</tt:Config>
</tt:IPv4>
</tds:NetworkInterfaces>
</tds:GetNetworkInterfacesResponse>" $(ifconfig | awk '/HWaddr/{print substr($5,1)}') $(ifconfig | awk '/inet addr/{print substr($2,6)}')
;;

*GetDNS*)
printf "<tds:GetDNSResponse>
<tds:DNSInformation>
<tt:FromDHCP>true</tt:FromDHCP>
<tt:DNSFromDHCP>
<tt:Type>IPv4</tt:Type>
<tt:IPv4Address>%s</tt:IPv4Address>
</tt:DNSFromDHCP>
</tds:DNSInformation>
</tds:GetDNSResponse>" $(cat /etc/resolv.conf | awk '{print substr($2,1)}')
;;

*GetNTP*)
printf "<tds:GetNTPResponse>
<tds:NTPInformation>
<tt:FromDHCP>true</tt:FromDHCP>
</tds:NTPInformation>
</tds:GetNTPResponse>"
;;

*GetCapabilities*)
IPADDR=$(ifconfig | awk '/inet addr/{print substr($2,6)}')
printf "<tds:GetCapabilitiesResponse>
<tds:Capabilities>
<tt:Device>
<tt:XAddr>http://%s/onvif/device_service</tt:XAddr>
<tt:Network>
<tt:IPFilter>false</tt:IPFilter>
<tt:ZeroConfiguration>false</tt:ZeroConfiguration>
<tt:IPVersion6>false</tt:IPVersion6>
<tt:DynDNS>false</tt:DynDNS>
</tt:Network>
<tt:System>
<tt:DiscoveryResolve>true</tt:DiscoveryResolve>
<tt:DiscoveryBye>true</tt:DiscoveryBye>
<tt:RemoteDiscovery>true</tt:RemoteDiscovery>
<tt:SystemBackup>false</tt:SystemBackup>
<tt:SystemLogging>false</tt:SystemLogging>
<tt:FirmwareUpgrade>false</tt:FirmwareUpgrade>
<tt:SupportedVersions>
<tt:Major>1</tt:Major>
<tt:Minor>0</tt:Minor>
</tt:SupportedVersions>
</tt:System>
<tt:IO>
<tt:InputConnectors>0</tt:InputConnectors>
<tt:RelayOutputs>0</tt:RelayOutputs>
</tt:IO>
<tt:Security>
<tt:TLS1.1>false</tt:TLS1.1>
<tt:TLS1.2>false</tt:TLS1.2>
<tt:OnboardKeyGeneration>false</tt:OnboardKeyGeneration>
<tt:AccessPolicyConfig>false</tt:AccessPolicyConfig>
<tt:X.509Token>false</tt:X.509Token>
<tt:SAMLToken>false</tt:SAMLToken>
<tt:KerberosToken>false</tt:KerberosToken>
<tt:RELToken>false</tt:RELToken>
</tt:Security>
</tt:Device>
<tt:Events>
<tt:XAddr>http://%s/onvif/event_service</tt:XAddr>
<tt:WSSubscriptionPolicySupport>false</tt:WSSubscriptionPolicySupport>
<tt:WSPullPointSupport>false</tt:WSPullPointSupport>
<tt:WSPausableSubscriptionManagerInterfaceSupport>false</tt:WSPausableSubscriptionManagerInterfaceSupport>
</tt:Events>
<tt:Media>
<tt:XAddr>http://%s/onvif/media_service</tt:XAddr>
<tt:StreamingCapabilities>
<tt:RTPMulticast>false</tt:RTPMulticast>
<tt:RTP_TCP>true</tt:RTP_TCP>
<tt:RTP_RTSP_TCP>true</tt:RTP_RTSP_TCP>
</tt:StreamingCapabilities>
</tt:Media>
<tt:PTZ>
<tt:XAddr>http://%s/onvif/ptz_service</tt:XAddr>
</tt:PTZ>
</tds:Capabilities>
</tds:GetCapabilitiesResponse>" $IPADDR $IPADDR $IPADDR $IPADDR
;;

*GetHostname*)
printf "<tds:GetHostnameResponse>
<tds:HostnameInformation>
<tt:FromDHCP>false</tt:FromDHCP>
<tt:Name>%s</tt:Name>
</tds:HostnameInformation>
</tds:GetHostnameResponse>" $(hostname)
;;

*GetNetworkProtocols*)
printf "<GetNetworkProtocolsResponse xmlns=\"http://www.onvif.org/ver10/device/wsdl\">
<NetworkProtocols>
<tt:Name>HTTP</tt:Name>
<tt:Enabled>true</tt:Enabled>
<tt:Port>80</tt:Port>
</NetworkProtocols>
<NetworkProtocols>
<tt:Name>RTSP</tt:Name>
<tt:Enabled>true</tt:Enabled>
<tt:Port>554</tt:Port>
</NetworkProtocols>
<NetworkProtocols>
<tt:Name>HTTPS</tt:Name>
<tt:Enabled>false</tt:Enabled>
<tt:Port>443</tt:Port>
</NetworkProtocols>
</GetNetworkProtocolsResponse>"
;;

*GetNetworkDefaultGateway*)
printf "<tds:GetNetworkDefaultGatewayResponse>
<tds:NetworkGateway>
<tt:IPv4Address>%s</tt:IPv4Address>
</tds:NetworkGateway>
</tds:GetNetworkDefaultGatewayResponse>" $(route | awk '/default/{print substr($2,1)}')
;;

*SystemReboot*)
printf "<tds:SystemRebootResponse>
<tt:Message>Rebooting now.</tt:Message>
</tds:SystemRebootResponse>"
reboot
;;

*GetDiscoveryMode*)
printf "<tds:GetDiscoveryModeResponse>
<tds:DiscoveryMode>Discoverable</tds:DiscoveryMode>
</tds:GetDiscoveryModeResponse>"
;;

*GetUsers*)
printf "<tds:GetUsersResponse>"
cat /etc/passwd | while read USER; do
case $(echo $USER | cut -d: -f3) in
0) GROUP="Administrator" ;;
*) GROUP="User" ;;
esac
printf " <tds:User>
<tt:Username>%s</tt:Username>
<tt:UserLevel>%s</tt:UserLevel>
</tds:User>" $(echo $USER | cut -d: -f1) $GROUP
done
printf "</tds:GetUsersResponse>"
;;

*)
printf "<env:Fault>
<env:Code>
<env:Value>env:Receiver</env:Value>
<env:Subcode>
<env:Value>ter:ActionNotSupported</env:Value>
</env:Subcode>
</env:Code>
<env:Reason>
<env:Text xml:lang=\"en\">ActionNotSupported</env:Text>
</env:Reason>
<env:Detail>
<env:Text>The device do NOT support this feature.</env:Text>
</env:Detail>
</env:Fault>"
;;
esac

printf "</env:Body></env:Envelope>"
Loading