mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Add support for UNIX domain admin sockets to yggdrasilctl
This commit is contained in:
		
							parent
							
								
									cd6030ec8f
								
							
						
					
					
						commit
						047b7d95a1
					
				
					 1 changed files with 20 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
package main
 | 
			
		||||
 | 
			
		||||
import "errors"
 | 
			
		||||
import "flag"
 | 
			
		||||
import "fmt"
 | 
			
		||||
import "strings"
 | 
			
		||||
import "net"
 | 
			
		||||
import "net/url"
 | 
			
		||||
import "sort"
 | 
			
		||||
import "encoding/json"
 | 
			
		||||
import "strconv"
 | 
			
		||||
| 
						 | 
				
			
			@ -12,20 +14,34 @@ import "os"
 | 
			
		|||
type admin_info map[string]interface{}
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	server := flag.String("endpoint", "localhost:9001", "Admin socket endpoint")
 | 
			
		||||
	server := flag.String("endpoint", "tcp://localhost:9001", "Admin socket endpoint")
 | 
			
		||||
	injson := flag.Bool("json", false, "Output in JSON format")
 | 
			
		||||
	flag.Parse()
 | 
			
		||||
	args := flag.Args()
 | 
			
		||||
 | 
			
		||||
	if len(args) == 0 {
 | 
			
		||||
		fmt.Println("usage:", os.Args[0], "[-endpoint=localhost:9001] [-json] command [key=value] [...]")
 | 
			
		||||
		fmt.Println("usage:", os.Args[0], "[-endpoint=proto://server] [-json] command [key=value] [...]")
 | 
			
		||||
		fmt.Println("example:", os.Args[0], "getPeers")
 | 
			
		||||
		fmt.Println("example:", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false")
 | 
			
		||||
		fmt.Println("example:", os.Args[0], "-endpoint=localhost:9001 getDHT")
 | 
			
		||||
		fmt.Println("example:", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT")
 | 
			
		||||
		fmt.Println("example:", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	conn, err := net.Dial("tcp", *server)
 | 
			
		||||
	var conn net.Conn
 | 
			
		||||
	u, err := url.Parse(*server)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		switch strings.ToLower(u.Scheme) {
 | 
			
		||||
		case "unix":
 | 
			
		||||
			conn, err = net.Dial("unix", (*server)[7:])
 | 
			
		||||
		case "tcp":
 | 
			
		||||
			conn, err = net.Dial("tcp", u.Host)
 | 
			
		||||
		default:
 | 
			
		||||
			err = errors.New("protocol not supported")
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		conn, err = net.Dial("tcp", *server)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue