mirror of
https://gogs.blitter.com/RLabs/xs
synced 2024-08-14 10:26:42 +00:00
Initial (buggy) support for 'fancy arg' style ala ssh: eg user@example.org:port:path
This commit is contained in:
parent
f48b0c17ed
commit
5eb7d4d1e6
1 changed files with 70 additions and 6 deletions
|
@ -34,7 +34,8 @@ type cmdSpec struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
defPort = "2000"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get terminal size using 'stty' command
|
// Get terminal size using 'stty' command
|
||||||
|
@ -52,6 +53,53 @@ func GetSize() (cols, rows int, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseFancyEndpointArg(a []string, dp string) (user, host, port, path string) {
|
||||||
|
//TODO: Look for non-option fancyArg of syntax user@host:filespec to set -r,-t and -u
|
||||||
|
// Consider: whether fancyArg is src or dst file depends on flag.Args() index;
|
||||||
|
// fancyArg as last flag.Args() element denotes dstFile
|
||||||
|
// fancyArg as not-last flag.Args() element denotes srcFile
|
||||||
|
// * throw error if >1 fancyArgs are found in flags.Args()
|
||||||
|
var fancyUser, fancyHost, fancyPort, fancyPath string
|
||||||
|
for i, arg := range flag.Args() {
|
||||||
|
if strings.Contains(arg, ":") || strings.Contains(arg, "@") {
|
||||||
|
fancyArg := strings.Split(flag.Arg(i), "@")
|
||||||
|
var fancyHostPortPath []string
|
||||||
|
if len(fancyArg) < 2 {
|
||||||
|
//TODO: no user specified, use current
|
||||||
|
fancyUser = "[default:getUser]"
|
||||||
|
fancyHostPortPath = strings.Split(fancyArg[0], ":")
|
||||||
|
} else {
|
||||||
|
// user@....
|
||||||
|
fancyUser = fancyArg[0]
|
||||||
|
fancyHostPortPath = strings.Split(fancyArg[1], ":")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(fancyHostPortPath) > 2 {
|
||||||
|
// [user]@host[:port]:path
|
||||||
|
fancyPath = fancyHostPortPath[2]
|
||||||
|
}
|
||||||
|
if len(fancyHostPortPath) > 1 {
|
||||||
|
// [user]@host:port[:...] or [user]@host:path (default port)
|
||||||
|
fancyPort = fancyHostPortPath[1]
|
||||||
|
}
|
||||||
|
// [user]@host[:...[:...]]
|
||||||
|
fancyHost = fancyHostPortPath[0]
|
||||||
|
|
||||||
|
if fancyPort == "" {
|
||||||
|
fancyPort = dp
|
||||||
|
}
|
||||||
|
|
||||||
|
if fancyPath == "" {
|
||||||
|
fancyPath = "."
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("fancyArgs: user:", fancyUser, "host:", fancyHost, "port:", fancyPort, "path:", fancyPath)
|
||||||
|
break // ignore multiple 'fancyArgs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fancyUser, fancyHost, fancyPort, fancyPath
|
||||||
|
}
|
||||||
|
|
||||||
// Demo of a simple client that dials up to a simple test server to
|
// Demo of a simple client that dials up to a simple test server to
|
||||||
// send data.
|
// send data.
|
||||||
//
|
//
|
||||||
|
@ -90,29 +138,45 @@ func main() {
|
||||||
flag.BoolVar(&dbg, "d", false, "debug logging")
|
flag.BoolVar(&dbg, "d", false, "debug logging")
|
||||||
flag.StringVar(&cAlg, "c", "C_AES_256", "cipher [\"C_AES_256\" | \"C_TWOFISH_128\" | \"C_BLOWFISH_64\"]")
|
flag.StringVar(&cAlg, "c", "C_AES_256", "cipher [\"C_AES_256\" | \"C_TWOFISH_128\" | \"C_BLOWFISH_64\"]")
|
||||||
flag.StringVar(&hAlg, "m", "H_SHA256", "hmac [\"H_SHA256\"]")
|
flag.StringVar(&hAlg, "m", "H_SHA256", "hmac [\"H_SHA256\"]")
|
||||||
flag.StringVar(&server, "s", "localhost:2000", "server hostname/address[:port]")
|
flag.StringVar(&server, "s", "localhost:"+defPort, "server hostname/address[:port]")
|
||||||
flag.StringVar(&altUser, "u", "", "specify alternate user")
|
flag.StringVar(&altUser, "u", "", "specify alternate user")
|
||||||
flag.StringVar(&authCookie, "a", "", "auth cookie")
|
flag.StringVar(&authCookie, "a", "", "auth cookie")
|
||||||
flag.BoolVar(&chaffEnabled, "e", true, "enabled chaff pkts (default true)")
|
flag.BoolVar(&chaffEnabled, "e", true, "enabled chaff pkts (default true)")
|
||||||
flag.UintVar(&chaffFreqMin, "f", 100, "chaff pkt freq min (msecs)")
|
flag.UintVar(&chaffFreqMin, "f", 100, "chaff pkt freq min (msecs)")
|
||||||
flag.UintVar(&chaffFreqMax, "F", 5000, "chaff pkt freq max (msecs)")
|
flag.UintVar(&chaffFreqMax, "F", 5000, "chaff pkt freq max (msecs)")
|
||||||
flag.UintVar(&chaffBytesMax, "B", 64, "chaff pkt size max (bytes)")
|
flag.UintVar(&chaffBytesMax, "B", 64, "chaff pkt size max (bytes)")
|
||||||
|
|
||||||
// Find out what program we are (shell or copier)
|
// Find out what program we are (shell or copier)
|
||||||
myPath := strings.Split(os.Args[0], string(os.PathSeparator))
|
myPath := strings.Split(os.Args[0], string(os.PathSeparator))
|
||||||
if myPath[len(myPath)-1] != "hkexcp" {
|
if myPath[len(myPath)-1] != "hkexcp" && myPath[len(myPath)-1] != "hkexcp.exe" {
|
||||||
// hkexsh accepts a command (-x) but not
|
// hkexsh accepts a command (-x) but not
|
||||||
// a srcpath (-r) or dstpath (-t)
|
// a srcpath (-r) or dstpath (-t)
|
||||||
flag.StringVar(&cmdStr, "x", "", "command to run (default empty - interactive shell)")
|
flag.StringVar(&cmdStr, "x", "", "command to run (default empty - interactive shell)")
|
||||||
flag.Parse()
|
|
||||||
} else {
|
} else {
|
||||||
// hkexcp accepts srcpath (-r) and dstpath (-t), but not
|
// hkexcp accepts srcpath (-r) and dstpath (-t), but not
|
||||||
// a command (-x)
|
// a command (-x)
|
||||||
flag.StringVar(©Src, "r", "", "copy srcpath")
|
flag.StringVar(©Src, "r", "", "copy srcpath")
|
||||||
flag.StringVar(©Dst, "t", "", "copy dstpath")
|
flag.StringVar(©Dst, "t", "", "copy dstpath")
|
||||||
}
|
}
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
if flag.NFlag() == 0 {
|
fancyUser, fancyHost, fancyPort, fancyPath := parseFancyEndpointArg(flag.Args(), defPort /* defPort */)
|
||||||
|
fmt.Println("fancyHost:", fancyHost)
|
||||||
|
if fancyUser != "" {
|
||||||
|
altUser = fancyUser
|
||||||
|
}
|
||||||
|
if fancyHost != "" {
|
||||||
|
server = fancyHost + ":" + fancyPort
|
||||||
|
fmt.Println("fancyHost sets server to", server)
|
||||||
|
}
|
||||||
|
if fancyPath != "" {
|
||||||
|
//TODO: srcPath or dstPath depends on other flag.Args
|
||||||
|
copyDst = fancyPath
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("server finally is:", server)
|
||||||
|
|
||||||
|
if flag.NFlag() == 0 && server == "" {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue