Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flaskdav
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
flaskdav
Commits
0699cee1
Commit
0699cee1
authored
Nov 30, 2015
by
iv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small improvements.
parent
cf967d85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
11 deletions
+9
-11
README.md
README.md
+1
-2
flaskdav.py
flaskdav.py
+8
-9
No files found.
README.md
View file @
0699cee1
...
@@ -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.
...
...
flaskdav.py
View file @
0699cee1
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
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment