def start(): filename = utils.joinFilePath( utils.getenv('COWRY_ROOT'), 'core/components/cowry_admin/gunicorn_runner.py') configPath = utils.getenv('COWRY_CONFIG') cmd = 'python3 {} {}'.format(filename, configPath) completed = subprocess.Popen(cmd, shell=True)
def drop(self): """Clear system info and delete all info of cowry.""" # check if system been droped # Check that the system has been deleted if self.settings.default.inited == '0': self.log.info('the system has been deleted'.title()) utils.deleteFile(utils.getenv('COWRY_CONFIG')) exit() self.log.info('Start drop cowry system !!! ') # delete uploaded files if utils.checkFolderExists(self.settings.storage.datapath): utils.delfolder(self.settings.storage.datapath) # delete server certificates if utils.checkFileExists(self.settings.certificates.certificate ) or utils.checkFileExists( self.settings.certificates.privatekey): utils.deleteFile(self.settings.certificates.certificate) utils.deleteFile(self.settings.certificates.privatekey) utils.delfolder( utils.getDirNameByPath(self.settings.certificates.privatekey)) # delete all database tables self.init_db() self.db.drop() # delete all database file if use sqlite if self.settings.database.df: utils.deleteFile(self.settings.database.df) utils.delfolder(utils.getDirNameByPath(self.settings.database.df)) # delete configure file utils.deleteFile(utils.getenv('COWRY_CONFIG')) self.log.info('Finished drop cowry system') exit()
def init_setenv(self): # set host name if utils.verifyDomain(self.settings.server.bind_domain): utils.setenv('COWRY_HOST', self.settings.server.bind_domain) self.log.info('system bind server name on : {}'.format( utils.getenv('COWRY_HOST'))) else: utils.setenv('COWRY_HOST', self.settings.server.bind_address) self.log.info('system bind server name on : {}'.format( utils.getenv('COWRY_HOST')))
def init_configure(self): """Pass.""" # self.log.info('start init configure file') if not utils.checkFileExists(utils.getenv('COWRY_CONFIG')): src = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'cowry.conf.default') dst = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'cowry.conf') utils.copyfile(src, dst) print('Not find default configure file, copy default configure to use') self.settings = Settings() # set default certificates folders values if not self.settings.certificates.certdirs: setDefaultCertDirs = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'certs') self.settings._set(('certificates', 'certdirs', setDefaultCertDirs))
def init_status(self): """Pass.""" if utils.getenv('COWRY_STATUS') != 'NO': self.systemStatus = Status() self.systemStatus.start() else: self.log.info('Start system without echo status of system.')
def createDataSock(self): self.log.info('start create data socket') # create an INET, STREAMing socket self.dataSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.dataSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # bind the socket to a public host, and a well-known port while True: randomPort = utils.generateRandomDigitFromRange(2333, 2433) try: self.dataSocket.bind( (utils.getenv('COWRY_HOST'), int(randomPort))) except Exception as e: self.log.info(str(e)) else: dataSocketInfo = self.dataSocket.getsockname() self.log.info('data socket create successd on : {}'.format( dataSocketInfo)) break # become a server socket self.dataSocket.listen(1) # return data port return (0, randomPort)
def init_configure(self): """Pass.""" # self.log.info('start init configure file') if not utils.checkFileExists(utils.getenv('COWRY_CONFIG')): src = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'cowry.conf.default') dst = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'cowry.conf') utils.copyfile(src, dst) print( 'Not find default configure file, copy default configure to use' ) self.settings = Settings() # set default uploaded files path if not utils.checkAbsPath( self.settings.storage.datapath) or not utils.checkFolderExists( self.settings.storage.datapath): setDefaultDataPath = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'data') self.settings._set(('storage', 'datapath', setDefaultDataPath)) # set default certificates values if not utils.checkAbsPath(self.settings.certificates.privatekey ) and not utils.checkAbsPath( self.settings.certificates.certificate): setDefaultPrivateKey = utils.joinFilePath( utils.getenv('COWRY_ROOT'), 'certs', 'server.key') setDefaultCert = utils.joinFilePath(utils.getenv('COWRY_ROOT'), 'certs', 'server.crt') self.settings._set( ('certificates', 'privatekey', setDefaultPrivateKey)) self.settings._set(('certificates', 'certificate', setDefaultCert)) # set db default path if sqlite be used if self.settings.database.type == 'sqlite' and not self.settings.database.df: setDefaultSqliteDbPath = utils.joinFilePath( utils.getenv('COWRY_ROOT'), 'db', 'data', 'default.sqlite') self.settings._set(('database', 'df', setDefaultSqliteDbPath))
def __init__(self): super(Settings, self).__init__() self.configurePath = utils.getenv('COWRY_CONFIG') or 'cowry.conf' self.read(self.configurePath) self.analysis()