Add CAPTCHA
This commit is contained in:
parent
4be55cdb23
commit
fd1fcc8cf8
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,7 +185,11 @@ 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])
|
||||||
|
|
||||||
|
if 'ReadOnly' in Data and Data['ReadOnly'] == 'True':
|
||||||
|
FormMain, Good, Error = '', '', ''
|
||||||
|
else:
|
||||||
FormMain = FormMain.format(
|
FormMain = FormMain.format(
|
||||||
|
CAPTCHAHTML=CAPTCHAHTML(ReqID) if Config['CAPTCHA'] else '',
|
||||||
SecKey=Data['SecKey'] if 'SecKey' in Data and Data['SecKey'] else '',
|
SecKey=Data['SecKey'] if 'SecKey' in Data and Data['SecKey'] else '',
|
||||||
User=Data['User'] if 'User' in Data and Data['User'] else '',
|
User=Data['User'] if 'User' in Data and Data['User'] else '',
|
||||||
Comment=Data['Comment'] if 'Comment' in Data and Data['Comment'] else '')
|
Comment=Data['Comment'] if 'Comment' in Data and Data['Comment'] else '')
|
||||||
|
@ -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']:
|
||||||
|
|
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
|
||||||
|
|
Loading…
Reference in New Issue