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/sites.py

129 lines
3.6 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
6 months ago
from .option import getOption
6 months ago
__FIELD = 'id,name,path,status,ps,edate,type_id,add_time,update_time'
6 months ago
def checkSitesDomainIsExist(domain, port):
nums = mw.M('domain').where("name=? AND port=?", (domain, port,)).count()
if nums>0:
return True
nums = mw.M('binding').where("name=? AND port=?", (domain, port,)).count()
if nums>0:
return True
return False
6 months ago
def getSitesCount():
6 months ago
return mw.M('sites').count()
6 months ago
def getSitesById(site_id):
return mw.M('sites').field(__FIELD).where("id=?", (site_id,)).find()
6 months ago
def getSitesByName(site_name):
return mw.M('sites').field(__FIELD).where("name=?", (site_name,)).find()
def getSitesDomainById(site_id):
data = {}
domains = mw.M('domain').where('pid=?', (site_id,)).field('name,id').select()
binding = mw.M('binding').where('pid=?', (site_id,)).field('domain,id').select()
for b in binding:
t = {}
t['name'] = b['domain']
t['id'] = b['id']
domains.append(t)
data['domains'] = domains
6 months ago
data['email'] = getOption('ssl_email', default='')
6 months ago
return data
6 months ago
def addSites(name, path):
now_time = mw.getDateFromNow()
insert_data = {
'name': name,
'path': path,
'status': 1,
'ps':name,
'type_id':0,
'edate':'0000-00-00',
'add_time': now_time,
'update_time': now_time
}
return mw.M('sites').insert(insert_data)
def isSitesExist(name):
if mw.M('sites').where("name=?", (name,)).count() > 0:
return True
return False
6 months ago
def getSitesEdateList(edate):
elist = mw.M('sites').field(__FIELD).where('edate>? AND edate<? AND status=?', ('0000-00-00', edate, 1,)).select()
return elist
6 months ago
def getSitesList(
page:int | None = 1,
size:int | None = 10,
type_id:int | None = 0,
search: str | None = ''
):
sql_where = ''
if search != '' :
sql_where = " name like '%" + search + "%' or ps like '%" + search + "%' "
if type_id != '' and int(type_id) >= 0 and search != '' :
sql_where = sql_where + " and type_id=" + str(type_id) + ""
if type_id != '' and int(type_id) >= 0:
sql_where = " type_id=" + str(type_id)
6 months ago
dbM = dbC = mw.M('sites').field(__FIELD)
6 months ago
if sql_where != '':
count = dbC.where(sql_where).count()
else:
count = dbC.count()
start = (int(page) - 1) * (int(size))
limit = str(start) + ',' +str(size)
site_list = dbM.limit(limit).order('id desc').select()
data = {}
data['list'] = site_list
data['count'] = count
return data
6 months ago
6 months ago
def deleteSitesById(site_id):
return mw.M('sites').where("id=?", (site_id,)).delete()
def setSitesData(site_id,
edate: str | None = None,
ps: str | None = None,
6 months ago
path: str | None = None,
6 months ago
status: str | None = None,
6 months ago
):
update_data = {}
if edate is not None:
update_data['edate'] = edate
if ps is not None:
update_data['ps'] = ps
6 months ago
if path is not None:
update_data['path'] = path
6 months ago
if status is not None:
update_data['status'] = status
6 months ago
return mw.M('sites').where('id=?',(site_id,)).update(update_data)