Merge branch 'multi-deployment' of https://github.com/b3yond/ticketfrei into multi-deployment

This commit is contained in:
b3yond 2018-06-25 21:13:47 +02:00
commit 8dfffffe76
7 changed files with 97 additions and 5 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ include/
lib/
share/
local/
venv/

View file

@ -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
@ -149,3 +152,51 @@ 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
git checkout multi-deployment
```
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 &
```

9
db.py
View file

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

View file

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

View file

@ -41,3 +41,7 @@ input[type=text], input[type=password] {
display: inline-block;
border: 1px solid #ccc;
}
h2 {
padding-top: 1em;
}

View file

@ -16,7 +16,7 @@
Log in with Twitter
</a>
<section style="padding: 1.5em;">
<section>
<h2>Log in with Mastodon</h2>
<p>
<form action="/login/mastodon" method='post'>
@ -67,7 +67,22 @@
</p>
</section>
<div style="float: left; padding: 1.5em;">
<div>
<h2>Connect with Telegram</h2>
<p>
If you have a Telegram account, you can register a bot there. Just write to @botfather. You can find detailed
instructions <a href="https://botsfortelegram.com/project/the-bot-father/" target="_blank">on Bots for
Telegram</a>.
</p>
<p>
The botfather will give you an API key - with the API key, Ticketfrei can use the Telegram bot. Enter it here:
</p>
<form action="/settings/telegram" method="post">
<input type="text" name="apikey" placeholder="Telegram bot API key" id="apikey" required>
<input name='confirm' value='Login with Telegram' type='submit'/>
</div>
<div>
<h2>Edit your city page</h2>
<p>
With your bot, we generated you a page, which you can use for promotion: <a href="/city/{{city}}"
@ -81,7 +96,7 @@
</form>
</div>
<div style="float: left; padding: 1.5em;">
<div>
<h2>Edit your trigger patterns</h2>
<p>
These words have to be contained in a report.
@ -95,7 +110,7 @@
</form>
</div>
<div style="float:right; padding: 1.5em;">
<div>
<h2>Edit the blacklist</h2>
<p>
These words are not allowed in reports.

View file

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