liftoff / GateOne

Gate One is an HTML5-powered terminal emulator and SSH client
http://liftoffsoftware.com/Products/GateOne
Other
6.28k stars 925 forks source link

Connecting to two Gateone servers in the same page #129

Open tabdulradi opened 12 years ago

tabdulradi commented 12 years ago

I want to put multiple Gateone terminals in the same page, but each of them is pointing to a different server. So I did the following test:

$ sudo ./gateone.py --port=10001 --origins="*" --command='irb'
$ sudo ./gateone.py --port=10002 --origins="*" --command="ipython"
<!DOCTYPE html>
<html>
    <head>
                <script src="https://127.0.0.1:10001/static/gateone.js"></script>
                <title>Multi-GO Test</title>
    </head>
    <body>
                <div style="width: 60em; height: 30em; border: 1px solid red"><div id='GO1'></div></div>
                <div style="width: 60em; height: 30em; border: 1px solid red"><div id='GO2'></div></div>
        </body>

        <script>
                GateOne.init({goURL: "https://127.0.0.1:10001/", goDiv: "#GO1"});
                GateOne.init({goURL: "https://127.0.0.1:10002/", goDiv: "#GO2"});
        </script>
</html>

Then I put this html instead of /templates/index.html, in the first server, and opened it. It seems to work at first, but then I got some warnings about shortcuts

gateone.js (line 1209)
2012-08-30 08:55:29 WARNING Overwriting existing shortcut for: KEY_L
combined_js (line 3073)
2012-08-30 08:55:29 WARNING Overwriting existing shortcut for: KEY_F1
combined_js (line 3073)
2012-08-30 08:55:29 WARNING Overwriting existing shortcut for: KEY_S
combined_js (line 3073)
2012-08-30 08:55:29 WARNING Overwriting existing shortcut

Finally I get this message about accepting SSL http://imgur.com/bwXDZ for a fraction of a second then the page go back one level in history!

tabdulradi commented 12 years ago

Am I doing it wrong? Is there any better way to connect to multiple servers in the same page? I am thinking to use IFrames instead, to solve my problem.

liftoff commented 12 years ago

Calling GateOne.init() twice on the same page isn't supported... Yet. The problem is that GateOne stores all of the terminals' settings in GateOne.terminals[termNum]. If you call GateOne.init() and open a terminal it will store that terminal's information in GateOne.terminals[1]. then you call GateOne.init() again and it will overwrite GateOne.terminals[1].

Also, the WebSocket is stored in GateOne.ws. When you open up that second connection it will overwrite GateOne.ws, leaving the old WebSocket in a sort of limbo state.

In the short term I may be able to work around this problem by using the prefix like so: GateOne.terminals[GateOne.prefs.prefix+termNum] but that's really not the best way to do it (it should work though). I'll play around with that and see if I can get it working without having to make too many changes. If it doesn't "just work" after a little bit of search/replace it will have to wait until the next version.

For reference, nearly all other aspects of Gate One should be OK with multiple instances like that but you need to make sure you call GateOne.init() with a different prefix for each div you're attaching it to.

For the next version of Gate One I will be looking at changing how Gate One is initialized to be more like other JavaScript libraries. Probably something like "Go1 = new GateOne(); Go2 = new GateOne();".

I should also mention that Gate One will soon be supporting multiple terminal "types" that run different commands on the server. So you could call newTerminal(termNum, type) and depending on that type value it would launch either the 'command' in server.conf or something different (still haven't worked out how I want to configure it... Probably just a 'commands = {'default': 'ssh_connect.py ...', 'ipython': 'ipython', ...} option).

In the mean time you can work around this issue by having a single Gate One instance that controls multiple terminals simultaneously... You just need to configure Gate One to run a command-line program that allows one to select the terminal type to bring up. So you call newTerminal() and then just send it a string like: GateOne.Input.sendString('ipython\n');

liftoff commented 12 years ago

OK, I've done some investigating and I believe I've determined most of what needs to change in order to support multiple instances of GateOne on the same page. It is too much to change for 1.1. However, it will be one of the first things I change after 1.1 is released.

It's not that it will be complicated it is just that it is too much to change so close to the release of 1.1. There's too many bugs that could be introduced.

I'm going to label this issue as a feature request and leave it in the queue until I can get GateOne working as intended.

liftoff commented 12 years ago

I was thinking about this today and came up with an easier/alternate workaround: Just include two copies of gateone.js on the same page. Just do a search/replace "GateOne" with "Gate2" or something like that on one of the copies. Then just call Gate2.init() on the second copy.

Sure, it isn't efficient but it'll work until I get instantiation working which should be shortly after 1.1.