Skip to content

Commit

Permalink
新增功能:
Browse files Browse the repository at this point in the history
新增exchange开关选项卡,现在管理员可以配置系统是否使用exchange功能
优化:
优化uwsgi启动方式,现在前端加载更快,网络流量消耗更小
  • Loading branch information
SamGenTLEManKaka committed May 17, 2019
1 parent 6e364cb commit f10bfcb
Show file tree
Hide file tree
Showing 127 changed files with 535 additions and 1,085,660 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
详细功能可参见[基于web的AD、Exchange管理平台](https://www.opscaff.com/2019/04/28/%E5%9F%BA%E4%BA%8Ead%E3%80%81exchange%E7%9A%84%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0/)


## ToDo

* Exchange功能开关,系统不依赖Exchange运行。
* AD临时(短期)账号管理,自动清理过期账号

# ITOPS安装部署文档

Expand Down Expand Up @@ -171,7 +167,7 @@ cd /usr/local/its-itops/dbinfo/ \
> 运行下列命令启动平台服务
```
/usr/python35/bin/uwsgi --http-socket 0.0.0.0:8080 --chdir /usr/local/its-itops/ --plugin python --wsgi-file /usr/local/its-itops/itops/wsgi.py --master --static-map /static=/usr/local/its-itops/static/ --static-map /static=/usr/local/its-itops/frontend/dist/static/ --static-map /static=/usr/python35/lib/python3.5/site-packages/rest_framework/static/ --processes 8 --threads 8 --uid=99 --gid=99
/usr/python35/bin/uwsgi --http-socket 0.0.0.0:8080 --chdir /usr/local/its-itops/ --plugin python --wsgi-file /usr/local/its-itops/itops/wsgi.py --master --static-map /static=/usr/local/its-itops/static/ --static-map /static=/usr/local/its-itops/frontend/dist/static/ --static-map /static=/usr/python35/lib/python3.5/site-packages/rest_framework/static/ --processes 8 --threads 8 --uid=99 --gid=99 --static-gzip-dir=/usr/local/its-itops/frontend/
```
> 关闭uwsgi
Expand Down Expand Up @@ -256,7 +252,7 @@ EXChange服务器地址:具有powershell4.0 的CAS服务器
域名:AD域名
```

![](https://www.opscaff.com/wp-content/uploads/2019/05/picture_seven.png)
![](https://www.opscaff.com/wp-content/uploads/2019/05/c51406fd166189c4f07166ac5c8fdab2.png)

配置完成请点击提交
#### 5.1.8.账号权限配置
Expand Down
4 changes: 4 additions & 0 deletions apps/activeapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ def get_ou_for_dn(distinguishedName, treeid):
def get_object_for_dn(distinguishedName):
try:
with ldap3RESTARTABLE as conn:
conn.search(
search_base=distinguishedName,
search_filter="(objectClass=*)",
search_scope='BASE',)
object_list = []
total_entries = 0
entry_generator = conn.extend.standard.paged_search(
Expand Down
29 changes: 27 additions & 2 deletions apps/activedirectory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import json
from django.shortcuts import render_to_response

from ADapi.views import getmailboxdatabasenovalue, date_handler
from ADapi.views import getmailboxdatabasenovalue, date_handler, getskey
from apps.activeapi.views import moveToOu, \
delete_object, inspect_object, getObjectToDn, objectClassFrom, setAccount, \
resetPassword, dnMoveToOu, serchlock, unlockuser, can_accidentally_deleted, check_accidentally_deleted, uncheck_accidentally_deleted
Expand Down Expand Up @@ -80,9 +80,13 @@ def show_domain(request):
def show_ou_for_dn(request):
distinguishedName = request.POST.get('distinguishedName')
treeid = request.POST.get('id')
username = request.session.get('username')
if distinguishedName:
try:
result = get_ou_for_dn(distinguishedName,treeid)['message']
get_ou_for_dns = get_ou_for_dn(distinguishedName, treeid)
result = get_ou_for_dns['message']
if not get_ou_for_dns["isSuccess"]:
insert_log(username, request, str(get_ou_for_dns['isSuccess']), str(get_ou_for_dns), '')
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(json.dumps(result))
Expand All @@ -96,9 +100,12 @@ def show_ou_for_dn(request):
#获取下层目录所有对象
def show_object_for_dn(request):
distinguishedName = request.POST.get('distinguishedName')
username = request.session.get('username')
if distinguishedName:
try:
result = get_object_for_dn(distinguishedName)
if not result["isSuccess"]:
insert_log(username, request, str(result['isSuccess']), str(result), '')
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(json.dumps(result,default=date_handler))
Expand Down Expand Up @@ -669,4 +676,22 @@ def canAccidentallyDeleted(request):
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(json.dumps(result))
return response

# 获取数据库中的邮箱配置
def getExissconfig(request):
try:
getskeys = getskey()
if getskeys:
if str(getskeys.get('status', '0')) == '1':
result = {'isSuccess': True, "message": getskeys, "code": '1'}
else:
result = {'isSuccess': False, "message": getskeys, "code": '0'}
else:
result = {'isSuccess': False, "message": '未获取到exiisconfig表数据', "code": '0'}
except Exception as e:
result = {'isSuccess': False, "message": str(e), "code": '0'}
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(json.dumps(result))
return response
186 changes: 74 additions & 112 deletions dbinfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,7 @@ def crearldapdb():
print(e)
return False

#创建y邮箱表
def crearmaildb():
conn = dbinfo()
try:
conncur = conn.cursor()
connsql ='''CREATE TABLE `sendmailsite` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`mailcount` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`mailserver` varchar(255) DEFAULT NULL,
`mailaddress` varchar(255) DEFAULT NULL,
`datetime` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4'''
conncur.execute(connsql)
histroycounts = conncur.fetchall()
conn.commit()
conn.close()
return histroycounts
except Exception as e:
print(e)
return False



#验证ldap表是否存在
Expand Down Expand Up @@ -230,34 +209,6 @@ def crearperdb():
print(e)
return False

def searchsendmail():
conn = dbinfo()
try:
conncur = conn.cursor()
connsql = "select * from sendmailsite limit1"
conncur.execute(connsql, ())
histroycounts = conncur.fetchone()
conn.commit()
conn.close()
return histroycounts
except Exception as e:
print(e)
return False

#验证邮箱表是否存在
def selectmaildb():
conn = dbinfo()
try:
conncur = conn.cursor()
connsql = "show tables like 'sendmailsite'"
conncur.execute(connsql)
histroycounts = conncur.fetchone()
conn.commit()
conn.close()
return histroycounts
except Exception as e:
print(e)


#验证操作表是否存在
def selectperdb():
Expand All @@ -273,32 +224,6 @@ def selectperdb():
except Exception as e:
print(e)

def insert_sendmail(mailcount,password, mailserver,mailaddress):
createtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
conn = dbinfo()
try:
conncur = conn.cursor()
connsql = "select * from sendmailsite"
conncur.execute(connsql, ())
histroycounts = conncur.fetchone()
if histroycounts:
id =histroycounts['id']
conncur = conn.cursor()
connsql = "UPDATE sendmailsite SET mailcount=%s,password=%s, mailserver=%s,mailaddress=%s,datetime=%s WHERE id =%s"
conncur.execute(connsql, (mailcount,password, mailserver,mailaddress,createtime,id))
histroycounts = conncur.fetchall()
else:
conncur = conn.cursor()
connsql = "INSERT INTO sendmailsite (mailcount,password, mailserver,mailaddress,datetime) VALUES (%s,%s,%s,%s,%s) "
conncur.execute(connsql, (mailcount, password, mailserver, mailaddress, createtime))
histroycounts = conncur.fetchall()
conn.commit()
conn.close()
return histroycounts
except Exception as e:
print(e)
return False

def insert_userper(logongroup,changepwdgroup, fieldgroup,operagroup):
conn = dbinfo()
try:
Expand Down Expand Up @@ -427,31 +352,7 @@ def creariisdb():
print(e)
return False

# #iis信息写入
# def insert_iisexpmessage(iisip,iisport):
# conn = dbinfo()
# try:
# conncur = conn.cursor()
# connsql = "select * from exiisconfig"
# conncur.execute(connsql, ())
# histroycounts = conncur.fetchone()
# if histroycounts:
# id =histroycounts['id']
# conncur = conn.cursor()
# connsql = "UPDATE exiisconfig SET iisserver=%s,iisport=%s WHERE id =%s"
# conncur.execute(connsql, (iisip,iisport,id))
# histroycounts = conncur.fetchall()
# else:
# conncur = conn.cursor()
# connsql = "INSERT INTO exiisconfig (iisserver,iisport) VALUES (%s,%s) "
# conncur.execute(connsql, (iisip,iisport))
# histroycounts = conncur.fetchall()
# conn.commit()
# conn.close()
# return histroycounts
# except Exception as e:
# print(e)
# return False



#exchange信息写入
Expand All @@ -466,30 +367,38 @@ def insert_expmessage(exinputip,exinputaccount,password,exinputdomain):
if not exiisconfig:
conncur = conn.cursor()
connsql = '''DROP TABLE IF EXISTS `exiisconfig`;
CREATE TABLE `exiisconfig` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`exserver` varchar(255) DEFAULT NULL,
`exuser` varchar(255) DEFAULT NULL,
`expassword` varchar(255) DEFAULT NULL,
`exdomain` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
'''
CREATE TABLE `exiisconfig` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`exserver` varchar(255) DEFAULT NULL,
`exuser` varchar(255) DEFAULT NULL,
`expassword` varchar(255) DEFAULT NULL,
`exdomain` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`status` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;'''
conncur.execute(connsql)
conn.commit()
else:
try:
conncur = conn.cursor()
connsql = 'ALTER TABLE exiisconfig ADD COLUMN status VARCHAR(100) DEFAULT NULL'
conncur.execute(connsql)
conn.commit()
except Exception as e:
pass
conncur = conn.cursor()
connsql = "select * from exiisconfig"
conncur.execute(connsql, ())
histroycounts = conncur.fetchone()
if histroycounts:
id =histroycounts['id']
conncur = conn.cursor()
connsql = "UPDATE exiisconfig SET exserver=%s,exuser=%s,expassword=%s,exdomain=%s WHERE id =%s"
connsql = "UPDATE exiisconfig SET exserver=%s,exuser=%s,expassword=%s,exdomain=%s,status='1' WHERE id =%s"
conncur.execute(connsql, (exinputip,exinputaccount,password,exinputdomain,id))
histroycounts = conncur.fetchall()
else:
conncur = conn.cursor()
connsql = "INSERT INTO exiisconfig (exserver,exuser,expassword,exdomain) VALUES (%s,%s,%s,%s) "
connsql = "INSERT INTO exiisconfig (exserver,exuser,expassword,exdomain,status) VALUES (%s,%s,%s,%s,'1') "
conncur.execute(connsql, (exinputip,exinputaccount,password,exinputdomain))
histroycounts = conncur.fetchall()
conn.commit()
Expand All @@ -499,6 +408,59 @@ def insert_expmessage(exinputip,exinputaccount,password,exinputdomain):
print(e)
return False

#exchange不配做写入信息
def insert_exp():
conn = dbinfo()
try:
conncur = conn.cursor()
connsql = "show tables like 'exiisconfig'"
conncur.execute(connsql, ())
exiisconfig = conncur.fetchone()
conn.commit()
if not exiisconfig:
conncur = conn.cursor()
connsql = '''DROP TABLE IF EXISTS `exiisconfig`;
CREATE TABLE `exiisconfig` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`exserver` varchar(255) DEFAULT NULL,
`exuser` varchar(255) DEFAULT NULL,
`expassword` varchar(255) DEFAULT NULL,
`exdomain` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`status` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;'''
conncur.execute(connsql)
conn.commit()
else:
try:
conncur = conn.cursor()
connsql = 'ALTER TABLE exiisconfig ADD COLUMN status VARCHAR(100) DEFAULT NULL'
conncur.execute(connsql)
conn.commit()
except Exception as e:
pass
conncur = conn.cursor()
connsql = "select * from exiisconfig"
conncur.execute(connsql, ())
histroycounts = conncur.fetchone()
if histroycounts:
id =histroycounts['id']
conncur = conn.cursor()
connsql = "UPDATE exiisconfig SET status=%s WHERE id =%s"
conncur.execute(connsql, ('0',id))
histroycounts = conncur.fetchall()
else:
conncur = conn.cursor()
connsql = "INSERT INTO exiisconfig (status) VALUES ('0') "
conncur.execute(connsql, ())
histroycounts = conncur.fetchall()
conn.commit()
conn.close()
return histroycounts
except Exception as e:
print(e)
return False

# #iisskey
# def insert_iisekey(skeyvalue):
# conn = dbinfo()
Expand Down
13 changes: 13 additions & 0 deletions frontend/build/deloldjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let fs = require('fs');
function FileListPlugin(options) {}
FileListPlugin.prototype.apply = function(compiler) {
compiler.plugin("done", function (stats) {
var jsfilenamelist = Object.getOwnPropertyNames(stats.compilation.assets)
for (var i = 0; i < jsfilenamelist.length ; i++) {
if (jsfilenamelist[i].indexOf('.js.gz') !== -1 && jsfilenamelist[i].indexOf('static/js/') !== -1) {
fs.writeFileSync('./dist/' + jsfilenamelist[i].replace(/.gz/g,''), ' ')
}
}
});
}
module.exports = FileListPlugin;
6 changes: 6 additions & 0 deletions frontend/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const FileListPlugin = require('./deloldjs')

function resolve (dir) {
return path.join(__dirname, '..', dir)
Expand Down Expand Up @@ -35,6 +37,10 @@ module.exports = {
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
plugins: [
new CleanWebpackPlugin(),
new FileListPlugin()
],
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ if (config.build.productionGzip) {
config.build.productionGzipExtensions.join('|') +
')$'
),
threshold: 10240,
minRatio: 0.8
threshold: 0,
minRatio: 1
})
)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzip: true,
productionGzipExtensions: ['js', 'css'],

// Run the build command with an extra argument to
Expand Down
Loading

0 comments on commit f10bfcb

Please sign in to comment.