Пример #1
0
def generate_image(text):
    width = config('width', 300)
    height = config('height', 150)
    extra_char = len(text) - config('increase_after_char', 10)
    if extra_char > 0:
        width += config('per_char_width', 10) * extra_char

    img = Image.new('RGB', (width, height), 'black')
    d = ImageDraw.Draw(img)
    font = ImageFont.truetype('assets/VarelaRound-Regular.ttf',
                              size=config('font_size', 40))
    d.text((width / 2, height / 2), text, anchor='mm', font=font)
    with io.BytesIO() as output:
        img.save(output, format='JPEG')
        return output.getvalue()
Пример #2
0
def create_app(config=None, debug=False, testing=False, config_overrides=None):
    app = Flask(__name__)
    CORS(app)

    app.debug = debug
    app.testing = testing

    if config_overrides:
        app.config.update(config_overrides)

    # Configuration
    with warnings.catch_warnings(record=True):
        application.config(config)

    # Add endpoints
    from app.endpoints.statuses import blueprint as statuses_bp

    app.register_blueprint(statuses_bp)

    return app
Пример #3
0
for handler_name in handlers.__all__:
    handler_module = importlib.import_module('handlers.'+handler_name)
    handler = getattr(handler_module, 'handler', None)
    if handler:
        # callback = handler.callback

        # def db_callback(**args):
        #     res = callback(**args)
        #     db.close()
        #     return res

        # handlers.callback = callback
        

        updater.dispatcher.add_handler(handler)

updater.dispatcher.add_error_handler(error_handler)

PORT = int(config('PORT', 5000))

if config('environment','dev') == 'dev':
    updater.start_polling()
else:
    updater.start_webhook(listen="0.0.0.0",
                          port=int(PORT),
                          url_path=config('token'))
    updater.bot.setWebhook(config('url') + config('token'))


updater.idle()
Пример #4
0
def seed():
    user = User.create(username=config('username'))
    logger.info('user seeded successfully')
    seed_words(user)
Пример #5
0
import paho.mqtt.client as mqtt
from db_connection import DBConnection
from app import config

db = DBConnection(config("postgresql"))


def on_message(client, userdata, message):
    pill_id = message.payload.decode("utf-8")
    pill_id = int(pill_id)
    if pill_id:
        dose, quantity = db.execute_query(
            "SELECT dose, quantity FROM pills WHERE id='{}';".format(
                pill_id))[0]
        new_quantity = quantity - dose
        db.execute("UPDATE pills SET quantity={0} WHERE id={1};".format(
            new_quantity, pill_id))


client = mqtt.Client("subscriber-taken")
client.on_message = on_message
client.connect("broker.hivemq.com")
client.subscribe("pillsTaken")
client.loop_forever()
Пример #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-v', help='increase output verbosity', dest='verbose', action='store_true')
    parser.add_argument('-t', help='enable multi tunnel', dest='multi_tunnel_enabled', action='store_true')
    parser.add_argument('-c', help='how many core running (min 1, max 16)', dest='core', type=int)
    parser.add_argument('-r', help='reset exported files (all, config, data, database)', dest='reset', type=str)
    parser.add_argument('-f', help='frontend domains, example: akamai.net,akamai.net:443', dest='frontend_domains', type=str)
    parser.add_argument('-w', help='whitelist requests, example: akamai.net,akamai.net:443', dest='whitelist_requests', type=str)
    arguments = parser.parse_args()

    app.banners()

    config = app.config()

    if arguments.reset is not None:
        app.log('Resetting Exported Files')
        config.reset(arguments.reset)
        app.log('Resetting Exported Files Complete\n'.format(arguments.reset))
        return

    if config.system_machine not in config.files_psiphon_tunnel_core:
        app.log('This machine ({}) not available at this time!\n'.format(config.system_machine), color='[R1]')
        return

    if config.system_machine in config.system_machine_using_redsocks and not config.user_is_superuser():
        app.log('Please run "sudo -s" first! (don\'t use "sudo python3 app.py"!)\n', color='[R1]')
        return

    config.load()

    if config.force_use_redsocks and not config.user_is_superuser():
        app.log('Please run "sudo -s" first! (don\'t use "sudo python3 app.py"!)\n', color='[R1]')
        return

    if arguments.multi_tunnel_enabled:
        config.multi_tunnel_enabled = True

    if arguments.whitelist_requests is not None:
        config.whitelist_requests = app.process_to_host_port(arguments.whitelist_requests.split(','))
        arguments.whitelist_requests = ''
        for host_port in config.whitelist_requests:
            arguments.whitelist_requests += ' {}:{},'.format(host_port[0], host_port[1])
        app.log('Whitelist Requests is set by arguments: {}'.format(arguments.whitelist_requests.strip().rstrip(',')))

    if arguments.frontend_domains is not None:
        config.frontend_domains = app.process_to_host_port(arguments.frontend_domains.split(','))
        arguments.frontend_domains = ''
        for host_port in config.frontend_domains:
            arguments.frontend_domains += ' {}:{},'.format(host_port[0], host_port[1])
        app.log('Frontend Domains is set by arguments: {}'.format(arguments.frontend_domains.strip().rstrip(',')))

    app.log('SOCKS5 Proxy Rotator running on port {}'.format(config.proxyrotator_port))
    app.log('Domain Fronting running on port {}'.format(config.domainfronting_port))

    app.proxyrotator(('0.0.0.0', config.proxyrotator_port), buffer_size=65535).start()

    redsocks = app.redsocks(config.redsocks_enabled)
    redsocks.start()
    
    for i in range(int(arguments.core if arguments.core is not None and arguments.core > 0 and arguments.core <= 16 else config.core)):
        port = 3081 + i
        app.psiphon(
            '{} -config storage/psiphon/{}/{}'.format(app.real_path(config.files_psiphon_tunnel_core[config.system_machine][1]), port, 'config-multi-tunnel.json' if config.multi_tunnel_enabled else 'config.json'),
            port, config.kuota_data_limit, config.multi_tunnel_enabled, arguments.verbose
        ).start()

    try:
        domainfronting = app.domainfronting(('127.0.0.1', config.domainfronting_port), app.domainfronting_handler)
        domainfronting.whitelist_requests = config.whitelist_requests
        domainfronting.frontend_domains = config.frontend_domains
        domainfronting.buffer_size = 65535
        domainfronting.redsocks = redsocks
        domainfronting.serve_forever()
    except OSError:
        app.psiphon_stop.append(1)
        redsocks.stop()
        app.log('Port {} used by another programs'.format(config.domainfronting_port), color='[R1]')
        app.log('Ctrl-C to exit')
    except KeyboardInterrupt:
        app.psiphon_stop.append(1)
        redsocks.stop()
        with app.lock:
            sys.stdout.write('      \r')
            sys.stdout.flush()
            app.log('Ctrl-C again to exit    ')
Пример #7
0
#!/usr/bin/env python3

from app import (config, router, totoro)

from flask import Flask

# Flask app + config
app = Flask(__name__, static_folder='app/static')
app.config['ENV'] = config('env')
app.config['DEBUG'] = False
app.config['SESSION_COOKIE_NAME'] = 'shellman'

# Define routes
router.define_routes(app)

# Start Totoro
if config('use_tor') and totoro().start():
    print('Totoro successfully started !')

# Start the webserver
app.run(port=config('port'))