mirror of https://github.com/jumpserver/jumpserver
修改配置文件为相对路径,不用再指定目录了
parent
838b10d3b6
commit
54da30d93b
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0" is_locked="false">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<option name="myLocal" value="false" />
|
||||||
|
<inspection_tool class="SqlDialectInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -2,7 +2,7 @@
|
||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$" />
|
||||||
<orderEntry type="jdk" jdkName="Python 2.7.6 (C:/Python27/python.exe)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 2.7.8 (C:\Python27\python.exe)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
cur_dir = os.path.dirname(__file__)
|
||||||
|
sys.path.append('%s/webroot/AutoSA/' % cur_dir)
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
import pexpect
|
|
||||||
import struct
|
import struct
|
||||||
import fcntl
|
import fcntl
|
||||||
import termios
|
import termios
|
||||||
|
@ -17,10 +20,11 @@ from binascii import b2a_hex, a2b_hex
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import paramiko
|
import paramiko
|
||||||
import pxssh
|
import pxssh
|
||||||
|
from UserManage.models import User
|
||||||
|
|
||||||
|
|
||||||
base_dir = "/opt/jumpserver/"
|
|
||||||
cf = ConfigParser.ConfigParser()
|
cf = ConfigParser.ConfigParser()
|
||||||
cf.read('%s/jumpserver.conf' % base_dir)
|
cf.read('%s/jumpserver.conf' % cur_dir)
|
||||||
|
|
||||||
db_host = cf.get('db', 'host')
|
db_host = cf.get('db', 'host')
|
||||||
db_port = cf.getint('db', 'port')
|
db_port = cf.getint('db', 'port')
|
||||||
|
@ -34,6 +38,8 @@ assets_user_table = cf.get('jumpserver', 'assets_user_table')
|
||||||
key = cf.get('jumpserver', 'key')
|
key = cf.get('jumpserver', 'key')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PyCrypt(object):
|
class PyCrypt(object):
|
||||||
"""It's used to encrypt and decrypt password."""
|
"""It's used to encrypt and decrypt password."""
|
||||||
def __init__(self, key):
|
def __init__(self, key):
|
||||||
|
@ -112,8 +118,11 @@ def connect(host, port, user, password):
|
||||||
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
|
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
|
||||||
if not os.path.isdir(log_date_dir):
|
if not os.path.isdir(log_date_dir):
|
||||||
os.mkdir(log_date_dir)
|
os.mkdir(log_date_dir)
|
||||||
logfile = open("%s/%s_%s" % (log_date_dir, host, user), 'a')
|
logfile = open("%s/%s_%s_%s" % (log_date_dir, host, user, time.strftime('%Y%m%d%H%M%S')), 'a')
|
||||||
logfile.write('\n\n%s\n\n' % time.strftime('%Y%m%d_%H%M%S'))
|
db, cursor = connect_db(db_user, db_password, db_db, db_host, db_port)
|
||||||
|
cursor.execute('insert into logs (Fuser, Fhost, Flogfile, Fstart_time) value (%s, %s, %s, UNIX_TIMESTAMP())'
|
||||||
|
% (user, host, logfile))
|
||||||
|
logfile.write('\n%s\n' % time.strftime('%Y/%m/%d %H:%M:%S'))
|
||||||
try:
|
try:
|
||||||
global foo
|
global foo
|
||||||
foo = pxssh.pxssh()
|
foo = pxssh.pxssh()
|
||||||
|
@ -122,10 +131,13 @@ def connect(host, port, user, password):
|
||||||
foo.sendline('')
|
foo.sendline('')
|
||||||
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
|
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
|
||||||
foo.interact(escape_character=chr(28))
|
foo.interact(escape_character=chr(28))
|
||||||
|
cursor.execute('update logs set Ffindsh=True, Fend_time=UNIX_TIMESTAMP() where Flogfile=%s' % logfile)
|
||||||
except pxssh.ExceptionPxssh as e:
|
except pxssh.ExceptionPxssh as e:
|
||||||
print('登录失败: %s' % e)
|
print('登录失败: %s' % e)
|
||||||
|
cursor.execute('update logs set Ffindsh=2 where Flogfile=%s' % logfile)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
foo.logout()
|
foo.logout()
|
||||||
|
cursor.execute('update logs set Ffindsh=True, Fend_time=UNIX_TIMESTAMP() where Flogfile=%s ' % logfile)
|
||||||
|
|
||||||
|
|
||||||
def ip_all_select(username):
|
def ip_all_select(username):
|
||||||
|
|
|
@ -12,16 +12,16 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
|
||||||
import os
|
import os
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
base_dir = "/opt/jumpserver/"
|
|
||||||
cf = ConfigParser.ConfigParser()
|
|
||||||
cf.read('%s/jumpserver.conf' % base_dir)
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
CONF_DIR = os.path.dirname(os.path.dirname(BASE_DIR))
|
||||||
|
CF = ConfigParser.ConfigParser()
|
||||||
|
CF.read('%s/jumpserver.conf' % CONF_DIR)
|
||||||
|
|
||||||
db_host = cf.get('db', 'host')
|
DB_HOST = CF.get('db', 'host')
|
||||||
db_port = cf.getint('db', 'port')
|
DB_PORT = CF.getint('db', 'port')
|
||||||
db_user = cf.get('db', 'user')
|
DB_USER = CF.get('db', 'user')
|
||||||
db_password = cf.get('db', 'password')
|
DB_PASSWORD = CF.get('db', 'password')
|
||||||
db_db = cf.get('db', 'db')
|
DB_DB = CF.get('db', 'db')
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
|
||||||
|
@ -71,11 +71,11 @@ WSGI_APPLICATION = 'AutoSa.wsgi.application'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': db_db,
|
'NAME': DB_DB,
|
||||||
'USER': db_user,
|
'USER': DB_USER,
|
||||||
'PASSWORD': db_password,
|
'PASSWORD': DB_PASSWORD,
|
||||||
'HOST': db_host,
|
'HOST': DB_HOST,
|
||||||
'PORT': db_port,
|
'PORT': DB_PORT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,3 +23,16 @@ class User(models.Model):
|
||||||
return self.username
|
return self.username
|
||||||
|
|
||||||
|
|
||||||
|
class Logs(models.Model):
|
||||||
|
user = models.CharField(max_length=50)
|
||||||
|
host = models.CharField(max_length=20)
|
||||||
|
logfile = models.CharField(max_length=1000)
|
||||||
|
finish = models.SmallIntegerField(max_length=4)
|
||||||
|
start_time = models.IntegerField()
|
||||||
|
end_time = models.IntegerField()
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.logfile
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue