Compare commits

..
5 Commits
Author SHA1 Message Date
yisier e2dd6be756 更新程序 url 更改到当前仓库中 2023-02-24 17:52:51 +08:00
yisier 834f92933e 修复nps 在外部路径启动时找不到配置文件,增加 nps 启动参数 -conf_path 2023-02-24 17:38:11 +08:00
yisier d740a2774a Merge pull request #46 from 5high/patch-1
修复域名解析https下不显示404页面问题
2023-01-11 13:51:20 +08:00
5high 9d3e926256 Update https.go 2023-01-11 10:08:42 +08:00
yisier ab81f5b68e API 鉴权漏洞修复 2022-12-30 12:24:48 +08:00
7 changed files with 74 additions and 10 deletions
+20
View File
@@ -14,6 +14,26 @@
## 更新日志
- 2023-02-24 v0.26.15
***修复***:更新程序 url 更改到当前仓库中
***修复***:nps 在外部路径启动时找不到配置文件
***新增***:增加 nps 启动参数,`-conf_path=D:\test\nps`,可用于加载指定nps配置文件和web文件目录。
***window 使用示例:***
启动:`nps.exe -conf_path=D:\test\nps`
安装:`nps.exe install -conf_path=D:\test\nps`
安装启动:`nps start`
***linux 使用示例:***
直接启动:`./nps -conf_path=/app/nps`
安装:`./nps install -conf_path=/app/nps`
安装启动:`nps start -conf_path=/app/nps`
- 2022-12-30 v0.26.14
***修复***:API 鉴权漏洞修复
- 2022-12-19
***修复***:某些场景下丢包导致服务端意外退出
***优化***:新增隧道时,不指定服务端口时,将自动生成端口号
+29 -5
View File
@@ -28,8 +28,9 @@ import (
)
var (
level string
ver = flag.Bool("version", false, "show current version")
level string
ver = flag.Bool("version", false, "show current version")
confPath = flag.String("conf_path", "", "set current confPath")
)
func main() {
@@ -40,6 +41,18 @@ func main() {
common.PrintVersion()
return
}
// *confPath why get null value ?
for _, v := range os.Args[1:] {
switch v {
case "install", "start", "stop", "uninstall", "restart":
continue
}
if strings.Contains(v, "-conf_path=") {
common.ConfPath = strings.Replace(v, "-conf_path=", "", -1)
}
}
if err := beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf")); err != nil {
log.Fatalln("load config file error", err.Error())
}
@@ -66,6 +79,15 @@ func main() {
Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。",
Option: options,
}
for _, v := range os.Args[1:] {
switch v {
case "install", "start", "stop", "uninstall", "restart":
continue
}
svcConfig.Arguments = append(svcConfig.Arguments, v)
}
svcConfig.Arguments = append(svcConfig.Arguments, "service")
if len(os.Args) > 1 && os.Args[1] == "service" {
_ = logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`)
@@ -149,9 +171,9 @@ func main() {
case "update":
install.UpdateNps()
return
default:
logs.Error("command is not support")
return
//default:
// logs.Error("command is not support")
// return
}
}
@@ -203,6 +225,8 @@ func run() {
logs.Error("Getting bridge_port error", err)
os.Exit(0)
}
logs.Info("the config path is:" + common.GetRunPath())
logs.Info("the version of server is %s ,allow client core version to be %s", version.VERSION, version.GetVersion())
connection.InitConnectionService()
//crypt.InitTls(filepath.Join(common.GetRunPath(), "conf", "server.pem"), filepath.Join(common.GetRunPath(), "conf", "server.key"))
+14 -2
View File
@@ -6,13 +6,20 @@ import (
"runtime"
)
var ConfPath string
//Get the currently selected configuration file directory
//For non-Windows systems, select the /etc/nps as config directory if exist, or select ./
//windows system, select the C:\Program Files\nps as config directory if exist, or select ./
func GetRunPath() string {
var path string
if len(os.Args) <= 1 {
return "./"
if len(os.Args) == 1 {
if !IsWindows() {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) //返回
return dir + "/"
} else {
return "./"
}
} else {
if path = GetInstallPath(); !FileExists(path) {
return GetAppPath()
@@ -24,6 +31,11 @@ func GetRunPath() string {
//Different systems get different installation paths
func GetInstallPath() string {
var path string
if ConfPath != "" {
return ConfPath
}
if IsWindows() {
path = `C:\Program Files\nps`
} else {
+2 -2
View File
@@ -154,7 +154,7 @@ type release struct {
func downloadLatest(bin string) string {
// get version
data, err := http.Get("https://api.github.com/repos/ehang-io/nps/releases/latest")
data, err := http.Get("https://api.github.com/repos/yisier/nps/releases/latest")
if err != nil {
log.Fatal(err.Error())
}
@@ -168,7 +168,7 @@ func downloadLatest(bin string) string {
fmt.Println("the latest version is", version)
filename := runtime.GOOS + "_" + runtime.GOARCH + "_" + bin + ".tar.gz"
// download latest package
downloadUrl := fmt.Sprintf("https://ehang.io/nps/releases/download/%s/%s", version, filename)
downloadUrl := fmt.Sprintf("https://github.com/yisier/nps/releases/download/%s/%s", version, filename)
fmt.Println("download package from ", downloadUrl)
resp, err := http.Get(downloadUrl)
if err != nil {
+1 -1
View File
@@ -1,6 +1,6 @@
package version
const VERSION = "0.26.13"
const VERSION = "0.26.14"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
+5
View File
@@ -4,6 +4,7 @@ import (
"net"
"net/http"
"net/url"
"path/filepath"
"sync"
"ehang.io/nps/lib/cache"
@@ -34,6 +35,10 @@ func NewHttpsServer(l net.Listener, bridge NetBridge, useCache bool, cacheLen in
//start https server
func (https *HttpsServer) Start() error {
var err error
if https.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil {
https.errorContent = []byte("nps 404")
}
if b, err := beego.AppConfig.Bool("https_just_proxy"); err == nil && b {
conn.Accept(https.listener, func(c net.Conn) {
https.handleHttps(c)
+3
View File
@@ -32,6 +32,9 @@ func (s *BaseController) Prepare() {
md5Key := s.getEscapeString("auth_key")
timestamp := s.GetIntNoErr("timestamp")
configKey := beego.AppConfig.String("auth_key")
if configKey == "" {
configKey = crypt.GetRandomString(64)
}
timeNowUnix := time.Now().Unix()
if !(md5Key != "" && (math.Abs(float64(timeNowUnix-int64(timestamp))) <= 20) && (crypt.Md5(configKey+strconv.Itoa(timestamp)) == md5Key)) {
if s.GetSession("auth") != true {