summaryrefslogtreecommitdiffstats
path: root/config/notify_device
blob: c269147c55b3a3f75679672ef9879790fa99dd6a (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
#!/usr/bin/lua
socket = require("socket")
validator = require("acf.validator")

if not arg or #arg == 0 then
	print("Error - IP Address must be specified")
	return 1
end

local address = arg[1]
local user = arg[2] or ""
if not validator.is_ipv4(address) then
	print("Error - Invalid IP Address")
	return 1
end

local msg = "NOTIFY sip:"..user.."@"..address..":5060 SIP/2.0\n"..
"Via: SIP/2.0/UDP 127.0.0.1\n"..
"From: <sip:provisioning@127.0.0.1>\n"..
"To: <sip:"..user.."@"..address..">\n"..
"Event: check-sync\n"..
"Date: "..os.date().."\n"..
"Call-ID: "..os.time().."msgto0@"..address.."\n"..
"CSeq: 102 NOTIFY\n"..
"Contact: <sip:provisioning@127.0.0.1>\n"..
"Content-Length: 0\n\n"

local s = assert(socket.udp())
assert(s:sendto(msg, address, 5060))

if "" == user then
	msg = string.gsub(msg, "sip:", "sip:0")
	assert(s:sendto(msg, address, 5060))
end

s:close()