Some basic URL validation

master
Marek Baczynski 6 years ago
parent 444b9ecf9d
commit 5d6db5aea5

@ -4,8 +4,8 @@ from PIL import Image, ImageFont, ImageDraw
import qrcode import qrcode
from io import BytesIO from io import BytesIO
import json, random, re, string import json, random, re, string
app = Flask(__name__)
app = Flask(__name__)
systemURL = 'http://192.168.0.11:5000/' systemURL = 'http://192.168.0.11:5000/'
randomchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789' #note the lack of zero randomchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789' #note the lack of zero
@ -70,6 +70,10 @@ def edit():
if url is None: if url is None:
return render_template('editlink.html', code=code) return render_template('editlink.html', code=code)
#Saving the link: #Saving the link:
if url.lower().startswith('https://') is False and url.lower().startswith('http://') is False:
return render_template('message.html', message="Only http:// and https:// links alowed. Plz fix your link!")
if len(url)>1000:
return render_template('message.html', message="This link is too long! It probably contains tracking data or other crap. Please find a shorter link.")
links[code]['url']=url links[code]['url']=url
saveFile() saveFile()
return render_template('success.html') return render_template('success.html')

@ -6,7 +6,7 @@
QR-code:<br /> QR-code:<br />
<input type="text" value="{{code}}" disabled /><br /> <input type="text" value="{{code}}" disabled /><br />
URL:<br /> URL:<br />
<input type="text" name="url" value=""/><br /> <input type="url" name="url" value=""/><br />
<button type="submit" class="graybar" >Save </button> <button type="submit" class="graybar" >Save </button>
</form> </form>
{% endblock %} {% endblock %}
Loading…
Cancel
Save