From 83d8700e303a66cd24c4c566e3f27b833ed95607 Mon Sep 17 00:00:00 2001 From: b3yond Date: Mon, 28 May 2018 22:26:07 +0200 Subject: [PATCH 1/5] updated install instructions & gitignore --- .gitignore | 1 + README.md | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 001386f..0349db9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ include/ lib/ share/ local/ +venv/ diff --git a/README.md b/README.md index 2bdc8d7..1524707 100644 --- a/README.md +++ b/README.md @@ -118,9 +118,12 @@ 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 +# create folder for socket & database sudo mkdir /var/ticketfrei sudo chown www-data:www-data -R /var/ticketfrei + +# create folder for logs +sudo mkdir /var/log/ticketfrei sudo chown www-data:www-data -R /var/log/ticketfrei # start up nginx From 0719b094f8e9cca9d859bf8dfaf3e04d4501ea6c Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 24 Jun 2018 00:00:48 +0200 Subject: [PATCH 2/5] added telegram to frontend --- db.py | 9 +++++++++ frontend.py | 8 ++++++++ template/settings.tpl | 15 +++++++++++++++ user.py | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/db.py b/db.py index 942cbf5..f96927e 100644 --- a/db.py +++ b/db.py @@ -90,6 +90,13 @@ class DB(object): active INTEGER, FOREIGN KEY(user_id) REFERENCES user(id) ); + CREATE TABLE IF NOT EXISTS telegram_accounts ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, + user_id INTEGER, + apikey TEXT, + active INTEGER, + FOREIGN KEY(user_id) REFERENCES user(id) + ); CREATE TABLE IF NOT EXISTS seen_tweets ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, user_id INTEGER, @@ -173,6 +180,8 @@ u\d\d? uid = json['uid'] self.execute("INSERT INTO email (user_id, email) VALUES(?, ?);", (uid, json['email'])) + self.execute("""INSERT INTO telegram_accounts (user_id, apikey, + active) VALUES(?, ?, ?);""", (uid, "", 1)) self.commit() user = User(uid) user.set_city(city) diff --git a/frontend.py b/frontend.py index a3ae423..969bea6 100755 --- a/frontend.py +++ b/frontend.py @@ -114,6 +114,14 @@ def update_badwords(user): return user.state() +@post('/settings/telegram') +@view('template/settings.tpl') +def register_telegram(user): + apikey = request.forms['apikey'] + user.set_telegram_key(apikey) + return user.state() + + @get('/api/state') def api_enable(user): return user.state() diff --git a/template/settings.tpl b/template/settings.tpl index cd7e524..5ce48cb 100644 --- a/template/settings.tpl +++ b/template/settings.tpl @@ -67,6 +67,21 @@

+
+

Connect with Telegram

+

+ If you have a Telegram account, you can register a bot there. Just write to @botfather. You can find detailed + instructions on Bots for + Telegram. +

+

+ The botfather will give you an API key - with the API key, Ticketfrei can use the Telegram bot. Enter it here: +

+
+ + +

Edit your city page

diff --git a/user.py b/user.py index edadd48..368184a 100644 --- a/user.py +++ b/user.py @@ -205,6 +205,10 @@ schlitz (self.uid, )) return db.cur.fetchall() + def set_telegram_key(self, apikey): + db.execute("UPDATE telegram_accounts SET apikey = ? WHERE user_id = ?;", (apikey, self.uid)) + db.commit() + def get_mastodon_app_keys(self, instance): db.execute("SELECT client_id, client_secret FROM mastodon_instances WHERE instance = ?;", (instance, )) try: From 4c6ab2d3ae1eb96de9c7cf196020a5d0e5789058 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 24 Jun 2018 00:12:39 +0200 Subject: [PATCH 3/5] css fixes --- template/settings.tpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/template/settings.tpl b/template/settings.tpl index 5ce48cb..b177f79 100644 --- a/template/settings.tpl +++ b/template/settings.tpl @@ -16,7 +16,7 @@ Log in with Twitter -

+

Log in with Mastodon

@@ -67,7 +67,7 @@

-
+

Connect with Telegram

If you have a Telegram account, you can register a bot there. Just write to @botfather. You can find detailed @@ -80,9 +80,9 @@ -

-
+

Edit your city page

With your bot, we generated you a page, which you can use for promotion:

-
+

Edit your trigger patterns

These words have to be contained in a report. @@ -110,7 +110,7 @@

-
+

Edit the blacklist

These words are not allowed in reports. From 44cd1308ba03a9909cc25dce48e4ce508fb0c948 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 24 Jun 2018 00:24:01 +0200 Subject: [PATCH 4/5] added development instructions to README --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++ static/css/style.css | 4 ++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index 1524707..c715c50 100644 --- a/README.md +++ b/README.md @@ -152,3 +152,50 @@ less /var/log/syslog # for the nginx web server: less /var/log/nginx/example.org_error.log ``` + +### Development Install + +If you want to install it locally to develop on it: + +```shell +sudo apt install python3 virtualenv uwsgi uwsgi-plugin-python3 nginx git +sudo git clone https://github.com/b3yond/ticketfrei +cd ticketfrei +``` + +Install the necessary packages, create and activate virtualenv: + +```shell +virtualenv -p python3 . +. bin/activate +``` + +Install the dependencies: + +```shell +pip install tweepy pytoml Mastodon.py bottle pyjwt pylibscrypt Markdown +``` + +Configure the bot: + +```shell +cp config.toml.example config.toml +vim config.toml +``` + +This configuration is only for the admin. Users can log into +twitter/mastodon/mail and configure their personal bot on the settings page. + +```shell +# create folder for socket & database +sudo mkdir /var/ticketfrei +sudo chown $USER:$USER -R /var/ticketfrei + +# create folder for logs +sudo mkdir /var/log/ticketfrei +sudo chown $USER:$USER -R /var/log/ticketfrei + +# start Ticketfrei +./frontend.py & ./backend.py & +``` + diff --git a/static/css/style.css b/static/css/style.css index 54590a4..3dc8126 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -41,3 +41,7 @@ input[type=text], input[type=password] { display: inline-block; border: 1px solid #ccc; } + +h2 { + padding-top: 1em; +} From fd8f236cddbd5377471f2b3e167b8763d0c1b3c1 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 24 Jun 2018 00:26:00 +0200 Subject: [PATCH 5/5] you need to checkout the multi-deployment branch, if you're actively developing --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c715c50..83c23e2 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ If you want to install it locally to develop on it: sudo apt install python3 virtualenv uwsgi uwsgi-plugin-python3 nginx git sudo git clone https://github.com/b3yond/ticketfrei cd ticketfrei +git checkout multi-deployment ``` Install the necessary packages, create and activate virtualenv: