Module: Pssh

Defined in:
lib/pssh.rb,
lib/pssh/cli.rb,
lib/pssh/pty.rb,
lib/pssh/web.rb,
lib/pssh/client.rb,
lib/pssh/socket.rb,
lib/pssh/console.rb,
lib/pssh/version.rb

Defined Under Namespace

Classes: CLI, Client, Console, Pty, Socket, Web

Constant Summary collapse

DEFAULT_IO_MODE =
'rw'
DEFAULT_SOCKET_PREFIX =
'pssh'
DEFAULT_PORT =
8022
DEFAULT_CACHE_LENGTH =
16384
PSSH_DOMAIN =
'pssh.herokuapp.com'
VERSION =
"0.4.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_lengthObject

Public: This sets the amount of data that will be stored to show new connections when they join.



76
77
78
# File 'lib/pssh.rb', line 76

def cache_length
  @cache_length
end

.clientObject

Returns the value of attribute client.



38
39
40
# File 'lib/pssh.rb', line 38

def client
  @client
end

.commandObject

Public: This is the tool which we are going to use for our multiplexing. If we’re currently in a tmux or screen session, that is the first option, then it checks if tmux or screen is installed, and then it resorts to a plain old shell.

Returns a Symbol.



101
102
103
104
105
106
# File 'lib/pssh.rb', line 101

def command
  @command ||=
    (ENV['TMUX'] && :tmux) ||
    (ENV['STY'] && :screen) ||
    :shell
end

.io_modeObject

Public: This sets whether the connecting user can just view or can also write to the screen. Values are ‘rw, ’r’, and ‘w’.

Returns a String.



59
60
61
# File 'lib/pssh.rb', line 59

def io_mode
  @io_mode ||= DEFAULT_IO_MODE
end

.open_sessionsObject



51
52
53
# File 'lib/pssh.rb', line 51

def open_sessions
  @open_sessions ||= {}
end

.portObject



47
48
49
# File 'lib/pssh.rb', line 47

def port
  @port ||= DEFAULT_PORT
end

.promptObject

Public: This is the prompt character that shows up at the beginning of Pssh’s console.

Returns a String.



120
121
122
# File 'lib/pssh.rb', line 120

def prompt
  @prompt ||= "\u26a1 "
end

.ptyObject

Returns the value of attribute pty.



40
41
42
# File 'lib/pssh.rb', line 40

def pty
  @pty
end

.socketObject

Returns the value of attribute socket.



39
40
41
# File 'lib/pssh.rb', line 39

def socket
  @socket
end

.socket_pathObject

Returns the value of attribute socket_path.



36
37
38
# File 'lib/pssh.rb', line 36

def socket_path
  @socket_path
end

.socket_prefixObject

Public: This is the prefix that will be used to set up the socket for tmux or screen.

Returns a String.



83
84
85
# File 'lib/pssh.rb', line 83

def socket_prefix
  @socket_prefix ||= DEFAULT_SOCKET_PREFIX
end

.webObject

Returns the value of attribute web.



41
42
43
# File 'lib/pssh.rb', line 41

def web
  @web
end

Class Method Details

.base_pathObject



43
44
45
# File 'lib/pssh.rb', line 43

def base_path
  File.dirname(__FILE__) + "/.."
end

.configure {|_self| ... } ⇒ Object

Public: Allow configuring details of Pssh by making use of a block.

Returns True.

Yields:

  • (_self)

Yield Parameters:

  • _self (Pssh)

    the object that the method was called on



111
112
113
114
# File 'lib/pssh.rb', line 111

def configure
  yield self
  true
end

.create_session(username = nil) ⇒ Object

Public: Generates a random id for a session and stores it to a list.

Returns a String.



127
128
129
130
131
# File 'lib/pssh.rb', line 127

def create_session(username=nil)
  id = SecureRandom.uuid
  self.open_sessions[id] = username
  id
end

.default_socket_pathObject

Public: This is the default socket path that will be used if one is not provided in the command line arguments.

Returns a String.



91
92
93
# File 'lib/pssh.rb', line 91

def default_socket_path
  @socket_path ||= "#{socket_prefix}-#{SecureRandom.uuid}"
end

.share_urlObject

Public: This method retrieves the current IP address and compresses it into a short url that can be shared to redirect to your site.



65
66
67
68
69
70
71
72
# File 'lib/pssh.rb', line 65

def share_url
  return @share_url if @share_url
  ip = open("http://#{PSSH_DOMAIN}/ip").read
         .split('.')
         .map { |x| x.to_i.to_s(36).rjust(2,'0') }
         .join('')
  @share_url = "http://#{PSSH_DOMAIN}/#{ip}#{port.to_i.to_s(36)}"
end