mirror of
https://gitlab.com/octtspacc/PlainDiscuss
synced 2025-06-05 22:09:15 +02:00
Add CAPTCHA
This commit is contained in:
BIN
CAPTCHA/OpenDyslexic3-Regular.ttf
Normal file
BIN
CAPTCHA/OpenDyslexic3-Regular.ttf
Normal file
Binary file not shown.
BIN
CAPTCHA/en/0/default.wav
Normal file
BIN
CAPTCHA/en/0/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/1/default.wav
Normal file
BIN
CAPTCHA/en/1/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/2/default.wav
Normal file
BIN
CAPTCHA/en/2/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/3/default.wav
Normal file
BIN
CAPTCHA/en/3/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/4/default.wav
Normal file
BIN
CAPTCHA/en/4/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/5/default.wav
Normal file
BIN
CAPTCHA/en/5/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/6/default.wav
Normal file
BIN
CAPTCHA/en/6/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/7/default.wav
Normal file
BIN
CAPTCHA/en/7/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/8/default.wav
Normal file
BIN
CAPTCHA/en/8/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/9/default.wav
Normal file
BIN
CAPTCHA/en/9/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/a/default.wav
Normal file
BIN
CAPTCHA/en/a/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/b/default.wav
Normal file
BIN
CAPTCHA/en/b/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/c/default.wav
Normal file
BIN
CAPTCHA/en/c/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/d/default.wav
Normal file
BIN
CAPTCHA/en/d/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/e/default.wav
Normal file
BIN
CAPTCHA/en/e/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/f/default.wav
Normal file
BIN
CAPTCHA/en/f/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/g/default.wav
Normal file
BIN
CAPTCHA/en/g/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/h/default.wav
Normal file
BIN
CAPTCHA/en/h/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/i/default.wav
Normal file
BIN
CAPTCHA/en/i/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/j/default.wav
Normal file
BIN
CAPTCHA/en/j/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/k/default.wav
Normal file
BIN
CAPTCHA/en/k/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/l/default.wav
Normal file
BIN
CAPTCHA/en/l/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/m/default.wav
Normal file
BIN
CAPTCHA/en/m/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/n/default.wav
Normal file
BIN
CAPTCHA/en/n/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/o/default.wav
Normal file
BIN
CAPTCHA/en/o/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/p/default.wav
Normal file
BIN
CAPTCHA/en/p/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/q/default.wav
Normal file
BIN
CAPTCHA/en/q/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/r/default.wav
Normal file
BIN
CAPTCHA/en/r/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/s/default.wav
Normal file
BIN
CAPTCHA/en/s/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/t/default.wav
Normal file
BIN
CAPTCHA/en/t/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/u/default.wav
Normal file
BIN
CAPTCHA/en/u/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/v/default.wav
Normal file
BIN
CAPTCHA/en/v/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/w/default.wav
Normal file
BIN
CAPTCHA/en/w/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/x/default.wav
Normal file
BIN
CAPTCHA/en/x/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/y/default.wav
Normal file
BIN
CAPTCHA/en/y/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/en/z/default.wav
Normal file
BIN
CAPTCHA/en/z/default.wav
Normal file
Binary file not shown.
59334
CAPTCHA/it.txt
Normal file
59334
CAPTCHA/it.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
CAPTCHA/it/0/default.wav
Normal file
BIN
CAPTCHA/it/0/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/1/default.wav
Normal file
BIN
CAPTCHA/it/1/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/2/default.wav
Normal file
BIN
CAPTCHA/it/2/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/3/default.wav
Normal file
BIN
CAPTCHA/it/3/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/4/default.wav
Normal file
BIN
CAPTCHA/it/4/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/5/default.wav
Normal file
BIN
CAPTCHA/it/5/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/6/default.wav
Normal file
BIN
CAPTCHA/it/6/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/7/default.wav
Normal file
BIN
CAPTCHA/it/7/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/8/default.wav
Normal file
BIN
CAPTCHA/it/8/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/9/default.wav
Normal file
BIN
CAPTCHA/it/9/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/a/default.wav
Normal file
BIN
CAPTCHA/it/a/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/b/default.wav
Normal file
BIN
CAPTCHA/it/b/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/c/default.wav
Normal file
BIN
CAPTCHA/it/c/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/d/default.wav
Normal file
BIN
CAPTCHA/it/d/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/e/default.wav
Normal file
BIN
CAPTCHA/it/e/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/f/default.wav
Normal file
BIN
CAPTCHA/it/f/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/g/default.wav
Normal file
BIN
CAPTCHA/it/g/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/h/default.wav
Normal file
BIN
CAPTCHA/it/h/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/i/default.wav
Normal file
BIN
CAPTCHA/it/i/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/j/default.wav
Normal file
BIN
CAPTCHA/it/j/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/k/default.wav
Normal file
BIN
CAPTCHA/it/k/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/l/default.wav
Normal file
BIN
CAPTCHA/it/l/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/m/default.wav
Normal file
BIN
CAPTCHA/it/m/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/n/default.wav
Normal file
BIN
CAPTCHA/it/n/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/o/default.wav
Normal file
BIN
CAPTCHA/it/o/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/p/default.wav
Normal file
BIN
CAPTCHA/it/p/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/q/default.wav
Normal file
BIN
CAPTCHA/it/q/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/r/default.wav
Normal file
BIN
CAPTCHA/it/r/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/s/default.wav
Normal file
BIN
CAPTCHA/it/s/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/t/default.wav
Normal file
BIN
CAPTCHA/it/t/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/u/default.wav
Normal file
BIN
CAPTCHA/it/u/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/v/default.wav
Normal file
BIN
CAPTCHA/it/v/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/w/default.wav
Normal file
BIN
CAPTCHA/it/w/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/x/default.wav
Normal file
BIN
CAPTCHA/it/x/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/y/default.wav
Normal file
BIN
CAPTCHA/it/y/default.wav
Normal file
Binary file not shown.
BIN
CAPTCHA/it/z/default.wav
Normal file
BIN
CAPTCHA/it/z/default.wav
Normal file
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"Development": true
|
"Development": true,
|
||||||
|
"Port": 8081
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h3>[Locale:Comments]</h3>
|
||||||
<div id="StatusGoodDiv">
|
<div id="StatusGoodDiv">
|
||||||
{StatusGood}
|
{StatusGood}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<div>
|
<div>
|
||||||
<h3>Comments</h3>
|
|
||||||
<button type="submit" name="Action" value="Login">Admin Login</button>
|
<button type="submit" name="Action" value="Login">Admin Login</button>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
@ -9,8 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<label>CAPTCHA:</label>
|
{CAPTCHAHTML}
|
||||||
<span><input type="text" name="CAPTCHA"></span>
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
|
@ -7,18 +7,23 @@
|
|||||||
| =============================== """
|
| =============================== """
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import random
|
||||||
import secrets
|
import secrets
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
|
from base64 import b64encode
|
||||||
from flask import Flask, request, send_file
|
from flask import Flask, request, send_file
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from captcha.audio import AudioCaptcha
|
||||||
|
from captcha.image import ImageCaptcha
|
||||||
|
|
||||||
App = Flask(__name__)
|
App = Flask(__name__)
|
||||||
|
|
||||||
def ReadFile(p):
|
def ReadFile(p, m='r'):
|
||||||
try:
|
try:
|
||||||
with open(p, 'r') as f:
|
with open(p, m) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Error reading file {}".format(p))
|
print("Error reading file {}".format(p))
|
||||||
@ -53,7 +58,7 @@ def GetConfig():
|
|||||||
'Development': False,
|
'Development': False,
|
||||||
'Port': 8080,
|
'Port': 8080,
|
||||||
'Default Locale': 'en',
|
'Default Locale': 'en',
|
||||||
'Antispam Time': 0}
|
'CAPTCHA': True}
|
||||||
File = ReadFile('Config.json')
|
File = ReadFile('Config.json')
|
||||||
if File:
|
if File:
|
||||||
File = json.loads(File)
|
File = json.loads(File)
|
||||||
@ -71,6 +76,40 @@ def GetDB():
|
|||||||
DB = sqlite3.connect('Comments.db')
|
DB = sqlite3.connect('Comments.db')
|
||||||
return DB
|
return DB
|
||||||
|
|
||||||
|
def RandomWord():
|
||||||
|
Words = ReadFile('CAPTCHA/it.txt')
|
||||||
|
Word = '#'
|
||||||
|
while Word.startswith('#'):
|
||||||
|
Word = random.choice(Words.splitlines())
|
||||||
|
return Word.lower()
|
||||||
|
|
||||||
|
def MakeCAPTCHA(ID):
|
||||||
|
#ID = time.time()
|
||||||
|
String = RandomWord()
|
||||||
|
Audio = AudioCaptcha(voicedir='CAPTCHA/it')
|
||||||
|
Image = ImageCaptcha(fonts=['CAPTCHA/OpenDyslexic3-Regular.ttf'],width=len(String)*40, height=90)
|
||||||
|
CAPTCHA = Audio.generate(String)
|
||||||
|
Audio.write(String, 'CAPTCHA.{}.wav'.format(ID))
|
||||||
|
CAPTCHA = Image.generate(String)
|
||||||
|
Image.write(String, 'CAPTCHA.{}.png'.format(ID))
|
||||||
|
#return ID
|
||||||
|
|
||||||
|
def CAPTCHAHTML(ID):
|
||||||
|
#ID = MakeCAPTCHA()
|
||||||
|
MakeCAPTCHA(ID)
|
||||||
|
Audio = b64encode(ReadFile('CAPTCHA.{}.wav'.format(ID), 'rb'))
|
||||||
|
Image = b64encode(ReadFile('CAPTCHA.{}.png'.format(ID), 'rb'))
|
||||||
|
os.remove('CAPTCHA.{}.wav'.format(ID))
|
||||||
|
os.remove('CAPTCHA.{}.png'.format(ID))
|
||||||
|
return """\
|
||||||
|
<label>CAPTCHA:</label>
|
||||||
|
<br>
|
||||||
|
<img src="data:image/png;base64,{}">
|
||||||
|
<audio src="data:audio/wav;base64,{}"controls="controls"></audio>
|
||||||
|
<br>
|
||||||
|
<span><input type="text" name="CAPTCHA"></span>
|
||||||
|
""".format(Image.decode('UTF-8'), Audio.decode('UTF-8'))
|
||||||
|
|
||||||
def GetComments(Site, Page):
|
def GetComments(Site, Page):
|
||||||
DB = GetDB()
|
DB = GetDB()
|
||||||
Comments = []
|
Comments = []
|
||||||
@ -134,6 +173,7 @@ def PostCommentData(Data):
|
|||||||
return Good, Error
|
return Good, Error
|
||||||
|
|
||||||
def PatchCommentsHTML(Data):
|
def PatchCommentsHTML(Data):
|
||||||
|
ReqID = time.time()
|
||||||
FormBase = ReadFile('Source/Form.Base.html')
|
FormBase = ReadFile('Source/Form.Base.html')
|
||||||
FormMain = ReadFile('Source/Form.Main.html')
|
FormMain = ReadFile('Source/Form.Main.html')
|
||||||
FormComment = ReadFile('Source/Form.Comment.html')
|
FormComment = ReadFile('Source/Form.Comment.html')
|
||||||
@ -145,22 +185,26 @@ def PatchCommentsHTML(Data):
|
|||||||
FormMain = FormMain.replace('[Locale:{}]'.format(String), Locale[String])
|
FormMain = FormMain.replace('[Locale:{}]'.format(String), Locale[String])
|
||||||
FormComment = FormComment.replace('[Locale:{}]'.format(String), Locale[String])
|
FormComment = FormComment.replace('[Locale:{}]'.format(String), Locale[String])
|
||||||
|
|
||||||
FormMain = FormMain.format(
|
if 'ReadOnly' in Data and Data['ReadOnly'] == 'True':
|
||||||
SecKey=Data['SecKey'] if 'SecKey' in Data and Data['SecKey'] else '',
|
FormMain, Good, Error = '', '', ''
|
||||||
User=Data['User'] if 'User' in Data and Data['User'] else '',
|
|
||||||
Comment=Data['Comment'] if 'Comment' in Data and Data['Comment'] else '')
|
|
||||||
|
|
||||||
if 'Action' in Data and Data['Action']:
|
|
||||||
if Data['Action'] == 'Login':
|
|
||||||
Good, Error = '', ''
|
|
||||||
elif Data['Action'] == 'Post':
|
|
||||||
Good, Error = PostCommentData(Data)
|
|
||||||
elif 'Reply' in Data and Data['Reply']:
|
|
||||||
Good, Error = PostCommentData(Data)
|
|
||||||
elif 'Delete' in Data and Data['Delete']:
|
|
||||||
Good, Error = '', ''
|
|
||||||
else:
|
else:
|
||||||
Good, Error = '', ''
|
FormMain = FormMain.format(
|
||||||
|
CAPTCHAHTML=CAPTCHAHTML(ReqID) if Config['CAPTCHA'] else '',
|
||||||
|
SecKey=Data['SecKey'] if 'SecKey' in Data and Data['SecKey'] else '',
|
||||||
|
User=Data['User'] if 'User' in Data and Data['User'] else '',
|
||||||
|
Comment=Data['Comment'] if 'Comment' in Data and Data['Comment'] else '')
|
||||||
|
|
||||||
|
if 'Action' in Data and Data['Action']:
|
||||||
|
if Data['Action'] == 'Login':
|
||||||
|
Good, Error = '', ''
|
||||||
|
elif Data['Action'] == 'Post':
|
||||||
|
Good, Error = PostCommentData(Data)
|
||||||
|
elif 'Reply' in Data and Data['Reply']:
|
||||||
|
Good, Error = PostCommentData(Data)
|
||||||
|
elif 'Delete' in Data and Data['Delete']:
|
||||||
|
Good, Error = '', ''
|
||||||
|
else:
|
||||||
|
Good, Error = '', ''
|
||||||
|
|
||||||
Comments = ''
|
Comments = ''
|
||||||
for ID,User,Page,Reply,Date,Comment in GetComments(Data['Site'], Data['Page']):
|
for ID,User,Page,Reply,Date,Comment in GetComments(Data['Site'], Data['Page']):
|
||||||
@ -185,7 +229,7 @@ def Comments():
|
|||||||
Req = request
|
Req = request
|
||||||
Data = {}
|
Data = {}
|
||||||
if Req.method == 'GET':
|
if Req.method == 'GET':
|
||||||
for i in ['Lang','StyleFile','Site','Page']:
|
for i in ['Lang','StyleFile','Site','Page','ReadOnly']:
|
||||||
Data.update({i:Req.args.get(i)})
|
Data.update({i:Req.args.get(i)})
|
||||||
if Req.method == 'POST':
|
if Req.method == 'POST':
|
||||||
for i in ['Lang','StyleFile','Site','Page','User','CAPTCHA','Comment','SecKey','Action','Reply','Report','Delete']:
|
for i in ['Lang','StyleFile','Site','Page','User','CAPTCHA','Comment','SecKey','Action','Reply','Report','Delete']:
|
||||||
|
BIN
Source/__pycache__/Server.cpython-310.pyc
Normal file
BIN
Source/__pycache__/Server.cpython-310.pyc
Normal file
Binary file not shown.
@ -2,6 +2,6 @@
|
|||||||
<head>
|
<head>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<iframe src="http://localhost:8080/Comments?Lang=it&Site=5dGQi5vT0hxWULCprKW7Og9g0xRNkHqxxEKI3cGdh-A&Page=/index.html" width="100%" height="80%"></iframe>
|
<iframe src="http://localhost:8081/Comments?Lang=it&Site=5dGQi5vT0hxWULCprKW7Og9g0xRNkHqxxEKI3cGdh-A&Page=/index.html" width="100%" height="80%"></iframe>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
flask
|
flask
|
||||||
waitress
|
waitress
|
||||||
|
captcha
|
||||||
|
Reference in New Issue
Block a user