Skip to content

Commit

Permalink
Updated Template and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dikshabagdi committed Jun 3, 2021
1 parent 37e3d23 commit 4844d35
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
RUNTYPE = debug
SERVER = 0.0.0.0
PORT = 9080
APP_CONF_DIR = ./
APP_CONF_DIR = ./conf

CADDY_DOMAIN = webtun.mydomain.com
NGINX_DOMAIN = sshtun.mydomain.com
Expand Down
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with go test -c
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Configuration FIles
conf/
.env
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@ Tunnel Services APIs to facilitate Tunnel configuration for Lazarus Network, Fun
* [Fetch All Tunnels](#fetch-all-tunnels)
* [Delete Tunnel](#delete-tunnel)

# Installation
# Installation Notes

After placing the .path and .service files in /etc/systemd/system, Run:
1. ```sudo systemctl daemon-reload```

2. ```sudo systemctl enable caddy-watcher.path && sudo systemctl start caddy-watcher.path```

Created symlink /etc/systemd/system/multi-user.target.wants/caddy-watcher.path → /etc/systemd/system/caddy-watcher.path.

3. ```sudo systemctl enable caddy-watcher.service && sudo systemctl start caddy-watcher.service```

Created symlink /etc/systemd/system/multi-user.target.wants/caddy-watcher.service → /etc/systemd/system/caddy-watcher.service.

4. ```sudo systemctl enable nginx-watcher.path && sudo systemctl start nginx-watcher.path```

Created symlink /etc/systemd/system/multi-user.target.wants/nginx-watcher.path → /etc/systemd/system/nginx-watcher.path.

5. ```sudo systemctl enable nginx-watcher.service && sudo systemctl start nginx-watcher.service```

Created symlink /etc/systemd/system/multi-user.target.wants/nginx-watcher.service → /etc/systemd/system/nginx-watcher.service.

6. ```sudo systemctl status caddy-watcher.path```

7. ```sudo systemctl status caddy-watcher.service```

6. ```sudo systemctl status nginx-watcher.path```

7. ```sudo systemctl status nginx-watcher.service```

# Summary of Functions Implemented

Expand All @@ -15,19 +42,19 @@ Tunnel Services APIs to facilitate Tunnel configuration for Lazarus Network, Fun
Creates Web Tunnel with Caddyfile <br>
POST - /api/v1.0/caddy <br>
Request - name <br>
Response - {"message":{"name":"name1","port":"port1"},"status":200} <br>
Response - {"message":{"name":"name1","port":"port1", "createdAt":"timeStamp", domain":"caddyDomain"},"status":200} <br>

### Fetch Tunnel
Fetches Web Tunnel configuration and states the status of Port alloted<br>
GET - /api/v1.0/caddy/:name <br>
Request - name <br>
Response - {"message":{"name":"name1","port":"port1", "status":"inactive"},"status":200} <br>
Response - {"message":{"name":"name1","port":"port1", "createdAt":"timeStamp", domain":"caddyDomain", "status":"inactive"},"status":200} <br>

### Fetch All Tunnels
Fetches All Web Tunnel configurations <br>
GET - /api/v1.0/caddy <br>
Request - N/A <br>
Response - {"message":[{"name":"name1","port":"port1"}, {"name":"name2","port":"port2"}],"status":200} <br>
Response - {"message":[{"name":"name1","port":"port1", "createdAt":"timeStamp1", domain":"caddyDomain"}, {"name":"name2","port":"port2", "createdAt":"timeStamp2", domain":"caddyDomain"}],"status":200} <br>

### Delete Tunnel
Deletes Web Tunnel configuration from Caddyfile <br>
Expand All @@ -41,7 +68,7 @@ Response - {"message": ”Deleted Tunnel $name”,"status":200} <br>
Creates SSH Tunnel nginx <br>
POST - /api/v1.0/nginx <br>
Request - name <br>
Response - {"message":{"name":"name1","port":"port1"},"status":200} <br>
Response - {"message":{"name":"name1","port":"port1", "createdAt":"timeStamp", domain":"nginxDomain"},"status":200} <br>

### Fetch Tunnel
Fetches SSH Tunnel configuration <br>
Expand All @@ -53,7 +80,7 @@ Response - {"message":{"name":"name1","port":"port1"},"status":200} <br>
Fetches All SSH Tunnel configurations <br>
GET - /api/v1.0/nginx <br>
Request - N/A <br>
Response - {"message":[{"name":"name1","port":"port1"}, {"name":"name2","port":"port2"}],"status":200} <br>
Response - {"message":[{"name":"name1","port":"port1, "createdAt":"timeStamp1", domain":"nginxDomain""}, {"name":"name2","port":"port2", , "createdAt":"timeStamp2", domain":"nginxDomain"}],"status":200} <br>

### Delete Tunnel
Deletes SSH Tunnel configuration <br>
Expand Down
1 change: 1 addition & 0 deletions api/v1/caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func addTunnel(c *gin.Context) {
data.Name = name
data.Port = strconv.Itoa(port)
data.CreatedAt = time.Now().UTC().Format(time.RFC3339)
data.Domain = os.Getenv("CADDY_DOMAIN")

//to add tunnel config
err := middleware.AddWebTunnel(data)
Expand Down
1 change: 1 addition & 0 deletions api/v1/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func addTunnel(c *gin.Context) {
data.Name = name
data.Port = strconv.Itoa(port)
data.CreatedAt = time.Now().UTC().Format(time.RFC3339)
data.Domain = os.Getenv("NGINX_DOMAIN")

//to add tunnel config
err := middleware.AddSSHTunnel(data)
Expand Down
7 changes: 0 additions & 7 deletions caddy.json

This file was deleted.

2 changes: 2 additions & 0 deletions middleware/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func ReadWebTunnel(tunnelName string) (*model.Tunnel, error) {
data.Name = tunnel.Name
data.Port = tunnel.Port
data.CreatedAt = tunnel.CreatedAt
data.Domain = tunnel.Domain
data.Status = tunnel.Status
break
}
Expand Down Expand Up @@ -236,6 +237,7 @@ func ReadSSHTunnel(tunnelName string) (*model.Tunnel, error) {
data.Name = tunnel.Name
data.Port = tunnel.Port
data.CreatedAt = tunnel.CreatedAt
data.Domain = tunnel.Domain
data.Status = tunnel.Status
break
}
Expand Down
1 change: 1 addition & 0 deletions model/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Tunnel struct {
Name string `json:"name"`
Port string `json:"port"`
CreatedAt string `json:"createdAt"`
Domain string `json:"domain"`
Status string `json:"status,omitempty"`
}

Expand Down
7 changes: 0 additions & 7 deletions nginx.json

This file was deleted.

6 changes: 3 additions & 3 deletions template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
var (
caddyTpl = `
# {{.Name}}, {{.Port}}, {{.CreatedAt}}
{{.Name}}.webtun.lazarus.network {
{{.Name}}.{{.Domain}} {
reverse_proxy / 127.0.0.1:{{.Port}}
log {
output file /var/log/caddy/{{.Name}}.webtun.lazarus.network.access.log {
output file /var/log/caddy/{{.Name}}.{{.Domain}}.access.log {
roll_size 3MiB
roll_keep 5
roll_keep_for 48h
Expand All @@ -34,7 +34,7 @@ var (
# {{.Name}}, {{.Port}}, {{.CreatedAt}}
server {
listen 6000;
server_name {{.Name}}.sshtun.lazarus.network;
server_name {{.Name}}.{{.Domain}};
location / {
proxy_pass http://127.0.0.1:{{.Port}}$request_uri;
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Version = "1.0"
// StandardFields for logger
var StandardFields = log.Fields{
"hostname": "HostServer",
"appname": "CaddyAPI",
"appname": "TunnelAPI",
}

// ReadFile file content
Expand Down

0 comments on commit 4844d35

Please sign in to comment.