Exemplo n.º 1
0
def do_ban(obj, command, host):
 """
 Ban or unban an IP address.
 
 Synopsis:
  @ban <hostname or IP address>
  @unban <hostname or IP address>
 
 When banned, nobody logging in from the provided hostname will be able to connect to the server.
 """
 try:
  ip = socket.gethostbyname(host)
  hostname = '%s (%s)' % (host, ip)
 except socket.error as e:
  obj.notify('Could not find any address for host %s: %s.' % (host, e))
 else:
  if command == 'ban':
   if ip in server.get_config('banned_hosts'):
    obj.notify('Host %s is already a banned host.' % hostname)
   else:
    server.get_config('banned_hosts').append(ip)
    obj.notify('Host %s added to banned hosts list.' % hostname)
  else:
   try:
    server.get_config('banned_hosts').remove(ip)
    obj.notify('Removed host %s from banned hosts list.' % hostname)
   except KeyError:
    obj.notify('Host %s is not a banned host.' % hostname)
 finally:
  return True
Exemplo n.º 2
0
def do_banned(obj):
 """
 List banned hosts.
 
 Synopsis:
  @banned
 Hosts ban be banned or unbanned with the @ban and @unban commands.
 """
 banned = server.get_config('banned_hosts')
 if banned:
  obj.notify('Banned hosts: %s.' % len(banned))
  for b in banned:
   obj.notify('%s (%s)' % (b, socket.gethostbyaddr(b)[0]))
  obj.notify('Done.')
 else:
  obj.notify('There are no banned hosts.')
 return True
Exemplo n.º 3
0
def test_get_config():
    config_data = server.get_config()
    assert config_data['targets'][0]['url'] == 'http://localhost:15672'
    assert config_data['targets'][0]['login'] == 'guest'
    assert config_data['targets'][0]['password'] == 'guest'
Exemplo n.º 4
0
def test_clear_config():
 server.clear_config('test')
 with pytest.raises(KeyError):
  server.get_config('test')
Exemplo n.º 5
0
def test_get_config():
 assert server.get_config('test') == 'Testing.'
 assert server.get_config('non-existant', False) == False
def test_get_config():
    config_data = server.get_config()
    assert config_data['targets'][0]['name'] == 'localhost:9115'
    assert config_data['targets'][0]['url'] == 'http://localhost:9115'