Example #1
0
func (c *chatRemoton) start(session *remoton.SessionClient) {

	l := session.Listen("chat")

	for {
		wsconn, err := l.Accept()
		if err != nil {
			break
		}

		c.init()

		go func(remoteConn net.Conn) {
			c.cbSend[remoteConn] = func(msg string) {
				remoteConn.Write([]byte(msg))
			}

			for {
				buf := make([]byte, 32*512)
				rlen, err := remoteConn.Read(buf)
				if err != nil {
					delete(c.cbSend, remoteConn)
					break
				}
				if c.onRecv != nil {
					c.onRecv(strings.TrimSpace(string(buf[0:rlen])))
				}
			}

		}(wsconn)
	}

}
Example #2
0
func (c *vncRemoton) startRPC(caps common.Capabilities, session *remoton.SessionClient, addrSrv string) {
	l := session.Listen("rpc")
	srv := rpc.NewServer()
	srv.Register(&common.RemotonClient{
		Capabilities: &caps,
		NatIF:        c.natif,
	})
	srv.Accept(l)
}
Example #3
0
func (c *tunnelRemoton) Start(session *remoton.SessionClient, password string) error {
	if c.xpraSrv == nil {
		c.xpraSrv = &xpra.Xpra{}
	}
	c.xpraSrv.SetPassword(password)

	rpconn, err := session.Dial("rpc")
	if err != nil {
		return err
	}
	defer rpconn.Close()

	rpcclient := rpc.NewClient(rpconn)
	defer rpcclient.Close()

	var capsClient common.Capabilities
	err = rpcclient.Call("RemotonClient.GetCapabilities", struct{}{}, &capsClient)
	if err != nil {
		return err
	}
	if !strings.EqualFold(capsClient.XpraVersion, c.xpraSrv.Version()) {
		return fmt.Errorf("mismatch xpra version was %s expected %s",
			capsClient.XpraVersion, c.xpraSrv.Version())
	}

	serverDirect := false
	var clientExternalIP net.IP
	var clientExternalPort int
	err = rpcclient.Call("RemotonClient.GetExternalIP", struct{}{}, &clientExternalIP)
	if err == nil {
		rpcclient.Call("RemotonClient.GetExternalPort", struct{}{}, &clientExternalPort)
		conn, err := net.DialTimeout("tcp",
			fmt.Sprintf("%s:%d", clientExternalIP.String(), clientExternalPort),
			time.Second*3)
		if err == nil {
			conn.Close()
			serverDirect = true
		} else {
			log.Infof("failed connect direct to client %s:%d fallback to server",
				clientExternalIP, clientExternalPort)
		}

	}

	//BUG --auth=file xpra not work, so we secure it over tunnel SSL
	var clientOS string
	rpcclient.Call("RemotonClient.GetOS", struct{}{}, &clientOS)
	if clientOS == "windows" {
		serverDirect = false
	}

	if serverDirect {
		return c.srvDirect(session, clientExternalIP)
	}
	return c.srvTunnel(session)
}
Example #4
0
func (c *chatRemoton) Start(session *remoton.SessionClient) error {
	chatConn, err := session.Dial("chat")
	if err != nil {
		return err
	}
	c.conn = chatConn
	c.init()
	go c.handle()
	return nil
}
Example #5
0
func (c *tunnelRemoton) srvTunnel(session *remoton.SessionClient) error {
	port, _ := common.FindFreePortTCP(55123)
	addrSrv := "localhost:" + port
	log.Println("listen at " + addrSrv)
	listener, err := net.Listen("tcp", addrSrv)
	if err != nil {
		return err
	}
	c.listener = listener

	go func(listener net.Listener) {
		for {
			conn, err := listener.Accept()
			if err != nil {
				listener.Close()
				log.Error(err)
				break
			}
			remote, err := session.DialTCP("nx")
			if err != nil {
				log.Error(err)
				listener.Close()

				break
			}
			log.Println("new connection")
			go c.handle(conn, remote)
		}
	}(listener)

	log.Println("Xpra " + c.xpraSrv.Version() + " attaching to " + addrSrv)
	err = c.xpraSrv.Attach(addrSrv)
	if err != nil {
		listener.Close()
		return err
	}
	return nil
}
Example #6
0
func (c *vncRemoton) start(session *remoton.SessionClient, addrSrv string) {
	l := session.ListenTCP("nx")
	for {
		log.Println("vncRemoton.start: waiting connection")
		wsconn, err := l.Accept()
		if err != nil {
			log.Error(err)
			break
		}

		if c.onConnection != nil {
			c.onConnection(wsconn.RemoteAddr())
		}
		log.Println("vncRemoton.start: do tunneling")
		conn, err := net.Dial("tcp", addrSrv)
		if err != nil {
			log.Error("vncRemoton.start:", addrSrv, err)
			break
		}

		go c.handleTunnel(conn, wsconn)
	}
}