Exemple #1
0
    def test_as_dict(self):
        share = Share()
        share.account_id = 6
        share.key_id = 14
        share.local_port = 2022
        share.id = -1
        share.server_session_token = 'abcd'

        share.server = 'a.openport.io'
        share.server_port = 1234
        share.pid = 234
        share.active = True
        share.restart_command = ['restart', 'command']
        share.http_forward = True
        share.http_forward_address = 'http://jan.u.openport.io'
        share.open_port_for_ip_link = 'http//openport.io/l/1234/zerazer'

        share2 = Share().from_dict(share.as_dict())

        self.assertEquals(share.id, share2.id)
        self.assertEquals(share.server, share2.server)
        self.assertEquals(share.server_port, share2.server_port)
        self.assertEquals(share.pid, share2.pid)
        self.assertEquals(share.active, share2.active)
        self.assertEquals(share.account_id, share2.account_id)
        self.assertEquals(share.key_id, share2.key_id)
        self.assertEquals(share.local_port, share2.local_port)
        self.assertEquals(share.server_session_token,
                          share2.server_session_token)
        self.assertEquals(share.restart_command, share2.restart_command)
        self.assertEquals(share.http_forward, share2.http_forward)
        self.assertEquals(share.http_forward_address,
                          share2.http_forward_address)
        self.assertEquals(share.open_port_for_ip_link,
                          share2.open_port_for_ip_link)
Exemple #2
0
    def test_save_share(self):
        share = Share()
        share.account_id = 6
        share.key_id = 14
        share.local_port = 2022
        share.id = -1
        share.server_session_token = 'abcd'

        share.server = 'a.openport.io'
        share.server_port = 1234
        share.pid = 234
        share.active = True
        share.restart_command = ['restart', 'command']
        share.http_forward = True
        share.http_forward_address = 'http://jan.u.openport.io'
        share.app_management_port = 43122
        share.open_port_for_ip_link = 'http//openport.io/l/1234/zerazer'

        self.dbhandler.add_share(share)

        self.assertNotEqual(-1, share.id)

        share2 = self.dbhandler.get_share(share.id)

        self.assertEquals(share.id, share2.id)
        self.assertEquals(share.server, share2.server)
        self.assertEquals(share.server_port, share2.server_port)
        self.assertEquals(share.pid, share2.pid)
        self.assertEquals(share.active, share2.active)
        self.assertEquals(share.account_id, share2.account_id)
        self.assertEquals(share.key_id, share2.key_id)
        self.assertEquals(share.local_port, share2.local_port)
        self.assertEquals(share.server_session_token, share2.server_session_token)
        self.assertEquals(share.restart_command, share2.restart_command)
        self.assertEquals(share.http_forward, share2.http_forward)
        self.assertEquals(share.http_forward_address, share2.http_forward_address)
        self.assertEquals(share.app_management_port, share2.app_management_port)
        self.assertEquals(share.open_port_for_ip_link, share2.open_port_for_ip_link)
    def start(self):
        logger.debug("client pid:%s" % os.getpid())
        import argparse

        parser = argparse.ArgumentParser()
        self.add_default_arguments(parser, local_port_required=False)
        parser.add_argument("--file-token", default="", help="The token needed to download the file.")
        parser.add_argument("filename", help="The file you want to openport.")
        args = parser.parse_args()
        if args.no_gui:
            args.hide_message = True
            args.no_clipboard = True
        self.args = args

        def show_message_box(share):
            import wx

            wx.MessageBox(
                "You can now download your file(s) from %s\nThis link has been copied to your clipboard."
                % (share.get_link()),
                "Info",
                wx.OK | wx.ICON_INFORMATION,
            )

        def get_restart_command_for_share(share):
            command = self.get_restart_command(share)
            if not "--file-token" in command:
                command.extend(["--file-token", share.token])
            return command

        self.first_time = True

        def callback(ignore):
            #            global first_time
            if not self.first_time:
                return
            self.first_time = False

            share.restart_command = get_restart_command_for_share(share)
            if args.tray_port > 0:
                self.inform_tray_app_new(share, args.tray_port, start_tray=(not args.no_tray))

            share.error_observers.append(self.error_callback)
            share.success_observers.append(self.success_callback)

            if not args.no_clipboard:
                self.copy_share_to_clipboard(share)
            if args.hide_message:
                logger.info("Your file can be downloaded from %s" % share.get_link())
            else:
                self.show_message_box(share)

        share = Share()
        if args.file_token == "":
            share.token = crypt_service.get_token()
        else:
            share.token = args.file_token
        share.filePath = os.path.join(os.getcwd(), args.filename)
        share.server_port = args.request_port
        share.local_port = args.local_port
        share.server_session_token = args.request_token

        self.session = share
        self.open_port_file(share, callback)

        while True:
            sleep(1)