summaryrefslogtreecommitdiff
path: root/service/pixelated/runserver.py
diff options
context:
space:
mode:
Diffstat (limited to 'service/pixelated/runserver.py')
-rw-r--r--service/pixelated/runserver.py123
1 files changed, 2 insertions, 121 deletions
diff --git a/service/pixelated/runserver.py b/service/pixelated/runserver.py
index e3cef396..7b0a3b4f 100644
--- a/service/pixelated/runserver.py
+++ b/service/pixelated/runserver.py
@@ -14,127 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-import sys
-import logging
-import json
-
-import os
-
-import ConfigParser
-from twisted.python import log
-from leap.common.events import server as events_server
-from pixelated.config import app_factory
-import pixelated.config.args as input_args
-import pixelated.bitmask_libraries.register as leap_register
-from pixelated.bitmask_libraries.leap_srp import LeapAuthException
-import pixelated.config.credentials_prompt as credentials_prompt
-import pixelated.support.ext_protobuf # monkey patch for protobuf in OSX
-import pixelated.support.ext_sqlcipher # monkey patch for sqlcipher in debian
-
-
-class App:
-
- def __init__(self):
- self.resource = None
- self.config = None
- pass
-
-app = App()
-app.config = {}
-
-
-def setup_leap_cert(leap_cert):
- import pixelated.bitmask_libraries.certs as certs
- certs.LEAP_CERT = leap_cert
-
-
-def setup():
- args = input_args.parse()
- setup_leap_cert(args.leap_cert)
- setup_debugger(args.debug)
-
- if args.register:
- register(*args.register[::-1])
- else:
- if args.dispatcher:
- config = fetch_credentials_from_dispatcher(args.dispatcher)
- app.config['LEAP_SERVER_NAME'] = config['leap_provider_hostname']
- app.config['LEAP_USERNAME'] = config['user']
- app.config['LEAP_PASSWORD'] = config['password']
- elif args.dispatcher_stdin:
- config = fetch_credentials_from_dispatcher_stdin()
- app.config['LEAP_SERVER_NAME'] = config['leap_provider_hostname']
- app.config['LEAP_USERNAME'] = config['user']
- app.config['LEAP_PASSWORD'] = config['password']
- else:
- configuration_setup(args.config)
- start_services(args)
-
-
-def register(username, server_name):
- try:
- leap_register.register_new_user(username, server_name)
- except LeapAuthException:
- print('User already exists')
-
-
-def fetch_credentials_from_dispatcher(filename):
- if not os.path.exists(filename):
- print('The credentials pipe doesn\'t exist')
- sys.exit(1)
- with open(filename, 'r') as fifo:
- return json.loads(fifo.read())
-
-
-def fetch_credentials_from_dispatcher_stdin():
- return json.loads(sys.stdin.read())
-
-
-def setup_debugger(enabled):
- debug_enabled = enabled or os.environ.get('DEBUG', False)
- log.startLogging(sys.stdout)
-
- if debug_enabled:
- logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
- datefmt='%m-%d %H:%M',
- filename='/tmp/leap.log',
- filemode='w') # define a Handler which writes INFO messages or higher to the sys.stderr
-
- console = logging.StreamHandler()
- console.setLevel(logging.DEBUG)
- formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
- console.setFormatter(formatter)
- logging.getLogger('').addHandler(console)
-
- return debug_enabled
-
-
-def parse_config_from_file(config_file):
- config_parser = ConfigParser.ConfigParser()
- config_file = os.path.abspath(os.path.expanduser(config_file))
- config_parser.read(config_file)
- provider, user, password = \
- config_parser.get('pixelated', 'leap_server_name'), \
- config_parser.get('pixelated', 'leap_username'), \
- config_parser.get('pixelated', 'leap_password')
-
- # TODO: add error messages in case one of the parameters are empty
- return provider, user, password
-
-
-def configuration_setup(config_file):
- provider, user, password = parse_config_from_file(config_file) if config_file else credentials_prompt.run()
-
- app.config['LEAP_SERVER_NAME'] = provider
- app.config['LEAP_USERNAME'] = user
- app.config['LEAP_PASSWORD'] = password
-
-
-def start_services(args):
- events_server.ensure_server(port=8090)
- app_factory.create_app(app, args)
+from config import initialize
if __name__ == '__main__':
- setup()
+ initialize()