Commit 0699cee1 authored by iv's avatar iv

Small improvements.

parent cf967d85
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
WebDAV server based on Flask. WebDAV server based on Flask.
## Generate a certificate at the project's root ## Generate a certificate at the project's root
openssl genrsa 2048 > ssl.key openssl req -nodes -newkey rsa -days 365 -keyout "ssl.key" -x509 -out "ssl.cert"
openssl req -new -x509 -nodes -sha1 -days 365 -key ssl.key > ssl.cert
## LICENSE ## LICENSE
flaskdav is under the GPL2 license. flaskdav is under the GPL2 license.
......
from flask import Flask, request, redirect, url_for, render_template, make_response, g from flask import Flask, request, redirect, url_for, render_template, make_response, g
from flask.views import MethodView from flask.views import MethodView
from string import atoi
import shutil import shutil
import utils import utils
import os import os
...@@ -70,11 +69,10 @@ class WebDAV(MethodView): ...@@ -70,11 +69,10 @@ class WebDAV(MethodView):
def get_body(self): def get_body(self):
""" get the request's body """ """ get the request's body """
request_data = request.data request_data = request.data
if not request_data and atoi(request.headers['Content-length']): if not request_data and int(request.headers['Content-length']):
try: try:
d = request.form.items()[0][0] request_data = request.form.items()[0][0]
request_data = d except IndexError:
except:
request_data = None request_data = None
return request_data return request_data
...@@ -104,7 +102,7 @@ class WebDAV(MethodView): ...@@ -104,7 +102,7 @@ class WebDAV(MethodView):
# TODO send large response by chunks would be nice for big # TODO send large response by chunks would be nice for big
# files... http://flask.pocoo.org/docs/0.10/patterns/streaming/ # files... http://flask.pocoo.org/docs/0.10/patterns/streaming/
data = data_resource.read() data = data_resource.read()
except: except Exception:
# 403? # 403?
response.status = '403' response.status = '403'
else: else:
...@@ -216,12 +214,12 @@ class WebDAV(MethodView): ...@@ -216,12 +214,12 @@ class WebDAV(MethodView):
if os.path.isfile(localpath): if os.path.isfile(localpath):
try: try:
shutil.copy2(localpath, destination_path) shutil.copy2(localpath, destination_path)
except: except Exception:
print('problem with copy2') print('problem with copy2')
else: else:
try: try:
shutil.copytree(localpath, destination_path) shutil.copytree(localpath, destination_path)
except: except Exception:
print('problem with copytree') print('problem with copytree')
return response return response
...@@ -246,12 +244,13 @@ app.add_url_rule(URI_BEGINNING_PATH['webdav'] + '<path:pathname>', view_func=Web ...@@ -246,12 +244,13 @@ app.add_url_rule(URI_BEGINNING_PATH['webdav'] + '<path:pathname>', view_func=Web
@app.route(URI_BEGINNING_PATH['authorization'], methods=['GET', 'POST']) @app.route(URI_BEGINNING_PATH['authorization'], methods=['GET', 'POST'])
def authorize(): def authorize():
origin = request.headers.get('Origin')
if request.method == 'POST': if request.method == 'POST':
response = make_response(render_template('authorization_page_cookie_set.html', headers=headers, origin=origin, back_url=back_url)) response = make_response(render_template('authorization_page_cookie_set.html', headers=headers, origin=origin, back_url=back_url))
response.set_cookie('mycookie', value='', max_age=None, expires=None, path='/', response.set_cookie('mycookie', value='', max_age=None, expires=None, path='/',
domain=None, secure=None, httponly=False) domain=None, secure=None, httponly=False)
else: else:
origin = request.headers.get('Origin')
headers = request.headers headers = request.headers
back_url = request.args.get('back_url') back_url = request.args.get('back_url')
response = make_response(render_template('authorization_page.html', headers=headers, origin=origin, back_url=back_url)) response = make_response(render_template('authorization_page.html', headers=headers, origin=origin, back_url=back_url))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment