-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@badlop: Nice, very good job for this new PR! |
badlop
force-pushed
the
webadmin-commands
branch
from
June 10, 2024 19:49
b0ba7e4
to
6ed0ce1
Compare
badlop
force-pushed
the
webadmin-commands
branch
from
June 12, 2024 22:01
64c1880
to
97e2884
Compare
badlop
force-pushed
the
webadmin-commands
branch
from
June 12, 2024 23:24
97e2884
to
c2bdbd7
Compare
badlop
force-pushed
the
webadmin-commands
branch
from
June 18, 2024 10:21
c2bdbd7
to
474ee01
Compare
…rained permissions
badlop
force-pushed
the
webadmin-commands
branch
from
June 19, 2024 15:24
474ee01
to
e78ade6
Compare
- Update ejabberd WebAdmin logo - Add hyperlink in disclaimer text - Add welcome paragraph
Support to sort tables using Sortable library from: https://github.com/tofsjonas/sortable
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
force-pushed
the
webadmin-commands
branch
from
June 19, 2024 15:59
e78ade6
to
899b77c
Compare
@badlop: Really good job, a big improvements to all! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds several features, all of them related to WebAdmin usage of commands.
New
make_command
functions to easily generate HTML contentejabberd 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 pagesI'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 theadmin
ACL to execute all commands exceptstop
andstart
.Now
ejabberd_web_admin
is another valid command frontend that can be specified in thefrom
section. You can define fine-grained restrictions for accounts in WebAdmin, for example: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 Requestwebadmin_page_hostnode
: instead of Path, Query and Lang gets Requestwebadmin_user
: instead of just the Lang, gets the whole Requestwebadmin_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 andany
argument/resultDuring 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
andindent
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: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: