From 86f2acce21bb28d21bc318b6bb9b7b0be8963b9a Mon Sep 17 00:00:00 2001 From: Luca Bognolo <11542801+BoGnY@users.noreply.github.com> Date: Mon, 13 May 2024 15:38:43 +0200 Subject: [PATCH] Updated name, README and LICENSE --- .ci/fuzzy.sh | 24 +++--- LICENSE.md | 6 +- Makefile | 24 +++--- README.md | 108 +++++++++++++------------ bin/{vhost-gen => vhost-generator} | 50 ++++++------ etc/conf.yml | 8 +- etc/templates/apache22.yml | 2 +- etc/templates/apache24.yml | 2 +- etc/templates/nginx.yml | 2 +- examples/conf.apache22.yml | 8 +- examples/conf.apache24.yml | 8 +- examples/conf.nginx.yml | 8 +- setup.py | 16 ++-- tests/check-errors-normal.sh | 10 +-- tests/check-errors-reverse.sh | 10 +-- tests/check-errors-template-normal.sh | 10 +-- tests/check-errors-template-reverse.sh | 10 +-- 17 files changed, 156 insertions(+), 150 deletions(-) rename bin/{vhost-gen => vhost-generator} (96%) mode change 100755 => 100644 diff --git a/.ci/fuzzy.sh b/.ci/fuzzy.sh index 818a9ff..71f3b36 100755 --- a/.ci/fuzzy.sh +++ b/.ci/fuzzy.sh @@ -43,14 +43,14 @@ function fuzzy() { ### ### 1 Argument ### - cmd="${MY_PATH}/../bin/vhost-gen -${arg1} ${val1}" + cmd="${MY_PATH}/../bin/vhost-generator -${arg1} ${val1}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" echo "${out}" exit 1 fi - cmd="${MY_PATH}/../bin/vhost-gen -p ${val1}" + cmd="${MY_PATH}/../bin/vhost-generator -p ${val1}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" @@ -61,14 +61,14 @@ function fuzzy() { ### ### 2 Arguments ### - cmd="${MY_PATH}/../bin/vhost-gen -${arg1} ${val1} -${arg2} ${val2}" + cmd="${MY_PATH}/../bin/vhost-generator -${arg1} ${val1} -${arg2} ${val2}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" echo "${out}" exit 1 fi - cmd="${MY_PATH}/../bin/vhost-gen -p ${val1} -n NAME" + cmd="${MY_PATH}/../bin/vhost-generator -p ${val1} -n NAME" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" @@ -79,14 +79,14 @@ function fuzzy() { ### ### 3 Arguments ### - cmd="${MY_PATH}/../bin/vhost-gen -${arg1} ${val1} -${arg2} ${val2} -${arg3} ${val3}" + cmd="${MY_PATH}/../bin/vhost-generator -${arg1} ${val1} -${arg2} ${val2} -${arg3} ${val3}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" echo "${out}" exit 1 fi - cmd="${MY_PATH}/../bin/vhost-gen -p ${val1} -n NAME -${arg3} ${val3}" + cmd="${MY_PATH}/../bin/vhost-generator -p ${val1} -n NAME -${arg3} ${val3}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" @@ -97,14 +97,14 @@ function fuzzy() { ### ### 4 Arguments ### - cmd="${MY_PATH}/../bin/vhost-gen -${arg1} ${val1} -${arg2} ${val2} -${arg3} ${val3} -${arg4} ${val4}" + cmd="${MY_PATH}/../bin/vhost-generator -${arg1} ${val1} -${arg2} ${val2} -${arg3} ${val3} -${arg4} ${val4}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" echo "${out}" exit 1 fi - cmd="${MY_PATH}/../bin/vhost-gen -p ${val1} -n NAME -${arg3} ${val3} -${arg4} ${val4}" + cmd="${MY_PATH}/../bin/vhost-generator -p ${val1} -n NAME -${arg3} ${val3} -${arg4} ${val4}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" @@ -115,14 +115,14 @@ function fuzzy() { ### ### 5 Arguments ### - cmd="${MY_PATH}/../bin/vhost-gen -${arg1} ${val1} -${arg2} ${val2} -${arg3} ${val3} -${arg4} ${val4} -${arg5} ${val5}" + cmd="${MY_PATH}/../bin/vhost-generator -${arg1} ${val1} -${arg2} ${val2} -${arg3} ${val3} -${arg4} ${val4} -${arg5} ${val5}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" echo "${out}" exit 1 fi - cmd="${MY_PATH}/../bin/vhost-gen -p ${val1} -n NAME -${arg3} ${val3} -${arg4} ${val4} -${arg5} ${val5}" + cmd="${MY_PATH}/../bin/vhost-generator -p ${val1} -n NAME -${arg3} ${val3} -${arg4} ${val4} -${arg5} ${val5}" out="$( eval "${cmd}" 2>&1 || true )" if errored "${out}"; then printf "[%04d] %s\n" "${count}" "${cmd}" @@ -137,12 +137,12 @@ function fuzzy() { ### Round 1 (Supported Options only) ### declare -a args=(c p n t s o) -declare -a vals="(./ ./etc ./etc/conf.yml ./examples/conf.nginx.yml ./examples/conf.apache22.yml ./examples/conf.apache24.yml ./etc/templates ../ ../etc ../etc/conf.yml ../examples/conf.nginx.yml ../examples/conf.apache22.yml ../examples/conf.apache24.yml ../etc/templates ../../ ../../etc ../../etc/conf.yml ../../examples/conf.nginx.yml ../../examples/conf.apache22.yml ../../examples/conf.apache24.yml ../../etc/templates /etc /etc/vhost-gen /etc/vhost-gen/conf.yml /etc/vhost-gen/templates)" +declare -a vals="(./ ./etc ./etc/conf.yml ./examples/conf.nginx.yml ./examples/conf.apache22.yml ./examples/conf.apache24.yml ./etc/templates ../ ../etc ../etc/conf.yml ../examples/conf.nginx.yml ../examples/conf.apache22.yml ../examples/conf.apache24.yml ../etc/templates ../../ ../../etc ../../etc/conf.yml ../../examples/conf.nginx.yml ../../examples/conf.apache22.yml ../../examples/conf.apache24.yml ../../etc/templates /etc /etc/vhost-generator /etc/vhost-generator/conf.yml /etc/vhost-generator/templates)" fuzzy ### ### Round 2 (Any Options) ### declare -a args="(a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9)" -declare -a vals="(c p n t -c -p -n -t -h -v ./ ./etc ./etc/conf.yml ./examples/conf.nginx.yml ./examples/conf.apache22.yml ./examples/conf.apache24.yml ./etc/templates ../ ../etc ../etc/conf.yml ../examples/conf.nginx.yml ../examples/conf.apache22.yml ../examples/conf.apache24.yml ../etc/templates ../../ ../../etc ../../etc/conf.yml ../../examples/conf.nginx.yml ../../examples/conf.apache22.yml ../../examples/conf.apache24.yml ../../etc/templates /etc /etc/vhost-gen /etc/vhost-gen/conf.yml /etc/vhost-gen/templates)" +declare -a vals="(c p n t -c -p -n -t -h -v ./ ./etc ./etc/conf.yml ./examples/conf.nginx.yml ./examples/conf.apache22.yml ./examples/conf.apache24.yml ./etc/templates ../ ../etc ../etc/conf.yml ../examples/conf.nginx.yml ../examples/conf.apache22.yml ../examples/conf.apache24.yml ../etc/templates ../../ ../../etc ../../etc/conf.yml ../../examples/conf.nginx.yml ../../examples/conf.apache22.yml ../../examples/conf.apache24.yml ../../etc/templates /etc /etc/vhost-generator /etc/vhost-generator/conf.yml /etc/vhost-generator/templates)" fuzzy diff --git a/LICENSE.md b/LICENSE.md index e55c847..8fe4470 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,8 @@ -MIT License +# MIT License -Copyright (c) 2017 cytopia +**Copyright (c) 2017 [cytopia](https://github.com/cytopia)** + +**Copyright (c) 2024 [bogny](https://github.com/bogny)** Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 6bc9c13..efbbd33 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ endif VERSION = 2.7 BINPATH = bin/ -BINNAME = vhost-gen +BINNAME = vhost-generator CONFIG = conf.yml TPLDIR = templates @@ -58,17 +58,17 @@ _lint-version: @echo "# -------------------------------------------------------------------- #" @echo "# Check version config" @echo "# -------------------------------------------------------------------- #" - @VERSION_VHOSTGEN=$$( grep -E '^VERSION = "v?[.0-9]+(-\w+)?"' $(BINPATH)$(BINNAME) | awk -F'"' '{print $$2}' || true ); \ + @VERSION_VHOSTGENERATOR=$$( grep -E '^VERSION = "v?[.0-9]+(-\w+)?"' $(BINPATH)$(BINNAME) | awk -F'"' '{print $$2}' || true ); \ VERSION_SETUP=$$( grep version= setup.py | awk -F'"' '{print $$2}' || true ); \ - if [ "$${VERSION_VHOSTGEN}" != "$${VERSION_SETUP}" ]; then \ + if [ "$${VERSION_VHOSTGENERATOR}" != "$${VERSION_SETUP}" ]; then \ echo "[ERROR] Version mismatch"; \ - echo "bin/vhost-gen: $${VERSION_VHOSTGEN}"; \ - echo "setup.py: $${VERSION_SETUP}"; \ + echo "bin/vhost-generator: $${VERSION_VHOSTGENERATOR}"; \ + echo "setup.py: $${VERSION_SETUP}"; \ exit 1; \ else \ echo "[OK] Version match"; \ - echo "bin/vhost-gen: $${VERSION_VHOSTGEN}"; \ - echo "setup.py: $${VERSION_SETUP}"; \ + echo "bin/vhost-generator: $${VERSION_VHOSTGENERATOR}"; \ + echo "setup.py: $${VERSION_SETUP}"; \ exit 0; \ fi \ @@ -231,13 +231,13 @@ install: @echo "Installing files" @echo "" @# Create directories - mkdir -p /etc/vhost-gen - mkdir -p /etc/vhost-gen/templates + mkdir -p /etc/vhost-generator + mkdir -p /etc/vhost-generator/templates @# Install binary install -m 0755 $(BINPATH)/$(BINNAME) /usr/bin/$(BINNAME) @# Install configs - install -m 0644 etc/$(CONFIG) /etc/vhost-gen/$(CONFIG) - install -m 0644 etc/$(TPLDIR)/*.yml /etc/vhost-gen/$(TPLDIR) + install -m 0644 etc/$(CONFIG) /etc/vhost-generator/$(CONFIG) + install -m 0644 etc/$(TPLDIR)/*.yml /etc/vhost-generator/$(TPLDIR) @echo "Installation complete:" @echo "----------------------------------------------------------------------" @echo "" @@ -245,7 +245,7 @@ install: uninstall: @echo "Removing files" @echo "" - rm -r /etc/vhost-gen + rm -r /etc/vhost-generator rm /usr/bin/$(BINNAME) @echo "Uninstallation complete:" @echo "----------------------------------------------------------------------" diff --git a/README.md b/README.md index fd7780f..0506589 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ -# vhost-gen +# vhost-generator [![](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) -[![PyPI](https://img.shields.io/pypi/v/vhost-gen)](https://pypi.org/project/vhost-gen/) -[![PyPI - Status](https://img.shields.io/pypi/status/vhost-gen)](https://pypi.org/project/vhost-gen/) -[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/vhost-gen)](https://pypi.org/project/vhost-gen/) -[![PyPI - Format](https://img.shields.io/pypi/format/vhost-gen)](https://pypi.org/project/vhost-gen/) -[![PyPI - Implementation](https://img.shields.io/pypi/implementation/vhost-gen)](https://pypi.org/project/vhost-gen/) -[![PyPI - License](https://img.shields.io/pypi/l/vhost-gen)](https://pypi.org/project/vhost-gen/) +[![PyPI](https://img.shields.io/pypi/v/vhost-generator)](https://pypi.org/project/vhost-generator/) +[![PyPI - Status](https://img.shields.io/pypi/status/vhost-generator)](https://pypi.org/project/vhost-generator/) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/vhost-generator)](https://pypi.org/project/vhost-generator/) +[![PyPI - Format](https://img.shields.io/pypi/format/vhost-generator)](https://pypi.org/project/vhost-generator/) +[![PyPI - Implementation](https://img.shields.io/pypi/implementation/vhost-generator)](https://pypi.org/project/vhost-generator/) +[![PyPI - License](https://img.shields.io/pypi/l/vhost-generator)](https://pypi.org/project/vhost-generator/) **Continuous Integration** -[![testing](https://github.com/devilbox/vhost-gen/workflows/testing/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Atesting) -[![fuzzing](https://github.com/devilbox/vhost-gen/workflows/fuzzing/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Afuzzing) +[![testing](https://github.com/wevtoolbox/vhost-generator/workflows/testing/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Atesting) +[![fuzzing](https://github.com/wevtoolbox/vhost-generator/workflows/fuzzing/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Afuzzing) -[![linting](https://github.com/devilbox/vhost-gen/workflows/linting/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Alinting) -[![pylint](https://github.com/devilbox/vhost-gen/workflows/pylint/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Apylint) -[![black](https://github.com/devilbox/vhost-gen/workflows/black/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Ablack) -[![mypy](https://github.com/devilbox/vhost-gen/workflows/mypy/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Amypy) -[![pycode](https://github.com/devilbox/vhost-gen/workflows/pycode/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Apycode) -[![pydoc](https://github.com/devilbox/vhost-gen/workflows/pydoc/badge.svg)](https://github.com/devilbox/vhost-gen/actions?query=workflow%3Apydoc) +[![linting](https://github.com/wevtoolbox/vhost-generator/workflows/linting/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Alinting) +[![pylint](https://github.com/wevtoolbox/vhost-generator/workflows/pylint/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Apylint) +[![black](https://github.com/wevtoolbox/vhost-generator/workflows/black/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Ablack) +[![mypy](https://github.com/wevtoolbox/vhost-generator/workflows/mypy/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Amypy) +[![pycode](https://github.com/wevtoolbox/vhost-generator/workflows/pycode/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Apycode) +[![pydoc](https://github.com/wevtoolbox/vhost-generator/workflows/pydoc/badge.svg)](https://github.com/wevtoolbox/vhost-generator/actions?query=workflow%3Apydoc) -**[vhost-gen](bin/vhost-gen)** will dynamically generate **vhost** or **reverse proxy** (with or without **websocket support**) configuration files for Apache 2.2, Apache 2.4 and Nginx depending on what you have set in [conf.yml](etc/conf.yml). This makes it easy to switch between different web servers while keeping the exact same functionality. +**[vhost-generator](bin/vhost-generator)** will dynamically generate **vhost** or **reverse proxy** (with or without **websocket support**) configuration files for Apache 2.2, Apache 2.4 and Nginx depending on what you have set in [conf.yml](etc/conf.yml). This makes it easy to switch between different web servers while keeping the exact same functionality. --- @@ -29,34 +29,34 @@ #### Via pip ```bash -pip install vhost-gen +pip install vhost-generator ``` #### From git **Note:** When using the Makefile, ensure that `pyyaml` is installed (`pip install pyyaml`). ```bash -git clone https://github.com/devilbox/vhost-gen -cd vhost-gen +git clone https://github.com/wevtoolbox/vhost-generator +cd vhost-generator sudo make install ``` ## What is all the fuzz? -Imagine you have to create virtual hosts for your web server over and over again. The only things that might change are document root, log files and server names and possibly some other minor changes. Instead of having to copy and adjust the server's vhost config file each time, you can use `vhost-gen` to generate them for you. By supporting different web server versions, it makes it also easy for you to switch back and forth between Apache 2.2, Apache 2.4 and Nginx. +Imagine you have to create virtual hosts for your web server over and over again. The only things that might change are document root, log files and server names and possibly some other minor changes. Instead of having to copy and adjust the server's vhost config file each time, you can use `vhost-generator` to generate them for you. By supporting different web server versions, it makes it also easy for you to switch back and forth between Apache 2.2, Apache 2.4 and Nginx. ```bash # vHost -$ vhost-gen -p /shared/httpd/www.example.com -n www.example.com +$ vhost-generator -p /shared/httpd/www.example.com -n www.example.com # Reverse Proxy -$ vhost-gen -r http://127.0.0.1:8080 -l / -n api.example.com +$ vhost-generator -r http://127.0.0.1:8080 -l / -n api.example.com ``` -**`vhost-gen`** alone simply creates a new virtual host every time you execute it. The goal however is to also automate the execution of the vhost generator itself. +**`vhost-generator`** alone simply creates a new virtual host every time you execute it. The goal however is to also automate the execution of the vhost generator itself. -#### 1. Reverse Proxy automation: [watcherp](https://github.com/devilbox/watcherp) +#### 1. Reverse Proxy automation: [watcherp](https://github.com/wevtoolbox/watcherp) -Here enters **[watcherp](https://github.com/devilbox/watcherp)** the game. **[watcherp](https://github.com/devilbox/watcherp)** listens for changes of port bindings and triggers a command whenever a new port has been bound or a binding has been removed. By combining these two tools, you could automate the creating of reverse proxies with one command: +Here enters **[watcherp](https://github.com/wevtoolbox/watcherp)** the game. **[watcherp](https://github.com/wevtoolbox/watcherp)** listens for changes of port bindings and triggers a command whenever a new port has been bound or a binding has been removed. By combining these two tools, you could automate the creating of reverse proxies with one command: ```bash # %n will be replaced by watcherp with the address a port has binded @@ -64,44 +64,44 @@ Here enters **[watcherp](https://github.com/devilbox/watcherp)** the game. **[wa # -p argument from watcherp specifies ports to ignore for changes $ watcherp -v \ -p 80,443 \ - -a "vhost-gen -r 'http://%n:%p' -l '/' -n '%n.example.com' -s" \ + -a "vhost-generator -r 'http://%n:%p' -l '/' -n '%n.example.com' -s" \ -d "rm /etc/nginx/conf.d/%n.example.com.conf" \ -t "nginx -s reload" ``` -#### 2. Virtual Host automation: [watcherd](https://github.com/devilbox/watcherd) +#### 2. Virtual Host automation: [watcherd](https://github.com/wevtoolbox/watcherd) -Here enters **[watcherd](https://github.com/devilbox/watcherd)** the game. **[watcherd](https://github.com/devilbox/watcherd)** listens for directory changes and triggers a command whenever a directory has been created or deleted. By combining these two tools, you could automate mass virtual hosting with one command: +Here enters **[watcherd](https://github.com/wevtoolbox/watcherd)** the game. **[watcherd](https://github.com/wevtoolbox/watcherd)** listens for directory changes and triggers a command whenever a directory has been created or deleted. By combining these two tools, you could automate mass virtual hosting with one command: ```bash # %n will be replaced by watcherd with the new directory name # %p will be replaced by watcherd with the new directory path $ watcherd -v \ -p /shared/httpd \ - -a "vhost-gen -p %p -n %n -s" \ + -a "vhost-generator -p %p -n %n -s" \ -d "rm /etc/nginx/conf.d/%n.conf" \ -t "nginx -s reload" ``` ##### More customization -Now it might look much more interesting. With the above command every vhost will have the exact same definition (except server name, document root and log file names). It is however also possible that every vhost could be customized depending on their needs. **`vhost-gen`** allows for additional overwriting its template. So inside each newly created folder you could have a sub-directory (e.g. `templates/`) with folder specific defines. Those custom templates would only be sourced if they exist: +Now it might look much more interesting. With the above command every vhost will have the exact same definition (except server name, document root and log file names). It is however also possible that every vhost could be customized depending on their needs. **`vhost-generator`** allows for additional overwriting its template. So inside each newly created folder you could have a sub-directory (e.g. `templates/`) with folder specific defines. Those custom templates would only be sourced if they exist: ```bash # Note: Adding -o %p/templates $ watcherd -v \ -p /shared/httpd \ - -a "vhost-gen -p %p -n %n -o %p/templates -s" \ + -a "vhost-generator -p %p -n %n -o %p/templates -s" \ -d "rm /etc/nginx/conf.d/%n.conf" \ -t "nginx -s reload" ``` ##### Making it robust -If you don't trust the stability of **[watcherd](https://github.com/devilbox/watcherd)** or want other means of controlling this daemon, you can utilize **[supervisord](http://supervisord.org/)**: +If you don't trust the stability of **[watcherd](https://github.com/wevtoolbox/watcherd)** or want other means of controlling this daemon, you can utilize **[supervisord](http://supervisord.org/)**: ```ini [program:watcherd] -command=watcherd -v -p /shared/httpd -a "vhost-gen -p %%p -n %%n -s" -d "rm /etc/nginx/custom.d/%%n.conf" -t "nginx -s reload" +command=watcherd -v -p /shared/httpd -a "vhost-generator -p %%p -n %%n -s" -d "rm /etc/nginx/custom.d/%%n.conf" -t "nginx -s reload" startsecs = 0 autorestart = true stdout_logfile=/dev/stdout @@ -114,14 +114,14 @@ stderr_events_enabled=true #### 3. Dockerizing -If you don't want to implement it yourself, there are already four fully functional dockerized containers available that offer automated mass virtual hosting based on `vhost-gen` and `watcherd`: +If you don't want to implement it yourself, there are already four fully functional dockerized containers available that offer automated mass virtual hosting based on `vhost-generator` and `watcherd`: -| Base Image | Web server | Repository | -|------------|------------|------------| -| Nginx stable (official) | nginx | https://github.com/devilbox/docker-nginx-stable | -| Nginx mainline (official) | nginx | https://github.com/devilbox/docker-nginx-mainline | -| Apache 2.2 (official) | Apache 2.2 | https://github.com/devilbox/docker-apache-2.2 | -| Apache 2.4 (official) | Apache 2.4 | https://github.com/devilbox/docker-apache-2.4 | +| Base Image | Web server | Repository | +|---------------------------|------------|-----------------------------------------------------| +| Nginx stable (official) | nginx | https://github.com/wevtoolbox/docker-nginx-stable | +| Nginx mainline (official) | nginx | https://github.com/wevtoolbox/docker-nginx-mainline | +| Apache 2.2 (official) | Apache 2.2 | https://github.com/wevtoolbox/docker-apache-2.2 | +| Apache 2.4 (official) | Apache 2.4 | https://github.com/wevtoolbox/docker-apache-2.4 | ## Insights @@ -157,17 +157,17 @@ If you are not satisfied with the default definitions for the webserver configur * vHost name is specified as a command line argument * vHost templates for major webservers are defined in etc/templates * vHost templates contain variables that must be replaced -* Webserver type/version is defined in /etc/vhost-gen/conf.yml -* Variable replacer are defined in /etc/vhost-gen/conf.yml +* Webserver type/version is defined in /etc/vhost-generator/conf.yml +* Variable replacer are defined in /etc/vhost-generator/conf.yml * Additional variable replacer can also be defined (`-o`) **The following describes the program flow:** -1. [vhost-gen](bin/vhost-gen) will read /etc/vhost-gen/conf.yml to get defines and webserver type/version +1. [vhost-generator](bin/vhost-generator) will read /etc/vhost-generator/conf.yml to get defines and webserver type/version 2. Base on the webserver version/type, it will read etc/templates/.yml template 3. Variables in the chosen template are replaced 4. The vHost name (`-n`) is also placed into the template -5. Template is written to webserver's config location (defined in /etc/vhost-gen/conf.yml) +5. Template is written to webserver's config location (defined in /etc/vhost-generator/conf.yml) ## Usage @@ -238,13 +238,13 @@ If you are not satisfied with the `Allow from all` permissions, simply rewrite t #### Available command line options ```bash -Usage: vhost-gen -p|r -n [-l -c -t -o -d -s -v] - vhost-gen --help - vhost-gen --version +Usage: vhost-generator -p|r -n [-l -c -t -o -d -s -v] + vhost-generator --help + vhost-generator --version -vhost-gen will dynamically generate vhost configuration files +vhost-generator will dynamically generate vhost configuration files for Nginx, Apache 2.2 or Apache 2.4 depending on what you have set -in /etc/vhost-gen/conf.yml +in /etc/vhost-generator/conf.yml Required arguments: -p|r You need to choose one of the mutually exclusive arguments. @@ -267,10 +267,10 @@ Optional arguments: -m both: Generate http and https version -m redir: Generate https version and make http redirect to https -c Path to global configuration file. - If not set, the default location is /etc/vhost-gen/conf.yml + If not set, the default location is /etc/vhost-generator/conf.yml If no config is found, a default is used with all features turned off. -t Path to global vhost template directory. - If not set, the default location is /etc/vhost-gen/templates/ + If not set, the default location is /etc/vhost-generator/templates/ If vhost template files are not found in this directory, the program will abort. -o Path to local override vhost template directory. @@ -302,8 +302,10 @@ This is an open source project and done in spare time. If you want to help out y * Whatever else you can imagine of -## License +## 📄 License **[MIT License](LICENSE.md)** -Copyright (c) 2017 [cytopia](https://github.com/cytopia) +Copyright (c) 2017 **[cytopia](https://github.com/cytopia)** + +Copyright (c) 2024 **[bogny](https://github.com/bogny)** diff --git a/bin/vhost-gen b/bin/vhost-generator old mode 100755 new mode 100644 similarity index 96% rename from bin/vhost-gen rename to bin/vhost-generator index d28f5b5..a4635e0 --- a/bin/vhost-gen +++ b/bin/vhost-generator @@ -4,6 +4,8 @@ # The MIT License (MIT) # # Copyright (c) 2017 cytopia +# +# Copyright (c) 2024 wevtoolbox """ vHost creator for Apache 2.2, Apache 2.4 and Nginx. @@ -27,14 +29,14 @@ if os.environ.get("MYPY_CHECK", False): # -------------------------------------------------------------------------------------------------- # Globals # -------------------------------------------------------------------------------------------------- -APPNAME = "vhost-gen" -APPREPO = "https://github.com/devilbox/vhost-gen" -VERSION = "1.0.10" -RELDATE = "2022-12-31" +APPNAME = "vhost-generator" +APPREPO = "https://github.com/wevtoolbox/vhost-generator" +VERSION = "1.0.11" +RELDATE = "2024-05-13" # Default paths -CONFIG_PATH = "/etc/vhost-gen/conf.yml" -TEMPLATE_DIR = "/etc/vhost-gen/templates" +CONFIG_PATH = "/etc/vhost-generator/conf.yml" +TEMPLATE_DIR = "/etc/vhost-generator/templates" # stdout/stderr log paths STDOUT_ACCESS = "/tmp/www-access.log" @@ -91,13 +93,13 @@ def log(level, message, verbosity): # stime = time.strftime("%Y-%m-%d %H:%M:%S") if level == 0: - print("vhost-gen: \x1b[31;21m[ERR] %s\x1b[0m" % (message), file=sys.stderr) + print("vhost-generator: \x1b[31;21m[ERR] %s\x1b[0m" % (message), file=sys.stderr) elif level == 1: - print("vhost-gen: \x1b[33;21m[WARN] %s\x1b[0m" % (message), file=sys.stderr) + print("vhost-generator: \x1b[33;21m[WARN] %s\x1b[0m" % (message), file=sys.stderr) elif level == 2 and verbosity >= 1: - print("vhost-gen: [INFO] %s" % (message), file=sys.stderr) + print("vhost-generator: [INFO] %s" % (message), file=sys.stderr) elif level == 3 and verbosity >= 2: - print("vhost-gen: [DBG] %s" % (message), file=sys.stderr) + print("vhost-generator: [DBG] %s" % (message), file=sys.stderr) def print_help(): @@ -105,20 +107,20 @@ def print_help(): """Show program help.""" print( """ -Usage: vhost-gen -p|r -n [-l -c -t -o -d -s -v] - vhost-gen --help - vhost-gen --version +Usage: vhost-generator -p|r -n [-l -c -t -o -d -s -v] + vhost-generator --help + vhost-generator --version -vhost-gen will dynamically generate vhost configuration files +vhost-generator will dynamically generate vhost configuration files for Nginx, Apache 2.2 or Apache 2.4 depending on what you have set -in /etc/vhost-gen/conf.yml +in /etc/vhost-generator/conf.yml Required arguments: -p|r You need to choose one of the mutually exclusive arguments. -p: Path to document root. -r: http(s)://Host:Port for reverse proxy. -r: ws(s)://Host:Port for reverse proxy with websocket support. - Depening on the choice, it will either generate a document serving + Depending on the choice, it will either generate a document serving vhost or a reverse proxy vhost. Note, when using -p, this can also have a suffix directory to be set in conf.yml @@ -134,16 +136,16 @@ Optional arguments: -m both: Generate http and https version -m redir: Generate https version and make http redirect to https -c Path to global configuration file. - If not set, the default location is /etc/vhost-gen/conf.yml + If not set, the default location is /etc/vhost-generator/conf.yml If no config is found, a default is used with all features turned off. -t Path to global vhost template directory. - If not set, the default location is /etc/vhost-gen/templates/ + If not set, the default location is /etc/vhost-generator/templates/ If vhost template files are not found in this directory, the program will abort. -o Path to local override vhost template directory. This is used as a secondary template directory and definitions found here will be merged with the ones found in the global template directory. - Note, definitions in local vhost teplate directory take precedence over + Note, definitions in local vhost template directory take precedence over the ones found in the global template directory. -d Make this vhost the default virtual host. Note, this will also change the server_name directive of nginx to '_' @@ -163,9 +165,9 @@ Misc arguments: def print_version(): # type: () -> None """Show program version.""" - print("%s: Version v%s (%s) by cytopia" % (APPNAME, VERSION, RELDATE)) - print("") - print("") + print("%s: Version v%s (%s) by wevtoolbox" % (APPNAME, VERSION, RELDATE)) + print("") + print("") print("The MIT License (MIT)") @@ -768,7 +770,7 @@ def vhost_get_denies(config, template, verbose): def vhost_get_server_status(config, template, verbose): # type: (Dict[str, Any], Dict[str, Any], int) -> str - """Get virtual host server status directivs.""" + """Get virtual host server status directives.""" status = "" enable = config["vhost"]["server_status"]["enable"] @@ -1107,7 +1109,7 @@ def main(argv): # Load template succ, template, err_tpl = load_template(tpl_dir, o_tpl_dir, config["server"], verbose) if not succ: - log(0, "Error loading tempalte: {}".format(err_tpl), verbose) + log(0, "Error loading template: {}".format(err_tpl), verbose) log(0, "Type --help for help", verbose) sys.exit(1) diff --git a/etc/conf.yml b/etc/conf.yml index 94f8b75..66f3560 100644 --- a/etc/conf.yml +++ b/etc/conf.yml @@ -1,8 +1,8 @@ --- # Generic vhost generator configuration file. -# Location: /etc/vhost-gen/conf.yml +# Location: /etc/vhost-generator/conf.yml # -# See: https://github.com/devilbox/vhost-gen +# See: https://github.com/wevtoolbox/vhost-generator # # If not specified or file is missing the following # default values will be merged to your current (if any) @@ -77,13 +77,13 @@ vhost: ssl_port: 443 # The virtual host name is specified as an command line argument - # to vhost-gen via '-n', however it is possible + # to vhost-generator via '-n', however it is possible # to prepend and/or append additional name strings. name: prefix: suffix: .loc # The document root directory is specified as an command line argument - # to vhost-gen via '-p', however it is possible + # to vhost-generator via '-p', however it is possible # to prepend another subdirectory here. docroot: suffix: htdocs diff --git a/etc/templates/apache22.yml b/etc/templates/apache22.yml index ca65395..dc2f0c7 100644 --- a/etc/templates/apache22.yml +++ b/etc/templates/apache22.yml @@ -1,6 +1,6 @@ --- -# Apache 2.2 vHost Template defintion for vhost-gen.py +# Apache 2.2 vHost Template definition for vhost-generator.py # # The 'feature' section contains optional features that can be enabled via # conf.yml and will then be replaced into the main vhost ('structure' section) diff --git a/etc/templates/apache24.yml b/etc/templates/apache24.yml index c58eacf..bae87ae 100644 --- a/etc/templates/apache24.yml +++ b/etc/templates/apache24.yml @@ -1,6 +1,6 @@ --- -# Apache 2.4 vHost Template defintion for vhost-gen.py +# Apache 2.4 vHost Template definition for vhost-generator.py # # The 'feature' section contains optional features that can be enabled via # conf.yml and will then be replaced into the main vhost ('structure' section) diff --git a/etc/templates/nginx.yml b/etc/templates/nginx.yml index 5d0de86..b012328 100644 --- a/etc/templates/nginx.yml +++ b/etc/templates/nginx.yml @@ -1,6 +1,6 @@ --- -# Nginx vHost Template defintion for vhost-gen.py +# Nginx vHost Template definition for vhost-generator.py # # The 'feature' section contains optional features that can be enabled via # conf.yml and will then be replaced into the main vhost ('structure' section) diff --git a/examples/conf.apache22.yml b/examples/conf.apache22.yml index 99c5c00..758f02a 100644 --- a/examples/conf.apache22.yml +++ b/examples/conf.apache22.yml @@ -1,8 +1,8 @@ --- # Generic vhost generator configuration file. -# Location: /etc/vhost-gen/conf.yml +# Location: /etc/vhost-generator/conf.yml # -# See: https://github.com/devilbox/vhost-gen +# See: https://github.com/wevtoolbox/vhost-generator # # If not specified or file is missing the following # default values will be merged to your current (if any) @@ -77,13 +77,13 @@ vhost: ssl_port: 443 # The virtual host name is specified as an command line argument - # to vhost-gen via '-n', however it is possible + # to vhost-generator via '-n', however it is possible # to prepend and/or append additional name strings. name: prefix: suffix: .loc # The document root directory is specified as an command line argument - # to vhost-gen via '-p', however it is possible + # to vhost-generator via '-p', however it is possible # to prepend another subdirectory here. docroot: suffix: htdocs diff --git a/examples/conf.apache24.yml b/examples/conf.apache24.yml index 0426502..d3d4c57 100644 --- a/examples/conf.apache24.yml +++ b/examples/conf.apache24.yml @@ -1,8 +1,8 @@ --- # Generic vhost generator configuration file. -# Location: /etc/vhost-gen/conf.yml +# Location: /etc/vhost-generator/conf.yml # -# See: https://github.com/devilbox/vhost-gen +# See: https://github.com/wevtoolbox/vhost-generator # # If not specified or file is missing the following # default values will be merged to your current (if any) @@ -77,13 +77,13 @@ vhost: ssl_port: 443 # The virtual host name is specified as an command line argument - # to vhost-gen via '-n', however it is possible + # to vhost-generator via '-n', however it is possible # to prepend and/or append additional name strings. name: prefix: suffix: .loc # The document root directory is specified as an command line argument - # to vhost-gen via '-p', however it is possible + # to vhost-generator via '-p', however it is possible # to prepend another subdirectory here. docroot: suffix: htdocs diff --git a/examples/conf.nginx.yml b/examples/conf.nginx.yml index 94f8b75..66f3560 100644 --- a/examples/conf.nginx.yml +++ b/examples/conf.nginx.yml @@ -1,8 +1,8 @@ --- # Generic vhost generator configuration file. -# Location: /etc/vhost-gen/conf.yml +# Location: /etc/vhost-generator/conf.yml # -# See: https://github.com/devilbox/vhost-gen +# See: https://github.com/wevtoolbox/vhost-generator # # If not specified or file is missing the following # default values will be merged to your current (if any) @@ -77,13 +77,13 @@ vhost: ssl_port: 443 # The virtual host name is specified as an command line argument - # to vhost-gen via '-n', however it is possible + # to vhost-generator via '-n', however it is possible # to prepend and/or append additional name strings. name: prefix: suffix: .loc # The document root directory is specified as an command line argument - # to vhost-gen via '-p', however it is possible + # to vhost-generator via '-p', however it is possible # to prepend another subdirectory here. docroot: suffix: htdocs diff --git a/setup.py b/setup.py index 28e55f5..01089e3 100644 --- a/setup.py +++ b/setup.py @@ -5,23 +5,23 @@ long_description = fh.read() setup( - name="vhost-gen", + name="vhost-generator", version="1.0.10", description="Configurable vHost generator for Apache 2.2, Apache 2.4 and Nginx.", license="MIT", long_description=long_description, long_description_content_type="text/markdown", - author="cytopia", - author_email="cytopia@everythingcli.org", - url="https://github.com/devilbox/vhost-gen", + author="wevtoolbox", + author_email="wevtoolbox@gmail.com", + url="https://github.com/wevtoolbox/vhost-generator", install_requires=["pyyaml", "future"], scripts=[ - "bin/vhost-gen" + "bin/vhost-generator" ], project_urls={ - 'Source Code': 'https://github.com/devilbox/vhost-gen', - 'Documentation': 'https://devilbox.readthedocs.io/en/latest/', - 'Bug Tracker': 'https://github.com/devilbox/vhost-gen/issues', + 'Source Code': 'https://github.com/wevtoolbox/vhost-generator', + 'Documentation': 'https://wevtoolbox.readthedocs.io/en/latest/', + 'Bug Tracker': 'https://github.com/wevtoolbox/vhost-generator/issues', }, classifiers=[ # https://pypi.org/classifiers/ diff --git a/tests/check-errors-normal.sh b/tests/check-errors-normal.sh index 2e6a6fd..03d00f3 100755 --- a/tests/check-errors-normal.sh +++ b/tests/check-errors-normal.sh @@ -11,8 +11,8 @@ echo "------------------------------------------------------------" echo "- Test: ${0}" echo "------------------------------------------------------------" -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ >/dev/null -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c etc/conf.yml >/dev/null -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c examples/conf.nginx.yml >/dev/null -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c examples/conf.apache22.yml >/dev/null -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c examples/conf.apache24.yml >/dev/null +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ >/dev/null +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c etc/conf.yml >/dev/null +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c examples/conf.nginx.yml >/dev/null +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c examples/conf.apache22.yml >/dev/null +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c examples/conf.apache24.yml >/dev/null diff --git a/tests/check-errors-reverse.sh b/tests/check-errors-reverse.sh index 55b5ea3..d4f5785 100755 --- a/tests/check-errors-reverse.sh +++ b/tests/check-errors-reverse.sh @@ -11,8 +11,8 @@ echo "------------------------------------------------------------" echo "- Test: ${0}" echo "------------------------------------------------------------" -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ >/dev/null -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c etc/conf.yml >/dev/null -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.nginx.yml >/dev/null -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache22.yml >/dev/null -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache24.yml >/dev/null +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ >/dev/null +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c etc/conf.yml >/dev/null +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.nginx.yml >/dev/null +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache22.yml >/dev/null +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache24.yml >/dev/null diff --git a/tests/check-errors-template-normal.sh b/tests/check-errors-template-normal.sh index 466309b..a7b6b0a 100755 --- a/tests/check-errors-template-normal.sh +++ b/tests/check-errors-template-normal.sh @@ -11,8 +11,8 @@ echo "------------------------------------------------------------" echo "- Test: ${0}" echo "------------------------------------------------------------" -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ | grep -v '__' -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c etc/conf.yml | grep -v '__' -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c examples/conf.nginx.yml | grep -v '__' -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c examples/conf.apache22.yml | grep -v '__' -"${BIN_PATH}/vhost-gen" -p ./ -n name -t etc/templates/ -c examples/conf.apache24.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ | grep -v '__' +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c etc/conf.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c examples/conf.nginx.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c examples/conf.apache22.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -p ./ -n name -t etc/templates/ -c examples/conf.apache24.yml | grep -v '__' diff --git a/tests/check-errors-template-reverse.sh b/tests/check-errors-template-reverse.sh index a2d9df7..cb417b8 100755 --- a/tests/check-errors-template-reverse.sh +++ b/tests/check-errors-template-reverse.sh @@ -11,8 +11,8 @@ echo "------------------------------------------------------------" echo "- Test: ${0}" echo "------------------------------------------------------------" -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ | grep -v '__' -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c etc/conf.yml | grep -v '__' -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.nginx.yml | grep -v '__' -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache22.yml | grep -v '__' -"${BIN_PATH}/vhost-gen" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache24.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ | grep -v '__' +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c etc/conf.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.nginx.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache22.yml | grep -v '__' +"${BIN_PATH}/vhost-generator" -r http://127.0.0.1:3000 -l / -n name -t etc/templates/ -c examples/conf.apache24.yml | grep -v '__'