-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathumtskeeper
executable file
·2498 lines (2117 loc) · 101 KB
/
umtskeeper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python
#automatic UMTS internet connect/reconnect
#
#Copyright: Written by Markus Petz (Mintaka), 2012, 2013
#
#Acknowledgements:
# Kal, author of ipcheck.py (http://ipcheck.sourceforge.net/)
# Sakis Dimopoulos, author of Sakis3G (http://sakis3g.org/)
#
#Sources:
# http://mintakaconciencia.net/squares/umtskeeper/
# http://nixcraft.com/shell-scripting/12611-shell-script-detect-if-internet-link-up-not.html
# http://code.activestate.com/recipes/425210/ (hints on using BaseHTTPServer)
# http://www.sakis3g.org
#
#Licensed under the Hacktivismo Enhanced-Source Software License Agreement, Version 0.1
#
#This file is part of UMTSkeeper.
#
# This program is released under a double license:
# ------------------------------------------------
# Primarily, the Hacktivismo Enhanced-Source Software License Agreement (HESSLA),
# which can be found in full and with an additional statement about its objectives,
# at http://www.hacktivismo.com/about/hessla.php;
# and for compatibility reasons, the GNU General Public License (GPL),
# see http://www.gnu.org/licenses/.
#
# While the GPL contains the terms and conditions under which this software and
# derivative works thereof can be freely distributed, and thus is aimed merely
# at software developers, the HESSLA, while granting the same rights and
# obligations to modify and distribute the software or derivative works,
# contains additional terms that govern the use of this software. This makes
# the HESSLA function as a contract between the author and the user, rather
# than just being a copyleft agreement.
# In particular, the HESSLA contains objectives on security standards
# (section 9), the adherence of the use of the software to respecting
# human rights, political freedom and privacy standards (section 10), as well as
# special terms on the use of the software by governmental entities and
# governmental persons (section 14).
#
# For the purpose of including this software or portions thereof in GNU GPL
# licensed projects, this software is also licensed under the GPL. You may
# distribute this software or derivatives under the GNU GPL, provided that
# YOUR DISTRIBUTION IS ALSO SUBJECT TO THE HESSLA.
#
# The HESSLA; full text included in LICENSE.txt
# ---------------------------------------------
# UMTSkeeper is free software: you can redistribute it and/or modify it
# under the terms of the
# Hacktivismo Enhanced-Source Software License Agreement (HESSLA)
# as published by Hacktivismo, either version 1, or prior, of the License,
# or (at your option) any later version.
#
# By using this software, you express that you read and understood this
# license agreement, and that you are a Qualified Licensee of the software
# as laid out in section 0.8 at the time you use this software, meaning that
# you will not use this software for infringement of human rights or the
# right to privacy. You will not use this software for surveillance purposes
# or to otherwise spy on people, neither for doing any harm to a human being.
#
# UMTSkeeper is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Hacktivismo Enhanced-Source Software License Agreement (HESSLA)
# at http://www.hacktivismo.com/about/hessla.php for more details.
# The latest source of this program can be found at
# http://mintakaconciencia.net/squares/umtskeeper/
# GNU GPL:
# --------
# UMTSkeeper is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# UMTSkeeper is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with UMTSkeeper. If not, see <http://www.gnu.org/licenses/>.
import atexit, base64, hashlib, httplib, os, re, shlex, signal, subprocess, sys, thread, urllib2
from shutil import copy
from time import sleep, strftime, time, mktime, localtime
from datetime import datetime
from calendar import monthrange
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import pdb
version = '2.03'
subVersion = '20130722.22'
###### begin config
conf = {}
conf['testCycle'] = 8 #connection test period (cycles)
conf['statCycle'] = 4 #statistics cycle in seconds
conf['statSecureInt'] = 60 #period of saving the statistics file to disk
conf['wrongPinDelay'] = 60 #delay next connection try if we encounter wrong pin. This could mean that the modem is just not yet ready for connections.
conf['deviceName'] = '' #get this from lsusb (should be a part of the device name string without spaces)
conf['ifaceNAT'] = '' #network interface to share connection on (used for NAT function)
conf['ifaceName'] = 'ppp0' #network interface to monitor
conf['monthStartDay'] = 1 #day of month the monthly traffic counter is reset
conf['limitMonth'] = 0 #monthly transfer limit (in Bytes, 0 = no limit)
conf['doLimitDay'] = 0 #daily transfer limit as given on command line (in Bytes, or "auto")
conf['sakisSwitches'] = ''
conf['sakisOperators'] = ''
conf['sakisMaxFails'] = 4
conf['sakisFailLockDuration'] = 300
conf['logOnly'] = False
conf['printMsg'] = True
conf['logMsg'] = False
conf['logFile'] = '/var/log/umtskeeper.log'
#1 kByte = 1000 bytes, 1 MByte = 10^6 bytes
conf['rateThreshold'] = 250 #lower threshold for counting rate in average rates (bytes/s)
conf['secGraphMaxX'] = 100 #width of second graph (in statIntervals)
conf['secGraph'] = {'scale': 2, 'markMajor': 20, 'markMinor': 10} #kBytes/pixel, kBytes/s, kBytes/s
conf['daysGraph'] = {'scale': 50000, 'markMajor': 1000000, 'markMinor': 200000}
conf['hoursGraph'] = {'scale': 2000, 'markMajor': 100000, 'markMinor': 20000}
conf['hoursAvgGraph'] = {'scale': 1000, 'markMajor': 50000, 'markMinor': 10000}
conf['writeStats'] = True
conf['writeHTMLStats'] = False
conf['htmlReloadInterval'] = 4 #auto-refresh cycle of HTML page in seconds (0 means no refresh)
conf['htmlShowLog'] = False
conf['htmlShowGraphs'] = 2
conf['httpServer'] = False
conf['httpPort'] = 8000
conf['httpWhiteList'] = ['', 'umtskeeper.stat.html', 'style.css', 'favicon.ico', 'robots.txt']
conf['httpIPList'] = False
conf['dDNSProg'] = ''
conf['dDNSUseFreeDNSMethod'] = False
conf['dDNSUpdateURIs'] = ''
conf['dDNSSite'] = ''
conf['dDNSUseHTTPS'] = True
conf['dDNSUseHTTP'] = False
conf['dDNSPort'] = 80 #8245 is alternate for dyndns.com
conf['dDNSSendIP'] = True
conf['dDNSUsername'] = ''
conf['dDNSPassword'] = ''
conf['dDNSHosts'] = ''
conf['ipWebsite'] = ''
conf['debugLevel'] = 0
####### end config
#variables initialisation:
progPath = sys.path[0] + '/'
progName = 'umtskeeper'
sakisProg = 'nice ' + progPath + 'sakis3g'
usbResetProg = progPath + 'resetusb'
confFileName = progName + '.conf'
confFile = ''
if os.path.isfile(progPath + confFileName): #look for config file in progPath
confFile = progPath + confFileName
# if os.path.isfile('/etc/umtskeeper/' + confFileName): #look for config file in /etc/umtskeeper/
# confFile = '/etc/umtskeeper/' + confFileName
#/run/ is usually tmpfs (ramdisk) so we don't write to a possible SSD/SD-card constantly:
if os.path.isdir('/run'): conf['tempPath'] = '/run/umtskeeper/'
else: conf['tempPath'] = '/var/run/umtskeeper/' #/run/ might not be present on every system
conf['statFilePath'] = progPath
statFileName = progName + '.stat'
conf['htmlPath'] = ''
statFileHTMLName = progName + '.stat.html'
monthlyFileName = progName + '.monthly.csv'
dailyFileName = progName + '.daily.csv'
hourlyFileName = progName + '.hourly.csv'
limitExceeded = False
newSession = False
inetIsDown = True
modemPlugged = False
netOperstate = ''
disconnectNecessary = False
wrongPinCount = 0
limitDay = 0 #daily transfer limit (in Bytes, 0 = infinite)
sakisFailCtr = 0
sakisLockedUntil = 0
graphs = {}
currRate = 0
rxCurrRate = 0
txCurrRate = 0
uSecond = 0
nextStatCopySecond = 0
sessionStartTime = ''
connectionMsg = ''
rxBytes = 0
txBytes = 0
remainingBytesDaily = 0
rxRateSeconds = [0] * conf['secGraphMaxX']
txRateSeconds = [0] * conf['secGraphMaxX']
timeRateSeconds = [0.0] * conf['secGraphMaxX']
intLog = []
timer = [0.0] * 5 #killme: debug var
statFileGlobals = "st, statProgVersion, statProgSubVersion, statFileComplete"
st = {}
statProgVersion = ''
statProgSubVersion = ''
st['ifaceName'] = ''
st['lastuSec'] = 0
st['currHr'] = datetime.now().hour
st['currQHr'] = datetime.now().minute / 15
st['today'] = datetime.now().day
st['yesday'] = 0
st['dateToday'] = ''
st['weekDay'] = datetime.now().weekday()
st['currMonth'] = datetime.now().month
st['nextMonthStartSec'] = long(mktime((datetime.now().year, st['currMonth']+1, conf['monthStartDay'], 0, 0, 0, 0, 0, 0)))
st['currCalendarMonth'] = st['currMonth']
st['currYear'] = datetime.now().year
st['sessStartTmSaved'] = ''
st['offlSince'] = ''
st['rxBTot'] = 0
st['txBTot'] = 0
st['rxBSessStart'] = 0
st['txBSessStart'] = 0
st['rxBytes'] = 0
st['txBytes'] = 0
st['rxBQHrStart'] = 0
st['txBQHrStart'] = 0
st['rxBQHr'] = 0
st['txBQHr'] = 0
st['rxBHrStart'] = 0
st['txBHrStart'] = 0
st['rxBHr'] = 0
st['txBHr'] = 0
st['qHrMaxRate'] = 0
st['qHrAvgRateAcc'] = 0
st['qHrAvgRateAccCtr'] = 0
st['hrMaxRate'] = 0
st['hrAvgRateAcc'] = 0
st['hrAvgRateAccCtr'] = 0
st['rxBTodayStart'] = 0
st['txBTodayStart'] = 0
st['rxBToday'] = 0
st['txBToday'] = 0
st['rxBYesday'] = 0
st['txBYesday'] = 0
st['rxBMonthStart'] = 0
st['txBMonthStart'] = 0
st['rxBMonth'] = 0
st['txBMonth'] = 0
st['bMonthMin'] = 0
st['bMonthMinDate'] = 'n/a'
st['bMonthMax'] = 0
st['bMonthMaxDate'] = 'n/a'
st['rateSecondsHr'] = [0]
st['rateSecondsQHr'] = [0]
st['rxBHrs'] = [0] * 24
st['txBHrs'] = [0] * 24
st['rxBHrsYesday'] = [0] * 24
st['txBHrsYesday'] = [0] * 24
st['rxBQHrs'] = map(lambda x: [x,x,x,x], st['rxBHrs'])
st['txBQHrs'] = map(lambda x: [x,x,x,x], st['txBHrs'])
st['rxBQHrsYesday'] = map(lambda x: [x,x,x,x], st['rxBHrsYesday'])
st['txBQHrsYesday'] = map(lambda x: [x,x,x,x], st['txBHrsYesday'])
st['rxBDays'] = [0] * 31
st['txBDays'] = [0] * 31
st['rxBDaysLastMonth'] = [0] * 31
st['txBDaysLastMonth'] = [0] * 31
st['rxBHrsAcc'] = [0] * 24
st['txBHrsAcc'] = [0] * 24
st['bHrsAccCtr'] = [0] * 24
st['rxBQHrsAcc'] = map(lambda x: [x,x,x,x], st['rxBHrsAcc'])
st['txBQHrsAcc'] = map(lambda x: [x,x,x,x], st['txBHrsAcc'])
st['bQHrsAccCtr'] = map(lambda x: [x,x,x,x], st['bHrsAccCtr'])
st['rxBHrsWAcc'] = [0] * 24 * 7
st['txBHrsWAcc'] = [0] * 24 * 7
st['bHrsWAccCtr'] = [0] * 24 * 7
st['hrsMaxRateAcc'] = [0] * 24
st['hrsMaxRateAccCtr'] = [0] * 24
st['hrs95RateAcc'] = [0] * 24 #experimental: 95-percentile should work better than max rate
st['hrs50RateAcc'] = [0] * 24 #experimental: median could work better than mean
st['hrs95RateAccCtr'] = [0] * 24 #counters for both 95-percentiles and medians
st['qHrsMaxRateAcc'] = map(lambda x: [x,x,x,x], st['hrsMaxRateAcc'])
st['qHrsMaxRateAccCtr'] = map(lambda x: [x,x,x,x], st['hrsMaxRateAccCtr'])
st['qHrs95RateAcc'] = map(lambda x: [x,x,x,x], st['hrs95RateAcc']) #experimental: 95-percentile should work better than max rate
st['qHrs50RateAcc'] = map(lambda x: [x,x,x,x], st['hrs50RateAcc']) #experimental: median could work better than mean
st['qHrs95RateAccCtr'] = map(lambda x: [x,x,x,x], st['hrs95RateAccCtr']) #counters for both 95-percentiles and medians
st['hrsMaxRateWAcc'] = [0] * 24 * 7
st['hrsMaxRateWAccCtr'] = [0] * 24 * 7
st['hrs95RateWAcc'] = [0] * 24 * 7 #experimental: 95-percentile should work better than max rate
st['hrs50RateWAcc'] = [0] * 24 * 7 #experimental: median could work better than mean
st['hrs95RateWAccCtr'] = [0] * 24 * 7 #counters for both 95-percentiles and medians
st['hrsAvgRateAcc'] = [0] * 24
st['hrsAvgRateAccCtr'] = [0] * 24
st['qHrsAvgRateAcc'] = map(lambda x: [x,x,x,x], st['hrsAvgRateAcc'])
st['qHrsAvgRateAccCtr'] = map(lambda x: [x,x,x,x], st['hrsAvgRateAccCtr'])
st['hrsAvgRateWAcc'] = [0] * 24 * 7
st['hrsAvgRateWAccCtr'] = [0] * 24 * 7
st['ip'] = ''
st['dDNSLocked'] = False
st['dDNSLockedUntil'] = 0
st['dDNSConfHash'] = ''
st['dDNSNextTest'] = 0
statFileComplete = False
class DNSUpdater():
def __init__(self):
if conf['dDNSProg']+conf['dDNSUpdateURIs']+conf['dDNSHosts'] != '':
self.enabled = True
else:
self.enabled = False
#end __init__
def GetIP_local(self, ifName):
ipdata = subprocess.Popen('ip addr', shell=True, stdout=subprocess.PIPE).communicate()[0]
reIP = re.compile(r'.*'+ifName+'.*inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', re.DOTALL)
return reIP.search(ipdata).group(1)
#end GetIP_local
def GetIP_web(self, site):
try:
PrintMessage('Trying to get IP from URL ' + site)
req = urllib2.Request(site)
req.add_header('User-agent', 'UMTSkeeper/'+version)
urlfp = urllib2.urlopen(req)
ipdata = urlfp.read()
urlfp.close()
# grab first thing that looks like an IP address
Addressgrep = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
ipmatch = Addressgrep.search(ipdata)
if ipmatch != None:
return ipmatch.group()
except Exception, e:
PrintMessage('Unable to open URL ' + site + ': ' + str(e))
return ''
#end GetIP_web
def GetConfHash(self):
return hashlib.sha256(conf['dDNSSite'] + str(conf['dDNSUseHTTP']) + str(conf['dDNSUseHTTPS']) + str(conf['dDNSPort']) + \
conf['dDNSHosts'] + conf['dDNSUsername'] + conf['dDNSPassword']).hexdigest()
def Update(self):
global conf, st
#unlock timer update lock:
if st['dDNSLockedUntil'] and (time() > st['dDNSLockedUntil']):
st['dDNSLockedUntil'] = 0
st['dDNSLocked'] = False
if st['dDNSLocked']:
if self.GetConfHash() != st['dDNSConfHash']: #configuration has changed -> unlock update
st['dDNSLocked'] = False
else:
PrintMessage('DNS update is locked (see previous errors).', False)
#call external DDNS update prog
if conf['dDNSProg'] != '':
SubprocessCallWithLog(conf['dDNSProg'])
##################
# internal updater
elif \
( (conf['dDNSUseFreeDNSMethod'] and conf['dDNSUpdateURIs'] != '') \
or \
( (conf['dDNSSite'] != '') and \
(conf['dDNSHosts'] != '') and \
(conf['dDNSUsername'] != '') and \
(conf['dDNSPassword'] != '') \
) \
) \
and (not st['dDNSLocked']) \
:
if conf['ipWebsite'] != '': #get IP from website
ip = self.GetIP_web(conf['ipWebsite'])
if ip == '':
if conf['runDDNSRetry']:
conf['runDDNSRetry'] -= 1
st['dDNSNextTest'] = time() + 10
else:
st['dDNSNextTest'] = time() + 30 * 60
PrintMessage('Retry limit reached, could not get the IP from %s. Check if the address is correct and the internet connections works.' % conf['ipWebsite'], False)
else: #get local IP
ip = self.GetIP_local(conf['ifaceName'])
if ip == '':
PrintMessage('Unable to get IP.', False)
return(0)
#test for private IP:
elif \
(ip[:7] == '192.168') or \
(ip[:3] == '10.') or \
(ip[:3] == '172' and ip[6] == '.' and (int(ip[4:6]) >= 16 and int(ip[4:6]) <= 31)) or \
(ip == '127.0.0.1') \
:
PrintMessage('Got a private IP for interface %s: %s, but would need a public IP to update DNS. Perhaps you are connected to the internet through a gateway/firewall with address translation. In this case, your public IP can be determined with the help of an external webserver. Set a website address that returns your IP, using conf[\'ipWebsite\'].' % (conf['ifaceName'], ip), False)
else: #alright, we got an IP
msg = 'Got IP: %s; ' % ip
if ip == st['ip']:
PrintMessage(msg+'no change - no need for DNS update.', False)
else: #new ip does not match stored one -> update DNS
PrintMessage(msg+'IP has changed. Starting DNS update.', False)
#freedns style update method:
if conf['dDNSUseFreeDNSMethod']:
updateURIs = conf['dDNSUpdateURIs'].replace(' ', '').split(',') #strip spaces from hosts list
for uri in updateURIs:
req = urllib2.Request(uri)
req.add_header('User-agent', 'UMTSkeeper/'+version)
urlfp = urllib2.urlopen(req)
httpData = urlfp.read()
urlfp.close()
PrintMessage(httpData, False)
#end freedns style update method
#Members NIC Update API (dyndns style update method):
elif conf['dDNSHosts'] != '':
dDNSHosts = conf['dDNSHosts'].replace(' ', '') #strip spaces from hosts list
dDNSSite = conf['dDNSSite']
if dDNSSite[0:7] == 'http://': dDNSSite = dDNSSite[7:]
if dDNSSite[0:8] == 'https://': dDNSSite = dDNSSite[8:]
i = dDNSSite.find('/')
dDNSPage = dDNSSite[i:]
dDNSSite = dDNSSite[0:i]
if conf['dDNSSendIP']:
suffix = '?myip=' + ip + '&hostname=' + dDNSHosts
else:
suffix = '?myip=&hostname=' + dDNSHosts
h2 = None
tryHTTP = True
if conf['dDNSUseHTTPS']:
try:
h2 = httplib.HTTPS(conf['dDNSSite'])
PrintMessage('HTTPS connection to ' + dDNSSite + ' successful.', False)
tryHTTP = False
except:
PrintMessage('HTTPS connection to ' + dDNSSite + ' failed.', False)
if conf['dDNSPort'] == 443: tryHTTP = False #if port is HTTPS then skip HTTP
if conf['dDNSUseHTTP'] and tryHTTP:
try:
h2 = httplib.HTTP(dDNSSite, conf['dDNSPort'])
PrintMessage('HTTP connection to ' + dDNSSite + ' on port ' + str(conf['dDNSPort']) + ' successful.', False)
except:
PrintMessage('HTTP connection to ' + dDNSSite + ' on port ' + str(conf['dDNSPort']) + ' failed. Can not update DNS.', False)
if not h2: return
h2.putrequest('GET', dDNSPage + suffix)
h2.putheader('HOST', dDNSSite)
h2.putheader('USER-AGENT', 'UMTSkeeper/' + version + ' http://mintakaconciencia.net/')
authstring = base64.encodestring(conf['dDNSUsername'] + ':' + conf['dDNSPassword'])
authstring = authstring.replace('\012', '')
h2.putheader('AUTHORIZATION', 'Basic ' + authstring)
h2.endheaders()
errMsg = ''
errCode = 0
errCode, errMsg, headers = h2.getreply()
PrintMessage('HTTP return code: %d; %s' % (errCode, errMsg))
lockMsg = 'To prevent being blocked, DNS update is LOCKED until the configuration is corrected and UMTSkeeper is restarted.'
if errCode == 404:
PrintMessage('Received a 404 error. This means that conf[\'dDNSSite\'] or conf[\'dDNSPage\'] is wrong. '+lockMsg, False)
st['dDNSLocked'] = True
#get the html text
try:
f = h2.getfile()
httpData = f.read()
f.close()
except:
httpData = 'No output from HTTP request.'
#process return codes:
hostRes = map(lambda x: x.split(' '), httpData.split('\n'))
hosts = conf['dDNSHosts'].split(',')
for key, r in enumerate(hostRes):
if r[0] == 'good':
if r[1] == '127.0.0.1':
PrintMessage(hosts[key] + ': The request was ignored because the user agent does not follow DDNS specifications. Please report to the author of UMTSkeeper.', False)
st['dDNSLocked'] = True
else:
PrintMessage(hosts[key] + ': IP updated', False)
elif r[0] == 'nochg':
PrintMessage(hosts[key] + ': IP didn\'t change', False)
elif r[0] == 'badauth':
PrintMessage('Bad authentication. The username or password is wrong. '+lockMsg, False)
elif r[0] == '!donator':
PrintMessage('An update request was sent including a feature that is not available to that particular user. '+lockMsg, False)
elif r[0] == 'notfqdn':
PrintMessage(hosts[key] + ': The hostname specified is not a fully-qualified domain name. '+lockMsg, False)
elif r[0] == 'nohost':
PrintMessage(hosts[key] + ': The hostname specified does not exist in this user account. '+lockMsg, False)
elif r[0] == 'numhost':
PrintMessage(hosts[key] + ': Too many hosts (more than 20) specified in an update. '+lockMsg, False)
elif r[0] == 'abuse':
PrintMessage(hosts[key] + ': The user specified is blocked for update abuse. '+lockMsg, False)
elif r[0] == 'badagent':
PrintMessage(hosts[key] + ': The user agent was not sent or HTTP method is not permitted. Please report to the author of UMTSkeeper.', False)
elif r[0] == 'dnserr':
PrintMessage(hosts[key] + ': DNS error encountered. This is a remote server error. DNS update will be suspended for 30 minutes. Contact your DDNS customer support if this error persists.', False)
st['dDNSLockedUntil'] = time() + 30 * 60
elif r[0] == '911':
PrintMessage(hosts[key] + ': There is a problem or scheduled maintenance on the DDNS side. This is a remote server error. DNS update will be suspended for 30 minutes. Contact your DDNS customer support if this error persists.', False)
st['dDNSLockedUntil'] = time() + 30 * 60
lockCodes = ['badauth', '!donator', 'notfqdn', 'nohost', 'numhost', 'abuse', 'badagent', 'dnserr', '911']
if r[0] in lockCodes: st['dDNSLocked'] = True
#end Members NIC Update API
if st['dDNSLocked']:
st['dDNSConfHash'] = self.GetConfHash()
else:
st['ip'] = ip
#end if ip != st['ip']
#end if got IP
#end elif conf['dDNSSite']
st['dDNSNextTest'] = time() + 30*60
#end Update
#end class DNSUpdater
class HTTPHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args):
pass
def do_GET(self):
global conf, st
self.path = self.path[1:]
try:
#whitelist of client IPs, accept '*' wildcard at end:
if (not conf['httpIPList']) or \
(reduce( \
lambda x,y: x or y,
map(lambda a: \
(a[0:-1] == self.client_address[0][0:-1][0:len(a)-1]) if a[-1]=='*' \
else (a == self.client_address[0]), \
conf['httpIPList']) \
)):
#process URI arguments:
iarg = self.path.find('?')
if iarg >= 0:
args = map(lambda x: x.split('='), self.path[iarg+1:].split('&'))
for arg in args:
try:
if arg[0] == 'refresh': conf['runHTMLReloadInterval'] = int(arg[1])
elif arg[0] == 'showlog': conf['runHTMLShowLog'] = int(arg[1])
elif arg[0] == 'showgraphs': conf['runHTMLShowGraphs'] = int(arg[1])
elif arg[0] == 'reconnect': SakisReconnect()
elif arg[0] == 'updatedns': st['dDNSNextTest'] = time()
except: pass
self.path = self.path[0:iarg]
#whitelist of files to serve (see else: clause):
if (not conf['httpWhiteList']) or (self.path in conf['httpWhiteList']):
if conf['htmlPath'] != '': docroot = conf['htmlPath']
else: docroot = conf['tempPath']
if self.path == '':
if os.path.isfile(docroot + 'index.html'): #if index.html is found, serve that one
self.path = 'index.html'
else:
self.path = statFileHTMLName #else serve stat file
if (not conf['writeHTMLStats']) and (self.path == statFileHTMLName):
s = WriteStatFileHTML(True)
else:
f = open(docroot + self.path)
s = f.read()
f.close()
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(s)
else: #file not found in whitelist
self.send_error(403,'Forbidden: %s' % self.path)
else: #ip not in ip whitelist
self.send_error(403,'Access denied by IP whitelist')
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
#end class HTTPHandler
class ThreadedHTTPServer(HTTPServer):
def serve(self):
while 1:
self.handle_request()
class Graph:
def __init__(self, \
which='', fileName='', values=[], width=0, xTextPos=10, plotMargin=[2,0,0,2], graphMargin=[0,0,0,0], \
drawXScale=False, drawXScaleMarks=False, xScaleMajor=0, xScaleMinor=0, \
xText=[], xTextOffs=0, fontStyle='font-family:sans-serif', fontSize=8, \
yAxisPos=0, graphMaxPreset=0, yScale=0, yScaleMajor=0, yScaleMinor=0, yGridMajor=True, yGridMinor=True, \
barWidth=[14,14,4,4], barDist=[16,16,4,4], barStyles=['fill:#df2f2f','fill:#2fbf2f','fill:#ff70d0;fill-opacity:0.75','fill:70ffd0;fill-opacity:0.75'] \
):
self.which = which
self.fileName = fileName
self.file = conf['tempPath'] + self.fileName
self.values = values
self.horLines = []
self.vertLines = []
self.valScaled = []
self.width = width
self.height = 0
self.xTextPos = xTextPos
self.plotMargin = plotMargin #margin around plot area (area inside the axes)
self.graphMargin = graphMargin #margin around whole graph (including axes and scales)
self.margin = map(lambda pm,gm: pm+gm, self.plotMargin, self.graphMargin) #margins for everything in plot area
self.drawXScale = drawXScale
self.drawXScaleMarks = drawXScaleMarks
self.xScaleMajor = xScaleMajor
self.xScaleMinor = xScaleMinor
self.xText = xText
self.xTextOffs = xTextOffs
self.fontStyle = fontStyle
self.fontSize = fontSize
self.yAxisPos = yAxisPos
self.graphMaxPreset = graphMaxPreset
self.graphMax = 0
self.yScale = yScale
self.xAxisPos = 0
self.yScaleMajor = yScaleMajor
self.yScaleMinor = yScaleMinor
self.yGridMajor = yGridMajor
self.yGridMinor = yGridMinor
self.barWidth = barWidth
self.barDist = barDist
self.barStyles = barStyles
self.svg = ''
self.refresh = True
#end __init__
def InitGraph(self, maxValue):
self.graphMax = self.graphMaxPreset
if maxValue > self.graphMax: self.graphMax = maxValue
self.horLines = sorted(self.horLines)
if (len(self.horLines) > 0) and (self.horLines[-1][0] > self.graphMax):
self.graphMax = self.horLines[-1][0]
self.xAxisPos = self.margin[0] + self.graphMax / self.yScale
self.height = self.xAxisPos + self.xTextPos + self.margin[2] + 1
self.yAxisPos = self.margin[3] + len(self.values[0]) * self.barDist[0]
if self.width == 0: self.width = self.yAxisPos + 33 + self.margin[1]
self.valScaled = []
#end InitGraph
def AddBarData(self, upEnd, lowEndScaled=False):
#compile list of boxes to draw for two sets of boxes: [[[y0,y1,y2...],[h0,h1,h2...]...], [[y0,y1,y2...],[h0,h1,h2...]...]]
self.valScaled.append( \
[ ([1]*len(upEnd) if not lowEndScaled \
else map(lambda x: x+1, lowEndScaled)), map(lambda x: (float(x)/self.yScale), upEnd) \
] \
)
#end AddBarData
def SVGStart(self):
self.svg = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 %d %d" preserveAspectRatio="xMinYMin meet" style="%s;font-size:%dpx">' % (self.width, self.height, self.fontStyle, self.fontSize)
self.svg += '<rect x="%d" y="%d" width="%d" height="%d" style="fill:#e0e0e0"/>' % (self.graphMargin[3], self.graphMargin[0], self.yAxisPos-self.graphMargin[3], self.xAxisPos-self.graphMargin[0]) #shaded background
#end SVGStart
def DrawHorizontalScale(self):
ap = self.xAxisPos + 0.5
self.svg += '<g style="stroke:rgb(0,0,0);shape-rendering:crispEdges">'
#x-axis line
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d"/>' % (self.graphMargin[3], ap, self.yAxisPos+0.5, ap)
if self.drawXScale:
scaleMarkDist = self.xScaleMinor * self.barDist[0]
for i in range(0, (self.yAxisPos-self.margin[3])/scaleMarkDist):
if i % (self.xScaleMajor / self.xScaleMinor) == 0: #major scale
if i > 0:
if self.drawXScaleMarks:
#major scale marks
x = self.margin[3]+i*scaleMarkDist
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,0)"/>' % \
(x, ap, x, self.xAxisPos+7)
#major scale text
self.svg += '<text x="%d" y="%d">%s</text>' % \
( self.margin[3]+i*scaleMarkDist+self.xTextOffs, \
self.xAxisPos+self.xTextPos, \
self.xText[i/(self.xScaleMajor/self.xScaleMinor)] \
)
elif self.xScaleMinor != self.xScaleMajor: #minor scale: marks can be turned off by setting minor scale = major scale
if self.drawXScaleMarks > 0:
#minor scale marks
x = self.margin[3]+i*scaleMarkDist
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,0)"/>' % \
(x, ap, x, self.xAxisPos+4)
self.svg += '</g>'
#end DrawHorizontalScale
def DrawVertScale(self):
scaleMarkDist = self.yScaleMinor / self.yScale
markerDiv = 1
if self.yScaleMajor > 999999999:
markerDiv = 1000000000
markerChar = "G"
elif self.yScaleMajor > 999999:
markerDiv = 1000000
markerChar = "M"
elif self.yScaleMajor > 999:
markerDiv = 1000
markerChar = "k"
ap = self.yAxisPos + 0.5
self.svg += '<g style="stroke:rgb(0,0,0);shape-rendering:crispEdges">'
#y-axis line
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d"/>' % (ap, self.graphMargin[0], ap, self.xAxisPos+1)
for i in range(1, int((self.xAxisPos-self.margin[0])/scaleMarkDist)+1):
y = self.xAxisPos - (i * scaleMarkDist)
if i % (self.yScaleMajor / self.yScaleMinor) == 0: #major scale
#major scale marks
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d"/>' % (ap, y, ap+7, y)
if i > 0:
#major scale text
self.svg += '<text x="%d" y="%d">%d%s</text>' % (ap+10, y+self.fontSize/2-1, (i*self.yScaleMinor)/markerDiv, markerChar)
if self.yGridMajor:
#major grid
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:#a0a0a0;stroke-opacity:0.4"/>' % \
(self.margin[3], y, ap-0.5, y)
else: #minor scale
#minor scale marks
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d"/>' % (ap, y, ap+4, y)
if self.yGridMinor:
#minor grid
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:#c0c0c0;stroke-opacity:0.4"/>' % \
(self.margin[3], y, ap-0.5, y)
self.svg += '</g>'
#end DrawVertScale
def DrawBars(self, addsFront, addsBack):
self.svg += addsBack
for j in range(0, len(self.valScaled)):
self.svg += '<g style="%s">' % (self.barStyles[j]) #group bars for style
#reduce box coordinates list to svg:
self.svg += reduce(lambda s1,s2: s1+s2, \
map( \
lambda y,h: ( \
'<rect x="%d" y="%.1f" width="%d" height="%.1f"/>' %
(self.margin[3]+y[0]*self.barDist[j], self.xAxisPos-y[1]-h+1, self.barWidth[j], h) \
) if h>0.25 else '', \
list(enumerate(self.valScaled[j][0])), self.valScaled[j][1] \
) \
)
self.svg += '</g>'
self.svg += addsFront
#end DrawBars
def DrawLines(self):
self.svg += '<g style="shape-rendering:crispEdges">'
lh = self.fontSize + 2
i = self.xAxisPos - 2
ty1 = self.xAxisPos - 2 + lh
lineList = list(enumerate(self.horLines))
for l in lineList:
#spacing the captions:
ty = self.xAxisPos - l[1][0] / self.yScale
if ty > (ty1 - lh): ty = ty1 - lh
if ty < (self.margin[0] + self.fontSize/2 + (len(lineList)-1-l[0])*lh):
ty = self.margin[0] + self.fontSize/2 + (len(lineList)-1-l[0])*lh
#horizontal line:
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="%s"/>' % \
( self.margin[3], \
self.xAxisPos - l[1][0] / self.yScale, \
self.yAxisPos, \
self.xAxisPos - l[1][0] / self.yScale, \
l[1][1] \
)
if l[1][2] != '':
#connecting line to caption:
self.svg += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="%s"/>' % \
( self.margin[3], \
self.xAxisPos - l[1][0] / self.yScale, \
self.margin[3] - lh, \
ty, \
l[1][1] \
)
#caption text:
self.svg += '<text x="%d" y="%d" text-anchor="end">%s</text>' % \
(self.margin[3]-12, ty+self.fontSize/2-1, l[1][2])
ty1 = ty
i -= lh
self.svg += '</g>'
#end DrawLines
def SVGEnd(self):
self.svg += '</svg>'
#end SVGEnd
def ComposeSVG(self, addsFront='', addsBack=''):
self.SVGStart()
self.DrawHorizontalScale()
self.DrawBars(addsFront, addsBack)
self.DrawVertScale()
self.DrawLines()
self.SVGEnd()
#end ComposeSVG
def Draw(self):
s = ''
#'seconds' graph:
if self.which == 'sec':
self.values = [txRateSeconds, rxRateSeconds]
st['rateSecondsHr'].sort()
self.horLines = []
# self.horLines.append([st['rateSecondsHr'][-1], 'stroke:rgb(64,64,160)', 'maximum: %d' % (st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.99)])])
self.horLines.append([st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.95)], 'stroke:#6060a0;stroke-opacity:0.8', '95-percentile: %d' % (st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.95)])])
hr95 = int(st['hrs95RateWAcc'][st['currHr'] + 24 * (st['weekDay'] - 1)] / (st['hrs95RateWAccCtr'][st['currHr'] + 24 * (st['weekDay'] - 1)] + 1e-6)) #get 95-percentile for this hour of the week
self.horLines.append([hr95, 'stroke:#a0a0c0;stroke-opacity:0.8', 'exp. 95%%: %d' % hr95])
# self.horLines.append([st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.90)], 'stroke:rgb(128,128,224)', '90-percentile: %d' % (st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.90)])])
# self.horLines.append([st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.50)], 'stroke:rgb(96,96,192)', 'median: %d' % (st['rateSecondsHr'][int(len(st['rateSecondsHr'])*0.50)])])
self.horLines.append([st['hrAvgRateAcc'] / (st['hrAvgRateAccCtr']+1e-6), 'stroke:#a04000;stroke-opacity:0.8', 'hour mean: %d' % (st['hrAvgRateAcc'] / (st['hrAvgRateAccCtr']+1e-6))])
hrAvg = int(st['hrsAvgRateWAcc'][st['currHr'] + 24 * (st['weekDay'] - 1)] / (st['hrsAvgRateWAccCtr'][st['currHr'] + 24 * (st['weekDay'] - 1)] + 1e-6)) #get average for this hour of the week
self.horLines.append([hrAvg, 'stroke:#a0a000;stroke-opacity:0.8', 'exp. mean: %d' % hrAvg])
self.graphMaxPreset = len(self.horLines) * (self.fontSize + 2) * self.yScale
self.InitGraph(max(map(lambda x,y: x+y, self.values[0], self.values[1])))
#'seconds' rate graph has a special dynamic x scale:
ti = 15
markMinDist = 1.5
i = len(timeRateSeconds)-2
t0 = timeRateSeconds[i+1]
x1 = self.yAxisPos
s += '<g style="stroke:rgb(0,0,0);shape-rendering:crispEdges">'
while i > 0:
t = timeRateSeconds[i]
if (t > 0):
if t0-t >= ti:
x = self.yAxisPos - (len(timeRateSeconds) - 1 - InterpolLin(t0-t, i, t0-timeRateSeconds[i+1], i+1, ti)) * self.barDist[0] #nicely interpolate scale mark position: looks way better
if (x1 - x) >= markMinDist:
x1 = x
if ti%4 == 0:
#major scale marks
s += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,0)"/>' % \
( x, self.xAxisPos+0.5, \
x, self.xAxisPos+7)
#major scale text
s += '<text x="%d" y="%d">%s</text>' % \
( x+self.xTextOffs, \
self.xAxisPos+self.xTextPos, \
str(ti/60) \
)
else:
#minor scale marks
s += '<line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,0)"/>' % \
( x, self.xAxisPos+0.5, \
x, self.xAxisPos+4)
ti += 15
i += 1 #try the same bar again (reconnects may have 15+ sec in one bar)
#end if (x1 - x) >= markMinDist
#end if t > 0
i -= 1
#end for t
s += '</g>'
self.AddBarData(self.values[0])
self.AddBarData(self.values[1], self.valScaled[0][1])
#end 'seconds' graph
#'hours' graph:
elif self.which == 'hrs':
self.values = [ \
st['txBHrsYesday'] + st['txBHrs'], \
st['rxBHrsYesday'] + st['rxBHrs'], \
reduce(lambda y1,y2: y1+y2, st['txBQHrsYesday']) + reduce(lambda y1,y2: y1+y2, st['txBQHrs']), \
reduce(lambda y1,y2: y1+y2, st['rxBQHrsYesday']) + reduce(lambda y1,y2: y1+y2, st['rxBQHrs']) \
]
self.InitGraph(max(map(lambda x,y: x+y, self.values[0], self.values[1])))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1], self.valScaled[0][1])
self.AddBarData(self.values[2])
self.AddBarData(self.values[3], self.valScaled[2][1])
#'days' graph:
elif self.which == 'days':
self.values = [ \
st['txBDaysLastMonth'] + st['txBDays'], \
st['rxBDaysLastMonth'] + st['rxBDays'], \
]
self.yAxisPos = self.barDist[0] * len(self.values[0])
self.width = self.yAxisPos + 33
#get a list of day numbers for last month and current month:
self.xText = \
map(lambda x: '%02d' % (x[0]+1), list(enumerate(st['rxBDaysLastMonth']))) + \
map(lambda x: '%02d' % (x[0]+1), list(enumerate(st['rxBDays'])))
self.InitGraph(max(map(lambda x,y: x+y, self.values[0], self.values[1])))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1], self.valScaled[0][1])
#'hours average week' graph:
elif self.which == 'hrsWAcc':
self.values = [ \
map(lambda x,n: x/(n+1e-6), st['txBHrsWAcc'], st['bHrsWAccCtr']), \
map(lambda x,n: x/(n+1e-6), st['rxBHrsWAcc'], st['bHrsWAccCtr']), \
]
self.InitGraph(max(map(lambda x,y: x+y, self.values[0], self.values[1])))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1], self.valScaled[0][1])
#'hours avgrate' graph:
elif self.which == 'hrsAvgRate':
self.values = [ \
# map(lambda x,n: x/(n+1e-6), st['hrsAvgRateAcc'], st['hrsAvgRateAccCtr']), \
map(lambda x,n: x/(n+1e-6), reduce(lambda y1,y2: y1+y2, st['qHrsAvgRateAcc']), reduce(lambda y1,y2: y1+y2, st['qHrsAvgRateAccCtr'])), \
map(lambda x,n: x/(n+1e-6), reduce(lambda y1,y2: y1+y2, st['qHrs50RateAcc']), reduce(lambda y1,y2: y1+y2, st['qHrs95RateAccCtr'])) \
]
self.InitGraph(max(self.values[0] + self.values[1]))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1])
#'hours maxrate' graph:
elif self.which == 'hrsMaxRate':
self.values = [ \
# map(lambda x,n: x/(n+1e-6), st['hrsMaxRateAcc'], st['hrsMaxRateAccCtr']), \
map(lambda x,n: x/(n+1e-6), reduce(lambda y1,y2: y1+y2, st['qHrsMaxRateAcc']), reduce(lambda y1,y2: y1+y2, st['qHrsMaxRateAccCtr'])), \
map(lambda x,n: x/(n+1e-6), reduce(lambda y1,y2: y1+y2, st['qHrs95RateAcc']), reduce(lambda y1,y2: y1+y2, st['qHrs95RateAccCtr'])) \
]
self.InitGraph(max(self.values[0] + self.values[1]))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1])
#'hours average rate week' graph:
elif self.which == 'hrsAvgRateW':
self.values = [ \
map(lambda x,n: x/(n+1e-6), st['hrsAvgRateWAcc'], st['hrsAvgRateWAccCtr']), \
map(lambda x,n: x/(n+1e-6), st['hrs50RateWAcc'], st['hrs95RateWAccCtr']) \
]
self.InitGraph(max(self.values[0] + self.values[1]))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1])
#'hours max rate week' graph:
elif self.which == 'hrsMaxRateW':
self.values = [ \
map(lambda x,n: x/(n+1e-6), st['hrsMaxRateWAcc'], st['hrsMaxRateWAccCtr']), \
map(lambda x,n: x/(n+1e-6), st['hrs95RateWAcc'], st['hrs95RateWAccCtr']) \
]
self.InitGraph(max(self.values[0] + self.values[1]))
self.AddBarData(self.values[0])
self.AddBarData(self.values[1])
#'hours average' graph: