Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Added NGINX_AUTH_USERS_AND_PASSWORDS option
Browse files Browse the repository at this point in the history
  • Loading branch information
Paramtamtam committed Aug 27, 2018
1 parent 3d4b6fd commit 995c400
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].

## v2.2.0 - Aug 27, 2018

### Changed

- Option `NGINX_AUTH_USERS_AND_PASSWORDS` instead `NGINX_USE_AUTH` + `NGINX_AUTH_USER` + `NGINX_AUTH_PASSWORD`

## v2.1.0 - Aug 27, 2018

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -16,7 +16,7 @@ Docker-образ со скриптом для создания зеркала
- [Docker][install_docker]
- [Docker compose][install_docker_compose]

## :octocat: Особенности
## Особенности :octocat:

- Запускается в docker-контейнере, довольно экономично относится к ресурсам системы;
- Успешно работает с различными версиями антивирусов Eset Nod32 *(для определения "рабочих" директорий различных версий Eset Nod32 используется проверки `User-Agent` и редиректы средствами `nginx`)*;
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.live.yml
Expand Up @@ -15,9 +15,7 @@ services:
NGINX_SERVER_ACCESS_LOG_PATH: '/dev/stdout'
NGINX_SERVER_SCHEME: 'http'
NGINX_SERVER_NAME: '127.0.0.1'
NGINX_USE_AUTH: 'false' # or "true"
NGINX_AUTH_USER: 'some_login' # only if "NGINX_USE_AUTH" is "true"
NGINX_AUTH_PASSWORD: 'some_password' # only if "NGINX_USE_AUTH" is "true"
NGINX_AUTH_USERS_AND_PASSWORDS: 'user1:password1 user2:password2' # Comment this line or set "" to disable
entrypoint: /nginx-extrypoint.sh
command: nginx
volumes:
Expand Down
48 changes: 23 additions & 25 deletions docker-compose.yml
Expand Up @@ -29,9 +29,7 @@ services:
NGINX_SERVER_NAME: '127.0.0.1'
NGINX_SERVER_ROOT_DIRECTORY: '/data'
NGINX_SERVER_ACCESS_LOG_PATH: '/dev/stdout'
NGINX_USE_AUTH: 'true' # or "false"
NGINX_AUTH_USER: 'some_login' # only if "NGINX_USE_AUTH" is "true"
NGINX_AUTH_PASSWORD: 'some_password' # only if "NGINX_USE_AUTH" is "true"
NGINX_AUTH_USERS_AND_PASSWORDS: 'user1:password1 user2:password2' # Comment this line or set "" to disable
NGINX_SERVER_EXTRA: '# No extra SERVER config'
entrypoint: /nginx-extrypoint.sh
command: nginx
Expand All @@ -40,25 +38,25 @@ services:
ports:
- '8080:80'

scheduler:
build: .
restart: on-failure
stop_grace_period: 3s
environment:
FIRST_START_DELAY: '2' # In SECONDS
SCHEDULE_PERIOD: '900' # In SECONDS
START_BEFORE_LOOP: 'true'
NOD32MIRROR_DEBUG_MODE: '1'
NOD32MIRROR_USE_FREE_KEY: '1'
NOD32MIRROR_MIRROR_DIR: '/data'
NOD32MIRROR_LOG_PATH: '/var/log/nod32/nod32mirror.log'
NOD32MIRROR_KEYS_DIRECTORY: '/opt/nod32keys'
NOD32MIRROR_VERSIONS: 'pcu 4 5 6 7 8 9'
NOD32MIRROR_LANGUAGES: '1033 1049'
NOD32MIRROR_DOWNLOAD_SPEED_LIMIT: '20480'
entrypoint: /scheduler-entrypoint.sh
command: /src/nod32-mirror.sh --force-yes --keys-update; /src/nod32-mirror.sh --force-yes --update
volumes:
- nod32-data:/data:rw
- nod32-logs:/var/log/nod32:rw
- nod32-keys:/opt/nod32keys:rw
# scheduler:
# build: .
# restart: on-failure
# stop_grace_period: 3s
# environment:
# FIRST_START_DELAY: '2' # In SECONDS
# SCHEDULE_PERIOD: '900' # In SECONDS
# START_BEFORE_LOOP: 'true'
# NOD32MIRROR_DEBUG_MODE: '1'
# NOD32MIRROR_USE_FREE_KEY: '1'
# NOD32MIRROR_MIRROR_DIR: '/data'
# NOD32MIRROR_LOG_PATH: '/var/log/nod32/nod32mirror.log'
# NOD32MIRROR_KEYS_DIRECTORY: '/opt/nod32keys'
# NOD32MIRROR_VERSIONS: 'pcu 4 5 6 7 8 9'
# NOD32MIRROR_LANGUAGES: '1033 1049'
# NOD32MIRROR_DOWNLOAD_SPEED_LIMIT: '20480'
# entrypoint: /scheduler-entrypoint.sh
# command: /src/nod32-mirror.sh --force-yes --keys-update; /src/nod32-mirror.sh --force-yes --update
# volumes:
# - nod32-data:/data:rw
# - nod32-logs:/var/log/nod32:rw
# - nod32-keys:/opt/nod32keys:rw
27 changes: 18 additions & 9 deletions nginx/entrypoint.sh
Expand Up @@ -5,10 +5,8 @@ set -e
NGINX_CONFIG_FILE_PATH="${NGINX_CONFIG_FILE_PATH:-/etc/nginx/nginx.conf}";

