root/trunk/tool/renetcolGUI.py @ 73

Revision 73, 53.4 KB (checked in by andreu, 15 years ago)

last changes before next release

  • Property svn:eol-style set to native
Line 
1
2##  File: renetcolGUI.py
3 
4##  Authors: ANDREU Francois-Xavier
5 
6##  Copyright (C) 2005-2006-2007-2008 GIP RENATER
7 
8
9##   This file is part of renetcol.
10 
11##   renetcol is free software; you can redistribute it and/or modify
12##   it under the terms of the GNU General Public License as published by
13##   the Free Software Foundation; either version 2 of the License, or
14##   (at your option) any later version.
15 
16##   renetcol is distributed in the hope that it will be useful,
17##   but WITHOUT ANY WARRANTY; without even the implied warranty of
18##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19##   GNU General Public License for more details.
20 
21##   You should have received a copy of the GNU General Public License
22##   along with renetcol; if not, write to the Free Software
23##   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 
25
26# Make Windows actually find the stuff installed
27# You must check up if it's the good path to GTK
28gtkdir = 'C:/Program Files/Fichiers communs/GTK/'
29
30import os
31import binascii
32import struct
33import time
34os.environ['PATH'] += ";%s/lib;%s/bin" % (gtkdir, gtkdir)
35
36import threading
37import string
38import re
39import socket
40import sys
41import gtk
42import traceback
43import pango
44import commands
45from optparse import OptionParser
46
47########### DEFAULT VALUES, YOU MUST CHANGE IT ###############################
48IPversion = 4
49localAddr = ''
50localAddr6 = '0::'
51localPort = 2222
52collectorAddr = "127.0.0.1"
53collectorAddr6 = "0::"
54collectorPort = 52571  # if you change this port number, apply the
55                       # modification on the renetcolSender.h file
56                       # and you'll need a new compilation of the colllector
57##############################################################################
58
59myInputControlThread = None
60printValue =      [ 0,1,1,0,1,0,0,1,1,0,
61                    0,1,1,0,0,0,0,0,0,0,
62                    1,0,0,0,0,0,0,1,1,0,
63                    0,0,0,0,0,0,0,0,0,0,
64                    0,0,0,0,0,0,1,1,0,0,
65                    0,0,0,0,0,0,0,0,0,0,
66                    0,0,0,0,0,0,0,0,0,0,
67                    1,1,1,1,1,1,1,1,1,1,
68                    0,0,0,0,0,0,0,0,0,0
69                    ]
70firstParseValue = [ 0,0,0,0,0,0,0,0,0,0,
71                    0,0,0,0,0,0,0,0,0,0,
72                    0,0,0,0,0,0,0,0,0,0,
73                    0,0,0,0,0,0,0,0,0,0,
74                    0,0,0,0,0,0,0,0,0,0,
75                    0,0,0,0,0,0,0,0,0,0,
76                    0,0,0,0,0,0,0,0,0,0,
77                    0,0,0,0,0,0,0,0,0,0,
78                    0,0,0,0,0,0,0,0,0,0
79                    ]
80checkUpValues =   [ 0,0,0,0,0,0,0,0,0,0,
81                    0,0,0,0,0,0,0,0,0,0,
82                    0,0,0,0,0,0,0,0,0,0,
83                    0,0,0,0,0,0,0,0,0,0,
84                    0,0,0,0,0,0,0,0,0,0,
85                    0,0,0,0,0,0,0,0,0,0,
86                    0,0,0,0,0,0,0,0,0,0,
87                    0,0,0,0,0,0,0,0,0,0,
88                    0,0,0,0,0,0,0,0,0,0
89                    ]
90fieldsName =  [ "","IN_BYT","IN_PKTS","","PROT","TOS","TCP_FL","S_PORT","IPv4@S","S_MASK",
91                "InSNMP","D_PORT","IPv4@D","D_MASK","OutSNMP","NextHop","S_AS","D_AS","","",
92                "","Time","","","","","","IPv6@S","IPv6@D","",
93                "","","","","","","","","","",
94                "","","","","","","M_T_L_T","M_T_L_@","","",
95                "","","","","","","","","","",
96                "","","","","","","","","","ROUTER",
97                "M_L_1","M_L_2","M_L_3","M_L_4","M_L_5","M_L_6","M_L_7","M_L_8","M_L_9","M_L_10",
98                "","","","","","","","","",""
99                ]
100flowCpt = 0
101mask = [ 0,0,0 ]
102spaceSep = " "
103tabSep = "\t"
104freeze = 0
105record = 0
106record_file_name = ""
107record_file = None
108is_already_see = 0
109collectorRule=""
110coll_window = gtk.Window()
111router=0
112tpl_def = {}
113os_type = 0
114oldTpl = 0
115fromRouter = ""
116myTimer = None
117myCPT = 1
118
119class InputControl(threading.Thread):
120    def kill(self, timeout):
121        self.imRunning = 0
122        time.sleep(1)
123        print "\n.\n..\n..."
124        time.sleep(1)
125        print "....\n.....\n......"       
126        time.sleep(1)
127        if self.myFlowInput:
128            self.myFlowInput.socket_close()
129        self.join(timeout)
130       
131    def __init__(self, address, port):
132        self.imRunning = 1
133        self.currentflow = None
134        threading.Thread.__init__(self)
135        self.myFlowInput = FlowInput(address, port)
136
137    def run(self):
138        global freeze, record
139        while self.imRunning:
140            if self.myFlowInput:
141                tmp = self.myFlowInput.get_flow()
142                if (tmp[0]!=None):
143                    self.currentflow = Flow(tmp)
144                    if (freeze==0) & self.currentflow.enable():
145                        self.currentflow.print_flow2()
146                    if (record==1) & self.currentflow.enable():
147                        self.currentflow.write_flow2()
148##                else:
149##                    self.myFlowInput = None
150   
151class Flow:
152    def __init__(self, data):
153        self.flow = [ data[0], data[1] ]
154
155# flow selection
156    def enable(self):
157        global firstParseValue, checkUpValues, tpl_def, fromRouter
158        res = 1
159        resS = 1
160        resD = 1
161        for i in range (0, len(tpl_def[self.flow[0]])):
162            f = tpl_def[self.flow[0]][i][0]
163            # or f==15 or f==18 or f==47
164            if ( f==8 ) and ( checkUpValues[f]==1 ):
165                resS = resS & ( ((struct.unpack('>L',(socket.inet_aton(self.flow[1][i])))[0] & mask[1-1]) == firstParseValue[f]) )
166            elif ( f==12 ) and ( checkUpValues[f]==1 ):
167                resD = resD & ( ((struct.unpack('>L',(socket.inet_aton(self.flow[1][i])))[0] & mask[1-1]) == firstParseValue[f]) )
168            elif ( i==27 or i==28 ):
169                pass
170            elif ( (f==1) and (checkUpValues[f]==1) ):
171                res = res & ( (self.flow[1][i] <= ((firstParseValue[f])+((firstParseValue[f])*5/100))) and ((self.flow[1][i] >= ((firstParseValue[f])-((firstParseValue[f])*5/100)))) )
172            elif (checkUpValues[f]==1):
173                res = res & (self.flow[1][i] == firstParseValue[f])
174        if ( checkUpValues[69]==1 ):
175            res = res & ( (fromRouter == firstParseValue[69]) )
176        res = res & (resS or resD)
177        return res
178
179# flow print
180    def print_flow2(self):
181        global printValue, tpl_def, flowCpt, fieldsName, oldTpl, os_type, fromRouter
182        myliste = []
183        myTpl = []
184        strFlow = ""
185        strField = ""
186        underscore_line = ""
187        flowCpt+=1
188##        if (flowCpt%20 == 0 or oldTpl != self.flow[0]):
189        if (flowCpt%100 == 0):
190            flowCpt = 0
191            for i in range (0, len(tpl_def[self.flow[0]])):
192                f = tpl_def[self.flow[0]][i][0]
193                if printValue[f]:
194                    if ( f==27 or f==28 or f==62 or f==63 ):
195                        strField += str(fieldsName[f])
196                        l = len(str(fieldsName[f]))
197                        if ((40-l)%8 == 0):
198                            tabNb = int((40-l)/8)
199                        else:
200                            tabNb = int((40-l)/8) + 1
201                        for j in range (0, tabNb):
202                            strField += "\t"
203                        for k in range (0, 40):
204                            underscore_line += "-"
205                    elif ( f==8 or f==15 or f==12 or f==18 or f==47 ):
206                        strField += str(fieldsName[f])
207                        l = len(str(fieldsName[f]))
208                        if ((16-l)%8 == 0):
209                            tabNb = int((16-l)/8)
210                        else:
211                            tabNb = int((16-l)/8) + 1
212                        for j in range (0, tabNb):
213                            strField += "\t"
214                        for k in range (0, 16):
215                            underscore_line += "-"
216                    else:
217                        strField += str(fieldsName[f])
218                        strField += "\t"
219                        for k in range (0, 8):
220                            underscore_line += "-"
221            if (oldTpl != self.flow[0]):
222                print " "
223            if (os_type == 0):
224                esc = '\x1b['
225                sep = ';'
226                end = 'm'
227                if (printValue[69]):
228                    rt = str(fieldsName[69])
229                    toprint = esc+"37"+sep+"44"+end+strField+rt+esc+"0"+end
230                else:
231                    toprint = esc+"37"+sep+"44"+end+strField+esc+"0"+end
232                print toprint
233            else:
234                if (printValue[69]):
235                    strField += str(fieldsName[69])
236                print strField
237                print underscore_line
238        for i in range (0, len(tpl_def[self.flow[0]])):
239            f = tpl_def[self.flow[0]][i][0]
240            if printValue[f]:
241                if ( f==27 or f==28 or f==62 or f==63 ):
242                    strFlow += str(self.flow[1][i])
243                    l = len(str(self.flow[1][i]))
244                    if ((40-l)%8 == 0):
245                        tabNb = int((40-l)/8)
246                    else:
247                        tabNb = int((40-l)/8) + 1
248                    for j in range (0, tabNb):
249                        strFlow += "\t"
250                elif ( f==8 or f==12 or f==15 or f==18 or f==47 ):
251                    strFlow += str(self.flow[1][i])
252                    l = len(str(self.flow[1][i]))
253                    if ((16-l)%8 == 0):
254                        tabNb = int((16-l)/8)
255                    else:
256                        tabNb = int((16-l)/8) + 1
257                    for j in range (0, tabNb):
258                        strFlow += "\t"
259                elif (f==21):
260                    myliste += [str(self.flow[1][i]-self.flow[1][i+1])]
261                    strFlow += str(self.flow[1][i]-self.flow[1][i+1])
262                    strFlow += "\t"
263                elif (f==22):
264                    pass
265                else:
266                    myliste += [str(self.flow[1][i])]
267                    strFlow += str(self.flow[1][i])
268                    for k in range (len(str(self.flow[1][i])), 7):
269                        strFlow += " "
270                    strFlow += "\t"
271        if (printValue[69]):
272            strFlow += fromRouter
273        print strFlow
274        oldTpl = self.flow[0]
275
276# flow record
277    def write_flow2(self):
278        global printValue, record_file, tpl_def
279        myliste = []
280        for i in range (0, len(tpl_def[self.flow[0]])):
281            f = tpl_def[self.flow[0]][i][0]
282            if printValue[f]:
283                if (f==21):
284                    myliste += [str(self.flow[1][i]-self.flow[1][i+1])]
285                elif (f==22):
286                    pass
287                else:
288                    myliste += [str(self.flow[1][i])]
289        theflow = string.join(myliste, "\t")+"\t"+fromRouter+"\n"
290        record_file.write(theflow)
291       
292class FlowInput:
293    def __init__(self, h, p):
294        self.HOST = h
295        self.PORT = p
296        if (IPversion == 4):
297            self.socketnumber = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
298        elif (IPversion == 6):
299            self.socketnumber = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
300        else:
301            print "IP protocol ", IPversion ," not supported"
302            exit(0)
303        self.socketnumber.bind((self.HOST, self.PORT))
304   
305    def get_flow(self):
306        global collectorRule, tpl_def, os_type, fromRouter
307        if (self.socketnumber!=None):
308            data = self.socketnumber.recvfrom(1024)
309            flow = data[0]
310            code = struct.unpack('<H', flow[0:2])
311            if (code[0] == 1): ## a def packet
312                routerSrc = struct.unpack('<L', flow[2:6])
313                sourceId = struct.unpack('<L', flow[6:10])
314                tplId = struct.unpack('<H', flow[10:12])
315                mykeylst = []
316                mykeylst += [str(routerSrc[0])]
317                mykeylst += [str(sourceId[0])]
318                mykeylst += [str(tplId[0])]
319                mykeystr = string.join(mykeylst,"");
320                fields = []
321                fieldNb = struct.unpack('<H', flow[12:14])
322                for i in range(0, fieldNb[0]):
323                    fd = struct.unpack('<H',flow[14+(i*4):16+(i*4)])
324                    tp = struct.unpack('<H',flow[14+(2+i*4):16+(2+i*4)])
325                    fields.insert(i,(fd[0],tp[0]))
326                tpl_def[mykeystr] = fields
327                return ( None, None)
328            if (code[0]==11): ## a data packet
329                routerSrc = struct.unpack('<L', flow[4:8])
330                tmp =  struct.unpack('<L', flow[4:8])
331                fromRouter = socket.inet_ntoa(struct.pack('>L', tmp[0]))
332                sourceId = struct.unpack('<L', flow[8:12])
333                tplId = struct.unpack('<H', flow[12:14])
334                mykeylst = []
335                mykeylst += [str(routerSrc[0])]
336                mykeylst += [str(sourceId[0])]
337                mykeylst += [str(tplId[0])]
338                mykeystr = string.join(mykeylst,"")
339                if (tpl_def.has_key(mykeystr)== True):
340                    field_list = []
341                    index = 0
342                    for i in range (0, len(tpl_def[mykeystr])):
343                        if (tpl_def[mykeystr][i][1]==1):
344                            value = struct.unpack('<B',flow[14+index:15+index])
345                            field_list.insert(i,value[0])
346                        if (tpl_def[mykeystr][i][1]==2):
347                            value = struct.unpack('>H',flow[14+index:16+index])
348                            field_list.insert(i,value[0])
349                        if (tpl_def[mykeystr][i][1]==3):
350                            value = struct.unpack('<BBB',flow[14+index:17+index])
351                            valueTmp = struct.pack('<BBBB',value[2],value[1],value[0],0)
352                            valueFinal = struct.unpack('<L', valueTmp)
353                            valueFinal2 = (valueFinal[0])>>4
354                            field_list.insert(i,valueFinal2)
355                        if (tpl_def[mykeystr][i][1]==4):
356                            if (tpl_def[mykeystr][i][0]==8 or tpl_def[mykeystr][i][0]==12 or tpl_def[mykeystr][i][0]==15 or tpl_def[mykeystr][i][0]==18 or tpl_def[mykeystr][i][0]==47):
357                                value = socket.inet_ntoa(flow[14+index:18+index])
358                                field_list.insert(i,value)
359                            else:
360                                value = struct.unpack('<L', flow[14+index:18+index])
361                                value = struct.unpack('>L', flow[14+index:18+index])
362                                field_list.insert(i,value[0])
363                        if (tpl_def[mykeystr][i][1]==16):
364                            if (os_type==1):
365                                field_list.insert(i,nt_inet_ntop(flow[14+index:30+index]))
366                            else:
367                                tmp = socket.inet_ntop(socket.AF_INET6,flow[14+index:30+index])
368                                field_list.insert(i,tmp)
369                        index += tpl_def[mykeystr][i][1]
370                    return mykeystr, field_list
371##                else:
372##                  print "I'm waiting the tpl def for the key", mykeystr
373##                return (routerSrc[0], field_list)
374            return ( None, None)
375        return ( None, None)
376
377    def socket_close(self):
378        if self.socketnumber:
379           try :
380               self.socketnumber.shutdown(2)
381               self.socketnumber = None
382           except socket.error:
383              pass
384
385class FileSel:
386    def file_ok_sel(self, w):
387        global record, record_file, record_file_name
388        record = 1
389        record_file_name = self.fileSel.get_filename()
390        record_file = file(record_file_name, 'w')
391        print "%s" % self.fileSel.get_filename()
392        self.fileSel.destroy()
393
394    def destroy(self, widget):
395        self.fileSel.destroy()
396
397    def __init__(self):
398        self.fileSel = gtk.FileSelection("File Selection")
399        self.fileSel.connect("destroy", self.destroy)
400        self.fileSel.ok_button.connect("clicked", self.file_ok_sel)
401        self.fileSel.cancel_button.connect("clicked",
402                                           lambda w: self.fileSel.destroy())
403        self.fileSel.set_filename("flow_record.txt")
404        self.fileSel.show()
405
406def print_hello(widget, event):
407    print "Hello, World!"
408
409def nt_inet_ntop(packed_ip):
410    cpt = 0
411    double = 0
412    string_ip = ""
413    tmp = binascii.hexlify(packed_ip[0:2])
414    if ( int(tmp,16)!=0 ):
415        string_ip += tmp
416        tmp = binascii.hexlify(packed_ip[2:4])
417        if ( int(tmp,16)==0 ):
418            cpt+=1
419            double = 1
420            if (cpt==1):
421                string_ip += ":"
422        else:
423            cpt=0
424            string_ip += ":"+tmp
425        tmp = binascii.hexlify(packed_ip[4:6])
426        if ( int(tmp,16)==0 ):
427            cpt+=1
428            double = 1
429            if (cpt==1):
430                string_ip += ":"
431        else:
432            cpt=0
433            string_ip += ":"+tmp
434        tmp = binascii.hexlify(packed_ip[6:8])
435        if ( int(tmp,16)==0 ):
436            if (double==1 and cpt==0):
437                string_ip += ":0"
438            else:
439                cpt+=1
440                double = 1
441                if (cpt==1):
442                    string_ip += ":"
443        else:
444            cpt=0
445            string_ip += ":"+tmp
446        tmp = binascii.hexlify(packed_ip[8:10])
447        if ( int(tmp,16)==0 ):
448            if (double==1 and cpt==0):
449                string_ip += ":0"
450            else:
451                cpt+=1
452                double = 1
453                if (cpt==1):
454                    string_ip += ":"
455        else:
456            cpt=0
457            string_ip += ":"+tmp
458        tmp = binascii.hexlify(packed_ip[10:12])
459        if ( int(tmp,16)==0 ):
460            if (double==1 and cpt==0):
461                string_ip += ":0"
462            else:
463                cpt+=1
464                double = 1
465                if (cpt==1):
466                    string_ip += ":"
467        else:
468            cpt=0
469            string_ip += ":"+tmp
470        tmp = binascii.hexlify(packed_ip[12:14])
471        if ( int(tmp,16)==0 ):
472            if (double==1 and cpt==0):
473                string_ip += ":0"
474            else:
475                cpt+=1
476                double = 1
477                if (cpt==1):
478                    string_ip += ":"
479        else:
480            cpt=0
481            string_ip += ":"+tmp
482        tmp = binascii.hexlify(packed_ip[14:16])
483        if ( int(tmp,16) != 0 ):
484            string_ip += ":"+tmp
485        else:
486            string_ip += ":"
487    else:
488        string_ip = "::"
489    return string_ip
490
491def get_main_menu(self, window):
492    accel_group = gtk.AccelGroup()
493    item_factory = gtk.ItemFactory(gtk.MenuBar, "<main>", accel_group)
494    item_factory.create_items(menu_items)
495    window.add_accel_group(accel_group)
496    item_factory = item_factory
497    return item_factory.get_widget("<main>")
498
499def reception(widget, event):
500    global myInputControlThread
501    global localAddr, localPort
502    myInputControlThread = InputControl(localAddr, localPort)
503    myInputControlThread.start()
504
505def close_recept(widget, event):
506    global myInputControlThread
507    if myInputControlThread != None:
508        myInputControlThread.kill(1)
509        myInputControlThread = None
510        print "\n\n\n\n\n Input Stream closed. \n\n\n\n\n"
511
512def about_dialog(widget, event):
513    dialog = gtk.MessageDialog(
514        parent         = None,
515        flags          = gtk.DIALOG_MODAL,
516        type           = gtk.MESSAGE_INFO,
517        buttons        = gtk.BUTTONS_OK,
518        message_format = "Author : FX Andreu\nemail andreu@renater.fr\nCopyright (C) 2005-2008 GIP RENATER\n\nThis file is part of renetcol.\n\nrenetcol 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.\n\nrenetcol 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.\n\nYou should have received a copy of the GNU General Public License along with renetcol; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA ")
519    dialog.set_title('About')
520    dialog.connect('response', lambda dialog, response: dialog.destroy())
521    dialog.show()
522
523def check_dialog(widget, event, text):
524    dialog = gtk.MessageDialog(
525        parent         = None,
526        flags          = gtk.DIALOG_MODAL,
527        type           = gtk.MESSAGE_INFO,
528        buttons        = gtk.BUTTONS_OK,
529        message_format = text)
530    dialog.set_title('Value check ')
531    dialog.connect('response', lambda dialog, response: dialog.destroy())
532    dialog.show()
533
534def info_dialog(widget, event, text):
535    dialog = gtk.MessageDialog(
536        parent         = None,
537        flags          = gtk.DIALOG_MODAL,
538        type           = gtk.MESSAGE_INFO,
539        buttons        = gtk.BUTTONS_OK,
540        message_format = text)
541    dialog.set_title('Information ')
542    dialog.connect('response', lambda dialog, response: dialog.destroy())
543    dialog.show()
544
545def callback_freeze(widget, data=None):
546    global freeze
547    if widget.get_active() == 1:
548        freeze = 1
549        print "FREEZE ACTIF"
550    if widget.get_active() == 0:
551        freeze = 0
552        print "FREEZE NOT ACTIF"
553
554def wind_destroy(widget, data=None):
555    widget.destroy()
556   
557def callback_record(widget, data=None):
558    global record, record_file, record_file_name
559    if widget.get_active() == 1:
560        FileSel()
561    if widget.get_active() == 0:
562        record = 0
563        time.sleep(2)
564        record_file.close()
565
566def strsend(target, message):
567   global collectorAddr, collectorPort
568   s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
569   s.connect((collectorAddr, collectorPort))
570   s.send(message)
571   s.close()
572
573def callback_refresh(widget, parent):
574    global collectorAddr
575    strsend(collectorAddr, 'REFRESH')
576    parent.destroy()
577   
578def callback_delete_rule(widget, parent):
579    global collectorAddr, collectorPort
580    if widget.get_active() == 1:
581        sent_rule(widget, "DELETE")
582        widget.set_active(0)
583        parent.destroy()
584
585def callback_check_rule(widget, data=None):
586    global router
587    if widget.get_active()==1:
588        router=1
589
590def timer_action():
591    global record_file, record_file_name, myTimer, myCPT
592    myCPT+=1
593    myTimer.cancel()
594    my_new_file_name = "%s_%s_%d" % (record_file_name,time.strftime("%Y%m%d", time.gmtime()),myCPT)
595    ##my_new_file_name = "%s_%d" % (record_file_name,myCPT)
596    print my_new_file_name
597    new_record_file = file(my_new_file_name, 'w')
598    old_record_file = record_file
599    record_file = new_record_file
600    old_record_file.close()
601    now2 = time.time()
602    reste = 360-(operator.mod(now2,360))
603    myTimer = threading.Timer(360.0,timer_action)
604    myTimer.start()
605
606def callback_RotRec(widget, data=None):
607    global record, myTimer
608    if ((record == 0) and (widget.get_active() == 1)):
609        info_dialog(widget, None, "You must before activated the record ! ")
610        widget.set_active(0)
611    else:
612        if widget.get_active() == 1:
613            print "STARTING RECORD ROTATION"
614            now2 = time.time()
615            reste = 360-(operator.mod(now2,360))
616            myTimer = threading.Timer(360,timer_action)
617            myTimer.start()
618        if widget.get_active() == 0:
619            myTimer.cancel()
620            print "STOPPING RECORD ROTATION"
621
622def callback_collector(widget, controlWindow):
623    global is_already_see, collectorRule, myInputControlThread, coll_window, collectorAddr
624    if ((myInputControlThread == None) and (widget.get_active() == 1)):
625        info_dialog(widget, None, "You must before activated the stream reception ! (File menu)")
626        widget.set_active(0)
627    else:
628        if widget.get_active() == 1:
629            widget.set_active(0)
630            coll_window.connect("destroy", wind_destroy)
631            coll_window.set_title("Collector control ")
632            coll_window.set_size_request(500, 250)
633            coll_vbox = gtk.VBox(False, 1)
634            coll_vbox.set_border_width(1)
635            coll_window.add(coll_vbox)
636            coll_frame = gtk.Frame("Enter your filter (format described in tip), validate by enter")
637            coll_vbox.pack_start(coll_frame, False, False, 5)
638            coll_hbox = gtk.VBox(False, 0)
639            coll_hbox.set_border_width(5)
640            coll_frame.add(coll_hbox)
641##            button = gtk.CheckButton(" router ")
642##            button.connect("toggled", callback_check_rule, None)
643##            coll_hbox.pack_start(button, False, False, 0)
644##            mainTT.set_tip(button, "Check it to capture all flows from one router and enter the IPv4 address of this router. IN TEST")
645##            button.show()
646            coll_pbbox = gtk.HButtonBox()
647            coll_hbox.pack_start(coll_pbbox, False, True, 5)
648            prefix_entry(249, "Required Format : \n<field> = <value>[ & <field> = <value>]\
649            \nlike \
650            \n8 = 10.0.0.4 \
651            \n\t(all flows from IP Source 10.0.0.4)\
652            \nor 8 = 10.0.1.0/24 \
653            \n\t(all flows with IP Source in subnet 10.0.1.0/24)\
654            \nor 27 = 2001::1 (IPv6 address only on Linux system)\
655            \n\t(all flows from IP Source 2001::1)\
656            \nor 27 = 2001::/64 \
657            \n\t(all flows with IP Source in subnet 2001::/64)\
658            \nor 0 = 10.0.0.1 & 4 = 1\
659            \n\t(all ICMP flows from router 10.0.0.1)\
660            \nonly equal operator in this release\
661            \nmaximum 4 logical '&' for one filter (limit 249 chars)\
662            \n----------------------------------\
663            \n---- NetFlow Fields list ------\
664            \nROUTER_SRC_ADDR:\t 0\
665            \nIN_BYTES:\t\t\t 1\
666            \nL4_PROT:\t\t\t 4\
667            \nL4_SRC_PORT:\t\t 7\
668            \nIPV4_SRC_ADDR:\t\t 8\
669            \nINPUT_SNMP:\t\t\t10\
670            \nL4_DST_PORT:\t\t11\
671            \nIPV4_DST_ADDR:\t\t12\
672            \nOUTPUT_SNMP:\t\t14\
673            \nIPV4_NEXT_HOP:\t\t15\
674            \nSRC_AS:\t\t\t\t16\
675            \nDST_AS:\t\t\t\t17\
676            \nBGP_IPV4_NEXT_HOP:\t18\
677            \nIPV6_SRC_ADDR:\t\t27\
678            \nIPV6_DST_ADDR:\t\t28\
679            \nIPV6_NEXT_HOP:\t\t62\
680            \nBPG_IPV6_NEXT_HOP:\t63\
681            \nIP_PROT_VERSION:\t60\
682            \n---------------------------", coll_pbbox, "", 0)
683            coll_frame2 = gtk.Frame("Disable rules")
684            coll_vbox.pack_start(coll_frame2, False, False, 5)
685            coll_hbox2 = gtk.VBox(False, 0)
686            coll_hbox2.set_border_width(5)
687            coll_frame2.add(coll_hbox2)
688            coll_pbbox2 = gtk.HButtonBox()
689            coll_hbox2.pack_start(coll_pbbox2, False, True, 5)
690            buttondelete = gtk.ToggleButton("Delete")
691            buttondelete.connect("toggled", callback_delete_rule, coll_window)
692            mainTT.set_tip(buttondelete, "Delete all your rules of the collector configuration.")
693            coll_hbox2.pack_start(buttondelete, False, False, 2)
694            buttondelete.show()
695            coll_vbox.show()
696            coll_window.show_all()
697            if (is_already_see==0):
698                info_dialog(widget, None, "You should register only one rule for each GUI parser ! Think of using the DELETE button !")
699                is_already_see=1
700
701def callback_fields_printed( widget, data=None):
702    global printValue
703    printValue[data] = widget.get_active()
704
705def callback_check_ip( widget, data=None):
706    global src_Or_Dst_IP
707    if widget.get_active()==1:
708        if checkUpValues[1]:
709            src_Or_Dst_IP = 1
710        else:
711            widget.set_active(0)
712            check_dialog(widget, None, "First, enter a source address.")
713    else:
714            src_Or_Dst_IP = 0
715
716def callback_comboR(widget, data=None):
717    global comboRouter, routerHash
718    nop = 0
719    print struct.unpack('>L',socket.inet_aton(routerHash[comboRouter.entry.get_text()]))
720   
721def callback_src_mask(widget, data=None):
722    nop = 0
723
724def callback_dst_mask(widget, data=None):
725    nop = 0
726
727def callback_tos(widget, data=None):
728    nop = 0
729
730def callback_prot(widget, data=None):
731    nop = 0
732
733def create_button(title, state, callback_function, ptr_var, parent, tooltip_Text):
734    global mainTT
735    button = gtk.ToggleButton(title)
736    if state==1:
737        button.set_active(True)
738    else:
739        button.set_active(False)
740    button.connect("toggled", callback_function, ptr_var)
741    if tooltip_Text!=None:
742        mainTT.set_tip(button, tooltip_Text)
743    parent.pack_start(button, False, True, 2)
744    button.show()
745
746def create_entry(maxLen, tooltip_Text, parent, lab, id):
747    global mainTT
748    vbox = gtk.VBox(False, 0)
749    parent.pack_start(vbox, False, True, 0)
750    label = gtk.Label(lab)
751    label.set_alignment(0, 0.5)
752    vbox.pack_start(label, False, True, 0)
753    entry = gtk.Entry(max=maxLen)
754    entry.set_max_length(maxLen)
755    entry.connect("activate", enter_callback, entry, id)
756    entry.set_text("")
757    entry.select_region(0, len(entry.get_text()))
758    if tooltip_Text!=None:
759        mainTT.set_tip(entry, tooltip_Text)
760    vbox.pack_start(entry, False, True, 0)
761    entry.show()
762
763def sent_rule(widget, msg):
764    global collectorAddr, collectorPort, collectorAddr6, IPversion
765    s = None
766    if (IPversion==4):
767        tmpaf =  socket.AF_INET
768        addr = collectorAddr
769        port = collectorPort
770    elif (IPversion == 6):
771        tmpaf =  socket.AF_INET6
772        addr = collectorAddr6
773        port = collectorPort
774    else:
775        print "Wrong IP version : ", IPversion
776        exit(0)
777    for res in socket.getaddrinfo(addr, port, tmpaf, socket.SOCK_STREAM):
778        af, socktype, proto, canonname, sa = res
779        try:
780            s = socket.socket(af, socktype, proto)
781        except socket.error, msg:
782            s = None
783            continue
784        try:
785            s.connect(sa)
786        except socket.error, msg:
787            s.close()
788            s = None
789            continue
790        break
791    if s is None:
792        check_dialog( widget, None, "could not open socket")
793    else:
794        s.send(msg)
795        check_dialog( widget, None, "Action was sent")
796        s.close()
797
798def sent_rule_from_cli(msg):
799    global collectorAddr, collectorPort, collectorAddr6, IPversion
800    s = None
801    if (IPversion==4):
802        tmpaf =  socket.AF_INET
803        addr = collectorAddr
804        port = collectorPort
805    elif (IPversion == 6):
806        tmpaf =  socket.AF_INET6
807        addr = collectorAddr6
808        port = collectorPort
809    else:
810        print "Wrong IP version : ", IPversion
811        exit(0)
812    for res in socket.getaddrinfo(addr, port, tmpaf, socket.SOCK_STREAM):
813        af, socktype, proto, canonname, sa = res
814        try:
815            s = socket.socket(af, socktype, proto)
816        except socket.error, msg:
817            s = None
818            continue
819        try:
820            s.connect(sa)
821        except socket.error, msg:
822            s.close()
823            s = None
824            continue
825        break
826    if s is None:
827        check_dialog( None, None, "could not open socket")
828    else:
829        s.send(msg)
830        check_dialog( None, None, "Action was sent")
831        s.close()
832
833# dialog box to collector control
834def prefix_callback( widget, entry, id):
835    global collPrefix, coll_window, router, localPort
836    entry_text = entry.get_text()
837    is_good = 0
838    mymsg = []
839    if (id == 0):
840        if ( entry_text==""):
841            collPrefix = 0
842        else:
843            ## here we parse the filter, possibility of many filter concatened with '&' operator
844            filters = entry_text.split('&')
845            if len(filters)>5:
846                check_dialog( widget, None, "No more 4 '&' !")
847                is_ok = 0
848            else:
849                is_ok = 1
850                for f in filters:
851                    rule = f.split(' ')
852                    if len(mymsg)==0:
853                        field = rule[0]
854                        operator = rule[1]
855                        value = rule[2]
856                        mymsg = "C" + "_" + field + "_" + operator + "_" + value
857                    else:
858                        field = rule[1]
859                        operator = rule[2]
860                        value = rule[3]                       
861                        mymsg += "_C" + "_" + field + "_" + operator + "_" + value
862                    print f
863                    print mymsg
864                    if (field=='0' or field=='8' or field=='12' or field=='15' or field=='18' or field=='47'):
865                        if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',value)):
866                            splitter = value.split('/')
867                            adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
868                            if len(splitter)>1:
869                                bits = int(splitter[1])
870                                if bits <= 32 and bits > 0:
871                                    mask[1] = 0xffffffffL << (32 - bits)
872                                    is_good = 1
873                                else:
874                                    check_dialog( widget, None, "Wrong value in mask!")
875                                    is_good = 0
876                            else:
877                                value = value+"/32"
878                                mask[1] = 0xffffffffL
879                                is_good = 1
880                        else:
881                            check_dialog( widget, None, "Wrong value !")
882                    if (field=='27' or field=='28' or field=='62'):
883                        ipv6ad_mask = value.split('/')
884                        if len(ipv6ad_mask)==1:
885                            try:
886                                socket.gethostbyaddr(value)
887                                is_good = 1
888                            except socket.gaierror:
889                                check_dialog( widget, None, "Wrong value !")
890                            except socket.herror: ## can't resolv
891                                check_dialog( widget, None, "I can't resolv !")
892                            except socket.error:
893                                check_dialog( widget, None, "Error in gethostbyaddr()!")
894                        else:
895                            is_good = 1
896                    ##here, check the prefix value?
897                    if (field=='60' or field=='46'):
898                        if (int(value) < 256):
899                            is_good = 1
900                        else:
901                            check_dialog( widget, None, "Wrong value, must be < 256 !")
902                            is_good = 0
903                    if (field=='1'):
904                        if (int(value) < 4294967295):
905                            is_good = 1
906                        else:
907                            check_dialog( widget, None, "Wrong value, must be < 4294967295 !")
908                            is_good = 0
909                    if (field=='7' or field=='11' or field=='4'):
910                        if (int(value) < 65536):
911                            is_good = 1
912                        else:
913                            check_dialog( widget, None, "Wrong value, must be < 65536 !")
914                            is_good = 0
915                    if (field=='10' or field=='14' or field=='16' or field=='17'):
916                        if (int(value) < 65536):
917                            is_good = 1
918                        else:
919                            check_dialog( widget, None, "Wrong value, must be < 65536 !")
920                            is_good = 0
921            if (is_good==1 and is_ok==1):
922                ##collPrefix = adip & mask[1]
923                ## Here tcp exchange between collector & client
924                ##msg = str(localPort) +" "+ field +" "+ operator+" "+ value
925                msg = str(localPort) + " " + mymsg
926                print msg
927                sent_rule(widget, msg)
928                widget.set_editable(False)
929                coll_window.destroy()
930    else:
931        check_dialog( widget, None, "Internal program error ;) !")
932
933# collector control button
934def prefix_entry(maxLen, tooltip_Text, parent, lab, id):
935    global mainTT
936    vbox = gtk.VBox(False, 0)
937    parent.pack_start(vbox, False, True, 0)
938    label = gtk.Label(lab)
939    label.set_alignment(0, 0.5)
940    vbox.pack_start(label, False, True, 0)
941    entry = gtk.Entry(max=maxLen)
942    entry.set_max_length(maxLen)
943    entry.connect("activate", prefix_callback, entry, id)
944    entry.set_text("")
945    entry.select_region(0, len(entry.get_text()))
946    if tooltip_Text!=None:
947        mainTT.set_tip(entry, tooltip_Text)
948    vbox.pack_start(entry, False, True, 0)
949    entry.show()
950
951def user_quit(widget, data=None):
952    global myInputControlThread, localPort, record_file, myTimer
953    if myInputControlThread != None:
954        myInputControlThread.kill(1)
955        myInputControlThread = None
956        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
957        s.connect(('localhost', localPort))
958        s.send("FIN")
959        s.close()
960        if (record_file!=None):
961            record_file.close()
962        sent_rule_from_cli("DELETE")
963        print "\n\n\n\n\n Input Stream closed. \n\n\n\n\n By :-) \n\n\n\n"
964    if (myTimer != None):
965        myTimer.cancel()
966    gtk.main_quit()
967
968# Flow Selection
969def enter_callback( widget, entry, id):
970    global firstParseValue
971    entry_text = entry.get_text()
972    if id == 0:
973        if (entry_text==""):
974            checkUpValues[0] = 0
975        else:
976            if (re.search('\D',entry_text)) or (int(entry_text) >= 99) or (int(entry_text) <= 0):
977                check_dialog( widget, None, "Wrong value !")
978            else:
979                firstParseValue[0] = int(entry_text)
980                checkUpValues[0] = 1
981    if id == 1:
982        if ( entry_text==""):
983            checkUpValues[8] = 0
984            checkUpValues[12] = 0
985        else:
986            if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',entry_text)):
987                splitter = entry_text.split('/')
988                adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
989                if len(splitter)>1:
990                    bits = int(splitter[1])
991                    if bits <= 32 and bits > 0:
992                        mask[0] = 0xffffffffL << (32 - bits)
993                    else:
994                        check_dialog( widget, None, "Wrong value in mask!")
995                else:
996                    mask[0] = 0xffffffffL
997                firstParseValue[8] = adip & mask[0]
998                checkUpValues[8] = 1
999                firstParseValue[12] = adip & mask[0]
1000                checkUpValues[12] = 1
1001            else:
1002                check_dialog( widget, None, "Wrong value !")
1003    if id == 2:
1004        if ( entry_text==""):
1005            checkUpValues[2] = 0
1006        else:
1007            check_dialog( widget, None, "NOT YET IMPLEMEMTED")
1008            ## pb with IPv6 and getaddrinfo() ??
1009##            splitter = entry_text.split('/')
1010##            try:
1011##                socket.gethostbyaddr(splitter[0])
1012##            except socket.gaierror:
1013##                check_dialog( widget, None, "Wrong value !")
1014##            except socket.herror: ## can't resolv
1015##                pass
1016##            except socket.error:
1017##                pass
1018    if id == 3:
1019        if ( entry_text==""):
1020            checkUpValues[15] = 0
1021        else:
1022            if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',entry_text)):
1023                splitter = entry_text.split('/')
1024                adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
1025                if len(splitter)>1:
1026                    bits = int(splitter[1])
1027                    if bits <= 32 and bits > 0:
1028                        mask[2] = 0xffffffffL << (32 - bits)
1029                    else:
1030                        check_dialog( widget, None, "Wrong value in mask!")
1031                else:
1032                    mask[2] = 0xffffffffL
1033                firstParseValue[15] = adip & mask[2]
1034                checkUpValues[15] = 1
1035            else:
1036                check_dialog( widget, None, "Wrong value !")
1037    if id == 4: ## In|Out
1038        if ( entry_text==""):
1039            checkUpValues[10] = 0
1040            checkUpValues[14] = 0
1041        else:
1042            if (re.search('\D',entry_text)) or (int(entry_text) > 65535) or (int(entry_text) < 0):
1043                check_dialog( widget, None, "Wrong value !")
1044            else:
1045                firstParseValue[10] = int(entry_text)
1046                checkUpValues[10] = 1
1047                firstParseValue[14] = int(entry_text)
1048                checkUpValues[14] = 1
1049    if id == 6: ## bytes
1050        if ( entry_text==""):
1051            checkUpValues[1] = 0
1052        else:
1053            if (re.search('\D',entry_text)) or (int(entry_text) > 999999999) or (int(entry_text) <= 0):
1054                check_dialog( widget, None, "Wrong value !")
1055            else:
1056                firstParseValue[1] = int(entry_text)
1057                if ( int(entry_text) == 0 ):
1058                    firstParseValue[1] = 1000000000
1059                else:
1060                    firstParseValue[1] = int(entry_text)
1061                checkUpValues[1] = 1
1062    if id == 7: ## pkts
1063        if ( entry_text==""):
1064            checkUpValues[2] = 0
1065        else:
1066            if (re.search('\D',entry_text)) or (int(entry_text) > 9999) or (int(entry_text) <= 0):
1067                check_dialog( widget, None, "Wrong value !")
1068            else:
1069                firstParseValue[2] = int(entry_text)
1070                checkUpValues[2] = 1
1071    if id == 8: ## time no concordance with nfv9 field number
1072        if ( entry_text==""):
1073            checkUpValues[0] = 0
1074        else:
1075            if (re.search('\D',entry_text)) or (int(entry_text) > 99) or (int(entry_text) < 0):
1076                check_dialog( widget, None, "Wrong value !")
1077            else:
1078                firstParseValue[0] = int(entry_text)
1079                checkUpValues[0] = 1
1080    if id == 9: ## port range
1081        if ( entry_text==""):
1082            checkUpValues[7] = 0
1083        else:
1084            port_list = string.split(entry_text)
1085            if (len(port_list)!=2)or((re.search('\D',port_list[0])) or (int(port_list[0]) > 65535) or (int(port_list[0]) <= 0) or (re.search('\D',port_list[1])) or (int(port_list[1]) > 65535) or (int(port_list[1]) <= 0)):
1086                check_dialog( widget, None, "Wrong value !")
1087            else:
1088                firstParseValue[7] = int(port_list[0])
1089                firstParseValue[11] = int(port_list[1])
1090                checkUpValues[7] = 1
1091    if id == 11: ## tcp flags
1092        if ( entry_text==""):
1093            checkUpValues[6] = 0
1094        else:
1095            if (re.search('\D',entry_text)) or (int(entry_text) > 255) or (int(entry_text) <= 0):
1096                check_dialog( widget, None, "Wrong value !")
1097            else:
1098                firstParseValue[6] = int(entry_text)
1099                checkUpValues[6] = 1
1100    if id == 12: ## prot
1101        if ( entry_text==""):
1102            checkUpValues[4] = 0
1103        else:
1104            if (re.search('\D',entry_text)) or (int(entry_text) > 255) or (int(entry_text) <= 0):
1105                check_dialog( widget, None, "Wrong value !")
1106            else:
1107                firstParseValue[4] = int(entry_text)
1108                checkUpValues[4] = 1
1109    if id == 13: ## tos
1110        if ( entry_text==""):
1111            checkUpValues[5] = 0
1112        else:
1113            if (re.search('\D',entry_text)) or (int(entry_text) > 255) or (int(entry_text) < 0):
1114                check_dialog( widget, None, "Wrong value !")
1115            else:
1116                firstParseValue[5] = int(entry_text)
1117                checkUpValues[5] = 1
1118    if id == 14: ## src AS
1119        if ( entry_text==""):
1120            checkUpValues[16] = 0
1121        else:
1122            if (re.search('\D',entry_text)) or (int(entry_text) > 65535) or (int(entry_text) < 0):
1123                check_dialog( widget, None, "Wrong value !")
1124            else:
1125                firstParseValue[16] = int(entry_text)
1126                checkUpValues[16] = 1
1127    if id == 15: ## dst AS
1128        if ( entry_text==""):
1129            checkUpValues[17] = 0
1130        else:
1131            if (re.search('\D',entry_text)) or (int(entry_text) > 65535) or (int(entry_text) < 0):
1132                check_dialog( widget, None, "Wrong value !")
1133            else:
1134                firstParseValue[17] = int(entry_text)
1135                checkUpValues[17] = 1
1136    if id == 18: ## from router
1137        if ( entry_text==""):
1138            checkUpValues[69] = 0
1139        else:
1140            if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',entry_text)):
1141                splitter = entry_text.split('/')
1142                adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
1143                if len(splitter)>1:
1144                    bits = int(splitter[1])
1145                    if bits <= 32 and bits > 0:
1146                        mask[0] = 0xffffffffL << (32 - bits)
1147                    else:
1148                        check_dialog( widget, None, "Wrong value in mask!")
1149                else:
1150                    mask[0] = 0xffffffffL
1151                firstParseValue[69] = splitter[0]
1152                checkUpValues[69] = 1
1153            else:
1154                check_dialog( widget, None, "Wrong value !")
1155   
1156if __name__ == "__main__":
1157    global window, mainTT, comboRouter, os_type, printShit
1158    global localAddr, localPort
1159   
1160    gtk.gdk.threads_init()
1161   
1162    if (os.name =="nt"):
1163        os_type = 1
1164    elif (os.name =="posix"):
1165        os_type = 0
1166    else:
1167        os_type = 3
1168
1169    parser = OptionParser()
1170    parser.add_option("-r", "--router", dest="rtr", help ="router address used for NetFlow data export")
1171    parser.add_option("-i", "--index", dest="ind", help ="Interface index get with snmpwalk")
1172    (options, args) = parser.parse_args()
1173    rtr = options.rtr
1174    ind = options.ind
1175
1176    if len(sys.argv)==5:
1177        myInputControlThread = InputControl(localAddr, localPort)
1178        myInputControlThread.start()
1179        msg = str(localPort) + " C_0_=_" + rtr + "_C_10_=_" + ind
1180        print msg
1181        sent_rule_from_cli(msg)
1182       
1183    print "---------------------------------------------------------------"
1184    print "In this version, you can only apply rules on the collector based on the following fields:"
1185    print "IN_BYTES: 1,"
1186    print "L4_PROT: 4,"
1187    print "L4_SRC_PORT: 7,"
1188    print "IPV4_SRC_ADDR: 8,"
1189    print "INPUT_SNMP: 10,"
1190    print "L4_DST_PORT: 11,"
1191    print "IPV4_DST_ADDR: 12,"
1192    print "OUTPUT_SNMP: 14,"
1193    print "IPV4_NEXT_HOP: 15,"
1194    print "SRC_AS: 16,"
1195    print "DST_AS: 17,"
1196    print "BGP_IPV4_NEXT_HOP: 18,"
1197    print "IPV6_SRC_ADDR: 27,"
1198    print "IPV6_DST_ADDR: 28,"
1199    print "MPLS_TOP_LABEL_TYPE: 46,"
1200    print "IPV6_NEXT_HOP: 62,"
1201    print "BPG_IPV6_NEXT_HOP: 63,"
1202    print "IP_PROTOCOL_VERSION: 60, please note that the IPv4 templates don't have this field"
1203    print "ROUTER_SRC_ADDR: 0, !!! it's not a real number for a field, but it's a great function"
1204    print "----------------------------------------------------------------"
1205   
1206    mainTT = gtk.Tooltips()
1207    window = gtk.Window(gtk.WINDOW_TOPLEVEL)   
1208    window.connect("destroy", gtk.main_quit, "WM destroy")
1209    window.set_title("RenetcolGUI")
1210    window.set_size_request(850, 550)
1211   
1212    main_vbox = gtk.VBox(False, 1)
1213    main_vbox.set_border_width(1)
1214    window.add(main_vbox)
1215
1216##  menu
1217    file_menu = gtk.Menu()
1218    receive_item = gtk.MenuItem("Receive Stream")
1219    stop_item = gtk.MenuItem("Stop Stream")
1220    quit_item  = gtk.MenuItem("Quit")
1221    file_menu.append(receive_item)
1222    file_menu.append(stop_item)
1223    file_menu.append(quit_item)
1224    receive_item.connect("activate", reception, None)
1225    stop_item.connect("activate", close_recept, None)
1226    quit_item.connect("activate", user_quit, None)
1227    receive_item.show()
1228    stop_item.show()
1229    quit_item.show()
1230
1231    help_menu = gtk.Menu()
1232    about_item = gtk.MenuItem("About")
1233    help_menu.append(about_item)
1234    about_item.connect("activate", about_dialog, None)
1235    about_item.show()
1236
1237    menu_bar = gtk.MenuBar()
1238    main_vbox.pack_start(menu_bar, False, False, 0)
1239    menu_bar.show()
1240    file_item = gtk.MenuItem("File")
1241    file_item.show()
1242    help_item = gtk.MenuItem("Help")
1243    help_item.show()
1244
1245    file_item.set_submenu(file_menu)
1246    menu_bar.append(file_item)
1247    menu_bar.append(file_menu)
1248    file_item.set_right_justified(0)
1249
1250    help_item.set_submenu(help_menu)
1251    menu_bar.append(help_item)
1252    menu_bar.append(help_menu)
1253    help_item.set_right_justified(1)
1254
1255##  first frame
1256    frame = gtk.Frame("Input Stream Control")
1257    main_vbox.pack_start(frame, False, True, 0)
1258    hbox = gtk.HBox(False, 0)
1259    hbox.set_border_width(5)
1260    frame.add(hbox)
1261
1262    ## freeze button
1263    buttonfreeze = gtk.ToggleButton("Freeze")
1264    buttonfreeze.connect("toggled", callback_freeze, None)
1265    mainTT.set_tip(buttonfreeze, "Stop/Start the output in the window.")
1266    hbox.pack_start(buttonfreeze, False, False, 2)
1267    buttonfreeze.show()
1268    ## record button
1269    buttonrecord = gtk.ToggleButton("Record")
1270    buttonrecord.connect("toggled", callback_record, None)
1271    mainTT.set_tip(buttonrecord, "Stop/Start the record in a text file.")
1272    hbox.pack_start(buttonrecord, False, False, 2)
1273    buttonrecord.show()
1274    ## incremental record
1275    buttonRotRec = gtk.ToggleButton("Rot. Record")
1276    buttonRotRec.connect("toggled", callback_RotRec, None)
1277    mainTT.set_tip(buttonRotRec, "Stop/Start the record in a different file for each day.")
1278    hbox.pack_start(buttonRotRec, False, False, 2)
1279    buttonRotRec.show()
1280    ## control collector button
1281    buttoncollector = gtk.ToggleButton("Collector Control")
1282    buttoncollector.connect("toggled", callback_collector, None)
1283    mainTT.set_tip(buttoncollector, "Change the rule which is applied on the collector. You must have activated the input stream before.")
1284    hbox.pack_start(buttoncollector, False, False, 2)
1285    buttoncollector.show()
1286
1287    ipv4_vbox = gtk.VBox(False, 1)
1288    ipv4_vbox.set_border_width(1)
1289    main_vbox.add(ipv4_vbox)
1290##  second frame
1291    frame = gtk.Frame("Select printed fields")
1292    ipv4_vbox.pack_start(frame, False, False, 0)
1293   
1294    vbox = gtk.VBox(False, 0)
1295    vbox.set_border_width(5)
1296    frame.add(vbox)
1297    bbox = gtk.HButtonBox()
1298    vbox.pack_start(bbox, False, True, 5)
1299   
1300    create_button("Src \n IP", 1, callback_fields_printed, 8, bbox, "Source IP")
1301    create_button("Dst\n IP", 1, callback_fields_printed, 12, bbox, "Destination IP")
1302    create_button("Flw\n IP", 0, callback_fields_printed, 15, bbox, "Following IP")
1303    create_button("Index\n In", 0, callback_fields_printed, 10, bbox, "SNMP Index Input")
1304    create_button("Index\n Out", 0, callback_fields_printed, 14, bbox, "SNMP Index Output")
1305    create_button("Size (P)", 1, callback_fields_printed, 2, bbox, "Packets number")
1306    create_button("Size (B)", 1, callback_fields_printed, 1, bbox, "Size in Bytes")
1307    create_button("Time", 0, callback_fields_printed, 0, bbox, "Age of flow")
1308
1309    b2box = gtk.HButtonBox()
1310    vbox.pack_start(b2box, False, True, 5)
1311    create_button("Src\n Port", 1, callback_fields_printed, 7, b2box, "TCP/UDP source port")
1312    create_button("Dst\n Port", 1, callback_fields_printed, 11, b2box, "TCP/UDP destination port")
1313    create_button("TCP\n Flags", 0, callback_fields_printed, 6, b2box, "TCP Flags")
1314    create_button("Prot", 1, callback_fields_printed, 4, b2box, "Protocol")
1315    create_button("Tos", 0, callback_fields_printed, 5, b2box, "Type of service")
1316    create_button("Src\nAs", 0, callback_fields_printed, 16, b2box, "Source AS")
1317    create_button("Dst\nAs", 0, callback_fields_printed, 17, b2box, "Destination AS")
1318    create_button("Src\nMask", 0, callback_fields_printed, 9, b2box, "Source Mask")
1319    create_button("Dst\nMask", 0, callback_fields_printed, 13, b2box, "Destination Mask")
1320
1321    b3box = gtk.HButtonBox()
1322    vbox.pack_start(b3box, False, True, 5)
1323    create_button("Router", 0, callback_fields_printed, 69, b3box, "Router address")
1324
1325##  third frame
1326    frame = gtk.Frame("Parsing values")
1327    ipv4_vbox.pack_start(frame, False, False, 5)
1328    hbox = gtk.VBox(False, 0)
1329    hbox.set_border_width(5)
1330    frame.add(hbox)
1331    pbbox = gtk.HButtonBox()
1332    hbox.pack_start(pbbox, False, True, 5)
1333##  here entry button
1334    create_entry(18, "Required Format : \n an IPv4 address like x.x.x.x \n or a network address like x.x.x.x/x", pbbox, "IPv4 address :", 1)
1335    create_entry(39, "Required Format : \n an IPv6 address like x:x:x:x:x::x \n or a network address like x:x:x/x NOT YET SUPPORTED", pbbox, "(IPv6 address :)", 2)
1336    create_entry(18, "Required Format : \n an IP address like x.x.x.x \n or a network address like x.x.x.x/x", pbbox, "Flw IP ad. :", 3)
1337    dbbox = gtk.HButtonBox()
1338    hbox.pack_start(dbbox, False, True, 5)
1339    create_entry(5, "Required Format : a number less than 65535", dbbox, "SNMP Index In|Out :", 4)
1340    create_entry(4, "Required Format : a number less than 9999", dbbox, "Packet NB :", 7)
1341    create_entry(17, "Required Format : a number less than 999999999, each flow who the size equal this number +/- 5%", dbbox, "Bytes :", 6)
1342    tbbox = gtk.HButtonBox()
1343    hbox.pack_start(tbbox, False, True, 5)
1344    create_entry(2, "Required Format : a number less than 99", tbbox, "Time :", 8)
1345    create_entry(11, "Required Format : a range, each number less than 65535 and space as separator: \"6881 6889\"", tbbox, "Port :", 9)
1346    #create_entry(5, "Required Format : a number less than 65535", tbbox, "Dst port :", 10)
1347    create_entry(3, "Required Format : a number less than 255", tbbox, "TCP Flag :", 11)
1348    fbbox = gtk.HButtonBox()
1349    hbox.pack_start(fbbox, False, True, 5)
1350    create_entry(5, "Required Format : a number less than 65535", fbbox, "Protocol :", 12)
1351    create_entry(3, "Required Format : a number less than 255", fbbox, "ToS :", 13)
1352    create_entry(5, "Required Format : a number less than 65535", fbbox, "Src AS :", 14)
1353    create_entry(5, "Required Format : a number less than 65535", fbbox, "Dst AS :", 15)
1354    kbbox = gtk.HButtonBox()
1355    hbox.pack_start(kbbox, False, True, 5)
1356    create_entry(18, "Required Format : \n an IP address like x.x.x.x or x.x.x.x/x", kbbox, "The flows sending by this Router :", 18)
1357
1358##  Show
1359    vbox.show()
1360    main_vbox.show()
1361    window.show_all()
1362    mainTT.enable()
1363
1364##  gtk main loop
1365    gtk.gdk.threads_enter()
1366    gtk.main()
1367    gtk.gdk.threads_leave()
Note: See TracBrowser for help on using the browser.