Пример #1
0
func executeChild(command *client.SegmentCommand, seg *Segment, chain bool) error {
	id := utils.Uuid()
	cinfo, err := createSegmentLocal(id, command.ChildInit, command.ChildTrig, &seg.Tail)
	if err != nil {
		return err
	}
	if chain {
		seg.Tail = *cinfo
	}
	seg.ChildId = id
	return nil
}
Пример #2
0
func executeTunnel(command *client.SegmentCommand, seg *Segment, udp bool) error {
	_, dst, err := createTunnel(command.Arg, udp)
	if err != nil {
		return err
	}
	urlCommand := client.SegmentCommand{Type: client.URL, Arg: dst.String()}
	command.ChildInit = append(command.ChildInit, urlCommand)
	c, err := client.NewClient(command.Arg, opts.config)
	if err != nil {
		return err
	}
	id := utils.Uuid()
	url, err := c.CreateSegment(id, command.ChildInit, command.ChildTrig)
	if err != nil {
		return err
	}
	seg.Tail.Proto, _, seg.Tail.Hostname, seg.Tail.Port, err = utils.ParseUrl(url)
	if err != nil {
		return err
	}
	seg.ChildHost = command.Arg
	seg.ChildId = id
	return nil
}
Пример #3
0
func parseSegment(args []string) (string, []client.SegmentCommand, []client.SegmentCommand, error) {
	id := utils.Uuid()
	s := client.SegmentCommand{}
	chain, tail, trigger := false, false, false
	command := ""
	cur := &s
	for len(args) > 0 {
		command, args = args[0], args[1:]
		var action *client.SegmentCommand
		switch command {
		case "id":
			id = parseName(&args)
			continue
		case "url":
			action = parseUrl(tail, &args)
		case "docker-ns":
			action = parseDockerNs(tail, &args)
		case "docker-run":
			action = parseDockerRun(tail, &args)
		case "child":
			action = parseChild()
			chain = true
		case "chain":
			action = parseChain()
			chain = true
		case "remote":
			action = parseRemote(&args)
			chain = true
		case "tunnel":
			action = parseTunnel(&args)
			chain = true
		case "udptunnel":
			action = parseUdptunnel(&args)
			chain = true
		case "tail":
			tail = true
			continue
		case "trigger":
			trigger = true
			tail = true
			continue
		default:
			log.Fatalf("Action %s not recognized", command)
		}
		if trigger {
			cur.AddTrig(action)
			if chain {
				cur = &cur.ChildTrig[len(cur.ChildTrig)-1]
				chain = false
				trigger = false
				tail = false
			}
		} else {
			cur.AddInit(action)
			if chain {
				cur = &cur.ChildInit[len(cur.ChildInit)-1]
				chain = false
				trigger = false
				tail = false
			}
		}
	}
	return id, s.ChildInit, s.ChildTrig, nil
}