# Nginx basic auth settings
NGINX_USE_AUTH="${NGINX_USE_AUTH:-true}";
NGINX_AUTH_FILE_PATH="${NGINX_AUTH_FILE_PATH:-/etc/nginx/.htpasswd}";
NGINX_AUTH_USER="${NGINX_AUTH_USER:-login}";
NGINX_AUTH_PASSWORD="${NGINX_AUTH_PASSWORD:-password}";
NGINX_AUTH_USERS_AND_PASSWORDS="${NGINX_AUTH_USERS_AND_PASSWORDS:-}";

# Make replaces using pattern in a file. Pattern must looks like: '%ENV_VAR_NAME|default value%', where:
# - 'ENV_VAR_NAME' - Environment variable name for replacing
Expand Down Expand Up @@ -43,13 +41,24 @@ function make_replaces() {
}

# Setup nginx basic auth settings
if [ "$NGINX_USE_AUTH" == "true" ]; then
echo "Generate nginx basic auth file: $NGINX_AUTH_FILE_PATH ($NGINX_AUTH_USER : $NGINX_AUTH_PASSWORD)";
# Generate file
htpasswd -cb "$NGINX_AUTH_FILE_PATH" "$NGINX_AUTH_USER" "$NGINX_AUTH_PASSWORD";
if [ "$NGINX_AUTH_USERS_AND_PASSWORDS" != "" ]; then
# Create empty file for passwords
[ ! -f "$NGINX_AUTH_FILE_PATH" ] && touch "$NGINX_AUTH_FILE_PATH";

for single_entry in $(echo "$NGINX_AUTH_USERS_AND_PASSWORDS" | tr [:space:] ' '); do
username=$(echo "${single_entry}" | cut -d ':' -f 1);
password=$(echo "${single_entry}" | cut -d ':' -f 2);

echo "Generate nginx basic auth file: $NGINX_AUTH_FILE_PATH ($username : $password)";
# Generate entry
htpasswd -b "$NGINX_AUTH_FILE_PATH" "$username" "$password";
# Make verification
htpasswd -vb "$NGINX_AUTH_FILE_PATH" "$username" "$password";
done;

echo 'Passwords file content:';
cat "$NGINX_AUTH_FILE_PATH";
# Make verification
htpasswd -vb "$NGINX_AUTH_FILE_PATH" "$NGINX_AUTH_USER" "$NGINX_AUTH_PASSWORD";

# Export environment value with nginx settings (function "make_replaces" works with it)
# Also - you need to escape "^" char for passing into sed
export NGINX_AUTH_SETTINGS='location ~* \^.+\.nup$ {
Expand Down
2 changes: 1 addition & 1 deletion src/nod32-mirror.sh
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.

# Declare important variables
export NOD32MIRROR_VERSION="2.1.0";
export NOD32MIRROR_VERSION="2.2.0";
[[ -z $NOD32MIRROR_BASE_DIR ]] && export NOD32MIRROR_BASE_DIR=$(realpath $(dirname $0));

# Execute bootstrap script
Expand Down

0 comments on commit 995c400

Please sign in to comment.