def initialize(self):
"""
Called inside of :meth:`TerminalApplication.initialize` shortly after the
WebSocket is instantiated. Attaches our two `terminal:authenticate` events
(to create the user's .ssh dir and send our CSS template) and ensures that
the ssh_connect.py script is executable.
"""
ssh_connect_path = os.path.join(PLUGIN_PATH, 'scripts', 'ssh_connect.py')
if os.path.exists(ssh_connect_path):
import stat
st = os.stat(ssh_connect_path)
if not bool(st.st_mode & stat.S_IXOTH):
try:
os.chmod(ssh_connect_path, 0o755)
except OSError:
ssh_log.error(_(
"Could not set %s as executable. You will need to 'chmod "
"a+x' that script manually.") % ssh_connect_path)
user_msg = _(
"Error loading SSH plugin: The ssh_connect.py script is "
"not executable. See the logs for more details.")
send_msg = partial(self.ws.send_message, user_msg)
events = ["terminal:authenticate", "terminal:new_terminal"]
self.on(events, send_msg)
self.ssh_log = go_logger("gateone.terminal.ssh", plugin='ssh')
# NOTE: Why not use the 'Events' hook for these? You can't attach two
# functions to the same event via that mechanism because it's a dict
# (one would override the other).
# An alternative would be to write a single function say, on_auth() that
# calls both of these functions then assign it to 'terminal:authenticate' in
# the 'Events' hook. I think this way is better since it is more explicit.
self.on('terminal:authenticate', bind(send_ssh_css_template, self))
self.on('terminal:authenticate', bind(create_user_ssh_dir, self))
评论列表
文章目录