Commit Graph

13 Commits

Author SHA1 Message Date
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