Commit Graph

39 Commits

Author SHA1 Message Date
Xavier Del Campo Romero b4572c6217
page.c: Do not get filename on previews
This change should provide the same behaviour, but would avoid
unnecessary calls to dynstr_append and basename(3) when a preview is to
be served.
2024-03-01 00:06:03 +01:00
Xavier Del Campo Romero 6c3bfa270b
page.c: Use open(2) fdopen(3) and fstat(2)
Now, the same file descriptor can be reused for all of the operations
above, instead of calling stat(2) and fopen(3) separately.
2024-02-19 23:35:09 +01:00
Xavier Del Campo Romero 78c8c4dabb
page.c: URL-encode href
Otherwise, files with special characters, such as '%', could not be
downloaded or previewed.
2024-02-19 23:35:09 +01:00
Xavier Del Campo Romero 472b4ddbf1
Implement HEAD support 2023-10-14 01:08:02 +02:00
Xavier Del Campo Romero 1d2ce3f9c2
List number of files and directories
Sometimes, users want to know how many files and/or directories reside
on a directory. Now, slcl prints such information below the logout form.
2023-10-11 00:08:44 +02:00
Xavier Del Campo Romero 91f1a38d5c
page.c: Force whitespace rendering 2023-10-11 00:08:44 +02:00
Xavier Del Campo Romero 28ae865e5e
Apply slweb renaming to libweb 2023-10-11 00:08:40 +02:00
Xavier Del Campo Romero 7471da3886
page.c: Update project URL 2023-09-09 00:19:07 +02:00
Xavier Del Campo Romero 75f1f223d4
Do some minor rebranding
Despite designed around portability and minimalism, I feel slcl no
longer aligns with the philosophical views from the suckless project.
Therefore, I think it was appropriate to unlink its branding from it.
2023-08-01 02:25:30 +02:00
Xavier Del Campo Romero e49f1da7ae
Adapt to slweb's include paths
slweb puts its header files into its own directory in order to avoid
potential name clashing.
2023-07-21 01:40:55 +02:00
Xavier Del Campo Romero 38f3f82a77
Limit amount of search results
When a user enters a search term that is too generic, slcl would
generate a long list of search results, where this generation could have
a big impact on the server performance and its available resources.

Therefore, it is reasonable to limit the number of search results to an
arbitrary limit, so that users are forced to enter a more specific
search term in order to achieve more relevant results.
2023-07-11 13:27:49 +02:00
Xavier Del Campo Romero e79e955d93
Allow admins to define their own stylesheet
slcl used to provide a hardcoded stylesheet. However, it would be
desirable for some admins to provide a custom stylesheet without having
to rebuild the application.

Now, slcl creates a default stylesheet, namely style.css, into the
target directory, that can be later modified by admins.

While this might contradict the suckless philosophy a bit, hopefully
some admins might find this new feature useful.
2023-07-11 01:49:12 +02:00
Xavier Del Campo Romero 4236c7fc3a
page.c: Allow add_element to hide checkboxes
Since removing files or directories is currently not an option in
searches, it is better to leave checkboxes out to avoid confusion.
2023-07-09 05:54:56 +02:00
Xavier Del Campo Romero 55f0efb8ab
page.c: Remove back button from searches
- The back button would not return to the previous directory, but to the
user root directory.
- While this could have been solved easily (e.g.: by inserting the
referrer directory into the form), it would have implied extra and
unneeded complexity.
2023-07-09 05:54:56 +02:00
Xavier Del Campo Romero 0822a982ef
Implement file/directory removal
The following workflow has been implemented:

- A new checkbox for each object inside a directory is shown.
- When one or more objects are selected, the user submits a request
through a HTML5 form.
- Then, slcl will ask the user for confirmation, listing the selected
objects, while reminding the user about the effects.
- The user confirms the selection.
- slcl removes the selected objects. All objects from non-empty
directories are removed, too.
- Finally, slcl redirects the user to the directory the request was
made from.
2023-07-08 03:08:07 +02:00
Xavier Del Campo Romero 8bff49d9c8
page.c: Return HTTP_STATUS_OK on successful page_search
This was probably a copy-paste issue when implementing page_search based
on page_quota_exceeded.
2023-07-08 00:52:53 +02:00
Xavier Del Campo Romero 5a6c92d69b
Implement search
This new feature adds a HTML form on each directory listing that allows
to search files recursively, starting from the current user directory.
Wildcard patterns are also allowed.
2023-06-06 03:52:16 +02:00
Xavier Del Campo Romero c4a3d54ac9
page.c: Apply minor fixes and improvements to stylesheet
- Rules applying to body already apply to input.
- input already had a "margin: auto" rule.
- Missing whitespace on "margin:auto" rule.
2023-06-06 03:48:36 +02:00
Xavier Del Campo Romero 3102e0da4b
page.c: Call page_not_found on ENOTDIR
ENOTDIR is another non-fatal errno value that can be returned by
stat(2).
2023-06-06 02:22:28 +02:00
Xavier Del Campo Romero 17502e7e32
page.c: Display login forms as grid
While commit 1ffba8f5 fixed a wrong display of the mkdir, upload and
logout forms, it did not take login forms into consideration, which must
displayed as grid.
2023-06-02 09:03:57 +02:00
Xavier Del Campo Romero 800dde6838
page.c: Add padding to mkdir, logout, and upload forms 2023-06-02 08:59:19 +02:00
Xavier Del Campo Romero 1ffba8f5f9
page.c: Do not display forms as grid
Otherwise, each element from the form would be stacked on top of
another, which is confusing to users.
2023-06-02 08:57:44 +02:00
Xavier Del Campo Romero 759a16a460
page.c: Apply max-width to table
This will help users to read tables with long file names.
2023-05-30 08:34:05 +02:00
Xavier Del Campo Romero 054f2a628d
page.c: Apply lightgray background to even cells
This will help users to navigate through large tables.
2023-05-30 08:16:06 +02:00
Xavier Del Campo Romero fa997aa2c1
Implement file previews
When using HTTP "Content-Disposition: attachment;", users are forced to
download files in order to use them, whereas others might prefer to open
them in the browser.

