Commit Graph

128 Commits (1d68e2619a74d7d8b2bd8faefbf01b9794f3a2f7)
 

Author SHA1 Message Date
Jose M. Guisado 1d68e2619a Show error messages in action_image_restore
If something goes wrong, the application shows an error message after
redirecting to the commands view.

Do not show blank pages with plain text error codes.
2022-02-23 10:07:45 +01:00
Jose M. Guisado 5de191964a Show error message for invalid setup form
Do not show plain text '400 Bad Request'. Instead, show error message
and return to commands view.
2022-02-23 10:01:53 +01:00
Jose M. Guisado c5cb75eea3 Move 'Update' button up in hardware view 2022-02-23 09:58:30 +01:00
Jose M. Guisado ca00bd5e89 Redirect to commands view after hardware POST 2022-02-23 09:58:10 +01:00
Jose M. Guisado a326119937 Hardware inventory template extends from command.html
Extending from command.html is required for action views to mantain
the scope context on the left side column.

Enables setting dropdown button and action button as active when loading
the hardware inventory view.
2022-02-22 17:01:27 +01:00
Jose M. Guisado ba5063871c Update Spanish translations 2022-02-22 16:58:04 +01:00
Jose M. Guisado 93f7fa17c5 Rename "Log" action to "System Log" 2022-02-22 16:51:29 +01:00
Jose M. Guisado 8e6fa1b1be Group command buttons into dropdowns
Group related actions in the "commands" section inside a
dropdown button.

Declutters the panel in which the buttons are displayed.

Dropdown button jinja block name is used as prefix for the block names
of inside buttons. For example, for the image dropwdown button:

<button class="...{% block nav_image %}{% endblock %}...">
    {{ _('Image') }}
</button>

Actions such as restore and create will show a jinja block inside class
attr like:

<input class="... dropdown-item{% block nav_image_restore %}{% endblock %}" ...
<input class="... dropdown-item{% block nav_image_create %}{% endblock %}" ...
2022-02-22 16:28:16 +01:00
Jose M. Guisado d2e8131ffa Setup view sets nav button as active
When loading the setup view, it's nav button becomes active.
2022-02-22 13:03:11 +01:00
Jose M. Guisado 17e13ad6a8 Add nav blocks to commands template
Adds empty jinja blocks for the class attribute of all action buttons.

Child templates from command (actions) can set their nav button as
active overriding the corresponding {% block %}.

Currently, not all action templates extends the commands.html template.
This is not a problem, as the blocks are just empty.

This is a preparation for changes on each action template to extend
commands.html template.
2022-02-22 12:57:20 +01:00
Jose M. Guisado ea4ee6662f Highlight active nav items
Use bold font for active nav items.
2022-02-22 12:40:26 +01:00
Jose M. Guisado 07b69dab90 Merge nav into base template
{% block %} defined in nav template cannot be overriden by child
templates from base. This is a limitation in jinja.

Merge nav into base template so jinja blocks so no {% include %} is used
and these blocks can be overriden by child templates (commands, images,
dashboard...)

Avoid using request.endpoint to determine active nav item, decoupling
endpoint names from navigation. Instead use child templates to override
jinja blocks.

[1] https://stackoverflow.com/q/40537752
    https://stackoverflow.com/a/40562662
    https://github.com/pallets/jinja/issues/243
2022-02-22 12:34:03 +01:00
Javier Sánchez Parra 5d9ad78ed3 Check scopes checkboxes recursively
Otherwise, nested scopes are not checked and mislead users.

When a scope is checked, we search all its children and check them too.
2022-01-31 16:28:53 +01:00
Javier Sánchez Parra 9a6508c686 Add helper function to store checksum status
This function stores checksum status if is checked to browser local
storage. Otherwise, it removes checksum from the storage.
2022-01-31 16:28:53 +01:00
Jose M. Guisado ed294050f1 Group log commands buttons into dropdown
Compacts Commands view with a single "Logs" dropdown button. Dropdown
shows current log commands.
2022-01-31 16:02:35 +01:00
Javier Sánchez Parra a9e6340517 Keep selected clients in the scopes tree
Otherwise, users have to click clients checkboxes every time they
switch view.

This commit adds one hook to capture when clients checkboxes changes.
When they are checked, ogcp (front-end) stores them in browser's local
storage. When they are unchecked, ogcp removes them from local storage.

Every time users load a page with the scopes tree, ogcp checks local
storage to restore selected clients.
2022-01-28 12:51:07 +01:00
Javier Sánchez Parra b7e4f47f5c Keep scopes tree state
Otherwise, users have to expand the scopes tree every time they switch
view.

This commit adds two hooks to capture when an element of the tree is
shown or is hidden[1]. When they are shown, ogcp (front-end) stores them
in browser's local storage[2]. When they are hidden, ogcp removes them
from local storage.

Every time users load a page with the scopes tree, ogcp checks local
storage to restore the scopes tree state.

Store and remove functions use stopPropagation() to prevent ancestors of
clicked elements to also be stored or removed from local storage.[3]

