import os
from datetime import *
+import re
from time import time as get_timestamp
import crack
import struct
from ais.common import Nmea, NmeaFeeder, strmmsi_to_mmsi, SHIP_TYPES, STATUS_CODES, AIS_STATUS_NOT_AVAILABLE, AIS_ROT_NOT_AVAILABLE, AIS_LATLON_SCALE, AIS_LON_NOT_AVAILABLE, AIS_LAT_NOT_AVAILABLE, AIS_COG_SCALE, AIS_COG_NOT_AVAILABLE, AIS_NO_HEADING, AIS_SOG_SCALE, AIS_SOG_NOT_AVAILABLE, AIS_SOG_MAX_SPEED, add_nmea1, add_nmea5_partial, load_fleet_to_uset
from ais.ntools import datetime_to_timestamp, clean_ais_charset
from ais.inputs.stats import STATS_DIR
+from ais.inputs.config import peers_get_config
def auth(username, raw_password):
try:
else:
return render_to_response('users.html', {'users':users}, RequestContext(request))
+phone_re = re.compile('^\\+.+')
class UserEditForm(forms.Form):
login = forms.RegexField(regex=r'^[a-zA-Z0-9_]+$', max_length=16,
error_message ='Login must only contain letters, numbers and underscores')
name = forms.CharField(max_length=50)
email = forms.EmailField()
+ phone = forms.RegexField(regex='\\+.+', max_length=20, required=False,
+ error_message ='Phones must start with a \'+\'')
def __init__(self, *args, **kargs):
forms.Form.__init__(self, *args, **kargs)
self.old_login = kargs['initial']['login']
initial['login'] = user.login
initial['name'] = user.name
initial['email'] = user.email
+ initial['phone'] = user.phone
if request.method == 'POST':
form = UserEditForm(request.POST, initial=initial)
if form.is_valid():
user.login = form.cleaned_data['login']
user.name = form.cleaned_data['name']
user.email = form.cleaned_data['email']
+ user.phone = form.cleaned_data['phone']
user.save()
return HttpResponseRedirect('/user/')
else: # GET
@http_authenticate(auth, 'ais')
def sources(request):
- sources = ( 'NMMT', 'NMKT', 'NMRW', 'NMNZ', 'NMEZ', 'NMAS', 'NMAH', 'NMBB' )
+ #sources = ( 'NMMT', 'NMKT', 'NMRW', 'NMNZ', 'NMEZ', 'NMAS', 'NMAH', 'NMBB' )
now = int(get_timestamp())
periods = ({
#'name_tiny': '2h',
'seconds': 90*24*60*60
})
- for source in sources:
+ sources = peers_get_config()
+ for id4, source in sources.iteritems():
+ source['id4'] = id4
for period in periods:
- args = os.path.join(STATS_DIR, source+'-'+period['name_tiny']+'-bytes.png'), \
+ args = os.path.join(STATS_DIR, id4+'-'+period['name_tiny']+'-bytes.png'), \
'--lazy', \
'-l', '0', \
- '--title', source+' - Bandwidth usage - '+period['name_long'], \
- '--start', '%d' % (now-period['seconds']), \
+ '--title', source['name'] + ' - Bandwidth usage - ' + period['name_long'], \
+ '--start', '%d' % (now - period['seconds']), \
'--end', '%d' % now, \
'--vertical-label', 'bps', \
- 'DEF:bytes=%s:bytes:AVERAGE' % os.path.join(STATS_DIR, source+'.rrd'), \
- 'DEF:rawbytes=%s:rawbytes:AVERAGE' % os.path.join(STATS_DIR, source+'.rrd'), \
+ 'DEF:bytes=%s:bytes:AVERAGE' % os.path.join(STATS_DIR, id4+'.rrd'), \
+ 'DEF:rawbytes=%s:rawbytes:AVERAGE' % os.path.join(STATS_DIR, id4+'.rrd'), \
'CDEF:bits=bytes,8,*', \
'CDEF:rawbits=rawbytes,8,*', \
'LINE:bits#00FF00:IP payload', \
'LINE:rawbits#FF0000:IP with headers'
rrdtool.graph(*args)
- args = os.path.join(STATS_DIR, source+'-'+period['name_tiny']+'-counts.png'), \
+ args = os.path.join(STATS_DIR, id4+'-'+period['name_tiny']+'-counts.png'), \
'--lazy', \
'-l', '0', \
- '--title', source+' - Packet\'izer stats - '+period['name_long'], \
+ '--title', source['name'] + ' - Packet\'izer stats - ' + period['name_long'], \
'--start', '%d' % (now-period['seconds']), \
'--end', '%d' % now, \
'--vertical-label', 'Hz', \
- 'DEF:packets=%s:packets:AVERAGE' % os.path.join(STATS_DIR, source+'.rrd'), \
- 'DEF:lines=%s:lines:AVERAGE' % os.path.join(STATS_DIR, source+'.rrd'), \
+ 'DEF:packets=%s:packets:AVERAGE' % os.path.join(STATS_DIR, id4+'.rrd'), \
+ 'DEF:lines=%s:lines:AVERAGE' % os.path.join(STATS_DIR, id4+'.rrd'), \
'LINE:packets#FF0000:input packets', \
'LINE:lines#00FF00:AIVDM lines'
rrdtool.graph(*args)
- return render_to_response('sources.html', {'sources':sources, 'periods': periods}, RequestContext(request))
+ return render_to_response('sources.html', {'sources':sources.values(), 'periods': periods}, RequestContext(request))
assert len(spl)==3, \
'line #%s: There should be exactaly 3 strings sepatated by spaces' % \
lineno
- id4, io, definition = line.split(' ')
+ id4, io, definition = spl
assert len(id4)==4, 'source name (first parameter) must be 4 char long.'
- assert io in ('in', 'out'), \
- "line #%s: second parameter must be either 'in' or 'out'.\r%s" % \
- (lineno, line)
logging.debug('%s %s %s', id4, io, definition)
if id4 not in SOURCES:
SOURCES[id4] = {}
if io == 'in':
SOURCES[id4]['in'] = definition
- else: # 'out'
+ elif io == 'out':
if not SOURCES[id4].has_key('out'):
SOURCES[id4]['out'] = []
SOURCES[id4]['out'].append(definition)
+ elif io == 'name':
+ SOURCES[id4]['name'] = definition
+ else:
+ raise AssertionError( \
+ "line #%s: second parameter must be either 'in' or 'out'.\r%s" % \
+ (lineno, line))
+
logging.debug('SOURCES \n%s', pprint.pformat(SOURCES))
logging.debug('SOURCES (raw):\n%s', pprint.pformat(SOURCES))
assert len(id4) == 4, \
'Invalid ID %s in SOURCES. It should be 4 characters long.'
+ if 'name' not in settings:
+ settings['name'] =id4
try:
in_ = settings['in']
except KeyError: