sshpoff.py
def command():
  """
  Executes a command to a given device (form field 'id') when triggered.
  """
  global config, devices

  if request.method == 'POST':
    name = request.form['id']
    try:
      properties = devices[name]
      ssh = pxssh()
      ssh.force_password = True
      ssh.options['StrictHostKeyChecking'] = 'no'
      ssh.login(
        server = properties['host'],
        username = properties['user'],
        password = properties['password'],
        port = properties['port']
      )
      ssh.sendline(properties['command'])
      ssh.logout()
      # log
      log.info('%s -> %s: OK.', request.remote_addr, properties['host'])
      return config['success-msg'].format(name)
    except (KeyError, ExceptionPxssh) as e:
      if isinstance(e, KeyError):
        # user tried to launch a command on an unexistent device
        log.error('%s -> %s: invalid device.', request.remote_addr,
          properties['host']) 
        return config['unvalid-msg'].format(name)
      elif isinstance(e, ExceptionPxssh):
        # ssh connection failed
        log.error('%s -> %s: KO.', request.remote_addr, properties['host'])
        return config['no-ssh-msg'].format(name)

  Executes a command to a given device (form field 'id') when triggered.
  
Executes a command to a given device (form field 'id') when triggered.
Executes a command to a given device ( form field ' id ' ) when triggered .
def command():
  global config, devices
  if request.method == 'POST':
    name = request.form['id']
    try:
      properties = devices[name]
      ssh = pxssh()
      ssh.force_password = True
      ssh.options['StrictHostKeyChecking'] = 'no'
      ssh.login(
        server = properties['host'],
        username = properties['user'],
        password = properties['password'],
        port = properties['port']
      )
      ssh.sendline(properties['command'])
      ssh.logout()
      log.info('%s -> %s: OK.', request.remote_addr, properties['host'])
      return config['success-msg'].format(name)
    except (KeyError, ExceptionPxssh) as e:
      if isinstance(e, KeyError):
        log.error('%s -> %s: invalid device.', request.remote_addr,
          properties['host']) 
        return config['unvalid-msg'].format(name)
      elif isinstance(e, ExceptionPxssh):
        log.error('%s -> %s: KO.', request.remote_addr, properties['host'])
        return config['no-ssh-msg'].format(name)
def command ( ) : global config , devices if request . method == 'POST' : name = request . form [ 'id' ] try : properties = devices [ name ] ssh = pxssh ( ) ssh . force_password = True ssh . options [ 'StrictHostKeyChecking' ] = 'no' ssh . login ( server = properties [ 'host' ] , username = properties [ 'user' ] , password = properties [ 'password' ] , port = properties [ 'port' ] ) ssh . sendline ( properties [ 'command' ] ) ssh . logout ( ) log . info ( '%s -> %s: OK.' , request . remote_addr , properties [ 'host' ] ) return config [ 'success-msg' ] . format ( name ) except ( KeyError , ExceptionPxssh ) as e : if isinstance ( e , KeyError ) : log . error ( '%s -> %s: invalid device.' , request . remote_addr , properties [ 'host' ] ) return config [ 'unvalid-msg' ] . format ( name ) elif isinstance ( e , ExceptionPxssh ) : log . error ( '%s -> %s: KO.' , request . remote_addr , properties [ 'host' ] ) return config [ 'no-ssh-msg' ] . format ( name )
Executes a command to a given device (form field 'id') when triggered.
Executes a command to a given device ( form field ' id ' ) when triggered .
"""
  Executes a command to a given device (form field 'id') when triggered.
  """ # log # user tried to launch a command on an unexistent device # ssh connection failed