diff --git a/.Config.json.kate-swp b/.Config.json.kate-swp
deleted file mode 100644
index 4efa903..0000000
Binary files a/.Config.json.kate-swp and /dev/null differ
diff --git a/Config.json b/Config.json
index f008140..33c0862 100644
--- a/Config.json
+++ b/Config.json
@@ -1,4 +1,3 @@
{
- "Development": true,
- "Port": 8080
+ "Development": true
}
diff --git a/Locale/en.json b/Locale/en.json
index d5a739e..f6c77a9 100644
--- a/Locale/en.json
+++ b/Locale/en.json
@@ -4,8 +4,12 @@
"DoDelete": "Delete",
"DoReply": "Reply",
"Reply": "Reply",
- "SecretKey": "Secret Key",
+ "SecKey": "Secret Key",
"Optional": "Optional",
"YourName": "Your Name",
- "DoPost": "Post as New Comment"
+ "DoPost": "Post as New Comment",
+ "Management": "Management",
+ "AddSite": "Add New Site",
+ "DelSite": "DELETE SITE",
+ "DangerZone": "Danger Zone"
}
diff --git a/Locale/it.json b/Locale/it.json
index b0c7446..305ce3b 100644
--- a/Locale/it.json
+++ b/Locale/it.json
@@ -4,8 +4,12 @@
"DoDelete": "Cancella",
"DoReply": "Rispondi",
"Reply": "Risposta",
- "SecretKey": "Chiave Segreta",
+ "SecKey": "Chiave Segreta",
"Optional": "Opzionale",
"YourName": "Il tuo Nome",
- "DoPost": "Pubblica come Nuovo Commento"
+ "DoPost": "Pubblica come Nuovo Commento",
+ "Management": "Gestione",
+ "AddSite": "Aggiungi Nuovo Sito",
+ "DelSite": "CANCELLA SITO",
+ "DangerZone": "Zona Pericolosa"
}
diff --git a/Source/Form.Base.html b/Source/Form.Base.html
index cbe1ee1..689d47e 100644
--- a/Source/Form.Base.html
+++ b/Source/Form.Base.html
@@ -6,7 +6,14 @@
-
diff --git a/Source/Form.Main.html b/Source/Form.Main.html
index a39d221..ec84cf1 100644
--- a/Source/Form.Main.html
+++ b/Source/Form.Main.html
@@ -4,8 +4,8 @@
-
-
+
+
@@ -14,12 +14,12 @@
-
-
+
+
-
+
diff --git a/Source/Manage.html b/Source/Manage.html
index 53a7f24..d1700b4 100644
--- a/Source/Manage.html
+++ b/Source/Manage.html
@@ -1,6 +1,31 @@
+
+ PlainDiscuss > [Locale:Management]
+
+{StatusGood}
+
+
+{StatusError}
+
+
diff --git a/Source/Server.py b/Source/Server.py
index e3c894d..1112bff 100755
--- a/Source/Server.py
+++ b/Source/Server.py
@@ -7,6 +7,7 @@
| =============================== """
import json
+import secrets
import sqlite3
import time
from ast import literal_eval
@@ -41,11 +42,18 @@ def GetLocales():
Locales.update({Lang:Locale})
return Locales
+def SelectLocale(Data):
+ if Data['Lang'] and Data['Lang'] in Locales:
+ return Locales[Data['Lang']]
+ else:
+ return Locales[Config['Default Locale']]
+
def GetConfig():
Config = {
'Development': False,
'Port': 8080,
- 'Default Locale': 'en'}
+ 'Default Locale': 'en',
+ 'Antispam Time': 0}
File = ReadFile('Config.json')
if File:
File = json.loads(File)
@@ -60,7 +68,8 @@ def InitDB():
DB.commit()
def GetDB():
- return sqlite3.connect('Comments.db')
+ DB = sqlite3.connect('Comments.db')
+ return DB
def GetComments(Site, Page):
DB = GetDB()
@@ -69,24 +78,26 @@ def GetComments(Site, Page):
PageID = DB.cursor().execute('SELECT "ID" FROM "Pages" WHERE "Site" == "{}" AND "Path" == "{}"'.format(SiteID, Page))
Comments = DB.cursor().execute('SELECT * FROM "Comments" WHERE "Page" == "{}"'.format(PageID))
- DB.close()
+ DB.commit()
return Comments
-def PatchHTML(Data):
+def PatchCommentsHTML(Data):
FormBase = ReadFile('Source/Form.Base.html')
FormMain = ReadFile('Source/Form.Main.html')
FormComment = ReadFile('Source/Form.Comment.html')
- if Data['Lang'] and Data['Lang'] in Locales:
- Locale = Locales[Data['Lang']]
- else:
- Locale = Locales[Config['Default Locale']]
+ Locale = SelectLocale(Data)
for String in Locale:
FormBase = FormBase.replace('[Locale:{}]'.format(String), Locale[String])
FormMain = FormMain.replace('[Locale:{}]'.format(String), Locale[String])
FormComment = FormComment.replace('[Locale:{}]'.format(String), Locale[String])
+ FormMain = FormMain.format(
+ SecKey=Data['SecKey'] if Data['SecKey'] else '',
+ User=Data['User'] if Data['User'] else '',
+ Comment=Data['Comment'] if Data['Comment'] else '')
+
Comments = ''
for Comment in GetComments(Data['Site'], Data['Page']):
Comments += "\n
\n" + FormComment.format(
@@ -95,43 +106,118 @@ def PatchHTML(Data):
ID="ID",
Comment="Comment")
- return FormBase.format(Style='',Form=FormMain+Comments)
+ return FormBase.format(
+ Lang=Data['Lang'] if Data['Lang'] else '',
+ Style='',
+ Site=Data['Site'] if Data['Site'] else '',
+ Page=Data['Page'] if Data['Page'] else '',
+ Form=FormMain+Comments,
+ StatusGood='',
+ StatusError='')
-def Get(Req):
+def CommentsGet(Req):
Data = {}
for i in ['Lang','StyleFile','Site','Page']:
Data.update({i:Req.args.get(i)})
- return PatchHTML(Data)
+ return PatchCommentsHTML(Data)
-def Post(Req):
+def CommentsPost(Req):
Data = {}
- for i in ['Lang','StyleFile','Site','Page','User','CAPTCHA','Comment','SecretKey','Action','Reply','Report','Delete']:
- Data.update({i:Req.args.get(i)})
- return PatchHTML(Data)
-
-@App.route('/Manage.html')
-def SendManage():
- return send_file('Manage.html')
-
-@App.route('/Main.css')
-def SendCSS():
- return send_file('Main.css')
+ for i in ['Lang','StyleFile','Site','Page','User','CAPTCHA','Comment','SecKey','Action','Reply','Report','Delete']:
+ Data.update({i:Req.form.get(i)})
+ return PatchCommentsHTML(Data)
@App.route('/Comments', methods=['GET', 'POST'])
def Comments():
Req = request
if Req.method == 'GET':
- return Get(Req)
+ return CommentsGet(Req)
if Req.method == 'POST':
- return Post(Req)
+ return CommentsPost(Req)
+
+@App.route('/Main.css')
+def SendCSS():
+ return send_file('Main.css')
+
+def AddSite():
+ PubKey = secrets.token_urlsafe(32)
+ SecKey = secrets.token_urlsafe(64)
+ Good, Error = "", ""
+ try:
+ DB = GetDB()
+ DB.cursor().execute('INSERT INTO "Sites"("PubKey", "SecKey") VALUES("{}", "{}")'.format(PubKey, SecKey))
+ DB.commit()
+ Good = """\
+
+ Created your new site API keys. Please store these safely, they can't be recovered.
+
+ Public Key (for showing comments on your site):
{}
+ Secret Key (for managing comments, KEEP IT SECRET): {}
+""".format(PubKey, SecKey)
+ except Exception:
+ Error = "Server error. Please try again later.
"
+ return Good, Error
+
+def DelSite():
+ pass
+
+def PatchManageHTML(Data):
+ HTML = ReadFile('Source/Manage.html')
+
+ Locale = SelectLocale(Data)
+
+ for String in Locale:
+ HTML = HTML.replace('[Locale:{}]'.format(String), Locale[String])
+
+ if 'Action' in Data and Data['Action']:
+ if Data['Action'] == 'AddSite':
+ Good, Error = AddSite()
+ elif Data['Action'] == 'DelSite':
+ Good, Error = DelSite()
+ else:
+ Good, Error = '', ''
+
+ return HTML.format(
+ Lang=Data['Lang'] if Data['Lang'] else '',
+ StatusGood=Good,
+ StatusError=Error)
+
+"""
+def ManageGet(Req):
+ Data = {}
+ for i in ['Lang']:
+ Data.update({i:Req.args.get(i)})
+ return PatchManageHTML(Data)
+
+def ManagePost(Req):
+ Data = {}
+ for i in ['Lang', 'Action']:
+ Data.update({i:Req.form.get(i)})
+ return PatchManageHTML(Data)
+"""
+
+@App.route('/Manage', methods=['GET', 'POST'])
+def SendManage():
+ Req = request
+ Data = {}
+ if Req.method == 'GET':
+ #return ManageGet(Req)
+ for i in ['Lang']:
+ Data.update({i:Req.args.get(i)})
+ elif Req.method == 'POST':
+ #return ManagePost(Req)
+ for i in ['Lang', 'Action']:
+ Data.update({i:Req.form.get(i)})
+ return PatchManageHTML(Data)
if __name__ == '__main__':
Locales = GetLocales()
Config = GetConfig()
+ #DB = sqlite3.connect('Comments.db')
DB = GetDB()
InitDB()
- DB.close()
+ #DB.close()
if Config['Development']:
App.run(host='0.0.0.0', port=Config['Port'], debug=True)