summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/phones/snom_vision.lua
blob: 7adace45366d97b8f4b7130c3b90d51c7fe3691e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Gemeinschaft 5 module: snom vision extension module model class
-- (c) AMOOMA GmbH 2012-2013
-- 

module(...,package.seeall)

SnomVision = {}

-- Create SnomVision object
function SnomVision.new(self, arg)
  arg = arg or {}
  object = arg.object or {}
  setmetatable(object, self);
  self.__index = self;
  self.log = arg.log;
  self.reboot = arg.reboot or true;
  self.class = 'snomvision';
  return object;
end

-- send reload message to module
function SnomVision.resync(self, arg)
  if arg.ip_address then
    return self:resync_http(arg.ip_address, arg.http_user, arg.http_password, arg.http_port);
  end

  return false;
end


function SnomVision.resync_http(self, ip_address, http_user, http_password, http_port)
  local port_str = '';
  if tonumber(http_port) then
    port_str = ':' .. http_port;
  end

  local command = 'http_request.lua snom_vision_resync http://' .. tostring(ip_address):gsub('[^0-9%.]', '') .. port_str .. '/ConfigurationModule/restart ' .. (http_user or '') .. ' ' .. (http_password or '');
  require 'common.fapi'
  return common.fapi.FApi:new():execute('luarun', command);
end