modern #2
6 changed files with 127 additions and 13 deletions
|
|
@ -1,19 +1,86 @@
|
||||||
|
"""
|
||||||
|
Parameciofm is a series of wrappers for bottlepy, mako and others and construct a simple headless cms.
|
||||||
|
|
||||||
|
Copyright (C) 2024 Antonio de la Rosa Caballero
|
||||||
|
|
||||||
|
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 by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
from hashlib import sha512, sha256
|
from hashlib import sha512, sha256
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from os import urandom
|
from os import urandom
|
||||||
|
import string
|
||||||
|
import secrets
|
||||||
|
|
||||||
# Functions for create random strings usando urandom
|
# Functions for create random strings usando urandom
|
||||||
|
|
||||||
def create_key_encrypt(n=10):
|
def create_key_encrypt(n=10):
|
||||||
|
""" Simple function for create a random string
|
||||||
|
|
||||||
|
Simple function for create a random string based in sha512
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): size of string random bytes (view urandom function in Python3 Help)
|
||||||
|
"""
|
||||||
|
|
||||||
return sha512(urandom(n)).hexdigest()
|
return sha512(urandom(n)).hexdigest()
|
||||||
|
|
||||||
def create_key_encrypt_256(n=10):
|
def create_key_encrypt_256(n=10):
|
||||||
|
|
||||||
|
""" Simple function for create a random string
|
||||||
|
|
||||||
|
Simple function for create a random string based in sha256
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): size of string random bytes (view urandom function in Python3 Help)
|
||||||
|
"""
|
||||||
|
|
||||||
return sha256(urandom(n)).hexdigest()
|
return sha256(urandom(n)).hexdigest()
|
||||||
|
|
||||||
def create_key(n=10):
|
def create_key(n=10):
|
||||||
|
|
||||||
|
""" Simple function for create a random string
|
||||||
|
|
||||||
|
Simple function for create a random string based in urandom function and base64 encoding
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): size of string random bytes (view urandom function in Python3 Help)
|
||||||
|
"""
|
||||||
|
|
||||||
rand_bytes=urandom(n)
|
rand_bytes=urandom(n)
|
||||||
|
|
||||||
return b64encode(rand_bytes).decode('utf-8')[0:-2]
|
return b64encode(rand_bytes).decode('utf-8')[0:-2]
|
||||||
|
|
||||||
|
def create_simple_password(n=14):
|
||||||
|
|
||||||
|
""" Based in python3 documentation for create passwords using secrets module
|
||||||
|
|
||||||
|
https://docs.python.org/3/library/secrets.html
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): Number of random elements of the password
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
password=''
|
||||||
|
|
||||||
|
alphabet=string.ascii_letters+string.digits+string.punctuation
|
||||||
|
|
||||||
|
while True:
|
||||||
|
password=''.join(secrets.choice(alphabet) for i in range(n))
|
||||||
|
if (any(c.islower() for c in password) and any(c.isupper() for c in password) and sum(c.isdigit() for c in password) >= 3):
|
||||||
|
break
|
||||||
|
|
||||||
|
return password
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,52 @@ elif config.session_opts['session.type']=='redis':
|
||||||
def after_session():
|
def after_session():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
elif config.session_opts['session.type']=='cookie':
|
||||||
|
|
||||||
|
from itsdangerous.url_safe import URLSafeSerializer
|
||||||
|
|
||||||
|
def generate_session(session : dict ={} , max_age=None):
|
||||||
|
|
||||||
|
#se=UrlSafeSerializer(config.key_encrypt)
|
||||||
|
|
||||||
|
#cookie_value=se.dumps(session)
|
||||||
|
|
||||||
|
request.environ['session']=session
|
||||||
|
|
||||||
|
return session
|
||||||
|
|
||||||
|
def regenerate_session():
|
||||||
|
|
||||||
|
request.environ['session']={}
|
||||||
|
|
||||||
|
return ParamecioSession({})
|
||||||
|
|
||||||
|
def load_session(token):
|
||||||
|
|
||||||
|
se=URLSafeSerializer(config.key_encrypt)
|
||||||
|
|
||||||
|
s=se.loads(token)
|
||||||
|
|
||||||
|
return s
|
||||||
|
|
||||||
|
def save_session(token, session, create_file=False):
|
||||||
|
|
||||||
|
cookie=session
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
if not max_age:
|
||||||
|
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'], httponly=True)
|
||||||
|
else:
|
||||||
|
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'], max_age=max_age, httponly=True)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except:
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def generate_session(session={}, max_age=None):
|
def generate_session(session={}, max_age=None):
|
||||||
|
|
@ -183,9 +229,9 @@ else:
|
||||||
# Bug in python 3.6, if you put max_age how None, is passed to header cookie.
|
# Bug in python 3.6, if you put max_age how None, is passed to header cookie.
|
||||||
|
|
||||||
if not max_age:
|
if not max_age:
|
||||||
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'])
|
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'], httponly=True)
|
||||||
else:
|
else:
|
||||||
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'], max_age=max_age)
|
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'], max_age=max_age, httponly=True)
|
||||||
#Set-Cookie: phango_session=n2ro4lghim75p8vjseb5v3lhap; path=/experiment2/
|
#Set-Cookie: phango_session=n2ro4lghim75p8vjseb5v3lhap; path=/experiment2/
|
||||||
#response.set_header('Set-Cookie', '%s=%s; path=%s' % (config.cookie_name, token, config.session_opts['session.path']) )
|
#response.set_header('Set-Cookie', '%s=%s; path=%s' % (config.cookie_name, token, config.session_opts['session.path']) )
|
||||||
|
|
||||||
|
|
@ -205,7 +251,7 @@ else:
|
||||||
|
|
||||||
s={'token': token}
|
s={'token': token}
|
||||||
|
|
||||||
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'])
|
response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path'], httponly=True)
|
||||||
|
|
||||||
file_session=config.session_opts['session.data_dir']+'/'+token+'_session'
|
file_session=config.session_opts['session.data_dir']+'/'+token+'_session'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ body
|
||||||
|
|
||||||
margin:0px;
|
margin:0px;
|
||||||
background-color:#f4f6f9;
|
background-color:#f4f6f9;
|
||||||
font-family: "Roboto", sans, sans-serif, serif;
|
font-family: sans, sans-serif;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
/*-webkit-transition: all 0.5s ease-in-out;
|
/*-webkit-transition: all 0.5s ease-in-out;
|
||||||
transition: all 0.5s ease-in-out;
|
transition: all 0.5s ease-in-out;
|
||||||
|
|
@ -56,7 +56,7 @@ a:hover {
|
||||||
height:52px;
|
height:52px;
|
||||||
color:#000;
|
color:#000;
|
||||||
font-size:22px;
|
font-size:22px;
|
||||||
font-family:"Roboto", sans, serif;
|
font-family:sans, sans-serif;
|
||||||
/*background-image:url('../images/background.png');
|
/*background-image:url('../images/background.png');
|
||||||
background-position:top;
|
background-position:top;
|
||||||
background-repeat:repeat-x;*/
|
background-repeat:repeat-x;*/
|
||||||
|
|
@ -78,7 +78,7 @@ a:hover {
|
||||||
font-size:28px;
|
font-size:28px;
|
||||||
padding-left:15px;
|
padding-left:15px;
|
||||||
color: #555555;
|
color: #555555;
|
||||||
font-family:"Roboto", sans, serif;
|
font-family: sans, serif;
|
||||||
/*font-style:italic;*/
|
/*font-style:italic;*/
|
||||||
/*text-shadow:#000000 1px 1px 1px;
|
/*text-shadow:#000000 1px 1px 1px;
|
||||||
filter: progid:DXImageTransform.Microsoft.Shadow(color='#000000', Direction=130, Strength=4);*/
|
filter: progid:DXImageTransform.Microsoft.Shadow(color='#000000', Direction=130, Strength=4);*/
|
||||||
|
|
@ -99,7 +99,7 @@ a:hover {
|
||||||
h1, h2
|
h1, h2
|
||||||
{
|
{
|
||||||
|
|
||||||
font-family:"Roboto", sans, serif;
|
font-family: sans, sans-serif;
|
||||||
border: solid #cbcbcb;
|
border: solid #cbcbcb;
|
||||||
border-width: 0px 0px 1px 1px;
|
border-width: 0px 0px 1px 1px;
|
||||||
font-size:26px;
|
font-size:26px;
|
||||||
|
|
@ -243,7 +243,7 @@ p {
|
||||||
|
|
||||||
padding:5px;
|
padding:5px;
|
||||||
font-size:18px;
|
font-size:18px;
|
||||||
font-family:"Roboto", sans, serif;
|
font-family: sans, sans-serif;
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
/*background-image:url('../images/background_title.png');
|
/*background-image:url('../images/background_title.png');
|
||||||
background-position:top;
|
background-position:top;
|
||||||
|
|
@ -260,7 +260,7 @@ p {
|
||||||
|
|
||||||
.father_admin {
|
.father_admin {
|
||||||
|
|
||||||
font-family:"Roboto", sans, serif;
|
font-family:sans, sans-serif;
|
||||||
padding:5px;
|
padding:5px;
|
||||||
font-size:18px;
|
font-size:18px;
|
||||||
display: block;
|
display: block;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Paramecio WebFramework</title>
|
<title>Paramecio WebFramework</title>
|
||||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
|
<!--<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>-->
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
h1, h2, h3 {
|
h1, h2, h3 {
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
margin-left:15px;
|
margin-left:15px;
|
||||||
margin-right:15px;
|
margin-right:15px;
|
||||||
font-size:14px;
|
font-size:14px;
|
||||||
font-family: 'Open Sans', sans-serif;
|
font-family: 'sans', sans-serif;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ install_requires=[
|
||||||
"bleach",
|
"bleach",
|
||||||
"argon2-cffi",
|
"argon2-cffi",
|
||||||
"oslo.concurrency",
|
"oslo.concurrency",
|
||||||
"gunicorn"
|
"gunicorn",
|
||||||
|
"itsdangerous"
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -21,7 +21,7 @@ setup(name='paramecio',
|
||||||
url='https://git.cuchulu.com/paramecio/parameciofm/',
|
url='https://git.cuchulu.com/paramecio/parameciofm/',
|
||||||
packages=['paramecio', 'paramecio.i18n', 'paramecio.settings'],
|
packages=['paramecio', 'paramecio.i18n', 'paramecio.settings'],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=['bottle', 'mako', 'pymysql', 'sqlalchemy', 'oslo.concurrency', 'itsdangerous', 'colorama','cherrypy', 'arrow', 'argon2-cffi', 'pillow'],
|
install_requires=['bottle', 'mako', 'pymysql', 'sqlalchemy', 'oslo.concurrency', 'itsdangerous', 'colorama','cherrypy', 'arrow', 'argon2-cffi', 'pillow', 'itsdangerous'],
|
||||||
entry_points={'console_scripts': [
|
entry_points={'console_scripts': [
|
||||||
'paramecio = paramecio.console:start',
|
'paramecio = paramecio.console:start',
|
||||||
'parameciodb = paramecio.cromosoma.dbamin.start'
|
'parameciodb = paramecio.cromosoma.dbamin.start'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue