Update for sr.ht unified config

This commit is contained in:
Drew DeVault 2018-09-02 21:00:27 -04:00
parent bbbf3ad23e
commit 68b2993205
8 changed files with 90 additions and 86 deletions

View File

@ -1,63 +1,65 @@
[sr.ht]
#
# lists.sr.ht config
[server]
# The name of your network of sr.ht-based sites
site-name=sr.ht
#
# Specifies the protocol (usually http or https) meta.sr.ht runs with.
protocol=http
# Contact information for the site owners
owner-name=Drew DeVault
owner-email=sir@cmpwn.com
#
# Specifies the domain name lists.sr.ht is running on.
domain=lists.sr.ht.local
# The source code for your fork of sr.ht
source-url=https://git.sr.ht/~sircmpwn/srht
#
# A secret key to encrypt session cookies with.
# A secret key to encrypt session cookies with
secret-key=CHANGEME
[debug]
[mail]
#
# Address and port to bind the debug server to.
# Outgoing SMTP settings
smtp-host=
smtp-port=
smtp-user=
smtp-password=
smtp-from=
#
# Application exceptions are emailed to this address
error-to=
error-from=
#
# Your PGP key information (DO NOT mix up pub and priv here)
# You must remove the password from your secret key, if present.
# You can do this with gpg --edit-key [key-id], then use the passwd
# command and do not enter a new password.
pgp-privkey=
pgp-pubkey=
pgp-key-id=
[lists.sr.ht]
#
# URL lists.sr.ht is being served at (protocol://domain)
origin=http://lists.sr.ht.local
#
# Address and port to bind the debug server to
debug-host=0.0.0.0
debug-port=5006
[sr.ht]
#
# Configures the SQLAlchemy connection string for the database.
connection-string=postgresql://postgres@localhost/lists.sr.ht
#
# The name of your network of sr.ht-based sites
site-name=sr.ht
[mail]
#
# SMTP settings for outgoing mail
smtp-host=CHANGEME
smtp-port=CHANGEME
smtp-user=CHANGEME
smtp-password=CHANGEME
[network]
#
# Location of other sites in your network
#
# This isn't a hardcoded list, add or remove entries as you like. The upstream
# sites do know about each other and will omit integrations if you leave out
# the relevant site. Only meta is required.
meta=http://meta.sr.ht.local
git=http://git.sr.ht.local
builds=http://builds.sr.ht.local
lists=http://lists.sr.ht.local
todo=http://todo.sr.ht.local
man=http://man.sr.ht.local
dispatch=http://dispatch.sr.ht.local
[meta.sr.ht]
oauth-client-id=3312905beddc2b3f
oauth-client-secret=07cc502b5097808f30a9098925b45acb
[lists]
# The redis connection used for the Celery worker (configure this on both the
# master and workers)
redis=redis://localhost:6379/0
#
# The domain that incoming email should be sent to. Forward mail sent here to
# the LTMP socket.
posting-domain=lists.localhost.localdomain
posting-domain=lists.sr.ht.local
#
# lists.sr.ht's OAuth client ID and secret for meta.sr.ht
# Register your client at meta.example.org/oauth
oauth-client-id=
oauth-client-secret=
[lists.sr.ht::worker]
#
# Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
sock=/tmp/lists.sr.ht-lmtp.sock
@ -82,7 +84,7 @@ reject-mimetypes=text/html
#
# Link to include in the rejection message where senders can get help
# correcting their email.
reject-url=https://man.sr.ht/lists.sr.ht/etiquette.md
#
# Redis instance used by celery for dispatching email blast tasks
redis=redis://localhost:6379/0
reject-url=https://man.sr.ht/lists.sr.ht/how-to-send.md
[meta.sr.ht]
origin=http://meta.sr.ht.local

View File

