|
|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
-- This is a stripped down version of mod_vcard for returning
|
|
|
|
|
-- simply a vcard containing some info of
|
|
|
|
|
-- the requested user.
|
|
|
|
|
-- http://xmpp.org/extensions/xep-0054.html
|
|
|
|
|
--
|
|
|
|
|
-- This project is MIT/X11 licensed. Please see the
|
|
|
|
|
-- COPYING file in the source package for more information.
|
|
|
|
|
@ -20,27 +21,24 @@ SELECT bc.email, bccc.email FROM billing.voip_subscribers AS vs
|
|
|
|
|
LEFT join billing.contacts AS bc ON vs.contact_id = bc.id
|
|
|
|
|
LEFT join billing.contracts AS bcc ON vs.contract_id = bcc.id
|
|
|
|
|
LEFT join billing.contacts AS bccc ON bcc.contact_id = bccc.id
|
|
|
|
|
WHERE vs.username = ?
|
|
|
|
|
AND vs.domain_id = ?;
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
local account_id_query = [[
|
|
|
|
|
SELECT id, domain_id
|
|
|
|
|
FROM provisioning.voip_subscribers
|
|
|
|
|
WHERE username = ? AND
|
|
|
|
|
domain_id = ( SELECT id FROM provisioning.voip_domains where domain = ?);
|
|
|
|
|
LEFT join billing.domains AS bd ON vs.domain_id = bd.id
|
|
|
|
|
WHERE vs.username = ? AND bd.domain = ?;
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
local display_usr_query = [[
|
|
|
|
|
SELECT vp.attribute, vup.value FROM provisioning.voip_preferences vp
|
|
|
|
|
LEFT JOIN provisioning.voip_usr_preferences vup ON vup.attribute_id = vp.id
|
|
|
|
|
LEFT JOIN provisioning.voip_subscribers AS ps ON ps.id = vup.subscriber_id
|
|
|
|
|
LEFT JOIN provisioning.voip_domains AS pd ON ps.domain_id = pd.id
|
|
|
|
|
WHERE vp.attribute = 'display_name'
|
|
|
|
|
AND vup.subscriber_id = ?
|
|
|
|
|
AND ps.username = ? AND pd.domain = ?
|
|
|
|
|
]];
|
|
|
|
|
|
|
|
|
|
local aliases_query = [[
|
|
|
|
|
SELECT username FROM provisioning.voip_dbaliases
|
|
|
|
|
WHERE subscriber_id = ?;
|
|
|
|
|
SELECT pa.username FROM provisioning.voip_dbaliases AS pa
|
|
|
|
|
LEFT JOIN provisioning.voip_subscribers AS ps ON ps.id = pa.subscriber_id
|
|
|
|
|
LEFT JOIN provisioning.voip_domains AS pd ON ps.domain_id = pd.id
|
|
|
|
|
WHERE ps.username = ? AND pd.domain = ?;
|
|
|
|
|
]];
|
|
|
|
|
|
|
|
|
|
local mod_sql = module:require("sql");
|
|
|
|
|
@ -58,7 +56,6 @@ module:add_feature("vcard-temp");
|
|
|
|
|
|
|
|
|
|
local function get_subscriber_info(user, host)
|
|
|
|
|
local info = { user = user, domain = host, aliases = {} };
|
|
|
|
|
local subscriber_id, domain_id;
|
|
|
|
|
local row;
|
|
|
|
|
-- Reconnect to DB if necessary
|
|
|
|
|
if not engine.conn:ping() then
|
|
|
|
|
@ -66,30 +63,20 @@ local function get_subscriber_info(user, host)
|
|
|
|
|
engine:connect();
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for row in engine:select(account_id_query, user, host) do
|
|
|
|
|
subscriber_id = row[1];
|
|
|
|
|
domain_id = row[2];
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module:log("debug",
|
|
|
|
|
string.format("user:%s subscriber_id:%d domain_id:%d",
|
|
|
|
|
user, subscriber_id, domain_id
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
for row in engine:select(display_usr_query, subscriber_id) do
|
|
|
|
|
for row in engine:select(display_usr_query, user, host) do
|
|
|
|
|
info['display_name'] = row[2];
|
|
|
|
|
module:log("debug", string.format("display_name:[%s]", row[2]));
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for row in engine:select(aliases_query, subscriber_id) do
|
|
|
|
|
for row in engine:select(aliases_query, user, host) do
|
|
|
|
|
table.insert(info['aliases'], row[1]);
|
|
|
|
|
module:log("debug", string.format("aliases:%s", row[1]));
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for row in engine:select(email_query, user, domain_id) do
|
|
|
|
|
for row in engine:select(email_query, user, host) do
|
|
|
|
|
local email = row[1] or row[2];
|
|
|
|
|
if email then
|
|
|
|
|
table.insert(info['email'], email);
|
|
|
|
|
info['email'] = email;
|
|
|
|
|
module:log("debug", string.format("email:%s", row[1]));
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@ -101,9 +88,13 @@ local function generate_vcard(info)
|
|
|
|
|
local tmp = {
|
|
|
|
|
name = name,
|
|
|
|
|
attr = { xmlns = "vcard-temp" },
|
|
|
|
|
value
|
|
|
|
|
};
|
|
|
|
|
table.insert(t, tmp)
|
|
|
|
|
if value then table.insert(tmp, value) end
|
|
|
|
|
if t then
|
|
|
|
|
table.insert(t, tmp);
|
|
|
|
|
else
|
|
|
|
|
return tmp;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local vCard = {
|
|
|
|
|
name = "vCard",
|
|
|
|
|
@ -111,23 +102,26 @@ local function generate_vcard(info)
|
|
|
|
|
xmlns = "vcard-temp",
|
|
|
|
|
prodid = "-//HandGen//NONSGML vGen v1.0//EN",
|
|
|
|
|
version = "2.0"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "TEL",
|
|
|
|
|
attr = { xmlns = "vcard-temp" },
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
local uri = info["user"] .. '@' .. info["domain"];
|
|
|
|
|
local _,v;
|
|
|
|
|
local t,_,v;
|
|
|
|
|
|
|
|
|
|
add(vCard[1], "NUMBER", "sip:" .. uri);
|
|
|
|
|
add(vCard[1], "VIDEO", "sip:" .. uri);
|
|
|
|
|
t = add(nil, "NUMBER", "sip:" .. uri);
|
|
|
|
|
add(vCard, "TEL", t);
|
|
|
|
|
t = add(nil, "VIDEO", "sip:" .. uri);
|
|
|
|
|
add(vCard, "TEL", t);
|
|
|
|
|
for _,v in ipairs(info['aliases']) do
|
|
|
|
|
add(vCard[1], "NUMBER", v);
|
|
|
|
|
t = add(nil, "NUMBER", v);
|
|
|
|
|
add(vCard, "TEL", t);
|
|
|
|
|
end
|
|
|
|
|
if info['display_name'] then
|
|
|
|
|
add(vCard, "FN", info['display_name']);
|
|
|
|
|
end
|
|
|
|
|
if info['email'] then
|
|
|
|
|
t = add(nil, "USERID", info['email']);
|
|
|
|
|
add(vCard, "EMAIL", t);
|
|
|
|
|
end
|
|
|
|
|
return vCard;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -145,7 +139,9 @@ local function handle_vcard(event)
|
|
|
|
|
end
|
|
|
|
|
local info = get_subscriber_info(user, host);
|
|
|
|
|
local vCard = generate_vcard(info);
|
|
|
|
|
session.send(st.reply(stanza):add_child(st.deserialize(vCard)));
|
|
|
|
|
local reply = st.reply(stanza):add_child(st.deserialize(vCard));
|
|
|
|
|
--module:log("debug", tostring(reply));
|
|
|
|
|
session.send(reply);
|
|
|
|
|
else
|
|
|
|
|
module:log("debug", "reject setting vcard");
|
|
|
|
|
session.send(st.error_reply(stanza, "auth", "forbidden"));
|
|
|
|
|
|