Commit Graph

210 Commits (b6b16f895e72a049eeafc0e07eb9336d0bd9825e)

Author SHA1 Message Date
Jose M. Guisado db68dcea46 ogcp: add backup boolean field in image update
User can use this boolean field to specify if an backup copy needs to be
created before updating an image.

This only applies when sending a request to a client (ogClient)
supporting this parameter.
2023-07-07 13:22:23 +02:00
Jose M. Guisado ae3f83b3c3 views: use \s to match whitespace in client import regex
Some programs substitute regular space characters (\u0020) by en spaces
(\u2002) when displaying monospace text. Others replace it by
non-breaking spaces.

Using a character set such as [ \t\n] to match any possible "space
related" character. Use \s to match any kind of whitespace related
character in the regex.

Pasted from python's documentation:

\s

    For Unicode (str) patterns:

	Matches Unicode whitespace characters (which includes
	[ \t\n\r\f\v], and also many other characters, for example the
	non-breaking spaces mandated by typography rules in many languages). If
	the ASCII flag is used, only [ \t\n\r\f\v] is matched.
	[...]

Fixes: d9f8c95618
('views: better dhcp conf parsing when importing clients')
2023-06-28 12:48:22 +02:00
Jose M. Guisado d9f8c95618 views: better dhcp conf parsing when importing clients
This new regex allows parsing of:

	- Irrelevant options that the user may paste from its config
	  file, eg. 'option host-name'.
	- Allows linebreaks.

Hosts still require to have 'hardware ethernet' first, and then
'fixed-address'.

For example this regex admits dhcp host declarations such as

	host pir36-22_78 {
	      hardware ethernet d8:5e:d3:25:28:9d;
	      fixed-address 10.1.36.78;
	      option host-name "pc_78";
	}

Summary of the regex:

(?: *host *)			# Match host keyword and spaces
([\w.-]*)     			# Match any word character (alphanum and underscore)
(?:[ \n\r]*{[ \n\r]*)  		# Match any space or newline, then match { and any following space or newline
(?:[ \t]*hardware *ethernet *)  # Match any space or tab character followed by 'hardware ethernet'
((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))  # Match the mac address using ':' or '-' as separator
(?: *;)				# Match any space character before a ';'
(?:[ \t\n\r]*fixed-address *)	# Match any space, tab or newline followed by 'fixed address' and any following space
(\d+\.\d+\.\d+\.\d+)		# Match an ip address (no validity check)
(?: *;)(?:[ \r\n]*[^}]*})	# Match any space followed by ';', then match any character except '}'
2023-06-27 17:06:34 +02:00
Jose M. Guisado 9c91fb16b4 views: add placeholder text inside dhcp conf textarea
Help user by hinting the current expected format via a placeholder in
the textarea box.

Current regex has its limitations when parsing dhcpd host declarations.
It does not support multi line host declarations or different options
outside "hardware ethernet ..." and "fixed-address ...".
2023-06-27 08:56:49 +02:00
Javier Sánchez Parra d029df8e84 Show warning when formatting clients without disks
If an administrator selects a client without disks and goes to
"Partition & Format", ogCP redirects it again to "Commands" and shows a
floating message indicating that the client has no disks.
2022-11-17 17:36:15 +01:00
Javier Sánchez Parra fc02d891cd Fix typo in save_user() function 2022-11-17 17:36:15 +01:00
Javier Sánchez Parra 693f5255b1 Assign servers to users
Instead of give permissions on all centers of a server selecting each one
of them, you can select the server that contains all this centers.
2022-11-07 12:58:27 +01:00
Javier Sánchez Parra 0f6641d92f Set server variable on GET /action/image/update
Otherwise, ogCP crashes on image update.

Fixes: 8726ade ("Adapt commands to work with several ogServers")
2022-11-07 12:58:27 +01:00
Javier Sánchez Parra f834253a80 Remove unused variable "g.server"
Since ogCP multi ogServer support, g.server is not used anymore. The
list of available servers is stored in the global variable "servers" at
og_server.py
2022-09-29 13:01:28 +02:00
Javier Sánchez Parra cb2f534f64 Get available scopes from all the servers
When creating o editing a user, you can select in which scopes from all
servers the user has permission.
2022-09-29 13:01:28 +02:00
Javier Sánchez Parra 4f3c66f04a Fix ogServer deletion from the configuration file
Otherwise, users can not remove from the web a server declared in the
deprecated way.
2022-09-29 13:01:28 +02:00
Javier Sánchez Parra 328ead9168 Create servers list if do not exists
Otherwise, if the configuration file do not have 'SERVERS' array, ogCP
crashes trying to append a new server.
2022-09-29 13:01:28 +02:00
Javier Sánchez Parra 30d27c8951 Adapt aux function to work with several ogServers
Otherwise, get_repositories() and get_repository() functions only get
the repositories of the first ogServer of the list.
2022-09-29 13:01:28 +02:00
Javier Sánchez Parra 6142a171fd Fix repositories retrieving
Commit X wrongly changed the URI to retrieve the repositories of an
ogServer.

