diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..de6b7f4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+Comments.db
diff --git a/Source/Comments.sql b/Source/Comments.sql
new file mode 100644
index 0000000..265106a
--- /dev/null
+++ b/Source/Comments.sql
@@ -0,0 +1,31 @@
+CREATE TABLE IF NOT EXISTS "Users" (
+ "ID" INTEGER NOT NULL UNIQUE,
+ "Name" TEXT NOT NULL,
+ "SecKey" TEXT NOT NULL UNIQUE,
+ PRIMARY KEY("ID" AUTOINCREMENT)
+);
+
+CREATE TABLE IF NOT EXISTS "Sites" (
+ "ID" INTEGER NOT NULL UNIQUE,
+ "PubKey" TEXT NOT NULL UNIQUE,
+ "SecKey" TEXT NOT NULL UNIQUE,
+ PRIMARY KEY("ID" AUTOINCREMENT)
+);
+
+CREATE TABLE IF NOT EXISTS "Pages" (
+ "ID" INTEGER NOT NULL UNIQUE,
+ "Site" INTEGER NOT NULL,
+ "Path" TEXT NOT NULL,
+ PRIMARY KEY("ID" AUTOINCREMENT),
+ FOREIGN KEY("Site") REFERENCES "Sites"("ID")
+);
+
+CREATE TABLE IF NOT EXISTS "Comments" (
+ "ID" INTEGER NOT NULL UNIQUE,
+ "User" INTEGER NOT NULL,
+ "Page" TEXT NOT NULL,
+ "Reply" INTEGER,
+ PRIMARY KEY("ID" AUTOINCREMENT),
+ FOREIGN KEY("Page") REFERENCES "Pages"("ID"),
+ FOREIGN KEY("User") REFERENCES "Users"("ID")
+);
diff --git a/Source/Form.Comment.html b/Source/Form.Comment.html
index 533892f..5dcd37f 100644
--- a/Source/Form.Comment.html
+++ b/Source/Form.Comment.html
@@ -1,5 +1,6 @@
diff --git a/Source/Server.py b/Source/Server.py
index 813f27a..d10cd79 100755
--- a/Source/Server.py
+++ b/Source/Server.py
@@ -7,6 +7,7 @@
| =============================== """
import json
+import sqlite3
from ast import literal_eval
from flask import Flask, request, send_file
#from APIConfig import *
@@ -30,11 +31,11 @@ def WriteFile(p, c):
print("Error writing file {}".format(p))
return False
-def SetConfig():
+def GetConfig():
Config = {
'Development': False,
'Port': 8080}
- File = ReadFile('Config.json')
+ File = ReadFile('Config.json')
if File:
File = json.loads(File)
for i in File:
@@ -42,10 +43,18 @@ def SetConfig():
Config[i] = File[i]
return Config
+def InitDB():
+ for i in ReadFile('Source/Comments.sql').split(';'):
+ DB.cursor().execute(i)
+ DB.commit()
+
+def GetDB():
+ return sqlite3.connect('Comments.db')
+
def GetComments():
return [0,0,0]
-def PatchHTML():
+def PatchHTML(Data):
Base = ReadFile('Source/Main.html')
FormMain = ReadFile('Source/Form.Main.html')
FormComment = ReadFile('Source/Form.Comment.html')
@@ -60,17 +69,11 @@ def PatchHTML():
return Base.format(FormMain + Comments)
def Get(Req):
- Data = Req.args
- print(Data.get('Site'))
- print(Data.get('Page'))
- print(Data.get('User'))
- print(Data.get('CAPTCHA'))
- print(Data.get('Comment'))
- print(Data.get('SecretKey'))
- print(Data.get('Action'))
- print(Data.get('Reply'))
- print(Data.get('Report'))
- return PatchHTML()
+ Data = {}
+ for i in ['Site','Page','User','CAPTCHA','Comment','SecretKey','Select','Action','Reply','Report']:
+ Data.update({i:Req.args.get(i)})
+ print(Req.args.get(i))
+ return PatchHTML(Data)
def Post(Req):
Data = Req.get_json()
@@ -89,7 +92,9 @@ def Comments():
return Post(Req)
if __name__ == '__main__':
- Config = SetConfig()
+ Config = GetConfig()
+ DB = GetDB()
+ InitDB()
if Config['Development']:
App.run(host='0.0.0.0', port=Config['Port'], debug=True)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..4319354
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+flask
+waitress