Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/web/thisdb/firewall.py

50 lines
1.4 KiB

6 months ago
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
import core.mw as mw
__FIELD = 'id,port,protocol,ps,add_time,update_time'
6 months ago
def getFirewallList(page=1,size=10):
6 months ago
start = (int(page) - 1) * (int(size))
limit = str(start) + ',' +str(size)
firewall_list = mw.M('firewall').field(__FIELD).limit(limit).order('id desc').select()
count = mw.M('firewall').count()
data = {}
data['count'] = count
data['list'] = firewall_list
return data
6 months ago
def addFirewall(port, protocol='tcp',ps='备注') -> bool:
6 months ago
'''
设置配置的值
:port -> str 端口 (必填)
:protocol -> str 协议 (可选|tcp,udp,tcp/udp)
:ps -> str 备注 (可选)
'''
now_time = mw.formatDate()
insert_data = {
'port':port,
'protocol':protocol,
'ps':ps,
'add_time':now_time,
'update_time':now_time,
}
mw.M('firewall').insert(insert_data)
return True
def getFirewallCountByPort(port):
return mw.M('firewall').where('port=?',(port,)).count()