1. https://getbootstrap.com/docs/4.1/components/collapse/#events
2. https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
3. https://javascript.info/bubbling-and-capturing
2022-01-28 08:23:43 +01:00
Javier Sánchez Parra 5fbcff64f2 Remove dead code in macro.html
scopes_tree_collapse() replaces this dead code.
2022-01-28 08:23:43 +01:00
Jose M. Guisado 31b1e92077 Add confirmation page when deleting image
User can confirm when deleting an image by double checking the
information displayed on this page.

Adds a new optional field in GenericForm: 'ids'. Used when dealing with
ids instead of ips.
2022-01-27 16:51:35 +01:00
Javier Sánchez Parra b566528012 Adds confirmation page to reboot clients
This commit adds an extra view to ensure users do not reboot clients
accidentally.

ogcp GET /reboot returns the confirmation page and POST /reboot
builds and sends the request to ogServer.

It also includes Spanish translation of the new strings.
2022-01-20 15:20:38 +01:00
Javier Sánchez Parra ddd4629571 Adds confirmation page to power off clients
This commit adds an extra view to ensure users do not power off clients
accidentally.

ogcp GET /poweroff returns the confirmation page and POST /poweroff
builds and sends the request to ogServer.

It also includes Spanish translation of the new strings.
2022-01-20 12:54:57 +01:00
Javier Sánchez Parra 20a89ce965 Rename to "Partition Table Type"
Otherwise, "Partition Table" is ambiguous.
2022-01-20 09:41:57 +01:00
Javier Sánchez Parra e11125ef9e Rename MSDOS to MBR
This commit rename partition table type MSDOS to MBR in the front-end.

At the back-end ogCP still uses MSDOS string because ogClient scripts
(aka cloning engine) expects it.
2022-01-20 09:25:18 +01:00
Javier Sánchez Parra 302a776c5f Show disk and partition size in mebibytes
This commit converts disk and partition size from kibibytes to mebibytes
to improve usability. Disk and partition size are used in "Client
details" and "Partition & format" forms.

It also returns size to kibibytes when creating /setup API
payload as required by ogServer.
2022-01-19 17:08:16 +01:00
Javier Sánchez Parra 813b9e28d1 Fix typo in the dashboard 2022-01-19 15:48:39 +01:00
Javier Sánchez Parra 73963a0273 Ask twice to delete clients
This commit adds an extra view to ensure users do not clients
accidentally.

It also includes Spanish translation of the new strings.
2022-01-19 15:36:58 +01:00
Javier Sánchez Parra 96d2797ec3 Fix "Add client" form redirection
Otherwise, ogcp redirects to a blank page instead of the scopes view.
2022-01-14 09:08:04 +01:00
Javier Sánchez Parra c34da1e098 Add language configuration and Spanish translation
This commits configures and sets up flask-babel and adds Spanish po
file. Flask-babel is already a dependency so this commits no needs to
add it.

Users can edit ogcp.json to choose between English or Spanish. After
changing the language in the configuration file, users must restart ogcp
service.

Instructions to generate translation files, inspired by
https://flask-babel.tkte.ch/:

1. Download ogcp source code.

   git clone git://git.soleta.eu/ogCP /path/to/ogcp

2. Create a python virtual environment.

   python3 -m venv /path/to/new/venv

3. Activate the virtual environment.

   source /path/to/new/venv/bin/activate

4. Install dependencies to the virtual environment.

   cd /path/to/ogcp
   pip3 install -r requirements.txt

5. Extract ogcp strings.

   cd /path/to/ogcp/ogcp
   pybabel extract -F babel.cfg -k _l -o messages.pot .

   NOTE: "-k _l" is needed to extract strings which use lazy
   translations.

6. Create or update translation files.

   a. Create translation file. This example creates a french translation
   file.

      pybabel init -i messages.pot -d translations -l fr

   b. Update translation files. You need to do this when ogcp strings
   change and want to update current supported languages.

      pybabel update -i messages.pot -d translations

7. Edit the translations .po file as needed. Example route:
   /path/to/ogcp/ogcp/translations/fr/LC_MESSAGES/messages.po.

8. Compile translations.

   pybabel compile -d translations

9. Launch ogcp and check the translations.

   cd /path/to/ogcp
   pip3 install -r requirements.txt

10. Commit and push .po files with translation changes.
2022-01-13 11:36:46 +01:00
Javier Sánchez Parra 4777fcaee6 Add gettext to dashboard strings
Otherwise, this texts could not be translated.
2022-01-13 11:36:46 +01:00
Javier Sánchez Parra 09498a8887 Use lazy translation in classes
From flask babel documentation:
---
Additionally if you want to use constant strings somewhere in your
application and define them outside of a request, you can use a lazy
strings. Lazy strings will not be evaluated until they are actually
used. To use such a lazy string, use the lazy_gettext() function.
---

_() and _l() functions are aliases of gettext() and lazy_gettext()
respectively. Both functions belong to flask babel library.
2022-01-13 11:36:46 +01:00
Javier Sánchez Parra 91f3567d09 Change some f-strings to format()
python-babel is not compatible with f-strings.

