Add auto-generated channel stats [beta]

This commit is contained in:
dave 2015-01-23 23:37:24 -08:00
parent 2e361e2d9e
commit f7726b1de1
5 changed files with 123 additions and 1 deletions

View File

@ -7,15 +7,36 @@ RUN useradd --create-home --groups sudo admin ; echo "admin:admin" | chpasswd ;
RUN useradd --create-home znc ; echo "znc:znc" | chpasswd
# Install sshd, znc, and znc extras
RUN mkdir /var/run/sshd ; apt-get update ; apt-get install -y supervisor vim openssh-server znc znc-python znc-dev dpkg-dev
RUN mkdir /var/run/sshd ; apt-get update ; apt-get install -y supervisor vim openssh-server znc znc-python znc-dev dpkg-dev pisg nginx-light
# Get ZNC source
RUN su -c 'cd /home/znc ; apt-get source znc' znc
# Set nginx workers to a low number
RNN sed -i -e"s/^worker_processes\s*4/worker_processes 1/" /etc/nginx/nginx.conf
# Set nginx user to ZNC user
RUN sed -i -e"s/^user\s*www\-data/user znc/" /etc/nginx/nginx.conf
# Set nginx root
RUN sed -i -e"s/^\s*root\s*\/usr\/share\/nginx\/html/ root \/home\/znc\/pisg\/output/" /etc/nginx/sites-enabled/default
# Make pisg root
RUN su -c "mkdir /home/znc/pisg ; mkdir /home/znc/pisg/output ; mkdir /home/znc/pisg/config" znc
# Turn off nginx daemon
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Install crontab
COPY crontab /tmp/
RUN crontab -u znc /tmp/crontab
RUN rm /tmp/crontab
# Install stuff for log generation
RUN mkdir /home/znc/pisg /home/znc/pisg/cache /home/znc/pisg/output
COPY pisg.py /home/znc/pisg/
RUN chmod +x /home/znc/pisg/pisg.py
# Install startup stuff
COPY daemons.conf /etc/supervisor/conf.d/daemons.conf
COPY start /start
RUN chmod +x /start
# Ports
EXPOSE 80
EXPOSE 22

2
crontab Normal file
View File

@ -0,0 +1,2 @@
0 3 * * * /home/znc/pisg/pisg.py

View File

@ -9,3 +9,11 @@ autorestart=true
command=su -c "/usr/bin/znc --foreground" znc
autorestart=true
[program:cron]
command=/usr/sbin/cron -f
autorestart=true
[program:nginx]
command=/usr/sbin/nginx
autorestart=true

14
default Normal file
View File

@ -0,0 +1,14 @@
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/znc/pisg/output;
index index.html index.htm;
server_name localhost;
location / {
autoindex on;
try_files $uri $uri/ =404;
}
location /gfx/ {
alias /usr/share/pisg/gfx/;
}
}

77
pisg.py Executable file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env python3
import subprocess
from os import listdir,unlink,chdir
from os.path import exists
from sys import exit
from random import randint
class logfile:
def __init__(self, username, network, channel):
self.username = username
self.network = network
self.channel = channel
self.path = "/home/znc/.znc/users/%s/moddata/log/%s_%s" % (self.username, self.network, self.channel)
def __str__(self):
return "<logfile username=%s network=%s channel=%s path=%s>" % (self.username, self.network, self.channel, self.path)
def generate_config(self):
return """<set ShowMostActiveByHour="1">
<set ShowMostActiveByHourGraph="1">
<set ActiveNicksByHour="15">
<set ShowTime="1">
<set ShowLines="0">
<set ShowWpl="1">
<set ShowWords="1">
<set ShowLineTime="0">
<set ShowSmileys="1">
<set ShowKarma="1">
<set KarmaHistory="15">
<set TopicHistory="25">
<set PicLocation="gfx">
<set UserPics="1">
<set ActiveNicks="50">
<set CacheDir="/home/znc/pisg/cache">
<set FoulWords="shit piss fuck cunt cocksucker motherfucker tits fag faggot nigger">
<channel="%(channel)s">
Logfile = "%(logdir)s_*.log"
Format = "energymech"
Network = "%(network)s"
OutputFile = "/home/znc/pisg/output/%(username)s_%(network)s_%(channel)s.html"
</channel>""" % {"logdir":self.path, "network":self.network, "channel":self.channel, "username":self.username}
def run_pisg(self):
configname = "config.%s" % str(randint(0,10000))
open(configname, "w").write(self.generate_config())
proc = subprocess.Popen(['pisg',"-co", configname], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(self.path +": "+str(proc.communicate()))
unlink(configname)
if __name__ == "__main__":
chdir("/home/znc/pisg")
logs = []
for user in listdir("/home/znc/.znc/users/"):
if not exists("/home/znc/.znc/users/%s/moddata/log/" % user):
continue
networks = {}
for fname in listdir("/home/znc/.znc/users/%s/moddata/log/" % user):
network, parts = fname.split("_", 1)
if not network in networks:
networks[network]=[]
channel, parts = parts.rsplit("_", 1)
if "#" in channel and not channel in networks[network]:
networks[network].append(channel)
print(user)
print(networks)
for network in networks:
for channel in networks[network]:
logs.append(logfile(user, network, channel))
for log in logs:
log.run_pisg()