<s> import os <EOL> from BroControl import util <EOL> from BroControl import config <EOL> def get_syncs ( ) : <EOL> syncs = [ <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , True ) <EOL> ] <EOL> return syncs <EOL> def get_nfssyncs ( ) : <EOL> nfssyncs = [ <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) <EOL> ] <EOL> return nfssyncs <EOL> def make_broctl_config_sh ( cmdout ) : <EOL> cfg_path = os . path . join ( config . Config . broctlconfigdir , "<STR_LIT>" ) <EOL> with open ( cfg_path , "<STR_LIT:w>" ) as out : <EOL> for ( varname , value ) in config . Config . options ( dynamic = False ) : <EOL> if isinstance ( value , bool ) : <EOL> value = ( value and "<STR_LIT:1>" or "<STR_LIT:0>" ) <EOL> else : <EOL> value = str ( value ) <EOL> out . write ( '<STR_LIT>' % ( varname . replace ( "<STR_LIT:.>" , "<STR_LIT:_>" ) , <EOL> value . replace ( '<STR_LIT:">' , '<STR_LIT>' ) ) ) <EOL> symlink = os . path . join ( config . Config . scriptsdir , "<STR_LIT>" ) <EOL> if not os . path . islink ( symlink ) or os . readlink ( symlink ) != cfg_path : <EOL> try : <EOL> util . force_symlink ( cfg_path , symlink ) <EOL> except OSError as e : <EOL> cmdout . error ( "<STR_LIT>" % ( symlink , cfg_path , e . strerror ) ) <EOL> return False <EOL> return True <EOL> def make_layout ( path , cmdout , silent = False ) : <EOL> class Port : <EOL> def __init__ ( self , startport ) : <EOL> self . p = startport <EOL> def next_port ( self , node ) : <EOL> self . p += <NUM_LIT:1> <EOL> node . setPort ( self . p ) <EOL> return self . p <EOL> manager = config . Config . manager ( ) <EOL> filename = os . path . join ( path , "<STR_LIT>" ) <EOL> if config . Config . nodes ( "<STR_LIT>" ) : <EOL> if os . access ( filename , os . W_OK ) : <EOL> os . unlink ( filename ) <EOL> if not silent : <EOL> cmdout . info ( "<STR_LIT>" ) <EOL> filename = os . path . join ( path , "<STR_LIT>" ) <EOL> with open ( filename , "<STR_LIT:w>" ) as out : <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" % config . Config . broport ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" % ( util . format_bro_addr ( manager . addr ) , manager . zone_id ) ) <EOL> out . write ( "<STR_LIT>" ) <EOL> else : <EOL> if not silent : <EOL> cmdout . info ( "<STR_LIT>" ) <EOL> broport = Port ( config . Config . broport ) <EOL> workers = config . Config . nodes ( "<STR_LIT>" ) <EOL> proxies = config . Config . nodes ( "<STR_LIT>" ) <EOL> with open ( filename , "<STR_LIT:w>" ) as out : <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" % ( util . format_bro_addr ( manager . addr ) , config . Config . zoneid , config . Config . broport ) ) <EOL> out . write ( "<STR_LIT>" % ( manager . name , util . format_bro_addr ( manager . addr ) , manager . zone_id , broport . next_port ( manager ) ) ) <EOL> for s in workers : <EOL> out . write ( "<STR_LIT>" % s . name ) <EOL> if s != workers [ - <NUM_LIT:1> ] : <EOL> out . write ( "<STR_LIT:U+002CU+0020>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> for p in proxies : <EOL> out . write ( "<STR_LIT>" % ( p . name , util . format_bro_addr ( p . addr ) , p . zone_id , broport . next_port ( p ) , manager . name ) ) <EOL> for s in workers : <EOL> out . write ( "<STR_LIT>" % s . name ) <EOL> if s != workers [ - <NUM_LIT:1> ] : <EOL> out . write ( "<STR_LIT:U+002CU+0020>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> for w in workers : <EOL> p = w . count % len ( proxies ) <EOL> out . write ( "<STR_LIT>" % ( w . name , util . format_bro_addr ( w . addr ) , w . zone_id , broport . next_port ( w ) , w . interface , manager . name , proxies [ p ] . name ) ) <EOL> if config . Config . timemachinehost : <EOL> out . write ( "<STR_LIT>" % ( config . Config . timemachinehost , config . Config . timemachineport ) ) <EOL> out . write ( "<STR_LIT>" ) <EOL> def read_networks ( fname ) : <EOL> nets = [ ] <EOL> with open ( fname , "<STR_LIT:r>" ) as f : <EOL> for line in f : <EOL> line = line . strip ( ) <EOL> if not line or line . startswith ( "<STR_LIT:#>" ) : <EOL> continue <EOL> fields = line . split ( None , <NUM_LIT:1> ) <EOL> cidr = util . format_bro_prefix ( fields [ <NUM_LIT:0> ] ) <EOL> tag = "<STR_LIT>" <EOL> if len ( fields ) == <NUM_LIT:2> : <EOL> tag = fields [ <NUM_LIT:1> ] <EOL> nets += [ ( cidr , tag ) ] <EOL> return nets <EOL> def make_local_networks ( path , cmdout , silent = False ) : <EOL> netcfg = config . Config . localnetscfg <EOL> if not os . path . exists ( netcfg ) : <EOL> cmdout . error ( "<STR_LIT>" % netcfg ) <EOL> return False <EOL> nets = read_networks ( netcfg ) <EOL> with open ( os . path . join ( path , "<STR_LIT>" ) , "<STR_LIT:w>" ) as out : <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> for ( cidr , tag ) in nets : <EOL> out . write ( "<STR_LIT>" % cidr ) <EOL> if tag : <EOL> out . write ( "<STR_LIT>" % tag ) <EOL> out . write ( "<STR_LIT:\n>" ) <EOL> out . write ( "<STR_LIT>" ) <EOL> return True <EOL> def make_broctl_config_policy ( path , cmdout , silent = False ) : <EOL> manager = config . Config . manager ( ) <EOL> filename = os . path . join ( path , "<STR_LIT>" ) <EOL> with open ( filename , "<STR_LIT:w>" ) as out : <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" % config . Config . mailto ) <EOL> out . write ( "<STR_LIT>" % config . Config . mailalarmsto ) <EOL> out . write ( "<STR_LIT>" % config . Config . sendmail ) <EOL> out . write ( "<STR_LIT>" % config . Config . mailsubjectprefix ) <EOL> out . write ( "<STR_LIT>" % config . Config . mailfrom ) <EOL> if manager . type != "<STR_LIT>" : <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" % config . Config . logrotationinterval ) <EOL> out . write ( "<STR_LIT>" % config . Config . mailalarmsinterval ) <EOL> if manager . type != "<STR_LIT>" : <EOL> out . write ( "<STR_LIT>" ) <EOL> if config . Config . ipv6comm : <EOL> out . write ( "<STR_LIT>" ) <EOL> else : <EOL> out . write ( "<STR_LIT>" ) <EOL> out . write ( "<STR_LIT>" % config . Config . pcapsnaplen ) <EOL> out . write ( "<STR_LIT>" % config . Config . pcapbufsize ) </s>
