ID-Mapping and sections-configuration

This commit is contained in:
Thor77 2015-05-12 21:38:34 +02:00
parent dc91b8fc59
commit e86d2154bc
3 changed files with 68 additions and 19 deletions

View File

@ -8,21 +8,39 @@ Run `tsstats.py` and point your web-server to the generated .html-file, now you
###Configname
`config.ini`
###Sections
#### Keys
`[General]`
### Keys
- title `HTMl-Title`
- logfile `Path to TS3Server-logfile`
- outputfile `Path to the location, where the generator will put the generated .html-file`
`[HTML]`
- title `HTML-Title`
- onlinetime `Show the onlinetime-section (default=True)`
- kicks `Show the kicks-section (default=True)`
- pkicks `Show the passive-kicks-section (default=True)`
- bans `Show the bans-section (default=True)`
## Example
```
[General]
title = TeamspeakStats
logfile = /usr/local/bin/teamspeak-server/logs/ts3server_2015-03-02__14_01_43.110983_1.log
outputfile = /var/www/html/stats.html
[HTML]
title = TeamspeakStats
bans = False
```
# ID-Mapping
`id_map.json`
You can map multiple ID's to one (for example, when an user creates a new identity)
## Example
```json
{
"1": "2",
"3": "2"
}
```
The online-time of `1` and `3` will be added to the online-time of `2`
# TODO
- Localization
- Map multiple ID's to one user (`json`)
- find a better way to count kicks and bans

View File

@ -11,6 +11,7 @@
</head>
<body>
{# Onlinetime #}
{% if show_onlinetime is sameas true %}
<h1>Onlinetime</h1>
<ul class="list-group">
{% for clid, nick, onlinetime_, connected in onlinetime %}
@ -19,7 +20,10 @@
<li class="list-group-item">No data</li>
{% endfor %}
</ul>
{% endif %}
{# Kicks #}
{% if show_kicks is sameas true %}
<h1>Kicks</h1>
<ul class="list-group">
{% for _, nick, kicks_ in kicks %}
@ -28,7 +32,10 @@
<li class="list-group-item">No data</li>
{% endfor %}
</ul>
{% endif %}
{# passive Kicks #}
{% if show_pkicks is sameas true %}
<h1>passive Kicks</h1>
<ul class="list-group">
{% for _, nick, pkicks_ in pkicks %}
@ -37,7 +44,10 @@
<li class="list-group-item">No data</li>
{% endfor %}
</ul>
{% endif %}
{# Bans #}
{% if show_bans is sameas true %}
<h1>Bans</h1>
<ul class="list-group">
{% for _, nick, bans_ in bans %}
@ -46,6 +56,7 @@
<li class="list-group-item">No data</li>
{% endfor %}
</ul>
{% endif %}
<p>generated in {{ seconds }} at {{ date }}</p>
</body>
</html>

View File

@ -1,5 +1,6 @@
import re
import sys
import json
import configparser
from time import mktime
from datetime import datetime, timedelta
@ -18,13 +19,22 @@ path += '/'
# parse config
config = configparser.ConfigParser()
config.read(path + 'config.ini')
if 'General' not in config or not ('title' in config['General'] and 'logfile' in config['General'] and 'outputfile' in config['General']):
print('Invalid configuration!')
# check keys
general = config['General']
html = config['HTML']
if ('logfile' not in general or 'outputfile' not in general) or ('title' not in html):
print('Invalid config!')
import sys
sys.exit()
title = config['General']['title']
log_path = config['General']['logfile']
output_path = config['General']['outputfile']
log_path = general['logfile']
output_path = general['outputfile']
title = html['title']
show_onlinetime = html.get('onlinetime', True)
show_kicks = html.get('kicks', True)
show_pkicks = html.get('pkicks', True)
show_bans = html.get('bans', True)
# read id_map
id_map = json.load(open(path + 'id_map.json'))
generation_start = datetime.now()
clients = {} # clid: {'nick': ..., 'onlinetime': ..., 'kicks': ..., 'pkicks': ..., 'bans': ..., 'last_connect': ..., 'connected': ...}
@ -97,22 +107,27 @@ with open(log_path, 'r') as f:
if data.startswith('client'):
r = cldata.findall(data)[0]
nick = r[0]
id = r[1]
clid = r[1]
#print(clid, nick, sep=' | ')
if clid in id_map:
clid = id_map[clid]
if data.startswith('client connected'):
add_connect(id, nick, logdatetime)
add_connect(clid, nick, logdatetime)
elif data.startswith('client disconnected'):
add_disconnect(id, nick, logdatetime)
add_disconnect(clid, nick, logdatetime)
if 'invokerid' in data:
add_pkick(id, nick)
add_pkick(clid, nick)
r = cldata_invoker.findall(data)[0]
nick = r[1]
id = r[0]
add_kick(id, nick)
clid = r[0]
if clid in id_map:
clid = id_map[clid]
add_kick(clid, nick)
elif data.startswith('ban added') and 'cluid' in data:
r = cldata_ban.findall(data)[0]
nick = r[0]
id = r[1]
add_ban(id, nick)
clid = r[1]
add_ban(clid, nick)
for clid in clients:
if 'connected' not in clients[clid]:
@ -154,7 +169,12 @@ def render_template():
onlinetime_desc[idx] = (clid, nick, onlinetime_str, clients[clid]['connected'])
with open(output_path, 'w+') as f:
f.write(template.render(title=title, onlinetime=onlinetime_desc, kicks=desc('kicks'), pkicks=desc('pkicks'), bans=desc('bans'), seconds='{}.{}'.format(generation_delta.seconds, generation_delta.microseconds), date=generation_end.strftime('%d.%m.%Y um %H:%M')))
f.write(template.render(title=title, onlinetime=onlinetime_desc, kicks=desc('kicks'), pkicks=desc('pkicks'), bans=desc('bans'), seconds='{}.{}'.format(generation_delta.seconds, generation_delta.microseconds),
date=generation_end.strftime('%d.%m.%Y um %H:%M'),
show_onlinetime=show_onlinetime,
show_kicks=show_kicks,
show_pkicks=show_pkicks,
show_bans=show_bans))
if len(clients) < 1:
print('Not enough data!')