Compare commits

...

27 Commits
csrf ... master

Author SHA1 Message Date
missytake 78871608b1 improved systemd file which recovers more easily from crashes 2020-01-15 19:57:18 +01:00
anon_user 1b9fb6727c vmike read the docs & did some magic 2019-11-20 23:15:21 +01:00
anon_user 0dc0e915ee don't spam the log if the network is failing 2019-09-15 07:30:50 +02:00
anon_user d5c801184c Fixed shutdowns when Mastodon Errors can't get instance name 2019-09-14 12:12:16 +02:00
b3yond d9a1bbf10f
Merge pull request #106 from ticketfrei/masto502
More detailed Mastodon Server errors
2019-08-11 10:06:46 +02:00
b3yond 8f21e7d134 those errors are not unknown of course. 2019-08-09 15:29:51 +02:00
b3yond 81f32e0898 added backtrace to general error message 2019-08-09 15:21:49 +02:00
b3yond fc0ffca1f7
Merge pull request #104 from ticketfrei/hotfix-tg-2.1.6
Hotfix tg 2.1.6
2019-08-09 15:46:30 +03:00
b3yond c8bf3e1fba fixing None TypeError 2019-08-09 14:41:14 +02:00
b3yond 3ed458b518 logging telegram messages for debug purposes 2019-08-09 14:35:01 +02:00
b3yond 2df0b1317e ... sending text reports should of course be allowed. 2019-08-09 12:24:09 +02:00
b3yond ce15776077
Merge pull request #101 from SchoolGuy/fix-non-text-message-crash
Fix non text message crash
2019-07-22 21:05:37 +02:00
Enno G 5bb5f9f05b
Change to hasattr 2019-07-22 20:51:49 +02:00
SchoolGuy 06d5568a03
Check if the text property is inside the message object. 2019-07-14 15:58:22 +02:00
b3yond adea5004f4 fixed uwsgi deployment instructions 2019-07-13 09:04:05 +02:00
b3yond 013643bc78 added the server URL to masto server errors 2019-07-08 23:09:32 +02:00
b3yond 22488d3aa6 more detailed Mastodon 5xx error messages 2019-07-08 23:04:33 +02:00
b3yond 8b58615dc3 Created a borgbackup script for deployments with nginx & uwsgi 2019-07-07 19:22:07 +02:00
b3yond 8c778927ee fixing import error 2019-05-17 20:42:13 +02:00
b3yond 079166e74c
Merge pull request #86 from ticketfrei/masto502
don't log Mastodon 502 errors.
2019-05-04 12:04:51 +02:00
b3yond fb15771cf2
Merge pull request #93 from ticketfrei/images
Notify that telegram image reports are not supported. #90
2019-05-04 10:23:34 +02:00
sid d1b11fe932
Update active_bots/telegrambot.py
Co-Authored-By: b3yond <b3yond@riseup.net>
2019-05-04 10:22:03 +02:00
b3yond c30f9d8eaa
Merge pull request #87 from ticketfrei/fix-none-error
fixed wrong exception
2019-05-03 17:11:25 +02:00
b3yond 7a7e8f0a30 Notify that telegram image reports are not supported. #90 2019-05-03 14:35:06 +02:00
b3yond e18244e149 don't log Mastodon 502 errors. 2019-05-03 10:07:16 +02:00
b3yond cd3c8be2dc fixed wrong exception 2019-02-19 16:16:21 +01:00
b3yond 02f117a864
Merge pull request #82 from ticketfrei/csrf
Building in CSRF prevention
2019-01-27 17:56:53 +01:00
7 changed files with 120 additions and 31 deletions

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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(

View File

@ -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:

21
deployment/backup.sh Normal file
View File

@ -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

View File

@ -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