Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
specify a server
Browse files Browse the repository at this point in the history
  • Loading branch information
Visnu Pitiyanuvath committed Oct 3, 2010
1 parent d318ef4 commit b850800
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
public/*.css
public/stylesheets/*.css
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sshjs",
"name": "ssh-ios",
"description": "ssh for ios via websockets and node.js",
"author": "Fortnight Labs, LLC",
"version": "0.0.1",
Expand Down
34 changes: 0 additions & 34 deletions public/application.js

This file was deleted.

17 changes: 17 additions & 0 deletions public/javascripts/ansi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function($, window, document, undefined) {
var esc = new RegExp(String.fromCharCode(27) + '\\[([0-9;]*?m)', 'g');

$.ansi = {
colorize: function(data) {
var spans = 0;
data = $('<div>').text(data).html().replace(esc, function(m, p1) {
spans++;
return '<span class="e' + p1.replace(/[;m]/g, ' e') + '">';
});
for (var i = 0; i < spans; i++)
data += '</span>';

return data;
}
};
})(jQuery, window, document);
36 changes: 36 additions & 0 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$(function() {
$(':text:first').focus();

var $window = $(window),
$stdout = $('#stdout'),
$prompt = $('#prompt');

var socket = new io.Socket(null, {
transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
})
.on('message', function(data) {
$stdout.append($.ansi.colorize(data));
$window.scrollTo($prompt);
})
.connect();

$('form')
.submit(function() {
socket.send($(this).serialize());
$stdout.text('');
$prompt.focus();
return false;
})
.click(function(e) {
e.stopPropagation();
});

$prompt.keypress(function(e) {
socket.send(String.fromCharCode(e.which));
return false;
});

$(document).click(function() {
$prompt.focus();
});
});
17 changes: 14 additions & 3 deletions public/application.sass → public/stylesheets/application.sass
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
body, input
:font 10pt courier new, monospace

body
:background-color black
:color white
:font-family menlo, monospace
:background-color black

#stdout
:display inline

input
input[type=submit], button
:color white
:text-shadow 0px -1px 0px hsla(0, 0%, 0%, 0.1)
:border solid 1px hsla(0, 0%, 0%, 0.1)
:border-radius 3px
:background hsl(190, 80%, 50%) -webkit-gradient(linear, left top, left bottom, from(hsla(0, 100%, 100%, 0.8)), to(hsla(0, 0%, 80%, 0.8)))
input[type=submit]:active, button:active
:background hsl(190, 80%, 50%) -webkit-gradient(linear, left bottom, left top, from(hsla(0, 100%, 100%, 0.8)), to(hsla(0, 0%, 80%, 0.8)))

input#prompt
:color white
:background-color transparent
:border none
Expand Down
23 changes: 13 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ socket = io.listen(app);

socket.on('connection', function(client) {
var spawn = require('child_process').spawn,
ssh = spawn('ssh', ['-t', '-t', 'pinkyurl.com']),
running = true;

ssh.on('exit', function() { running = false; });
ssh.stderr.on('data', function(data) { client.send(data); });
ssh.stdout.on('data', function(data) { client.send(data); });
ssh = null;

client.on('message', function(data) {
if (!running) return;
if (data === '\r') data = '\n';
ssh.stdin.write(data);
if (!ssh) {
var params = require('querystring').parse(data);
ssh = spawn('ssh', ['-t', '-t', params.server]);
ssh.on('exit', function() { ssh = null; });
ssh.stderr.on('data', function(data) { client.send(data); });
ssh.stdout.on('data', function(data) { client.send(data); });
} else {
if (data === '\r') data = '\n';
ssh.stdin.write(data);
}
});

client.on('disconnect', function() {
if (running) ssh.kill();
if (ssh) ssh.kill();
ssh = null;
});
});

Expand Down
9 changes: 4 additions & 5 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
form#server
input( name: 'server', placeholder: 'server' )
input( type: 'submit', value: 'ssh' )
pre#stdout
input( type: 'text', autocapitalize: 'off', autocorrect: 'off' )
script( src: 'http://code.jquery.com/jquery.min.js', type: 'text/javascript' )
script( src: 'http://cdn.socket.io/stable/socket.io.js', type: 'text/javascript' )
script( src: '/jquery.scrollTo-1.4.2-min.js', type: 'text/javascript' )
script( src: '/application.js', type: 'text/javascript' )
input#prompt( type: 'text', autocapitalize: 'off', autocorrect: 'off' )
12 changes: 9 additions & 3 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
html( lang: "en" )
head
title ssh.js - ssh over websockets for iOS
meta( name: "viewport", content: "initial-scale=0.5,user-scalable=no" )
link( rel: "stylesheet", type: "text/css", href: "/application.css" )
body!= body
meta( name: "viewport", content: "user-scalable=no" )
link( rel: "stylesheet", type: "text/css", href: "/stylesheets/application.css" )
body
!= body
script( src: 'http://code.jquery.com/jquery.min.js', type: 'text/javascript' )
script( src: 'http://cdn.socket.io/stable/socket.io.js', type: 'text/javascript' )
script( src: '/javascripts/jquery.scrollTo-1.4.2-min.js', type: 'text/javascript' )
script( src: '/javascripts/ansi.js', type: 'text/javascript' )
script( src: '/javascripts/application.js', type: 'text/javascript' )

0 comments on commit b850800

Please sign in to comment.