This commit is contained in:
Jan Schneider 2017-03-24 19:57:23 +01:00
parent 7c6ba94ea7
commit 9c3156f0f6
3 changed files with 137 additions and 0 deletions

37
addon/www/index.html Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<!--
RaspMatic update addon
Copyright (C) 2017 Jan Schneider <oss@janschneider.net>
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 <http://www.gnu.org/licenses/>.
-->
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css" integrity="sha256-wT6CFc7EKRuf7uyVfi+MQNHUzojuHN2pSw0YWFt2K5E=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.js" integrity="sha256-flVaeawsBV96vCHiLmXn03IRJym7+ZfcLVvUWONCas8=" crossorigin="anonymous"></script>
<style>
</style>
<title>RaspberryMatic Update Addon</title>
<script>
</script>
</head>
<body>
</body>
</html>

69
addon/www/rest.cgi Normal file
View File

@ -0,0 +1,69 @@
#!/bin/tclsh
# RaspMatic update addon
#
# Copyright (C) 2017 Jan Schneider <oss@janschneider.net>
#
# 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 <http://www.gnu.org/licenses/>.
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
}

31
addon/www/update.cgi Normal file
View File

@ -0,0 +1,31 @@
#!/bin/tclsh
# RaspMatic update addon
#
# Copyright (C) 2017 Jan Schneider <oss@janschneider.net>
#
# 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 <http://www.gnu.org/licenses/>.
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 "<html><head><meta http-equiv=\"refresh\" content=\"0; url=${package_url}\" /></head></html>"
} else {
puts [exec /usr/bin/wget -q --no-check-certificate -O- "${version_url}"]
}