| 296 | myTpl = [] |
| 297 | strFlow = "" |
| 298 | strField = "" |
| 299 | underscore_line = "" |
| 300 | flowCptW+=1 |
| 301 | if (flowCptW%6 == 0 or oldTplW != self.flow[0]): |
| 302 | ## if (flowCpt%100 == 0): |
| 303 | flowCptW = 0 |
| 304 | for i in range (0, len(tpl_def[self.flow[0]])): |
| 305 | f = tpl_def[self.flow[0]][i][0] |
| 306 | if printValue[f]: |
| 307 | if ( f==27 or f==28 or f==62 or f==63 ): |
| 308 | strField += str(fieldsName[f]) |
| 309 | l = len(str(fieldsName[f])) |
| 310 | if ((40-l)%8 == 0): |
| 311 | tabNb = int((40-l)/8) |
| 312 | else: |
| 313 | tabNb = int((40-l)/8) + 1 |
| 314 | for j in range (0, tabNb): |
| 315 | strField += ";" |
| 316 | for k in range (0, 40): |
| 317 | underscore_line += "-" |
| 318 | elif ( f==8 or f==15 or f==12 or f==18 or f==47 ): |
| 319 | strField += str(fieldsName[f]) |
| 320 | l = len(str(fieldsName[f])) |
| 321 | if ((16-l)%8 == 0): |
| 322 | tabNb = int((16-l)/8) |
| 323 | else: |
| 324 | tabNb = int((16-l)/8) + 1 |
| 325 | for j in range (0, tabNb): |
| 326 | strField += ";" |
| 327 | for k in range (0, 16): |
| 328 | underscore_line += "-" |
| 329 | else: |
| 330 | strField += str(fieldsName[f]) |
| 331 | strField += ";" |
| 332 | for k in range (0, 8): |
| 333 | underscore_line += "-" |
| 334 | if (oldTplW != self.flow[0]): |
| 335 | record_file.write("") |
| 336 | if (os_type == 0): |
| 337 | esc = '\x1b[' |
| 338 | sep = ';' |
| 339 | end = 'm' |
| 340 | if (printValue[69]): |
| 341 | rt = str(fieldsName[69]) |
| 342 | toprint = esc+"37"+sep+"44"+end+strField+rt+esc+"0"+end+"\n" |
| 343 | else: |
| 344 | toprint = esc+"37"+sep+"44"+end+strField+esc+"0"+end+"\n" |
| 345 | record_file.write(toprint) |
| 346 | else: |
| 347 | if (printValue[69]): |
| 348 | strField += str(fieldsName[69]) |
| 349 | if (record_file!=None): |
| 350 | record_file.write(strField) |
| 351 | record_file.write("\n") |
| 352 | record_file.write(underscore_line) |
| 353 | record_file.write("\n") |
500 | | def callback_RotRec(widget, data=None): |
501 | | global record, myTimer |
502 | | if ((record == 0) and (widget.get_active() == 1)): |
503 | | info_dialog(widget, None, "You must before activated the record ! ") |
504 | | widget.set_active(0) |
505 | | else: |
506 | | if widget.get_active() == 1: |
507 | | print "STARTING RECORD ROTATION" |
508 | | now2 = time.time() |
509 | | reste = 300-(operator.mod(now2,300)) |
510 | | myTimer = threading.Timer(300,timer_action) |
511 | | myTimer.start() |
512 | | if widget.get_active() == 0: |
513 | | myTimer.cancel() |
514 | | print "STOPPING RECORD ROTATION" |
| 562 | def RotRec(): |
| 563 | global record, myTimer, rrt |
| 568 | global rrt, record, record_file_name |
| 569 | |
| 570 | print "" |
| 571 | print "" |
| 572 | print "" |
| 573 | |
| 574 | print "----------------------------------------------------------------------------" |
| 575 | print " renetcolRC is part of renetcol " |
| 576 | print " This module writed in python is a remote client which can received flows " |
| 577 | print " information from renetcol. It was built from renetcolGUI source without " |
| 578 | print " the gtk interface and without the interaction with renetcol." |
| 579 | print " To receive flows from renetcol the filter with the field number 69 MUST be" |
| 580 | print " actived on renetcol (in your file rules.txt)" |
| 581 | print "----------------------------------------------------------------------------" |
| 590 | parser = OptionParser() |
| 591 | parser.add_option("-o", "--output", dest="out", help ="Output filename prefix, ex: \"/tmp/myrecord\", timestamp will be add to the filename") |
| 592 | parser.add_option("-t", "--time", dest="tim", help ="Round robin interval (in seconde), default is \"3600\" for 1h") |
| 593 | (options, args) = parser.parse_args() |
| 594 | outputFileName = options.out |
| 595 | rrt = int(options.tim) |
| 596 | |
| 597 | if (outputFileName!=None): |
| 598 | record = 1 |
| 599 | record_file_name = outputFileName |
| 600 | record_file = file(record_file_name, 'a+') |
| 601 | RotRec() |
| 602 | else: |
| 603 | record = 0 |
| 604 | |
| 605 | print "" |
| 606 | print "" |
| 607 | print "" |
| 608 | print " ---------------------------------------" |
| 609 | print " STARTING RECORD ROTATION" |
| 610 | print " with following parameters:" |
| 611 | print " output filename prefix :",outputFileName |
| 612 | print " interval: ",rrt, " seconds" |
| 613 | print " ---------------------------------------" |
| 614 | now2 = time.time() |
| 615 | reste = rrt-(operator.mod(now2,rrt)) |
| 616 | myTimer = threading.Timer(rrt,timer_action) |
| 617 | myTimer.start() |
| 618 | ##myTimer.cancel() |
| 619 | ##print "STOPPING RECORD ROTATION" |
| 620 | |