Search code examples
ejabberd

Remove some options from room config MUC


When owner join and the room and open room config panel when few config options appears.

I want to remove some options from config panel like

  1. Maximum number of users > max limit is 200 but i want to set max limit to 30 and field is uneditable. (No one can change 30 limit)

    1. Pressence real Jids to - (Default is Moderator) i want to set default value is Everyone and field hidden.

    2. Roles of which presence is broadcast (Default is selected all). just want to hide this field. Nothing change.

    3. Make room moderated (just want to hide this field. Unchecked.)

    4. Default users as participant (just want to hide this field. Checked by default)

    5. Allow visitors to send status text in presence broadcast (Just want to hide this field. Unchecked)

    6. Allow visitor to change nickname (just want to hide this field. Unchecked)

    7. Allow visitor to send voice request (Just want to Uncheck and hide this field)

    8. Allow Subscribtion (Just want to Uncheck and hide this field)

I know these all modification will done in .erl file and i try to do but nothing happens. Can anyone know how to do this.

Please help.


Solution

  • As a server admin, you can set default room values in ejabberd.yml with this mod_muc option: default_room_options, see https://docs.ejabberd.im/admin/configuration/#mod-muc

    Then you have to modify mod_muc_room.erl to hide the field, and also to not use the options if a clever room owner adds them manually. Later you compile this file (or all ejabberd), and install the modified mod_muc_room.beam, overwritting the old one, and finally restart ejabberd. If you don't see the changes, maybe you copied the beam file to another place (maybe you have two ejabberd installed, one that is running and other that is old and is confusing you?).

    I think this change includes all the options you wanted, but better you verify, maybe I forgot some. I tried this change in ejabberd 18.09, and it hides several options in the room config formulary:

    diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
    index 267514b20..a6fc0e73f 100644
    --- a/src/mod_muc_room.erl
    +++ b/src/mod_muc_room.erl
    @@ -58,7 +58,7 @@
     -include("mod_muc_room.hrl").
    
     -define(MAX_USERS_DEFAULT_LIST,
    -   [5, 10, 20, 30, 50, 100, 200, 500, 1000, 2000, 5000]).
    +   [30]).
    
     -define(DEFAULT_MAX_USERS_PRESENCE,1000).
    
    @@ -3363,23 +3363,23 @@ get_config(Lang, StateData, From) ->
                         MaxUsersRoom
                         | ?MAX_USERS_DEFAULT_LIST]),
                   N =< ServiceMaxUsers]},
    -    {whois, if Config#config.anonymous -> moderators;
    -           true -> anyone
    -        end},
    -    {presencebroadcast, Config#config.presence_broadcast},
    +    %{whois, if Config#config.anonymous -> moderators;
    +   %       true -> anyone
    +   %    end},
    +    %{presencebroadcast, Config#config.presence_broadcast},
         {membersonly, Config#config.members_only},
    -    {moderatedroom, Config#config.moderated},
    -    {members_by_default, Config#config.members_by_default},
    +    %{moderatedroom, Config#config.moderated},
    +    %{members_by_default, Config#config.members_by_default},
         {changesubject, Config#config.allow_change_subj},
         {allow_private_messages, Config#config.allow_private_messages},
         {allow_private_messages_from_visitors,
          Config#config.allow_private_messages_from_visitors},
         {allow_query_users, Config#config.allow_query_users},
         {allowinvites, Config#config.allow_user_invites},
    -    {allow_visitor_status, Config#config.allow_visitor_status},
    -    {allow_visitor_nickchange, Config#config.allow_visitor_nickchange},
    -    {allow_voice_requests, Config#config.allow_voice_requests},
    -    {allow_subscription, Config#config.allow_subscription},
    +    %{allow_visitor_status, Config#config.allow_visitor_status},
    +    %{allow_visitor_nickchange, Config#config.allow_visitor_nickchange},
    +    %{allow_voice_requests, Config#config.allow_voice_requests},
    +    %{allow_subscription, Config#config.allow_subscription},
         {voice_request_min_interval, Config#config.voice_request_min_interval},
         {pubsub, Config#config.pubsub}]
        ++
    @@ -3440,27 +3440,27 @@ set_config(Opts, Config, ServerHost, Lang) ->
              C#config{allow_private_messages = V};
         ({allow_private_messages_from_visitors, V}, C) ->
              C#config{allow_private_messages_from_visitors = V};
    -    ({allow_visitor_status, V}, C) -> C#config{allow_visitor_status = V};
    -    ({allow_visitor_nickchange, V}, C) ->
    -         C#config{allow_visitor_nickchange = V};
    +    %({allow_visitor_status, V}, C) -> C#config{allow_visitor_status = V};
    +    %({allow_visitor_nickchange, V}, C) ->
    +         %C#config{allow_visitor_nickchange = V};
         ({publicroom, V}, C) -> C#config{public = V};
         ({public_list, V}, C) -> C#config{public_list = V};
         ({persistentroom, V}, C) -> C#config{persistent = V};
    -    ({moderatedroom, V}, C) -> C#config{moderated = V};
    -    ({members_by_default, V}, C) -> C#config{members_by_default = V};
    +    %({moderatedroom, V}, C) -> C#config{moderated = V};
    +    %({members_by_default, V}, C) -> C#config{members_by_default = V};
         ({membersonly, V}, C) -> C#config{members_only = V};
         ({captcha_protected, V}, C) -> C#config{captcha_protected = V};
         ({allowinvites, V}, C) -> C#config{allow_user_invites = V};
    -    ({allow_subscription, V}, C) -> C#config{allow_subscription = V};
    +    %({allow_subscription, V}, C) -> C#config{allow_subscription = V};
         ({passwordprotectedroom, V}, C) -> C#config{password_protected = V};
         ({roomsecret, V}, C) -> C#config{password = V};
         ({anonymous, V}, C) -> C#config{anonymous = V};
         ({presencebroadcast, V}, C) -> C#config{presence_broadcast = V};
    -    ({allow_voice_requests, V}, C) -> C#config{allow_voice_requests = V};
    +    %({allow_voice_requests, V}, C) -> C#config{allow_voice_requests = V};
         ({voice_request_min_interval, V}, C) ->
              C#config{voice_request_min_interval = V};
    -    ({whois, moderators}, C) -> C#config{anonymous = true};
    -    ({whois, anyone}, C) -> C#config{anonymous = false};
    +    %({whois, moderators}, C) -> C#config{anonymous = true};
    +    %({whois, anyone}, C) -> C#config{anonymous = false};
         ({maxusers, V}, C) -> C#config{max_users = V};
         ({enablelogging, V}, C) -> C#config{logging = V};
         ({pubsub, V}, C) -> C#config{pubsub = V};
    

    There's an option that disallows visitors to change nickname. If you want this option to also disallow participants, apply this change:

    diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
    index 267514b20..16ce21ba1 100644
    --- a/src/mod_muc_room.erl
    +++ b/src/mod_muc_room.erl
    @@ -1031,7 +1031,7 @@ do_process_presence(Nick, #presence{from = From, type = available, lang = Lang}
                               StateData#state.host,
                               From, Nick),
                  {(StateData#state.config)#config.allow_visitor_nickchange,
    -              is_visitor(From, StateData)}} of
    +              is_visitor_or_participant(From, StateData)}} of
                {_, _, {false, true}} ->
                    Packet1 = Packet#presence{sub_els = [#muc{}]},
                    ErrText = <<"Visitors are not allowed to change their "
    @@ -1501,6 +1501,11 @@ get_default_role(Affiliation, StateData) ->
     is_visitor(Jid, StateData) ->
         get_role(Jid, StateData) =:= visitor.
    
    +is_visitor_or_participant(Jid, StateData) ->
    +    (get_role(Jid, StateData) =:= visitor)
    +    or
    +    (get_role(Jid, StateData) =:= participant).
    +
     -spec is_moderator(jid(), state()) -> boolean().
     is_moderator(Jid, StateData) ->
         get_role(Jid, StateData) =:= moderator.
    

    On the other hand, if you want to disallow all roles to change the nick, the change is smaller:

    diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
    index 267514b20..2ef75e6ed 100644
    --- a/src/mod_muc_room.erl
    +++ b/src/mod_muc_room.erl
    @@ -1032,7 +1032,7 @@ do_process_presence(Nick, #presence{from = From, type = available, lang = Lang}
                           From, Nick),
                  {(StateData#state.config)#config.allow_visitor_nickchange,
                   is_visitor(From, StateData)}} of
    -           {_, _, {false, true}} ->
    +           {_, _, {false, _}} ->
                Packet1 = Packet#presence{sub_els = [#muc{}]},
                ErrText = <<"Visitors are not allowed to change their "
                        "nicknames in this room">>,