2020-01-15 12:48:22 +00:00
|
|
|
# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
|
|
|
|
# Copyright: (c) <spug.dev@gmail.com>
|
|
|
|
# Released under the MIT License.
|
2020-03-20 07:17:55 +00:00
|
|
|
import django
|
2019-12-06 06:02:22 +00:00
|
|
|
from django.views.generic import View
|
2020-03-20 07:17:55 +00:00
|
|
|
from django.conf import settings
|
2019-12-06 06:02:22 +00:00
|
|
|
from libs import JsonParser, Argument, json_response
|
|
|
|
from apps.setting.utils import AppSetting
|
|
|
|
from apps.setting.models import Setting
|
2020-03-20 07:17:55 +00:00
|
|
|
import platform
|
2020-03-08 13:06:38 +00:00
|
|
|
import ldap
|
2019-12-06 06:02:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SettingView(View):
|
|
|
|
def get(self, request):
|
|
|
|
settings = Setting.objects.exclude(key__in=('public_key', 'private_key'))
|
|
|
|
return json_response(settings)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form, error = JsonParser(
|
|
|
|
Argument('data', type=list, help='缺少必要的参数')
|
|
|
|
).parse(request.body)
|
|
|
|
if error is None:
|
|
|
|
for item in form.data:
|
|
|
|
AppSetting.set(**item)
|
|
|
|
return json_response(error=error)
|
2020-03-08 13:06:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ldap_test(request):
|
|
|
|
form, error = JsonParser(
|
|
|
|
Argument('server'),
|
|
|
|
Argument('port', type=int),
|
|
|
|
Argument('admin_dn'),
|
|
|
|
Argument('password'),
|
|
|
|
).parse(request.body)
|
|
|
|
if error is None:
|
|
|
|
try:
|
|
|
|
con = ldap.initialize("ldap://{0}:{1}".format(form.server, form.port), bytes_mode=False)
|
|
|
|
con.simple_bind_s(form.admin_dn, form.password)
|
|
|
|
return json_response()
|
|
|
|
except Exception as e:
|
|
|
|
error = eval(str(e))
|
|
|
|
return json_response(error=error['desc'])
|
|
|
|
return json_response(error=error)
|
|
|
|
|
|
|
|
|
2020-03-20 07:17:55 +00:00
|
|
|
def get_about(request):
|
|
|
|
return json_response({
|
|
|
|
'python_version': platform.python_version(),
|
|
|
|
'system_version': platform.platform(),
|
|
|
|
'spug_version': settings.SPUG_VERSION,
|
|
|
|
'django_version': django.get_version()
|
|
|
|
})
|
|
|
|
|
2020-03-08 13:06:38 +00:00
|
|
|
|
|
|
|
|