def __init__(self, config_dir): cfg_file = os.path.join(config_dir, 'profigure.conf') if not os.path.exists( cfg_file ): raise pro_conf.ConfigError('Missing configuation file: %s' % cfg_file) self.config = pro_conf.ProfigureConf(cfg_file) if self.config.database_dir is None: raise pro_conf.ConfigError('Missing required attribute "database_dir" from configuration file: ' + cfg_file) database_dir = self.config.database_dir self.dist_dir = os.path.join(database_dir, 'distribution') self.err_dir = os.path.join(database_dir, 'err_logs') self.ssl_dir = os.path.join(database_dir, 'ssl_certs') self.repository = os.path.join(database_dir, 'repository') self.rev_file = os.path.join(database_dir, 'rev_number') def chkdir( d ): if not os.path.exists( d ): u = os.umask(0007) os.makedirs( d ) os.umask(u) chkdir( self.dist_dir ) chkdir( self.err_dir ) chkdir( self.ssl_dir ) self.current_rev = None with open( self.rev_file, 'r' ) as f: self.current_rev = f.read().strip() self.connected_hosts = dict() self.connected_admins = dict() self.client_code = None # Binary data of gzipped tarfile containing client Python code self.load_client_code() print 'Connecting to SRP Database' self.srp_db = srp_db.SqliteSrpDB( os.path.join(database_dir, 'srp_db.sqlite') ) print 'Connecting to Account Database' self.acct_db = acct_db.AcctDB( os.path.join(database_dir, 'acct_db.sqlite') ) print 'Starting file transfer protocol' file_transfer.start_main_server() print 'Starting connection handler' pb_srp.accept_connections( self.config.master_port, self.avatar_factory, self.srp_db, self.ssl_dir ) print 'WATCHING PATH' self.inotifier = inotify.INotify() self.inotifier.startReading() for d in (this_dir, os.path.join(this_dir, 'scanners')): self.inotifier.watch( filepath.FilePath(d), mask=inotify.IN_MODIFY, callbacks=[self.code_updated,])
def start_host(config_dir, peer_addr, username, session_key, disconnect_func, peer_pb_if): dft = file_transfer.start_main_server() def start(_): return MasterConnection(config_dir, peer_addr, username, session_key, disconnect_func, peer_pb_if) dft.addCallback(start) return dft
def __init__(self, master_hostname, master_port, username, password, conf_dir = '~/.profigure'): self.username = username self.password = password self.conn = None self.dconn = None self.master_hostname = master_hostname self.master_port = master_port # TODO: Enhance security here. Check for directory ownership & permissions. Essentially, the same stuff SSH does. conf_dir = os.path.expanduser(conf_dir) ssl_dir = os.path.join(conf_dir, 'ssl') if not os.path.exists( conf_dir ): umsk = os.umask( 0077 ) os.makedirs(conf_dir) os.makedirs(ssl_dir) os.umask( umsk ) self.conf_dir = conf_dir dft = file_transfer.start_main_server()