diff --git a/connect.py b/connect.py index e4e318b01..d9733a3d0 100755 --- a/connect.py +++ b/connect.py @@ -10,7 +10,6 @@ import struct import fcntl import signal - try: import termios import tty @@ -32,10 +31,11 @@ def red_print(string): def alert_print(string): - red_print(string) + red_print('AlertError: %s' % string) time.sleep(2) sys.exit() + def get_win_size(): """This function use to get the size of the windows!""" if 'TIOCGWINSZ' in dir(termios): @@ -110,6 +110,7 @@ def posix_shell(chan, user, host): finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty) + log.close() def connect(username, password, host, port): @@ -140,7 +141,7 @@ def connect(username, password, host, port): except: pass - # set PS1 and msg it + # Set PS1 and msg it channel.send(ps1) channel.send(login_msg) print channel.get_name() @@ -148,7 +149,7 @@ def connect(username, password, host, port): # Make ssh interactive tunnel posix_shell(channel, username, host) - # shutdown channel socket + # Shutdown channel socket channel.close() ssh.close() diff --git a/jumpserver.conf b/jumpserver.conf index 3722bc9f3..14b53b0b6 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -1,3 +1,10 @@ #coding: utf8 -[jumpserver] +[db] +host = 127.0.0.1 +port = 3306 +user = jumpserver +password = mysql345 +database = jumpserver + + diff --git a/jumpserver/settings.py b/jumpserver/settings.py index af56a60d5..887ed8d90 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -10,8 +10,18 @@ https://docs.djangoproject.com/en/1.7/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +import ConfigParser +config = ConfigParser.ConfigParser() + +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +config.read(os.path.join(BASE_DIR, 'jumpserver.conf')) + +DB_HOST = config.get('db', 'host') +DB_PORT = config.getint('db', 'port') +DB_USER = config.get('db', 'user') +DB_PASSWORD = config.get('db', 'password') +DB_DATABASE = config.get('db', 'database') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ @@ -36,12 +46,14 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'juser', + 'jasset', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', + #'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', @@ -58,11 +70,34 @@ WSGI_APPLICATION = 'jumpserver.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.mysql', + 'NAME': DB_DATABASE, + 'USER': DB_USER, + 'PASSWORD': DB_PASSWORD, + 'HOST': DB_HOST, + 'PORT': DB_PORT, } } +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.contrib.auth.context_processors.auth', + 'django.core.context_processors.debug', + 'django.core.context_processors.i18n', + 'django.core.context_processors.media', + 'django.core.context_processors.static', + 'django.core.context_processors.tz', + 'django.contrib.messages.context_processors.messages', +) + +TEMPLATE_DIRS = ( + os.path.join(BASE_DIR, 'templates'), +) + +#STATIC_ROOT = os.path.join(BASE_DIR, 'static') + +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, "static"), +) # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ @@ -81,3 +116,5 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.7/howto/static-files/ STATIC_URL = '/static/' + +SESSION_COOKIE_AGE = 3600