Fixes: cf02e0c ("Add Servers section")
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra a010f11224 Set server variable on GET /action/image/restore
Otherwise, ogCP crashes on image restore.

Fixes: 8726ade ("Adapt commands to work with several ogServers")
2022-09-27 09:48:36 +02:00
Daniel García Moreno 0c66443db8 Add multiple servers to the dashboard view 2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 1db12230f9 Adapt Delete clients to work with several ogServers
This commit makes Delete clients view to use "get_server_from_clients()"
function to send the deletion request to the correct ogServer.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra d74ad9336e Ignore unreachable ogServers
Otherwise, ogCP crashes trying to connect to unreachable ogServers.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 3459de36f3 Add Servers section
In Servers section/view, users can add or delete ogServers from ogCP
configuration file.

Replaces Repositories views and recycle some of its code.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 07c5cb25d2 Store configuration file path on a global variable
Otherwise, users may change the file path on one place of the code and
forget to change the other places.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 083cb7af7f Adapt MAC retrieving to support several ogServers
Clients pills show MACs regardless of the ogServer they belong to. Flask
GET /client/mac API uses "get_server_from_clients()" function to send
the command to the correct ogServer.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 083caf00c6 Adapt Delete image to work with several ogServers
This commit makes Delete image view to use ogServer field from
imagesForm to send the deletion request to the correct ogServer.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 70eb7389bb Add ogServer parameter to imagesForm
When users select an image, its ogServer is sent too. Then, the back-end
(flask) processes the form to obtain this ogServer and send it the
pertinent requests.

It also makes "Image details" view use this new parameter, and adds
javascript code to ensure that users can only work with several images
at the same time if they belong to the same ogServer.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra c543ba25a6 Adapt images tree to work with several ogServers
Images view fetch images from all ogServers configured and show them in
the left tree as a nested list. ogServers are represented as the parents
of their images.
2022-09-27 09:48:36 +02:00
Javier Sánchez Parra 873bee30aa Adapt Delete center to work with several ogServers
This commit makes Delete center view to use ogServer field from
scopesForm to send the command to the correct ogServer.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 43d2df0e7d Delete center using the scopes tree
With this commit users can select a center from the scopes tree, and
then delete it.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 9ca010a981 Adapt Add center to work with several ogServers
This commit adds a new select input with all available ogServers to "Add
center" view. The ogCP creates the center in the ogServer selected by
the user.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 3d42c2c66c Adapt Delete room to work with several ogServers
This commit makes Delete room view to use ogServer field from scopesForm
to send the command to the correct ogServer.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra f009a188b1 Delete room using the scopes tree
With this commit users can select a room from the scopes tree, and then
delete it.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra bf4192a5d4 Adapt Add room to work with several ogServers
This commit makes Add room view to use ogServer field from
scopesForm to send the command to the correct ogServer.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 0cc65a057d Add a room to a center using the scopes tree
With this commit users can select a center from the scopes tree, and then
add a room to that center.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 0db56d5eee Adapt Import Clients to work with several ogServers
This commit makes Import Clients view to use ogServer field from
scopesForm to send the command to the correct ogServer.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra f16b1a0347 Import clients to a room using the scopes tree
With this commit users can select a room from the scopes tree, and then
import clients to that room.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 028f810a47 Fix selection of scopes with empty IPs list
This commit prevents ogcp from always mark as selected/checked scopes
that have an empty IP list.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 229ad311be Add current ogServer to scopesForm
With this commit when users select a scope, the ogServer to
which it belongs is also sent. Then when processing the form we obtain
this ogServer and we can send it the pertinent requests.

This commit also makes action "Add client" to use the ogServer sent in
the form.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 2614c9304e Add a client to a room using the scopes tree
With this commit users can select a room from the scopes tree, and then
add a client to that room.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 75dc842284 Adapt commands to work with several ogServers
This commit makes commands views to use "get_server_from_clients()"
function to send the command to the correct ogServer.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra b4c0bd5c5e Fix ogServer names on the scopes tree
This commit adapt how "get_scopes()" accesses the name of the ogServer
because commit eae64dd changes how "multi_request()" returns it.

Fixes: eae64dd ("Initial support of ogServer requests routing")
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 74e9ff9907 Initial support of ogServer requests "routing"
This commit adds a helper function ("get_server_from_clients()") to get
the adequate ogServer according to the targeted clients.

It also makes "Client details" command use this function.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra ddea404c5b Add status of all clients to the scopes tree
Fetch clients status using 'get_clients()'.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 279184df5f Fetch clients from all ogServers in the dashboard
With this commit, ogcp fetch all clients lists an join them.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra af0a3255b4 Add helper function to send requests to all ogServers
'multi_request()' function make requests to ogServers defined in the
configuration and aggregates it responses.

This commit also makes 'get_scopes()' use it.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 2cbe6b774c Retreive scopes from several ogServers
Update the configuration file format to support several ogServers and
retrieve scopes from those ogServers.

The old config file format is still supported.
2022-09-27 09:48:35 +02:00
Javier Sánchez Parra 9e386e5454 Add "Delete Repository"
In "Repositories" view, users select a repository from the list on the
left and press "Delete repository".
2022-07-04 15:34:03 +02:00
Javier Sánchez Parra c068bd2144 Create "Add Repository" form and view
Creates "Add repository" form with the required inputs: name and IP.
2022-07-04 15:34:02 +02:00
Javier Sánchez Parra 9a6981d289 Add Repositories section
In Repositories section/view, users can manage task related to
repositories. For example: list, add, delete and edit them.
2022-07-04 15:34:02 +02:00
Javier Sánchez Parra eb61229b29 Use repository id on image creation
On image creation use the id to identify repositories instead of the IP.

ogServer related commit:
  * 52a38d3 ("#915 Use the repository id on image creation")
2022-06-30 10:24:02 +02:00
Javier Sánchez Parra 61bd6bc4ba Move password hashing to the backend
This patch moves login password hashing from the frontend/javascript to
the backend/flask.

This patch moves password hashing of login and user management forms.

Related commits:
  * c7b0024 ("Add password hashing")
  * 661254b ("Add 'Add user' to Users section")
2022-06-30 09:26:18 +02:00
Javier Sánchez Parra 85be1258e1 Use assigned repository on images transfers
Otherwise, update/restore fails on images not saved in the same machine
which runs ogServer.
2022-05-24 09:28:51 +02:00
Javier Sánchez Parra d9d3d2ad5f Add repository field to "Create image" form
Let users choose which repository want to use to save the image.
2022-05-24 09:28:51 +02:00
Javier Sánchez Parra b74820a84c Improve MAC formatting
Add ":" separator between each byte in hexadecimal and transform chars
to uppercase.
2022-05-18 11:35:35 +02:00
Javier Sánchez Parra 4c6e3a90f1 Show last command result for clients in ogLive
If the last command sent to a client/s finishes with errors, their icons
in the scopes tree change to a yellow circle with an times sign inside.
2022-05-13 11:34:44 +02:00
Javier Sánchez Parra 08cae4b6ca Add link speed to pills
If the clients API response include link speed information, show it in
clients' pills.
2022-05-11 17:37:00 +02:00
Javier Sánchez Parra ce651453c4 Add MAC to pills
Retrieve and cache MACs one by one as users select clients.
2022-05-06 09:55:58 +02:00
Javier Sánchez Parra 72c10e1529 Add 'Delete user' to Users section
Creates "Delete user" form. The user to be deleted is selected from the
sidebar in Users section.
2022-04-27 17:34:36 +02:00
Javier Sánchez Parra eb8ddd236a Add 'Edit user' to Users section
Creates "Edit user" form with the following inputs: password, password
confirmation, role (administrator or regular), allowed scopes. It does
no allow to change/edit the username.
2022-04-27 17:34:26 +02:00
Javier Sánchez Parra 661254b76e Add 'Add user' to Users section
Creates "Add user" form with the following inputs: username, password,
password confirmation, role (administrator or regular), allowed scopes.
2022-04-27 17:27:50 +02:00
Javier Sánchez Parra d8bac16a98 Add Users section
In Users section/view, administrator accounts can manage all task
related to users. For example: add, delete and edit users.
2022-04-27 17:26:40 +02:00
Javier Sánchez Parra 57da4f4efa Add user role administrator
ogCP now have to types of users, regular and administrator users.

ogCP configuration file defines users roles with the boolean field
"ADMIN".
2022-04-27 17:24:08 +02:00
Javier Sánchez Parra c7b0024d24 Add password hashing
The front-end now hashes passwords before sending them to the back-end.
It uses SHA-512.

This commit adds a hidden input which sends the password hash to not
interfere with browsers' save password functionality.

Also change passwords of the template configuration file for their
hashed/digested versions.
2022-04-22 13:02:30 +02:00
Javier Sánchez Parra 09884080c3 Add import clients action
Add import clients form with required inputs: room and dhcpd.conf.

This permits users to rapidly add large amounts of clients to a room
using dhcpd.conf's syntax. Users can copy full dhcpd.conf files to the
text area and the parser only matches lines with the following format as
clients:

host dummy {hardware ethernet 12:34:56:78:90:ab; fixed-address 192.168.1.55; }
2022-04-19 16:03:41 +02:00
Javier Sánchez Parra 974b74649a Handle ogServer connection error on login
On connection error show a (toast) message warning the user. Otherwise,
users see Werkzeug debug page.
2022-04-11 17:37:26 +02:00
Javier Sánchez Parra fcbaf7d66d Add Update image to commands
Allows updating the image file for an existing image.

This action is related to /image/create in ogServer API. If ogServer
receives an POST /image/create without the parameter "description", it
does not create a new image and only updates.
2022-04-08 08:03:32 +02:00
Javier Sánchez Parra d2fef8e85d Move search_image() outside action_image_restore() 2022-04-08 08:03:10 +02:00
Javier Sánchez Parra f86eaffefe Add form for disk selection
Disk selection uses "scopesForm" to submit the change, but setup/show
view receives new parameters not provided by this form.

Commit 17757baa4727 adds those parameters.

This commit gives disk selection its own form with all the required
parameters.
2022-04-04 09:28:49 +02:00
Javier Sánchez Parra 52a06822b2 Ask for reference when partitioning several clients
Allow the user to choose a computer as reference to display the
partition scheme form.
2022-04-01 15:07:05 +02:00
Javier Sánchez Parra bb39f67a46 Change get_client_setup to receive a string
get_client_setup() takes an IP address that identify the client,
instead of passing an iterator with one single IP address, pass
directly such IP address.
2022-03-31 13:54:20 +02:00
Javier Sánchez Parra ce10f04b97 Remove unused variable db_partitions 2022-03-29 12:37:52 +02:00
Javier Sánchez Parra 1356145026 Add ogServer uptime to the dashboard
ogServer GET /stats returns ogServer uptime in seconds.

Transform seconds to days, hours and minutes and print them in the
dashboard.
2022-03-28 08:37:53 +02:00
Javier Sánchez Parra ee6880a9f2 Use lazy translation on intervals' strings
Constant strings outside of a request must use lazy strings. See
flask-babel documentation for more information.
2022-03-22 11:19:26 +01:00
Javier Sánchez Parra 3283843d56 Add /stats data to the dashboard
Add certain statistics on memory and swap usage, as well as the uptime.
2022-03-16 17:33:34 +01:00
Javier Sánchez Parra 16ef1ae7ac Extend images html in "image details" template
Otherwise, "image details" page lose the images tree and buttons.
2022-03-03 12:35:48 +01:00
Javier Sánchez Parra b0fb32d767 Extend scopes html
Otherwise, this actions pages lose the scopes tree and the scopes
buttons.
2022-03-03 12:25:31 +01:00
Javier Sánchez Parra 4005b019ee Extend scopes or commands in client details
Both "Add client" and "Client details" views use client_details.html
template. With this commit, "Add client" extends scopes.html and "Client
details" extend commands.hmlt.
2022-03-03 11:41:16 +01:00
Javier Sánchez Parra 3db3659499 Use pill style in confirmation pages
Draw selected clients from confirmation pages like selected clients from
scopes and commands pages.
2022-03-03 11:41:16 +01:00
Javier Sánchez Parra 3271a4a08d Extend commands html
Otherwise, this actions pages lose the scopes tree and the commands
buttons.
2022-03-02 17:29:41 +01:00
Jose M. Guisado ee2e7a86dd Improve software inventory command
Extend commands.html template to keep scope tree, and action buttons
state.

When in the software inventory view, there exists two options: 'update'
or 'view'. Do not print raw json response from ogserver about the software
inventory/profile.

When vieweing the software list, print a html table using the new
template: software_list.html.

Do not print blank pages with plain text html error codes when something
goes wrong. Instead, print an error message after redirecting to the
commands view.
2022-02-23 11:42:25 +01:00
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 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 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 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 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 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 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 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