processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6k stars 1.5k forks source link

Use commands in WebAdmin to generate page content #4228

Closed badlop closed 2 weeks ago

badlop commented 1 month ago

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:

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:

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:

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:

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 commented 1 month ago

Coverage Status

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

coveralls commented 4 weeks ago

Coverage Status

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

coveralls commented 4 weeks ago

Coverage Status

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

Neustradamus commented 4 weeks ago

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

coveralls commented 3 weeks ago

Coverage Status

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

coveralls commented 3 weeks ago

Coverage Status

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

coveralls commented 3 weeks ago

Coverage Status

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

coveralls commented 3 weeks ago

Coverage Status

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

coveralls commented 3 weeks ago

Coverage Status

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

coveralls commented 3 weeks ago

Coverage Status

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

coveralls commented 2 weeks ago

Coverage Status

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

coveralls commented 2 weeks ago

Coverage Status

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

Neustradamus commented 2 weeks ago

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

coveralls commented 2 weeks ago

Coverage Status

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