Merge remote-tracking branch 'origin/local-ss' into local-ss
This commit is contained in:
29
agent-wdd/cmd/Acme.go
Normal file
29
agent-wdd/cmd/Acme.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// addAcmeSubcommands acme的相关任务
|
||||||
|
func addAcmeSubcommands(cmd *cobra.Command) {
|
||||||
|
proxyCmd := &cobra.Command{
|
||||||
|
Use: "proxy [url] [dest]",
|
||||||
|
Short: "使用代理下载",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Downloading with proxy: %s -> %s\n", args[0], args[1])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
unproxyCmd := &cobra.Command{
|
||||||
|
Use: "unproxy [url] [dest]",
|
||||||
|
Short: "不使用代理下载",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Downloading without proxy: %s -> %s\n", args[0], args[1])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.AddCommand(proxyCmd, unproxyCmd)
|
||||||
|
}
|
||||||
73
agent-wdd/cmd/Base.go
Normal file
73
agent-wdd/cmd/Base.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 添加base子命令
|
||||||
|
func addBaseSubcommands(cmd *cobra.Command) {
|
||||||
|
// 1.1 docker
|
||||||
|
dockerCmd := &cobra.Command{
|
||||||
|
Use: "docker",
|
||||||
|
Short: "Docker相关操作",
|
||||||
|
}
|
||||||
|
addDockerSubcommands(dockerCmd)
|
||||||
|
|
||||||
|
// 1.2 dockercompose
|
||||||
|
dockerComposeCmd := &cobra.Command{
|
||||||
|
Use: "dockercompose",
|
||||||
|
Short: "Docker Compose相关操作",
|
||||||
|
}
|
||||||
|
addDockerComposeSubcommands(dockerComposeCmd)
|
||||||
|
|
||||||
|
// 其他base子命令...
|
||||||
|
|
||||||
|
cmd.AddCommand(
|
||||||
|
dockerCmd,
|
||||||
|
dockerComposeCmd,
|
||||||
|
// 其他命令...
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加docker子命令
|
||||||
|
func addDockerSubcommands(cmd *cobra.Command) {
|
||||||
|
onlineCmd := &cobra.Command{
|
||||||
|
Use: "online [version]",
|
||||||
|
Short: "网络安装Docker",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Installing Docker version: %s\n", args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCmd := &cobra.Command{
|
||||||
|
Use: "remove",
|
||||||
|
Short: "卸载Docker",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Removing Docker...")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
localCmd := &cobra.Command{
|
||||||
|
Use: "local [path]",
|
||||||
|
Short: "本地安装Docker",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Installing Docker from: %s\n", args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.AddCommand(onlineCmd, removeCmd, localCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addDockerComposeSubcommands(cmd *cobra.Command) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// addToolsSubcommands 利用本机的yum,apt等从网络安装常用的软件
|
||||||
|
func addToolsSubcommands(cmd *cobra.Command) {
|
||||||
|
// 检测本机使用的包安装方式为apt还是yum
|
||||||
|
// 检查本机
|
||||||
|
//
|
||||||
|
}
|
||||||
7
agent-wdd/cmd/Config.go
Normal file
7
agent-wdd/cmd/Config.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
|
func addConfigSubcommands(cmd *cobra.Command) {
|
||||||
|
|
||||||
|
}
|
||||||
31
agent-wdd/cmd/Download.go
Normal file
31
agent-wdd/cmd/Download.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 示例:添加download子命令
|
||||||
|
func addDownloadSubcommands(cmd *cobra.Command) {
|
||||||
|
proxyCmd := &cobra.Command{
|
||||||
|
Use: "proxy [url] [dest]",
|
||||||
|
Short: "使用代理下载",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Downloading with proxy: %s -> %s\n", args[0], args[1])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
unproxyCmd := &cobra.Command{
|
||||||
|
Use: "unproxy [url] [dest]",
|
||||||
|
Short: "不使用代理下载",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Downloading without proxy: %s -> %s\n", args[0], args[1])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.AddCommand(proxyCmd, unproxyCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据需求补充其他子命令的添加函数...
|
||||||
38
agent-wdd/cmd/Proxy.go
Normal file
38
agent-wdd/cmd/Proxy.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 添加proxy子命令
|
||||||
|
func addProxySubcommands(cmd *cobra.Command) {
|
||||||
|
xrayCmd := &cobra.Command{
|
||||||
|
Use: "xray",
|
||||||
|
Short: "Xray相关操作",
|
||||||
|
}
|
||||||
|
xrayCmd.AddCommand(
|
||||||
|
&cobra.Command{
|
||||||
|
Use: "install",
|
||||||
|
Short: "安装Xray",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Installing Xray...")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 其他xray子命令...
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd.AddCommand(
|
||||||
|
xrayCmd,
|
||||||
|
&cobra.Command{
|
||||||
|
Use: "vmess",
|
||||||
|
Short: "设置VMESS代理",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Setting up VMESS proxy...")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 其他proxy子命令...
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他命令结构类似,根据需求补充完整...
|
||||||
7
agent-wdd/cmd/WddHost.go
Normal file
7
agent-wdd/cmd/WddHost.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
|
func addWddSubcommands(cmd *cobra.Command) {
|
||||||
|
|
||||||
|
}
|
||||||
7
agent-wdd/cmd/Zsh.go
Normal file
7
agent-wdd/cmd/Zsh.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
|
func addZshSubcommands(cmd *cobra.Command) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -58,6 +58,97 @@ func initConfig() {
|
|||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
|
|
||||||
|
// 1. base命令
|
||||||
|
baseCmd := &cobra.Command{
|
||||||
|
Use: "base",
|
||||||
|
Short: "服务器基础操作",
|
||||||
|
}
|
||||||
|
addBaseSubcommands(baseCmd)
|
||||||
|
|
||||||
|
// 2. zsh命令
|
||||||
|
zshCmd := &cobra.Command{
|
||||||
|
Use: "zsh",
|
||||||
|
Short: "zsh相关的内容",
|
||||||
|
}
|
||||||
|
addZshSubcommands(zshCmd)
|
||||||
|
|
||||||
|
// 3. proxy命令
|
||||||
|
proxyCmd := &cobra.Command{
|
||||||
|
Use: "proxy",
|
||||||
|
Short: "主机代理相关的内容",
|
||||||
|
}
|
||||||
|
addProxySubcommands(proxyCmd)
|
||||||
|
|
||||||
|
// 4. acme命令
|
||||||
|
acmeCmd := &cobra.Command{
|
||||||
|
Use: "acme",
|
||||||
|
Short: "acme相关的内容",
|
||||||
|
}
|
||||||
|
addAcmeSubcommands(acmeCmd)
|
||||||
|
|
||||||
|
// 5. wdd命令
|
||||||
|
wddCmd := &cobra.Command{
|
||||||
|
Use: "wdd",
|
||||||
|
Short: "WDD相关操作",
|
||||||
|
}
|
||||||
|
addWddSubcommands(wddCmd)
|
||||||
|
|
||||||
|
// 6. security命令
|
||||||
|
securityCmd := &cobra.Command{
|
||||||
|
Use: "security",
|
||||||
|
Short: "安全相关操作",
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. info命令
|
||||||
|
infoCmd := &cobra.Command{
|
||||||
|
Use: "info",
|
||||||
|
Short: "打印主机详细信息",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
// 实现info逻辑
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. version命令
|
||||||
|
versionCmd := &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "打印版本信息",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
// 实现version逻辑
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. config命令
|
||||||
|
configCmd := &cobra.Command{
|
||||||
|
Use: "config",
|
||||||
|
Short: "配置文件管理",
|
||||||
|
}
|
||||||
|
addConfigSubcommands(configCmd)
|
||||||
|
|
||||||
|
// 10. download命令
|
||||||
|
downloadCmd := &cobra.Command{
|
||||||
|
Use: "download",
|
||||||
|
Short: "文件下载管理",
|
||||||
|
}
|
||||||
|
addDownloadSubcommands(downloadCmd)
|
||||||
|
|
||||||
|
// 添加所有根命令
|
||||||
|
rootCmd.AddCommand(
|
||||||
|
baseCmd,
|
||||||
|
zshCmd,
|
||||||
|
proxyCmd,
|
||||||
|
acmeCmd,
|
||||||
|
wddCmd,
|
||||||
|
securityCmd,
|
||||||
|
infoCmd,
|
||||||
|
versionCmd,
|
||||||
|
configCmd,
|
||||||
|
downloadCmd,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
67
agent-wdd/config/Info.go
Normal file
67
agent-wdd/config/Info.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AgentServerInfo struct {
|
||||||
|
NetworkInfo
|
||||||
|
CPUInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type NetworkInfo struct {
|
||||||
|
Interfaces []InterfaceInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type InterfaceInfo struct {
|
||||||
|
Name string
|
||||||
|
HardwareAddr string
|
||||||
|
Addrs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetworkInfo() (*NetworkInfo, error) {
|
||||||
|
interfaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var networkInfo NetworkInfo
|
||||||
|
for _, iface := range interfaces {
|
||||||
|
var addrs []string
|
||||||
|
addresses, err := iface.Addrs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, addr := range addresses {
|
||||||
|
addrs = append(addrs, addr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
interfaceInfo := InterfaceInfo{
|
||||||
|
Name: iface.Name,
|
||||||
|
HardwareAddr: iface.HardwareAddr.String(),
|
||||||
|
Addrs: addrs,
|
||||||
|
}
|
||||||
|
networkInfo.Interfaces = append(networkInfo.Interfaces, interfaceInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &networkInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type CPUInfo struct {
|
||||||
|
ModelName string
|
||||||
|
Cores int
|
||||||
|
Mhz float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCpuInfo() CPUInfo {
|
||||||
|
info := CPUInfo{}
|
||||||
|
info.ModelName = runtime.GOARCH
|
||||||
|
info.Cores = runtime.NumCPU()
|
||||||
|
info.Mhz = 0.0
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *AgentServerInfo) GetAgentInfo() {
|
||||||
|
|
||||||
|
}
|
||||||
25
agent-wdd/config/Network.go
Normal file
25
agent-wdd/config/Network.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CanConnectInternet 判定主机能否上网 请求 www.google.com 如果请求正常 返回2 如果超时三秒 请求baidu.com,如果没有错误返回1 如果错误返回0
|
||||||
|
func CanConnectInternet() int {
|
||||||
|
client := http.Client{
|
||||||
|
Timeout: 3 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := client.Get("https://www.google.com")
|
||||||
|
if err == nil {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.Get("https://www.baidu.com")
|
||||||
|
if err == nil {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -3,5 +3,8 @@ package main
|
|||||||
import "agent-wdd/cmd"
|
import "agent-wdd/cmd"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
// WDD 启动
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user