Compare commits
41 Commits
master
...
system/aut
Author | SHA1 | Date | |
---|---|---|---|
37facfda80 | |||
fc4839c682 | |||
aebfc08edf | |||
144d2bddf2 | |||
a4887a2286 | |||
345ad468a3 | |||
7070f85f1f | |||
4c1107979f | |||
ef0e47d7f5 | |||
7f77ad39bf | |||
2be2f425c6 | |||
182c888553 | |||
c85c2ac8ff | |||
cb257cb443 | |||
981192ad69 | |||
6fd96fd7ce | |||
4dac4d439c | |||
a329f6b71b | |||
43b46d9bad | |||
d5b59aa4e7 | |||
6fd242e4c6 | |||
b6d5ee5848 | |||
a3dac61276 | |||
14e2977931 | |||
7f4f367cf4 | |||
4d8381dcea | |||
6c4d9f0445 | |||
39192b165b | |||
4d741561a3 | |||
3b56ba845c | |||
c9993e2aba | |||
abb184e0e1 | |||
7b294192e9 | |||
37c39437c9 | |||
2f4b9fb1a3 | |||
32d2fa6059 | |||
b39f91ad6c | |||
310d662a05 | |||
42d9beffb1 | |||
1e74238456 | |||
7ba6d5de08 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,3 +12,5 @@ nohup.out
|
||||
|
||||
.gadogado
|
||||
|
||||
.ssh
|
||||
|
||||
|
18
bruno/authsquare/Auth/Login.bru
Normal file
18
bruno/authsquare/Auth/Login.bru
Normal file
@ -0,0 +1,18 @@
|
||||
meta {
|
||||
name: Login
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/auth/login
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username":"su",
|
||||
"password":"su"
|
||||
}
|
||||
}
|
15
bruno/authsquare/Auth/Logout.bru
Normal file
15
bruno/authsquare/Auth/Logout.bru
Normal file
@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: Logout
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/auth/logout
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer xx.xx.xx
|
||||
}
|
15
bruno/authsquare/Auth/Notme.bru
Normal file
15
bruno/authsquare/Auth/Notme.bru
Normal file
@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: Notme
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:11000/api/auth/notme?token=xx.xx.xx
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:query {
|
||||
token: xx.xx.xx
|
||||
}
|
24
bruno/authsquare/Auth/Register.bru
Normal file
24
bruno/authsquare/Auth/Register.bru
Normal file
@ -0,0 +1,24 @@
|
||||
meta {
|
||||
name: Register
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/auth/register/:roles
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:path {
|
||||
roles: su
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"captcha":"test",
|
||||
"username":"su",
|
||||
"email":"user@domain.com",
|
||||
"password":"su"
|
||||
}
|
||||
}
|
15
bruno/authsquare/Auth/Resend.bru
Normal file
15
bruno/authsquare/Auth/Resend.bru
Normal file
@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: Resend
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:11000/api/auth/resend?email=user@domain.com
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:query {
|
||||
email: user@domain.com
|
||||
}
|
30
bruno/authsquare/Auth/Session.bru
Normal file
30
bruno/authsquare/Auth/Session.bru
Normal file
@ -0,0 +1,30 @@
|
||||
meta {
|
||||
name: Session
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/auth/session/:type
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:path {
|
||||
type: check
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer xx.xx.xx
|
||||
}
|
||||
|
||||
docs {
|
||||
This API only used when you use CostaPy as your main client.
|
||||
|
||||
Session have a 3 type:
|
||||
- `set` for set the Bearer inside the Authorization. Need to declare a `jwt` on JSON Body.
|
||||
- `check` for check the Bearer is still valid or not.
|
||||
- `out` for remove the Bearer inside of Authorization.
|
||||
|
||||
The `set`, `out`, and some part of `check` is still not tested yet. Need the interface to test it.
|
||||
}
|
15
bruno/authsquare/Auth/Verify.bru
Normal file
15
bruno/authsquare/Auth/Verify.bru
Normal file
@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: Verify
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:11000/api/auth/verify?token=xx.xx.xx
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:query {
|
||||
token: xx.xx.xx
|
||||
}
|
5
bruno/authsquare/bruno.json
Normal file
5
bruno/authsquare/bruno.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "authsquare",
|
||||
"type": "collection"
|
||||
}
|
@ -1,13 +1,19 @@
|
||||
from core import template
|
||||
|
||||
page = {
|
||||
'public' :'pages/public'
|
||||
'public' :'pages/public',
|
||||
'dashboard' :'pages/dashboard',
|
||||
'email' :'pages/email'
|
||||
}
|
||||
|
||||
static = [
|
||||
{
|
||||
"route" :"/css/<filepath:re:.*\.(css|sass|css.map)>",
|
||||
"root" :"./static/css"
|
||||
},
|
||||
{
|
||||
"route" :"/js/<filepath:re:.*\.(js)>",
|
||||
"root" :"./static/js"
|
||||
}
|
||||
]
|
||||
template.add(static, "templates")
|
||||
|
11
config/email.py
Normal file
11
config/email.py
Normal file
@ -0,0 +1,11 @@
|
||||
smtpconfig = {
|
||||
"login" : {
|
||||
"email" : "user@domain.com",
|
||||
"password" : "your_password"
|
||||
},
|
||||
"server" : {
|
||||
"host" : "smtp.domain.com",
|
||||
"port" : 587
|
||||
},
|
||||
"from" : "user@domain.com"
|
||||
}
|
@ -1,3 +1,48 @@
|
||||
title = "CostaPy"
|
||||
import datetime
|
||||
|
||||
title = "Authsquare"
|
||||
header = f"Welcome to {title}"
|
||||
copyright = "Copyright (C) 2024 Dita Aji Pratama"
|
||||
|
||||
production = False
|
||||
forbidden_registration = ['su', 'admin']
|
||||
|
||||
auth_key = 'your_key'
|
||||
|
||||
ssh = {
|
||||
"key":{
|
||||
"private" : "/root/.ssh/id_rsa",
|
||||
"public" : "/root/.ssh/id_rsa.pub"
|
||||
},
|
||||
"passphrase" : None # use b'value' if use passphrase
|
||||
}
|
||||
|
||||
reCAPTCHA = {
|
||||
"client" : "your_key",
|
||||
"server" : "your_key"
|
||||
}
|
||||
|
||||
verification_link_expiration = datetime.datetime.now() + datetime.timedelta(minutes=30)
|
||||
forgot_link_expiration = datetime.datetime.now() + datetime.timedelta(minutes=30)
|
||||
# Can be hours or minutes
|
||||
|
||||
baseurl = "https://domain.com"
|
||||
if production == False:
|
||||
baseurl = "http://localhost:11000"
|
||||
|
||||
def resend_url(email):
|
||||
url = f"{baseurl}/api/auth/registration/resend?email={email}"
|
||||
return url
|
||||
|
||||
def notme_url(token):
|
||||
url = f"{baseurl}/notme?token={token}"
|
||||
return url
|
||||
|
||||
def verification_url(token):
|
||||
url = f"{baseurl}/verify?token={token}"
|
||||
return url
|
||||
|
||||
def change_forgot_url(token):
|
||||
url = f"{baseurl}/reset?token={token}"
|
||||
return url
|
||||
|
||||
copyright = "Copyright (C) 2022 Dita Aji Pratama"
|
||||
|
@ -1,23 +1,89 @@
|
||||
menu = {
|
||||
menu = {
|
||||
"public": {
|
||||
"navbar": [
|
||||
{
|
||||
"name":"Home",
|
||||
"target":"_self",
|
||||
"href":"/",
|
||||
"roles":["guest"]
|
||||
"roles":[0,1,2,3]
|
||||
},
|
||||
{
|
||||
"name":"About",
|
||||
"name":"Dashboard",
|
||||
"target":"_self",
|
||||
"href":"/about",
|
||||
"roles":["guest"]
|
||||
"href":"/dashboard",
|
||||
"roles":[1,2]
|
||||
},
|
||||
{
|
||||
"name":"Docs",
|
||||
"target":"_blank",
|
||||
"href":"https://costapy.ditaajipratama.net",
|
||||
"roles":["guest"]
|
||||
"name":"Register",
|
||||
"target":"_self",
|
||||
"href":"/register/member",
|
||||
"roles":[0]
|
||||
},
|
||||
{
|
||||
"name":"Login",
|
||||
"target":"_self",
|
||||
"href":"/login",
|
||||
"roles":[0]
|
||||
},
|
||||
{
|
||||
"name":"Logout",
|
||||
"target":"_self",
|
||||
"href":"/logout",
|
||||
"roles":[1,2,3]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dashboard": {
|
||||
"navbar": [
|
||||
{
|
||||
"name":"Home",
|
||||
"target":"_self",
|
||||
"href":"/",
|
||||
"notification":0,
|
||||
"roles":[0,1,2,3]
|
||||
}
|
||||
],
|
||||
"profile": [
|
||||
{
|
||||
"name" :"Profile",
|
||||
"href" :"/dashboard/profile",
|
||||
"target":"_self",
|
||||
"roles":[1,2]
|
||||
},
|
||||
{
|
||||
"name" :"Settings",
|
||||
"href" :"/dashboard/settings",
|
||||
"target":"_self",
|
||||
"roles":[1,2]
|
||||
},
|
||||
{
|
||||
"name" :"Logout",
|
||||
"href" :"/logout",
|
||||
"target":"_self",
|
||||
"roles":[1,2,3]
|
||||
}
|
||||
],
|
||||
"sidebar": [
|
||||
{
|
||||
"icon":"fa-solid fa-gauge",
|
||||
"name":"Dashboard",
|
||||
"target":"_self",
|
||||
"href":"/dashboard",
|
||||
"roles":[1,2]
|
||||
},
|
||||
{
|
||||
"icon":"fa-solid fa-user-tag",
|
||||
"name":"Roles",
|
||||
"target":"_self",
|
||||
"href":"/dashboard/roles",
|
||||
"roles":[1]
|
||||
},
|
||||
{
|
||||
"icon":"fa-solid fa-address-card",
|
||||
"name":"Users",
|
||||
"target":"_self",
|
||||
"href":"/dashboard/users",
|
||||
"roles":[1,2]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
267
handler.py
267
handler.py
@ -5,11 +5,25 @@
|
||||
# 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 General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
|
||||
from bottle import Bottle, route
|
||||
from bottle import Bottle, route, request, response, redirect
|
||||
from config import directory
|
||||
|
||||
import json
|
||||
|
||||
import templates.plain.main as template_public
|
||||
import templates.postcard.main as template_email
|
||||
|
||||
import modules.public.home as public_home
|
||||
import modules.public.register as public_register
|
||||
import modules.public.notme as public_notme
|
||||
import modules.public.verify as public_verify
|
||||
import modules.public.login as public_login
|
||||
import modules.public.forgot as public_forgot
|
||||
import modules.public.reset as public_reset
|
||||
|
||||
import modules.api.auth as api_auth
|
||||
import modules.api.roles as api_auth_roles
|
||||
import modules.api.users as api_auth_users
|
||||
|
||||
app = Bottle()
|
||||
|
||||
@ -21,3 +35,254 @@ def index():
|
||||
}
|
||||
}
|
||||
return public_home.main().html(params)
|
||||
|
||||
@app.route('/register/<roles>')
|
||||
def index(roles):
|
||||
params = {
|
||||
"roles" :roles,
|
||||
"mako" :{
|
||||
"website" : template_public.main(directory.page["public"], "register")
|
||||
}
|
||||
}
|
||||
return public_register.register().html(params)
|
||||
|
||||
@app.route('/notme', method='GET')
|
||||
def index():
|
||||
params = {
|
||||
"mako" : {
|
||||
"website" : template_public.main(directory.page["public"], "notme")
|
||||
}
|
||||
}
|
||||
return public_notme.notme().html(params)
|
||||
|
||||
@app.route('/verify', method='GET')
|
||||
def index():
|
||||
params = {
|
||||
"mako" : {
|
||||
"website" : template_public.main(directory.page["public"], "verify")
|
||||
}
|
||||
}
|
||||
return public_verify.verify().html(params)
|
||||
|
||||
@app.route('/forgot')
|
||||
def index():
|
||||
params = {
|
||||
"mako" : {
|
||||
"website" : template_public.main(directory.page["public"], "forgot")
|
||||
}
|
||||
}
|
||||
return public_forgot.forgot().html(params)
|
||||
|
||||
@app.route('/reset', method='GET')
|
||||
def index():
|
||||
params = {
|
||||
"mako" : {
|
||||
"website" : template_public.main(directory.page["public"], "reset")
|
||||
}
|
||||
}
|
||||
return public_reset.reset().html(params)
|
||||
|
||||
@app.route('/login')
|
||||
def index():
|
||||
params = {
|
||||
"mako" : {
|
||||
"website" : template_public.main(directory.page["public"], "login")
|
||||
}
|
||||
}
|
||||
return public_login.login().html(params)
|
||||
|
||||
@app.route('/logout')
|
||||
def index():
|
||||
beaker_session = request.environ.get('beaker.session')
|
||||
if "token" in beaker_session:
|
||||
params = {
|
||||
"jwt" : beaker_session["token"],
|
||||
"type" : "out"
|
||||
}
|
||||
response_session = api_auth.auth().session(params)
|
||||
response_logout = api_auth.auth().logout(params)
|
||||
if response_session['status'] == 'success' and response_logout['status'] == 'success' :
|
||||
redirect('/?message=logout success')
|
||||
else:
|
||||
print('logout failed')
|
||||
print(f"response session: {response_session['status']}")
|
||||
print(f"response logout: {response_logout['status']}")
|
||||
redirect('/?message=logout failed')
|
||||
else:
|
||||
redirect('/')
|
||||
|
||||
@app.route('/api/auth/register/<roles>', method=['OPTIONS', 'POST'])
|
||||
def index(roles):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
params["roles" ] = roles
|
||||
params["mako" ] = {
|
||||
"email" : template_email.main(directory.page["email"], "verification")
|
||||
}
|
||||
return json.dumps(api_auth.auth().register(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/resend', method='GET')
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = {
|
||||
"email" : request.query.email,
|
||||
"mako" : {
|
||||
"email" : template_email.main(directory.page["email"], "verification")
|
||||
}
|
||||
}
|
||||
return json.dumps(api_auth.auth().resend(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/notme', method=['OPTIONS', 'POST'])
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
params["mako" ] = {
|
||||
"email" : template_email.main(directory.page["email"], "message")
|
||||
}
|
||||
return json.dumps(api_auth.auth().notme(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/verify', method=['OPTIONS', 'POST'])
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
params["mako" ] = {
|
||||
"email" : template_email.main(directory.page["email"], "message")
|
||||
}
|
||||
return json.dumps(api_auth.auth().verify(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/forgot', method=['OPTIONS', 'POST'])
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
params["mako" ] = {
|
||||
"email" : template_email.main(directory.page["email"], "reset")
|
||||
}
|
||||
return json.dumps(api_auth.auth().forgot(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/reset', method=['OPTIONS', 'POST'])
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
params["mako" ] = {
|
||||
"email" : template_email.main(directory.page["email"], "message")
|
||||
}
|
||||
return json.dumps(api_auth.auth().reset(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/login', method=['OPTIONS', 'POST'])
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
return json.dumps(api_auth.auth().login(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/session/<type>', method=['OPTIONS', 'POST'])
|
||||
def index(type):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
params["type" ] = type
|
||||
return json.dumps(api_auth.auth().session(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/logout', method=['OPTIONS', 'POST'])
|
||||
def index():
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
params = request.json
|
||||
return json.dumps(api_auth.auth().logout(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/roles/<alder>', method=['OPTIONS', 'POST'])
|
||||
def index(alder):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
if alder == 'add':
|
||||
return json.dumps(api_auth_roles.roles().add(params), indent = 2).encode()
|
||||
elif alder == 'list':
|
||||
return json.dumps(api_auth_roles.roles().list(params), indent = 2).encode()
|
||||
elif alder == 'edit':
|
||||
return json.dumps(api_auth_roles.roles().edit(params), indent = 2).encode()
|
||||
elif alder == 'remove':
|
||||
return json.dumps(api_auth_roles.roles().remove(params), indent = 2).encode()
|
||||
else:
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/users/<alder>', method=['OPTIONS', 'POST'])
|
||||
def index(alder):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
if alder == 'list':
|
||||
return json.dumps(api_auth_users.users().list(params), indent = 2).encode()
|
||||
else:
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
19
install.sh
19
install.sh
@ -1,12 +1,13 @@
|
||||
python3 -m venv .venv # Create .venv
|
||||
python3 -m venv .venv # Create .venv
|
||||
|
||||
.venv/bin/pip3 install --upgrade pip # Upgrade pip
|
||||
.venv/bin/pip3 install --upgrade pip # Upgrade pip
|
||||
|
||||
.venv/bin/pip3 install bottle # Micro Framework
|
||||
.venv/bin/pip3 install gunicorn # WSGI Server Backend
|
||||
.venv/bin/pip3 install beaker # Session & caching library
|
||||
.venv/bin/pip3 install mako # Template library
|
||||
.venv/bin/pip3 install bottle # Micro Framework
|
||||
.venv/bin/pip3 install gunicorn # WSGI Server Backend
|
||||
.venv/bin/pip3 install beaker # Session & caching library
|
||||
.venv/bin/pip3 install mako # Template library
|
||||
|
||||
.venv/bin/pip3 install mysql-connector # Database connector
|
||||
.venv/bin/pip3 install bcrypt # Password hash
|
||||
.venv/bin/pip3 install pyjwt[crypto] # JWT
|
||||
.venv/bin/pip3 install mysql-connector # Database connector
|
||||
.venv/bin/pip3 install bcrypt # Password hash
|
||||
.venv/bin/pip3 install pyjwt[crypto] # JWT
|
||||
.venv/bin/pip3 install requests # For HTTP Request (Recaptcha need a POST HTTP requests)
|
||||
|
459
modules/api/auth.py
Normal file
459
modules/api/auth.py
Normal file
@ -0,0 +1,459 @@
|
||||
import mysql.connector as mariadb
|
||||
from mako.template import Template
|
||||
from bottle import request, response as bottle_response
|
||||
|
||||
from config import database, email, globalvar
|
||||
|
||||
import bcrypt
|
||||
import datetime
|
||||
|
||||
from scripts import loggorilla, saltedkey, googly, tokenguard, sendwave
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
import procedure.webmail as procedure_webmail
|
||||
|
||||
class auth:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
self.smtpconfig = email.smtpconfig
|
||||
|
||||
def register(self, params):
|
||||
APIADDR = "/api/auth/register/:roles"
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
response = {}
|
||||
captcha = params["captcha" ]
|
||||
username = params["username" ].lower()
|
||||
email = params["email" ].lower()
|
||||
password = params["password" ]
|
||||
roles = params["roles" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
self.cursor.execute(f"SELECT id, name FROM `auth_roles` WHERE auth_roles.name = %s ; ", (roles,) )
|
||||
result_roles = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Process parameters")
|
||||
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
||||
token = saltedkey.token(username, hashed)
|
||||
if globalvar.production == True:
|
||||
captcha_r = googly.recaptcha(captcha, globalvar.reCAPTCHA['server'])
|
||||
score = captcha_r["score"]
|
||||
else:
|
||||
captcha_r = 'dev mode'
|
||||
score = 0.9
|
||||
loggorilla.fyinf(APIADDR, f'captcha_r : {captcha_r}')
|
||||
loggorilla.fyinf(APIADDR, f'score : {score}')
|
||||
|
||||
loggorilla.prcss(APIADDR, "Validation")
|
||||
result_validation = procedure_validation.validation().register(APIADDR, captcha, score, roles, username, password, email)
|
||||
if result_validation['status'] == "valid":
|
||||
loggorilla.prcss(APIADDR, "Inserting")
|
||||
self.cursor.execute("INSERT INTO `auth` VALUES (%s, %s);", (token, hashed) )
|
||||
self.cursor.execute("INSERT INTO `auth_profile` VALUES (DEFAULT, %s, %s, %s, NULL);", (token, username, email) )
|
||||
auth_profile_lastrowid = self.cursor.lastrowid
|
||||
self.cursor.execute("INSERT INTO `auth_profile_verification` VALUES (DEFAULT, %s, 'email', 0);", (auth_profile_lastrowid,) )
|
||||
self.cursor.execute("INSERT INTO `auth_profile_roles` VALUES (DEFAULT, %s, %s);", (auth_profile_lastrowid, result_roles['id']) )
|
||||
loggorilla.prcss(APIADDR, "Generate URL")
|
||||
expired = globalvar.verification_link_expiration
|
||||
expired_isoformat = expired.isoformat()
|
||||
payload = {
|
||||
"token" : token,
|
||||
"expired": expired_isoformat
|
||||
}
|
||||
token_encrypt = tokenguard.encode(payload, globalvar.ssh['key']['private'], globalvar.ssh['passphrase'])
|
||||
verification_url = globalvar.verification_url(token_encrypt)
|
||||
notme_url = globalvar.notme_url(token_encrypt)
|
||||
loggorilla.prcss(APIADDR, "Sending email")
|
||||
webmail_data = {"verify": verification_url, "notme": notme_url}
|
||||
result_webmail = procedure_webmail.webmail().verification(APIADDR, params, webmail_data)
|
||||
self.smtpconfig['to' ] = email
|
||||
self.smtpconfig['subject' ] = result_webmail['subject']
|
||||
self.smtpconfig['text' ] = result_webmail['text' ]
|
||||
self.smtpconfig['html' ] = result_webmail['html' ]
|
||||
sendwave.smtp(self.smtpconfig)
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Register success. Check email for verification."
|
||||
response["data" ] = {
|
||||
"recaptcha":captcha_r
|
||||
}
|
||||
else:
|
||||
response = result_validation
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def resend(self, params):
|
||||
APIADDR = "/api/auth/resend"
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
response = {}
|
||||
email = params["email"].lower()
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Get data for checking")
|
||||
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.token, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.email = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 0 ; ", (email,) )
|
||||
result_unverified = self.cursor.fetchone()
|
||||
token = result_unverified["token"].decode()
|
||||
if result_unverified["count"] >= 1:
|
||||
loggorilla.prcss(APIADDR, "Generate URL")
|
||||
expired = globalvar.verification_link_expiration
|
||||
expired_isoformat = expired.isoformat()
|
||||
payload = {
|
||||
"token" : token,
|
||||
"expired": expired_isoformat
|
||||
}
|
||||
token_encrypt = tokenguard.encode(payload, globalvar.ssh['key']['private'], globalvar.ssh['passphrase'])
|
||||
verification_url = globalvar.verification_url(token_encrypt)
|
||||
notme_url = globalvar.notme_url(token_encrypt)
|
||||
loggorilla.prcss(APIADDR, "Sending email")
|
||||
webmail_data = {"verify": verification_url, "notme": notme_url}
|
||||
result_webmail = procedure_webmail.webmail().verification(APIADDR, params, webmail_data)
|
||||
self.smtpconfig['to' ] = email
|
||||
self.smtpconfig['subject' ] = result_webmail['subject']
|
||||
self.smtpconfig['text' ] = result_webmail['text' ]
|
||||
self.smtpconfig['html' ] = result_webmail['html' ]
|
||||
sendwave.smtp(self.smtpconfig)
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Resend success. Check email for verification."
|
||||
else:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "The parameters seems suspicious and you are not authorized for that"
|
||||
except Exception as e:
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def notme(self, params):
|
||||
APIADDR = "/api/auth/notme"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token_encrypt = params["token"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Decrypt token")
|
||||
payload = tokenguard.decode(token_encrypt, globalvar.ssh['key']['public'])
|
||||
token = payload['token']
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile_verification.verified FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' ; ", (token,) )
|
||||
result_verification = self.cursor.fetchone()
|
||||
self.cursor.execute("SELECT COUNT(*) AS `count`, token, id, email FROM auth_profile WHERE token = %s ; ", (token,) )
|
||||
result_profile = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Validation")
|
||||
if result_verification['verified'] == 1:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Your account already verified"
|
||||
else:
|
||||
loggorilla.prcss(APIADDR, "Deleting")
|
||||
self.cursor.execute("DELETE FROM auth WHERE token = %s ; ", (token,) )
|
||||
loggorilla.prcss(APIADDR, "Sending email")
|
||||
webmail_data = {}
|
||||
result_webmail = procedure_webmail.webmail().notme(APIADDR, params, webmail_data)
|
||||
self.smtpconfig['to' ] = result_profile['email' ]
|
||||
self.smtpconfig['subject' ] = result_webmail['subject']
|
||||
self.smtpconfig['text' ] = result_webmail['text' ]
|
||||
self.smtpconfig['html' ] = result_webmail['html' ]
|
||||
sendwave.smtp(self.smtpconfig)
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Thanks for your report. Now your data will be deleted from our system."
|
||||
except Exception as e:
|
||||
loggorilla.prcss(APIADDR, "Rollback")
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def verify(self, params):
|
||||
APIADDR = "/api/auth/verify"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token_encrypt = params["token"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Decrypt token")
|
||||
payload = tokenguard.decode(token_encrypt, globalvar.ssh['key']['public'])
|
||||
token = payload['token']
|
||||
expired = datetime.datetime.fromisoformat(payload['expired'])
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile_verification.verified FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' ; ", (token,) )
|
||||
result_verification = self.cursor.fetchone()
|
||||
self.cursor.execute("SELECT COUNT(*) AS `count`, token, username, id, email FROM auth_profile WHERE token = %s ; ", (token,) )
|
||||
result_profile = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Validation")
|
||||
if result_verification['verified'] == 1:
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Your account already verified"
|
||||
elif datetime.datetime.now() > expired:
|
||||
loggorilla.prcss(APIADDR, "Deleting")
|
||||
self.cursor.execute("DELETE FROM `auth` WHERE `token` = %s ; ", (token,) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Expired. Your data removed."
|
||||
else:
|
||||
loggorilla.prcss(APIADDR, "Updating")
|
||||
self.cursor.execute("UPDATE `auth_profile_verification` SET `verified` = 1 WHERE `type` = 'email' AND `profile` = %s ; ", (result_profile['id'],) )
|
||||
loggorilla.prcss(APIADDR, "Sending email")
|
||||
webmail_data = {
|
||||
"username" : result_profile['username' ],
|
||||
"email" : result_profile['email' ]
|
||||
}
|
||||
result_webmail = procedure_webmail.webmail().welcome(APIADDR, params, webmail_data)
|
||||
self.smtpconfig['to' ] = result_profile['email' ]
|
||||
self.smtpconfig['subject' ] = result_webmail['subject']
|
||||
self.smtpconfig['text' ] = result_webmail['text' ]
|
||||
self.smtpconfig['html' ] = result_webmail['html' ]
|
||||
sendwave.smtp(self.smtpconfig)
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Congratulation. Your account is verified."
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def login(self, params):
|
||||
APIADDR = "/api/auth/login"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
username = params["username"].lower()
|
||||
password = params["password"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
self.cursor.execute("SELECT COUNT(*) AS `count`, auth.token, auth_profile.id, auth_profile.username, auth.password FROM auth_profile INNER JOIN auth ON auth.token = auth_profile.token WHERE auth_profile.username = %s ; ", (username,) )
|
||||
result_login = self.cursor.fetchone()
|
||||
self.cursor.execute("SELECT `profile`, `type`, `verified` FROM auth_profile_verification WHERE `type` = 'email' AND `profile` = %s ; ", (result_login['id'],) )
|
||||
result_verification = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Validation")
|
||||
if result_login['count'] == 1 and result_verification['verified'] == 1 and bcrypt.checkpw(password.encode(), result_login['password'].decode().encode() ) :
|
||||
loggorilla.prcss(APIADDR, "Add session")
|
||||
self.cursor.execute(f"INSERT INTO `auth_session` VALUES (DEFAULT, %s, NOW(), NOW() + INTERVAL 60 DAY)", ( result_login['token'], ) )
|
||||
session_last_id = self.cursor.lastrowid
|
||||
self.cursor.execute(f"SELECT `id`, `start`, `end` FROM `auth_session` WHERE id = %s ; ", ( session_last_id, ) )
|
||||
session = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Generate JWT token")
|
||||
payload = {
|
||||
"session" : {
|
||||
"id" : session['id' ],
|
||||
"start" : session['start' ].isoformat(),
|
||||
"end" : session['end' ].isoformat()
|
||||
}
|
||||
}
|
||||
jwt_token = tokenguard.encode(payload, globalvar.ssh['key']['private'], globalvar.ssh['passphrase'])
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Login success. Session added."
|
||||
response["data" ] = {
|
||||
"jwt" : jwt_token,
|
||||
"username" : username
|
||||
}
|
||||
else:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Username or password is incorrect"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
# Special API for Bottle web session
|
||||
def session(self, params):
|
||||
APIADDR = "/api/auth/session/:type"
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
response = {}
|
||||
try:
|
||||
type = params["type" ] # set / out
|
||||
loggorilla.prcss(APIADDR, "Extract the token from Header")
|
||||
auth_header = request.get_header('Authorization')
|
||||
if auth_header and auth_header.split(' ')[0] == 'Bearer':
|
||||
loggorilla.fyinf(APIADDR, "Use Bearer")
|
||||
jwt = auth_header.split(' ')[1]
|
||||
payload = tokenguard.decode(jwt, globalvar.ssh['key']['public'])
|
||||
session_id = payload["session"]["id"]
|
||||
else:
|
||||
loggorilla.fyinf(APIADDR, "Not use Bearer")
|
||||
jwt = None
|
||||
session_beaker = request.environ.get('beaker.session')
|
||||
if type == 'set':
|
||||
loggorilla.prcss(APIADDR, "Set session")
|
||||
session_beaker["token"] = jwt
|
||||
session_beaker.save()
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Session set"
|
||||
elif type == 'out':
|
||||
loggorilla.prcss(APIADDR, "Out session")
|
||||
session_beaker.delete()
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Session out"
|
||||
else:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "False parameters"
|
||||
except Exception as e:
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def forgot(self, params):
|
||||
APIADDR = "/api/auth/forgot"
|
||||
response = {}
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
email = params["email"].lower()
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.token, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.email = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ", (email,) )
|
||||
result_verified = self.cursor.fetchone()
|
||||
if result_verified["count"] >= 1:
|
||||
loggorilla.prcss(APIADDR, "Get token")
|
||||
token = result_verified["token"].decode()
|
||||
loggorilla.prcss(APIADDR, "Generate URL")
|
||||
expired = globalvar.forgot_link_expiration
|
||||
expired_isoformat = expired.isoformat()
|
||||
payload = {
|
||||
"token" : token,
|
||||
"expired": expired_isoformat
|
||||
}
|
||||
token_encrypt = tokenguard.encode(payload, globalvar.ssh['key']['private'], globalvar.ssh['passphrase'])
|
||||
change_forgot_url = globalvar.change_forgot_url(token_encrypt)
|
||||
loggorilla.prcss(APIADDR, "Sending email")
|
||||
webmail_data = {"reset" : change_forgot_url }
|
||||
result_webmail = procedure_webmail.webmail().reset(APIADDR, params, webmail_data)
|
||||
self.smtpconfig['to' ] = email
|
||||
self.smtpconfig['subject' ] = result_webmail['subject']
|
||||
self.smtpconfig['text' ] = result_webmail['text' ]
|
||||
self.smtpconfig['html' ] = result_webmail['html' ]
|
||||
sendwave.smtp(self.smtpconfig)
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "Check email for reset password."
|
||||
else:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "The parameters seems suspicious and you are not authorized for that"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def reset(self, params):
|
||||
APIADDR = "/api/auth/reset"
|
||||
response = {}
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token_encrypt = params["token" ]
|
||||
password = params["password" ]
|
||||
loggorilla.prcss(APIADDR, "Decrypt token")
|
||||
payload = tokenguard.decode(token_encrypt, globalvar.ssh['key']['public'])
|
||||
token = payload['token']
|
||||
expired = datetime.datetime.fromisoformat(payload['expired'])
|
||||
loggorilla.prcss(APIADDR, "Process parameters")
|
||||
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ", (token,) )
|
||||
result_verified = self.cursor.fetchone()
|
||||
email = result_verified['email']
|
||||
loggorilla.prcss(APIADDR, "Validation")
|
||||
if datetime.datetime.now() > expired:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Expired"
|
||||
elif len(password) < 6:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "password too short"
|
||||
elif result_verified["count"] == 0:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Forbidden: No active account for this"
|
||||
response["data" ] = {
|
||||
"message": "Please contact us if you still had a problem"
|
||||
}
|
||||
else:
|
||||
loggorilla.prcss(APIADDR, "Updating")
|
||||
self.cursor.execute("UPDATE `auth` SET `password` = %s WHERE `token` = %s", (hashed, token) )
|
||||
loggorilla.prcss(APIADDR, "Sending email")
|
||||
webmail_data = {}
|
||||
result_webmail = procedure_webmail.webmail().changed(APIADDR, params, webmail_data)
|
||||
self.smtpconfig['to' ] = email
|
||||
self.smtpconfig['subject' ] = result_webmail['subject']
|
||||
self.smtpconfig['text' ] = result_webmail['text' ]
|
||||
self.smtpconfig['html' ] = result_webmail['html' ]
|
||||
sendwave.smtp(self.smtpconfig)
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "password change success"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def logout(self, params):
|
||||
APIADDR = "/api/auth/logout"
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Extract the Authorization token from Header")
|
||||
auth_header = request.get_header('Authorization')
|
||||
jwt = auth_header.split(' ')[1]
|
||||
payload = tokenguard.decode(jwt, globalvar.ssh['key']['public'])
|
||||
session_id = payload["session"]["id"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Deleting")
|
||||
self.cursor.execute("DELETE FROM auth_session WHERE id = %s ; ", (session_id,) )
|
||||
loggorilla.fyinf(APIADDR, f"Session {session_id} removed.")
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = f"Session ({session_id}) removed."
|
||||
except Exception as e:
|
||||
loggorilla.prcss(APIADDR, "Rollback")
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error. for detail"
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
143
modules/api/roles.py
Normal file
143
modules/api/roles.py
Normal file
@ -0,0 +1,143 @@
|
||||
import mysql.connector as mariadb
|
||||
from mako.template import Template
|
||||
from bottle import request
|
||||
|
||||
from config import database, globalvar
|
||||
|
||||
from scripts import loggorilla, tokenguard
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class roles:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def add(self, params):
|
||||
APIADDR = "/api/auth/roles/add"
|
||||
response = {}
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token = params["token" ]
|
||||
id = params["id" ]
|
||||
name = params["name" ]
|
||||
allowed_roles = [1]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
||||
user = user_validation['data']
|
||||
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("INSERT INTO `auth_roles` VALUES (%s, %s) ;", (id, name) )
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data added"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def list(self, params):
|
||||
APIADDR = "/api/auth/roles/list"
|
||||
response = {}
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token = params["token" ]
|
||||
allowed_roles = [1,2] # Roles list is public or not?
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
||||
user = user_validation['data']
|
||||
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select auth_roles.id, auth_roles.name, (select count(*) from auth_profile_roles apr where apr.roles = auth_roles.id) AS `count` from auth_roles;")
|
||||
r_roles = self.cursor.fetchall()
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = r_roles
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def edit(self, params):
|
||||
APIADDR = "/api/auth/roles/edit"
|
||||
response = {}
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token = params["token" ]
|
||||
key = params["key" ]
|
||||
id = params["id" ]
|
||||
name = params["name" ]
|
||||
allowed_roles = [1]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
||||
user = user_validation['data']
|
||||
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
if key == 1 or id == 1:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Cannot change super user"
|
||||
else:
|
||||
self.cursor.execute("UPDATE `auth_roles` SET `id` = %s, `name` = %s WHERE `id` = %s ;", (id, name, key) )
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data change"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def remove(self, params):
|
||||
APIADDR = "/api/auth/roles/remove"
|
||||
response = {}
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token = params["token" ]
|
||||
key = params["key" ]
|
||||
allowed_roles = [1]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
||||
user = user_validation['data']
|
||||
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
if key == 1:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Cannot change super user"
|
||||
else:
|
||||
self.cursor.execute("DELETE FROM `auth_roles` WHERE `id` = %s ;", (key,) )
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data removed"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
61
modules/api/users.py
Normal file
61
modules/api/users.py
Normal file
@ -0,0 +1,61 @@
|
||||
import mysql.connector as mariadb
|
||||
from mako.template import Template
|
||||
from bottle import request
|
||||
|
||||
from config import database, globalvar
|
||||
|
||||
from scripts import loggorilla, tokenguard
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class users:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def list(self, params):
|
||||
APIADDR = "/api/auth/users/list"
|
||||
response = {}
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
token = params["token" ]
|
||||
allowed_roles = [1,2]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
||||
user = user_validation['data']
|
||||
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
r_profile = []
|
||||
self.cursor.execute("select auth_profile.id, auth_profile.username, auth_profile.email, auth_profile.phone from auth_profile;")
|
||||
l1 = self.cursor.fetchall()
|
||||
c1 = 0
|
||||
for d1 in l1:
|
||||
r_profile.append({
|
||||
"id" : d1["id" ],
|
||||
"username" : d1["username" ],
|
||||
"email" : d1["email" ],
|
||||
"phone" : d1["phone" ],
|
||||
"roles" : [],
|
||||
"verification" : []
|
||||
})
|
||||
self.cursor.execute("select auth_roles.id, auth_roles.name from auth_profile_roles inner join auth_roles on auth_profile_roles.roles = auth_roles.id where auth_profile_roles.profile = %s ; ", ( d1["id"], ) )
|
||||
r_profile[c1]["roles"] = self.cursor.fetchall()
|
||||
self.cursor.execute("select `type`, `verified` from auth_profile_verification where profile = %s ; ", ( d1["id"], ) )
|
||||
r_profile[c1]["verification"] = self.cursor.fetchall()
|
||||
c1 += 1
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = r_profile
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
35
modules/public/forgot.py
Normal file
35
modules/public/forgot.py
Normal file
@ -0,0 +1,35 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class forgot:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/forgot"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Forgot"
|
||||
allowed_roles = [0]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
),
|
||||
container = Template(params["mako"]["website"]['container']).render()
|
||||
)
|
@ -1,5 +1,8 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class main:
|
||||
|
||||
@ -7,13 +10,23 @@ class main:
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Home"
|
||||
allowed_roles = [0,1,2,3]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = "Welcome to CostaPy",
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = ["guest"],
|
||||
active_page = "Home"
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
|
35
modules/public/login.py
Normal file
35
modules/public/login.py
Normal file
@ -0,0 +1,35 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class login:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/login"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Login"
|
||||
allowed_roles = [0]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
),
|
||||
container = Template(params["mako"]["website"]['container']).render()
|
||||
)
|
37
modules/public/notme.py
Normal file
37
modules/public/notme.py
Normal file
@ -0,0 +1,37 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class notme:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/notme"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Not Me"
|
||||
allowed_roles = [0,1,2,3]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
),
|
||||
container = Template(params["mako"]["website"]['container']).render(
|
||||
title = globalvar.title
|
||||
)
|
||||
)
|
41
modules/public/register.py
Normal file
41
modules/public/register.py
Normal file
@ -0,0 +1,41 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class register:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/register"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Register"
|
||||
allowed_roles = [0]
|
||||
roles = params["roles"]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
),
|
||||
container = Template(params["mako"]["website"]['container']).render(
|
||||
title = globalvar.title,
|
||||
reCAPTCHA_client = globalvar.reCAPTCHA['client'],
|
||||
roles = roles,
|
||||
production = globalvar.production
|
||||
)
|
||||
)
|
35
modules/public/reset.py
Normal file
35
modules/public/reset.py
Normal file
@ -0,0 +1,35 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class reset:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/reset"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Reset"
|
||||
allowed_roles = [0]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
),
|
||||
container = Template(params["mako"]["website"]['container']).render()
|
||||
)
|
35
modules/public/verify.py
Normal file
35
modules/public/verify.py
Normal file
@ -0,0 +1,35 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar, navigation
|
||||
from scripts import loggorilla
|
||||
|
||||
import procedure.validation as procedure_validation
|
||||
|
||||
class verify:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def html(self, params):
|
||||
APIADDR = "/verify"
|
||||
|
||||
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||
active_page = "Verify"
|
||||
allowed_roles = [0]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Account validation")
|
||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
|
||||
user = user_validation['data']
|
||||
|
||||
return Template(params["mako"]["website"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.header,
|
||||
navbar = Template(params["mako"]["website"]['navbar']).render(
|
||||
menu = navigation.menu['public']['navbar'],
|
||||
user_roles = user['profile']['roles'],
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = globalvar.copyright,
|
||||
),
|
||||
container = Template(params["mako"]["website"]['container']).render()
|
||||
)
|
1
pages/email/message.html
Normal file
1
pages/email/message.html
Normal file
@ -0,0 +1 @@
|
||||
<p>${message}</p>
|
6
pages/email/reset.html
Normal file
6
pages/email/reset.html
Normal file
@ -0,0 +1,6 @@
|
||||
<h2>Forgot Password</h2>
|
||||
|
||||
<p>Please visit this link below to reset password. <b>Avoid the link if you are not request this.</b> </p>
|
||||
<a href="${reset}" class="button">
|
||||
Reset password
|
||||
</a>
|
11
pages/email/verification.html
Normal file
11
pages/email/verification.html
Normal file
@ -0,0 +1,11 @@
|
||||
<h2>${header}</h2>
|
||||
|
||||
<p>Thanks for signing up! This is the start of an exciting journey and you’re just one step away from completing your account setup to start using your profile.</p>
|
||||
<p>Click the button below to verify your account and get started.</p>
|
||||
<a href="${verify}" class="button">
|
||||
Verify email address
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
<p>You are not registering this? <a href="${notme}">I'm not registering this</a></p>
|
||||
<br>
|
15
pages/public/forgot.html
Normal file
15
pages/public/forgot.html
Normal file
@ -0,0 +1,15 @@
|
||||
<h1>Forgot Password</h1>
|
||||
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<!-- FORM -->
|
||||
<input required type="email" id="form-email" placeholder="Email"> <br>
|
||||
|
||||
<button onclick="onSubmit()">Submit</button>
|
||||
|
||||
<!-- RESPONSE -->
|
||||
<div id="alert-response" role="alert">
|
||||
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/js/auth/forgot.js"></script>
|
15
pages/public/login.html
Normal file
15
pages/public/login.html
Normal file
@ -0,0 +1,15 @@
|
||||
<h1>Login</h1>
|
||||
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<input required type="text" id="form-username" placeholder="Username" > <br>
|
||||
<input required type="password" id="form-password" placeholder="Password" > <br>
|
||||
<button type="button" onclick="onSubmit()">Login</button> <br>
|
||||
|
||||
<a href="/forgot">Forgot password</a>
|
||||
|
||||
<div id="alert-response" role="alert">
|
||||
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/js/auth/login.js"></script>
|
14
pages/public/notme.html
Normal file
14
pages/public/notme.html
Normal file
@ -0,0 +1,14 @@
|
||||
<h1>Not me</h1>
|
||||
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<p>I hereby declare that I have never registered with ${title} and will delete the data that uses my email</p>
|
||||
<button id="notme-link" onclick="notme()">
|
||||
Submit
|
||||
</button>
|
||||
|
||||
<div id="alert-response" role="alert">
|
||||
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/js/auth/notme.js"></script>
|
32
pages/public/register.html
Normal file
32
pages/public/register.html
Normal file
@ -0,0 +1,32 @@
|
||||
<h1>Register</h1>
|
||||
|
||||
% if production:
|
||||
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
|
||||
% endif
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<!-- FORM -->
|
||||
<input type="hidden" id="roles" value="${roles}">
|
||||
<input required type="email" id="form-email" placeholder="Email" > <br>
|
||||
<input required type="text" id="form-username" placeholder="Username" > <br>
|
||||
<input required type="password" id="form-password" placeholder="Password" > <br>
|
||||
|
||||
% if production:
|
||||
<button class="g-recaptcha" data-sitekey="${reCAPTCHA_client}" data-callback='onSubmit' data-action='submit'>Register</button>
|
||||
% else:
|
||||
<button onclick="onSubmit('dev')">Register</button>
|
||||
% endif
|
||||
|
||||
<!-- RESPONSE -->
|
||||
<div id="alert-response" role="alert">
|
||||
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
|
||||
</div>
|
||||
|
||||
<!-- RESEND FORM -->
|
||||
<div id="resend-div">
|
||||
<input type="hidden" id="resend-email" value="">
|
||||
<button id="resend-link" onclick="resending()">Resend verification</button>
|
||||
<p id="resend-message">Message here</p>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/js/auth/register.js"></script>
|
16
pages/public/reset.html
Normal file
16
pages/public/reset.html
Normal file
@ -0,0 +1,16 @@
|
||||
<h1>Reset Password</h1>
|
||||
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<!-- FORM -->
|
||||
<div id="form">
|
||||
<input required type="password" id="form-password" placeholder="New Password"> <br>
|
||||
<button onclick="onSubmit()">Submit</button>
|
||||
</div>
|
||||
|
||||
<!-- RESPONSE -->
|
||||
<div id="alert-response" role="alert">
|
||||
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/js/auth/reset.js"></script>
|
9
pages/public/verify.html
Normal file
9
pages/public/verify.html
Normal file
@ -0,0 +1,9 @@
|
||||
<h1>Verify</h1>
|
||||
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<div id="alert-response" role="alert">
|
||||
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/js/auth/verify.js"></script>
|
224
procedure/validation.py
Normal file
224
procedure/validation.py
Normal file
@ -0,0 +1,224 @@
|
||||
import mysql.connector as mariadb
|
||||
import datetime
|
||||
import re
|
||||
from bottle import request, abort, redirect
|
||||
from config import database, globalvar
|
||||
from scripts import loggorilla, tokenguard
|
||||
|
||||
class validation():
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def register(self, APIADDR, captcha, score, roles, username, password, email):
|
||||
response={}
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Get the data for checking")
|
||||
self.cursor.execute("SELECT COUNT(*) AS `count` FROM auth_profile WHERE email = %s ; ", (email,) )
|
||||
result_profile = self.cursor.fetchone()
|
||||
self.cursor.execute("SELECT COUNT(*) AS `count` FROM auth_profile WHERE username = %s ; ", (username,) )
|
||||
result_username = self.cursor.fetchone()
|
||||
self.cursor.execute(f"SELECT COUNT(*) AS `count` FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.email = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 0 ; ", (email,) )
|
||||
result_unverified = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Validating")
|
||||
if score < 0.2:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "you are sus as a bot"
|
||||
elif roles in globalvar.forbidden_registration:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = f"Forbidden to become {roles}"
|
||||
elif not re.match(r'^\w+$', username):
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "username can only use letters, numbers, and the underscore symbol"
|
||||
elif len(username) > 35:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "username can not longer than 35 character"
|
||||
elif len(username) < 3:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "username too short"
|
||||
elif len(password) < 6:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "password too short"
|
||||
elif result_unverified["count"] >= 1:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "check email for verification"
|
||||
response["data" ] = {
|
||||
"message": "Check email for verification. Please contact us if you still had a problem",
|
||||
"resend": globalvar.resend_url(email)
|
||||
}
|
||||
elif result_profile["count"] >= 1:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "email already taken"
|
||||
elif result_username["count"] >= 1:
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "username already taken"
|
||||
elif not (captcha and username and email and password):
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Form not complete."
|
||||
else:
|
||||
response["status" ] = "valid"
|
||||
response["desc" ] = "You can continue your register process"
|
||||
loggorilla.accss(APIADDR, f"Status : {response['status']}")
|
||||
loggorilla.accss(APIADDR, f"Description : {response['desc' ]}")
|
||||
except Exception as e:
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def account(self, APIADDR, allowed_roles, jwt=None):
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Get jwt")
|
||||
if jwt is None:
|
||||
loggorilla.fyinf(APIADDR, "jwt params is empty: Use beaker session")
|
||||
for_api = False
|
||||
beaker_session = request.environ.get('beaker.session')
|
||||
jwt = beaker_session["token"] if "token" in beaker_session else None
|
||||
else:
|
||||
loggorilla.fyinf(APIADDR, "jwt params is available: Use jwt from params")
|
||||
for_api = True
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
if jwt is None:
|
||||
loggorilla.fyinf(APIADDR, "Guest")
|
||||
r_session = {}
|
||||
r_profile = {
|
||||
"username" :None,
|
||||
"email" :None,
|
||||
"phone" :None,
|
||||
"roles" :[0]
|
||||
}
|
||||
session_not_found = False
|
||||
else:
|
||||
loggorilla.fyinf(APIADDR, "With JWT")
|
||||
|
||||
loggorilla.prcss(APIADDR, "Get JWT payload data")
|
||||
payload = tokenguard.decode(jwt, globalvar.ssh['key']['public'])
|
||||
|
||||
loggorilla.prcss(APIADDR, "Connect DB")
|
||||
db_main = mariadb.connect(**database.db_main)
|
||||
cursor = db_main.cursor(dictionary=True)
|
||||
|
||||
loggorilla.prcss(APIADDR, "Get dependency data")
|
||||
|
||||
cursor.execute(f"SELECT * FROM auth_session WHERE id = %s ; ", (payload["session"]["id"],) )
|
||||
r_session = cursor.fetchone()
|
||||
|
||||
if r_session is None:
|
||||
session_not_found = True
|
||||
r_session = {}
|
||||
r_profile = {
|
||||
"username" :None,
|
||||
"email" :None,
|
||||
"phone" :None,
|
||||
"roles" :[0]
|
||||
}
|
||||
else:
|
||||
session_not_found = False
|
||||
cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.* FROM auth_profile_verification LEFT JOIN auth_profile ON auth_profile.id = auth_profile_verification.profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ", (r_session['token'],) )
|
||||
r_profile = cursor.fetchone()
|
||||
cursor.execute(f"SELECT roles FROM auth_profile_roles WHERE profile = %s ; ", (r_profile['id'],) )
|
||||
r_roles = cursor.fetchall()
|
||||
r_profile['roles'] = [item['roles'] for item in r_roles]
|
||||
|
||||
loggorilla.prcss(APIADDR, "Close DB")
|
||||
cursor.close()
|
||||
db_main.close()
|
||||
|
||||
loggorilla.accss(APIADDR, f"Session ID : {r_session['id' ] if 'id' in r_session else None}" )
|
||||
loggorilla.accss(APIADDR, f"Session Start : {r_session['start' ].strftime('%Y-%m-%d %H:%M:%S') if 'start' in r_session else None}" )
|
||||
loggorilla.accss(APIADDR, f"Session End : {r_session['end' ].strftime('%Y-%m-%d %H:%M:%S') if 'end' in r_session else None}" )
|
||||
loggorilla.accss(APIADDR, f"Profile ID : {r_profile['id' ] if 'id' in r_profile else None}" )
|
||||
loggorilla.accss(APIADDR, f"Profile Username : {r_profile['username' ] if 'username' in r_profile else None}" )
|
||||
loggorilla.accss(APIADDR, f"Profile Email : {r_profile['email' ] if 'email' in r_profile else None}" )
|
||||
loggorilla.accss(APIADDR, f"Profile Phone : {r_profile['phone' ] if 'phone' in r_profile else None}" )
|
||||
loggorilla.accss(APIADDR, f"Profile Roles : {r_profile['roles' ] if 'roles' in r_profile else None}" )
|
||||
|
||||
loggorilla.prcss(APIADDR, "Validation")
|
||||
if session_not_found:
|
||||
loggorilla.accss(APIADDR, "Session not found" )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Your session not found."
|
||||
response["data" ] = {
|
||||
"token" : jwt,
|
||||
"valid" :{
|
||||
"status" : 0,
|
||||
"desc" : "removed"
|
||||
},
|
||||
"session" : r_session,
|
||||
"profile" : r_profile
|
||||
}
|
||||
if for_api is True:
|
||||
abort(401, "Session not found")
|
||||
else:
|
||||
redirect('/logout?msg=removed')
|
||||
elif 0 not in r_profile['roles'] and datetime.datetime.now() > r_session['end']:
|
||||
loggorilla.accss(APIADDR, "Session expired" )
|
||||
loggorilla.prcss(APIADDR, "Deleting session")
|
||||
self.cursor.execute("DELETE FROM auth_session WHERE id = %s ; ", (r_session['id'],) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Expired. Your session removed."
|
||||
response["data" ] = {
|
||||
"token" : jwt,
|
||||
"valid" :{
|
||||
"status" : 0,
|
||||
"desc" : "expired"
|
||||
},
|
||||
"session" : r_session,
|
||||
"profile" : r_profile
|
||||
}
|
||||
if for_api is True:
|
||||
abort(401, "Session expired")
|
||||
else:
|
||||
redirect('/logout?msg=expired')
|
||||
elif 0 not in r_profile['roles'] and r_profile["count"] == 0:
|
||||
loggorilla.accss(APIADDR, "No active account for this" )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "No active account for this"
|
||||
response["data" ] = {
|
||||
"token" : jwt,
|
||||
"message" : "Please contact us if you still had a problem",
|
||||
"valid" :{
|
||||
"status" : 0,
|
||||
"desc" : "fake"
|
||||
},
|
||||
"session" : r_session,
|
||||
"profile" : r_profile
|
||||
}
|
||||
abort(403, "Please contact us if you still had a problem.") # 403 Forbidden
|
||||
elif any(role in allowed_roles for role in r_profile['roles']):
|
||||
loggorilla.accss(APIADDR, "User roles authorized" )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "User roles authorized"
|
||||
response["data" ] = {
|
||||
"token" : str(jwt),
|
||||
"valid" :{
|
||||
"status" : 1,
|
||||
"desc" : "authorized"
|
||||
},
|
||||
"session" : r_session,
|
||||
"profile" : r_profile
|
||||
}
|
||||
return response
|
||||
else:
|
||||
loggorilla.accss(APIADDR, "User roles unauthorized" )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "User roles unauthorized"
|
||||
response["data" ] = {
|
||||
"token" : jwt,
|
||||
"valid" :{
|
||||
"status" : 0,
|
||||
"desc" : "unauthorized"
|
||||
},
|
||||
"session" : r_session,
|
||||
"profile" : r_profile
|
||||
}
|
||||
abort(401, "User roles unauthorized") # 401 Unauthorized
|
79
procedure/webmail.py
Normal file
79
procedure/webmail.py
Normal file
@ -0,0 +1,79 @@
|
||||
from mako.template import Template
|
||||
from config import globalvar
|
||||
|
||||
class webmail():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def verification(self, APIADDR, params, data):
|
||||
return {
|
||||
"subject" : f"{globalvar.title} email verification",
|
||||
"text" : f"Please visit this link to complete the registration: {data['verify']} . You are not registering this? report on this: {data['notme']} .",
|
||||
"html" : Template(params["mako"]["email"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.title,
|
||||
copyright = globalvar.copyright,
|
||||
container = Template(params["mako"]["email"]['container']).render(
|
||||
header = "One more step to complete your registration!",
|
||||
verify = data['verify' ],
|
||||
notme = data['notme' ]
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def notme(self, APIADDR, params, data):
|
||||
return {
|
||||
"subject" : f"{globalvar.title} - Thanks for the reporting",
|
||||
"text" : "Thanks for your report. Now your data will be deleted from our system.",
|
||||
"html" : Template(params["mako"]["email"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.title,
|
||||
copyright = globalvar.copyright,
|
||||
container = Template(params["mako"]["email"]['container']).render(
|
||||
message = "Thanks for your report. Now your data will be deleted from our system."
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def welcome(self, APIADDR, params, data):
|
||||
return {
|
||||
"subject" : f"Welcome to {globalvar.title}",
|
||||
"text" : f"Welcome {data['username']}, Now your account is verified.",
|
||||
"html" : Template(params["mako"]["email"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.title,
|
||||
copyright = globalvar.copyright,
|
||||
container = Template(params["mako"]["email"]['container']).render(
|
||||
message = f"Welcome {data['username']}, Now your account is verified."
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def reset(self, APIADDR, params, data):
|
||||
return {
|
||||
"subject" : f"{globalvar.title} - Reset password",
|
||||
"text" : f"Please visit this link to reset password: {data['reset']}. Avoid the link if you are not request this.",
|
||||
"html" : Template(params["mako"]["email"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.title,
|
||||
copyright = globalvar.copyright,
|
||||
container = Template(params["mako"]["email"]['container']).render(
|
||||
reset = data['reset']
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def changed(self, APIADDR, params, data):
|
||||
return {
|
||||
"subject" : f"{globalvar.title} - password change success",
|
||||
"text" : "You had change your password.",
|
||||
"html" : Template(params["mako"]["email"]['index']).render(
|
||||
title = globalvar.title,
|
||||
header = globalvar.title,
|
||||
copyright = globalvar.copyright,
|
||||
container = Template(params["mako"]["email"]['container']).render(
|
||||
message = "You had change your password."
|
||||
)
|
||||
)
|
||||
}
|
11
scripts/googly.py
Normal file
11
scripts/googly.py
Normal file
@ -0,0 +1,11 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
def recaptcha(captcha, secret):
|
||||
url = "https://www.google.com/recaptcha/api/siteverify"
|
||||
myobj = {
|
||||
"secret" : secret,
|
||||
"response" : captcha
|
||||
}
|
||||
response = json.loads(requests.post(url, data = myobj).text)
|
||||
return response
|
13
scripts/loggorilla.py
Normal file
13
scripts/loggorilla.py
Normal file
@ -0,0 +1,13 @@
|
||||
import datetime
|
||||
|
||||
def prcss(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[32mprcss\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
||||
|
||||
def accss(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[36maccss\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
||||
|
||||
def fyinf(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[93mfyinf\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
||||
|
||||
def error(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[31merror\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
5
scripts/saltedkey.py
Normal file
5
scripts/saltedkey.py
Normal file
@ -0,0 +1,5 @@
|
||||
import bcrypt
|
||||
import hashlib
|
||||
|
||||
def token(username, hashed):
|
||||
return hashlib.sha1( (username+username[:3]+hashed[-6:]).encode() ).hexdigest()
|
23
scripts/sendwave.py
Normal file
23
scripts/sendwave.py
Normal file
@ -0,0 +1,23 @@
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
import smtplib
|
||||
|
||||
def smtp(config):
|
||||
|
||||
msg = MIMEMultipart('alternative')
|
||||
msg['Subject' ] = config['subject' ]
|
||||
msg['From' ] = config['from' ]
|
||||
msg['To' ] = config['to' ]
|
||||
|
||||
part1 = MIMEText(config['text'], 'plain')
|
||||
part2 = MIMEText(config['html'], 'html' )
|
||||
|
||||
msg.attach(part1)
|
||||
msg.attach(part2)
|
||||
|
||||
smtp_server = smtplib.SMTP(config['server']['host'], config['server']['port'])
|
||||
smtp_server.ehlo()
|
||||
smtp_server.starttls()
|
||||
smtp_server.login( config['login']['email'], config['login']['password'] )
|
||||
smtp_server.sendmail('&&&&&&', config['to'], msg.as_string() )
|
||||
smtp_server.quit()
|
23
scripts/tokenguard.py
Normal file
23
scripts/tokenguard.py
Normal file
@ -0,0 +1,23 @@
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
import jwt
|
||||
|
||||
def encode(payload, id_rsa, passphrase):
|
||||
private_key = open(id_rsa, 'r').read()
|
||||
key = serialization.load_ssh_private_key(private_key.encode(), password=passphrase)
|
||||
token = jwt.encode(
|
||||
payload = payload,
|
||||
key = key,
|
||||
algorithm = 'RS256'
|
||||
)
|
||||
return token
|
||||
|
||||
def decode(token, id_rsa):
|
||||
public_key = open(id_rsa, 'r').read()
|
||||
key = serialization.load_ssh_public_key(public_key.encode())
|
||||
header = jwt.get_unverified_header(token)
|
||||
payload = jwt.decode(
|
||||
jwt = token,
|
||||
key = key,
|
||||
algorithms = [header['alg'], ]
|
||||
)
|
||||
return payload
|
77
sql/auth.sql
Normal file
77
sql/auth.sql
Normal file
@ -0,0 +1,77 @@
|
||||
-- README
|
||||
-- idx_ = index
|
||||
-- fk_ = foreign
|
||||
-- Create an index for fast lookups
|
||||
-- Defining constraints separately for better readability & maintainability
|
||||
-- NOTE
|
||||
-- Next verification variation should be based from identity and contact
|
||||
|
||||
CREATE TABLE `auth` (
|
||||
`token` binary(40) NOT NULL PRIMARY KEY,
|
||||
`password` binary(60) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `auth_roles` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` varchar(36) NOT NULL UNIQUE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `auth_session` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`token` binary(40) NOT NULL,
|
||||
`start` datetime NOT NULL,
|
||||
`end` datetime DEFAULT NULL,
|
||||
KEY `idx_token` (`token`),
|
||||
CONSTRAINT `auth_session_fk_token`
|
||||
FOREIGN KEY (`token`) REFERENCES `auth` (`token`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `auth_profile` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`token` binary(40) NOT NULL,
|
||||
`username` varchar(36) NOT NULL UNIQUE,
|
||||
`email` longtext DEFAULT NULL,
|
||||
`phone` bigint(20) DEFAULT NULL,
|
||||
KEY `idx_token` (`token`),
|
||||
CONSTRAINT `auth_profile_fk_token`
|
||||
FOREIGN KEY (`token`) REFERENCES `auth` (`token`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `auth_profile_verification` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`profile` int(11) NOT NULL,
|
||||
`type` longtext DEFAULT NULL, -- Can be email, ID card, phone, etc
|
||||
`verified` int(1) DEFAULT 0,
|
||||
KEY `idx_profile` (`profile`),
|
||||
CONSTRAINT `auth_profile_verification_fk_profile`
|
||||
FOREIGN KEY (`profile`) REFERENCES `auth_profile` (`id`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `auth_profile_roles` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`profile` int(11) NOT NULL,
|
||||
`roles` int(11) NOT NULL,
|
||||
KEY `idx_profile` (`profile`),
|
||||
KEY `idx_roles` (`roles`),
|
||||
CONSTRAINT `auth_profile_roles_fk_profile`
|
||||
FOREIGN KEY (`profile`) REFERENCES `auth_profile` (`id`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT `auth_profile_roles_fk_roles`
|
||||
FOREIGN KEY (`roles`) REFERENCES `auth_roles` (`id`)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT INTO `auth_roles` VALUES
|
||||
(1, 'su' ),
|
||||
(2, 'admin' ),
|
||||
(3, 'member' ),
|
||||
(4, 'tester' );
|
||||
|
42
static/js/auth/forgot.js
Normal file
42
static/js/auth/forgot.js
Normal file
@ -0,0 +1,42 @@
|
||||
function flushResponse() {
|
||||
document.getElementById("alert-response" ).style.display = 'none';
|
||||
document.getElementById("alert-response" ).classList.remove('alert-success' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-danger' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-primary' );
|
||||
}
|
||||
|
||||
function loadingResponse() {
|
||||
flushResponse();
|
||||
document.getElementById("alert-status" ).innerHTML = "Loading...";
|
||||
document.getElementById("alert-desc" ).innerHTML = "Please wait...";
|
||||
document.getElementById("alert-response").classList.add('alert-primary');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function responseAlert(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
if (obj.status == "success" ) document.getElementById("alert-response").classList.add('alert-success' );
|
||||
if (obj.status == "failed" ) document.getElementById("alert-response").classList.add('alert-danger' );
|
||||
document.getElementById("alert-status" ).innerHTML = obj.status;
|
||||
document.getElementById("alert-desc" ).innerHTML = obj.desc;
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
loadingResponse();
|
||||
var email = document.getElementById("form-email" ).value;
|
||||
var url = "/api/auth/forgot";
|
||||
var payload = {
|
||||
"email" : email
|
||||
};
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
flushResponse();
|
81
static/js/auth/login.js
Normal file
81
static/js/auth/login.js
Normal file
@ -0,0 +1,81 @@
|
||||
function flushResponse() {
|
||||
document.getElementById("alert-response" ).style.display = 'none';
|
||||
document.getElementById("alert-response" ).classList.remove('alert-success' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-danger' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-primary' );
|
||||
}
|
||||
|
||||
function loadingResponse() {
|
||||
flushResponse();
|
||||
document.getElementById("alert-status" ).innerHTML = "Loading...";
|
||||
document.getElementById("alert-desc" ).innerHTML = "Please wait...";
|
||||
document.getElementById("alert-response").classList.add('alert-primary');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function responseSession(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
document.getElementById("alert-status").innerHTML = obj.status;
|
||||
if (obj.status == "success") {
|
||||
document.getElementById("alert-desc" ).innerHTML = "Welcome!";
|
||||
document.getElementById("alert-response").classList.add('alert-success');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
window.location.replace("/?msg=Welcome");
|
||||
}
|
||||
else {
|
||||
document.getElementById("alert-desc" ).innerHTML = "Internal error";
|
||||
document.getElementById("alert-response").classList.add('alert-danger');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function setSession(jwt) {
|
||||
var url = "/api/auth/session/set";
|
||||
var payload = {};
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseSession(response);
|
||||
}
|
||||
}, "application/json", `Bearer ${jwt}`);
|
||||
}
|
||||
|
||||
function responseAlert(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
if (obj.status == "success") {
|
||||
loadingResponse();
|
||||
document.getElementById("alert-desc" ).innerHTML = "Set the session";
|
||||
setSession(obj.data.jwt);
|
||||
}
|
||||
if (obj.status == "failed") {
|
||||
document.getElementById("alert-response").classList.add('alert-danger');
|
||||
document.getElementById("alert-status" ).innerHTML = obj.status;
|
||||
document.getElementById("alert-desc" ).innerHTML = obj.desc;
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
loadingResponse();
|
||||
var username = document.getElementById("form-username").value;
|
||||
var password = document.getElementById("form-password").value;
|
||||
|
||||
var url = "/api/auth/login";
|
||||
var payload = {
|
||||
"username" : username,
|
||||
"password" : password
|
||||
};
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "application/json");
|
||||
|
||||
}
|
||||
|
||||
flushResponse();
|
45
static/js/auth/notme.js
Normal file
45
static/js/auth/notme.js
Normal file
@ -0,0 +1,45 @@
|
||||
function flushResponse() {
|
||||
document.getElementById("alert-response" ).style.display = 'none';
|
||||
document.getElementById("alert-response" ).classList.remove('alert-success' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-danger' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-primary' );
|
||||
}
|
||||
|
||||
function loadingResponse() {
|
||||
flushResponse();
|
||||
document.getElementById("alert-status" ).innerHTML = "Loading...";
|
||||
document.getElementById("alert-desc" ).innerHTML = "Please wait...";
|
||||
document.getElementById("alert-response").classList.add('alert-primary');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function responseAlert(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
if (obj.status == "success" ) document.getElementById("alert-response").classList.add('alert-success' );
|
||||
if (obj.status == "failed" ) document.getElementById("alert-response").classList.add('alert-danger' );
|
||||
document.getElementById("alert-status" ).innerHTML = obj.status;
|
||||
document.getElementById("alert-desc" ).innerHTML = obj.desc;
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function notme() {
|
||||
document.getElementById("notme-link").style.display = 'none';
|
||||
loadingResponse();
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const token = urlParams.get('token');
|
||||
var url = "/api/auth/notme";
|
||||
var payload = {
|
||||
"token" : token
|
||||
};
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
flushResponse();
|
68
static/js/auth/register.js
Normal file
68
static/js/auth/register.js
Normal file
@ -0,0 +1,68 @@
|
||||
function flushResponse() {
|
||||
document.getElementById("alert-response" ).style.display = 'none';
|
||||
document.getElementById("resend-div" ).style.display = 'none';
|
||||
document.getElementById("alert-response" ).classList.remove('alert-success' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-danger' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-primary' );
|
||||
}
|
||||
|
||||
function loadingResponse() {
|
||||
flushResponse();
|
||||
document.getElementById("alert-status" ).innerHTML = "Loading...";
|
||||
document.getElementById("alert-desc" ).innerHTML = "Please wait...";
|
||||
document.getElementById("alert-response").classList.add('alert-primary');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function responseAlert(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
if (obj.status == "success" ) document.getElementById("alert-response").classList.add('alert-success' );
|
||||
if (obj.status == "failed" ) document.getElementById("alert-response").classList.add('alert-danger' );
|
||||
if (obj.desc == "check email for verification") {
|
||||
document.getElementById("resend-email" ).value = document.getElementById("form-email").value;
|
||||
document.getElementById("resend-message" ).innerHTML = obj.data.message;
|
||||
document.getElementById("resend-link" ).setAttribute('href', obj.data.resend);
|
||||
document.getElementById("resend-div" ).style.display = 'block';
|
||||
}
|
||||
document.getElementById("alert-status" ).innerHTML = obj.status;
|
||||
document.getElementById("alert-desc" ).innerHTML = obj.desc;
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function onSubmit(token) {
|
||||
loadingResponse();
|
||||
var email = document.getElementById("form-email" ).value;
|
||||
var username = document.getElementById("form-username" ).value;
|
||||
var password = document.getElementById("form-password" ).value;
|
||||
var roles = document.getElementById("roles" ).value;
|
||||
var url = "/api/auth/register/"+roles;
|
||||
var payload = {
|
||||
"email" : email,
|
||||
"username" : username,
|
||||
"password" : password
|
||||
};
|
||||
payload.captcha = token; // Add response from reCAPTCHA
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
function resending() {
|
||||
loadingResponse();
|
||||
var email = document.getElementById("resend-email").value;
|
||||
var url = "/api/auth/resend?email="+email;
|
||||
sendHttpRequest(url, "GET", null, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "multipart/form-data");
|
||||
}
|
||||
|
||||
flushResponse();
|
49
static/js/auth/reset.js
Normal file
49
static/js/auth/reset.js
Normal file
@ -0,0 +1,49 @@
|
||||
function flushResponse() {
|
||||
document.getElementById("alert-response" ).style.display = 'none';
|
||||
document.getElementById("alert-response" ).classList.remove('alert-success' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-danger' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-primary' );
|
||||
}
|
||||
|
||||
function loadingResponse() {
|
||||
flushResponse();
|
||||
document.getElementById("alert-status" ).innerHTML = "Loading...";
|
||||
document.getElementById("alert-desc" ).innerHTML = "Please wait...";
|
||||
document.getElementById("alert-response").classList.add('alert-primary');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function responseAlert(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
if (obj.status == "success" ) {
|
||||
document.getElementById("form").style.display = 'none';
|
||||
document.getElementById("alert-response").classList.add('alert-success' );
|
||||
}
|
||||
if (obj.status == "failed" ) document.getElementById("alert-response").classList.add('alert-danger' );
|
||||
document.getElementById("alert-status" ).innerHTML = obj.status;
|
||||
document.getElementById("alert-desc" ).innerHTML = obj.desc;
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
loadingResponse();
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const token = urlParams.get('token')
|
||||
var password = document.getElementById("form-password").value;
|
||||
var url = "/api/auth/reset";
|
||||
var payload = {
|
||||
"token" : token,
|
||||
"password" : password
|
||||
};
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
flushResponse();
|
44
static/js/auth/verify.js
Normal file
44
static/js/auth/verify.js
Normal file
@ -0,0 +1,44 @@
|
||||
function flushResponse() {
|
||||
document.getElementById("alert-response" ).style.display = 'none';
|
||||
document.getElementById("alert-response" ).classList.remove('alert-success' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-danger' );
|
||||
document.getElementById("alert-response" ).classList.remove('alert-primary' );
|
||||
}
|
||||
|
||||
function loadingResponse() {
|
||||
flushResponse();
|
||||
document.getElementById("alert-status" ).innerHTML = "Loading...";
|
||||
document.getElementById("alert-desc" ).innerHTML = "Please wait...";
|
||||
document.getElementById("alert-response").classList.add('alert-primary');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function responseAlert(response) {
|
||||
flushResponse();
|
||||
const obj = JSON.parse(response);
|
||||
if (obj.status == "success" ) document.getElementById("alert-response").classList.add('alert-success' );
|
||||
if (obj.status == "failed" ) document.getElementById("alert-response").classList.add('alert-danger' );
|
||||
document.getElementById("alert-status" ).innerHTML = obj.status;
|
||||
document.getElementById("alert-desc" ).innerHTML = obj.desc;
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
}
|
||||
|
||||
function verify() {
|
||||
loadingResponse();
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const token = urlParams.get('token')
|
||||
var url = "/api/auth/verify";
|
||||
var payload = {
|
||||
"token" : token
|
||||
};
|
||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||
if (error) console.error("Error:", error);
|
||||
else {
|
||||
console.log("JSON Response:", response);
|
||||
responseAlert(response);
|
||||
}
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
verify();
|
19
static/js/carrack.js
Normal file
19
static/js/carrack.js
Normal file
@ -0,0 +1,19 @@
|
||||
function sendHttpRequest(url, method, data, callback, contentType = "multipart/form-data", authorization = "") {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open(method, url, true);
|
||||
xhr.setRequestHeader("Content-Type", contentType);
|
||||
xhr.setRequestHeader("Authorization", authorization);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
var response = xhr.responseText;
|
||||
callback(null, response);
|
||||
}
|
||||
else callback(xhr.status, null);
|
||||
}
|
||||
};
|
||||
var requestData;
|
||||
if (contentType === "application/json") requestData = JSON.stringify(data);
|
||||
else requestData = data;
|
||||
xhr.send(requestData);
|
||||
}
|
674
templates/postcard/LICENSE
Normal file
674
templates/postcard/LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
59
templates/postcard/html/index.html
Normal file
59
templates/postcard/html/index.html
Normal file
@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>${title}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
color: #333;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: #f4f4f4;
|
||||
color: #333;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.button {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>${header}</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
${container}
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>${copyright}</p>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
16
templates/postcard/main.py
Normal file
16
templates/postcard/main.py
Normal file
@ -0,0 +1,16 @@
|
||||
# CostaPy Template - Postcard
|
||||
# Copyright (C) 2024 Dita Aji Pratama
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
|
||||
from core import html
|
||||
|
||||
def main(dir, page):
|
||||
html_template = html.main.get_html("templates/postcard/html")
|
||||
html_page = html.main.get_html(dir)
|
||||
return {
|
||||
"index" : html_template [ "index.html" ],
|
||||
"container" : html_page [f"{page}.html" ]
|
||||
}
|
Loading…
Reference in New Issue
Block a user