From 59d1764411f9ec449ab709e918b94a11df8e4152 Mon Sep 17 00:00:00 2001 From: Jens Maus Date: Mon, 26 Nov 2018 09:15:36 +0100 Subject: [PATCH] fixed issue with non working rssilist.cgi with CCU firmware 3.41.x and modified xmlrpc calls to read the interface urls from Interfaces.xml dynamically. This fixes #23. --- xmlapi/common.tcl | 36 ++++++++++++++++++++++++++++++++++++ xmlapi/mastervalue.cgi | 16 ++++++++++------ xmlapi/mastervaluechange.cgi | 16 ++++++++++------ xmlapi/rssilist.cgi | 3 ++- 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/xmlapi/common.tcl b/xmlapi/common.tcl index ae80fa9..bca7329 100755 --- a/xmlapi/common.tcl +++ b/xmlapi/common.tcl @@ -154,3 +154,39 @@ proc uniq {liste} { return $u_list } + +set INTERFACES_FILE "/etc/config/InterfacesList.xml" +array set interfaces "" +array set interface_descriptions "" + +proc read_interfaces {} { + global interfaces interface_descriptions INTERFACES_FILE env + set retval 1 + if { [ info exist env(BIDCOS_SERVICE) ] } { + set interfaces(default) "$env(BIDCOS_SERVICE)" + set interface_descriptions(default) "Default BidCoS Interface" + } else { + set fd -1 + catch {set fd [open $INTERFACES_FILE r]} + if { $fd >=0 } { + set contents [read $fd] + while { [regexp -indices {]*>} $contents range] } { + set section [string range $contents 0 [lindex $range 1]] + set contents [string range $contents [expr [lindex $range 1] + 1] end] + if { + [regexp {]*>([^<]+)]*>([^<]+)]*>([^<]+)= 0} { - set ausgabe [xmlrpc http://127.0.0.1:9292/groups getParamset [list string $deviceAddress] [list string "MASTER"] ] - } elseif {[string first "HMIP-" $deviceType] >= 0} { - set ausgabe [xmlrpc http://127.0.0.1:2010/ getParamset [list string $deviceAddress] [list string "MASTER"] ] - } else { - set ausgabe [xmlrpc http://127.0.0.1:2001/ getParamset [list string $deviceAddress] [list string "MASTER"] ] + if {[string compare -nocase -length 9 "HM-CC-VG-" $deviceType] == 0} { + set ausgabe [xmlrpc $interfaces(VirtualDevices) getParamset [list string $deviceAddress] [list string "MASTER"] ] + } elseif {[string compare -nocase -length 5 "HMIP-" $deviceType] == 0} { + set ausgabe [xmlrpc $interfaces(HmIP-RF) getParamset [list string $deviceAddress] [list string "MASTER"] ] + } else { + set ausgabe [xmlrpc $interfaces(BidCos-RF) getParamset [list string $deviceAddress] [list string "MASTER"] ] } foreach { bezeichnung wert } $ausgabe { diff --git a/xmlapi/mastervaluechange.cgi b/xmlapi/mastervaluechange.cgi index a78f7a2..59c60b1 100755 --- a/xmlapi/mastervaluechange.cgi +++ b/xmlapi/mastervaluechange.cgi @@ -1,6 +1,8 @@ #!/bin/tclsh load tclrega.so load tclrpc.so +source common.tcl + puts -nonewline {Content-Type: text/xml Access-Control-Allow-Origin: * @@ -20,6 +22,8 @@ catch { } } +read_interfaces + set rec_devids [split $device_id "\,"] set rec_mvaluename [split $name "\,"] set rec_mvaluevalue [split $value "\,"] @@ -50,13 +54,13 @@ for {set counter 0} {$counter<[llength $rec_devids]} {incr counter} { set deviceType $values(deviceType) puts -nonewline $values(STDOUT) - - if {[string first "HM-CC-VG-" $deviceType] >= 0} { - set ausgabe [xmlrpc http://127.0.0.1:9292/groups putParamset [list string $deviceAddress] [list string "MASTER"] [list struct $cmd]] - } elseif {[string first "HMIP-" $deviceType] >= 0} { - set ausgabe [xmlrpc http://127.0.0.1:2010/ putParamset [list string $deviceAddress] [list string "MASTER"] [list struct $cmd]] + + if {[string compare -nocase -length 9 "HM-CC-VG-" $deviceType] == 0} { + set ausgabe [xmlrpc $interfaces(VirtualDevices) putParamset [list string $deviceAddress] [list string "MASTER"] [list struct $cmd]] + } elseif {[string compare -nocase -length 5 "HMIP-" $deviceType] == 0} { + set ausgabe [xmlrpc $interfaces(HmIP-RF) putParamset [list string $deviceAddress] [list string "MASTER"] [list struct $cmd]] } else { - set ausgabe [xmlrpc http://127.0.0.1:2001/ putParamset [list string $deviceAddress] [list string "MASTER"] [list struct $cmd]] + set ausgabe [xmlrpc $interfaces(BidCos-RF) putParamset [list string $deviceAddress] [list string "MASTER"] [list struct $cmd]] } puts -nonewline {