@ -12,7 +12,7 @@ import os
import signal
import sys
load_config("lists")
load_config("lists.sr.ht")
from listssrht.process import dispatch_message
@ -23,9 +23,11 @@ class MailHandler:
self.pg = pg
async def initialize(self):
self.permit_mimetypes = cfg("lists", "permit-mimetypes").split(',')
self.reject_mimetypes = cfg("lists", "reject-mimetypes").split(',')
self.reject_url = cfg("lists", "reject-url")
self.permit_mimetypes = cfg("lists.sr.ht::worker",
"permit-mimetypes").split(',')
self.reject_mimetypes = cfg("lists.sr.ht::worker",
"reject-mimetypes").split(',')
self.reject_url = cfg("lists.sr.ht::worker", "reject-url")
self.fetch_user = await self.pg.prepare(
'''SELECT "id" FROM "user"
WHERE username = $1''')
@ -154,11 +156,11 @@ class MailHandler:
return "250 Message accepted for delivery"
async def create_server():
sock_gid = getgrnam(cfg("lists", "sock-group")).gr_gid
pg = await asyncpg.connect(dsn=cfg("sr.ht", "connection-string"))
sock_gid = getgrnam(cfg("lists.sr.ht::worker", "sock-group")).gr_gid
pg = await asyncpg.connect(dsn=cfg("lists.sr.ht", "connection-string"))
handler = MailHandler(pg)
await handler.initialize()
sock_path = cfg("lists", "sock")
sock_path = cfg("lists.sr.ht::worker", "sock")
await loop.create_unix_server(
lambda: LMTP(handler, enable_SMTPUTF8=True),
path=sock_path)

View File

@ -1,21 +1,18 @@
from srht.flask import SrhtFlask
from srht.config import cfg, load_config
load_config("lists")
from urllib.parse import quote
from srht.config import cfg
from srht.database import DbSession
db = DbSession(cfg("sr.ht", "connection-string"))
db = DbSession(cfg("lists.sr.ht", "connection-string"))
from listssrht.types import User
db.init()
from listssrht.blueprints.archives import archives
from listssrht.blueprints.user import user
from jinja2 import Markup, escape
from urllib.parse import quote
def _post_address(ml, suffix=""):
domain = cfg("lists", "posting-domain")
domain = cfg("lists.sr.ht", "posting-domain")
return "{}/{}{}@{}".format(
ml.owner.canonical_name(), ml.name, suffix, domain)
@ -146,15 +143,18 @@ def _diffstat(patch):
class LoginApp(SrhtFlask):
def __init__(self):
super().__init__("lists", __name__)
super().__init__("lists.sr.ht", __name__)
self.url_map.strict_slashes = False
from listssrht.blueprints.archives import archives
from listssrht.blueprints.user import user
self.register_blueprint(archives)
self.register_blueprint(user)
meta_client_id = cfg("meta.sr.ht", "oauth-client-id")
meta_client_secret = cfg("meta.sr.ht", "oauth-client-secret")
meta_client_id = cfg("lists.sr.ht", "oauth-client-id")
meta_client_secret = cfg("lists.sr.ht", "oauth-client-secret")
self.configure_meta_auth(meta_client_id, meta_client_secret)
@self.context_processor

View File

@ -12,7 +12,7 @@ import re
user = Blueprint("user", __name__)
meta_uri = cfg("network", "meta")
meta_uri = cfg("meta.sr.ht", "origin")
@user.route("/")
def index():

View File

