Commit 216163f4 authored by ibuler's avatar ibuler

stash

parent d3e9c8c9
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import logging
import os
BASE_DIR = os.path.dirname(os.path.abspath(__name__))
LOG_LEVEL_CHOICES = {
'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'critical': logging.CRITICAL
}
class Config:
LOG_LEVEL = ''
LOG_DIR = os.path.join(BASE_DIR, 'logs')
LOGGING = {
'version': 1,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'main': {
'datefmt': '%Y-%m-%d %H:%M:%S',
'format': '%(asctime)s [%(module)s %(levelname)s] %(message)s',
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'main'
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'formatter': 'main',
'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log')
},
},
'loggers': {
'django': {
'handlers': ['null'],
'propagate': False,
'level': LOG_LEVEL,
},
'django.request': {
'handlers': ['console', 'file'],
'level': LOG_LEVEL,
'propagate': False,
},
'django.server': {
'handlers': ['console', 'file'],
'level': LOG_LEVEL,
'propagate': False,
},
'jumpserver': {
'handlers': ['console', 'file'],
'level': LOG_LEVEL,
},
'jumpserver.users.api': {
'handlers': ['console', 'file'],
'level': LOG_LEVEL,
},
'jumpserver.users.view': {
'handlers': ['console', 'file'],
'level': LOG_LEVEL,
}
}
}
def __init__(self):
pass
def __getattr__(self, item):
return None
if __name__ == '__main__':
pass
...@@ -37,14 +37,7 @@ from users.utils import ssh_key_gen, check_user_is_valid ...@@ -37,14 +37,7 @@ from users.utils import ssh_key_gen, check_user_is_valid
logger = get_logger(__name__) logger = get_logger(__name__)
class SSHService(paramiko.ServerInterface): class SSHServerInterface(paramiko.ServerInterface):
# data = (b'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hp'
# b'fAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMC'
# b'KDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iT'
# b'UWT10hcuO4Ks8=')
# good_pub_key = paramiko.RSAKey(data=decodebytes(data))
# host_key = paramiko.RSAKey(filename='test_rsa.key')
host_key_path = os.path.join(BASE_DIR, 'host_rsa_key') host_key_path = os.path.join(BASE_DIR, 'host_rsa_key')
def __init__(self): def __init__(self):
...@@ -138,10 +131,10 @@ class SSHServer: ...@@ -138,10 +131,10 @@ class SSHServer:
logger.warning('(Failed to load moduli -- gex will be unsupported.)') logger.warning('(Failed to load moduli -- gex will be unsupported.)')
raise raise
transport.add_server_key(SSHService.get_host_key()) transport.add_server_key(SSHServerInterface.get_host_key())
service = SSHService() ssh_interface = SSHServerInterface()
try: try:
transport.start_server(server=service) transport.start_server(server=ssh_interface)
except paramiko.SSHException: except paramiko.SSHException:
print('*** SSH negotiation failed.') print('*** SSH negotiation failed.')
return return
...@@ -158,7 +151,7 @@ class SSHServer: ...@@ -158,7 +151,7 @@ class SSHServer:
channel.send('We are on fire all the time! Hooray! Candy corn for everyone!\r\n') channel.send('We are on fire all the time! Hooray! Candy corn for everyone!\r\n')
channel.send('Happy birthday to Robot Dave!\r\n\r\n') channel.send('Happy birthday to Robot Dave!\r\n\r\n')
server_channel = self.connect() server_channel = self.connect()
if not service.event.is_set(): if not ssh_interface.event.is_set():
print('*** Client never asked for a shell.') print('*** Client never asked for a shell.')
return return
server_data = [] server_data = []
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import logging
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
if __name__ == '__main__':
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment