Exemple #1
0
    def connect(self, message, id):
        self.message.reply_channel.send({"accept": True})
        client = GuacamoleClient(settings.GUACD_HOST, settings.GUACD_PORT)
        try:
            data = ServerInfor.objects.get(id=id)
            if data.credential.protocol in ['vnc', 'rdp', 'telnet']:
                pass
            else:
                self.message.reply_channel.send({"accept": False})
        except ObjectDoesNotExist:
            #server info not exist
            self.message.reply_channel.send({"accept": False})
        client.handshake(protocol=data.credential.protocol,
                         hostname=data.ip,
                         port=data.credential.port,
                         username=data.credential.username,
                         password=data.credential.password)
        #security='any',)
        cache_key = str(uuid.uuid4())
        self.message.reply_channel.send(
            {"text": '0.,{0}.{1};'.format(len(cache_key), cache_key)},
            immediately=True)
        #'0.,36.83940151-b2f9-4743-b5e4-b6eb85a97743;'

        guacamolethread = GuacamoleThread(self.message, client)
        guacamolethread.setDaemon = True
        guacamolethread.start()

        guacamolethreadwrite = GuacamoleThreadWrite(self.message, client)
        guacamolethreadwrite.setDaemon = True
        guacamolethreadwrite.start()
Exemple #2
0
    def connect(self, message, id):
        self.message.reply_channel.send({"accept": True})
        if not self.authenticate:
            self.message.reply_channel.send(
                {
                    "text":
                    json.dumps({
                        'status': False,
                        'message': 'You must login to the system!'
                    })
                },
                immediately=True)
            self.message.reply_channel.send({"accept": False})
        else:
            #permission auth
            if not self.haspermission('common.can_monitor_serverinfo'):
                self.message.reply_channel.send(
                    {
                        "text":
                        json.dumps({
                            'status':
                            False,
                            'message':
                            'You have not permission to monitor user action!'
                        })
                    },
                    immediately=True)
                self.message.reply_channel.send({"accept": False})

            client = GuacamoleClient(settings.GUACD_HOST, settings.GUACD_PORT)
            log_object = Log.objects.get(id=id)
            cache_key = str(log_object.gucamole_client_id)

            data = log_object.server

            #draft version for real time monitor
            client.send_instruction(Instruction('select', cache_key))
            instruction = client.read_instruction()
            kwargs = {'width': 1024, 'height': 768, 'read_only': 'true'}
            connection_args = [
                kwargs.get(arg.replace('-', '_'), '')
                for arg in instruction.args
            ]
            client.send_instruction(Instruction('size', 1024, 768, 96))
            client.send_instruction(Instruction('audio', *list()))
            client.send_instruction(Instruction('video', *list()))
            client.send_instruction(Instruction('image', *list()))
            client.send_instruction(Instruction('connect', *connection_args))

            #self.message.reply_channel.send({"text":'0.,{0}.{1};'.format(len(cache_key),cache_key)},immediately=True)
            guacamolethread = GuacamoleThread(self.message, client)
            guacamolethread.setDaemon = True
            guacamolethread.start()

            guacamolethreadwrite = GuacamoleThreadWrite(self.message, client)
            guacamolethreadwrite.setDaemon = True
            guacamolethreadwrite.start()
Exemple #3
0
    def connect(self, message, id):
        self.message.reply_channel.send({"accept": True})
        client = GuacamoleClient(settings.GUACD_HOST, settings.GUACD_PORT)
        try:
            data = ServerInfor.objects.get(id=id)
            if data.credential.protocol in ['vnc', 'rdp', 'telnet']:
                pass
            else:
                self.message.reply_channel.send({"accept": False})
        except ObjectDoesNotExist:
            #server info not exist
            self.message.reply_channel.send({"accept": False})
        cache_key = str(uuid.uuid4())

        directory_date_time = now()
        recording_path = os.path.join(
            MEDIA_ROOT, '{0}-{1}-{2}'.format(directory_date_time.year,
                                             directory_date_time.month,
                                             directory_date_time.day))

        client.handshake(
            width=data.credential.width,
            height=data.credential.height,
            protocol=data.credential.protocol,
            hostname=data.ip,
            port=data.credential.port,
            username=data.credential.username,
            password=data.credential.password,
            recording_path=recording_path,
            recording_name=cache_key,
            create_recording_path='true',
            enable_wallpaper='true',
            ignore_cert='true',
        )
        #security='tls',)
        self.message.reply_channel.send(
            {"text": '0.,{0}.{1};'.format(len(cache_key), cache_key)},
            immediately=True)
        #'0.,36.83940151-b2f9-4743-b5e4-b6eb85a97743;'

        audit_log = Log.objects.create(
            user=User.objects.get(username=self.message.user),
            server=data,
            channel=self.message.reply_channel.name,
            width=data.credential.width,
            height=data.credential.height,
            log=cache_key)
        audit_log.save()
        guacamolethread = GuacamoleThread(self.message, client)
        guacamolethread.setDaemon = True
        guacamolethread.start()

        guacamolethreadwrite = GuacamoleThreadWrite(self.message, client)
        guacamolethreadwrite.setDaemon = True
        guacamolethreadwrite.start()
Exemple #4
0
    def connect(self, message):
        self.message.reply_channel.send({"accept": True})
        client = GuacamoleClient(settings.GUACD_HOST, settings.GUACD_PORT)
        client.handshake(protocol='rdp',
                         hostname=settings.SSH_HOST,
                         port=settings.SSH_PORT,
                         username=settings.SSH_USER,
                         password=settings.SSH_PASSWORD)
                         #security='any',)
        cache_key = str(uuid.uuid4())
        self.message.reply_channel.send({"text":'0.,{0}.{1};'.format(len(cache_key),cache_key)},immediately=True)
       #'0.,36.83940151-b2f9-4743-b5e4-b6eb85a97743;'

        guacamolethread=GuacamoleThread(self.message,client)
        guacamolethread.setDaemon = True
        guacamolethread.start()

        guacamolethreadwrite=GuacamoleThreadWrite(self.message,client)
        guacamolethreadwrite.setDaemon = True
        guacamolethreadwrite.start()
Exemple #5
0
    def connect(self, message, id):
        self.message.reply_channel.send({"accept": True})
        if not self.authenticate:
            self.message.reply_channel.send(
                {
                    "text":
                    json.dumps({
                        'status': False,
                        'message': 'You must login to the system!'
                    })
                },
                immediately=True)
            self.message.reply_channel.send({"accept": False})
        else:
            client = GuacamoleClient(settings.GUACD_HOST, settings.GUACD_PORT)
            log_object = Log.objects.get(id=id)
            cache_key = str(log_object.gucamole_client_id)

            data = log_object.server
            print 'cache_key', cache_key
            client.handshake(
                width=data.credential.width,
                height=data.credential.height,
                protocol=data.credential.protocol,
                hostname=data.ip,
                port=data.credential.port,
                username=data.credential.username,
                password=data.credential.password,
                read_only=True,
            )

            client.send_instruction(Instruction('select', cache_key))
            #self.message.reply_channel.send({"text":'0.,{0}.{1};'.format(len(cache_key),cache_key)},immediately=True)
            guacamolethread = GuacamoleThread(self.message, client)
            guacamolethread.setDaemon = True
            guacamolethread.start()

            guacamolethreadwrite = GuacamoleThreadWrite(self.message, client)
            guacamolethreadwrite.setDaemon = True
            guacamolethreadwrite.start()
    def connect(self, message, id):
        self.message.reply_channel.send({"accept": True})
        user = get_redis_instance().get(id)
        if not self.authenticate(id):
            self.message.reply_channel.send({"text": json.dumps(
                {'status': False, 'message': 'You must login to the system!'})}, immediately=True)
            self.message.reply_channel.send({"accept": False})
        else:
            # permission auth
            username = get_redis_instance().get(id)
            try:
                Permission.objects.get(
                    user__username=username, groups__servers__id=int(id[-1]))
            except ObjectDoesNotExist:
                self.message.reply_channel.send({"text": json.dumps(
                    '\033[1;3;31mYou have not permission to connect server !\033[0m')}, immediately=True)
                self.message.reply_channel.send({"accept": False})
                return
            except MultipleObjectsReturned:
                pass
            client = GuacamoleClient(
                settings.GUACD_HOST, settings.GUACD_PORT)
            try:
                data = ServerInfor.objects.get(id=int(id[-1]))
                if data.credential.protocol in ['vnc', 'rdp', 'telnet']:
                    pass
                else:
                    self.message.reply_channel.send({"accept": False})
            except ObjectDoesNotExist:
                # server info not exist
                self.message.reply_channel.send({"accept": False})
            cache_key = str(uuid.uuid4())
            directory_date_time = now()
            recording_path = os.path.join(MEDIA_ROOT, '{0}-{1}-{2}'.format(
                directory_date_time.year, directory_date_time.month, directory_date_time.day))

            if isinstance(username, bytes):
                username = username.decode()
            drive_path = os.path.join(MEDIA_ROOT, str(username), 'Download')
            """
            Create recording media file and drive path
            """
            mkdir_p(recording_path)
            mkdir_p(drive_path)

            try:
                client.handshake(width=data.credential.width,
                                 height=data.credential.height,
                                 protocol=data.credential.protocol,
                                 hostname=data.ip,
                                 port=data.credential.port,
                                 username=data.credential.username,
                                 password=data.credential.password,
                                 recording_path=recording_path,
                                 recording_name=cache_key,
                                 create_recording_path='true',
                                 enable_wallpaper='true',
                                 ignore_cert='true',
                                 enable_drive='true',
                                 drive_path=drive_path,
                                 create_drive_path='true',
                                 security=data.credential.security,
                                 # console_audio='true',
                                 # enable_audio_input='true',
                                 # disable_audio='false',
                                 # console='true',
                                 enable_full_window_drag='true',
                                 resize_method="reconnect"  # display-update
                                 )
            except Exception as e:
                print(e)
                print(traceback.print_exc())
                self.message.reply_channel.send({"accept": False})
                return
            self.message.reply_channel.send(
                {"text": '0.,{0}.{1};'.format(len(cache_key), cache_key)}, immediately=True)

            audit_log = Log.objects.create(user=User.objects.get(username=username), server=data, channel=self.message.reply_channel.name,
                                           width=data.credential.width, height=data.credential.height, log=cache_key, gucamole_client_id=client._id)
            audit_log.save()
            guacamolethread = GuacamoleThread(self.message, client)
            guacamolethread.setDaemon = True
            guacamolethread.start()

            guacamolethreadwrite = GuacamoleThreadWrite(self.message, client)
            guacamolethreadwrite.setDaemon = True
            guacamolethreadwrite.start()
Exemple #7
0
    def connect(self, message, id):
        self.message.reply_channel.send({"accept": True})
        if not self.authenticate:
            self.message.reply_channel.send(
                {
                    "text":
                    json.dumps({
                        'status': False,
                        'message': 'You must login to the system!'
                    })
                },
                immediately=True)
            self.message.reply_channel.send({"accept": False})
        else:
            #permission auth
            try:
                Permission.objects.get(
                    user__username=self.message.user.username,
                    groups__servers__id=id)
            except ObjectDoesNotExist:
                self.message.reply_channel.send(
                    {
                        "text":
                        json.dumps(
                            '\033[1;3;31mYou have not permission to connect server !\033[0m'
                        )
                    },
                    immediately=True)
                self.message.reply_channel.send({"accept": False})
                return
            client = GuacamoleClient(settings.GUACD_HOST, settings.GUACD_PORT)
            try:
                data = ServerInfor.objects.get(id=id)
                if data.credential.protocol in ['vnc', 'rdp', 'telnet']:
                    pass
                else:
                    self.message.reply_channel.send({"accept": False})
            except ObjectDoesNotExist:
                #server info not exist
                self.message.reply_channel.send({"accept": False})
            cache_key = str(uuid.uuid4())

            directory_date_time = now()
            recording_path = os.path.join(
                MEDIA_ROOT, '{0}-{1}-{2}'.format(directory_date_time.year,
                                                 directory_date_time.month,
                                                 directory_date_time.day))
            drive_path = os.path.join(MEDIA_ROOT, self.message.user.username)
            """
            Create recording media file and drive path
            """
            mkdir_p(recording_path)
            mkdir_p(drive_path)

            try:
                client.handshake(width=data.credential.width,
                                 height=data.credential.height,
                                 protocol=data.credential.protocol,
                                 hostname=data.ip,
                                 port=data.credential.port,
                                 username=data.credential.username,
                                 password=data.credential.password,
                                 recording_path=recording_path,
                                 recording_name=cache_key,
                                 create_recording_path='true',
                                 enable_wallpaper='true',
                                 ignore_cert='true',
                                 enable_drive='true',
                                 drive_path=drive_path,
                                 create_drive_path='true')
                #security='tls',)
            except Exception:
                self.message.reply_channel.send({"accept": False})
                return

            self.message.reply_channel.send(
                {"text": '0.,{0}.{1};'.format(len(cache_key), cache_key)},
                immediately=True)

            audit_log = Log.objects.create(
                user=User.objects.get(username=self.message.user),
                server=data,
                channel=self.message.reply_channel.name,
                width=data.credential.width,
                height=data.credential.height,
                log=cache_key,
                gucamole_client_id=client._id)
            audit_log.save()
            guacamolethread = GuacamoleThread(self.message, client)
            guacamolethread.setDaemon = True
            guacamolethread.start()

            guacamolethreadwrite = GuacamoleThreadWrite(self.message, client)
            guacamolethreadwrite.setDaemon = True
            guacamolethreadwrite.start()