Prevent custom sip port from breaking provision.lua and add prevent nil concatenation errors.
This commit is contained in:
@@ -75,31 +75,40 @@
|
|||||||
--get the user and domain name from the user argv user@domain
|
--get the user and domain name from the user argv user@domain
|
||||||
sip_from_uri = session:getVariable("sip_from_uri");
|
sip_from_uri = session:getVariable("sip_from_uri");
|
||||||
user_table = explode("@",sip_from_uri);
|
user_table = explode("@",sip_from_uri);
|
||||||
|
domain_table = explode(":",user_table[2]);
|
||||||
user = user_table[1];
|
user = user_table[1];
|
||||||
domain = user_table[2];
|
domain = domain_table[1];
|
||||||
|
|
||||||
--show the phone that will be overridden
|
--show the phone that will be overridden
|
||||||
freeswitch.consoleLog("NOTICE", "[provision] sip_from_uri: ".. sip_from_uri .. "\n");
|
if (sip_from_uri ~= nil) then
|
||||||
freeswitch.consoleLog("NOTICE", "[provision] user: ".. user .. "\n");
|
freeswitch.consoleLog("NOTICE", "[provision] sip_from_uri: ".. sip_from_uri .. "\n");
|
||||||
freeswitch.consoleLog("NOTICE", "[provision] domain: ".. domain .. "\n");
|
end
|
||||||
|
if (user ~= nil) then
|
||||||
|
freeswitch.consoleLog("NOTICE", "[provision] user: ".. user .. "\n");
|
||||||
|
end
|
||||||
|
if (domain ~= nil) then
|
||||||
|
freeswitch.consoleLog("NOTICE", "[provision] domain: ".. domain .. "\n");
|
||||||
|
end
|
||||||
|
|
||||||
--get the device uuid for the phone that will have its configuration overridden
|
--get the device uuid for the phone that will have its configuration overridden
|
||||||
sql = [[SELECT * FROM v_device_lines ]];
|
if (user ~= nil and domain ~= nil and domain_uuid ~= nil) then
|
||||||
sql = sql .. [[WHERE user_id = ']] .. user .. [[' ]];
|
sql = [[SELECT * FROM v_device_lines ]];
|
||||||
sql = sql .. [[AND server_address = ']]..domain..[[' ]];
|
sql = sql .. [[WHERE user_id = ']] .. user .. [[' ]];
|
||||||
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
sql = sql .. [[AND server_address = ']]..domain..[[' ]];
|
||||||
if (debug["sql"]) then
|
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
||||||
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
|
if (debug["sql"]) then
|
||||||
end
|
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
|
||||||
dbh:query(sql, function(row)
|
end
|
||||||
--get device uuid
|
dbh:query(sql, function(row)
|
||||||
|
--get device uuid
|
||||||
device_uuid = row.device_uuid;
|
device_uuid = row.device_uuid;
|
||||||
freeswitch.consoleLog("NOTICE", "[provision] device_uuid: ".. device_uuid .. "\n");
|
freeswitch.consoleLog("NOTICE", "[provision] device_uuid: ".. device_uuid .. "\n");
|
||||||
end);
|
end);
|
||||||
|
end
|
||||||
|
|
||||||
--get the alternate device uuid using the device username and password
|
--get the alternate device uuid using the device username and password
|
||||||
authorized = 'false';
|
authorized = 'false';
|
||||||
if (user_id ~= '' and password ~= '') then
|
if (user_id ~= nil and password ~= nil and domain_uuid ~= nil) then
|
||||||
sql = [[SELECT * FROM v_devices ]];
|
sql = [[SELECT * FROM v_devices ]];
|
||||||
sql = sql .. [[WHERE device_username = ']]..user_id..[[' ]];
|
sql = sql .. [[WHERE device_username = ']]..user_id..[[' ]];
|
||||||
sql = sql .. [[AND device_password = ']]..password..[[' ]]
|
sql = sql .. [[AND device_password = ']]..password..[[' ]]
|
||||||
@@ -122,7 +131,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
--this device already has an alternate find the correct device_uuid and then override current one
|
--this device already has an alternate find the correct device_uuid and then override current one
|
||||||
if (authorized == 'true' and action == "login" and device_uuid_alternate ~= nil) then
|
if (authorized == 'true' and action == "login" and device_uuid_alternate ~= nil and device_uuid ~= nil and domain_uuid ~= nil) then
|
||||||
sql = [[SELECT * FROM v_devices ]];
|
sql = [[SELECT * FROM v_devices ]];
|
||||||
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]];
|
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]];
|
||||||
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
||||||
@@ -137,7 +146,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
--remove the alternate device from another device so that it can be added to this device
|
--remove the alternate device from another device so that it can be added to this device
|
||||||
if (authorized == 'true' and action == "login") then
|
if (authorized == 'true' and action == "login" and device_uuid_alternate ~= nil and domain_uuid ~= nil) then
|
||||||
sql = [[SELECT * FROM v_device_lines ]];
|
sql = [[SELECT * FROM v_device_lines ]];
|
||||||
sql = sql .. [[WHERE device_uuid = ']]..device_uuid_alternate..[[' ]];
|
sql = sql .. [[WHERE device_uuid = ']]..device_uuid_alternate..[[' ]];
|
||||||
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
||||||
@@ -170,7 +179,7 @@
|
|||||||
|
|
||||||
--add the override to the device uuid (login)
|
--add the override to the device uuid (login)
|
||||||
if (authorized == 'true' and action == "login") then
|
if (authorized == 'true' and action == "login") then
|
||||||
if (device_uuid_alternate ~= nil) then
|
if (device_uuid_alternate ~= nil and device_uuid ~= nil and domain_uuid ~= nil) then
|
||||||
--send a hangup
|
--send a hangup
|
||||||
session:hangup();
|
session:hangup();
|
||||||
--add the new alternate
|
--add the new alternate
|
||||||
@@ -186,7 +195,7 @@
|
|||||||
|
|
||||||
--remove the override to the device uuid (logout)
|
--remove the override to the device uuid (logout)
|
||||||
if (authorized == 'true' and action == "logout") then
|
if (authorized == 'true' and action == "logout") then
|
||||||
if (device_uuid_alternate ~= nil) then
|
if (device_uuid_alternate ~= nil and device_uuid ~= nil and domain_uuid ~= nil) then
|
||||||
sql = [[UPDATE v_devices SET device_uuid_alternate = null ]];
|
sql = [[UPDATE v_devices SET device_uuid_alternate = null ]];
|
||||||
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]];
|
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]];
|
||||||
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
|
||||||
|
|||||||
Reference in New Issue
Block a user