Exemple #1
0
//Start vnc server now it's xpra and connect to server
func (c *vncRemoton) Start(session *remoton.SessionClient, password string) error {
	var err error
	var port string
	port, c.iport = common.FindFreePortTCP(6900)

	addrSrv := net.JoinHostPort("localhost", port)
	c.xpra.SetPassword(password)
	err = c.xpra.Bind(addrSrv)
	if err != nil {
		log.Error("vncRemoton:", err)
		return err
	}
	conn, err := net.DialTimeout("tcp", addrSrv, time.Second*3)
	if err != nil {
		c.xpra.Terminate()
		return err
	}
	conn.Close()
	log.Println("started xpra")

	go c.startNat(addrSrv)
	go c.startRPC(
		common.Capabilities{
			XpraVersion: c.xpra.Version(),
		},
		session,
		addrSrv)
	go c.start(session, addrSrv)
	return nil
}
Exemple #2
0
//startNat add support for nat
func (c *vncRemoton) startNat(addrSrv string) error {
	var err error
	var eport string
	eport, c.eport = common.FindFreePortTCP(44442)
	c.natif, err = nat.Parse("any")
	if err != nil {
		log.Error(err)
		return err
	}

	if _, err = c.natif.ExternalIP(); err != nil {
		return err
	}

	if err = c.natif.DeleteMapping("TCP", 9932, c.eport); err != nil {
		log.Infof("can't delete external map: %s", err.Error())
	}

	if err = c.natif.AddMapping("TCP", 9932, c.eport, "remoton", time.Hour); err != nil {
		log.Infof("can't add mapping external map: %d -> %d", 9932, c.eport)
		return err
	}

	c.elistener, err = net.Listen("tcp", net.JoinHostPort("0.0.0.0", eport))
	if err != nil {
		return err
	}
	log.Println("Nat enabled")
	//redict from public to localhost
	go func() {
		eip, err := c.natif.ExternalIP()
		if err != nil {
			return
		}

		for {
			conn, err := c.elistener.Accept()
			if err != nil {
				break
			}
			//only allow frow gateway
			if !strings.EqualFold(conn.RemoteAddr().String(), eip.String()) {
				conn.Close()
				continue
			}
			proxy, err := net.DialTimeout("tcp", addrSrv, time.Second)
			if err != nil {
				break
			}
			go io.Copy(conn, proxy)
			go io.Copy(proxy, conn)
		}
	}()

	return nil
}
Exemple #3
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
}