Encoded URLs, should fix #1
This commit is contained in:
parent
af9b1f0c5d
commit
7872bd31af
@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
import urllib.parse
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@ -122,7 +123,7 @@ USE_TZ = True
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# 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')
|
||||
|
||||
USE_X_FORWARDED_HOST = True
|
||||
|
@ -44,7 +44,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
<!-- /#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>
|
||||
$(function() {
|
||||
function handleResize() {
|
||||
|
@ -3,8 +3,8 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.homepage, name='homepage'),
|
||||
url(r'^iframe/(?P<url>.+)$', views.iframe, name='iframe'),
|
||||
url(r'^setup/(?P<url>.+)$', views.setup, name='setup'),
|
||||
url(r'^iframe/(?P<encodedurl>.+)$', views.iframe, name='iframe'),
|
||||
url(r'^setup/(?P<encodedurl>.+)$', views.setup, name='setup'),
|
||||
url(r'^newfeed$', views.newfeed, name='newfeed'),
|
||||
url(r'^feeds$', views.feeds, name='feeds'),
|
||||
url(r'^feeds/delete/(?P<id>[0-9]+)$', views.feed_delete, name='feed_delete'),
|
||||
|
17
web/views.py
17
web/views.py
@ -5,12 +5,15 @@ from .models import Feed
|
||||
from django.db.models import ObjectDoesNotExist
|
||||
from bs4 import BeautifulSoup
|
||||
import logging
|
||||
from urllib.parse import quote_plus, unquote_plus
|
||||
# Create your views here.
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def iframe(request, url):
|
||||
|
||||
def iframe(request, encodedurl):
|
||||
try:
|
||||
url = unquote_plus(encodedurl)
|
||||
req = get_url(url)
|
||||
html = req.content
|
||||
bs = False
|
||||
@ -60,22 +63,26 @@ def iframe(request, url):
|
||||
return HttpResponse("An error has occured", content_type=500)
|
||||
return HttpResponse(html, content_type=content_type)
|
||||
|
||||
|
||||
def dummy(request):
|
||||
return HttpResponse("toto")
|
||||
|
||||
|
||||
def homepage(request):
|
||||
if request.method == 'POST':
|
||||
if "url" in request.POST and request.POST["url"]:
|
||||
url = request.POST["url"]
|
||||
if is_valid_url(url):
|
||||
return redirect("setup", url=url)
|
||||
return redirect("setup", encodedurl=quote_plus(url))
|
||||
else:
|
||||
return render(request, 'homepage.html', {"url": url, "error": url+" is not a valid URL."})
|
||||
return render(request, 'homepage.html')
|
||||
|
||||
def setup(request, url):
|
||||
if is_valid_url(url):
|
||||
return render(request, 'setup.html', {"url": url})
|
||||
|
||||
def setup(request, encodedurl):
|
||||
decoded_url = unquote_plus(encodedurl)
|
||||
if is_valid_url(decoded_url):
|
||||
return render(request, 'setup.html', {"encodedurl": encodedurl, "url": decoded_url})
|
||||
else:
|
||||
return redirect("homepage")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user