diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7c1e5b0..045eb1c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -17,6 +17,9 @@ Steps to reproduce the behavior: 3. Scroll down to '....' 4. See error +**Ticketfrei Version** +See the commit on which Ticketfrei is running at example.org/version. + **Screenshots** If applicable, add screenshots to help explain your problem. diff --git a/LICENSE b/LICENSE index 6b24afd..2249ac4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ Copyright (c) 2017 Thomas L Copyright (c) 2017 b3yond -Copyright (c) 2018 sid +Copyright (c) 2018 sid Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/README.md b/README.md index 680285d..0a68e78 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ virtualenv -p python3 . Install the dependencies: ```shell -pip install tweepy pytoml Mastodon.py bottle pyjwt pylibscrypt Markdown twx +pip install tweepy pytoml Mastodon.py bottle pyjwt pylibscrypt Markdown twx gitpython ``` Configure the bot: diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py index 7c8fcb5..fbcd02b 100644 --- a/active_bots/mailbot.py +++ b/active_bots/mailbot.py @@ -19,7 +19,11 @@ class Mailbot(Bot): def crawl(self, user): reports = [] # todo: adjust to actual mailbox - mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user']) + try: + mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user']) + except FileNotFoundError: + logger.error("No mbox file found.") + return reports for msg in mails: if get_date_from_header(msg['Date']) > user.get_seen_mail(): if user.get_city().lower() in msg['To'].lower(): diff --git a/config.py b/config.py index fa01302..bc7baaf 100755 --- a/config.py +++ b/config.py @@ -1,5 +1,70 @@ import pytoml as toml +import os + + +def load_env(): + """ + load environment variables from the environment. If empty, use default + values from config.toml.example. + + :return: config dictionary of dictionaries. + """ + with open('config.toml.example') as defaultconf: + configdict = toml.load(defaultconf) + + try: + if os.environ['CONSUMER_KEY'] != "": + configdict['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] + except KeyError: + pass + + try: + if os.environ['CONSUMER_SECRET'] != "": + configdict['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET'] + except KeyError: + pass + + try: + if os.environ['HOST'] != "": + configdict['web']['host'] = os.environ['HOST'] + except KeyError: + pass + + try: + if os.environ['PORT'] != "": + configdict['web']['port'] = os.environ['PORT'] + except KeyError: + pass + + try: + if os.environ['CONTACT'] != "": + configdict['web']['contact'] = os.environ['CONTACT'] + except KeyError: + pass + + try: + if os.environ['MBOX_USER'] != "": + configdict['mail']['mbox_user'] = os.environ['MBOX_USER'] + except KeyError: + pass + + try: + if os.environ['DB_PATH'] != "": + configdict['database']['db_path'] = os.environ['DB_PATH'] + except KeyError: + pass + + return configdict + # read config in TOML format (https://github.com/toml-lang/toml#toml) -with open('config.toml') as configfile: - config = toml.load(configfile) +try: + with open('config.toml') as configfile: + config = toml.load(configfile) +except FileNotFoundError: + config = load_env() + +if __name__ == "__main__": + for category in config: + for key in config[category]: + print(key + "=" + str(config[category][key])) diff --git a/db.py b/db.py index 811d197..61100ae 100644 --- a/db.py +++ b/db.py @@ -14,7 +14,6 @@ class DB(object): self.conn = sqlite3.connect(dbfile) self.cur = self.conn.cursor() self.create() - self.secret = self.get_secret() def execute(self, *args, **kwargs): return self.cur.execute(*args, **kwargs) @@ -189,7 +188,7 @@ class DB(object): 'passhash': scrypt_mcf( password.encode('utf-8') ).decode('ascii') - }, self.secret).decode('ascii') + }, self.get_secret()).decode('ascii') def mail_subscription_token(self, email, city): """ @@ -203,17 +202,17 @@ class DB(object): token = jwt.encode({ 'email': email, 'city': city - }, self.secret).decode('ascii') + }, self.get_secret()).decode('ascii') return token def confirm_subscription(self, token): - json = jwt.decode(token, self.secret) + json = jwt.decode(token, self.get_secret()) return json['email'], json['city'] def confirm(self, token, city): from user import User try: - json = jwt.decode(token, self.secret) + json = jwt.decode(token, self.get_secret()) except jwt.DecodeError: return None # invalid token if 'passhash' in json.keys(): diff --git a/frontend.py b/frontend.py index 37144d3..452769f 100755 --- a/frontend.py +++ b/frontend.py @@ -56,11 +56,22 @@ def register_post(): @get('/confirm//') @view('template/propaganda.tpl') def confirm(city, token): + # check whether city already exists + if db.by_city(city): + return dict(error='This Account was already confirmed, please try ' + 'signing in.') # create db-entry if db.confirm(token, city): # :todo show info "Account creation successful." redirect('/settings') - return dict(error='Email confirmation failed.') + return dict(error='Account creation failed. Please try to register again.') + + +@get('/version') +def version(): + import git + repo = git.Repo(search_parent_directories=True) + return repo.head.object.hexsha @post('/login') @@ -259,7 +270,6 @@ application = bottle.default_app() bottle.install(SessionPlugin('/')) if __name__ == '__main__': - # testing only - bottle.run(host=config["web"]["host"], port=config["web"]["port"]) + bottle.run(host="0.0.0.0", port=config["web"]["port"]) else: application.catchall = False