Deploying WebDAV on Debian 10 using WsgiDAV

Introduction

Web Distributed Authoring and Versioning (WebDAV) is a HTTP extension that provides a framework for remotely creating and modifying files on a server. WsgiDAV is a WebDAV server written in python. This guide will help you through the installation of WsgiDAV version 3.0 on a Vultr server running Debian 10. We will also obtain an SSL certificate to provide a secure connection as well as PAM authentication.

Prerequisites

  • A Debian 10 system to which you have privileged access (via the root user or any sudo user.)
  • The $EDITOR environment variable must be set to a text editor of your choice.
  • A registered domain name is required. Its nameservers must be configured with an A record pointing to your server's IPv4 address, and optionally an AAAA record pointing to the IPv6 address.
  • Familiarity with the YAML syntax is recommended.

The placeholder dav.example.com will be used for your server's domain name.

Installation

SSL certificate

We will start by updating the system and obtaining a free SSL certificate from Let's Encrypt. To do so, first update your system and install the certbot utility:

 sudo apt update
 sudo apt upgrade -y
 sudo apt install -y certbot

In the command below, replace dav.example.com and email@domain.tld with your domain name and email address respectively before executing it:

sudo certbot certonly --standalone --agree-tos -m email@domain.tld -d dav.example.com

Your server will be sent a challenge to verify that you control the domain name specified. If it succeeds, the certificate will be issued and saved, along with other files such as the private key, under /etc/letsencrypt/live/dav.example.com/.

Installing WsgiDAV

First, install the python package manager pip:

sudo apt update
sudo apt install -y python3-pip

WsgiDAV requires a HTTP server that supports WSGI. We will install the default option, which is Cheroot. We will also install the lxml python library, which tends to perform better than the XML library installed by default. The PAM (Pluggable Authentication Module) python3 library is needed as well. Install the required packages using the pip tool:

sudo pip3 install wsgidav cheroot lxml python-pam

Configuring WsgiDAV

The WsgiDAV executable is stored in /usr/local/bin, so we will place the configuration file in the /usr/local/etc directory. Download the sample configuration file with the following commands:

sudo mkdir -p /usr/local/etc
sudo wget https://github.com/mar10/wsgidav/raw/master/sample_wsgidav.yaml -O /usr/local/etc/wsgidav.yaml

Open it with your editor:

sudo $EDITOR /usr/local/etc/wsgidav.yaml

Find the following lines in the "SSL Support" section:

# ssl_certificate: "wsgidav/server/sample_bogo_server.crt"
# ssl_private_key: "wsgidav/server/sample_bogo_server.key"
# ssl_certificate_chain: null

Replace them with the following:

ssl_certificate: "/etc/letsencrypt/live/dav.example.com/cert.pem"
ssl_private_key: "/etc/letsencrypt/live/dav.example.com/privkey.pem"
ssl_certificate_chain: "/etc/letsencrypt/live/dav.example.com/chain.pem"

Next, we will configure the share paths by mapping HTTP paths (such as /) to corresponding locations on the filesystem (such as /var/www/dir1). For demonstration purposes, we will share two directories, one of which will be read-only. Find the provider_mapping block in the "SHARES" section:

provider_mapping:
    "/": "/path/to/share1"
    "/pub":
        root: "/path/to/share2"
        readonly: true
    "/share3":
        provider: path.to.CustomDAVProviderClass
        args: ["/path/to/share3", "second_arg"]
        kwargs: {"another_arg": 42}

Replace it:

provider_mapping:
    "/":
    root: "/var/www/html/documents"
    readonly: false
"/reports":
    root: "/var/www/html/reports"
    readonly: true

With these mappings, https://dav.example.com:8080/ will correspond to the /var/www/html/documents directory on the server, while https://dav.example.com:8080/reports will map to /var/www/html/reports with no write access.

For authentication, we will use the PAM driver. This removes the need for separate WebDAV user accounts and allows system users to login using their usual credentials.

In the "AUTHENTICATION" section, find these lines:

accept_basic: true
accept_digest: true
default_to_digest: true
domain_controller: null