@ -1,11 +1,11 @@
from srht.config import cfg, cfgi, load_config, loaded
is_celery = False
if not loaded():
load_config("lists")
load_config("lists.sr.ht")
is_celery = True
from srht.database import DbSession, db
if is_celery:
db = DbSession(cfg("sr.ht", "connection-string"))
db = DbSession(cfg("lists.sr.ht", "connection-string"))
import listssrht.types
db.init()
from listssrht.types import Email, List, User, Subscription, ListAccess
@ -22,7 +22,7 @@ from email.mime.text import MIMEText
from email.utils import parseaddr, getaddresses
from unidiff import PatchSet
dispatch = Celery("lists.sr.ht", broker=cfg("lists", "redis"))
dispatch = Celery("lists.sr.ht", broker=cfg("lists.sr.ht", "redis"))
smtp_host = cfg("mail", "smtp-host", default=None)
smtp_port = cfgi("mail", "smtp-port", default=None)
@ -30,7 +30,7 @@ smtp_user = cfg("mail", "smtp-user", default=None)
smtp_password = cfg("mail", "smtp-password", default=None)
def _forward(dest, mail):
domain = cfg("lists", "posting-domain")
domain = cfg("lists.sr.ht", "posting-domain")
list_name = "{}/{}".format(dest.owner.canonical_name(), dest.name)
list_unsubscribe = list_name + "+unsubscribe@" + domain
list_subscribe = list_name + "+subscribe@" + domain
@ -42,8 +42,8 @@ def _forward(dest, mail):
"<mailto:{}?subject=unsubscribe>".format(list_unsubscribe))
mail["List-Subscribe"] = (
"<mailto:{}?subject=subscribe>".format(list_subscribe))
mail["List-Archive"] = "<{}://{}/{}>".format(
cfg("server", "protocol"), cfg("server", "domain"), list_name)
mail["List-Archive"] = "<{}/{}>".format(
cfg("lists.sr.ht", "origin"), list_name)
mail["List-Post"] = "<mailto:{}@{}>".format(list_name, domain)
mail["List-ID"] = "{} <{}@{}>".format(dest.name, list_name, domain)
mail["Sender"] = "{} <{}@{}>".format(list_name, list_name, domain)
@ -148,7 +148,7 @@ list are restricted. Your request has been disregarded.{}
However, you are permitted to post mail to this list at this address:
{}@{}""".format(list_addr, cfg("lists", "posting-domain"))
{}@{}""".format(list_addr, cfg("lists.sr.ht", "posting-domain"))
if ListAccess.post in perms else "")))
elif sub is None:
reply = MIMEText("""Hi {}!
@ -160,7 +160,7 @@ email to this address:
Feel free to reply to this email if you have any questions.""".format(
sender[0] or sender[1], list_addr, list_addr,
cfg("lists", "posting-domain")))
cfg("lists.sr.ht", "posting-domain")))
sub = Subscription()
sub.user_id = user.id if user else None
sub.list_id = dest.id
@ -176,9 +176,9 @@ looks like you're already subscribed. To unsubscribe, send an email to:
Feel free to reply to this email if you have any questions.""".format(
sender[0] or sender[1], list_addr, list_addr,
cfg("lists", "posting-domain")))
cfg("lists.sr.ht", "posting-domain")))
reply["To"] = mail["From"]
reply["From"] = "mailer@" + cfg("lists", "posting-domain")
reply["From"] = "mailer@" + cfg("lists.sr.ht", "posting-domain")
reply["In-Reply-To"] = mail["Message-ID"]
reply["Subject"] = "Re: " + (
mail.get("Subject") or "Your subscription request")
@ -224,9 +224,9 @@ re-subscribe, send an email to:
Feel free to reply to this email if you have any questions.""".format(
sender[0] or sender[1], list_addr, list_addr,
cfg("lists", "posting-domain")))
cfg("lists.sr.ht", "posting-domain")))
reply["To"] = mail["From"]
reply["From"] = "mailer@" + cfg("lists", "posting-domain")
reply["From"] = "mailer@" + cfg("lists.sr.ht", "posting-domain")
reply["In-Reply-To"] = mail["Message-ID"]
reply["Subject"] = "Re: " + (
mail.get("Subject") or "Your subscription request")

View File

@ -1,7 +1,7 @@
{% extends "lists.html" %}
{% block title %}
<title>
{{ owner.canonical_name() }}/{{ ml.name }} archives &mdash; {{ cfg("sr.ht", "site-name") }} lists
{{ owner.canonical_name() }}/{{ ml.name }} archives &mdash; {{site}}
</title>
{% endblock %}
{% block content %}

View File

@ -4,13 +4,13 @@
<div class="row">
<div class="col-md-6">
<p>
Welcome to {{cfg("server", "domain")}}. This is a part of the
<a href="{{cfg("network", "meta")}}">
Welcome to {{domain}}. This is a part of the
<a href="{{cfg("meta.sr.ht", "origin")}}">
{{cfg("sr.ht", "site-name")}} network
</a>
and provides mailing list services to members. If you already have an
account, you can <a href="{{oauth_url}}">log in here</a>. New users can
<a href="{{cfg("network", "meta")}}">register here</a>.
<a href="{{cfg("meta.sr.ht", "origin")}}">register here</a>.
</p>
</div>
</div>

4
run.py
View File

@ -6,6 +6,6 @@ import os
app.static_folder = os.path.join(os.getcwd(), "static")
if __name__ == '__main__':
app.run(host=cfg("debug", "debug-host"),
port=cfgi("debug", "debug-port"),
app.run(host=cfg("lists.sr.ht", "debug-host"),
port=cfgi("lists.sr.ht", "debug-port"),
debug=True)