Forum Archive

proxy or sshtunnel (Dynamic Port Forwarding)

tomomo

Is it possible to use proxy or sshtunnel (Dynamic Port Forwarding) in uiwebview?

mikael

@tomomo, trying to understand what you are trying to do.

Creating an ssh tunnel, then opening a localhost page in WebView?

tomomo

@mikael
Yes, I would like to access the sshtunnel or proxy on the jump server to connect to the intranet.

tomomo

I also want to access the web site via the jump server in addition to the intranet access.

mikael

@tomomo, check out this convenient-looking sshtunnel module.

It is Python-only, installed cleanly and did not throw any errors before not connecting because I do not have a convenient SSH endpoint around.

tomomo

@mikael
Tried sshtunnel.
I was connected to the jump server, but I could not access the site via the jump server.

tomomo
from sshtunnel import SSHTunnelForwarder
import ui

server = SSHTunnelForwarder(
    '123.123.123.123',
    ssh_username='user',
    ssh_password='pass',
    remote_bind_address=('127.0.0.1',3128)
)
server.start()

main = ui.ScrollView(frame=(0, 0, 375, 812))
main.content_size = (375, 812)
wv = ui.WebView(frame=(0, 0, *main.content_size))
wv.load_url('http://10.10.10.254')
main.add_subview(wv)
main.present('panel')
mikael

@tomomo, I suggest you check your understanding of which sshtunnel address is which. Is your jump server address really 123.123.123.123? load_url should use 127.0.0.1, i.e. the local endpoint of the tunnel - you can use the local_bind_address to specify the port.

Also, would recommend the with ... as tunnel: format to manage the opening and closing of the tunnel.

(ScrollView is not needed, WebView can scroll on its own.)

tomomo

@mikael
123.123.123.123 is dummy ip address.
ssh username and password is dummy.

from sshtunnel import SSHTunnelForwarder
import ui

with SSHTunnelForwarder(
    'serveripaddress',
    ssh_username='user',
    ssh_password='pass',
    remote_bind_address=('127.0.0.1',80),
    local_bind_address=('127.0.0.1',80)
) as server:
    wv = ui.WebView()
    wv.load_url('http://127.0.0.1')
    #wv.load_url('https://www.google.co.jp')
    wv.present('panel')

I also put apache in the jump server for testing.

I tried to change the source code, but I was logged in with ssh.However, the ssh session seems to be closed immediately and the process will not continue.

mikael

@tomomo, present is not modal, so the context closes immediately after, closing the tunnel.

Adding wv.wait_modal() after it should wait until you close the view.