Пример #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)

}
Пример #2
0
func (s *Server) RemoteRequest(w http.ResponseWriter, r *http.Request, req *types.ListPathRequest) {

	// dispatch handler to appropriate handler based on content

	log.Tracef("remote request %s", req)

	dopts := vapi.DefaultDialOptions()

	c, err := vapi.Connect(req.ServerName, dopts)
	if err != nil {
		WriteError(w, r, "remote:%s connect %s: %s", req.ServerName, req.Path, err)
		return
	}

	list_req := &vapi.ListRequest{
		User: req.User,
		Path: req.Path,
	}

	res, err := c.Client.ListFiles(s.Ctx, list_req)
	if err != nil {
		WriteError(w, r, "remote:%s list files %s: %s", req.ServerName, req.Path, err)
		return
	}
	log.Tracef("response layout:%s files:%d",
		res.Layout, len(res.Files))

	hndlr := &handler.Handler{
		Username:     req.User,
		UrlPrefix:    res.UrlPrefix,
		RemoteServer: res.RemoteServer,
		RelPath:      res.RelPath,
		LocalPath:    res.LocalPath,
		Template:     s.Template,
	}

	if res.IsDir == false {
		// deliver the object normally
		handler.NewListHandler(hndlr).ServeHTTP(w, r)
		return
	}

	hndlr.Layout = filetype.TypeFromString(res.Layout)
	files := make([]*types.File, 0)
	for _, file := range res.Files {
		f := &types.File{
			IsDir: file.IsDir,
			Name:  file.Name,
			Size:  file.Size,
		}
		files = append(files, f)
	}
	hndlr.Files = files

	log.Debugf("dispatch %s user:%s files:%d",
		hndlr.Layout, req.User, len(files))

	reqHandler := s.Factory.MakeHandler(hndlr)
	if reqHandler == nil {
		handler.NewListHandler(hndlr).ServeHTTP(w, r)
	} else {
		reqHandler.ServeHTTP(w, r)
	}

}
Пример #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
	}

}