Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use commands in WebAdmin to generate page content #4228

Merged
merged 13 commits into from
Jun 19, 2024

Conversation

badlop
Copy link
Member

@badlop badlop commented Jun 4, 2024

This PR adds several features, all of them related to WebAdmin usage of commands.

New make_command functions to easily generate HTML content

ejabberd already has around 200 commands to perform many administrative tasks, both to get information about the server and its status, and also to perform operations with side-effects. Those commands have its input and output parameters clearly described, and also documented.

The purpose of this PR is to use all those commands to generate HTML content in the ejabberd WebAdmin: instead of writing again erlang code to perform those operations, and then write code to format it and display as HTML... let's have some frontend functions (make_command family) to call the command and generate the HTML content.

Use the new make_command functions in many WebAdmin pages

I've converted most of the ejabberd WebAdmin to the make_command feature. It works perfectly for me using a small server and also a backup of an old server with 5000 registered accounts and 10 years of history.

With that new feature, writting content for WebAdmin is much easier if a command already exists, so I've also added many more pages to WebAdmin using other existing commands.

When this code is tested with greater and varied databases, I imagine some problems could appear:

  • webadmin crashing and displaying empty page when there is some non-latin formatted data
  • inefficient page generation when large amount of data

There are still a few pages not yet updated.

Configuration requirements

Most WebAdmin pages use commands to generate the content, and access to those commands can be restricted using the api_permissions toplevel option.

The default ejabberd.yml configuration file already defines "admin access" that allows access from loopback IP address and accounts in the admin ACL to execute all commands except stop and start.

Now ejabberd_web_admin is another valid command frontend that can be specified in the from section. You can define fine-grained restrictions for accounts in WebAdmin, for example:

api_permissions:
  "webadmin commands":
    from:
      - ejabberd_web_admin
    who: admin
    what:
      - "*"
      - "![tag:oauth]"

Hook changes

There are several changes in webadmin hooks that now provide the whole HTTP request instead of only some of its elements.

