diff --git a/addon/www/index.html b/addon/www/index.html new file mode 100644 index 0000000..533e979 --- /dev/null +++ b/addon/www/index.html @@ -0,0 +1,37 @@ + + + + + + + + + + + + + RaspberryMatic Update Addon + + + + + diff --git a/addon/www/rest.cgi b/addon/www/rest.cgi new file mode 100644 index 0000000..48fd8c9 --- /dev/null +++ b/addon/www/rest.cgi @@ -0,0 +1,69 @@ +#!/bin/tclsh + +# RaspMatic update addon +# +# Copyright (C) 2017 Jan Schneider +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +source /usr/local/addons/rmupdate/lib/rmupdate.tcl + +proc json_string {str} { + set replace_map { + "\"" "\\\"" + "\\" "\\\\" + "\b" "\\b" + "\f" "\\f" + "\n" "\\n" + "\r" "\\r" + "\t" "\\t" + } + return "[string map $replace_map $str]" +} + +proc process {} { + global env + if { [info exists env(QUERY_STRING)] } { + set query $env(QUERY_STRING) + set data "" + if { [info exists env(CONTENT_LENGTH)] } { + set data [read stdin $env(CONTENT_LENGTH)] + } + set path [split $query {/}] + set plen [expr [llength $path] - 1] + + if {[lindex $path 1] == "version"} { + return "\"[rmupdate::version]\"" + } elseif {[lindex $path 1] == "xy"} { + } + } + error "invalid request" "Not found" 404 +} + +if [catch {process} result] { + set status 500 + if { [info exists $errorCode] } { + set status $errorCode + } + puts "Content-Type: application/json" + puts "Status: $status"; + puts "" + set result [json_string $result] + puts -nonewline "\{\"error\":\"${result}\"\}" +} else { + puts "Content-Type: application/json" + puts "Status: 200 OK"; + puts "" + puts -nonewline $result +} diff --git a/addon/www/update.cgi b/addon/www/update.cgi new file mode 100644 index 0000000..809952b --- /dev/null +++ b/addon/www/update.cgi @@ -0,0 +1,31 @@ +#!/bin/tclsh + +# RaspMatic update addon +# +# Copyright (C) 2017 Jan Schneider +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set version_url "https://github.com/j-a-n/raspberrymatic-addon-hue/raw/master/VERSION" +set package_url "https://github.com/j-a-n/raspberrymatic-addon-hue/raw/master/rmupdate.tar.gz" + +set cmd "" +if {[info exists env(QUERY_STRING)]} { + regexp {cmd=([^&]+)} $env(QUERY_STRING) match cmd +} +if {$cmd == "download"} { + puts "" +} else { + puts [exec /usr/bin/wget -q --no-check-certificate -O- "${version_url}"] +}