2020-08-23 02:40:35 +08:00
|
|
|
from pyngrok import ngrok
|
|
|
|
from pyngrok import exception as pyngrok_exceptions
|
|
|
|
from pyngrok import installer as pyngrok_installer
|
|
|
|
from pyngrok import conf as pyngrok_config
|
|
|
|
|
|
|
|
|
|
|
|
class NgrokController:
|
|
|
|
def __init__(self, config_path: str = ".config/ngrok.yml", model=ngrok, exceptions=pyngrok_exceptions, installer=pyngrok_installer, config=pyngrok_config):
|
|
|
|
self._model = model
|
|
|
|
self._exceptions = exceptions
|
|
|
|
self._installer = installer
|
|
|
|
self._config = config
|
|
|
|
self._config_path = config_path
|
|
|
|
self._tunnels = None
|
|
|
|
self._ngrok_url = None
|
|
|
|
|
2020-08-23 02:41:24 +08:00
|
|
|
def close_latest_connection(self):
|
|
|
|
try:
|
|
|
|
self._model.disconnect(self._ngrok_url)
|
|
|
|
except self._exceptions.PyngrokError:
|
|
|
|
print("Can't find any latest connections.") # FIXME replace with View entry
|
|
|
|
pass
|
2020-08-23 02:41:50 +08:00
|
|
|
|
|
|
|
def maintain_default_config(self):
|
2020-08-23 02:42:17 +08:00
|
|
|
self._installer.install_default_config(self._config_path)
|
|
|
|
|
|
|
|
|
|
|
|
def activate_config_path(self):
|
2020-08-23 02:42:33 +08:00
|
|
|
self._config.PyngrokConfig(config_path=self._config_path)
|
|
|
|
|
|
|
|
def establish_connection(self, port='80'):
|
2020-08-23 02:42:52 +08:00
|
|
|
self._model.connect(port=port, name='HiddenEye Connection', pyngrok_config=self._config_path)
|
|
|
|
|
|
|
|
def obtain_tunnels(self):
|
|
|
|
self._tunnels = self._model.get_tunnels()
|