This commit is contained in:
Izalia Mae 2020-01-15 08:57:07 -05:00
parent 46489746c5
commit 69cb899a93
8 changed files with 398 additions and 0 deletions

79
paws/oauth.py Normal file
View file

@ -0,0 +1,79 @@
import os
import json
import sys
import logging
import time
import traceback
import http.client as http
from urllib.parse import urlencode, urlparse
from mastodon import Mastodon
from .config import PAWSCONFIG, MASTOCONFIG, VERSION, stor_path
HEADERS = {
'User-Agent': f'PAWS/{VERSION}',
'Accept': 'application/json'
}
SCOPES = ['read:accounts']
REDIR_URI = f'https://{MASTOCONFIG["domain"]}/paws/auth'
WEBSITE = 'https://git.barkshark.xyz/izaliamae/paws'
def get_webhost(domain):
conn = http.HTTPSConnection(domain)
conn.request('GET', '/.well-known/host-meta', headers=HEADERS)
response = conn.getresponse()
if response.status == 301:
url = response.msg.get('Location')
return urlparse(url).netloc
elif response.status != 200:
return
return domain
def create_app(domain):
instance = get_webhost(domain)
try:
app_id, app_secret = Mastodon.create_app(
f'PAWS @ {MASTOCONFIG["domain"]}',
api_base_url=instance,
scopes=SCOPES,
redirect_uris=REDIR_URI,
website=WEBSITE
)
except Exception as e:
traceback.print_exc()
logging.error(f'Failed to create app: {e}')
return
client = Mastodon(
api_base_url=instance,
client_id=app_id,
client_secret=app_secret
)
return (app_id, app_secret, client.auth_request_url(redirect_uris=REDIR_URI, scopes=SCOPES))
def login(user, code):
fetch = Mastodon(
api_base_url=user['domain'],
client_id=user['appid'],
client_secret=user['appsecret']
)
token = fetch.log_in(redirect_uri=REDIR_URI, scopes=SCOPES, code=code)
client = Mastodon(api_base_url=user['domain'], access_token=token)
fetch_user = client.me()
return (token, fetch_user)

26
paws/templates/base.html Normal file
View file

@ -0,0 +1,26 @@
{% set default_open = 'open' %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>PAWS@{{domain}}: {{page}}</title>
<link rel=stylesheet href="/paws/style.css" media="screen">
</head>
<body>
<div id="content">
<div id="header">
<h1 id="name">PAWS</h1>
</div>
{% block content %}{% endblock %}
<div class="section grid-container" id="footer">
<div class="grid-item col1">
<p><a href="https://{{domain}}/about">{{domain}}</a></p>
</div>
<div class="grid-item col2">
<p><a href="https://git.barkshark.xyz/izaliamae/paws" target="_new">PAWS/{{VERSION}}</a></p>
</div>
</div>
</div>
</body>
</html>

105
paws/templates/color.css Normal file
View file

@ -0,0 +1,105 @@
{% set primary = '#C6C' %}
{% set secondary = '#68C' %}
{% set error = '#C64' %}
{% set background = '#202020' %}
{% set text = '#DDD' %}
/* variables */
:root {
--text: {{text}};
--bg-color: {{background}};
--bg-color-dark: {{desaturate(darken(primary, 0.85), 0.8)}};
--bg-color-lighter: {{lighten(background, 0.075)}};
--bg-dark: {{desaturate(darken(primary, 0.90), 0.5)}};
--primary: {{primary}};
--error: {{desaturate(darken('red', 0.2), 0.25)}};
--valid: {{desaturate(darken('green', 0.2), 0.25)}};
--shadow-color: {{rgba('black', 0.5)}};
--shadow: 0 4px 4px 0 var(--shadow-color), 0 6px 10px 0 var(--shadow-color);
--border-radius: 10px;
}
/* general */
*:not(#content) {
transition-property: color, background-color, border, width, height;
transition-timing-function: ease-in-out;
transition-duration: 0.35s;
}
body {
background-color: var(--bg-dark);
color: var(--text);
}
a {
color: {{saturate(lighten(primary, 0.4), 0.2)}};
text-decoration: none;
}
select {
-webkit-appearance: none;
-moz-appearance: none;
}
input, textarea, select {
color: var(--text);
border: 1px solid transparent;
background-color: var(--bg-color);
box-shadow: var(--shadow);
}
input:hover, textarea:hover, select:hover {
color: {{desaturate(primary, 0.6)}};
border-color: {{desaturate(primary, 0.6)}};
}
input:focus, textarea:focus, select:focus {
color: {{primary}};
background-color: var(--bg-dark);
border-color: {{primary}};
}
a:hover {
color: {{saturate(primary, 0.8)}};
}
#content {
background-color: var(--bg-color);
box-shadow: var(--shadow);
}
.section {
background-color: var(--bg-color-lighter);
box-shadow: var(--shadow);
}
tr {
border: 1px solid black;
border-radius: var(--border-radius);
}
tr:nth-child(odd):not(.header) td {
background-color: {{desaturate(darken(primary, 0.80), 0.9)}};
}
tr:nth-child(even) td {
background-color: {{desaturate(darken(primary, 0.75), 1)}};
}
tr:not(.header):hover td {
color: var(--bg-color-dark);
background-color: {{desaturate(primary, 0.2)}};
}
tr:not(.header):hover td a {
color: var(--bg-color-dark);
}
.error {
color: var(--error);
font-weight: bold;
}
{% include 'layout.css' %}

