~rbdr/ngx_http_office_hours_filter_module

A victory for the server's labor rights: An nginx module that allows you to serve your content only during office hours.
b11e9118 — Ruben Beltran del Rio 9 months ago
Formatting
8b830d84 — Ruben Beltran del Rio 9 months ago
Add support for office_hours_additional_information
f34685bb — Ruben Beltran del Rio 9 months ago
Use snprintf for safety

clone

read-only
https://git.sr.ht/~rbdr/ngx_http_office_hours_filter_module
read/write
git@git.sr.ht:~rbdr/ngx_http_office_hours_filter_module

You can also use your local clone with git send-email.

#Nginx Office Hours

A victory for the server's labor rights: An nginx module that allows you to serve your content only during office hours.

#Using the directive

The office_hours directive expects a list of time ranges separated by spaces. The first range will be used as the default, and the rest will be read from right to left, ending with sunday

#Example 1: Open 24 hours

Don't use this directive.

#Example 2: Open every day from 08:30 AM to 7:00 PM

office_hours 8:30-19;

Some things worth noting here: the format of time ranges uses 24 hour style, so no pesky AMs or PMs. Likewise, minutes are optional. Finally, note that since only one range was defined, this is applied to all days of the week. Another noteworthy

#Example 3: Open every day from 08:30 AM to 7:00 PM, but closed sundays

office_hours 8:30-19 closed;

Two important things here: first notice that the closed keyword specifies that the server is closed on a specific day; second, notice how the last element is used for sunday, while the first one still applies to Monday-Saturday.

#Example 4: Open weekdays from 08:30 AM to 7:00 PM, Saturdays 10:00 AM to 4:00 PM, closed on sundays

office_hours 8:30-19 10-16 closed;

Now hopefully you can see the pattern: The first time range applies to Monday-Friday, next one to Saturday and last one to Sunday.

#Example 5: Open weekdays from 08:30 AM to 7:00 PM, closed on thursdays, reduced hours on weekends.

office_hours 8:30-19 closed 8:30-19 10-16 10-16;

Since we had to specify from Thursday, we have to explicitly set the values for Friday, Saturday and Sunday.

#Example 6: Closed every day.

Uninstall nginx.

#Adding more information

This plugin also provides an office_hours_additional_information directive that lets you add informative HTML to the page that shows when outside office hours.

office_hours_additional_information "<h1>Additional Information></h1>
<p>Please do not email us asking to open the website 24/7. Send all complaints to friendship.quest/@ruben</p>"

#What you will need to get started

#Building the module

You can build office hours as a dynamic module. From the nginx source directory run:

./configure --add-dynamic-module=/path/to/ngx_http_office_hours_filter_module
make

For more information check the nginx docs

#Installing git hooks

This repo contains a pre-commit git hook so indent will run before every commit. Run make setup_hooks to install it.

#Further Improvements

  • Add support for double shifts in the same day
  • Add support for serving custom HTML when server is closed
  • Add support for timezones (currently only GMT)
  • Add support for public holidays
  • Add support to respect the time zone of the visitor and not just the server