See also: https://github.com/python-babel/babel/issues/594
2022-01-13 11:36:41 +01:00
Javier Sánchez Parra a8e16a3388 Check images list content in client details view
Otherwise, client image assignation fails if "images" variable is empty.
2021-12-20 12:21:08 +01:00
Javier Sánchez Parra d12b401d30 Add available ogLives to client details
Otherwise, ogLive field always shows the default value.
2021-12-17 13:24:00 +01:00
Javier Sánchez Parra e07c8afcce Add set ogLive to commands
This action is related to /oglive in ogServer's API. Allows changing the
ogLive for a set of given clients, previously selected in the /commands
view.
2021-12-16 17:17:07 +01:00
Javier Sánchez Parra 695c19f86e Add scope permission support
ogCP limits which scopes can use each user.

Configuration file stores allowed scopes by their names. Leave scope
list empty to give a user permissions on all scopes.
2021-12-10 13:06:18 +01:00
Javier Sánchez Parra a5681a4b85 Add multi user support
It is inspired by the following example:
c760c0ef7c/README.md (usage)
2021-12-08 12:10:38 +01:00
Javier Sánchez Parra f70d90ba32 Ensure unique HTML ids for scope elements
Otherwise, undesired collapse/expand events may occur when users click
an element of the scope.

Old id format example: level3-2

New id format example: id_1-1_2-4_3-2

Explanation:

	* "id" -> Prefix needed because html ids must start with an
	  alphabetic character.

	* "_" -> Separator.

	* "1-1" -> Values pair separated by "-". The first value is the
	  level of the node. The second value is its position with
	  respect to its siblings. This is always 1-1 because is the
	  root node.

	* "_" -> Separator.

	* "2-4" -> Child node of the previous node. In this example,
	  this node its in level 2 and has the fourth position.

	* "_" -> Separator.

	* "3-2" -> Child of node "2-4" in level 3 and in the second
	  position. This is the final node in this example.

In other cases ogcp may draws deeper nodes, so it creates longer ids.
For example: id_1-1_2-1_3-2_4-1_5-1_6-1
2021-11-26 12:43:53 +01:00
Javier Sánchez Parra 792e4ed3dd Add legacy real-time log
Clients in ogLive offer a web page with lighttpd that shows a real-time
log. This commit links this log in ogcp.

Future patches will deprecate this log functionality in favour of more
robust solutions.
2021-11-08 11:42:59 +01:00
Javier Sánchez Parra 7faa607131 Set default value on partition data parsing
Otherwise, ogcp breaks when receiving an unknown disk table type,
partition type or file system.
2021-11-02 16:48:06 +01:00
Javier Sánchez Parra cbeafea273 Support partition of computers with several disks
Add a new select input and button to choose which disk you want to
partition.

TODO: Current argument parsing function returns a list with all the
arguments, except csrf_token. Future patches should add granular parsing
of different types of arguments.
2021-11-02 16:24:18 +01:00
Javier Sánchez Parra 20a94dbc3e Add legacy log
Future patches will deprecate this log functionality in favour of more
robust solutions.
2021-10-28 11:29:03 +02:00
Javier Sánchez Parra c493d24349 Set tiptorrent as unique restore image method
Soleta Networks only offers support of tiptorrent for restore image
transferences.
2021-10-20 11:54:28 +02:00
Jose M. Guisado 76d500fe2e Keep scopes collapsed by default
For large scopes, unfolding by default slows page loading. It also
takes lots of vertical space and the scroll bar gets smaller.
2021-10-15 12:14:53 +02:00
Javier Sánchez Parra 0b424aa34e Add partitions info to client details
Show a table with client's disks and partitions information.
2021-10-13 13:06:49 +02:00
Javier Sánchez Parra 3e7801e487 Add "Delete image" action
Adds a new button in the images view.

This action handles image deletion, one at a time for security. Users
must select an image using the images tree.
2021-09-29 17:12:15 +02:00
Javier Sánchez Parra f572643605 Fix cache partition creation
Partition & Format JSON cache fields always have the default values (no
cache) although users order to create a cache partition.

Set JSON cache fields with the values filled by the user.
2021-09-16 11:57:59 +02:00
Javier Sánchez Parra da9b2ea9c2 Add image details action
This action is used to visualize the specific details of an image, as
its ID, name, size, etc.
2021-09-03 14:51:15 +02:00
Javier Sánchez Parra d83e456daf Rename validate and parse IPs functions
These functions can work with any kind of strings and not only with IPs.

This is required by the "image details form" that a follow up patch
implements. "Image details form" validates and parses IDs instead of IPs
with these functions.

Rename validate and parse IPs functions to a generic name, so it makes
sense to use them with any kind of string.
2021-09-03 14:51:15 +02:00
Javier Sánchez Parra 27ea5016c4 Add images view
Images view manages all the images stored in the server.

Follow up patches adds actions to get and edit image details, and to
delete them.
2021-09-03 14:51:14 +02:00
Javier Sánchez Parra 37a0304575 Add most common partition codes and filesystems
To increase the compatibility of "Partition & format" (aka setup).
2021-08-24 13:35:42 +02:00