146
paws/templates/layout.css Normal file
View file

@ -0,0 +1,146 @@
/* general */
body {
font-family: "Noto Sans", Sans-Serif;
font-size: 12pt;
margin: 0px;
}
input, textarea, select, div.placeholder {
height: 22px;
padding: 2px 7px;
-moz-border-radius: var(--border-radius);
border-radius: var(--border-radius);
margin: 5px;
}
select {
height: 28px !important;
}
summary:hover {
cursor: pointer;
}
#content {
width: 1000px;
margin: 0 auto;
padding-bottom: 1px;
border-radius: var(--border-radius);
}
#header h1 {
margin: 0px;
padding-top: 20px;
padding-bottom: 15px;
text-align: center;
}
#header div {
text-align: center;
}
#footer {
grid-template-columns: auto auto;
font-size: 12px;
}
#footer .col2 {
text-align: right;
}
#footer p {
margin: 0;
}
.section {
margin: 15px auto;
padding: 10px;
width: calc(100% - 45px);
border-radius: var(--border-radius);
}
.section .title {
margin-top: 0;
margin-bottom: 10px;
text-align: center;
}
input.placeholder {
height: 21px;
}
label.placeholder {
height: 19px;
}
table {
width: 100%;
border-spacing: 0;
}
td {
padding: 5px;
}
tr:nth-child(2) .col1 {
border-top-left-radius: var(--border-radius);
}
tr:nth-child(2) .col2 {
border-top-right-radius: var(--border-radius);
}
tr:last-child .col1 {
border-bottom-left-radius: var(--border-radius);
}
tr:last-child .col2 {
border-bottom-right-radius: var(--border-radius);
}
.indent1 {
padding-left: 20px;
}
.indent2 {
padding-left: 40px;
}
.indent3 {
padding-left: 60px;
}
/* Grids */
.grid-container {
display: grid;
grid-gap: 0;
grid-template-columns: 50% auto;
}
.grid-item {
display: inline-grid;
}
/* Login */
#auth {
text-align: center;
}
.msg, .error {
margin-bottom: 10px;
}
/* mobile/small screen */
@media (max-width : 1000px) {
#content {
width: 100%;
border-radius: 0;
}
.grid-container {
grid-template-columns: auto;
}
}

View file

@ -0,0 +1 @@
Missing template file

View file

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% set page = 'Error ' + code %}
{% block content %}
<div class="section" id="error">
<h2 class="title">Error {{code}}</h2>
{{msg}}
</div>
{% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "base.html" %}
{% set page = 'Login' %}
{% block content %}
<div class="section" id="auth">
<h2 class="title">Login</h2>
{% if msg %}
<div class="error">{{msg}}</div>
{% endif %}
<form action="/paws/login" method="post">
<input type="hidden" name="redir" value="{{redir}}" />
<input type="hidden" name="numid" value="{{numid}}" />
<div class="msg">This instance requres you to login via oauth to view public pages<br />
Please input the instance of the account you'd like to login with</div>
<input type="text" name="domain" placeholder="bofa.lol" /><br />
<input type="submit" value="Submit">
</form>
</div>
{% endblock %}

View file

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% set page = 'Login' %}
{% block content %}
<!-- Reminder: Include this file instead of linking to an outside source -->
<center><img src="https://static.barkshark.xyz/main/img/YouDidntSayTheMagicWord.gif" /></center>
{% endblock %}