You can update your code easily, see:

  • webadmin_page_node: instead of Path, Query and Lang, gets Request

    -webadmin_page_node(Acc, Node, Path, Query, Lang) ->
    +webadmin_page_node(Acc, Node, #request{path = Path, q = Query, lang = Lang}) ->
  • webadmin_page_hostnode: instead of Path, Query and Lang gets Request

    -webadmin_page_hostnode(Acc, Host, Node, Path, Query, Lang) ->
    +webadmin_page_hostnode(Acc, Host, Node, #request{path = Path, q = Query, lang = Lang}) ->
  • webadmin_user: instead of just the Lang, gets the whole Request

    -webadmin_user(Acc, User, Server, Lang) ->
    +webadmin_user(Acc, User, Server, #request{lang = Lang}) ->
  • webadmin_menu_hostuser: new hook added:

    +webadmin_menu_hostuser(Acc, Host, Username, Lang) ->
  • webadmin_page_hostuser: new hook added:

    +webadmin_page_hostuser(Acc, Host, Username, Request) ->

internal command tag and any argument/result

During the development of this feature, I noticed the necessity to define some commands that will be used by WebAdmin (or maybe also by other ejabberd code), but should NOT be accessed by command frontends (like ejabberdctl, mod_http_api, ejabberd_xmlrpc).

Such commands are identified because they have the internal tag.

Those commands can use any arbitrarily-formatted arguments/results, defined as any in the command.

make format and indent

I use Vim, it indents erlang code correctly, but sometimes I modify code and forget to reindent it.

The new make format uses https://github.com/AdRoll/rebar3_format to format and indent files, with those restrictions:

  • Only formats a file if it contains a line with this string, and formats only starting in that line:

    %% @format-begin
  • Formatting can be disabled later in the file by adding another line that contains

    %% @format-end
  • Furthermore, it is later possible to enable formatting again in the same file, in case there is another piece of the file that should be automatically formatted.

Alternatively, it is possible to indent files using Emacs, it also replaces tabs with blankspaces and removes ending spaces. The new make indent indents the lines between:

%% @indent-begin
...
%% @indent-end

TODO

General to-do tasks:

  • ejabberd Docs: Update WebAdmin page explaning to administrators how to configure permissions
  • ejabberd Docs: Update WebAdmin page explaining to developers how to write new pages
  • Update modules in ejabberd-contrib to support the new hooks
  • Update modules in ejabberd-contrib to benefit from the new make_command feature

Some pages are not yet updated to use the proper commands. Instead, the existing code has been included in internal commands in the meantime:

@coveralls
Copy link

Coverage Status

coverage: 32.249% (+0.6%) from 31.673%
when pulling 9f86361 on badlop:webadmin-commands
into 7ba9f2e on processone:master.

@coveralls
Copy link

Coverage Status

coverage: 32.184% (+0.5%) from 31.673%
when pulling 1012151 on badlop:webadmin-commands
into 7ba9f2e on processone:master.

@coveralls
Copy link

Coverage Status

coverage: 32.187% (+0.5%) from 31.673%
when pulling 7a3d757 on badlop:webadmin-commands
into 7ba9f2e on processone:master.

@Neustradamus
Copy link

@badlop: Nice, very good job for this new PR!

@coveralls
Copy link

Coverage Status

coverage: 32.187% (+0.5%) from 31.673%
when pulling b0ba7e4 on badlop:webadmin-commands
into 7ba9f2e on processone:master.

@badlop badlop force-pushed the webadmin-commands branch from b0ba7e4 to 6ed0ce1 Compare June 10, 2024 19:49
@coveralls
Copy link

Coverage Status

coverage: 32.143% (+0.5%) from 31.68%
when pulling 6ed0ce1 on badlop:webadmin-commands
into 103a30d on processone:master.

@coveralls
Copy link

Coverage Status

coverage: 32.145% (+0.5%) from 31.68%
when pulling e49c04c on badlop:webadmin-commands
into 103a30d on processone:master.

@coveralls
Copy link

Coverage Status

coverage: 32.132% (+0.5%) from 31.68%
when pulling 64c1880 on badlop:webadmin-commands
into 103a30d on processone:master.

@badlop badlop force-pushed the webadmin-commands branch from 64c1880 to 97e2884 Compare June 12, 2024 22:01
@coveralls
Copy link

Coverage Status

coverage: 32.132% (+0.5%) from 31.68%
when pulling 97e2884 on badlop:webadmin-commands
into 103a30d on processone:master.

@badlop badlop force-pushed the webadmin-commands branch from 97e2884 to c2bdbd7 Compare June 12, 2024 23:24
@coveralls
Copy link

Coverage Status

coverage: 32.12% (+0.4%) from 31.68%
when pulling c2bdbd7 on badlop:webadmin-commands
into 103a30d on processone:master.

@badlop badlop force-pushed the webadmin-commands branch from c2bdbd7 to 474ee01 Compare June 18, 2024 10:21
@coveralls
Copy link

Coverage Status

coverage: 32.119% (+0.4%) from 31.671%
when pulling 474ee01 on badlop:webadmin-commands
into 2c5a8f0 on processone:master.

@badlop badlop added this to the ejabberd 24.xx milestone Jun 19, 2024
@badlop badlop force-pushed the webadmin-commands branch from 474ee01 to e78ade6 Compare June 19, 2024 15:24
@coveralls
Copy link

Coverage Status

coverage: 32.144% (+0.5%) from 31.671%
when pulling e78ade6 on badlop:webadmin-commands
into be847a7 on processone:master.

badlop added 7 commits June 19, 2024 17:59
- Update ejabberd WebAdmin logo
- Add hyperlink in disclaimer text
- Add welcome paragraph
Also 'atom' may be used as argument type by some internal commands,
for example the ones that refer to erlang node names.
…ands

Also:
- Added support to view user subpages in the menu
- Webadmin hooks now get the full request
- New commands added to be used in webadmin pages
@badlop badlop force-pushed the webadmin-commands branch from e78ade6 to 899b77c Compare June 19, 2024 15:59
@badlop badlop merged commit 0380695 into processone:master Jun 19, 2024
30 checks passed
@Neustradamus
Copy link

@badlop: Really good job, a big improvements to all!

@coveralls
Copy link

Coverage Status

coverage: 32.119% (+0.4%) from 31.671%
when pulling 899b77c on badlop:webadmin-commands
into be847a7 on processone:master.

@badlop badlop deleted the webadmin-commands branch June 24, 2024 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants