-
Notifications
You must be signed in to change notification settings - Fork 60
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
Showing
14 changed files
with
176 additions
and
16 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
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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,58 @@ | ||
package main | ||
|
||
import ( | ||
bizclient "github.com/VaalaCat/frp-panel/biz/client" | ||
"github.com/VaalaCat/frp-panel/conf" | ||
"github.com/VaalaCat/frp-panel/pb" | ||
"github.com/VaalaCat/frp-panel/rpc" | ||
"github.com/VaalaCat/frp-panel/services/rpcclient" | ||
"github.com/VaalaCat/frp-panel/utils" | ||
"github.com/VaalaCat/frp-panel/watcher" | ||
"github.com/fatedier/golib/crypto" | ||
"github.com/sirupsen/logrus" | ||
"github.com/sourcegraph/conc" | ||
) | ||
|
||
func runClient(clientID, clientSecret string) { | ||
crypto.DefaultSalt = conf.Get().App.Secret | ||
logrus.Infof("start to run client") | ||
if len(clientSecret) == 0 { | ||
logrus.Fatal("client secret cannot be empty") | ||
} | ||
|
||
if len(clientID) == 0 { | ||
logrus.Fatal("client id cannot be empty") | ||
} | ||
|
||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPC)) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
conf.ClientCred = cred | ||
|
||
rpcclient.MustInitClientRPCSerivce( | ||
clientID, | ||
clientSecret, | ||
pb.Event_EVENT_REGISTER_CLIENT, | ||
bizclient.HandleServerMessage, | ||
) | ||
r := rpcclient.GetClientRPCSerivce() | ||
defer r.Stop() | ||
|
||
w := watcher.NewClient(bizclient.PullConfig, clientID, clientSecret) | ||
defer w.Stop() | ||
|
||
initClientOnce(clientID, clientSecret) | ||
|
||
var wg conc.WaitGroup | ||
wg.Go(r.Run) | ||
wg.Go(w.Run) | ||
wg.Wait() | ||
} | ||
|
||
func initClientOnce(clientID, clientSecret string) { | ||
err := bizclient.PullConfig(clientID, clientSecret) | ||
if err != nil { | ||
logrus.WithError(err).Errorf("cannot pull client config, wait for retry") | ||
} | ||
} |
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,75 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/VaalaCat/frp-panel/conf" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
clientCmd *cobra.Command | ||
rootCmd *cobra.Command | ||
) | ||
|
||
func initCommand() { | ||
var ( | ||
clientSecret string | ||
clientID string | ||
rpcHost string | ||
appSecret string | ||
rpcPort int | ||
apiPort int | ||
apiScheme string | ||
) | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
clientCmd = &cobra.Command{ | ||
Use: "client [-s client secret] [-i client id] [-a app secret] [-r rpc host] [-c rpc port] [-p api port]", | ||
Short: "run managed frpc", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
patchConfig(rpcHost, appSecret, rpcPort, apiPort) | ||
runClient(clientID, clientSecret) | ||
}, | ||
} | ||
rootCmd = &cobra.Command{ | ||
Use: "frp-panel-client", | ||
Short: "frp-panel-client is a frp panel client QwQ", | ||
} | ||
rootCmd.AddCommand(clientCmd) | ||
clientCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret") | ||
clientCmd.Flags().StringVarP(&clientID, "id", "i", hostname, "client id") | ||
clientCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "rpc host") | ||
clientCmd.Flags().StringVarP(&appSecret, "app", "a", "", "app secret") | ||
|
||
clientCmd.Flags().IntVarP(&rpcPort, "rpc-port", "c", 0, "rpc port") | ||
clientCmd.Flags().IntVarP(&apiPort, "api-port", "p", 0, "api port") | ||
|
||
clientCmd.Flags().StringVarP(&apiScheme, "api-scheme", "e", "", "api scheme") | ||
} | ||
|
||
func initLogger() { | ||
logrus.SetReportCaller(true) | ||
} | ||
|
||
func patchConfig(host, secret string, rpcPort, apiPort int) { | ||
if len(host) != 0 { | ||
conf.Get().Master.RPCHost = host | ||
conf.Get().Master.APIHost = host | ||
} | ||
if len(secret) != 0 { | ||
conf.Get().App.Secret = secret | ||
} | ||
if rpcPort != 0 { | ||
conf.Get().Master.RPCPort = rpcPort | ||
} | ||
if apiPort != 0 { | ||
conf.Get().Master.APIPort = apiPort | ||
} | ||
} |
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,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/VaalaCat/frp-panel/conf" | ||
"github.com/VaalaCat/frp-panel/rpc" | ||
) | ||
|
||
func main() { | ||
initLogger() | ||
initCommand() | ||
conf.InitConfig() | ||
rpc.InitRPCClients() | ||
|
||
rootCmd.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