# HG changeset patch # User Dennis Fink # Date 2014-07-16 01:26:27 # Node ID 3bbb12f4b7371b1b06268336484e5d8a46904d00 # Parent c34648b1a4d62fe080c9c9db3fa2389411d6ab4d # Parent 2e0ecf34317d863e8a92dd4bcc76c9a7ce4730c4 Merge diff --git a/Scripts/traffic_statistics.pl b/Scripts/traffic_statistics.pl deleted file mode 100644 --- a/Scripts/traffic_statistics.pl +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/perl -=About -This perl scripts generates statistics about the servers traffic consumption - -by virii -=cut -use HTTP::Tiny; -use IO::Socket; -use Chart::Clicker; -use Chart::Clicker::Context; -use Chart::Clicker::Data::DataSet; -use Chart::Clicker::Data::Marker; -use Chart::Clicker::Data::Series; -use Chart::Clicker::Renderer::Area; -use Geometry::Primitive::Rectangle; -use Graphics::Color::RGB; - -############### [Which year] ########################################### -$select_year = 2014; -$select_year = shift if $ARGV[0] =~ /^\d{4}$/; -############### [Create new statistics image] ########################## -$cc = Chart::Clicker->new(width => 1248, height => 800); -$ds = Chart::Clicker::Data::DataSet->new(); -@months = 1..12; -@series; -@traffix; -######################################################################## -@nodes = qw(relay exit); -############### [Servername gathering via Ennstatus API] ############### -foreach $node (@nodes) { - print "[+] Checking for $node\n"; - $gather_nodes = HTTP::Tiny->new->get('http://enn.lu/api/export/xml/' . $node) || die "[-] Cannot connect to $node API\n"; - @xml_response = split(/\n/,$gather_nodes->{content}); - foreach $xml_line (@xml_response) { - $counter++; - if ($xml_line =~ /\(\w+)\<\/server_name\>/i) { - $server_nick = $1; - if ($xml_response[$counter] =~ /\(\w+)\<\/server_status\>/i) { - push @servers, $server_nick if ($1 eq "Online"); # we want only those who are online - } - } - } -undef $counter; -} -####################### [Connect to each server] ####################### -foreach $server_name (@servers) { - print "[+] Checking '$server_name'\n"; - $server_response = HTTP::Tiny->new->get('http://' . $server_name . '.enn.lu/vnstat.xml'); - die "[-] '$server_name' Failed!\n" unless $server_response->{success}; - @xml_content = split(/\n/,$server_response->{content}); - foreach $xml_line (@xml_content) { - if ($xml_line =~ /\\\($select_year)\<\/year\>\(\d+)\<\/month\>\<\/date\>\(\d+)\<\/rx\>\(\d+)\<\/tx\>\<\/month\>/ig) { - ($id,$year,$month,$rx,$tx) = ($1,$2,$3,$4,$5,$6); - $rxtx = ($tx + $rx) * 10e-10; - $traffic = $1 if $rxtx =~ /^(\d+\.?\d{5})/; - push @traffix, $traffic; - } - } - for (scalar @traffix..11) { - push @traffix, 0 if $select_year == 2014; - unshift @traffix, 0 unless $select_year == 2014; - } - - $ds->add_to_series(Chart::Clicker::Data::Series->new( - keys => \@months, - values => [@traffix], - name => $server_name - )); - - undef @traffix; - -} - -$cc->add_to_datasets($ds); -$def = $cc->get_context('default'); -$def->range_axis->label('Tbit'); -$def->domain_axis->label('Month'); -$area = Chart::Clicker::Renderer::Area->new(opacity => .2); -$area->brush->width(3); -$def->renderer($area); -$def->range_axis->tick_values([qw(20 40 60 80 100 120 140 160 300)]); -$def->range_axis->format('%d'); -$def->domain_axis->ticks(11); -$def->domain_axis->tick_labels([qw(January February Mars April June July August September October November December)]); -$def->domain_axis->format('%d'); - -$cc->write_output('stats.png'); - diff --git a/Scripts/update_server.pl b/Scripts/update_server.pl deleted file mode 100644 --- a/Scripts/update_server.pl +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env perl -=begin About -This is a perlized "Update Server" script which should run out of the box -on most machines. If not you need to install HTTP::Tiny -sudo cpan ->install HTTP::Tiny - -by virii - -= end - -=cut - -use HTTP::Tiny; -use IO::Socket; -######## [defaults] ######## -@configs = @ARGV if @ARGV; # perl updater_server.pl torrc torrc0 torrc1 -@configs = qw(torrc torrc2) unless @ARGV; # OR hardcode every config file! like: torrc torrc0 torrc1 -$data_dir = '/var/lib/tor'; # default data dir -$pidfile = '/var/run/tor/tor.pid'; # default pid file -$API_url = 'http://enn.lu'; # will be ignored if /etc/ennstatus_updater.conf is present -######## [ennstatus URL - config file] ###### -if (-e '/etc/ennstatus_updater.conf') { - open ennstatus, "<", "/etc/ennstatus_updater.conf" || die "Cannot open 'ennstatus_updater.conf'!\n"; - while () { - $ennstatus_url = $1 if /^ennstatus_url = (.+)/i; - } - close ennstatus; -} else { - $ennstatus_url = $API_url; -} -######## [loop through configs] ######## -for (1..scalar @configs) { - open config, "<", "/etc/tor/" . $configs[$_ -1] || die "Cannot open $configs[$_ -1]\n"; - while () { - $server_name = $1 if /^Nickname (\w+)/i; - $server_type = 'Exit' if /^ExitPolicy accept \*:\*/i; - $server_type = 'Relay' if /^ExitPolicy reject \*:\*/i and $server_type ne 'Bridge'; - $server_type = 'Bridge' if /^BridgeRelay 1/i; - $data_dir = $1 if /^DataDirectory (.*)/i; - $pidfile = $1 if /^PidFile (.*)/i; - $obfs = 'True' if /^ServerTransportPlugin (obfs\d+|scramblesuit)/i; - $fteproxy = 'True' if /^ServerTransportPlugin fte/i; - $ip = $1 if /^OutboundBindAddress (\d+\.\d+\.\d+\.\d+)/i; - } - close config; -######## [obfs check] ######## - $obfs = 'False' if $obfs ne 'True' and $server_type eq 'Bridge'; -print $obfs . "\n"; -######## [fte check] ######## -$fteproxy = 'False' if $fteproxy ne 'True' and $server_type eq 'Bridge'; -print $fteproxy . "\n"; -######## [ip check] ######## - if ($ip == "") { - $socket = new IO::Socket::INET ( PeerAddr => "enn.lu", - PeerPort => 80, - Proto => 'tcp'); - $ip = $socket->sockhost; - close $socket; - } -######## [fingerprint] ######## - open fingerprint, "<", $data_dir . '/fingerprint'; - $read_in = ; - $fingerprint = $1 if $read_in =~ /^\w+ (\w{40})/i; - close fingerprint; -######## [pid check] ######## - open pidfile, "<", $pidfile; - $pid = ; - close pidfile; - $psaux = kill 0, $pid; - if ($psaux) { - $tor_status = 'Online'; - } else { - $tor_status = 'Offline'; - } -######## [create json string] ######## -if ($server_type eq "Bridge") { -$json_string = '{"fingerprint": "' . $fingerprint . - '", "ip": "' . $ip . - '", "server_name": "' . $server_name . - '", "server_type": "' . $server_type . - '", "obfs": "' . $obfs . - '", "fteproxy": "' . $fteproxy . - '", "tor_status": "' . $tor_status . - '"}'; -} else { -$json_string = '{"fingerprint": "' . $fingerprint . - '", "ip": "' . $ip . - '", "server_name": "' . $server_name . - '", "server_type": "' . $server_type . - '", "tor_status": "' . $tor_status . - '"}'; -} -######## [Send to server] ######## -$request = HTTP::Tiny->new->request('POST', $ennstatus_url . '/api/update', - { - content => $json_string, - headers => { 'content-type' => 'application/json' } - } - ); - -print $request->{content}; -######## [end of loop] ######## -} - - - diff --git a/Scripts/update_server.py b/Scripts/update_server.py --- a/Scripts/update_server.py +++ b/Scripts/update_server.py @@ -169,3 +169,4 @@ def main(): if __name__ == '__main__': main() + diff --git a/ennstatus/stats/__init__.py b/ennstatus/stats/__init__.py deleted file mode 100644 diff --git a/ennstatus/stats/forms.py b/ennstatus/stats/forms.py deleted file mode 100644 --- a/ennstatus/stats/forms.py +++ /dev/null @@ -1,36 +0,0 @@ -from flask_wtf import Form -from wtforms import SelectField -from wtforms.validators import DataRequired - -STYLES = [ - ('default', 'Default'), - ('light', 'Light'), - ('neon', 'Neon'), - ('light_red_blue', 'Red Blue'), - ('dark_solarized', 'Dark Solarized'), - ('light_solarized', 'Light Solarized'), - ('dark_colorized', 'Dark Colorized'), - ('light_colorized', 'Light Colorized'), - ('turquoise', 'Turquoise'), - ('green', 'Light green'), - ('dark_green', 'Dark green'), - ('dark_green_blue', 'Dark green blue'), - ('blue', 'Blue'), - ('solid_color', 'Solid Color'), -] - -SERVER_TYPES = [ - ('all', 'All'), - ('exit', 'Exit'), - ('relay', 'Relay'), - ('bridge', 'Bridge'), -] - - -class WorldmapStyleForm(Form): - style = SelectField('Style', - validators=[DataRequired()], - choices=STYLES) - server_type = SelectField('Server type', - validators=[DataRequired()], - choices=SERVER_TYPES) diff --git a/ennstatus/stats/functions.py b/ennstatus/stats/functions.py deleted file mode 100644 --- a/ennstatus/stats/functions.py +++ /dev/null @@ -1,54 +0,0 @@ -from collections import Counter, defaultdict - -from flask import current_app - -import pygal - - -from ennstatus.status.functions import split_all_servers_to_types - -COUNTRIES_TO_ISO = dict( - zip(pygal.i18n.COUNTRIES.values(), pygal.i18n.COUNTRIES.keys())) -COUNTRIES_TO_ISO['Isle of Man'] = 'gb' - -def _make_country_list(): - - servers = split_all_servers_to_types() - countries = defaultdict(list) - - for key, value in servers.items(): - for server in value: - country = COUNTRIES_TO_ISO[server['country']] - countries[key].append(country) - - return countries - - -def make_worldmap(server_type, style): - - arguments = { - 'title': '%s nodes' % server_type.capitalize(), - 'style': pygal.style.styles[style], - 'legend_at_bottom': True, - 'disable_xml_declaration': True, - 'pretty_print': True, - } - - countries = _make_country_list() - - exits_count = Counter(countries['Exit']) - relays_count = Counter(countries['Relay']) - bridges_count = Counter(countries['Bridge']) - - plot = pygal.Worldmap(**arguments) - - if server_type in ('all', 'exit'): - plot.add('Exits', exits_count) - - if server_type in ('all', 'relay'): - plot.add('Relays', relays_count) - - if server_type in ('all', 'bridge'): - plot.add('Bridges', bridges_count) - - return plot diff --git a/ennstatus/stats/views.py b/ennstatus/stats/views.py deleted file mode 100644 --- a/ennstatus/stats/views.py +++ /dev/null @@ -1,61 +0,0 @@ -from flask import (Blueprint, render_template, request, current_app, - redirect, url_for) - -from ennstatus.stats.functions import make_worldmap -from ennstatus.stats.forms import WorldmapStyleForm - -stats_page = Blueprint('stats', __name__) - - -@stats_page.route('/') -def index(): - return render_template('stats/index.html') - - -@stats_page.route('/worldmap', methods=('GET', 'POST')) -def worldmap(): - - current_app.logger.info('Handling worldmap') - form = WorldmapStyleForm() - style_choices = [choice[0] for choice in form.style.choices] - server_choices = [choice[0] for choice in form.server_type.choices] - - if request.method == 'POST': - current_app.logger.debug('Validating form') - if form.validate_on_submit(): - style = form.style.data - server_type = form.server_type.data - return redirect(url_for('stats.worldmap', server_type=server_type, - style=style)) - else: - if 'style' in request.args: - style = request.args['style'] - if style in style_choices: - current_app.logger.info('Using style %s' % style) - else: - current_app.logger.warn('Style %s not found' % style) - style = 'default' - else: - current_app.logger.info('Using default style') - style = 'default' - - if 'server_type' in request.args: - server_type = request.args['server_type'] - if server_type in server_choices: - current_app.logger.info('Showing %s nodes' % server_type) - else: - current_app.logger.warn('Server type %s not found' % style) - server_type = 'all' - else: - current_app.logger.info('Showing all servers') - server_type = 'all' - - - form.style.data = style - form.server_type.data = server_type - - plot = make_worldmap(server_type, style) - - return render_template('stats/worldmap.html', plot=plot, form=form) - -