Exemplo n.º 1
0
def user_password_authentication(user_name, password):
  global configuration_options

  if configuration_options.user_ignore_name and configuration_options.user_ignore_password:
    ldebug('user-password authentication credentials provided but ignored - user: %s, password: %s' % (user_name, '*' * len(str(password))))
    return True

  if configuration_options.user_override_name != None and configuration_options.user_override_password != None:
    if user_name == configuration_options.user_override_name and password == configuration_options.user_override_password:
      return True
    return False

  db = SQLiteR(configuration_options.user_db_name)
  if not db.connect():
    lerror('cound not connect to user database "%s"' % configuration_options.user_db_name)
    return False

  user = db.find(configuration_options.user_db_table, {configuration_options.user_db_name_row: user_name, configuration_options.user_db_password_row: password})
  db.disconnect()

  if user:
    ldebug('user-password authentication accepted - user: %s, password: %s' % (user_name, '*' * len(str(password))))
    return True

  linfo('user-password authentication failed - user: %s, password: %s' % (user_name, '*' * len(str(password))))
  return False
Exemplo n.º 2
0
    def handle_ami_client_message(self, message):

        if 'Action' in message:
            action = message['Action'].lower()

            if action == 'login':
                if 'UserName' in message:
                    self.account_name = message['UserName']
                if 'Secret' in message and self.user_password_authentication and self.user_password_authentication(
                        self.account_name, message['Secret']):
                    self.ami.send_login_ack()
                    ldebug(
                        'AMI connection authenticated - account: %s' %
                        self.account_name, self)
                else:
                    self.ami.send_login_nack()
                    linfo(
                        'AMI authentication failed - account: %s' %
                        sval(message, 'UserName'), self)
                    self.ami.stop()
                    self.stop()
            elif action == 'logoff':
                self.ami.send_logout_ack()
                ldebug('AMI logout', self)
                self.ami.stop()
                self.stop()
            elif action == 'ping':
                self.ami.send_pong(sval(message, 'ActionID'))
            elif action == 'status':
                self.ami.send_status_ack(sval(message, 'ActionID'))
            elif action == 'command' and sval(
                    message, 'Command') == 'core show version':
                self.ami.send_asterisk_version(sval(message, 'ActionID'))
            elif action == 'hangup':
                account_name, separator, uuid = str(sval(
                    message, 'Channel')).rpartition('-uuid-')
                if account_name != '':
                    self.event_socket.hangup(uuid)
                    self.ami.send_hangup_ack()
            elif action == 'originate':
                self.message_originate(message)
            elif action == 'extensionstate':
                self.ami.send_extension_state(sval(message, 'ActionID'),
                                              sval(message, 'Exten'),
                                              sval(message, 'Context'))
            else:
                ldebug('unknown asterisk message received: %s' % message, self)
                self.ami.send_message_unknown(message['Action'])
Exemplo n.º 3
0
def user_password_authentication(user_name, password):
    global configuration_options

    if configuration_options.user_ignore_name and configuration_options.user_ignore_password:
        ldebug(
            'user-password authentication credentials provided but ignored - user: %s, password: %s'
            % (user_name, '*' * len(str(password))))
        return True

    if configuration_options.user_override_name != None and configuration_options.user_override_password != None:
        if user_name == configuration_options.user_override_name and password == configuration_options.user_override_password:
            return True
        return False

    db = MySQLR(configuration_options.user_db_name,
                configuration_options.user_db_user,
                configuration_options.user_db_password)
    if not db.connect():
        lerror('cound not connect to user database "%s"' %
               configuration_options.user_db_name)
        return False

    user = db.find(
        configuration_options.user_db_table, {
            configuration_options.user_db_name_row: user_name,
            configuration_options.user_db_password_row: password
        })
    db.disconnect()

    if user:
        ldebug(
            'user-password authentication accepted - user: %s, password: %s' %
            (user_name, '*' * len(str(password))))
        return True

    linfo('user-password authentication failed - user: %s, password: %s' %
          (user_name, '*' * len(str(password))))

    return False
Exemplo n.º 4
0
  def handle_ami_client_message(self, message):

    if 'Action' in message:
      action = message['Action'].lower()
      
      if action == 'login':
        if 'UserName' in message:
          self.account_name = message['UserName']
        if 'Secret' in message and self.user_password_authentication and self.user_password_authentication(self.account_name, message['Secret']):
          self.ami.send_login_ack()
          ldebug('AMI connection authenticated - account: %s' % self.account_name, self)
        else:
          self.ami.send_login_nack()
          linfo('AMI authentication failed - account: %s' % sval(message, 'UserName'), self)
          self.ami.stop()
          self.stop()
      elif action == 'logoff':
        self.ami.send_logout_ack()
        ldebug('AMI logout', self)
        self.ami.stop()
        self.stop()
      elif action == 'ping':
        self.ami.send_pong(sval(message, 'ActionID'))
      elif action == 'status':
        self.ami.send_status_ack(sval(message, 'ActionID'))
      elif action == 'command' and sval(message, 'Command') == 'core show version':
        self.ami.send_asterisk_version(sval(message, 'ActionID'))
      elif action == 'hangup':
        account_name, separator, uuid = str(sval(message, 'Channel')).rpartition('-uuid-')
        if account_name != '':
          self.event_socket.hangup(uuid)
          self.ami.send_hangup_ack()
      elif action == 'originate':
        self.message_originate(message)
      elif action == 'extensionstate':
        self.ami.send_extension_state(sval(message, 'ActionID'), sval(message, 'Exten'), sval(message, 'Context'))
      else:
        ldebug('unknown asterisk message received: %s' % message, self)
        self.ami.send_message_unknown(message['Action'])