pull/109/head
midoks 6 years ago
parent 01286e692d
commit 3a59b701c6
  1. 24
      data/sql/default.sql
  2. 79
      plugins/mysql/class/mysql.py
  3. 17
      plugins/mysql/conf/mysql.sql
  4. 38
      plugins/mysql/index.py
  5. 3
      requirements.txt

@ -19,19 +19,6 @@ CREATE TABLE IF NOT EXISTS `binding` (
); );
CREATE TABLE IF NOT EXISTS `config` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`webserver` TEXT,
`backup_path` TEXT,
`sites_path` TEXT,
`status` INTEGER,
`mysql_root` TEXT
);
INSERT INTO `config` (`id`, `webserver`, `backup_path`, `sites_path`, `status`, `mysql_root`) VALUES
(1, 'nginx', '/www/backup', '/www/wwwroot', 0, 'admin');
CREATE TABLE IF NOT EXISTS `crontab` ( CREATE TABLE IF NOT EXISTS `crontab` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT, `name` TEXT,
@ -50,17 +37,6 @@ CREATE TABLE IF NOT EXISTS `crontab` (
`urladdress` TEXT `urladdress` TEXT
); );
CREATE TABLE IF NOT EXISTS `databases` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`pid` INTEGER,
`name` TEXT,
`username` TEXT,
`password` TEXT,
`accept` TEXT,
`ps` TEXT,
`addtime` TEXT
);
CREATE TABLE IF NOT EXISTS `firewall` ( CREATE TABLE IF NOT EXISTS `firewall` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
`port` TEXT, `port` TEXT,

@ -0,0 +1,79 @@
# coding: utf-8
import re
import os
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")
class mysql:
__DB_PASS = None
__DB_USER = 'root'
__DB_PORT = 3306
__DB_HOST = 'localhost'
__DB_CONN = None
__DB_CUR = None
__DB_ERR = None
__DB_CNF = '/etc/my.cnf'
def __Conn(self):
'''连接MYSQL数据库'''
try:
import public
socket = '/tmp/mysql.sock'
try:
import MySQLdb
except Exception, ex:
self.__DB_ERR = ex
return False
try:
myconf = public.readFile(self.__DB_CNF)
rep = "port\s*=\s*([0-9]+)"
self.__DB_PORT = int(re.search(rep, myconf).groups()[0])
except:
self.__DB_PORT = 3306
#self.__DB_PASS = public.M('config').where('id=?', (1,)).getField('mysql_root')
try:
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
port=self.__DB_PORT, charset="utf8", connect_timeout=1, unix_socket=socket)
except MySQLdb.Error, e:
self.__DB_HOST = '127.0.0.1'
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
port=self.__DB_PORT, charset="utf8", connect_timeout=1, unix_socket=socket)
self.__DB_CUR = self.__DB_CONN.cursor()
return True
except MySQLdb.Error, e:
self.__DB_ERR = e
return False
def execute(self, sql):
# 执行SQL语句返回受影响行
if not self.__Conn():
return self.__DB_ERR
try:
result = self.__DB_CUR.execute(sql)
self.__DB_CONN.commit()
self.__Close()
return result
except Exception, ex:
return ex
def query(self, sql):
# 执行SQL语句返回数据集
if not self.__Conn():
return self.__DB_ERR
try:
self.__DB_CUR.execute(sql)
result = self.__DB_CUR.fetchall()
# 将元组转换成列表
data = map(list, result)
self.__Close()
return data
except Exception, ex:
return ex
# 关闭连接
def __Close(self):
self.__DB_CUR.close()
self.__DB_CONN.close()

@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS `config` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`mysql_root` TEXT
);
INSERT INTO `config` (`id`, `mysql_root`) VALUES (1, 'admin');
CREATE TABLE IF NOT EXISTS `databases` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`pid` INTEGER,
`name` TEXT,
`username` TEXT,
`password` TEXT,
`accept` TEXT,
`ps` TEXT,
`addtime` TEXT
);

@ -10,6 +10,7 @@ import re
sys.path.append(os.getcwd() + "/class/core") sys.path.append(os.getcwd() + "/class/core")
import public import public
app_debug = False app_debug = False
if public.isAppleSystem(): if public.isAppleSystem():
app_debug = True app_debug = True
@ -22,6 +23,9 @@ def getPluginName():
def getPluginDir(): def getPluginDir():
return public.getPluginDir() + '/' + getPluginName() return public.getPluginDir() + '/' + getPluginName()
sys.path.append(getPluginDir() + "/class")
import mysql
def getServerDir(): def getServerDir():
return public.getServerDir() + '/' + getPluginName() return public.getServerDir() + '/' + getPluginName()
@ -51,7 +55,7 @@ def getArgs():
def getConf(): def getConf():
path = getServerDir() + '/conf/my.cnf' path = getServerDir() + '/etc/my.cnf'
return path return path
@ -68,6 +72,24 @@ def contentReplace(content):
return content return content
def pSqliteDb():
file = getServerDir() + '/mysql.db'
name = 'mysql'
if not os.path.exists(file):
conn = public.M(name).dbPos(getServerDir(), name)
csql = public.readFile(getPluginDir() + '/conf/mysql.sql')
csql_list = csql.split(';')
for index in range(len(csql_list)):
conn.execute(csql_list[index], ())
else:
conn = public.M(name).dbPos(getServerDir(), name)
return conn
def pMysqlDb():
return ''
def initDreplace(): def initDreplace():
initd_tpl = getInitdTpl() initd_tpl = getInitdTpl()
@ -82,7 +104,7 @@ def initDreplace():
public.writeFile(file_bin, content) public.writeFile(file_bin, content)
public.execShell('chmod +x ' + file_bin) public.execShell('chmod +x ' + file_bin)
mysql_conf_dir = getServerDir() + '/conf' mysql_conf_dir = getServerDir() + '/etc'
if not os.path.exists(mysql_conf_dir): if not os.path.exists(mysql_conf_dir):
os.mkdir(mysql_conf_dir) os.mkdir(mysql_conf_dir)
@ -120,6 +142,10 @@ def initMysqlData():
cmd = 'cd ' + serverdir + ' && ./scripts/mysql_install_db --user=midoks --basedir=' + \ cmd = 'cd ' + serverdir + ' && ./scripts/mysql_install_db --user=midoks --basedir=' + \
serverdir + ' --ldata=' + datadir serverdir + ' --ldata=' + datadir
public.execShell(cmd) public.execShell(cmd)
pwd = public.getRandomString(16)
cmd_pass = serverdir + '/bin/mysqladmin -uroot -p12345'
print cmd_pass
return True return True
@ -187,6 +213,14 @@ def initdUinstall():
return 'ok' return 'ok'
def runInfo():
db = mysql.mysql()
db.__DB_CNF = getConf()
data = db.query('show global status')
print data
return 'ok'
def getShowLog(): def getShowLog():
return 'ok' return 'ok'

@ -3,4 +3,5 @@ flask_session
gunicorn gunicorn
psutil psutil
pillow pillow
chardet chardet
MySQL-python
Loading…
Cancel
Save