edge

package module
v0.0.0-...-375fc8f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

README

4Chain

What is 4chain?

4chain is a simple、fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet.

Using the ssh protocol means that Linux, macOS can quickly connect using the ssh command, and windows can connect using ?

                                               Request                                                                                      
                            ┌───────────────dispatch: foo───────────┐                                                                       
                            │                                       │                                                                       
                            │                                       │                                                                       
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─                      ┌ ─ ─ ─ ─│─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─                                            
              Host Node     │        │                              │    Exit Node              │                                           
│                           ▼                              │        │                                                                       
   ┌───────────┐       ┌────────┐    │      .─────.            ┌────────┐        ┌──────────────┴────────┐        .─────.        ┌─────────┐
│  │   Node    │       │        │          ╱       ╲       │   │        │        │                       │       ╱       ╲       │         │
   │http://127.│◀ ─ ─ ▶│ client │◀═══╬═══▶(   SSH   )◀════════▶│ Server │◀ ─ ─ ─▶│http(s)://foo.4chain.me│◀ ─ ─▶(internet )◀─ ─ ▶│ Browser │
│  │0.0.1:3000 │       │        │          `.     ,'       │   │        │        │                       │       `.     ,'       │         │
   └───────────┘       └────────┘    │       `───'             └────────┘        └──────────────┬────────┘         `───'         └─────────┘
│                           │                              │        ▲                                                                       
     Private IPv4           │        │                              │                           │                                           
│                           │                              │        │                                                                       
 ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─│─ ─ ─ ─ ┘                      ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘                                           
                            │             Response                  │                                                                       
                            └────────────────OK─────────────────────┘                                                                       
                                                                                                                                                   

Feature

Quick start

  1. map the local listening port 8082 to the public network via 4chain.me
$ ssh -R 443::8082 4chain.me
  1. After establishing a successful remote SSH connection, the public access URL is returned https://0u6rq7.4chain.me

  2. Access from the public network

    curl https://0u6rq7.4chain.me

Deploy

Preparation:

  • domain name 4chain.me
  • server IP 157.xxx.xx.xx
{
  "addr": ":443",
  "email": "admin@4chain.me",
  "cf_token": "xxx",
  "ssh_addr": ":22",
  "domain": "4chain.me", # change you domain
  "idle_timeout": 300,
  "key": "-----BEGIN OPENSSH PRIVATE KEY-----\nxxxxxx\n-----END OPENSSH PRIVATE KEY-----\n"
}
  1. Configure cloudflare dns resolution
    A 4chain.me 157.xxx.xx.xx
    A *.4chain.me 157.xxx.xx.xx
  1. Get cloudflare token to the cf_token field of config.json

  2. generator ssh key:

$ ssh-keygen -b 2048 -f 4chain_rsa
$ cat 4chain_rsa #Copy the contents of the generated private key to the key field of config.json 
  1. start 4chain
#.
#├── 4chain
#└── config.json
#

$  ./4chain

TODO

  • Support windows

Developer

License

BSD

Other

Deepl

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(config *Config)

Types

type Config

type Config struct {
	Addr        string `json:"addr"`
	Email       string `json:"email"`
	SSHAddr     string `json:"ssh_addr"`
	Domain      string `json:"domain"`
	CfToken     string `json:"cf_token"`
	IdleTimeout int    `json:"idle_timeout"`
	Key         string `json:"key"`
}

type Conn

type Conn struct {
	gossh.Channel
	// contains filtered or unexported fields
}

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

type ForwardHandler

type ForwardHandler interface {
	TCPIPForward(ctx ssh.Context, srv *ssh.Server, req *gossh.Request) (ok bool, payload []byte)
	CancelTCPIPForward(ctx ssh.Context, srv *ssh.Server, req *gossh.Request) (ok bool, payload []byte)
	SessionHandler(sess ssh.Session)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL