server

command module
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

The Defacto2 application is a self-contained web server first devised in 2023. It is built with the Go language and can be easily compiled for significant server operating systems. The application relies on a PostgreSQL database setup for data queries using a PostgreSQL database connection.

All configurations and modifications to this web application's default settings are through system environment variables.

While you can compile the application to target Windows environments, it is ill-advised as it needs to work correctly with NTFS file paths. Instead, it is advisable to use Windows Subsystem for Linux.

Usage

While it will not be fully functional without directory paths or a database connection, the web server will work out of the box without any configuration provided.

Usage:

defacto2-server

The web server should be available at the unencrypted address, http://localhost:1323.

Commands

There are only two additional commands: one lists the accessible addresses the web server listens on, and the other lists the detected settings.

Usage:

defacto2-server [command]

The commands are:

address
		List the IP, hostname and port addresses the server is listening on.
config
		List the server configuration options and settings.

Flags

Usage:

defacto2-server [flags]

The flags are:

--help
		Print the basic command help and exit.
--version
		Print the application version and exit.

Configuration

All application configurations and default modifications are made with environment variables. In systemd, these can be provided using a system service (unit) file, using the Environment assignment under the Service type.

You can use an example of a defacto2.service unit file, which is found in the source code repository in the init/ directory.

A partial example of a defacto2.service unit file:

[Unit]
Description=Defacto2

[Service]
Environment="D2_MATCH_HOST=localhost"
Environment="D2_DATABASE_URL=postgres://root:example@localhost:5432/defacto2_ps"
Environment="D2_PROD_MODE=true" "D2_READ_ONLY=false" "D2_NO_CRAWL=true"

Database

This application expects a PostgreSQL database with the Defacto2 "files" table and the connection URL configured in the D2_DATABASE_URL environment variable.

The database connection URL uses a configuration by default but will fail to connect unless the testing Postgres database matches the same values. In production, you must provide a secure and working connection D2_DATABASE_URL variable. The default database connection URL is: postgres://root:example@localhost:5432/defacto2_ps

Some examples:

// local connection
D2_DATABASE_URL=postgres://username:password@localhost:5432/database_name

// Docker connection
D2_DATABASE_URL=postgres://username:password@host.docker.internal:5432/database_name

File assets

The web server uses the following environment variables to offer file downloads, software emulation, web server previews, and thumbnails. All paths must be absolute and valid and must contain tens of thousands of asset files named with universal unique identifiers. The website will turn off the associated feature if the provided path is invalid or contains unexpected files.

  • D2_DIR_DOWNLOAD is the absolute path to the file downloads directory.

  • D2_DIR_PREVIEW is the absolute path to the image screenshots directory.

  • D2_DIR_THUMBNAIL is the absolute path to the squared, image thumbnails directory.

  • D2_DIR_ORPHANED is the absolute path to the orphaned files directory.

  • D2_DIR_EXTRA is the absolute path to the extra files directory.

An example download setting:

D2_DIR_DOWNLOAD=/mnt/volume/assets/downloads

Log file storage

When the application runs in production mode, errors or warnings caused by the web server are saved to a log file. The location can be provided using the D2_DIR_LOG variable, which must point to an absolute directory path. Otherwise, the server will create a subdirectory using os.UserConfigDir.

An example log setting:

D2_DIR_LOG=/var/log/defacto2-server

Administrator accounts

The web server uses Google OAuth2 for administrator logins. The server requires a Google OAuth2 client ID to validate admin logins, which is provided in the D2_GOOGLE_CLIENT_ID environment variable.

The server also requires a list of Google OAuth2 user accounts, which is provided in the D2_GOOGLE_ACCOUNTS environment variable. A user account is the JWT "sub" field assertion in the form of a unique integer.

An example accounts setting:

D2_GOOGLE_CLIENT_ID=123-abc.apps.googleusercontent.com
D2_GOOGLE_ACCOUNTS=1234567890,0987654321

Production mode

The production mode is on by default and should be enabled in production as it has the following effects.

  1. It runs file assets and database entry checks on startup.
  2. Any errors or warnings get appended to a log file.
  3. If the server crashes, it will recover instead of exiting the program.
  4. Turns off the Uploader form debug feature.
  5. Force the administrator logins to be served only over encrypted HTTPS protocols.

To turn off production mode:

D2_PROD_MODE=false

Read-only mode

Read-only mode blocks any website feature that writes to the server database, including the Uploader and administrator database entry edits.

To turn off the read-only mode:

D2_READ_ONLY=true

No crawl mode

The no crawler mode inserts an X-Robots-Tag with the "none" value for all network response headers sent by the web server. The header advises search engines and other bots not to index the website or assets.

To enable no crawl mode:

D2_NO_CRAWL=true

Quiet startup

When quiet is turned on, the majority of startup messages are suppressed. This option is meant for systemd to avoid spamming its log.

To enable quiet mode:

D2_QUIET=true

HTTP and HTTPS

The web server will listen to all HTTP requests on port 1323 without configuration. The value can be changed with the D2_HTTP_PORT variable, which can be set to 0 to disable HTTP.

