From 1665567b1f54f5be346d7c2a72f6e2feecf5d6ae Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Wed, 20 Apr 2011 10:06:58 +0200 Subject: [PATCH] [luci] delete restful.lua from the luci package --- .../admin-mini/luasrc/controller/restful.lua | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/restful.lua diff --git a/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/restful.lua b/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/restful.lua deleted file mode 100644 index 9219e5f..0000000 --- a/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/restful.lua +++ /dev/null @@ -1,82 +0,0 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id: rpc.lua 5118 2009-07-23 03:32:30Z jow $ -]]-- - -module ("luci.controller.restful", package.seeall) - -function index() - local uci = require "luci.model.uci".cursor() - - if uci:get("flukso", "main", "localEnable") == "1" then - uci:foreach("flukso", "sensor", function(section) - entry({section.id}, call("rest_sensor", {section.id})) - end) - end -end - ---- Decode a URL query string --- @param QS the to-be-decoded query string --- @return table containing [name] = value pairs --- @see rest_sensor -local function decode(QS) - local param = {} - - for name, value in QS:gmatch("([^&=]+)=([^&=]+)") do - param[name] = value - end - - return param -end - ---- Return a 400 error code to the client --- @param message custom error message (optional) --- @return false -function error400(message) - local http = require "luci.http" - - http.status(400, "Bad Request") - message = message or "Bad Request" - - http.prepare_content("text/plain") - http.write(message) - - return false -end - ---- Callback function for Flukso RESTful API --- @param id requested sensor id (table) --- @return json-encoded time series data -function rest_sensor(id) - local http = require "luci.http" - local ltn12 = require "luci.ltn12" - local uci = require "luci.model.uci".cursor() - - local path = uci:get("flukso", "main", "localDir") - local version = uci:get("flukso", "main", "localVersion") - local param = decode(http.getenv("QUERY_STRING")) - - http.prepare_content("application/json") - - if param.interval == "minute" and param.unit == "watt" and param.version == version then - local source = ltn12.source.file(io.open(path .. "/" .. id[1], "r")) - - if param.jsonp_callback then - source = ltn12.source.cat(ltn12.source.string(param.jsonp_callback .. "("), source, ltn12.source.string(")")) - end - - ltn12.pump.all(source, http.write) - else - error400("Malformed query string: interval, unit and version query parameters are required.") - end -end