增加新功能
This commit is contained in:
parent
4b5c89786e
commit
eef87ab6e8
23
app.py
23
app.py
@ -18,6 +18,7 @@ SQUID_PASSWD_FILE = 'config/squid_passwd'
|
||||
def init_db():
|
||||
with sqlite3.connect(DATABASE) as conn:
|
||||
cursor = conn.cursor()
|
||||
# 创建admin_users表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS admin_users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@ -25,6 +26,8 @@ def init_db():
|
||||
password TEXT NOT NULL
|
||||
)
|
||||
''')
|
||||
|
||||
# 创建squid_users表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS squid_users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@ -33,6 +36,8 @@ def init_db():
|
||||
is_active INTEGER DEFAULT 1
|
||||
)
|
||||
''')
|
||||
|
||||
# 创建settings表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
id INTEGER PRIMARY KEY DEFAULT 1,
|
||||
@ -42,21 +47,23 @@ def init_db():
|
||||
)
|
||||
''')
|
||||
|
||||
# 检查是否有管理员用户
|
||||
# 检查并初始化管理员用户
|
||||
cursor.execute("SELECT COUNT(*) FROM admin_users")
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute(
|
||||
"INSERT INTO admin_users (username, password) VALUES (?, ?)",
|
||||
('admin', generate_password_hash('admin123'))
|
||||
)
|
||||
|
||||
# 检查是否有设置
|
||||
cursor.execute("SELECT COUNT(*) FROM settings")
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute(
|
||||
"INSERT INTO settings (proxy_address, proxy_port) VALUES (?, ?)",
|
||||
('proxy.example.com', '3128'))
|
||||
# 检查并初始化设置
|
||||
cursor.execute("SELECT COUNT(*) FROM settings")
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute(
|
||||
"INSERT INTO settings (proxy_address, proxy_port) VALUES (?, ?)",
|
||||
('proxy.example.com', '3128')
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.commit()
|
||||
|
||||
# 数据库连接
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user