コード例 #1
0
ファイル: guacamole.py プロジェクト: shean023/ops
    def record(self):
        record_path = os.path.join(settings.MEDIA_ROOT, 'admin_guacamole_records', self.message.scope['user'].username,
                                   time.strftime('%Y-%m-%d'))
        if not os.path.exists(record_path):
            os.makedirs(record_path, exist_ok=True)
        record_file_name = '{}.{}.guac'.format(self.message.server_ip, time.strftime('%Y%m%d%H%M%S'))
        record_file_path = os.path.join(record_path, record_file_name)

        admin_file.delay(record_file_path, self.txt)

        login_status_time = time.time() - self.start_time
        if login_status_time >= 60:
            login_status_time = '{} m'.format(round(login_status_time / 60, 2))
        elif login_status_time >= 3600:
            login_status_time = '{} h'.format(round(login_status_time / 3660, 2))
        else:
            login_status_time = '{} s'.format(round(login_status_time))

        try:
            AdminRecord.objects.create(
                admin_login_user=self.message.scope['user'],
                admin_server=self.message.server_ip,
                admin_remote_ip=self.message.remote_ip,
                admin_start_time=self.current_time,
                admin_login_status_time=login_status_time,
                admin_record_file=record_file_path.split('media/')[1],
                admin_record_mode='guacamole'
            )
        except Exception as e:
            logging.getLogger().error('数据库添加用户操作记录失败,原因:{}'.format(e))
コード例 #2
0
    def record(self):
        record_path = os.path.join(settings.MEDIA_ROOT, self.chan.record_dir,
                                   self.chan.scope['user'].username,
                                   time.strftime('%Y-%m-%d'))
        if not os.path.exists(record_path):
            os.makedirs(record_path, exist_ok=True)
        record_file_name = '{}.{}.cast'.format(self.chan.ip,
                                               time.strftime('%Y%m%d%H%M%S'))
        record_file_path = os.path.join(record_path, record_file_name)

        header = {
            "version": 2,
            "width": self.chan.width,
            "height": self.chan.height,
            "timestamp": round(self.start_time),
            "title": "ssh",
            "env": {
                "TERM": os.environ.get('TERM'),
                "SHELL": os.environ.get('SHELL', '/bin/bash')
            },
        }

        login_status_time = self.format_time(time.time() - self.start_time)
        login_user = self.chan.scope['user']
        login_server = r'{}@{}'.format(self.chan.username, self.chan.ip)

        try:
            if login_user.is_superuser:
                admin_file.delay(record_file_path, self.stdout, header)
                AdminRecord.objects.create(
                    admin_login_user=login_user,
                    admin_server=login_server,
                    admin_remote_ip=self.chan.remote_ip,
                    admin_start_time=self.current_time,
                    admin_login_status_time=login_status_time,
                    admin_record_file=record_file_path.split('media/')[1],
                    admin_record_cmds='\n'.join(self.chan.cmd))
            else:
                fort_file.delay(record_file_path, self.stdout, header)
                FortRecord.objects.create(
                    login_user=login_user,
                    fort=login_server,
                    remote_ip=self.chan.remote_ip,
                    start_time=self.current_time,
                    login_status_time=login_status_time,
                    record_file=record_file_path.split('media/')[1],
                    record_cmds='\n'.join(self.chan.cmd))
        except Exception as e:
            fort_logger.error('数据库添加用户操作记录失败,原因:{}'.format(e))
コード例 #3
0
    def record(self):
        record_path = os.path.join(settings.MEDIA_ROOT, 'admin_ssh_records',
                                   self.chan.scope['user'].username,
                                   time.strftime('%Y-%m-%d'))
        if not os.path.exists(record_path):
            os.makedirs(record_path, exist_ok=True)
        record_file_name = '{}.{}.cast'.format(self.chan.host_ip,
                                               time.strftime('%Y%m%d%H%M%S'))
        record_file_path = os.path.join(record_path, record_file_name)

        header = {
            "version": 2,
            "width": self.chan.width,
            "height": self.chan.height,
            "timestamp": round(self.start_time),
            "title": "Demo",
            "env": {
                "TERM": os.environ.get('TERM'),
                "SHELL": os.environ.get('SHELL', '/bin/bash')
            },
        }

        admin_file.delay(record_file_path, self.stdout, header)

        login_status_time = time.time() - self.start_time
        if login_status_time >= 60:
            login_status_time = '{} m'.format(round(login_status_time / 60, 2))
        elif login_status_time >= 3600:
            login_status_time = '{} h'.format(
                round(login_status_time / 3660, 2))
        else:
            login_status_time = '{} s'.format(round(login_status_time))

        try:
            AdminRecord.objects.create(
                admin_login_user=self.chan.scope['user'],
                admin_server=self.chan.host_ip,
                admin_remote_ip=self.chan.remote_ip,
                admin_start_time=self.current_time,
                admin_login_status_time=login_status_time,
                admin_record_file=record_file_path.split('media/')[1])
        except Exception as e:
            logging.getLogger().error('数据库添加用户操作记录失败,原因:{}'.format(e))
コード例 #4
0
ファイル: guacamole.py プロジェクト: shean023/Ops-1
    def record(self):
        record_path = os.path.join(settings.MEDIA_ROOT,
                                   self.message.record_dir,
                                   self.message.scope['user'].username,
                                   time.strftime('%Y-%m-%d'))
        if not os.path.exists(record_path):
            os.makedirs(record_path, exist_ok=True)
        record_file_name = '{}.{}.guac'.format(self.message.ip,
                                               time.strftime('%Y%m%d%H%M%S'))
        record_file_path = os.path.join(record_path, record_file_name)

        login_status_time = self.format_time(time.time() - self.start_time)
        login_user = self.message.scope['user']
        login_server = r'{}@{}'.format(self.message.username, self.message.ip)

        try:
            if login_user.is_superuser:
                admin_file.delay(record_file_path, self.txt)
                AdminRecord.objects.create(
                    admin_login_user=login_user,
                    admin_server=login_server,
                    admin_remote_ip=self.message.remote_ip,
                    admin_start_time=self.current_time,
                    admin_login_status_time=login_status_time,
                    admin_record_file=record_file_path.split('media/')[1],
                    admin_record_mode='guacamole')
            else:
                fort_file.delay(record_file_path, self.txt)
                FortRecord.objects.create(
                    login_user=login_user,
                    fort=login_server,
                    remote_ip=self.message.remote_ip,
                    start_time=self.current_time,
                    login_status_time=login_status_time,
                    record_file=record_file_path.split('media/')[1],
                    record_mode='guacamole')
        except Exception as e:
            logging.getLogger().error('数据库添加用户操作记录失败,原因:{}'.format(e))