From 93d22e37650af8f2ae5354cf1fdc784eeaea7847 Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 24 Jan 2015 12:28:16 -0800 Subject: [PATCH] Allow importing existing setups, add basic auth for nginx pisg files --- README.md | 42 ++++++++++++++++++++++++++++++------- default | 2 ++ start | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 95 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6ad0259..1e29574 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,45 @@ -Docker ZNC -========== +#Docker ZNC -Suitable for create docker containers running ZNC (and sshd!) +Suitable for creating docker containers running ZNC. Now with pisg! +##Setup **General steps:** * Install docker * Clone this repo, cd in * Load it as a template: `sudo docker build -t znc .` -* Start a new container: `sudo docker run -it -p 666:22 -p 4421:4421 znc /start` - -On first start, the znc configuration will run. Set it up as needed; the port znc listens on must be exposed in the command used to start the container (-p 4421:4421 above). The final question asks if you want to start znc, **choose `NO`**. - +* Start a new container: `sudo docker run -it -p 666:22 -p 4421:4421 -p 80:80 znc /start` +* Configure znc * Find the new container in your list: `sudo docker ps -a` * Run it in the background: `sudo docker start mycontainerid` +When you first run the image, you'll be presented with two ways to configure znc: + +###Set up a new znc instance + +If no import of existing znc data is available, the znc configuration will run. Set it up as needed; the port znc listens on must be exposed in the command used to start the container (-p 4421:4421 above). The final question asks if you want to start znc, **choose `NO`!!**. + +###Import an existing znc instance's configuration + +You may migrate an existing ZNC instance into this container by providing a tarball of the source .znc directory. The tarball should contain the .znc directory, only, with everything inside it. The start script will prompt you to insert the .tar.gz file. + +##Pisg + +This container creates [pisg]-style channel statistics ([example]) for any ZNC users with the "log" module enabled. The stats are regenerated nightly and nginx serves the files on port 80 with a directory structure like this: + +* znc username + * znc network name + * \#channelname.html + +The channel information is private, nginx is configured with HTTP basic authentication; the password is prompted for during setup. + +## TODO + +* Ensure pisg cache files don't use too much disk space (/home/znc/pisg/cache) + * If this is a problem, maybe tar/gz channel groups and extract when necessary when running pisg +* Provide a way to make certain channel stat files public +* Provide a way to share channel files with secret links +* Provide all-time, yearly, and monthly pisg outputs + +[pisg]:http://pisg.sourceforge.net/ +[example]:http://pisg.sourceforge.net/examples diff --git a/default b/default index f0e9910..a766e04 100644 --- a/default +++ b/default @@ -4,6 +4,8 @@ server { root /home/znc/pisg/output; index index.html index.htm; server_name localhost; + auth_basic "Restricted"; + auth_basic_user_file /etc/nginx/htpasswd; location / { autoindex on; try_files $uri $uri/ =404; diff --git a/start b/start index dc3b2a6..02422bd 100644 --- a/start +++ b/start @@ -1,11 +1,65 @@ #!/bin/bash if [ ! -f /home/admin/znc_configured ]; then - touch /home/admin/znc_configured - echo "Configure ZNC to your liking now. Remember to choose NO when asked to launch znc!!" + echo "Welcome! I need to ask you a few questions to configure this ZNC instance for your liking. First, press enter choose and choose a time zone." + read + + dpkg-reconfigure tzdata + + if [ ! -f /znc.tar.gz ]; then + echo "If you want to load data from and existing znc instance create a tar.gz archive containing only the .znc directory and place it in the root of this container as znc.tar.gz." + echo "Copy the archive to the container using this command: cat znc.tar.gz | docker exec -i bash -c \"/bin/cat > /znc.tar.gz\"" + echo "Press enter when done. Or, to set up a new znc instance, press enter now." + read + fi + + if [ -f /znc.tar.gz ]; then + su -c "cd /home/znc ; tar zxvf /znc.tar.gz " znc + rm /znc.tar.gz + echo "Extracted znc data" + if [ ! -d /home/znc/.znc ]; then + echo ".znc was not in the archive! Aborted" + exit 1 + fi + chown -R znc /home/znc/.znc + chgrp -R znc /home/znc/.znc + chmod -R 700 /home/znc/.znc + echo "ZNC settings loaded successfully." + else + echo "Configure ZNC to your liking now. Remember to choose NO when asked to launch znc!!" su -c "/usr/bin/znc --makeconf" znc - exit + echo "ZNC configured successfully." + fi + + echo "Enter a username and password to view pisg statistics" + while [ 1 ]; do + + echo -n "Username: " + read ng_username + + echo -n "Password: " + read -s ng_password + echo "" + + echo -n "Password (again): " + read -s ng_password_ + echo "" + + if [ ! "$ng_password" == "$ng_password_" ] || [ -z "$ng_password" ] || [ -z "$ng_username" ] ; then + echo "Passwords must match and not be blank" + echo "" + continue + fi + break + done + + printf "$ng_username:$(openssl passwd -crypt $ng_password)\n" > /etc/nginx/htpasswd + + touch /home/admin/znc_configured + + echo "Now, run docker start run znc in the background." + + exit fi supervisord -