def test_connect_fileserver(self): if "NGROK_AUTHTOKEN" not in os.environ: self.skipTest("NGROK_AUTHTOKEN environment variable not set") # GIVEN self.assertEqual(len(process._current_processes.keys()), 0) pyngrok_config = PyngrokConfig( config_path=conf.DEFAULT_NGROK_CONFIG_PATH, auth_token=os.environ["NGROK_AUTHTOKEN"]) # WHEN url = ngrok.connect("file:///", pyngrok_config=pyngrok_config) current_process = ngrok.get_ngrok_process() time.sleep(1) tunnels = ngrok.get_tunnels() # THEN self.assertEqual(len(tunnels), 2) self.assertIsNotNone(current_process) self.assertIsNone(current_process.proc.poll()) self.assertTrue(current_process._monitor_thread.is_alive()) self.assertIsNotNone(url) self.assertIsNotNone(process.get_process(self.pyngrok_config)) self.assertIn('http://', url) self.assertEqual(len(process._current_processes.keys()), 1) # WHEN ngrok.disconnect(url) time.sleep(1) tunnels = ngrok.get_tunnels() # THEN # There is still one tunnel left, as we only disconnected the http tunnel self.assertEqual(len(tunnels), 1)
def ngrokDisconnect(update: Update, context: CallbackContext) -> None: if not checkId(update.message.chat_id): return update.message.reply_text("There are " + str(len(ngrok.get_tunnels())) + " open tunnel(s)") ngrok.disconnect(tunnel.public_url) update.message.reply_text( str(len(ngrok.get_tunnels())) + " tunnel(s) left open")
def disconnect_tunnel(): tunnels = ngrok.get_tunnels() public_url = (tunnels.split( "NgrokTunnel: ", maxsplit=1)[-1].split(maxsplit=1)[0].strip('"')) ngrok.disconnect(public_url) ngrok.kill() tunnels_check = ngrok.get_tunnels() message = ("\nInitial tunnels: " + str(tunnels) + "\nFinal tunnels: " + str(tunnels_check)) return message
def __init__(self, threadID, name): QtCore.QThread.__init__(self, parent=None) self.threadID = threadID self.name = name if ngrok.get_tunnels() == []: ngrok.connect(port="22220") tunnels = ngrok.get_tunnels() if tunnels[0].public_url.find("https") == -1: self.url_callback = tunnels[1].public_url + "/twitter/webhooks" else: self.url_callback = tunnels[0].public_url + "/twitter/webhooks" self.readCredentials()
def delete_tunnels(self): try: for tunnel in ngrok.get_tunnels(): ngrok.disconnect(tunnel.public_url) if not ngrok.get_tunnels(): return 'All active Ngrok tunnels delete successfully!' return 'Something went wrong deleting the Ngrok tunnels!' except Exception as e: logger.exception(e) return self.error.format(e)
def ngrokConnect(update: Update, context: CallbackContext) -> None: if not checkId(update.message.chat_id): return global tunnel if len(ngrok.get_tunnels()) == 1: msg = "Already connected at: " + str(tunnel.public_url) update.message.reply_text(msg) elif len(ngrok.get_tunnels()) > 1: update.message.reply_text("Error! Multiple tunnels running!") else: conf.get_default().region = "eu" tunnel = ngrok.connect(4000, 'tcp', region="eu") process = ngrok.get_ngrok_process() update.message.reply_text("Connected at " + tunnel.public_url)
def get_tunnels(self): try: return str(ngrok.get_tunnels()) except Exception as e: logger.exception(e) return self.error.format(e)
def _start_server(self): active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) url = ngrok.connect(port=self.port, options={"bind_tls": True}) print(f"Code Server can be accessed on: {url}")
def test_api_request_delete_data_updated(self): # GIVEN current_process = ngrok.get_ngrok_process(pyngrok_config=self.pyngrok_config) ngrok.connect() time.sleep(1) tunnels = ngrok.get_tunnels() self.assertEqual(len(tunnels), 2) # WHEN response = ngrok.api_request("{}{}".format(current_process.api_url, tunnels[0].uri.replace("+", "%20")), "DELETE") # THEN self.assertIsNone(response) tunnels = ngrok.get_tunnels() self.assertEqual(len(tunnels), 1)
def test_disconnect(self): # GIVEN url = ngrok.connect(pyngrok_config=self.pyngrok_config) time.sleep(1) tunnels = ngrok.get_tunnels() # Two tunnels, as one each was created for "http" and "https" self.assertEqual(len(tunnels), 2) # WHEN ngrok.disconnect(url) time.sleep(1) tunnels = ngrok.get_tunnels() # THEN # There is still one tunnel left, as we only disconnected the http tunnel self.assertEqual(len(tunnels), 1)
def _init_ngrok(app): """Initialize ngrok if desired for development environment""" if app.config.get("ENV") == "development" and \ os.environ.get("USE_NGROK", "False") == "True": # pyngrok will only be installed, and should only ever be initialized, in a dev environment from pyngrok import ngrok # Create the ngrok tunnel on the first run of the app if os.environ.get("WERKZEUG_RUN_MAIN") != "true": # Get the dev server port (defaults to 5000 for Flask, can be overridden with `--port` # when starting the server port = sys.argv[sys.argv.index("--port") + 1] if "--port" in sys.argv else 5000 # Open a ngrok tunnel to the dev server public_url = ngrok.connect(port).public_url print(" * ngrok tunnel \"{}\" -> \"http://127.0.0.1:{}\"".format( public_url, port)) # Retrieve the ngrok public url upon reloads and save to app config else: public_url = ngrok.get_tunnels()[0].public_url # Save the public url to the app config app.config["PUBLIC_URL"] = public_url
def test_connect_fileserver(self): if "NGROK_AUTHTOKEN" not in os.environ: self.skipTest("NGROK_AUTHTOKEN environment variable not set") # GIVEN self.assertEqual(len(process._current_processes.keys()), 0) pyngrok_config = PyngrokConfig(config_path=conf.DEFAULT_NGROK_CONFIG_PATH, auth_token=os.environ["NGROK_AUTHTOKEN"]) # WHEN ngrok_tunnel = ngrok.connect("file:///", pyngrok_config=pyngrok_config) current_process = ngrok.get_ngrok_process() time.sleep(1) tunnels = ngrok.get_tunnels() # THEN self.assertEqual(len(tunnels), 2) self.assertIsNotNone(current_process) self.assertIsNone(current_process.proc.poll()) self.assertTrue(current_process._monitor_thread.is_alive()) self.assertTrue(ngrok_tunnel.name.startswith("http-file-")) self.assertEqual("file:///", ngrok_tunnel.config["addr"]) self.assertIsNotNone(ngrok_tunnel.public_url) self.assertIsNotNone(process.get_process(self.pyngrok_config)) self.assertIn('http://', ngrok_tunnel.public_url) self.assertEqual(len(process._current_processes.keys()), 1)
async def ngrokKapat(client, message): # < Başlangıç uyku = await message.reply("__asyncio.sleep(0.3)__") await asyncio.sleep(0.3) cevaplanan_mesaj = message.reply_to_message if cevaplanan_mesaj is None: yanitlanacak_mesaj = message.message_id else: yanitlanacak_mesaj = cevaplanan_mesaj.message_id await uyku.delete() ilk_mesaj = await message.reply("__Bekleyin..__", reply_to_message_id=yanitlanacak_mesaj, disable_web_page_preview=True, parse_mode="Markdown") #------------------------------------------------------------- Başlangıç > if message.from_user.id != bilgiler['kurucu']: await ilk_mesaj.edit( f"Admin değilmişim :)\n\n`{message.from_user.id}` __!=__ `{bilgiler['kurucu']}`" ) return tuneller = ngrok.get_tunnels() kapatildi = '' for tunel in range(len(tuneller)): kapatildi += f"`{tuneller[tunel].public_url}`\n" ngrok.kill() await ilk_mesaj.edit( f"**{kullanici_adi}** __oturumunda__\n\n{kapatildi}__kapatıldı__")
def stop_tunnel(self): """ Kill the current running ngrok tunnels """ if self.tunnel is None: return for tunnel in ngrok.get_tunnels(): ngrok.disconnect(tunnel.public_url) self.tunnel = None
def test_bind_tls_http_only(self): # WHEN url = ngrok.connect(bind_tls=False, pyngrok_config=self.pyngrok_config).public_url num_tunnels = len(ngrok.get_tunnels()) # THEN self.assertTrue(url.startswith("http")) self.assertEqual(num_tunnels, 1)
def ngrokIp(update: Update, context: CallbackContext) -> None: if not checkId(update.message.chat_id): return if len(ngrok.get_tunnels()) == 0: update.message.reply_text("No connections") else: update.message.reply_text(tunnel.public_url)
def get_tunnels(self): """ Get the list of active ``ngrok`` tunnels. :return: .. schema:: ngrok.NgrokTunnelSchema(many=True) """ from pyngrok import ngrok tunnels = ngrok.get_tunnels() return NgrokTunnelSchema().dump(tunnels, many=True)
def get_public_url(): previous_urls = ngrok.get_tunnels() for i in previous_urls: ngrok.disconnect(i.public_url) url = ngrok.connect(port=5000) url = url.replace('http', 'https') return url
def _start_server(self): active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) url = ngrok.connect(addr=self.port, options={"bind_tls": True}, return_ngrok_tunnel=True) print(f'Web App can be accessed on: {url.public_url}')
def _start_ngrok_server(self): if self.authtoken: ngrok.set_auth_token(self.authtoken) active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) url = ngrok.connect(addr=self.port, options={"bind_tls": True}) return url
def get_ngrok_address(): tunnels = ngrok.get_tunnels() for tunnel in tunnels: if tunnel.proto == 'https': print( f'Ngrok address: {tunnel.public_url} was copied to clipboard\n' ) clipboard.copy(tunnel.public_url) return tunnel.public_url return None
def _start_server(self): if self.authtoken: ngrok.set_auth_token(self.authtoken) active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) url = ngrok.connect(addr=self.port, options={"bind_tls": True}) print(f"Code Server can be accessed on: {url}") self.url = url
def disconnect(self): if self.option == "localtunnel": try: self.connection.kill() except: pass elif self.option == "ngrok": active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url)
def _start_server(self): if self.authtoken: ngrok.set_auth_token(self.authtoken) active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) NgrokTunnel = ngrok.connect(addr=self.port, options={"bind_tls": True}) https_url = self._get_https_url(str(NgrokTunnel)) print(f'\n\nopen code server via https: {https_url}\n\n') print(f"Code Server can be accessed on: {NgrokTunnel}")
def start(): wh.update("No experiment right now. <br> How's it going anyway?",100) os.chdir('C:\\Users\\lvbt\\Documents') # Open a HTTP tunnel on the default port 80 # <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://*****:*****@gmail.com','TP-Exp-'+dt) os.system('python -m http.server 80')
def get_public_url(path: str = None, use_ngrok: bool = True): """Returns a public accessible url of a site using ngrok. """ if frappe.conf.developer_mode and use_ngrok: tunnels = ngrok.get_tunnels() if tunnels: domain = tunnels[0].public_url else: port = frappe.conf.http_port or frappe.conf.webserver_port domain = ngrok.connect(port) return '/'.join(map(lambda x: x.strip('/'), [domain, path or ''])) return get_url(path)
def _start_server(self): if self.authtoken: ngrok.set_auth_token(self.authtoken) active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) url = ngrok.connect(addr=self.port, bind_tls=True) if self._code: print(f"Code Server can be accessed on: {url}") else: print(f"Public URL: {url}")
def test_api_get_request_success(self): # GIVEN current_process = ngrok.get_ngrok_process(pyngrok_config=self.pyngrok_config) ngrok.connect() time.sleep(1) tunnel = ngrok.get_tunnels()[0] # WHEN response = ngrok.api_request("{}{}".format(current_process.api_url, tunnel.uri.replace("+", "%20")), "GET") # THEN self.assertEqual(tunnel.name, response["name"])
def _start_server(self): conf.get_default().region = self.region if self.authtoken: ngrok.set_auth_token(self.authtoken) active_tunnels = ngrok.get_tunnels() for tunnel in active_tunnels: public_url = tunnel.public_url ngrok.disconnect(public_url) url = ngrok.connect(addr=self.port, options={"bind_tls": True}) if self._code: print(f"Code Server can be accessed on: {url}") else: print(f"Public URL: {url}")
def test_disconnect_fileserver(self): if "NGROK_AUTHTOKEN" not in os.environ: self.skipTest("NGROK_AUTHTOKEN environment variable not set") # GIVEN self.assertEqual(len(process._current_processes.keys()), 0) pyngrok_config = PyngrokConfig( config_path=conf.DEFAULT_NGROK_CONFIG_PATH, auth_token=os.environ["NGROK_AUTHTOKEN"]) url = ngrok.connect("file:///", pyngrok_config=pyngrok_config) time.sleep(1) tunnel = ngrok.get_tunnels()[0] api_url = ngrok.get_ngrok_process(pyngrok_config).api_url # WHEN ngrok.disconnect(url) time.sleep(1) tunnels = ngrok.get_tunnels() # THEN # There is still one tunnel left, as we only disconnected the http tunnel self.assertEqual(len(tunnels), 1)