The D2_TLS_PORT variable, which is turned off by default, allows for an encrypted HTTPS service. In a production situation, you should supply the D2_TLS_CERT and D2_TLS_KEY variables. These should have an absolute path to a TLS (Transport Layer Security) certificate file and key file. If no certificate or key is provided, a dummy certificate will be used, but browsers will reject these.

If the D2_HTTP_PORT and the D2_TLS_PORT values are set to 0, the web server will override to enable port 1323 for HTTP connections. On Linux, ports 1-1023 are considered well-known and reserved for the operating system.

Providing a D2_MATCH_HOST variable can restrict the web server from listening to HTTP and HTTPS requests from a single IP address or host. Otherwise, the web server listens to all requests on the ports.

An example configuration to exclusively use HTTPS and only accept local connections:

D2_HTTP_PORT=0
D2_MATCH_HOST=localhost
D2_TLS_PORT=443
D2_TLS_CERT=/etc/ssl/certs/localhost.crt
D2_TLS_KEY=/etc/ssl/private/localhost.key

Directories

Path Synopsis
Package flags provides the command line interface for the Defacto2 server application.
Package flags provides the command line interface for the Defacto2 server application.
Package handler provides the HTTP handlers for the Defacto2 website.
Package handler provides the HTTP handlers for the Defacto2 website.
app
Package app handles the routes and views for the Defacto2 website.
Package app handles the routes and views for the Defacto2 website.
app/internal/extensions
Package extensions provides a list of file extensions used by some functions in app.
Package extensions provides a list of file extensions used by some functions in app.
app/internal/filerecord
Package filerecord provides functions for the file model which is an artifact record.
Package filerecord provides functions for the file model which is an artifact record.
app/internal/fileslice
Package fileslice provides functions that return model FileSlices, which are multiple artifact records.
Package fileslice provides functions that return model FileSlices, which are multiple artifact records.
app/internal/simple
Package simple provides functions for handling string or integer input data.
Package simple provides functions for handling string or integer input data.
app/remote
Package remote provides the remote download and update of artifact data from third-party sources such as API's.
Package remote provides the remote download and update of artifact data from third-party sources such as API's.
cache
Package cache provides a lightweight engine for storing key/value pairs.
Package cache provides a lightweight engine for storing key/value pairs.
demozoo
Package demozoo handles the retrieval of [production records] from the [Demozoo] API and the extraction of relevant data for the Defacto2 website.
Package demozoo handles the retrieval of [production records] from the [Demozoo] API and the extraction of relevant data for the Defacto2 website.
download
Package download handles the client file downloads.
Package download handles the client file downloads.
form
Package form provides functions for providing data for form and input elements.
Package form provides functions for providing data for form and input elements.
html3
Package html3 renders the html3 sub-route of the website.
Package html3 renders the html3 sub-route of the website.
html3/ext
Package ext contains common filename extensions used by the file records.
Package ext contains common filename extensions used by the file records.
htmx
Package htmx handles the routes and views for the AJAX responses using the htmx library.
Package htmx handles the routes and views for the AJAX responses using the htmx library.
jsdos
Package jsdos configures the js-dos v6.22 emulator.
Package jsdos configures the js-dos v6.22 emulator.
jsdos/msdos
Package msdos provides functions for working with MS-DOS FAT 12/16 file system filenames.
Package msdos provides functions for working with MS-DOS FAT 12/16 file system filenames.
pouet
Package pouet provides production, user voting data sourced from the Pouet website API.
Package pouet provides production, user voting data sourced from the Pouet website API.
readme
Package readme provides functions for reading and suggesting readme files.
Package readme provides functions for reading and suggesting readme files.
render
Package render provides the file content rendering for the web server.
Package render provides the file content rendering for the web server.
sess
Package sess provides functions for handling session and cookies.
Package sess provides functions for handling session and cookies.
site
Package web proves links and titles for recommended websites.
Package web proves links and titles for recommended websites.
sixteen
Package sixteen provides data about releasers and groups on the 16colors website.
Package sixteen provides data about releasers and groups on the 16colors website.
internal
command
Package command provides interfaces for the shell commands and programs on the host.
Package command provides interfaces for the shell commands and programs on the host.
config
Package config manages the environment variable configurations.
Package config manages the environment variable configurations.
postgres
Package postgres connects to and interacts with a PostgreSQL database server.
Package postgres connects to and interacts with a PostgreSQL database server.
tags
Package tags are categories and platform metadata used to classify the served files.
Package tags are categories and platform metadata used to classify the served files.
zaplog
Package zaplog uses the zap logging library for application logs.
Package zaplog uses the zap logging library for application logs.
Package model provides a database model for the Defacto2 website.
Package model provides a database model for the Defacto2 website.
fix
Package fix contains functions for repairing the database data.
Package fix contains functions for repairing the database data.
html3
Package htm3 is a sub-package of the model package that should only be used by the html3 handler.
Package htm3 is a sub-package of the model package that should only be used by the html3 handler.
querymod
Package querymod provides the query mod expressions for the file database.
Package querymod provides the query mod expressions for the file database.
Package runner is used to build and minify the css and js files.
Package runner is used to build and minify the css and js files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL