mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
ODBC support for mod_shared_roster
This commit is contained in:
parent
5fab00011e
commit
41a0eae0bd
@ -98,6 +98,7 @@
|
|||||||
\newcommand{\modrosterodbc}{\module{mod\_roster\_odbc}}
|
\newcommand{\modrosterodbc}{\module{mod\_roster\_odbc}}
|
||||||
\newcommand{\modservicelog}{\module{mod\_service\_log}}
|
\newcommand{\modservicelog}{\module{mod\_service\_log}}
|
||||||
\newcommand{\modsharedroster}{\module{mod\_shared\_roster}}
|
\newcommand{\modsharedroster}{\module{mod\_shared\_roster}}
|
||||||
|
\newcommand{\modsharedrosterodbc}{\module{mod\_shared\_roster\_odbc}}
|
||||||
\newcommand{\modsharedrosterldap}{\module{mod\_shared\_roster\_ldap}}
|
\newcommand{\modsharedrosterldap}{\module{mod\_shared\_roster\_ldap}}
|
||||||
\newcommand{\modsic}{\module{mod\_sic}}
|
\newcommand{\modsic}{\module{mod\_sic}}
|
||||||
\newcommand{\modstats}{\module{mod\_stats}}
|
\newcommand{\modstats}{\module{mod\_stats}}
|
||||||
@ -2616,6 +2617,8 @@ The following table lists all modules included in \ejabberd{}.
|
|||||||
\hline \ahrefloc{modservicelog}{\modservicelog{}} & Copy user messages to logger service & \\
|
\hline \ahrefloc{modservicelog}{\modservicelog{}} & Copy user messages to logger service & \\
|
||||||
\hline \ahrefloc{modsharedroster}{\modsharedroster{}} & Shared roster management & \modroster{} or \\
|
\hline \ahrefloc{modsharedroster}{\modsharedroster{}} & Shared roster management & \modroster{} or \\
|
||||||
& & \modrosterodbc\\
|
& & \modrosterodbc\\
|
||||||
|
\hline \ahrefloc{modsharedroster}{\modsharedrosterodbc{}} & Shared roster management & supported DB (*) and\\
|
||||||
|
& & \modroster{} or \modrosterodbc\\
|
||||||
\hline \ahrefloc{modsharedrosterldap}{\modsharedrosterldap{}} & LDAP Shared roster management & \modroster{} or \\
|
\hline \ahrefloc{modsharedrosterldap}{\modsharedrosterldap{}} & LDAP Shared roster management & \modroster{} or \\
|
||||||
& & \modrosterodbc\\
|
& & \modrosterodbc\\
|
||||||
\hline \ahrefloc{modsic}{\modsic{}} & Server IP Check (\xepref{0279}) & \\
|
\hline \ahrefloc{modsic}{\modsic{}} & Server IP Check (\xepref{0279}) & \\
|
||||||
@ -2656,6 +2659,7 @@ database for the following data:
|
|||||||
\item Offline messages: Use \term{mod\_offline\_odbc} instead of
|
\item Offline messages: Use \term{mod\_offline\_odbc} instead of
|
||||||
\term{mod\_offline}.
|
\term{mod\_offline}.
|
||||||
\item Rosters: Use \term{mod\_roster\_odbc} instead of \term{mod\_roster}.
|
\item Rosters: Use \term{mod\_roster\_odbc} instead of \term{mod\_roster}.
|
||||||
|
\item Shared Rosters: Use \term{mod\_shared\_roster\_odbc} instead of \term{mod\_shared\_roster}.
|
||||||
\item Users' VCARD: Use \term{mod\_vcard\_odbc} instead of \term{mod\_vcard}.
|
\item Users' VCARD: Use \term{mod\_vcard\_odbc} instead of \term{mod\_vcard}.
|
||||||
\item vCard-Based Avatars: Use \term{mod\_vcard\_xupdate\_odbc} instead of \term{mod\_vcard\_xupdate}.
|
\item vCard-Based Avatars: Use \term{mod\_vcard\_xupdate\_odbc} instead of \term{mod\_vcard\_xupdate}.
|
||||||
\item Private XML storage: Use \term{mod\_private\_odbc} instead of \term{mod\_private}.
|
\item Private XML storage: Use \term{mod\_private\_odbc} instead of \term{mod\_private}.
|
||||||
@ -4062,7 +4066,7 @@ Options:
|
|||||||
This option does not affect the client in any way.
|
This option does not affect the client in any way.
|
||||||
This option is only useful if Roster Versioning is enabled.
|
This option is only useful if Roster Versioning is enabled.
|
||||||
This option is disabled by default.
|
This option is disabled by default.
|
||||||
Important: if you use \modsharedroster{} or \modsharedrosterldap{},
|
Important: if you use \modsharedroster{}, \modsharedrosterodbc{} or \modsharedrosterldap{},
|
||||||
you must disable this option.
|
you must disable this option.
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
||||||
|
14
src/acl.erl
14
src/acl.erl
@ -181,9 +181,11 @@ match_acl(ACL, JID, Host) ->
|
|||||||
lists:member(Server, ?MYHOSTS)))
|
lists:member(Server, ?MYHOSTS)))
|
||||||
andalso is_regexp_match(User, UR);
|
andalso is_regexp_match(User, UR);
|
||||||
{shared_group, G} ->
|
{shared_group, G} ->
|
||||||
mod_shared_roster:is_user_in_group({User, Server}, G, Host);
|
Mod = loaded_shared_roster_module(Host),
|
||||||
|
Mod:is_user_in_group({User, Server}, G, Host);
|
||||||
{shared_group, G, H} ->
|
{shared_group, G, H} ->
|
||||||
mod_shared_roster:is_user_in_group({User, Server}, G, H);
|
Mod = loaded_shared_roster_module(H),
|
||||||
|
Mod:is_user_in_group({User, Server}, G, H);
|
||||||
{user_regexp, UR, S} ->
|
{user_regexp, UR, S} ->
|
||||||
(S == Server) andalso
|
(S == Server) andalso
|
||||||
is_regexp_match(User, UR);
|
is_regexp_match(User, UR);
|
||||||
@ -238,4 +240,10 @@ is_regexp_match(String, RegExp) ->
|
|||||||
is_glob_match(String, Glob) ->
|
is_glob_match(String, Glob) ->
|
||||||
is_regexp_match(String, ejabberd_regexp:sh_to_awk(Glob)).
|
is_regexp_match(String, ejabberd_regexp:sh_to_awk(Glob)).
|
||||||
|
|
||||||
|
loaded_shared_roster_module(Host) ->
|
||||||
|
case {gen_mod:is_loaded(Host, mod_shared_roster_odbc),
|
||||||
|
gen_mod:is_loaded(Host, mod_shared_roster_ldap)} of
|
||||||
|
{true, _} -> mod_shared_roster_odbc;
|
||||||
|
{_, true} -> mod_shared_roster_ldap;
|
||||||
|
_ -> mod_shared_roster
|
||||||
|
end.
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
export_motd/2,
|
export_motd/2,
|
||||||
export_motd_users/2,
|
export_motd_users/2,
|
||||||
export_irc_custom/2,
|
export_irc_custom/2,
|
||||||
|
export_sr_group/2,
|
||||||
|
export_sr_user/2,
|
||||||
export_muc_room/2,
|
export_muc_room/2,
|
||||||
export_muc_registered/2]).
|
export_muc_registered/2]).
|
||||||
|
|
||||||
@ -70,6 +72,8 @@
|
|||||||
-record(irc_custom, {us_host, data}).
|
-record(irc_custom, {us_host, data}).
|
||||||
-record(muc_room, {name_host, opts}).
|
-record(muc_room, {name_host, opts}).
|
||||||
-record(muc_registered, {us_host, nick}).
|
-record(muc_registered, {us_host, nick}).
|
||||||
|
-record(sr_group, {group_host, opts}).
|
||||||
|
-record(sr_user, {us, group_host}).
|
||||||
-record(motd, {server, packet}).
|
-record(motd, {server, packet}).
|
||||||
-record(motd_users, {us, dummy = []}).
|
-record(motd_users, {us, dummy = []}).
|
||||||
|
|
||||||
@ -397,6 +401,38 @@ export_privacy(Server, Output) ->
|
|||||||
[]
|
[]
|
||||||
end).
|
end).
|
||||||
|
|
||||||
|
export_sr_group(Server, Output) ->
|
||||||
|
export_common(
|
||||||
|
Server, sr_group, Output,
|
||||||
|
fun(Host, #sr_group{group_host = {Group, LServer}, opts = Opts})
|
||||||
|
when LServer == Host ->
|
||||||
|
SGroup = ejabberd_odbc:escape(Group),
|
||||||
|
SOpts = mod_shared_roster_odbc:encode_opts(Opts),
|
||||||
|
["delete from sr_group where name='", Group, "';"
|
||||||
|
"insert into sr_group(name, opts) values ('",
|
||||||
|
SGroup, "', '", SOpts, "');"];
|
||||||
|
(_Host, _R) ->
|
||||||
|
[]
|
||||||
|
end).
|
||||||
|
|
||||||
|
export_sr_user(Server, Output) ->
|
||||||
|
export_common(
|
||||||
|
Server, sr_user, Output,
|
||||||
|
fun(Host, #sr_user{us = {U, S}, group_host = {Group, LServer}})
|
||||||
|
when LServer == Host ->
|
||||||
|
SGroup = ejabberd_odbc:escape(Group),
|
||||||
|
SJID = ejabberd_odbc:escape(
|
||||||
|
jlib:jid_to_string(
|
||||||
|
jlib:jid_tolower(
|
||||||
|
jlib:make_jid(U, S, "")))),
|
||||||
|
["delete from sr_user where jid='", SJID,
|
||||||
|
"'and grp='", Group, "';"
|
||||||
|
"insert into sr_user(jid, grp) values ('",
|
||||||
|
SJID, "', '", SGroup, "');"];
|
||||||
|
(_Host, _R) ->
|
||||||
|
[]
|
||||||
|
end).
|
||||||
|
|
||||||
export_motd(Server, Output) ->
|
export_motd(Server, Output) ->
|
||||||
export_common(
|
export_common(
|
||||||
Server, motd, Output,
|
Server, motd, Output,
|
||||||
|
@ -186,7 +186,7 @@ get_vcard_module(Server) ->
|
|||||||
get_rosteritem_name([], _, _) ->
|
get_rosteritem_name([], _, _) ->
|
||||||
"";
|
"";
|
||||||
get_rosteritem_name([ModVcard], U, S) ->
|
get_rosteritem_name([ModVcard], U, S) ->
|
||||||
From = jlib:make_jid("", S, mod_shared_roster),
|
From = jlib:make_jid("", S, ?MODULE),
|
||||||
To = jlib:make_jid(U, S, ""),
|
To = jlib:make_jid(U, S, ""),
|
||||||
IQ = {iq,"",get,"vcard-temp","",
|
IQ = {iq,"",get,"vcard-temp","",
|
||||||
{xmlelement,"vCard",[{"xmlns","vcard-temp"}],[]}},
|
{xmlelement,"vCard",[{"xmlns","vcard-temp"}],[]}},
|
||||||
@ -619,14 +619,14 @@ add_user_to_group(Host, US, Group) ->
|
|||||||
{LUser, LServer} = US,
|
{LUser, LServer} = US,
|
||||||
case ejabberd_regexp:run(LUser, "^@.+@$") of
|
case ejabberd_regexp:run(LUser, "^@.+@$") of
|
||||||
match ->
|
match ->
|
||||||
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
|
GroupOpts = ?MODULE:get_group_opts(Host, Group),
|
||||||
MoreGroupOpts =
|
MoreGroupOpts =
|
||||||
case LUser of
|
case LUser of
|
||||||
"@all@" -> [{all_users, true}];
|
"@all@" -> [{all_users, true}];
|
||||||
"@online@" -> [{online_users, true}];
|
"@online@" -> [{online_users, true}];
|
||||||
_ -> []
|
_ -> []
|
||||||
end,
|
end,
|
||||||
mod_shared_roster:set_group_opts(
|
?MODULE:set_group_opts(
|
||||||
Host, Group,
|
Host, Group,
|
||||||
GroupOpts ++ MoreGroupOpts);
|
GroupOpts ++ MoreGroupOpts);
|
||||||
nomatch ->
|
nomatch ->
|
||||||
@ -652,7 +652,7 @@ remove_user_from_group(Host, US, Group) ->
|
|||||||
{LUser, LServer} = US,
|
{LUser, LServer} = US,
|
||||||
case ejabberd_regexp:run(LUser, "^@.+@$") of
|
case ejabberd_regexp:run(LUser, "^@.+@$") of
|
||||||
match ->
|
match ->
|
||||||
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
|
GroupOpts = ?MODULE:get_group_opts(Host, Group),
|
||||||
NewGroupOpts =
|
NewGroupOpts =
|
||||||
case LUser of
|
case LUser of
|
||||||
"@all@" ->
|
"@all@" ->
|
||||||
@ -660,7 +660,7 @@ remove_user_from_group(Host, US, Group) ->
|
|||||||
"@online@" ->
|
"@online@" ->
|
||||||
lists:filter(fun(X) -> X/={online_users,true} end, GroupOpts)
|
lists:filter(fun(X) -> X/={online_users,true} end, GroupOpts)
|
||||||
end,
|
end,
|
||||||
mod_shared_roster:set_group_opts(Host, Group, NewGroupOpts);
|
?MODULE:set_group_opts(Host, Group, NewGroupOpts);
|
||||||
nomatch ->
|
nomatch ->
|
||||||
R = #sr_user{us = US, group_host = GroupHost},
|
R = #sr_user{us = US, group_host = GroupHost},
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
@ -876,7 +876,7 @@ webadmin_page(Acc, _, _) -> Acc.
|
|||||||
|
|
||||||
list_shared_roster_groups(Host, Query, Lang) ->
|
list_shared_roster_groups(Host, Query, Lang) ->
|
||||||
Res = list_sr_groups_parse_query(Host, Query),
|
Res = list_sr_groups_parse_query(Host, Query),
|
||||||
SRGroups = mod_shared_roster:list_groups(Host),
|
SRGroups = ?MODULE:list_groups(Host),
|
||||||
FGroups =
|
FGroups =
|
||||||
?XAE("table", [],
|
?XAE("table", [],
|
||||||
[?XE("tbody",
|
[?XE("tbody",
|
||||||
@ -925,19 +925,19 @@ list_sr_groups_parse_query(Host, Query) ->
|
|||||||
list_sr_groups_parse_addnew(Host, Query) ->
|
list_sr_groups_parse_addnew(Host, Query) ->
|
||||||
case lists:keysearch("namenew", 1, Query) of
|
case lists:keysearch("namenew", 1, Query) of
|
||||||
{value, {_, Group}} when Group /= "" ->
|
{value, {_, Group}} when Group /= "" ->
|
||||||
mod_shared_roster:create_group(Host, Group),
|
?MODULE:create_group(Host, Group),
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
list_sr_groups_parse_delete(Host, Query) ->
|
list_sr_groups_parse_delete(Host, Query) ->
|
||||||
SRGroups = mod_shared_roster:list_groups(Host),
|
SRGroups = ?MODULE:list_groups(Host),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Group) ->
|
fun(Group) ->
|
||||||
case lists:member({"selected", Group}, Query) of
|
case lists:member({"selected", Group}, Query) of
|
||||||
true ->
|
true ->
|
||||||
mod_shared_roster:delete_group(Host, Group);
|
?MODULE:delete_group(Host, Group);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
@ -947,14 +947,14 @@ list_sr_groups_parse_delete(Host, Query) ->
|
|||||||
|
|
||||||
shared_roster_group(Host, Group, Query, Lang) ->
|
shared_roster_group(Host, Group, Query, Lang) ->
|
||||||
Res = shared_roster_group_parse_query(Host, Group, Query),
|
Res = shared_roster_group_parse_query(Host, Group, Query),
|
||||||
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
|
GroupOpts = ?MODULE:get_group_opts(Host, Group),
|
||||||
Name = get_opt(GroupOpts, name, ""),
|
Name = get_opt(GroupOpts, name, ""),
|
||||||
Description = get_opt(GroupOpts, description, ""),
|
Description = get_opt(GroupOpts, description, ""),
|
||||||
AllUsers = get_opt(GroupOpts, all_users, false),
|
AllUsers = get_opt(GroupOpts, all_users, false),
|
||||||
OnlineUsers = get_opt(GroupOpts, online_users, false),
|
OnlineUsers = get_opt(GroupOpts, online_users, false),
|
||||||
%%Disabled = false,
|
%%Disabled = false,
|
||||||
DisplayedGroups = get_opt(GroupOpts, displayed_groups, []),
|
DisplayedGroups = get_opt(GroupOpts, displayed_groups, []),
|
||||||
Members = mod_shared_roster:get_group_explicit_users(Host, Group),
|
Members = ?MODULE:get_group_explicit_users(Host, Group),
|
||||||
FMembers =
|
FMembers =
|
||||||
if
|
if
|
||||||
AllUsers ->
|
AllUsers ->
|
||||||
@ -1042,7 +1042,7 @@ shared_roster_group_parse_query(Host, Group, Query) ->
|
|||||||
true -> [{displayed_groups, DispGroups}]
|
true -> [{displayed_groups, DispGroups}]
|
||||||
end,
|
end,
|
||||||
|
|
||||||
OldMembers = mod_shared_roster:get_group_explicit_users(
|
OldMembers = ?MODULE:get_group_explicit_users(
|
||||||
Host, Group),
|
Host, Group),
|
||||||
SJIDs = string:tokens(SMembers, ", \r\n"),
|
SJIDs = string:tokens(SMembers, ", \r\n"),
|
||||||
NewMembers =
|
NewMembers =
|
||||||
@ -1074,7 +1074,7 @@ shared_roster_group_parse_query(Host, Group, Query) ->
|
|||||||
false -> []
|
false -> []
|
||||||
end,
|
end,
|
||||||
|
|
||||||
mod_shared_roster:set_group_opts(
|
?MODULE:set_group_opts(
|
||||||
Host, Group,
|
Host, Group,
|
||||||
NameOpt ++ DispGroupsOpt ++ DescriptionOpt ++ AllUsersOpt ++ OnlineUsersOpt),
|
NameOpt ++ DispGroupsOpt ++ DescriptionOpt ++ AllUsersOpt ++ OnlineUsersOpt),
|
||||||
|
|
||||||
@ -1085,12 +1085,12 @@ shared_roster_group_parse_query(Host, Group, Query) ->
|
|||||||
RemovedMembers = OldMembers -- NewMembers,
|
RemovedMembers = OldMembers -- NewMembers,
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(US) ->
|
fun(US) ->
|
||||||
mod_shared_roster:remove_user_from_group(
|
?MODULE:remove_user_from_group(
|
||||||
Host, US, Group)
|
Host, US, Group)
|
||||||
end, RemovedMembers),
|
end, RemovedMembers),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(US) ->
|
fun(US) ->
|
||||||
mod_shared_roster:add_user_to_group(
|
?MODULE:add_user_to_group(
|
||||||
Host, US, Group)
|
Host, US, Group)
|
||||||
end, AddedMembers),
|
end, AddedMembers),
|
||||||
ok
|
ok
|
||||||
|
1197
src/mod_shared_roster_odbc.erl
Normal file
1197
src/mod_shared_roster_odbc.erl
Normal file
File diff suppressed because it is too large
Load Diff
@ -59,6 +59,21 @@ CREATE TABLE rostergroups (
|
|||||||
|
|
||||||
CREATE INDEX pk_rosterg_user_jid ON rostergroups(username(75), jid(75));
|
CREATE INDEX pk_rosterg_user_jid ON rostergroups(username(75), jid(75));
|
||||||
|
|
||||||
|
CREATE TABLE sr_group (
|
||||||
|
name varchar(250) NOT NULL,
|
||||||
|
opts text NOT NULL,
|
||||||
|
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) CHARACTER SET utf8;
|
||||||
|
|
||||||
|
CREATE TABLE sr_user (
|
||||||
|
jid varchar(250) NOT NULL,
|
||||||
|
grp varchar(250) NOT NULL,
|
||||||
|
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) CHARACTER SET utf8;
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX i_sr_user_jid_group ON sr_user(jid(75), grp(75));
|
||||||
|
CREATE INDEX i_sr_user_jid ON sr_user(jid);
|
||||||
|
CREATE INDEX i_sr_user_grp ON sr_user(grp);
|
||||||
|
|
||||||
CREATE TABLE spool (
|
CREATE TABLE spool (
|
||||||
username varchar(250) NOT NULL,
|
username varchar(250) NOT NULL,
|
||||||
|
@ -57,6 +57,21 @@ CREATE TABLE rostergroups (
|
|||||||
|
|
||||||
CREATE INDEX pk_rosterg_user_jid ON rostergroups USING btree (username, jid);
|
CREATE INDEX pk_rosterg_user_jid ON rostergroups USING btree (username, jid);
|
||||||
|
|
||||||
|
CREATE TABLE sr_group (
|
||||||
|
name text NOT NULL,
|
||||||
|
opts text NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE sr_user (
|
||||||
|
jid text NOT NULL,
|
||||||
|
grp text NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX i_sr_user_jid_grp ON sr_user USING btree (jid, grp);
|
||||||
|
CREATE INDEX i_sr_user_jid ON sr_user USING btree (jid);
|
||||||
|
CREATE INDEX i_sr_user_grp ON sr_user USING btree (grp);
|
||||||
|
|
||||||
CREATE TABLE spool (
|
CREATE TABLE spool (
|
||||||
username text NOT NULL,
|
username text NOT NULL,
|
||||||
|
Loading…
Reference in New Issue
Block a user