Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pzks committed Dec 5, 2024
0 parents commit eed7a69
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export GO111MODULE=on

all: fp-multiuser

fp-multiuser:
go build -o ./bin/fp-multiuser ./cmd/fp-multiuser
21 changes: 21 additions & 0 deletions Makefile.cross-compiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export GO111MODULE=on
LDFLAGS := -s -w

all: build

build: app

app:
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-darwin-amd64 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-freebsd-386 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-freebsd-amd64 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-386 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-amd64 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-arm ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-arm64 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-windows-386.exe ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-windows-amd64.exe ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-mips64 ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-mips64le ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-mips ./cmd/fp-multiuser
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "$(LDFLAGS)" -o ./release/fp-multiuser-linux-mipsle ./cmd/fp-multiuser
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# more_user
frp多用户远程插件,基于官方开发,具体查看文档helofrp
Binary file added bin/linux_amd64/mu
Binary file not shown.
Binary file added bin/windows_amd64/mu.exe
Binary file not shown.
12 changes: 12 additions & 0 deletions builds.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off
echo start build inux amd64
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build -o ./bin/linux_amd64/mu ./cmd/more_user

echo start build windows amd64
SET CGO_ENABLED=0
SET GOOS=windows
SET GOARCH=amd64
go build -o ./bin/windows_amd64/mu.exe ./cmd/more_user
114 changes: 114 additions & 0 deletions cmd/more_user/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"

"github.com/gofrp/fp-multiuser/pkg/server"

"github.com/spf13/cobra"
)

const version = "0.1.1"

var (
showVersion bool

bindAddr string
tokenFile string
remoteToken string
)

func init() {
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version")
rootCmd.PersistentFlags().StringVarP(&bindAddr, "bind_addr", "l", "127.0.0.1:7200", "bind address")
rootCmd.PersistentFlags().StringVarP(&tokenFile, "token_file", "f", "./tokens", "token file")
rootCmd.PersistentFlags().StringVarP(&remoteToken, "remote_token", "m", "", "remote token file")
}

// rootCmd represents the root command for fp-multiuser.
var rootCmd = &cobra.Command{
Use: "HeloFrp_MU",
Short: "MU is the server plugin of frp to support multiple users based on fp-multiuser",
RunE: func(cmd *cobra.Command, args []string) error {
// Check if the version flag is set
if showVersion {
fmt.Println(version)
return nil
}

// Parse tokens from the specified file
var tokens map[string]string
var err error
if remoteToken != "" {
tokens, err = ParseTokensFromRemote(remoteToken)
} else {
tokens, err = ParseTokensFromFile(tokenFile)
}
if err != nil {
log.Printf("parse tokens error: %v", err)
return err
}

// Create a new server instance with the specified configuration
s, err := server.New(server.Config{
BindAddress: bindAddr,
Tokens: tokens,
})
if err != nil {
return err
}

// Start the server
s.Run()
return nil
},
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}

func ParseTokensFromFile(file string) (map[string]string, error) {
buf, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
ret := make(map[string]string)
rows := strings.Split(string(buf), "\n")
for _, row := range rows {
kvs := strings.SplitN(row, "=", 2)
if len(kvs) == 2 {
ret[strings.TrimSpace(kvs[0])] = strings.TrimSpace(kvs[1])
}
}
return ret, nil
}

func ParseTokensFromRemote(url string) (map[string]string, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

ret := make(map[string]string)
rows := strings.Split(string(buf), "\n")
for _, row := range rows {
kvs := strings.SplitN(row, "=", 2)
if len(kvs) == 2 {
ret[strings.TrimSpace(kvs[0])] = strings.TrimSpace(kvs[1])
}
}
return ret, nil
}
5 changes: 5 additions & 0 deletions cmd/more_user/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
Execute()
}
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/gofrp/fp-multiuser

go 1.15

require (
github.com/fatedier/frp v0.34.1
github.com/gin-gonic/gin v1.7.0
github.com/spf13/cobra v0.0.3
)
Loading

0 comments on commit eed7a69

Please sign in to comment.