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/class/core/common.py

84 lines
1.9 KiB

6 years ago
# coding: utf-8
import os
import sys
import time
import string
import json
import hashlib
import shlex
import datetime
import subprocess
import re
import hashlib
6 years ago
from random import Random
6 years ago
import mw
6 years ago
import db
6 years ago
from flask import redirect
6 years ago
def init():
6 years ago
6 years ago
initDB()
initInitD()
6 years ago
initUserInfo()
6 years ago
6 years ago
def local():
result = checkClose()
if result:
return result
6 years ago
# 检查面板是否关闭
def checkClose():
if os.path.exists('data/close.pl'):
return redirect('/close')
6 years ago
def initDB():
try:
sql = db.Sql().dbfile('default')
csql = mw.readFile('data/sql/default.sql')
6 years ago
csql_list = csql.split(';')
for index in range(len(csql_list)):
sql.execute(csql_list[index], ())
6 years ago
6 years ago
except Exception, ex:
print str(ex)
def initInitD():
script = mw.getRunDir() + '/scripts/init.d/mw.tpl'
script_bin = mw.getRunDir() + '/scripts/init.d/mw'
6 years ago
# if os.path.exists(script_bin):
# return
6 years ago
content = mw.readFile(script)
content = content.replace("{$SERVER_PATH}", mw.getRunDir())
6 years ago
mw.writeFile(script_bin, content)
mw.execShell('chmod +x ' + script_bin)
6 years ago
if not mw.isAppleSystem():
6 years ago
initd_bin = '/etc/init.d/mw'
if not os.path.exists(initd_bin):
6 years ago
import shutil
6 years ago
shutil.copyfile(script_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
# 加入自启动
mw.execShell('chkconfig --add mw')
6 years ago
def initUserInfo():
data = mw.M('users').where('id=?', (1,)).getField('password')
6 years ago
if data == '21232f297a57a5a743894a0e4a801fc3':
pwd = mw.getRandomString(8).lower()
file_pw = mw.getRunDir() + '/data/default.pl'
mw.writeFile(file_pw, pwd)
mw.M('users').where('id=?', (1,)).setField(
'password', mw.md5(pwd))