Skip to content

Commit

Permalink
Merge pull request #106 from diginc/README
Browse files Browse the repository at this point in the history
Web Password and updated documentation
  • Loading branch information
diginc authored Feb 9, 2017
2 parents 11e952a + 66314c8 commit 28b57e9
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 34 deletions.
70 changes: 36 additions & 34 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ setup_php_env_alpine() {
cat "$PHP_ENV_CONFIG"
}

setup_web_password() {
if [ -z "${WEBPASSWORD+x}" ] ; then
# Not set at all, give the user a random pass
WEBPASSWORD=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
echo "Assigning random password: $WEBPASSWORD"
fi;
pihole -a -p "$WEBPASSWORD"
}
setup_ipv4_ipv6() {
local ip_versions="IPv4 and IPv6"
if [ "$IPv6" != "True" ] ; then
Expand Down
1 change: 1 addition & 0 deletions docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ docker run -p 53:53/tcp -p 53:53/udp -p 80:80 \
--cap-add=NET_ADMIN \
-e ServerIP="$IP" \
--name pihole \
--restart=always \
-d "$IMAGE"
1 change: 1 addition & 0 deletions doco-alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ services:
- "80:80/tcp"
cap_add:
- NET_ADMIN
restart: always
1 change: 1 addition & 0 deletions doco-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ debian:
- "80:80/tcp"
cap_add:
- NET_ADMIN
restart: always
1 change: 1 addition & 0 deletions doco-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ pihole:
# WARNING: if this log don't exist as a file on the host already
# docker will try to create a directory in it's place making for lots of errors
# - '/var/log/pihole.log:/var/log/pihole.log'
restart: always
1 change: 1 addition & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ validate_env
prepare_setup_vars
change_setting "IPV4_ADDRESS" "$ServerIP"
change_setting "IPV6_ADDRESS" "$ServerIPv6"
setup_web_password "$WEBPASSWORD"
setup_dnsmasq_dns "$DNS1" "$DNS2"
setup_php_env
setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME"
Expand Down
20 changes: 20 additions & 0 deletions test/test_bash_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,23 @@ def test_debian_setup_php_env(Docker, tag, expected_lines, repeat_function):
search_config_cmd = "grep -c '{}' /etc/lighttpd/conf-enabled/15-fastcgi-php.conf".format(expected_line)
search_config_count = Docker.run(search_config_cmd)
assert search_config_count.stdout.rstrip('\n') == '1'

@pytest.mark.parametrize('args,secure,setupVarsHash', [
('-e ServerIP=1.2.3.4 -e WEBPASSWORD=login', True, 'WEBPASSWORD=6060d59351e8c2f48140f01b2c3f3b61652f396c53a5300ae239ebfbe7d5ff08'),
('-e ServerIP=1.2.3.4 -e WEBPASSWORD=""', False, ''),
('-e ServerIP=1.2.3.4', True, 'WEBPASSWORD='),
])
def test_webPassword_env_assigns_password_to_file(Docker, args, secure, setupVarsHash):
''' When a user sets webPassword env the admin password gets set to that '''
function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_password /start.sh`')
if secure and 'WEBPASSWORD' not in args:
assert 'Assigning random password' in function.stdout
else:
assert 'Assigning random password' not in function.stdout

if secure:
assert 'New password set' in function.stdout
assert Docker.run('grep -q \'{}\' {}'.format(setupVarsHash, '/etc/pihole/setupVars.conf')).rc == 0
else:
assert 'Password removed' in function.stdout
assert Docker.run('grep -q \'^WEBPASSWORD=$\' /etc/pihole/setupVars.conf').rc == 0

0 comments on commit 28b57e9

Please sign in to comment.