Exemple #1
0
func (ac *Application) Ping(c *cli.Context) {
	message := c.String("message")
	host := vapi.HostDefaultPort(c.String("host"), vapi.DefaultPortString)

	fmt.Printf("ping: host %s: message: %s\n", host, message)

	log.Tracef("request-secret:%s", ac.Cfg.Rpc.Secret)

	md := metadata.Pairs("request-secret", ac.Cfg.Rpc.Secret)
	ctx := context.Background()
	ctx = metadata.NewContext(ctx, md)

	dopts := vapi.DefaultDialOptions()

	con, err := vapi.Connect(host, dopts)
	if err != nil {
		log.Warnf("Connect %s: %s", host, err)
	}

	ping := &vapi.PingRequest{
		Message: message,
	}

	res, err := con.Client.Ping(ctx, ping)
	if err != nil {
		log.Warnf("Ping %s: %s", host, err)
	}

	fmt.Printf("%#v\n", res)

}
Exemple #2
0
// parse a url path and turn it into a list path request
func (s *Server) parseRequest(path string) (*types.ListPathRequest, error) {
	tmp := strings.Split(path, "/")

	identity := ""
	if strings.HasPrefix(tmp[1], "~") {
		identity = tmp[1][1:]
	}
	if identity == "" {
		return nil, fmt.Errorf("empty identity")
	}

	var username string
	var server string

	idx := strings.Index(identity, "@")
	if idx >= 0 {
		username = identity[:idx]
		server = identity[idx+1:]
		server = vapi.HostDefaultPort(server, vapi.DefaultPortString)
	} else {
		username = identity
	}

	res := &types.ListPathRequest{
		Server:     server,
		ServerName: server,
		User:       username,
		Path:       "/" + strings.Join(tmp[2:], "/"),
	}

	log.Tracef("user=%s: path %s return %+v", username, path, res)

	return res, nil

}
Exemple #3
0
func (me *DashboardHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Tracef("request %s", r.URL)
	log.Tracef("%#v", me)

	data := &DashboardData{
		Username:   me.Username,
		UrlPrefix:  "/~" + me.Username,
		ServerData: make(map[string]*ServerData, 0),
	}

	// local host server data
	req := &types.ListPathRequest{
		User: me.Username,
	}
	v, err := me.VoyFile.Load(req)
	if err != nil {
		log.Warnf("Load %s", err)
		return
	}
	data.ServerData["localhost"] = &ServerData{
		Server:     "localhost",
		ServerAddr: "localhost",
		Voy:        v,
	}

	log.Tracef("servers %s", v.Servers)

	dopts := vapi.DefaultDialOptions()
	for server, server_addr := range v.Servers {
		hostport := vapi.HostDefaultPort(server_addr, vapi.DefaultPortString)
		conn, err := vapi.Connect(hostport, dopts)
		if err != nil {
			log.Warnf("unable to connect to %s: %s", hostport, err)
			continue
		}

		creq := &vapi.ConfigRequest{
			User: me.Username,
		}

		cres, err := conn.Client.GetConfig(me.Ctx, creq)
		if err != nil {
			log.Warnf("unable to get config to %s: %s", hostport, err)
			continue
		}

		vf := &voy.VoyFile{
			Allow:   cres.Allow,
			Alias:   cres.Alias,
			Servers: cres.Servers,
		}
		data.ServerData[server] = &ServerData{
			Server:     server,
			ServerAddr: server_addr,
			Voy:        vf,
		}

	}

	tmplData, err := asset.Asset("dashboard.html")
	if err != nil {
		WriteError(w, r, "template: %s", err)
		return
	}

	tmpl := template.Must(template.New("dashboard.html").Parse(string(tmplData)))

	err = tmpl.Execute(w, data)
	if err != nil {
		WriteError(w, r, "template render: %s", err)
		return
	}

}