root/trunk/tool/renetcolGUI.py @ 63

Revision 63, 49.5 KB (checked in by andreu, 15 years ago)

add AS selection and rotated record (on 24hours)

  • 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 operator
37import threading
38import string
39import re
40import socket
41import sys
42import gtk
43import traceback
44import pango
45import commands
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")+"\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("The prefix/IP address/router, 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(45, "Required Format : \n <field> <operation> <address>\nlike 8 = 10.0.0.1 \nor 8 = 10.0.1.0/24 \nor 27 = 2001::1 \nor 27 = 2001::/64 (IPv6 address only on Linux system)\nonly '=' operator for the moment\n------------------------------\nIn this version 0.0.7, you can compare the following fields:\nROUTER_SRC_ADDR: 0\nIN_BYTES: 1\nL4_SRC_PORT: 7\nIPV4_SRC_ADDR: 8\nINPUT_SNMP: 10\nL4_DST_PORT: 11\nIPV4_DST_ADDR: 12\nOUTPUT_SNMP: 14\nIPV4_NEXT_HOP: 15\nSRC_AS: 16\nDST_AS: 17\nBGP_IPV4_NEXT_HOP: 18\nIPV6_SRC_ADDR: 27\nIPV6_DST_ADDR: 28\nIPV6_NEXT_HOP: 62\nBPG_IPV6_NEXT_HOP: 63\nIP_PROTOCOL_VERSION: 60\n---------------------------", coll_pbbox, "", 0)
648            coll_frame2 = gtk.Frame("Disable rules")
649            coll_vbox.pack_start(coll_frame2, False, False, 5)
650            coll_hbox2 = gtk.VBox(False, 0)
651            coll_hbox2.set_border_width(5)
652            coll_frame2.add(coll_hbox2)
653            coll_pbbox2 = gtk.HButtonBox()
654            coll_hbox2.pack_start(coll_pbbox2, False, True, 5)
655            buttondelete = gtk.ToggleButton("Delete")
656            buttondelete.connect("toggled", callback_delete_rule, coll_window)
657            mainTT.set_tip(buttondelete, "Delete all your rules of the collector configuration.")
658            coll_hbox2.pack_start(buttondelete, False, False, 2)
659            buttondelete.show()
660            coll_vbox.show()
661            coll_window.show_all()
662            if (is_already_see==0):
663                info_dialog(widget, None, "You should registered only one rule for each GUI parser ! Think of using the DELETE button !")
664                is_already_see=1
665
666def callback_fields_printed( widget, data=None):
667    global printValue
668    printValue[data] = widget.get_active()
669
670def callback_check_ip( widget, data=None):
671    global src_Or_Dst_IP
672    if widget.get_active()==1:
673        if checkUpValues[1]:
674            src_Or_Dst_IP = 1
675        else:
676            widget.set_active(0)
677            check_dialog(widget, None, "First, enter a source address.")
678    else:
679            src_Or_Dst_IP = 0
680
681def callback_comboR(widget, data=None):
682    global comboRouter, routerHash
683    nop = 0
684    print struct.unpack('>L',socket.inet_aton(routerHash[comboRouter.entry.get_text()]))
685   
686def callback_src_mask(widget, data=None):
687    nop = 0
688
689def callback_dst_mask(widget, data=None):
690    nop = 0
691
692def callback_tos(widget, data=None):
693    nop = 0
694
695def callback_prot(widget, data=None):
696    nop = 0
697
698def create_button(title, state, callback_function, ptr_var, parent, tooltip_Text):
699    global mainTT
700    button = gtk.ToggleButton(title)
701    if state==1:
702        button.set_active(True)
703    else:
704        button.set_active(False)
705    button.connect("toggled", callback_function, ptr_var)
706    if tooltip_Text!=None:
707        mainTT.set_tip(button, tooltip_Text)
708    parent.pack_start(button, False, True, 2)
709    button.show()
710
711def create_entry(maxLen, tooltip_Text, parent, lab, id):
712    global mainTT
713    vbox = gtk.VBox(False, 0)
714    parent.pack_start(vbox, False, True, 0)
715    label = gtk.Label(lab)
716    label.set_alignment(0, 0.5)
717    vbox.pack_start(label, False, True, 0)
718    entry = gtk.Entry(max=maxLen)
719    entry.set_max_length(maxLen)
720    entry.connect("activate", enter_callback, entry, id)
721    entry.set_text("")
722    entry.select_region(0, len(entry.get_text()))
723    if tooltip_Text!=None:
724        mainTT.set_tip(entry, tooltip_Text)
725    vbox.pack_start(entry, False, True, 0)
726    entry.show()
727
728def sent_rule(widget, msg):
729    global collectorAddr, collectorPort, collectorAddr6, IPversion
730    s = None
731    if (IPversion==4):
732        tmpaf =  socket.AF_INET
733        addr = collectorAddr
734        port = collectorPort
735    elif (IPversion == 6):
736        tmpaf =  socket.AF_INET6
737        addr = collectorAddr6
738        port = collectorPort
739    else:
740        print "Wrong IP version : ", IPversion
741        exit(0)
742    for res in socket.getaddrinfo(addr, port, tmpaf, socket.SOCK_STREAM):
743        af, socktype, proto, canonname, sa = res
744        try:
745            s = socket.socket(af, socktype, proto)
746        except socket.error, msg:
747            s = None
748            continue
749        try:
750            s.connect(sa)
751        except socket.error, msg:
752            s.close()
753            s = None
754            continue
755        break
756    if s is None:
757        check_dialog( widget, None, "could not open socket")
758    else:
759        s.send(msg)
760        check_dialog( widget, None, "Action was sent")
761        s.close()
762
763# dialog box to collector control
764def prefix_callback( widget, entry, id):
765    global collPrefix, coll_window, router, localPort
766    entry_text = entry.get_text()
767    is_good = 0
768    if (id == 0):
769        if ( entry_text==""):
770            collPrefix = 0
771        else:
772            rule = entry_text.split(' ')
773            field = rule[0]
774            operator = rule[1]
775            value = rule[2]
776            if (field=='0' or field=='8' or field=='12' or field=='15' or field=='18' or field=='47'):
777                if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',value)):
778                    splitter = value.split('/')
779                    adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
780                    if len(splitter)>1:
781                        bits = int(splitter[1])
782                        if bits <= 32 and bits > 0:
783                            mask[1] = 0xffffffffL << (32 - bits)
784                            is_good = 1
785                        else:
786                            check_dialog( widget, None, "Wrong value in mask!")
787                            is_good = 0
788                    else:
789                        value = value+"/32"
790                        mask[1] = 0xffffffffL
791                        is_good = 1
792                else:
793                    check_dialog( widget, None, "Wrong value !")
794            if (field=='27' or field=='28' or field=='62'):
795                ipv6ad_mask = value.split('/')
796                if len(ipv6ad_mask)==1:
797                    try:
798                        socket.gethostbyaddr(value)
799                        is_good = 1
800                    except socket.gaierror:
801                        check_dialog( widget, None, "Wrong value !")
802                    except socket.herror: ## can't resolv
803                        check_dialog( widget, None, "I can't resolv !")
804                    except socket.error:
805                        check_dialog( widget, None, "Error in gethostbyaddr()!")
806                else:
807                    is_good = 1
808                ##here, check the prefix value?
809            if (field=='60' or field=='46'):
810                if (int(value) < 256):
811                    is_good = 1
812                else:
813                    check_dialog( widget, None, "Wrong value, must be < 256 !")
814                    is_good = 0
815            if (field=='1'):
816                if (int(value) < 4294967295):
817                    is_good = 1
818                else:
819                    check_dialog( widget, None, "Wrong value, must be < 4294967295 !")
820                    is_good = 0
821            if (field=='7' or field=='11'):
822                if (int(value) < 65536):
823                    is_good = 1
824                else:
825                    check_dialog( widget, None, "Wrong value, must be < 65536 !")
826                    is_good = 0
827            if (field=='10' or field=='14' or field=='16' or field=='17'):
828                if (int(value) < 65536):
829                    is_good = 1
830                else:
831                    check_dialog( widget, None, "Wrong value, must be < 65536 !")
832                    is_good = 0                   
833            if (is_good==1):
834                ##collPrefix = adip & mask[1]
835                ## Here tcp exchange between collector & client
836                msg = str(localPort) +" "+ field +" "+ operator+" "+ value
837                sent_rule(widget, msg)
838                widget.set_editable(False)
839                coll_window.destroy()
840    else:
841        check_dialog( widget, None, "Internal program error ;) !")
842
843# collector control button
844def prefix_entry(maxLen, tooltip_Text, parent, lab, id):
845    global mainTT
846    vbox = gtk.VBox(False, 0)
847    parent.pack_start(vbox, False, True, 0)
848    label = gtk.Label(lab)
849    label.set_alignment(0, 0.5)
850    vbox.pack_start(label, False, True, 0)
851    entry = gtk.Entry(max=maxLen)
852    entry.set_max_length(maxLen)
853    entry.connect("activate", prefix_callback, entry, id)
854    entry.set_text("")
855    entry.select_region(0, len(entry.get_text()))
856    if tooltip_Text!=None:
857        mainTT.set_tip(entry, tooltip_Text)
858    vbox.pack_start(entry, False, True, 0)
859    entry.show()
860
861def user_quit(widget, data=None):
862    global myInputControlThread, localPort, record_file, myTimer
863    if myInputControlThread != None:
864        myInputControlThread.kill(1)
865        myInputControlThread = None
866        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
867        s.connect(('localhost', localPort))
868        s.send("FIN")
869        s.close()
870        if (record_file!=None):
871            record_file.close()
872        print "\n\n\n\n\n Input Stream closed. \n\n\n\n\n By :-) \n\n\n\n"
873    myTimer.cancel()
874    gtk.main_quit()
875
876# Flow Selection
877def enter_callback( widget, entry, id):
878    global firstParseValue
879    entry_text = entry.get_text()
880    if id == 0:
881        if (entry_text==""):
882            checkUpValues[0] = 0
883        else:
884            if (re.search('\D',entry_text)) or (int(entry_text) >= 99) or (int(entry_text) <= 0):
885                check_dialog( widget, None, "Wrong value !")
886            else:
887                firstParseValue[0] = int(entry_text)
888                checkUpValues[0] = 1
889    if id == 1:
890        if ( entry_text==""):
891            checkUpValues[8] = 0
892            checkUpValues[12] = 0
893        else:
894            if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',entry_text)):
895                splitter = entry_text.split('/')
896                adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
897                if len(splitter)>1:
898                    bits = int(splitter[1])
899                    if bits <= 32 and bits > 0:
900                        mask[0] = 0xffffffffL << (32 - bits)
901                    else:
902                        check_dialog( widget, None, "Wrong value in mask!")
903                else:
904                    mask[0] = 0xffffffffL
905                firstParseValue[8] = adip & mask[0]
906                checkUpValues[8] = 1
907                firstParseValue[12] = adip & mask[0]
908                checkUpValues[12] = 1
909            else:
910                check_dialog( widget, None, "Wrong value !")
911    if id == 2:
912        if ( entry_text==""):
913            checkUpValues[2] = 0
914        else:
915            check_dialog( widget, None, "NOT YET IMPLEMEMTED")
916            ## pb with IPv6 and getaddrinfo() ??
917##            splitter = entry_text.split('/')
918##            try:
919##                socket.gethostbyaddr(splitter[0])
920##            except socket.gaierror:
921##                check_dialog( widget, None, "Wrong value !")
922##            except socket.herror: ## can't resolv
923##                pass
924##            except socket.error:
925##                pass
926    if id == 3:
927        if ( entry_text==""):
928            checkUpValues[15] = 0
929        else:
930            if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',entry_text)):
931                splitter = entry_text.split('/')
932                adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
933                if len(splitter)>1:
934                    bits = int(splitter[1])
935                    if bits <= 32 and bits > 0:
936                        mask[2] = 0xffffffffL << (32 - bits)
937                    else:
938                        check_dialog( widget, None, "Wrong value in mask!")
939                else:
940                    mask[2] = 0xffffffffL
941                firstParseValue[15] = adip & mask[2]
942                checkUpValues[15] = 1
943            else:
944                check_dialog( widget, None, "Wrong value !")
945    if id == 4: ## In|Out
946        if ( entry_text==""):
947            checkUpValues[10] = 0
948            checkUpValues[14] = 0
949        else:
950            if (re.search('\D',entry_text)) or (int(entry_text) > 65535) or (int(entry_text) < 0):
951                check_dialog( widget, None, "Wrong value !")
952            else:
953                firstParseValue[10] = int(entry_text)
954                checkUpValues[10] = 1
955                firstParseValue[14] = int(entry_text)
956                checkUpValues[14] = 1
957    if id == 6: ## bytes
958        if ( entry_text==""):
959            checkUpValues[1] = 0
960        else:
961            if (re.search('\D',entry_text)) or (int(entry_text) > 999999999) or (int(entry_text) <= 0):
962                check_dialog( widget, None, "Wrong value !")
963            else:
964                firstParseValue[1] = int(entry_text)
965                if ( int(entry_text) == 0 ):
966                    firstParseValue[1] = 1000000000
967                else:
968                    firstParseValue[1] = int(entry_text)
969                checkUpValues[1] = 1
970    if id == 7: ## pkts
971        if ( entry_text==""):
972            checkUpValues[2] = 0
973        else:
974            if (re.search('\D',entry_text)) or (int(entry_text) > 9999) or (int(entry_text) <= 0):
975                check_dialog( widget, None, "Wrong value !")
976            else:
977                firstParseValue[2] = int(entry_text)
978                checkUpValues[2] = 1
979    if id == 8: ## time no concordance with nfv9 field number
980        if ( entry_text==""):
981            checkUpValues[0] = 0
982        else:
983            if (re.search('\D',entry_text)) or (int(entry_text) > 99) or (int(entry_text) < 0):
984                check_dialog( widget, None, "Wrong value !")
985            else:
986                firstParseValue[0] = int(entry_text)
987                checkUpValues[0] = 1
988    if id == 9: ## port range
989        if ( entry_text==""):
990            checkUpValues[7] = 0
991        else:
992            port_list = string.split(entry_text)
993            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)):
994                check_dialog( widget, None, "Wrong value !")
995            else:
996                firstParseValue[7] = int(port_list[0])
997                firstParseValue[11] = int(port_list[1])
998                checkUpValues[7] = 1
999    if id == 11: ## tcp flags
1000        if ( entry_text==""):
1001            checkUpValues[6] = 0
1002        else:
1003            if (re.search('\D',entry_text)) or (int(entry_text) > 255) or (int(entry_text) <= 0):
1004                check_dialog( widget, None, "Wrong value !")
1005            else:
1006                firstParseValue[6] = int(entry_text)
1007                checkUpValues[6] = 1
1008    if id == 12: ## prot
1009        if ( entry_text==""):
1010            checkUpValues[4] = 0
1011        else:
1012            if (re.search('\D',entry_text)) or (int(entry_text) > 255) or (int(entry_text) <= 0):
1013                check_dialog( widget, None, "Wrong value !")
1014            else:
1015                firstParseValue[4] = int(entry_text)
1016                checkUpValues[4] = 1
1017    if id == 13: ## tos
1018        if ( entry_text==""):
1019            checkUpValues[5] = 0
1020        else:
1021            if (re.search('\D',entry_text)) or (int(entry_text) > 255) or (int(entry_text) < 0):
1022                check_dialog( widget, None, "Wrong value !")
1023            else:
1024                firstParseValue[5] = int(entry_text)
1025                checkUpValues[5] = 1
1026    if id == 14: ## src AS
1027        if ( entry_text==""):
1028            checkUpValues[16] = 0
1029        else:
1030            if (re.search('\D',entry_text)) or (int(entry_text) > 65535) or (int(entry_text) < 0):
1031                check_dialog( widget, None, "Wrong value !")
1032            else:
1033                firstParseValue[16] = int(entry_text)
1034                checkUpValues[16] = 1
1035    if id == 15: ## dst AS
1036        if ( entry_text==""):
1037            checkUpValues[17] = 0
1038        else:
1039            if (re.search('\D',entry_text)) or (int(entry_text) > 65535) or (int(entry_text) < 0):
1040                check_dialog( widget, None, "Wrong value !")
1041            else:
1042                firstParseValue[17] = int(entry_text)
1043                checkUpValues[17] = 1
1044    if id == 18: ## from router
1045        if ( entry_text==""):
1046            checkUpValues[69] = 0
1047        else:
1048            if (re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$',entry_text)):
1049                splitter = entry_text.split('/')
1050                adip = struct.unpack('>L',socket.inet_aton(splitter[0]))[0]
1051                if len(splitter)>1:
1052                    bits = int(splitter[1])
1053                    if bits <= 32 and bits > 0:
1054                        mask[0] = 0xffffffffL << (32 - bits)
1055                    else:
1056                        check_dialog( widget, None, "Wrong value in mask!")
1057                else:
1058                    mask[0] = 0xffffffffL
1059                firstParseValue[69] = splitter[0]
1060                checkUpValues[69] = 1
1061            else:
1062                check_dialog( widget, None, "Wrong value !")
1063   
1064if __name__ == "__main__":
1065    global window, mainTT, comboRouter, os_type, printShit
1066   
1067    gtk.gdk.threads_init()
1068   
1069    if (os.name =="nt"):
1070        os_type = 1
1071    elif (os.name =="posix"):
1072        os_type = 0
1073    else:
1074        os_type = 3
1075
1076    print "---------------------------------------------------------------"
1077    print "In this version, you can only apply rules on the collector based on the following fields:"
1078    print "IN_BYTES: 1,"
1079    print "L4_SRC_PORT: 7,"
1080    print "IPV4_SRC_ADDR: 8,"
1081    print "INPUT_SNMP: 10,"
1082    print "L4_DST_PORT: 11,"
1083    print "IPV4_DST_ADDR: 12,"
1084    print "OUTPUT_SNMP: 14,"
1085    print "IPV4_NEXT_HOP: 15,"
1086    print "SRC_AS: 16,"
1087    print "DST_AS: 17,"
1088    print "BGP_IPV4_NEXT_HOP: 18,"
1089    print "IPV6_SRC_ADDR: 27,"
1090    print "IPV6_DST_ADDR: 28,"
1091    print "MPLS_TOP_LABEL_TYPE: 46,"
1092    print "IPV6_NEXT_HOP: 62,"
1093    print "BPG_IPV6_NEXT_HOP: 63,"
1094    print "IP_PROTOCOL_VERSION: 60, please note that the IPv4 templates don't have this field"
1095    print "ROUTER_SRC_ADDR: 0, !!! it's not a real number for a field, but it's a great function"
1096    print "----------------------------------------------------------------"
1097   
1098    mainTT = gtk.Tooltips()
1099    window = gtk.Window(gtk.WINDOW_TOPLEVEL)   
1100    window.connect("destroy", gtk.main_quit, "WM destroy")
1101    window.set_title("RenetcolGUI")
1102    window.set_size_request(850, 550)
1103   
1104    main_vbox = gtk.VBox(False, 1)
1105    main_vbox.set_border_width(1)
1106    window.add(main_vbox)
1107
1108##  menu
1109    file_menu = gtk.Menu()
1110    receive_item = gtk.MenuItem("Receive Stream")
1111    stop_item = gtk.MenuItem("Stop Stream")
1112    quit_item  = gtk.MenuItem("Quit")
1113    file_menu.append(receive_item)
1114    file_menu.append(stop_item)
1115    file_menu.append(quit_item)
1116    receive_item.connect("activate", reception, None)
1117    stop_item.connect("activate", close_recept, None)
1118    quit_item.connect("activate", user_quit, None)
1119    receive_item.show()
1120    stop_item.show()
1121    quit_item.show()
1122
1123    help_menu = gtk.Menu()
1124    about_item = gtk.MenuItem("About")
1125    help_menu.append(about_item)
1126    about_item.connect("activate", about_dialog, None)
1127    about_item.show()
1128
1129    menu_bar = gtk.MenuBar()
1130    main_vbox.pack_start(menu_bar, False, False, 0)
1131    menu_bar.show()
1132    file_item = gtk.MenuItem("File")
1133    file_item.show()
1134    help_item = gtk.MenuItem("Help")
1135    help_item.show()
1136
1137    file_item.set_submenu(file_menu)
1138    menu_bar.append(file_item)
1139    menu_bar.append(file_menu)
1140    file_item.set_right_justified(0)
1141
1142    help_item.set_submenu(help_menu)
1143    menu_bar.append(help_item)
1144    menu_bar.append(help_menu)
1145    help_item.set_right_justified(1)
1146
1147##  first frame
1148    frame = gtk.Frame("Input Stream Control")
1149    main_vbox.pack_start(frame, False, True, 0)
1150    hbox = gtk.HBox(False, 0)
1151    hbox.set_border_width(5)
1152    frame.add(hbox)
1153
1154    ## freeze button
1155    buttonfreeze = gtk.ToggleButton("Freeze")
1156    buttonfreeze.connect("toggled", callback_freeze, None)
1157    mainTT.set_tip(buttonfreeze, "Stop/Start the output in the window.")
1158    hbox.pack_start(buttonfreeze, False, False, 2)
1159    buttonfreeze.show()
1160    ## record button
1161    buttonrecord = gtk.ToggleButton("Record")
1162    buttonrecord.connect("toggled", callback_record, None)
1163    mainTT.set_tip(buttonrecord, "Stop/Start the record in a text file.")
1164    hbox.pack_start(buttonrecord, False, False, 2)
1165    buttonrecord.show()
1166    ## incremental record
1167    buttonRotRec = gtk.ToggleButton("Rot. Record")
1168    buttonRotRec.connect("toggled", callback_RotRec, None)
1169    mainTT.set_tip(buttonRotRec, "Stop/Start the record in a different file for each day.")
1170    hbox.pack_start(buttonRotRec, False, False, 2)
1171    buttonRotRec.show()
1172    ## control collector button
1173    buttoncollector = gtk.ToggleButton("Collector Control")
1174    buttoncollector.connect("toggled", callback_collector, None)
1175    mainTT.set_tip(buttoncollector, "Change the rule which is applied on the collector. You must have activated the input stream before.")
1176    hbox.pack_start(buttoncollector, False, False, 2)
1177    buttoncollector.show()
1178
1179    ipv4_vbox = gtk.VBox(False, 1)
1180    ipv4_vbox.set_border_width(1)
1181    main_vbox.add(ipv4_vbox)
1182##  second frame
1183    frame = gtk.Frame("Select printed fields")
1184    ipv4_vbox.pack_start(frame, False, False, 0)
1185   
1186    vbox = gtk.VBox(False, 0)
1187    vbox.set_border_width(5)
1188    frame.add(vbox)
1189    bbox = gtk.HButtonBox()
1190    vbox.pack_start(bbox, False, True, 5)
1191   
1192    create_button("Src \n IP", 1, callback_fields_printed, 8, bbox, "Source IP")
1193    create_button("Dst\n IP", 1, callback_fields_printed, 12, bbox, "Destination IP")
1194    create_button("Flw\n IP", 0, callback_fields_printed, 15, bbox, "Following IP")
1195    create_button("Index\n In", 0, callback_fields_printed, 10, bbox, "SNMP Index Input")
1196    create_button("Index\n Out", 0, callback_fields_printed, 14, bbox, "SNMP Index Output")
1197    create_button("Size (P)", 1, callback_fields_printed, 2, bbox, "Packets number")
1198    create_button("Size (B)", 1, callback_fields_printed, 1, bbox, "Size in Bytes")
1199    create_button("Time", 0, callback_fields_printed, 0, bbox, "Age of flow")
1200
1201    b2box = gtk.HButtonBox()
1202    vbox.pack_start(b2box, False, True, 5)
1203    create_button("Src\n Port", 1, callback_fields_printed, 7, b2box, "TCP/UDP source port")
1204    create_button("Dst\n Port", 1, callback_fields_printed, 11, b2box, "TCP/UDP destination port")
1205    create_button("TCP\n Flags", 0, callback_fields_printed, 6, b2box, "TCP Flags")
1206    create_button("Prot", 1, callback_fields_printed, 4, b2box, "Protocol")
1207    create_button("Tos", 0, callback_fields_printed, 5, b2box, "Type of service")
1208    create_button("Src\nAs", 0, callback_fields_printed, 16, b2box, "Source AS")
1209    create_button("Dst\nAs", 0, callback_fields_printed, 17, b2box, "Destination AS")
1210    create_button("Src\nMask", 0, callback_fields_printed, 9, b2box, "Source Mask")
1211    create_button("Dst\nMask", 0, callback_fields_printed, 13, b2box, "Destination Mask")
1212
1213    b3box = gtk.HButtonBox()
1214    vbox.pack_start(b3box, False, True, 5)
1215    create_button("Router", 0, callback_fields_printed, 69, b3box, "Router address")
1216
1217##  third frame
1218    frame = gtk.Frame("Parsing values")
1219    ipv4_vbox.pack_start(frame, False, False, 5)
1220    hbox = gtk.VBox(False, 0)
1221    hbox.set_border_width(5)
1222    frame.add(hbox)
1223    pbbox = gtk.HButtonBox()
1224    hbox.pack_start(pbbox, False, True, 5)
1225##  here entry button
1226    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)
1227    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)
1228    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)
1229    dbbox = gtk.HButtonBox()
1230    hbox.pack_start(dbbox, False, True, 5)
1231    create_entry(5, "Required Format : a number less than 65535", dbbox, "SNMP Index In|Out :", 4)
1232    create_entry(4, "Required Format : a number less than 9999", dbbox, "Packet NB :", 7)
1233    create_entry(17, "Required Format : a number less than 999999999, each flow who the size equal this number +/- 5%", dbbox, "Bytes :", 6)
1234    tbbox = gtk.HButtonBox()
1235    hbox.pack_start(tbbox, False, True, 5)
1236    create_entry(2, "Required Format : a number less than 99", tbbox, "Time :", 8)
1237    create_entry(11, "Required Format : a range, each number less than 65535 and space as separator: \"6881 6889\"", tbbox, "Port :", 9)
1238    #create_entry(5, "Required Format : a number less than 65535", tbbox, "Dst port :", 10)
1239    create_entry(3, "Required Format : a number less than 255", tbbox, "TCP Flag :", 11)
1240    fbbox = gtk.HButtonBox()
1241    hbox.pack_start(fbbox, False, True, 5)
1242    create_entry(5, "Required Format : a number less than 65535", fbbox, "Protocol :", 12)
1243    create_entry(3, "Required Format : a number less than 255", fbbox, "ToS :", 13)
1244    create_entry(5, "Required Format : a number less than 65535", fbbox, "Src AS :", 14)
1245    create_entry(5, "Required Format : a number less than 65535", fbbox, "Dst AS :", 15)
1246    kbbox = gtk.HButtonBox()
1247    hbox.pack_start(kbbox, False, True, 5)
1248    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)
1249
1250##  Show
1251    vbox.show()
1252    main_vbox.show()
1253    window.show_all()
1254    mainTT.enable()
1255
1256##  gtk main loop
1257    gtk.gdk.threads_enter()
1258    gtk.main()
1259    gtk.gdk.threads_leave()
Note: See TracBrowser for help on using the browser.