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

autoConnectURL investigation #237

Open palohan opened 11 years ago

palohan commented 11 years ago

I initialize GateOne in my application like this: window.onload = function() { GateOne.init({url:'https://10.0.0.1/',autoConnectURL:'ssh://palo@localhost:22', theme="solarized"}); }

I put this statement in gateone.js, line 256, to print GateOne.prefs object to Firebug console // Update GateOne.prefs with the settings provided in the calling page for (var setting in prefs) { go.prefs[setting] = prefs[setting]; } console.log(prefs);
and autoConnectURL is there Object { url="https://10.0.0.1/", autoConnectURL="ssh://palo@localhost:22", theme="solarized"}

But then when I try to print go.prefs.autoConnectURL in autoConnect function in ssh.js, it is set to null. Then if I comment the line checking if it isn't null and just pass an ssh URL manually with sendstring, it works OK.

autoConnect: function(term, termUndefined) { /**:GateOne.SSH.autoConnect()

    Automatically connects to `GateOne.prefs.autoConnectURL` if it set.
    */
    console.log(JSON.stringify(go.prefs.autoConnectURL));
    //if (go.prefs.autoConnectURL) {console.log(JSON.stringify(go.prefs.autoConnectURL)+term+termUndefined);
        // Only execute the autoConnectURL if this is a *new* terminal so resumed terminals don't get spammed with the autoConnectURL
        if (termUndefined) {
            setTimeout(function () {
                //go.Terminal.sendString(go.prefs.autoConnectURL+'\n');
                go.Terminal.sendString('ssh://palo:basketbal@localhost:22'+'\n');
            }, 500);
        }
    //}
}

So my conclusion is the autoConnectURL gets set to null somewhere along the way, while the rest of the passed prefs don't. So please Dan, have a look at this.

liftoff commented 11 years ago

How bizarre! I'll figure it out...

liftoff commented 11 years ago

I just pushed a commit that should fix this. I think when I moved that setting to ssh.js (from gateone.js) I copied a portion of the code I shouldn't have.

Please pull the latest code and let me know how it goes. Thanks.

palohan commented 11 years ago

It works now, all good! ...can't believe I couldn't spot it myself! :)

palohan commented 11 years ago

One more thing...when I try to pass password in url, I always get that exception with os.setsid in ssh_connect.py I tried a simple solution that somehow works:
First, I changed this if-else block a little bit: if password:

Create a temporary script to use with SSH_ASKPASS

    # temp = tempfile.NamedTemporaryFile(delete=False)
    # os.chmod(temp.name, 0o700)
    # temp.write('#!/bin/sh\necho "%s"\n' % password)
    # temp.close()
    # env['SSH_ASKPASS'] = temp.name
    # env['DISPLAY'] = ':9999'
    # This removes the temporary file in a timely manner
    # Popen("sleep 15 && /bin/rm -f %s" % temp.name, shell=True)
    # 15 seconds should be enough even for slow connections/servers
    # It's a tradeoff:  Lower number, more secure.  Higher number, less likely to fail
    <strong>sshpass="sshpass -p %s " % password
else:
    sshpass=""</strong></code><br>sshpass -p passes a password to ssh uninteractively (damn why my intendation doesn't work..)<br>

Then I just changed a few lines more: script = wrapper_script.format( socket=socket, cmd=sshpass+" ".join(args), temp=script_path)
Finally, I commented lines with os.setsid # if password:

SSH_ASKPASS needs some special handling

    # os.setsid() # This is the key</code><br>

And BAM, somehow I can pass password in URL without getting a stroke. I know it's a primitive solution, but there's no need to store the password anywhere, change env variables or anything. And that definetly works for me