2016-04-04 7 views
0

下のチュートリアルからsshのデモ用のguacamoleアプリケーションを作成しようとしました。guacamoleのsshのパラメータとしてhostnameを渡すにはどうすればいいですか

http://guac-dev.org/doc/gug/writing-you-own-guacamole-app.html

アプリは限り値はハードコードされたとしてうまく働きました。しかし、ユーザーからホスト名/ IPを取得する必要があります。私は以下のコードでrequest.getParameter()を使用しようとしたことを達成するために:?

package org.glyptodon.guacamole.net.example; 

import javax.servlet.http.HttpServletRequest; 
import org.glyptodon.guacamole.GuacamoleException; 
import org.glyptodon.guacamole.net.GuacamoleSocket; 
import org.glyptodon.guacamole.net.GuacamoleTunnel; 
import org.glyptodon.guacamole.net.InetGuacamoleSocket; 
import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel; 
import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket; 
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; 
import org.glyptodon.guacamole.servlet.GuacamoleHTTPTunnelServlet; 

public class TutorialGuacamoleTunnelServlet 
    extends GuacamoleHTTPTunnelServlet { 

    @Override 
    protected GuacamoleTunnel doConnect(HttpServletRequest request) 
     throws GuacamoleException { 

     // Create our configuration 
     String hostname = request.getParameter("hostname"); 
     GuacamoleConfiguration config = new GuacamoleConfiguration(); 
     config.setProtocol("ssh"); 
     config.setParameter("hostname", hostname); 
     config.setParameter("port", "22"); 

     // Connect to guacd - everything is hard-coded here. 
     GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
      new InetGuacamoleSocket("localhost", 4822), 
      config 
     ); 


     // Return a new tunnel which uses the connected socket 
     return new SimpleGuacamoleTunnel(socket); 

    } 

} 

をしかし、私は localhostのようにそれを使用しよう:8080 /ワカモレ-チュートリアル-0.9.9ホスト名= localhostを、動作しません。私は同じ値をハードコードしてもうまく動作します。 私を助けてください。

答えて

2

これらのパラメータをGuacamole.Clientのconnect()関数に渡すには、JavaScriptを使用する必要があります。 got from here

<script type="text/javascript"> 

    // Get display div from document 
    var display = document.getElementById("display"); 

    // Instantiate client, using an HTTP tunnel for communications. 
    var guac = new Guacamole.Client(
     new Guacamole.HTTPTunnel("tunnel") 
    ); 

    // Add client to display div 
    display.appendChild(guac.getDisplay().getElement()); 

    // Error handler 
    guac.onerror = function(error) { 
     alert(error); 
     console.log(error); 
    }; 
    // Connect 
    guac.connect('ip=192.168.99.100&user=root');** set parameters here** 

    // Disconnect on close 
    window.onunload = function() { 
     guac.disconnect(); 
    } 

    </script> 

とあなたのTutorialGuacamoleTunnelServletアクセスでこれら

config.setProtocol("ssh"); 
config.setParameter("hostname", request.getParameter("ip")); 
config.setParameter("username", request.getParameter("user")); 
+0

感謝として。しかし、それは私のユースケースに役立たないようです。 URLからこれらを取得する必要があります。どうやってやるの。 –

+1

あなたはjavascriptを使用してURLからデータを取得し、次にそれらを渡すことができますhttp://stackoverflow.com/a/901144/1315392 – vinay

関連する問題