forked from ticketfrei/ticketfrei
Compare commits
27 Commits
Author | SHA1 | Date |
---|---|---|
missytake | 78871608b1 | |
anon_user | 1b9fb6727c | |
anon_user | 0dc0e915ee | |
anon_user | d5c801184c | |
b3yond | d9a1bbf10f | |
b3yond | 8f21e7d134 | |
b3yond | 81f32e0898 | |
b3yond | fc0ffca1f7 | |
b3yond | c8bf3e1fba | |
b3yond | 3ed458b518 | |
b3yond | 2df0b1317e | |
b3yond | ce15776077 | |
Enno G | 5bb5f9f05b | |
SchoolGuy | 06d5568a03 | |
b3yond | adea5004f4 | |
b3yond | 013643bc78 | |
b3yond | 22488d3aa6 | |
b3yond | 8b58615dc3 | |
b3yond | 8c778927ee | |
b3yond | 079166e74c | |
b3yond | fb15771cf2 | |
sid | d1b11fe932 | |
b3yond | c30f9d8eaa | |
b3yond | 7a7e8f0a30 | |
b3yond | e18244e149 | |
b3yond | cd3c8be2dc | |
b3yond | 02f117a864 |
22
README.md
22
README.md
|
@ -152,10 +152,19 @@ echo "Enter your domain name into the following prompt:" && read DOMAIN
|
|||
# configure nginx
|
||||
sudo sed -r "s/example.org/$DOMAIN/g" deployment/example.org.conf > /etc/nginx/sites-enabled/$DOMAIN.conf
|
||||
|
||||
# create folder for socket & database
|
||||
# create folder for database
|
||||
sudo mkdir /var/ticketfrei
|
||||
sudo chown www-data:www-data -R /var/ticketfrei
|
||||
|
||||
# create folder for socket
|
||||
sudo mkdir /var/run/ticketfrei
|
||||
sudo chown -R www-data:www-data /var/run/ticketfrei
|
||||
sudo -s
|
||||
echo "mkdir /var/run/ticketfrei" >> /etc/rc.local
|
||||
echo "chown -R www-data:www-data /var/run/ticketfrei" >> /etc/rc.local
|
||||
echo "service ticketfrei-web restart" >> /etc/rc.local
|
||||
exit
|
||||
|
||||
# change /etc/aliases permissions to be able to receive reports per mail
|
||||
sudo chown root:www-data /etc/aliases
|
||||
sudo chmod 664 /etc/aliases
|
||||
|
@ -178,6 +187,17 @@ sudo systemctl daemon-reload
|
|||
sudo systemctl start ticketfrei-backend.service
|
||||
```
|
||||
|
||||
### Backup
|
||||
|
||||
For automated backups, you need to backup these files:
|
||||
|
||||
* `/var/ticketfrei/db.sqlite`
|
||||
* `/srv/ticketfrei/config.toml`
|
||||
* `/etc/aliases`
|
||||
|
||||
You can find an example how to do this with borgbackup in the deployment
|
||||
folder. Adjust it to your needs.
|
||||
|
||||
### Logs
|
||||
|
||||
There are several logfiles which you can look at:
|
||||
|
|
|
@ -58,29 +58,12 @@ def make_report(msg, user):
|
|||
date = get_date_from_header(msg['Date'])
|
||||
|
||||
author = msg['From'] # get mail author from email header
|
||||
|
||||
if msg.is_multipart():
|
||||
text = []
|
||||
for part in msg.get_payload():
|
||||
if part.get_content_type() == "text":
|
||||
text.append(part.get_payload())
|
||||
elif part.get_content_type() == "application/pgp-signature":
|
||||
pass # ignore PGP signatures
|
||||
elif part.get_content_type() == "multipart/mixed":
|
||||
for p in part:
|
||||
if isinstance(p, str):
|
||||
text.append(p)
|
||||
elif p.get_content_type() == "text":
|
||||
text.append(part.get_payload())
|
||||
else:
|
||||
logger.error("unknown MIMEtype: " +
|
||||
p.get_content_type())
|
||||
else:
|
||||
logger.error("unknown MIMEtype: " +
|
||||
part.get_content_type())
|
||||
text = '\n'.join(text)
|
||||
else:
|
||||
text = msg.get_payload()
|
||||
text = msg.get_body(('plain',))
|
||||
if not text:
|
||||
text = re.sub(r'<[^>]*>', '', msg.get_body(('html',)))
|
||||
if not text:
|
||||
logger.error('No suitable message body')
|
||||
return
|
||||
post = report.Report(author, "mail", text, None, date)
|
||||
user.save_seen_mail(date)
|
||||
return post
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from bot import Bot
|
||||
import logging
|
||||
from mastodon import Mastodon
|
||||
import mastodon
|
||||
import re
|
||||
from report import Report
|
||||
|
||||
|
@ -19,14 +19,43 @@ class MastodonBot(Bot):
|
|||
"""
|
||||
mentions = []
|
||||
try:
|
||||
m = Mastodon(*user.get_masto_credentials())
|
||||
m = mastodon.Mastodon(*user.get_masto_credentials())
|
||||
except TypeError:
|
||||
# logger.error("No Mastodon Credentials in database.", exc_info=True)
|
||||
# No Mastodon Credentials in database.
|
||||
return mentions
|
||||
try:
|
||||
notifications = m.notifications()
|
||||
except Exception:
|
||||
logger.error("Unknown Mastodon API Error.", exc_info=True)
|
||||
except mastodon.MastodonNetworkError:
|
||||
return mentions
|
||||
except mastodon.MastodonInternalServerError:
|
||||
try:
|
||||
logger.error("Mastodon Error: 500. Server: " + m.instance()['urls']['streaming_api'])
|
||||
except mastodon.MastodonServerError:
|
||||
logger.error("Mastodon Server Error 500, can't get instance.")
|
||||
return mentions
|
||||
except mastodon.MastodonBadGatewayError:
|
||||
try:
|
||||
logger.error("Mastodon Error: 502. Server: " + m.instance()['urls']['streaming_api'])
|
||||
except mastodon.MastodonServerError:
|
||||
logger.error("Mastodon Server Error 502, can't get instance.")
|
||||
return mentions
|
||||
except mastodon.MastodonServiceUnavailableError:
|
||||
try:
|
||||
logger.error("Mastodon Error: 503. Server: " + m.instance()['urls']['streaming_api'])
|
||||
except mastodon.MastodonServerError:
|
||||
logger.error("Mastodon Server Error 503, can't get instance.")
|
||||
return mentions
|
||||
except mastodon.MastodonGatewayTimeoutError:
|
||||
try:
|
||||
logger.error("Mastodon Error: 504. Server: " + m.instance()['urls']['streaming_api'])
|
||||
except mastodon.MastodonServerError:
|
||||
logger.error("Mastodon Server Error 504, can't get instance.")
|
||||
return mentions
|
||||
except mastodon.MastodonServerError:
|
||||
try:
|
||||
logger.error("Unknown Mastodon Server Error. Server: " + m.instance()['urls']['streaming_api'], exc_info=True)
|
||||
except mastodon.MastodonServerError:
|
||||
logger.error("Unknown Mastodon Server Error.", exc_info=True)
|
||||
return mentions
|
||||
for status in notifications:
|
||||
if (status['type'] == 'mention' and
|
||||
|
@ -54,7 +83,7 @@ class MastodonBot(Bot):
|
|||
|
||||
def post(self, user, report):
|
||||
try:
|
||||
m = Mastodon(*user.get_masto_credentials())
|
||||
m = mastodon.Mastodon(*user.get_masto_credentials())
|
||||
except TypeError:
|
||||
return # no mastodon account for this user.
|
||||
if report.source == self:
|
||||
|
|
|
@ -23,6 +23,7 @@ class TelegramBot(Bot):
|
|||
# return when telegram returns an error code
|
||||
if update in [303, 404, 420, 500, 502]:
|
||||
return reports
|
||||
# log unusual telegram error messages
|
||||
if isinstance(update, int):
|
||||
try:
|
||||
logger.error("City " + str(user.uid) +
|
||||
|
@ -31,7 +32,22 @@ class TelegramBot(Bot):
|
|||
except TypeError:
|
||||
logger.error("Unknown Telegram error code: " + str(update))
|
||||
return reports
|
||||
# save the last message, so it doesn't get crawled again
|
||||
user.save_seen_tg(update.update_id)
|
||||
# complain if message is a photo
|
||||
if update.message.photo:
|
||||
tb.send_message(
|
||||
update.message.sender.id,
|
||||
"Sending Photos is not supported for privacy reasons. Can "
|
||||
"you describe it as text instead?")
|
||||
continue
|
||||
# complain if message is a media file
|
||||
if update.message.text is None:
|
||||
tb.send_message(
|
||||
update.message.sender.id,
|
||||
"We only support text reporting for privacy reasons. Can "
|
||||
"you describe it as text instead?")
|
||||
continue
|
||||
if update.message.text.lower() == "/start":
|
||||
user.add_telegram_subscribers(update.message.sender.id)
|
||||
tb.send_message(
|
||||
|
|
|
@ -73,7 +73,7 @@ class TwitterBot(Bot):
|
|||
def post(self, user, report):
|
||||
try:
|
||||
api = self.get_api(user)
|
||||
except IndexError:
|
||||
except TypeError:
|
||||
return # no twitter account for this user.
|
||||
try:
|
||||
if report.source == self:
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
# This is a script to backup the necessary components for a deployment with
|
||||
# nginx and uwsgi with borgbackup.
|
||||
|
||||
# stop the services
|
||||
service ticketfrei-web stop
|
||||
service ticketfrei-backend stop
|
||||
|
||||
# export repository passphrase
|
||||
export BORG_PASSPHRASE='password'
|
||||
|
||||
# create backup
|
||||
borg create --stats --progress backup:repositories-borg/ticketfrei::'backup{now:%Y%m%d}' /etc/aliases /var/ticketfrei/db.sqlite /srv/ticketfrei/config.toml
|
||||
|
||||
# restart the service
|
||||
service ticketfrei-backend start
|
||||
service ticketfrei-web start
|
||||
|
||||
# prune outdated backups to save storage
|
||||
borg prune --keep-daily=7 --keep-weekly=4 backup:repositories-borg/ticketfrei
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
[Unit]
|
||||
Description=Ticketfrei Backend
|
||||
After=syslog.target network.target
|
||||
StartLimitIntervalSec=300
|
||||
StartLimitBurst=3
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/srv/ticketfrei
|
||||
ExecStart=/srv/ticketfrei/bin/python3 backend.py
|
||||
# Requires systemd version 211 or newer
|
||||
#RuntimeDirectory=uwsgi
|
||||
Restart=always
|
||||
RestartSec=60
|
||||
KillSignal=SIGQUIT
|
||||
Type=simple
|
||||
StandardError=syslog
|
||||
NotifyAccess=all
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue