diff options
author | Ted Trask <ttrask01@yahoo.com> | 2011-10-11 14:37:08 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2011-10-11 14:37:08 +0000 |
commit | 6b6de1fd8e91f2fe812db929fea4bef9d1224585 (patch) | |
tree | 5acabf997347d5954371a4dd840d82867423704f /provisioning-model.lua | |
parent | 933d3b99ff2dbc9da92f7e6327b9e4c58c33df79 (diff) | |
download | acf-provisioning-6b6de1fd8e91f2fe812db929fea4bef9d1224585.tar.bz2 acf-provisioning-6b6de1fd8e91f2fe812db929fea4bef9d1224585.tar.xz |
Implemented put_file for Polycom phones
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r-- | provisioning-model.lua | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua index 16bfd15..da39fb1 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -223,12 +223,8 @@ validateparam = function(p) end -- These are the functions that may be called from within loaded Lua code -local functions = { - getselectresponse=getselectresponse, - runsqlcommand=runsqlcommand, - get_device=get_device, - get_device_params=get_device_params, -} +-- The actual functions are added at the end of the file, after they're declared +local functions = {} local validateparamcoded validateparamcoded = function(p, top) @@ -264,7 +260,7 @@ validateparamcoded = function(p, top) end local function callscript(script, ...) - local result + local result, errtxt local env = {} setmetatable (env, {__index = _G}) -- loadfile loads into the global environment @@ -273,14 +269,14 @@ local function callscript(script, ...) local f = loadfile(script) if f then local res, err = pcall(function(...) - result = f(functions, ...) + result, errtxt = f(functions, ...) end, ...) if not res and err then assert(res, "Exception in "..script.." script\n"..err) end end setfenv (0, _G) - return result + return result, errtxt end local function validateluacode(code) @@ -1915,11 +1911,32 @@ end function put_file(mac, data) local retval = cfe({ label="PUT Data" }) + + -- Error if there's no mac + if not mac or mac == "" then + retval.errtxt = "No MAC Address" + return retval + end + local res, err = pcall(function() local connected = databaseconnect() - retval.value, retval.errtxt = callscript(processputscriptfile, mac, data) - -- If the script doesn't exist, allow the write - retval.value = retval.value or data + + -- Now, let's see if this device exists + local search = get_search_options() + search.value.id.value = "device.mac" + search.value.value.value = string.upper(mac) + search = search_device_values(search) + if search.errtxt then + retval.errtxt = search.errtxt + elseif #search.value.result.value == 0 then + retval.errtxt = "Device not found" + elseif #search.value.result.value > 1 then + retval.errtxt = "Multiple devices found" + else + retval.value, retval.errtxt = callscript(processputscriptfile, mac, data, search.value.result.value[1].device_id) + -- If the script doesn't exist, allow the write + retval.value = retval.value or data + end if connected then databasedisconnect() end end) if not res and err then @@ -1927,3 +1944,12 @@ function put_file(mac, data) end return retval end + +-- The functions must be added after they're declared +functions = { + getselectresponse=getselectresponse, + runsqlcommand=runsqlcommand, + get_device=get_device, + get_device_params=get_device_params, + set_device_params=set_device_params, +} |