From 1e02330b6c7026917408d341df3c4559f69f915d Mon Sep 17 00:00:00 2001 From: Ubergeek Date: Mon, 4 Feb 2019 13:58:54 +0000 Subject: [PATCH] Adding znc stuff --- .../files/etc/skel/public_gopher/gophermap | 4 ++ .../files/var/lib/znc/create-znc_account.sh | 43 ++++++++++++++ .../files/var/lib/znc/znc_account.newconf | 25 ++++++++ roles/shell/tasks/main.yml | 1 + roles/shell/tasks/users/z00t.yml | 15 +++++ roles/shell/tasks/znc.yml | 59 +++++++++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 roles/shell/files/etc/skel/public_gopher/gophermap create mode 100755 roles/shell/files/var/lib/znc/create-znc_account.sh create mode 100644 roles/shell/files/var/lib/znc/znc_account.newconf create mode 100644 roles/shell/tasks/users/z00t.yml create mode 100644 roles/shell/tasks/znc.yml diff --git a/roles/shell/files/etc/skel/public_gopher/gophermap b/roles/shell/files/etc/skel/public_gopher/gophermap new file mode 100644 index 0000000..4c7cf62 --- /dev/null +++ b/roles/shell/files/etc/skel/public_gopher/gophermap @@ -0,0 +1,4 @@ +This is my gopher page. +There are many like it, but this one is mine. +1Thunix gopher.thunix.cf + diff --git a/roles/shell/files/var/lib/znc/create-znc_account.sh b/roles/shell/files/var/lib/znc/create-znc_account.sh new file mode 100755 index 0000000..2d818f6 --- /dev/null +++ b/roles/shell/files/var/lib/znc/create-znc_account.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# ZNC account creation +CONF="/var/lib/znc/.znc/configs/znc.conf" +PID=$(pgrep -u znc znc) + +# $username and $password are retrieved from create-account script +if [[ -z $1 || -z $2 ]] +then + echo -e "Usage: $(basename $0) [username] [password]" + exit +fi + +# search if $username has been added previously +if grep -iq $1 $CONF +then + echo -e "User: '$1' already exists" + exit +fi + +username=$1 +password=$2 + +kill -s USR1 $PID # Rewrite znc.conf +sleep 1 + +# set username and password +sed s/newuser/$username/g znc_account.newconf >> $CONF +expect << EOF | grep -E 'Hash|Salt' | tr -d \\r >> $CONF +spawn znc --makepass +expect "*Enter password: " +send "$password\r" +expect "*Confirm password: " +send "$password\r" +expect eof +EOF +echo " " >> $CONF +echo "" >> $CONF + +sleep 1 +kill -s HUP $PID # Reload znc.conf +sleep 1 +kill -s USR1 $PID # Rewrite znc.conf diff --git a/roles/shell/files/var/lib/znc/znc_account.newconf b/roles/shell/files/var/lib/znc/znc_account.newconf new file mode 100644 index 0000000..771d168 --- /dev/null +++ b/roles/shell/files/var/lib/znc/znc_account.newconf @@ -0,0 +1,25 @@ + + Admin = false + AltNick = newuser|znc + AppendTimestamp = false + AutoClearChanBuffer = true + AutoClearQueryBuffer = true + Buffer = 50 + DenyLoadMod = false + DenySetBindHost = false + Ident = newuser + JoinTries = 10 + LoadModule = chansaver + MaxJoins = 0 + MaxNetworks = 2 + MaxQueryBuffers = 50 + MultiClients = true + Nick = newuser + PrependTimestamp = true + QuitMsg = bouncer provider phoenix.thunix.cf + RealName = Got Thunix ? + StatusPrefix = * + TimestampFormat = [%H:%M:%S] + + + Method = SHA256 diff --git a/roles/shell/tasks/main.yml b/roles/shell/tasks/main.yml index 1047022..bb33fd6 100644 --- a/roles/shell/tasks/main.yml +++ b/roles/shell/tasks/main.yml @@ -5,3 +5,4 @@ - include: users.yml - include: apache2-mods.yml - include: ufw.yml +- include: znc.yml diff --git a/roles/shell/tasks/users/z00t.yml b/roles/shell/tasks/users/z00t.yml new file mode 100644 index 0000000..348d55f --- /dev/null +++ b/roles/shell/tasks/users/z00t.yml @@ -0,0 +1,15 @@ +--- +- name: Setting up z00t + user: + name: z00t + groups: tilde + state: present + skeleton: /etc/skel + shell: /bin/bash + system: no + createhome: yes + home: /home/z00t +- authorized_key: + user: z00t + state: present + key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVLpxuui5LZYqnmPQU2jFesWjGGKx0rmJaU6TkqBMBNa3rVXN7AWfCM3+Wg5x/kLp75uzFjRUzkODCRo+YW8dRMOYPFxQsVT2NB102iX71hNS4NuP4GMgNxHzXk5WWekhYMCfhlMaoUYflVt5lqdUXvxSPnxUbkrh29DKK1r5bwQ1AVZy7Ib/wZZ4Z03UXq8lMAQqznKFpg0gn5rY/x1VFP9MYWu1GfMdDKsAIvsYA1/o2pHMPanDunkZlS6HdI9t08/qhkMhmH+HJrXyQa3KxkmT/5H/d89VKCjZRcCu0o+p7w9J2HGn9FTZKwoFv0nV+/i6Zfov6ptf4Bgm8A3NZ" diff --git a/roles/shell/tasks/znc.yml b/roles/shell/tasks/znc.yml new file mode 100644 index 0000000..c24952f --- /dev/null +++ b/roles/shell/tasks/znc.yml @@ -0,0 +1,59 @@ +# Install our baseline packages for all machines, irrespective of what role they might have +--- +- name: Create home dirs for znc + file: + path: /var/lib/znc/.znc + state: directory + owner: znc + group: root + mode: 770 + recurse: yes + +- name: Create znc run dir + file: + path: /var/run/znc + state: directory + owner: znc + group: root + mode: 770 + +- name: Install crontab target + copy: + dest: /etc/systemd/system/znc.service + content: | + [Install] + WantedBy=multi-user.target + [Unit] + Description=Simulates cron, limited to /etc/cron.* + Requires=crontab@hourly.timer + Requires=crontab@daily.timer + Requires=crontab@weekly.timer + Requires=crontab@monthly.timer + + [Unit] + Description=ZNC, an advanced IRC bouncer + After=network-online.target + + [Service] + ExecStart=/usr/bin/znc -f --datadir=/var/lib/znc/.znc + ExecReload=/bin/kill -HUP $MAINPID + User=znc + + [Install] + WantedBy=multi-user.target + +- name: Install znc_newaccount + copy: + src: ../files/var/lib/znc/znc_account.newconf + dest: /var/lib/znc/znc_account.newconf + owner: znc + group: root + mode: 660 + +- name: Install znc user script + copy: + src: ../files/var/lib/znc/create-znc_account.sh + dest: /var/lib/znc/create-znc_account.sh + owner: znc + group: root + mode: 770