root/trunk/tool/renetcolGUI.py @ 72

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

multi-filters and two parameters from CLI

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