Is it possible to use proxy or sshtunnel (Dynamic Port Forwarding) in uiwebview?
Forum Archive
proxy or sshtunnel (Dynamic Port Forwarding)
@tomomo, trying to understand what you are trying to do.
Creating an ssh tunnel, then opening a localhost page in WebView?
@mikael
Yes, I would like to access the sshtunnel or proxy on the jump server to connect to the intranet.
I also want to access the web site via the jump server in addition to the intranet access.
@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.
@mikael
Tried sshtunnel.
I was connected to the jump server, but I could not access the site via the jump server.
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')
@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.)
@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.
@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.