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