A package to expose your services to the internet using Ngrok
Project description
NgrokLinkify
A tool to expose your Ngrok URLs in an easy-to-access way. This tool uses the Ngrok free plan to get public URLs for your internal services and expose them. You can either use a telegram bot to get the public URLs or use redirection on Github pages to get a permanent URL to access your tunnels.
- Expose your tunnels public URL conveniently for your friends
- No need for setting up port forwarding on your system
- Relatively safe, no hardening needed
- Two choices to expose URLs: Telegram bot and Github pages
- Setup as a systemd service to do this on boot
Related Libraries
Installation
Dependencies
- You'll have to install Ngrok by downloading it from here. For ease of use you can create a config file similar to the one below
authtoken: TOKEN_ID
region: in # Set the region to closest one from your location
log_level: info
log_format: json
log: /var/log/ngrok.log
tunnels:
jupyter: # Name of the tunnel
proto: http
addr: 1234 # Port number of the service
bind_tls: true
file-download:
proto: http
addr: 5678
bind_tls: true
heimdall:
proto: http
addr: 1111
bind_tls: true
The name of your tunnel will be the path to the redirect link on Github pages. For ex. to visit the jupyter service you need to visit https://<github-username>.github.io/jupyter
. You'll be redirected to the tunnel and should be able access your service.
- You'll also need to install these dependencies
pip install PyGithub python-telegram-bot
Install NgrokLinkify
pip install NgrokLinkify
Once you install the tool you'll need to create a config file. The basic structure of the config file is available in the package as example-cfg.ini. You can copy the file and edit it according to your system.
[Default]
NgrokUrl = http://127.0.0.1:4040/api/tunnels #API endpoint for Ngrok, this is the default value
LogFile = /var/log/NgrokLinkify.log #Location of the Log File
[Git]
RepoPath = /path/to/github-pages/repo #Change this to the path to your local git pages repo
CommitComment = Committed URL at {0} # Commit Message when committing Github Pages
PagesContent = ---\ntitle: {0}\nredirect_to: {1}\n---\n #The content of the redirect file, I use https://github.com/jekyll/jekyll-redirect-from. You can use raw HTML by following https://stackoverflow.com/questions/5411538/redirect-from-an-html-page and replacing the URL by {0}
[Telegram]
FailureMsg = The server is not running currently! Ping @username #The Failure message to return when Ngrok isn't running
SuccessMsg = The public urls are \n ---------------------- \n{0} #The success message, {0} here contains tunnel name and public url
BotToken = 123123123 #The Bot token for telegram bot
Setup github repo
To ensure that you can update githuba pages without entering username or password. Enable ssh login to github by following this guide. Once done create and pull your github pages repo to the location mentioned in the config file.
Once you've enabled ssh access to your repo, set the upstream branch with ssh using the following command in the repo directory. Note the URL has to be a ssh url.
git remote set-url origin git@github.com:bagdeabhishek/bagdeabhishek.github.io.git
Usage
You can directly run the utility by using linkify command
Simple command line usage
linkify -config /path/to/config/file
You can choose to enable telegram bot or update the github page with redirection. use the -h
flag to get help
Use it programmatically inside python script
from NgrokLinkify.linkify import Linkify
Linkify(start_telegram_bot=False ,update_github_pages=True,config_file="/home/abhishek/linkify.ini")
Options
The command line utility accepts the following arguments
--config CONFIG_FILE_LOCATION
Path to the configuration file
--exclude-telegram
Don't run telegram bot
--exclude-gh-pages
Do not update github pages
Persist the services using systemd
The package contains example service file for both NgrokLinkify and Ngrok. You can copy them to /etc/systemd/system/
location.
Ngrok systemd service file
[Unit] Description=Ngrok After=network.service [Service] Type=simple User=user-name WorkingDirectory=/home/abhishek ExecStart=/path/to/ngrok start --all --config=".ngrok2/ngrok.yml" Restart=on-failure [Install] WantedBy=multi-user.target
Enable at boot
Create save this file as ngrok.service
in /etc/systemd/system/
location. Run the following commands to enable Ngrok at boot
sudo systemctl daemon-reload;
sudo systemctl enable ngrok.service;
NgrokLinkify systemd service
You can run NgrokLinkify as a service using the following example
[Unit] Description=Telegram bot to return URLs After=ngrok.service network.target network-online.target PartOf=ngrok.service [Service] Type=simple User=username ExecStart=/home/username/miniconda3/bin/linkify --config /home/username/linkify.ini Restart=on-failure [Install] WantedBy=multi-user.target
Save this file as NgrokLinkify.service
in /etc/systemd/system/
location. Enable the service at boot using the follwing commands
sudo systemctl daemon-reload;
sudo systemctl enable ngrok.service;
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file NgrokLinkify-1.0.tar.gz
.
File metadata
- Download URL: NgrokLinkify-1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 397d12f078ddbde9230379dfc3bf2cb0c567b4175a621b04bb0b84f3b507ea84 |
|
MD5 | f9f2e729635c40c710690538b7d6d364 |
|
BLAKE2b-256 | 755e6998c65b4807421af84d8a2294af55f4979cee0130eebd60fd2da2842868 |
File details
Details for the file NgrokLinkify-1.0-py3-none-any.whl
.
File metadata
- Download URL: NgrokLinkify-1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17560061d930fa5589c852663c8ab5f6b1d1ce8a929d921ae4a2ad7b77463c49 |
|
MD5 | 7534982580c9954cd44d3ce568456563 |
|
BLAKE2b-256 | 3e41e014d07098dba1bd22dd8f22366e8a93bf909b9dfbe82eda14f0e962759e |