Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Nuovo sito
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Nuovo sito
Commits
9afb805a
Commit
9afb805a
authored
Dec 13, 2016
by
Pietro Albini
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'secret-key' into develop
parents
2b8bb919
aa648f0e
Pipeline
#47
passed with stage
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
+38
-5
uitwww/__init__.py
uitwww/__init__.py
+22
-2
uitwww/__main__.py
uitwww/__main__.py
+0
-2
uitwww/utils.py
uitwww/utils.py
+16
-1
No files found.
uitwww/__init__.py
View file @
9afb805a
...
...
@@ -20,12 +20,25 @@ import flask
from
.
import
pages
from
.
import
cache
from
.
import
utils
def
create_app
(
data_path
):
"""Create a new instance of the application"""
app
=
flask
.
Flask
(
__name__
,
static_url_path
=
"/+assets"
)
app
.
config
[
"DATA_PATH"
]
=
data_path
# Normalize the data path
data_path
=
os
.
path
.
expanduser
(
os
.
path
.
abspath
(
data_path
))
app
=
flask
.
Flask
(
__name__
,
static_url_path
=
"/+assets"
,
instance_path
=
data_path
,
)
# Prepare the data directory
init_data_directory
(
data_path
)
# Load the secret key
with
open
(
os
.
path
.
join
(
data_path
,
"secret_key"
))
as
f
:
app
.
secret_key
=
f
.
read
().
strip
()
app
.
config
[
"CACHE_PATH"
]
=
os
.
path
.
join
(
data_path
,
"cache"
)
cache
.
install_cache
(
app
)
...
...
@@ -58,3 +71,10 @@ def init_data_directory(data_path):
if
os
.
path
.
exists
(
dest
):
os
.
remove
(
dest
)
os
.
symlink
(
os
.
path
.
join
(
src_directory
,
src
),
dest
)
# Generate the secret key if not present
secret_key_path
=
os
.
path
.
join
(
data_path
,
"secret_key"
)
if
not
os
.
path
.
exists
(
secret_key_path
):
with
open
(
secret_key_path
,
"w"
)
as
f
:
f
.
write
(
"%s
\
n
"
%
utils
.
random_key
(
64
))
os
.
chmod
(
secret_key_path
,
0o400
)
uitwww/__main__.py
View file @
9afb805a
...
...
@@ -40,8 +40,6 @@ def run(data, gunicorn_config, port, public, workers, debug):
# Create the application instance
src_directory
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
uitwww
.
init_data_directory
(
data
)
app
=
uitwww
.
create_app
(
data
)
app
.
wsgi_app
=
utils
.
ReverseProxied
(
app
.
wsgi_app
)
...
...
uitwww/utils.py
View file @
9afb805a
# Source code of the Ubuntu-it website
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
# Copyright (C) 2015
-2016
Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
...
...
@@ -14,9 +14,24 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
random
import
string
import
gunicorn.app.base
as
baseapp
def
random_key
(
length
):
"""Generate a random key of a given length"""
rng
=
random
.
SystemRandom
()
# Use /dev/urandom
space
=
string
.
digits
+
string
.
ascii_letters
+
string
.
punctuation
result
=
""
for
_
in
range
(
length
):
result
+=
rng
.
choice
(
space
)
return
result
class
GunicornInstance
(
baseapp
.
BaseApplication
):
"""A gunicorn instance which runs the app we want"""
...
...
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