Replace them with the following:

accept_basic: true
accept_digest: false
default_to_digest: false
domain_controller: wsgidav.dc.pam_dc.PAMDomainController

You can now test your server:

sudo wsgidav -c /usr/local/etc/wsgidav.yaml

Open https://dav.example.com:8080/ in your web browser. Since we configured PAM authentication, you will need to login with your Linux user account. Use CTRL + C to stop the server before proceeding.

Installing as a service

In order to run your WebDAV server as a system service managed by systemd, create a unit file:

sudo $EDITOR /etc/systemd/system/wsgidav.service

Enter the following:

[Unit]
Description=WsgiDAV WebDAV server
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/wsgidav -c /usr/local/etc/wsgidav.yaml
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=wsgidav_service

[Install]
WantedBy=multi-user.target

Then create a configuration file for the system logging service:

sudo $EDITOR /etc/rsyslog.d/wsgidav_service.conf

Populate the file with the following:

 if $programname == 'wsgidav_service' then /var/log/wsgidav.log
 & stop

Save and exit, then use the commands below to create the log file:

sudo touch /var/log/wsgidav.log
sudo chown root:adm /var/log/wsgidav.log

Finally, load the new systemd unit file and restart the logging service before starting WsgiDAV:

sudo systemctl daemon-reload
sudo systemctl restart rsyslog.service
sudo systemctl start wsgidav.service

You can now use systemctl to start, stop and restart your WebDAV server. WsgiDAV's standard output and error will be logged to /var/log/wsgidav.log, and can also be accessed using sudo journalctl -u wsgidav.service.

If you want the WebDAV server to start automatically at system boot time, execute:

 sudo systemctl enable wsgidav.service

Further reading

Dejar un comentario

ZPanel y Sentora en CentOS 6 x64

ZPanel y Sentora en CentOS 6 x64

ZPanel, un panel de control de alojamiento web popular, se bifurcó en 2014 a un nuevo proyecto llamado Sentora. Aprende a instalar Sentora en tu servidor con este tutorial.

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Aprende cómo instalar Vtiger CRM, una aplicación de gestión de relaciones con el cliente, en CentOS 7 para aumentar tus ventas y mejorar el servicio al cliente.

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Esta guía completa le mostrará cómo configurar un servidor Counter-Strike 1.6 en Linux, optimizando el rendimiento y la seguridad para el mejor juego. Aprende los pasos más recientes aquí.

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

Los ataques de ransomware van en aumento, pero ¿puede la IA ayudar a lidiar con el último virus informático? ¿Es la IA la respuesta? Lea aquí, sepa que la IA es una bendición o una perdición

ReactOS: ¿Es este el futuro de Windows?

ReactOS: ¿Es este el futuro de Windows?

ReactOS, un sistema operativo de código abierto y gratuito, está aquí con la última versión. ¿Puede satisfacer las necesidades de los usuarios de Windows de hoy en día y acabar con Microsoft? Averigüemos más sobre este estilo antiguo, pero una experiencia de sistema operativo más nueva.

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Whatsapp finalmente lanzó la aplicación de escritorio para usuarios de Mac y Windows. Ahora puede acceder a Whatsapp desde Windows o Mac fácilmente. Disponible para Windows 8+ y Mac OS 10.9+

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

Lea esto para saber cómo la Inteligencia Artificial se está volviendo popular entre las empresas de pequeña escala y cómo está aumentando las probabilidades de hacerlas crecer y dar ventaja a sus competidores.

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

Recientemente, Apple lanzó macOS Catalina 10.15.4, una actualización complementaria para solucionar problemas, pero parece que la actualización está causando más problemas que conducen al bloqueo de las máquinas Mac. Lee este artículo para obtener más información

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

¿Qué es un sistema de archivos de diario y cómo funciona?

¿Qué es un sistema de archivos de diario y cómo funciona?

Nuestra computadora almacena todos los datos de una manera organizada conocida como sistema de archivos de diario. Es un método eficiente que permite a la computadora buscar y mostrar archivos tan pronto como presiona buscar.