Encoded URLs, should fix #1

This commit is contained in:
Amazed 2018-12-19 13:18:15 +01:00
parent af9b1f0c5d
commit 7872bd31af
4 changed files with 17 additions and 9 deletions

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
""" """
import os import os
import urllib.parse
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -122,7 +123,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/ # https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/'+urllib.parse.urlparse(BASE_URL).path[1:]+'/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_ROOT = os.path.join(BASE_DIR, 'static')
USE_X_FORWARDED_HOST = True USE_X_FORWARDED_HOST = True

View File

@ -44,7 +44,7 @@
</ul> </ul>
</div> </div>
<!-- /#sidebar-wrapper --> <!-- /#sidebar-wrapper -->
<iframe id="preview" style="width:100%" src="{% url 'iframe' url=url %}"></iframe> <iframe id="preview" style="width:100%" src="{% url 'iframe' encodedurl=url %}"></iframe>
<script> <script>
$(function() { $(function() {
function handleResize() { function handleResize() {

View File

@ -3,8 +3,8 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.homepage, name='homepage'), url(r'^$', views.homepage, name='homepage'),
url(r'^iframe/(?P<url>.+)$', views.iframe, name='iframe'), url(r'^iframe/(?P<encodedurl>.+)$', views.iframe, name='iframe'),
url(r'^setup/(?P<url>.+)$', views.setup, name='setup'), url(r'^setup/(?P<encodedurl>.+)$', views.setup, name='setup'),
url(r'^newfeed$', views.newfeed, name='newfeed'), url(r'^newfeed$', views.newfeed, name='newfeed'),
url(r'^feeds$', views.feeds, name='feeds'), url(r'^feeds$', views.feeds, name='feeds'),
url(r'^feeds/delete/(?P<id>[0-9]+)$', views.feed_delete, name='feed_delete'), url(r'^feeds/delete/(?P<id>[0-9]+)$', views.feed_delete, name='feed_delete'),

View File

@ -5,12 +5,15 @@ from .models import Feed
from django.db.models import ObjectDoesNotExist from django.db.models import ObjectDoesNotExist
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import logging import logging
from urllib.parse import quote_plus, unquote_plus
# Create your views here. # Create your views here.
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def iframe(request, url):
def iframe(request, encodedurl):
try: try:
url = unquote_plus(encodedurl)
req = get_url(url) req = get_url(url)
html = req.content html = req.content
bs = False bs = False
@ -60,22 +63,26 @@ def iframe(request, url):
return HttpResponse("An error has occured", content_type=500) return HttpResponse("An error has occured", content_type=500)
return HttpResponse(html, content_type=content_type) return HttpResponse(html, content_type=content_type)
def dummy(request): def dummy(request):
return HttpResponse("toto") return HttpResponse("toto")
def homepage(request): def homepage(request):
if request.method == 'POST': if request.method == 'POST':
if "url" in request.POST and request.POST["url"]: if "url" in request.POST and request.POST["url"]:
url = request.POST["url"] url = request.POST["url"]
if is_valid_url(url): if is_valid_url(url):
return redirect("setup", url=url) return redirect("setup", encodedurl=quote_plus(url))
else: else:
return render(request, 'homepage.html', {"url": url, "error": url+" is not a valid URL."}) return render(request, 'homepage.html', {"url": url, "error": url+" is not a valid URL."})
return render(request, 'homepage.html') return render(request, 'homepage.html')
def setup(request, url):
if is_valid_url(url): def setup(request, encodedurl):
return render(request, 'setup.html', {"url": url}) decoded_url = unquote_plus(encodedurl)
if is_valid_url(decoded_url):
return render(request, 'setup.html', {"encodedurl": encodedurl, "url": decoded_url})
else: else:
return redirect("homepage") return redirect("homepage")