nessielight

package module
v0.0.0-...-cbea934 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

README

Nessie Light

⚠ This project is still under rapid development, thus everything may change.

GitHub license GitHub license Go Reference

Overview

Nessie Light is a proxy manager based on telegram bot written in go, supporting multiuser, permission control, traffic limitation and data statistics. It works with v2ray and (in the future) other network tools. Taking advantage of telegram's interaction, it preserves security, simplicity and functionality.

Nessie Light is planning to support web interaction in the future, which typically acts as an entry.

Getting Start

Before install Nessie Light, you first install v2ray and enable it as a system service. i. e. follow the official installation guide.

Since Nessie Light use api to communicate with v2ray, you should enable api and statistics in v2ray (add following configuration):

{
  "stats": {},
  "api": {
    "tag": "api",
    "services": ["StatsService", "LoggerService", "HandlerService"]
  },
  "policy": {
    "levels": {
      "0": {
        "statsUserUplink": true,
        "statsUserDownlink": true
      }
    },
    "system": {
      "statsInboundUplink": true,
      "statsInboundDownlink": true,
      "statsOutboundUplink": true,
      "statsOutboundDownlink": true
    }
  },
  "inbounds": [
    {
      "tag": "api",
      "listen": "127.0.0.1",
      "port": 10085,
      "protocol": "dokodemo-door",
      "settings": {
        "network": "tcp,udp",
        "address": "127.0.0.1"
      }
    }
  ]
}

Now restart v2ray service.

Currently, you're supposed to build Nessie Light from source to get the executable:

go build -trimpath -v -ldflags='-s -w -extldflags "-static"' -o dest/nessielight ./main

Usage:

$ ./nessielight --help
Usage of ./nessielight:
  -admin value
    	init admin using tg user id
  -listen string
    	listen address (default "127.0.0.1:3456")
  -token string
    	tg bot token
  -v2rayapi string
    	v2ray api listening address
  -vmessaddr string
    	vmess address
  -vmessclientport int
    	vmess client port (default 443)
  -vmessport int
    	vmess listening port (default 12345)
  -vmesstag string
    	vmess inbound tag
  -webhook string
    	tg bot webhook url
  -wspath string
    	websocket path

Lastly, create a telegram bot with webhook setting to corresponding url, and you're ready to start:

$ ./nessielight -token xxxxxx\
    -webhook https://xxxxxx:12345\
    -listen 0.0.0.0:12345\
    -vmessaddr example.com\
    -vmessport 38888\
    -vmessclientport 443\
    -vmesstag multiuser\
    -wspath /apath\
    -v2rayapi 127.0.0.1:10085\

Documentation

Index

Constants

View Source
const UUIDLen = 36

Variables

View Source
var VConfJson = template.Must(template.New("confjson").Parse(`
{
   "add":"{{.Domain}}",
   "aid":"0",
   "host":"{{.Domain}}",
   "id":"{{.ID}}",
   "net":"ws",
   "path":"{{.Path}}",
   "port":"{{.Port}}",
   "ps":"{{.Name}}",
   "scy":"auto",
   "sni":"{{.Domain}}",
   "tls":"tls",
   "type":"",
   "v":"2"
}
`))
View Source
var VConfText = template.Must(template.New("conftext").Parse(`
协议类型: vmess
地址: {{.Domain}}
伪装域名/SNI: {{.Domain}}
端口: <code>{{.Port}}</code>
用户ID: <code>{{.ID}}</code>
安全: tls
传输方式: ws
路径: <code>{{.Path}}</code>
`))

Functions

func ApplyUserProxy

func ApplyUserProxy(user User) error

func GetUserProxyMessage

func GetUserProxyMessage(user User) string

func InitDBwithFile

func InitDBwithFile(path string) error

func InitV2rayService

func InitV2rayService(inboundTag string, vmessPort, vmessClientPort int, vmessAddress, wsPath, v2rayApi string) error

func NewUUID

func NewUUID() string

func Restore

func Restore() error

func V2rayUpdateUserTraffic

func V2rayUpdateUserTraffic() error

Types

type GormDB

type GormDB = gorm.DB
var DataBase *GormDB

type NamedTraffic

type NamedTraffic struct {
	TrafficValue
	Name string
}

func GetV2rayTraffic

func GetV2rayTraffic() ([]NamedTraffic, error)

Get current traffic stats of all inbounds. Note that user stats is not correct due to V2rayUpdateUserTraffic

type Proxy

type Proxy interface {
	// identify this proxy
	ProxyID() uint
	// apply this proxy
	Activate() error
	// remove this proxy
	Deactivate() error
	// introduce this proxy in telegram message
	Message() string
}

describe a proxy config. Proxy can be store in sqldb

type SystemCtlService

type SystemCtlService interface {
	StartV2rayServer() error
	StopV2rayServer() error
	RestartV2rayServer() error
}

need implementation

type TelegramAuthService

type TelegramAuthService interface {
	// 生成一个注册用的 token
	GenToken() (token string)
	// 使用 token 注册用户,注册失败(token不匹配)返回错误
	Register(token string, tid int) (User, error)
}

implemented by simpleTelegramAuthService

var AuthServiceInstance TelegramAuthService

type TrafficValue

type TrafficValue struct {
	Uplink, Downlink utils.ByteValue
}

type User

type User interface {
	TelegramID() int
	Name() string
	Proxy() []Proxy
	SetProxy(proxy []Proxy) error
	SetName(name string) error
	// total traffic stored
	Traffic() TrafficValue
	SetTraffic(val TrafficValue) error
}

Interface for User. Typically implemented by UserManager.NewUser

type UserManager

type UserManager interface {
	AddUser(user User) error
	SetUser(user User) error
	DeleteUser(user User) error
	// find user by id, nil for not found
	FindUserByTelegramID(tid int) (User, error)
	// find user by proxy id, nil for not found
	FindUserByProxy(proxyid uint) (User, error)
	// generate new user by id
	NewUser(tid int) User
	All() ([]User, error)
}

implemented by simpleUserManager

var UserManagerInstance UserManager

type V2rayService

type V2rayService interface {
	SetUser(email string, uuid string) error
	AddUser(email string) (uuid string, err error)
	// remove a user identified by email
	RemoveUser(email string) error
	QueryTraffic(pattern string, reset bool) (stat []V2rayTrafficStat, err error)
	// query traffic for user under control only
	QueryUserTraffic(reset bool) (stat []V2rayTrafficStat, err error)
	Start(listen string) error
	VmessText(vmessid string) string
	VmessLink(vmessid string) string
	NewProxy() Proxy
	AddVmessWsInbound(tag string, port uint16, wspath string) error
	RemoveInbound(tag string) error
}

implemented by v2rayClient

var V2rayServiceInstance V2rayService

type V2rayTrafficStat

type V2rayTrafficStat struct {
	Name  string
	Value int64
}

Directories

Path Synopsis
package main implements command line interface
package main implements command line interface
a Telegram Bot Service framework based on yanzay/tbot
a Telegram Bot Service framework based on yanzay/tbot
utils module

Jump to

Keyboard shortcuts

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