-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eed7a69
Showing
13 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# more_user | ||
frp多用户远程插件,基于官方开发,具体查看文档helofrp |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
func main() { | ||
Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.