Therefore, now that URL parameters are supported by http.h, previews can
be forced by adding "preview=1" or "preview=true" (case-insensitive) as
a URL parameters. Any other parameters are ignored by slcl.

For users, a "Preview" link has been added next to the "Share" button
for each file.
2023-04-23 05:19:27 +02:00
Xavier Del Campo Romero 2e2c9b4c93
Improve CSS and apply to list_dir 2023-04-17 03:01:19 +02:00
Xavier Del Campo Romero b3ef22ac2a
Define _POSIX_C_SOURCE
This allows using the default compiler defined by make(1) (i.e.,
c99(1)), thus improving POSIX compatibility.
2023-03-24 02:49:11 +01:00
Xavier Del Campo Romero d9bb874591
Send response on quota exceeded
So far, slcl would just close the connection with a client when the
Content-Length of an incoming request exceeded the user quota, without
any meaningful information given back to the user.

Now, slcl responds with a HTML file with meaningful information about
the error.

Limitations:

- While this commits has been successfully tested on ungoogled-chromium,
LibreWolf (and I assume Firefox and any other derivates too) does not
seem to receive the response from the server.
    - However, this issue only occurred during local testing, but not
on remote instances.
2023-03-20 10:57:20 +01:00
Xavier Del Campo Romero 27b8a69718
page.c: Set Content-Disposition when serving files
So far, slcl used the default browser behaviour (i.e.,
Content-Disposition: inline), which means files were typically shown on
the web browser itself. However, this caused two issues:

- Users would have to right-click -> "Save Link As..." to download a
file, which might be inconvenient for some users.
- The original file name would not be retrieved for publicly shared
files.

Now, file download is always requested to the browser, and the original
file path is retrieved via readlink(2).
2023-03-16 01:49:18 +01:00
Xavier Del Campo Romero 69a059e0df
page.c: Fix wrong error message 2023-03-09 02:04:52 +01:00
Xavier Del Campo Romero 2e1b131396
Implement public file sharing
An HTML form is now added next to each regular file, that generates a
POST request. Then, slcl replies with a HTML document with a link to the
public resource (which are implemented as symlinks).

Limitations:

- For now, only regular files can be shared i.e., sharing directories is
not possible. While feasible, it still requires a larger refactor to
list_dir and resource_layout, so that read-only access to the directory
is provided to anonymous users.
2023-03-09 02:02:40 +01:00
Xavier Del Campo Romero 13f96054f6
page.c: Provide meaningful description on HTTP 404 2023-03-09 01:23:02 +01:00
Xavier Del Campo Romero 8016f537ca
page.c: Implement function for common <head> nodes
This will be used by future commits.
2023-03-09 01:20:18 +01:00
Xavier Del Campo Romero c4488c5e81
page.c: Set common <head> parameters 2023-03-08 18:52:03 +01:00
Xavier Del Campo Romero 0471658177
page.c: Show units for user quota 2023-03-08 00:33:55 +01:00
Xavier Del Campo Romero ba612d6621
page.c: Sort elements alphabetically 2023-03-08 00:33:20 +01:00
Xavier Del Campo Romero ff8da797a1
Implement user quota
This feature allows admins to set a specific quota for each user, in
MiB. This feature is particularly useful for shared instances, where
unlimited user storage might be unfeasible or even dangerous for the
server.

Also, a nice HTML5 <progress> element has been added to the site that
shows how much of the quota has been consumed.

If no quota is set, slcl falls back to the default behaviour i.e.,
assume unlimited storage.

Limitations:

- While HTTP does specify a Content-Length, which determines the length
of the whole request, it does not specify how many files are involved
or their individual sizes.
- Because of this, if multiple files are uploaded simultaneously, the
whole request would be dropped if user quota is exceeded, even if not
all files exceeded it.
- Also, Content-Length adds the length of some HTTP boilerplate
(e.g.: boundaries), but slcl must rely on this before accepting the
whole request. In other words, this means some requests might be
rejected by slcl because of the extra bytes caused by such boilerplate.
- When the quota is exceeded, slcl must close the connection so that
the rest of the transfer is cancelled. Unfortunately, this means no
HTML can be sent back to the customer to inform about the situation.
2023-03-06 05:51:49 +01:00
Xavier Del Campo Romero 4cd577afa9
Perform some minor optimizations 2023-03-06 00:59:07 +01:00
Xavier Del Campo Romero d26f046fc9
Initial commit 2023-02-28 01:43:56 +01:00