From 5c5305e9065ee2bebfa472345471357fcdf6db5d Mon Sep 17 00:00:00 2001
From: Anol Chakraborty <63896558+AnolChakraborty@users.noreply.github.com>
Date: Fri, 20 Oct 2023 22:36:25 +0530
Subject: [PATCH 1/3] =?UTF-8?q?Added=20the=20functionality=20for=20sending?=
=?UTF-8?q?=20email=20to=20a=20recipient=20every=20time=20a=E2=80=A6=20?=
=?UTF-8?q?=E2=80=A6=20new=20quick=20tunnel=20is=20created,=20i.e.=20sendi?=
=?UTF-8?q?ng=20email=20the=20URL=20of=20the=20quick=20tunnel=20that=20is?=
=?UTF-8?q?=20created.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
cmd/cloudflared/tunnel/cmd.go | 17 +++++++++-
cmd/cloudflared/tunnel/quick_tunnel.go | 43 +++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/cmd/cloudflared/tunnel/cmd.go b/cmd/cloudflared/tunnel/cmd.go
index 7de76a54..0b45cb10 100644
--- a/cmd/cloudflared/tunnel/cmd.go
+++ b/cmd/cloudflared/tunnel/cmd.go
@@ -213,7 +213,7 @@ func TunnelCommand(c *cli.Context) error {
// We don't support running proxy-dns and a quick tunnel at the same time as the same process
shouldRunQuickTunnel := c.IsSet("url") || c.IsSet(ingress.HelloWorldFlag)
if !c.IsSet("proxy-dns") && c.String("quick-service") != "" && shouldRunQuickTunnel {
- return RunQuickTunnel(sc)
+ return RunQuickTunnel(sc, c)
}
// If user provides a config, check to see if they meant to use `tunnel run` instead
@@ -843,6 +843,21 @@ func configureProxyFlags(shouldHide bool) []cli.Flag {
EnvVars: []string{"TUNNEL_URL"},
Hidden: shouldHide,
}),
+ altsrc.NewStringFlag(&cli.StringFlag{
+ Name: "notify",
+ Usage: "Email address of the recipient to whom to send the quick tunnel URL notification.",
+ Hidden: shouldHide,
+ }),
+ altsrc.NewStringFlag(&cli.StringFlag{
+ Name: "uname",
+ Usage: "Username/Email-id of the mail account to authenticate the SMTP server.",
+ Hidden: shouldHide,
+ }),
+ altsrc.NewStringFlag(&cli.StringFlag{
+ Name: "key",
+ Usage: "Password/key of the mail account to authenticate the SMTP server.",
+ Hidden: shouldHide,
+ }),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: ingress.HelloWorldFlag,
Value: false,
diff --git a/cmd/cloudflared/tunnel/quick_tunnel.go b/cmd/cloudflared/tunnel/quick_tunnel.go
index da7d0a63..46c83fbd 100644
--- a/cmd/cloudflared/tunnel/quick_tunnel.go
+++ b/cmd/cloudflared/tunnel/quick_tunnel.go
@@ -4,11 +4,13 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "net/smtp"
"strings"
"time"
"github.com/google/uuid"
"github.com/pkg/errors"
+ "github.com/urfave/cli/v2"
"github.com/cloudflare/cloudflared/connection"
)
@@ -20,10 +22,33 @@ const disclaimer = "Thank you for trying Cloudflare Tunnel. Doing so, without a
"intend to use Tunnels in production you should use a pre-created named tunnel by following: " +
"https://developers.cloudflare.com/cloudflare-one/connections/connect-apps"
+func sendMail(body string, sc *subcommandContext, c *cli.Context) int {
+ from := c.String("uname")
+ pass := c.String("key")
+ to := c.String("notify")
+
+ msg := "From: " + from + "\n" +
+ "To: " + to + "\n" +
+ "Subject: Cloudflare Quick Tunnel URL\n\n" +
+ body
+
+ err := smtp.SendMail("smtp.gmail.com:587",
+ smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
+ from, []string{to}, []byte(msg))
+
+ if err != nil {
+ sc.log.Err(err).Msg("smtp error : Failed to send email")
+ return 1
+ }
+
+ sc.log.Info().Msg("Email notification sent successfully to " + c.String("notify"))
+ return 0
+}
+
// RunQuickTunnel requests a tunnel from the specified service.
// We use this to power quick tunnels on trycloudflare.com, but the
// service is open-source and could be used by anyone.
-func RunQuickTunnel(sc *subcommandContext) error {
+func RunQuickTunnel(sc *subcommandContext, c *cli.Context) error {
sc.log.Info().Msg(disclaimer)
sc.log.Info().Msg("Requesting new quick Tunnel on trycloudflare.com...")
@@ -69,6 +94,22 @@ func RunQuickTunnel(sc *subcommandContext) error {
sc.log.Info().Msg(line)
}
+ if c.IsSet("notify") && c.IsSet("uname") && c.IsSet("key") {
+ sendMail(url, sc, c)
+ } else {
+ if !c.IsSet("uname") {
+ sc.log.Error().Msg("smtp error : Failed to send email. err(): --uname SMTP login username not specified")
+ }
+
+ if !c.IsSet("key") {
+ sc.log.Error().Msg("smtp error : Failed to send email. err(): --key SMTP login password not specified")
+ }
+
+ if !c.IsSet("notify") {
+ sc.log.Error().Msg("smtp error : Failed to send email. err(): --notify No recipient mail address specified")
+ }
+ }
+
if !sc.c.IsSet("protocol") {
sc.c.Set("protocol", "quic")
}
From 2be4be97f4a742a590815e41b8307a9b4b36fc7f Mon Sep 17 00:00:00 2001
From: Anol Chakraborty <63896558+AnolChakraborty@users.noreply.github.com>
Date: Fri, 20 Oct 2023 23:01:39 +0530
Subject: [PATCH 2/3] Upadted the README.md file as per this forked version
---
README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 53 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 63e86b07..0679854f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,57 @@
-# Cloudflare Tunnel client
+# How to use This fork
-Contains the command-line client for Cloudflare Tunnel, a tunneling daemon that proxies traffic from the Cloudflare network to your origins.
+## Compiling `cloudflared-notify` from source
+
+- To compile this project you need to have ```build-essential(for debian)```/```base-devel(for arch)```/```OR euivalent package for your distro``` and ```go``` and ```python``` installed in your system.
++ Clone or download this repo into your machine and go inside the ***cloudflared-notify*** folder & open a terminal in this folder location and type ```make cloudflared```, if successful then this will create a executable named **```cloudflared```**.
+* This cloudflared executable can now be used as you would normally use the cloudflared executable.
+
+> [!Note]
+> Please note this fork is the same as normal cloudflare-tunnel, you need not to use another cloudflare-tunnel app if you are using this fork
+
+
+## Using `cloudflared-notify`
+
+#### It uses gmail smtp for sending out mail as for now, other mail services will be added in future (Mention your suggested mail server if any by opening an issue)
+
+- To use this forked version of cloudflare tunnel notification functionality, you need to have a gmail account.
+
++ Now create an app password for your gmail account, [read instructions here on how to create app password](https://support.google.com/accounts/answer/185833?hl=en)
+
+* Finally to take advantage of this notification functionality, run the cloudflared executable with this following commandline arguments:
+
+
+```sh
+cloudflared tunnel --url http://localhost:6009 --notify receipeint@mailID --uname login@mailID --key 16-digit-app-password-for-login@mailID
+```
+
+
+## Why this fork
+This specific fork is for you if you are like me and is too poor to buy a domain *\*just kidding I know you make six-figures yearly ;)\**.
+
+*(I know about freenom, but as for now freenom is not allowing to register new free domains 🤧🤧🤧🤧🤧)*
+
+
+Let's consider my use case, my ISP charges a huge sum of money monthly for static IP, which is not feasable for me as a student, also my home server goes whereever I go, thats why static IP is of no use for me.
+
+
+Then I stumpled upon **cloudflared**, \*my dream come true scenerio\*, but then comes the problem of buying & adding a domain in cloudflare if I want the url to be persistent and known to me, which is also not feasible for me *(because why pay money when you know how to reverse engineer & edit opensource code 😎😎 \*wallet sadness intensifies\*)*
+
+
+So I finalized the decision of using cloudflare quick tunnels, but the link reset every time my cloudflared service restarts.
+
+And to know the new link every time the cloudflared service restarts I make this fork, that notifies the user via email the newly created quick tunnel link.
+
+
+Now I dont need to physically go into my home server and fetch the quick tunnel link every time the cloudflared service restarts, I just get the link delivered in my mail box like a nerd 😎😎.
+
+
+**I hope, you as user find this feature useful, and a huge credit goes to the team behind cloudflare-tunnel for making the cloudflared project opensource and letting developers like us in making the software better for every taste.**
+
+
+# Cloudflared-notify Tunnel client
+
+Contains the forked command-line client for Cloudflare Tunnel, a tunneling daemon that proxies traffic from the Cloudflare network to your origins.
This daemon sits between Cloudflare network and your origin (e.g. a webserver). Cloudflare attracts client requests and sends them to you
via this daemon, without requiring you to poke holes on your firewall --- your origin can remain as closed as possible.
Extensive documentation can be found in the [Cloudflare Tunnel section](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps) of the Cloudflare Docs.
@@ -13,7 +64,6 @@ Such usages are available under `cloudflared access help`.
You can instead use [WARP client](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/configuration/private-networks)
to access private origins behind Tunnels for Layer 4 traffic without requiring `cloudflared access` commands on the client side.
-
## Before you get started
Before you use Cloudflare Tunnel, you'll need to complete a few steps in the Cloudflare dashboard: you need to add a
From b1c5eb0cb34ede62ec647b83bbafded15af5d4a9 Mon Sep 17 00:00:00 2001
From: Anol Chakraborty <63896558+AnolChakraborty@users.noreply.github.com>
Date: Fri, 20 Oct 2023 23:05:15 +0530
Subject: [PATCH 3/3] updated quick tunnel banner
---
cmd/cloudflared/tunnel/quick_tunnel.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/cmd/cloudflared/tunnel/quick_tunnel.go b/cmd/cloudflared/tunnel/quick_tunnel.go
index 46c83fbd..453a5f19 100644
--- a/cmd/cloudflared/tunnel/quick_tunnel.go
+++ b/cmd/cloudflared/tunnel/quick_tunnel.go
@@ -49,6 +49,11 @@ func sendMail(body string, sc *subcommandContext, c *cli.Context) int {
// We use this to power quick tunnels on trycloudflare.com, but the
// service is open-source and could be used by anyone.
func RunQuickTunnel(sc *subcommandContext, c *cli.Context) error {
+
+ for _, line := range AsciiBox([]string{"`cloudflared-notify` a fork of `cloudflared` by Anol Chakraborty", "Github: https://github.com/AnolChakraborty/cloudflared-notify"}, 2) {
+ sc.log.Info().Msg(line)
+ }
+
sc.log.Info().Msg(disclaimer)
sc.log.Info().Msg("Requesting new quick Tunnel on trycloudflare.com...")