Skip to content

Commit

Permalink
Yearning v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cookie committed Jan 21, 2019
1 parent 129ca27 commit 39e5aec
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 187 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@ webpage/dist
# Distribution / packaging
.Python
src/deploy.conf
src/dist
src/exportData/*.docx
src/core/migrations/*.py
env/
Expand Down
12 changes: 9 additions & 3 deletions src/core/api/managerdb.py
Expand Up @@ -2,13 +2,15 @@
import json
import ast
from libs import baseview
from libs.cryptoAES import cryptoAES
from libs import con_database
from core.task import grained_permissions
from libs import util
from rest_framework.response import Response
from django.http import HttpResponse
from django.db import transaction
from libs.serializers import Sqllist
from settingConf import settings
from core.models import (
DatabaseList,
SqlRecord,
Expand All @@ -19,6 +21,8 @@

CUSTOM_ERROR = logging.getLogger('Yearning.core.views')

AES = cryptoAES(settings.SECRET_KEY)


class management_db(baseview.SuperUserpermissions):
'''
Expand Down Expand Up @@ -61,7 +65,7 @@ def get(self, request, args=None):
page_number = DatabaseList.objects.filter(connection_name__contains=con['connection_name'],
computer_room__contains=con['computer_room']).count()
info = DatabaseList.objects.filter(connection_name__contains=con['connection_name'],
computer_room__contains=con['computer_room'])[start:end]
computer_room__contains=con['computer_room'])[start:end]
else:
page_number = DatabaseList.objects.count()
info = DatabaseList.objects.all().order_by('connection_name')[start:end]
Expand Down Expand Up @@ -90,6 +94,7 @@ def post(self, request, args=None):

try:
data = json.loads(request.data['data'])
password = AES.encrypt(data['password'])
except KeyError as e:
CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}')
return HttpResponse(status=500)
Expand All @@ -100,7 +105,7 @@ def post(self, request, args=None):
ip=data['ip'],
computer_room=data['computer_room'],
username=data['username'],
password=data['password'],
password=password,
port=data['port']
)
return Response('ok')
Expand Down Expand Up @@ -140,6 +145,7 @@ def put(self, request, args=None):

try:
update_data = json.loads(request.data['data'])
password = AES.encrypt(update_data['password'])
except KeyError as e:
CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}')
return HttpResponse(status=500)
Expand All @@ -150,7 +156,7 @@ def put(self, request, args=None):
computer_room=update_data['computer_room']).update(
ip=update_data['ip'],
username=update_data['username'],
password=update_data['password'],
password=password,
port=update_data['port']
)
return Response('数据信息更新成功!')
Expand Down
7 changes: 4 additions & 3 deletions src/core/api/serachsql.py
Expand Up @@ -83,6 +83,7 @@ def post(self, request, args=None):
limit = ast.literal_eval(un_init['other'])
sql = request.data['sql']
check = str(sql).lower().strip().split(';\n')
raw_sql = str(sql).strip().split(';\n')[-1]
user = query_order.objects.filter(
username=request.user).order_by('-id').first()
un_init = util.init_conf()
Expand All @@ -109,14 +110,14 @@ def post(self, request, args=None):
return Response('语句中不得含有违禁关键字: update insert alter into for drop')

if check[-1].startswith('show'):
query_sql = check[-1]
query_sql = raw_sql
else:
if limit.get('limit').strip() == '':
CUSTOM_ERROR.error('未设置全局最大limit值,系统自动设置为1000')
query_sql = replace_limit(check[-1], 1000)
query_sql = replace_limit(raw_sql, 1000)
else:
query_sql = replace_limit(
check[-1], limit.get('limit'))
raw_sql, limit.get('limit'))
data_set = f.search(sql=query_sql)
except Exception as e:
CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}')
Expand Down
8 changes: 7 additions & 1 deletion src/libs/con_database.py
Expand Up @@ -7,17 +7,23 @@
cookie
'''

from libs.cryptoAES import cryptoAES
from settingConf import settings
import pymysql


class SQLgo(object):
def __init__(self, ip=None, user=None, password=None, db=None, port=None):
self.AES = cryptoAES(settings.SECRET_KEY)
self.ip = ip
self.user = user
self.password = password
self.db = db
self.port = int(port)
self.con = object
try:
self.password = self.AES.decrypt(password)
except ValueError:
self.password = password

@staticmethod
def addDic(theIndex, word, value):
Expand Down
26 changes: 26 additions & 0 deletions src/libs/cryptoAES.py
@@ -0,0 +1,26 @@
from Crypto.Cipher import AES
from binascii import b2a_hex, a2b_hex


class cryptoAES(object):
def __init__(self, key):
self.key = key[0:16]
self.mode = AES.MODE_CBC
self.ciphertext = None

def encrypt(self, text):
cryptor = AES.new(self.key, self.mode, self.key)
length = 16
count = len(text)
if count % length != 0:
add = length - (count % length)
else:
add = 0
text = text + ('\0' * add)
self.ciphertext = cryptor.encrypt(text)
return bytes.decode(b2a_hex(self.ciphertext))

def decrypt(self, text):
cryptor = AES.new(self.key, self.mode, self.key)
plain_text = cryptor.decrypt(a2b_hex(text))
return bytes.decode(plain_text.rstrip(b'\0'))
17 changes: 10 additions & 7 deletions src/libs/util.py
Expand Up @@ -82,10 +82,12 @@ def conf_path() -> object:
_conf.get('mysql', 'port'), _conf.get('mysql', 'username'),
_conf.get('mysql', 'password'), _conf.get('host', 'ipaddress'))


class LDAPConnection(object):
def __init__(self, url, user, password):
server = Server(url, get_info=ALL)
self.conn = Connection(server, user=user, password=password, check_names=True, lazy=False, raise_exceptions=False)
self.conn = Connection(server, user=user, password=password, check_names=True, lazy=False,
raise_exceptions=False)

def __enter__(self):
self.conn.bind()
Expand All @@ -94,6 +96,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
self.conn.unbind()


def test_auth(url, user, password):
with LDAPConnection(url, user, password) as conn:
if conn.bind():
Expand All @@ -110,7 +113,7 @@ def auth(username, password):

if LDAP_TYPE == '1':
search_filter = '(sAMAccountName={})'.format(username)
elif LDAP_TYPE == '2':
elif LDAP_TYPE == '2':
search_filter = '(uid={})'.format(username)
else:
search_filter = '(cn={})'.format(username)
Expand Down Expand Up @@ -138,11 +141,11 @@ def auth(username, password):

def init_conf():
with con_database.SQLgo(
ip=_conf.get('mysql', 'address'),
user=_conf.get('mysql', 'username'),
password=_conf.get('mysql', 'password'),
db=_conf.get('mysql', 'db'),
port=_conf.get('mysql', 'port')) as f:
ip=_conf.get('mysql', 'address'),
user=_conf.get('mysql', 'username'),
password=_conf.get('mysql', 'password'),
db=_conf.get('mysql', 'db'),
port=_conf.get('mysql', 'port')) as f:
res = f.query_info(
"select * from core_globalpermissions where authorization = 'global'")

Expand Down
28 changes: 26 additions & 2 deletions src/settingConf/settings.py
Expand Up @@ -37,7 +37,9 @@
'django.contrib.auth',
'django.contrib.contenttypes',
'core.apps.CoreConfig',
'rest_framework'
'rest_framework',
'django.contrib.staticfiles',
'settingConf'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -75,6 +77,28 @@
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['dist'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

STATIC_URL = '/static/'

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'dist/static').replace('\\', '/'),
)

# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -117,7 +141,7 @@
JWT_AUTH = {
'JWT_RESPONSE_PAYLOAD_HANDLER':
'rest_framework_jwt.utils.jwt_response_payload_handler',
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600),
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=7200),
}

LOGGING = {
Expand Down
3 changes: 3 additions & 0 deletions src/settingConf/urls.py
@@ -1,7 +1,9 @@
'''
url table
'''

from django.conf.urls import url
from django.views.generic import TemplateView
from rest_framework.urlpatterns import format_suffix_patterns

from core.api.user import (
Expand Down Expand Up @@ -62,5 +64,6 @@
url(r'^api/v1/undoOrder', del_order.as_view()),
url(r'^api/v1/osc/(.*)', osc_step.as_view()),
url(r'^api-token-auth/', login_auth.as_view()),
url(r'^$', TemplateView.as_view(template_name="index.html")),
]
urlpatterns = format_suffix_patterns(urlpatterns)
76 changes: 8 additions & 68 deletions webpage/src/components/home/home.vue
Expand Up @@ -51,22 +51,10 @@
<Row class="margin-top-10">
<Card>
<p slot="title" class="card-title">
<Icon type="md-checkbox-outline"></Icon>
待办事项
<Icon type="md-person" size="24"/>
个人信息
</p>
<a type="text" slot="extra" @click.prevent="addNewToDoItem">
<Icon type="md-add"></Icon>
</a>
<Modal v-model="showAddNewTodo" title="添加新的待办事项" @on-ok="addNew" @on-cancel="cancelAdd">
<Row type="flex" justify="center">
<Input v-model="newToDoItemValue" icon="compose" placeholder="请输入..." style="width: 300px"/>
</Row>
</Modal>
<div class="to-do-list-con">
<div v-for="(item, index) in toDoList" :key="index" class="to-do-item">
<to-do-list-item :content="item.title" :todoitem="false" @deltodo="deltodo"></to-do-list-item>
</div>
</div>
<userinfomation></userinfomation>
</Card>
</Row>
</Col>
Expand Down Expand Up @@ -124,12 +112,15 @@
import dataSourcePie from './components/dataSourcePie.vue'
import inforCard from './components/inforCard.vue'
import toDoListItem from './components/toDoListItem.vue'
import userinfomation from '../personalCenter/own-space'
export default {
components: {
dataSourcePie,
inforCard,
toDoListItem
toDoListItem,
userinfomation
},
data () {
return {
Expand All @@ -141,69 +132,19 @@
order: 0,
link: 0
},
showAddNewTodo: false,
newToDoItemValue: '',
time: '',
username: sessionStorage.getItem('user'),
board: {
'title': ['1.DDL语句生成', '2.数据库字典生成及查看', '3.SQL语句审核及回滚', '4.工单流程化', '5.可视化数据查询', '6.细粒度的权限划分']
'title': ['1.DDL语句生成', '2.SQL语句审核及回滚', '3.工单流程化', '4.可视化数据查询', '5.细粒度的权限划分']
}
}
},
methods: {
addNewToDoItem () {
this.showAddNewTodo = true
},
formatDate () {
let date = new Date()
let month = date.getMonth() + 1
this.time = date.getFullYear() + '/' + month + '/' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds()
},
addNew () {
if (this.newToDoItemValue.length !== 0) {
axios.post(`${this.$config.url}/homedata/todolist/`, {
'todo': this.newToDoItemValue
})
.then(() => {
let vm = this
this.toDoList.unshift({
title: this.newToDoItemValue
})
setTimeout(function () {
vm.newToDoItemValue = ''
}, 200)
this.showAddNewTodo = false
})
.catch(error => {
this.$config.err_notice(this, error)
})
} else {
this.$Message.error('请输入待办事项内容')
}
},
cancelAdd () {
this.showAddNewTodo = false
this.newToDoItemValue = ''
},
deltodo (val) {
axios.put(`${this.$config.url}/homedata/deltodo`, {
'todo': val
})
.then(() => {
this.gettodo()
})
.catch(error => {
this.$config.err_notice(this, error)
})
},
gettodo () {
axios.put(`${this.$config.url}/homedata/todolist`)
.then(res => {
this.toDoList = res.data
})
.catch(error => {
this.$config.err_notice(this, error)
})
}
},
mounted () {
Expand All @@ -216,7 +157,6 @@
.catch(error => {
this.$config.err_notice(this, error)
})
this.gettodo()
this.formatDate()
}
}
Expand Down

0 comments on commit 39e5aec

Please sign in to comment.