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__(self, remote, savefilepath, authtoken, fileinfo, decrypt_info): BaseSocket.__init__(self, host=remote[0], port=remote[1]) threading.Thread.__init__(self) # UploadSignal.__init__(self) self.createDataSock() self.signal = DownloadSignal() self.saveFilePath_E = utils.joinFilePath('/tmp/', fileinfo['name'] + '.enc') self.saveFilePath_D = savefilepath self.authtoken = authtoken self.fileinfo = fileinfo self.decrypt_info = decrypt_info self.fileHashCode = fileinfo['hashcode'] if fileinfo['encryption'] == 1: self.fileSize = fileinfo['encsize'] else: self.fileSize = fileinfo['size'] self.crypt = Cryptogram() self.settings = Settings() self.step = 0 # signal connect self.signal.recv.connect(self.drawProgress)
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 view_cert_info(self): certificate_name = str(self.Host.text().strip()) + '.crt' cert_info = utils.getCertInfo(utils.joinFilePath(self.settings.certificates.certdirs, certificate_name)) def sure(): self.certInfo_dialog.close() self.certInfo_dialog = QtWidgets.QDialog() self.certInfo_dialog.ui = Ui_Cert_Info() self.certInfo_dialog.accept = sure self.certInfo_dialog.ui.setupUi(self.certInfo_dialog) self.certInfo_dialog.ui.Signature.setText(cert_info['digest']) self.certInfo_dialog.ui.Filehash.setText(cert_info['filehash']) self.certInfo_dialog.show()
def main(): cmd = 'start' if args.config: print('read config from :', args.config) defaultConfigPath = args.config if utils.checkFileExists(defaultConfigPath): utils.setenv('COWRY_CONFIG', defaultConfigPath) else: currentPath = os.path.dirname(os.path.realpath(__file__)) utils.setenv('COWRY_ROOT', currentPath) defaultConfigPath = utils.joinFilePath(currentPath, 'cowry.conf') utils.setenv('COWRY_CONFIG', defaultConfigPath) app = QApplication(os.sys.argv) prog = Action_MainWindow() getattr(prog, cmd)() os.sys.exit(app.exec_())
def acquire_remote_cert(self): self.log.info('start acquire remote host cert') try: cert = ssl.get_server_certificate((self.host, self.port)) except Exception as e: self.log.info('can\' t load remote certificate :{}'.format(str(e))) return (1, str(e)) certFileName = "{}.crt".format(self.host) certFilePath = utils.joinFilePath(self.settings.certificates.certdirs, certFileName) try: with open(certFilePath, 'w') as f: f.write(cert) except Exception as e: self.log.info( 'can\' t save remote certificate on local :{}'.format(str(e))) return (1, str(e)) else: self.log.info('load and save remote server cert successd') return (0, 'ok')
def createSslConttext(self): self.sslContext = ssl.create_default_context() certFileName = "{}.crt".format(self.host) certFilePath = utils.joinFilePath(self.settings.certificates.certdirs, certFileName) print('fuck1') if not utils.checkFileExists(certFilePath): # get remote certificates self.acquire_remote_cert() try: # verify_cert utils.verify_cert(certFilePath, self.host) except Exception as e: self.log.error(str(e)) return (1, str(e)) print('fuck2') try: self.sslContext.load_verify_locations(certFilePath) except Exception as e: self.log.error(str(e)) return (1, str(e))
def main(): # currentPath = os.path.dirname(os.path.realpath(__file__)) # utils.setenv('COWRY_ROOT', currentPath) # utils.addAppPath(currentPath) cmd = 'start' if args.config: defaultConfigPath = args.config if utils.checkFileExists(defaultConfigPath): utils.setenv('COWRY_CONFIG', defaultConfigPath) currentPath = os.path.dirname(os.path.realpath(defaultConfigPath)) utils.setenv('COWRY_ROOT', currentPath) else: currentPath = os.path.dirname(os.path.realpath(__file__)) utils.setenv('COWRY_ROOT', currentPath) defaultConfigPath = utils.joinFilePath(currentPath, 'cowry.conf') utils.setenv('COWRY_CONFIG', defaultConfigPath) if args.new: cmd = 'new' if args.drop: cmd = 'drop' if args.quiet: utils.setenv('COWRY_STATUS', 'NO') else: utils.setenv('COWRY_STATUS', 'YES') if args.webconsole: utils.setenv('COWRY_WEB_CONSOLE', 'YES') else: utils.setenv('COWRY_WEB_CONSOLE', 'NO') server = Server() getattr(server, cmd)()
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 download(self): # recv info code {'info': 'download', 'code': '', 'filename': downloadFileName} downloadFileHash = self.recvInfo['filehash'] # downloadFileType = self.recvInfo['type'] # baseFileName, postfix = utils.seperateFileName(downloadFileName) # downloadFileSize = self.recvInfo['filesize'] # currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) # to do # to determeine whether have repeat value in db try: fileInfo = self.session.query(self.file).filter( or_( and_(self.file.uid == self.userid, self.file.hashcode == downloadFileHash), and_(self.file.hashcode == downloadFileHash, self.file.public == 1))).all() # self.session.add(self.file(uid= self.userid, name= downloadFileName, size= downloadFileSize, hashcode= downloadFileHashCode,updatetime= currentTime, postfix= postfix)) except Exception as e: remsg = { 'info': 'download', 'code': self.recvInfo['code'], 'status': '1', 'reason': str(e) } self.sendMsg(remsg) else: self.log.info('search file has : {}\'s'.format(len(fileInfo))) if len(fileInfo) == 1: fileInfo = fileInfo[0] elif len(fileInfo) >= 2: fileInfo = fileInfo[0] else: remsg = { 'info': 'download', 'code': self.recvInfo['code'], 'status': '1', 'reason': 'can\'t find download file' } retInfo = self.sendMsg(remsg) authToken = utils.generateAuthToken() if self.settings.default.cluster == '1': data_channel_info = ('127.0.0.1', 2334) self.r.set(authToken, 0) else: retInfo = self.createDataSock() #return (int, tuple(ip,port)) if retInfo[0] == 1: self.log.info('createDataSock fails: {}'.format( retInfo[1])) data_channel_info = (self.settings.server.bind_address, retInfo[1]) fileInfo = fileInfo.__dict__ del fileInfo['_sa_instance_state'] remsg = { 'info': 'download', 'code': self.recvInfo['code'], 'status': '0', 'token': authToken, 'dataAddress': data_channel_info, 'fileinfo': fileInfo } retInfo = self.sendMsg(remsg) if retInfo[0] == 1: self.log.info('sendMsg fails: {}'.format(retInfo[1])) elif self.settings.default.cluster != '1': downloadFilePath = utils.joinFilePath( self.settings.storage.datapath, fileInfo['hashcode']) self.downloadProcess = Download(self.sslContext, self.dataSocket, downloadFilePath, authToken) self.downloadProcess.start()
import gunicorn.workers.ggevent from gunicorn.app.wsgiapp import run PROJECT_PATH = os.path.dirname(sys.argv[1]) os.sys.path.append(PROJECT_PATH) from core import utils utils.setenv('COWRY_CONFIG', sys.argv[1]) utils.setenv('COWRY_ROOT', PROJECT_PATH) from core.config import Settings settings = Settings() ERROR_LOG = utils.joinFilePath(PROJECT_PATH, 'log/error.log') ACCESS_LOG = utils.joinFilePath(PROJECT_PATH, 'log/access.log') HOST = settings.webconsole.host PORT = settings.webconsole.port def number_of_workers(): return (multiprocessing.cpu_count() * 2) + 1 class StandaloneApplication(gunicorn.app.base.BaseApplication): def __init__(self, app, options=None): self.options = options or {} self.application = app super(StandaloneApplication, self).__init__()