Exemplo n.º 1
0
    def loop(self):
        connected = Platform.rdpSessionIsConnected()
        while True:
            channelConnected = Platform.rdpSessionIsConnected()

            if connected and not channelConnected:
                # Client has disconnected
                self.vchannel.Close()
            elif channelConnected and not connected:
                # Client has reconnected
                self.vchannel.Open()
                self.vchannel.Write(OvdAppChannel.getInitPacket())
                for instance in self.im.instances:
                    self.vchannel.Write(OvdAppChannel.build_packet_ORDER_STARTED(instance[3], instance[1]))

            connected = channelConnected
            if not connected:
                time.sleep(0.5)
                continue

                # Read a complete packet
                # so we assume a maximum packet size is 2048
            packet = self.vchannel.Read(2048)
            if packet is None:
                print "error at read"
                time.sleep(0.5)
                continue

            (order, data) = OvdAppChannel.parse_packet(packet)
            if order is None:
                print "OvdAppChannel error: %s" % (data)

            if order == OvdAppChannel.ORDER_START:
                (token, app_id) = data

                print "recv startapp order %d %d" % (token, app_id)
                self.jobs.put((order, token, app_id))

            elif order == OvdAppChannel.ORDER_START_WITH_ARGS:
                (token, app_id, dir_type, share, path) = data

                if dir_type == OvdAppChannel.DIR_TYPE_SHARED_FOLDER:
                    dir_type2 = self.im.DIR_TYPE_SHARED_FOLDER
                elif dir_type == OvdAppChannel.DIR_TYPE_RDP_DRIVE:
                    dir_type2 = self.im.DIR_TYPE_RDP_DRIVE
                elif dir_type == OvdAppChannel.DIR_TYPE_KNOWN_DRIVES:
                    dir_type2 = self.im.DIR_TYPE_KNOWN_DRIVES
                elif dir_type == OvdAppChannel.DIR_TYPE_HTTP_URL:
                    dir_type2 = self.im.DIR_TYPE_HTTP_URL
                else:
                    print "Message ORDER_START_WITH_ARGS: unknown dir type %X" % (dir_type)
                    return

                print "recv startapp order %d %d %d %s %s" % (token, app_id, dir_type2, share, path)
                self.jobs.put((order, token, app_id, dir_type2, share, path))

            elif order == OvdAppChannel.ORDER_STOP:
                (token) = data

                print "recv stop order %d" % (token)
                self.jobs.put((order, token))

            elif order == OvdAppChannel.ORDER_EXIT:
                # logoff
                print "recv exit order"
                return
Exemplo n.º 2
0
    def loop(self):
        connected = Platform.rdpSessionIsConnected()
        while True:
            channelConnected = Platform.rdpSessionIsConnected()

            if connected and not channelConnected:
                # Client has disconnected
                self.vchannel.Close()
            elif channelConnected and not connected:
                # Client has reconnected
                self.vchannel.Open()
                self.vchannel.Write(OvdAppChannel.getInitPacket())
                for instance in self.im.instances:
                    self.vchannel.Write(
                        OvdAppChannel.build_packet_ORDER_STARTED(
                            instance[3], instance[1]))

            connected = channelConnected
            if not connected:
                time.sleep(0.5)
                continue

            # Read a complete packet
            # so we assume a maximum packet size is 2048
            packet = self.vchannel.Read(2048)
            if packet is None:
                print "error at read"
                time.sleep(0.5)
                continue

            (order, data) = OvdAppChannel.parse_packet(packet)
            if order is None:
                print "OvdAppChannel error: %s" % (data)

            if order == OvdAppChannel.ORDER_START:
                (token, app_id) = data

                print "recv startapp order %d %d" % (token, app_id)
                self.jobs.put((order, token, app_id))

            elif order == OvdAppChannel.ORDER_START_WITH_ARGS:
                (token, app_id, dir_type, share, path) = data

                if dir_type == OvdAppChannel.DIR_TYPE_SHARED_FOLDER:
                    dir_type2 = self.im.DIR_TYPE_SHARED_FOLDER
                elif dir_type == OvdAppChannel.DIR_TYPE_RDP_DRIVE:
                    dir_type2 = self.im.DIR_TYPE_RDP_DRIVE
                elif dir_type == OvdAppChannel.DIR_TYPE_KNOWN_DRIVES:
                    dir_type2 = self.im.DIR_TYPE_KNOWN_DRIVES
                elif dir_type == OvdAppChannel.DIR_TYPE_HTTP_URL:
                    dir_type2 = self.im.DIR_TYPE_HTTP_URL
                else:
                    print "Message ORDER_START_WITH_ARGS: unknown dir type %X" % (
                        dir_type)
                    return

                print "recv startapp order %d %d %d %s %s" % (
                    token, app_id, dir_type2, share, path)
                self.jobs.put((order, token, app_id, dir_type2, share, path))

            elif order == OvdAppChannel.ORDER_STOP:
                (token) = data

                print "recv stop order %d" % (token)
                self.jobs.put((order, token))

            elif order == OvdAppChannel.ORDER_EXIT:
                # logoff
                print "recv exit order"
                return
Exemplo n.º 3
0
                    self.vchannel.Write(OvdAppChannel.build_packet_ORDER_STOPPED(token))

            tokens = self.im.get_exited_instances()
            if tokens is not None:
                for token in tokens:
                    self.vchannel.Write(OvdAppChannel.build_packet_ORDER_STOPPED(token))

            if job is None and len(tokens) == 0:
                time.sleep(0.1)

            t1 = time.time()
            t_init += t1 - t0
            if t_init > 5:
                # We send channel init time to time to manage the reconnection
                self.vchannel.Write(OvdAppChannel.getInitPacket())

                if self.use_known_drives and self.drives.rebuild():
                    self.vchannel.Write(OvdAppChannel.getDrivesMessage(self.drives.getListUID()))

                t_init = 0

    def stop(self):
        if self.isAlive():
            self._Thread__stop()

        t0 = time.time()
        self.im.kill_all_apps()
        while self.im.has_running_instances():
            if time.time() - t0 > 20:
                print "Still running instances after 20 seconds, exiting anyway ..."
Exemplo n.º 4
0
                        OvdAppChannel.build_packet_ORDER_STOPPED(token))

            tokens = self.im.get_exited_instances()
            if tokens is not None:
                for token in tokens:
                    self.vchannel.Write(
                        OvdAppChannel.build_packet_ORDER_STOPPED(token))

            if job is None and len(tokens) == 0:
                time.sleep(0.1)

            t1 = time.time()
            t_init += (t1 - t0)
            if t_init > 5:
                # We send channel init time to time to manage the reconnection
                self.vchannel.Write(OvdAppChannel.getInitPacket())

                if self.use_known_drives and self.drives.rebuild():
                    self.vchannel.Write(
                        OvdAppChannel.getDrivesMessage(
                            self.drives.getListUID()))

                t_init = 0

    def stop(self):
        if self.isAlive():
            self._Thread__stop()

        t0 = time.time()
        self.im.kill_all_apps()
        while self.im.has_running_instances():