forked from ticketfrei/ticketfrei
Merge branch 'multi-deployment' of https://github.com/b3yond/ticketfrei into multi-deployment
This commit is contained in:
commit
02a6e0509b
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -17,3 +17,4 @@ include/
|
||||||
lib/
|
lib/
|
||||||
share/
|
share/
|
||||||
local/
|
local/
|
||||||
|
venv/
|
||||||
|
|
53
README.md
53
README.md
|
@ -118,9 +118,12 @@ echo "Enter your domain name into the following prompt:" && read DOMAIN
|
||||||
# configure nginx
|
# configure nginx
|
||||||
sudo sed -r "s/example.org/$DOMAIN/g" deployment/example.org.conf > /etc/nginx/sites-enabled/$DOMAIN.conf
|
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 mkdir /var/ticketfrei
|
||||||
sudo chown www-data:www-data -R /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
|
sudo chown www-data:www-data -R /var/log/ticketfrei
|
||||||
|
|
||||||
# start up nginx
|
# start up nginx
|
||||||
|
@ -149,3 +152,51 @@ less /var/log/syslog
|
||||||
# for the nginx web server:
|
# for the nginx web server:
|
||||||
less /var/log/nginx/example.org_error.log
|
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
9
db.py
|
@ -90,6 +90,13 @@ class DB(object):
|
||||||
active INTEGER,
|
active INTEGER,
|
||||||
FOREIGN KEY(user_id) REFERENCES user(id)
|
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 (
|
CREATE TABLE IF NOT EXISTS seen_tweets (
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
user_id INTEGER,
|
user_id INTEGER,
|
||||||
|
@ -173,6 +180,8 @@ u\d\d?
|
||||||
uid = json['uid']
|
uid = json['uid']
|
||||||
self.execute("INSERT INTO email (user_id, email) VALUES(?, ?);",
|
self.execute("INSERT INTO email (user_id, email) VALUES(?, ?);",
|
||||||
(uid, json['email']))
|
(uid, json['email']))
|
||||||
|
self.execute("""INSERT INTO telegram_accounts (user_id, apikey,
|
||||||
|
active) VALUES(?, ?, ?);""", (uid, "", 1))
|
||||||
self.commit()
|
self.commit()
|
||||||
user = User(uid)
|
user = User(uid)
|
||||||
user.set_city(city)
|
user.set_city(city)
|
||||||
|
|
|
@ -114,6 +114,14 @@ def update_badwords(user):
|
||||||
return user.state()
|
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')
|
@get('/api/state')
|
||||||
def api_enable(user):
|
def api_enable(user):
|
||||||
return user.state()
|
return user.state()
|
||||||
|
|
|
@ -41,3 +41,7 @@ input[type=text], input[type=password] {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
padding-top: 1em;
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
Log in with Twitter
|
Log in with Twitter
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<section style="padding: 1.5em;">
|
<section>
|
||||||
<h2>Log in with Mastodon</h2>
|
<h2>Log in with Mastodon</h2>
|
||||||
<p>
|
<p>
|
||||||
<form action="/login/mastodon" method='post'>
|
<form action="/login/mastodon" method='post'>
|
||||||
|
@ -67,7 +67,22 @@
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</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>
|
<h2>Edit your city page</h2>
|
||||||
<p>
|
<p>
|
||||||
With your bot, we generated you a page, which you can use for promotion: <a href="/city/{{city}}"
|
With your bot, we generated you a page, which you can use for promotion: <a href="/city/{{city}}"
|
||||||
|
@ -81,7 +96,7 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="float: left; padding: 1.5em;">
|
<div>
|
||||||
<h2>Edit your trigger patterns</h2>
|
<h2>Edit your trigger patterns</h2>
|
||||||
<p>
|
<p>
|
||||||
These words have to be contained in a report.
|
These words have to be contained in a report.
|
||||||
|
@ -95,7 +110,7 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="float:right; padding: 1.5em;">
|
<div>
|
||||||
<h2>Edit the blacklist</h2>
|
<h2>Edit the blacklist</h2>
|
||||||
<p>
|
<p>
|
||||||
These words are not allowed in reports.
|
These words are not allowed in reports.
|
||||||
|
|
4
user.py
4
user.py
|
@ -205,6 +205,10 @@ schlitz
|
||||||
(self.uid, ))
|
(self.uid, ))
|
||||||
return db.cur.fetchall()
|
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):
|
def get_mastodon_app_keys(self, instance):
|
||||||
db.execute("SELECT client_id, client_secret FROM mastodon_instances WHERE instance = ?;", (instance, ))
|
db.execute("SELECT client_id, client_secret FROM mastodon_instances WHERE instance = ?;", (instance, ))
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue