Esempio n. 1
0
    def __init__(self, obj):
        locale = prism.settings.PRISM_CONFIG['locale']

        if isinstance(obj, BasePlugin):
            self.plugin_id = obj.plugin_id
            self.path = os.path.join(obj.plugin_folder, 'locale', locale)
        else:
            self.plugin_id = 'prism'
            self.path = os.path.join(obj, 'locale', locale)

        if not os.path.exists(self.path) and locale != 'en_US':
            locale = 'en_US'

            if isinstance(obj, BasePlugin):
                self.path = os.path.join(obj.plugin_folder, 'locale', 'en_US')
            else:
                self.path = os.path.join(obj, 'locale', 'en_US')

            logging.output(
                'Locale Warning: No locale for %s. Offender: %s falling back to en_US.'
                % (locale, self.plugin_id))

        if not os.path.exists(self.path):
            logging.output(
                'Locale Error: Failed to load locale. %s does not exist in %s. Offender: %s'
                % (locale, self.path, self.plugin_id))
            return

        with open(self.path) as f:
            for line in f:
                if '=' in line:
                    name, value = line.split('=', 1)
                    self.__dict__[name] = value.rstrip('\r\n')
Esempio n. 2
0
    def start(self, opts):
        logging.output('----------=\e[1mPrism\e[0m=----------')
        prism.settings.init(os.getpid())

        logging.up('Starting Prism')

        self.init_flask()
        self.jinja_options()
        self.init_flask_plugins()
        self.init_prism()

        prism.settings.post_init()

        self.start_http()

        return 0
Esempio n. 3
0
    def start_http(self):
        logging.output('Verifying SSL')
        has_ssl = False

        try:
            from OpenSSL import SSL
            has_ssl = True
        except ImportError:
            pass

        if has_ssl:
            ssl_crt = os.path.join(prism.settings.CONFIG_FOLDER,
                                   'prism-ssl.crt')
            ssl_key = os.path.join(prism.settings.CONFIG_FOLDER,
                                   'prism-ssl.key')

            ssl_files_exist = os.path.exists(ssl_crt)
            if ssl_files_exist:
                ssl_files_exist = os.path.exists(ssl_key)

            # Generate certificate
            if not ssl_files_exist:
                logging.up()

                logging.up('Generating SSL certificate')
                prism.settings.generate_certificate()
                logging.down()

                logging.down()

            if self.should_bind:
                # Finally, start Prism under a self-signed SSL connection
                self.flask_app.run(host='::',
                                   port=9000,
                                   threaded=True,
                                   debug=prism.settings.is_dev(),
                                   ssl_context=(ssl_crt, ssl_key))
        else:
            if self.should_bind:
                logging.error(
                    'Warning: Prism is starting under an insecure connection!')
                self.flask_app.run(host='::',
                                   port=9000,
                                   threaded=True,
                                   debug=prism.settings.is_dev())
Esempio n. 4
0
    def init(self, prism_state):
        self._available_widgets = {}
        self._widgets = self.config('widgets', {})

        # Search the plugins for Widget classes
        for plugin_id, plugin, name, obj in prism_state.plugin_manager.find_classes(
                Widget):
            widget = obj()
            widget.plugin_id = plugin.plugin_id
            widget.widget_id = plugin.plugin_id + '.' + widget.widget_id
            self._available_widgets[widget.widget_id] = widget

            if widget.widget_id not in self._widgets:
                self._widgets[widget.widget_id] = {
                    'shown': True,
                    'order': len(self._available_widgets)
                }

        logging.output('Registered %s widgets' % len(self._available_widgets))
        prism.flask_app(
        ).jinja_env.globals["render_widget"] = self.render_widget
Esempio n. 5
0
    def __init__(self, obj=None, filename=None, path=None, auto_save=True):
        if obj is not None:
            if filename is None:
                filename = 'config.json'

            if isinstance(obj, BasePlugin):
                self.path = os.path.join(obj.data_folder, filename)
            else:
                self.path = os.path.join(obj, filename)
        elif path is not None:
            self.path = path
        else:
            logging.output(
                'Error: Attmpted to create a config file with no path.')

        self.auto_save = auto_save

        if not os.path.exists(self.path):
            self.__dict__.update({})
        else:
            self.__dict__.update(json.loads(open(self.path).read()))
Esempio n. 6
0
def init(pid):
	global PANEL_PID, PRISM_PATH, TMP_PATH, PRISM_VERSIONING, CORE_PLUGINS_PATH, \
			PLUGINS_PATH, CONFIG_FOLDER_PLUGINS, CONFIG_FOLDER, PRISM_CONFIG, PRISM_LOCALE

	PANEL_PID = pid
	PRISM_PATH = os.path.dirname(os.path.realpath(__file__))

	CORE_PLUGINS_PATH = os.path.join(PRISM_PATH, 'core')
	if not os.path.exists(CORE_PLUGINS_PATH):
		os.makedirs(CORE_PLUGINS_PATH)

	PLUGINS_PATH = os.path.join(PRISM_PATH, 'plugins')
	if not os.path.exists(PLUGINS_PATH):
		os.makedirs(PLUGINS_PATH)

	TMP_PATH = os.path.join(PRISM_PATH, 'tmp')
	if not os.path.exists(TMP_PATH):
		os.makedirs(TMP_PATH)

	logging.info('Currently running in %s' % PRISM_PATH)
	logging.output()

	PRISM_VERSIONING = JSONConfig(path=os.path.join(TMP_PATH, 'VERSIONING-INFO'))

	# Load Prism's config
	CONFIG_FOLDER = os.path.join(PRISM_PATH, 'config')
	if not os.path.exists(CONFIG_FOLDER):
		os.makedirs(CONFIG_FOLDER)
	config_file = os.path.join(CONFIG_FOLDER, 'config.json')

	CONFIG_FOLDER_PLUGINS = os.path.join(CONFIG_FOLDER, 'plugins')
	if not os.path.exists(CONFIG_FOLDER_PLUGINS):
		os.makedirs(CONFIG_FOLDER_PLUGINS)

	PRISM_LOCALE = LocaleConfig(PRISM_PATH)

	# Generate default config values if the file doesn't exist
	# Also, prompt and generate a few of the config values that
	# must be done on first run.
	if not os.path.exists(config_file):
		# I have no idea what came over me when making this section,
		# but it's fabulous and I loved every second of it. I hope
		# I never have to change it. xD
		logging.output(PRISM_LOCALE['start.hello.1'])
		logging.output(PRISM_LOCALE['start.hello.2'])
		subst = {}

		# IP Address/Hostname prompt
		subst['host'] = socket.gethostbyname(socket.gethostname())
		logging.output(PRISM_LOCALE['start.host'].format(**subst))
		PRISM_CONFIG['host'], used_default = prism.get_input(PRISM_LOCALE['start.host.prompt'], default=subst['host'])

		if used_default:
			logging.output()
			logging.output(PRISM_LOCALE['start.host.correct'])

		# Secret generation
		logging.output()
		logging.output(PRISM_LOCALE['start.secret'])
		subst['secret_key'], used_default = prism.get_input(PRISM_LOCALE['start.secret.prompt'])

		logging.output()
		if used_default:
			subst['secret_key'] = prism.generate_random_string(32)
			logging.output(PRISM_LOCALE['start.secret.generate'].format(**subst))
		else:
			logging.output(PRISM_LOCALE['start.secret.done'].format(**subst))

		PRISM_CONFIG['secret_key'] = subst['secret_key']

		# Dev check
		logging.output()
		logging.output(PRISM_LOCALE['start.dev_mode'])
		PRISM_CONFIG['dev_mode'] = prism.get_yesno(PRISM_LOCALE['start.dev_mode.prompt'])

		logging.output()
		logging.output(PRISM_LOCALE['start.done'])
		logging.output()

		conf = JSONConfig(path=config_file)
		for key, value in PRISM_CONFIG.items():
			conf[key] = value
		PRISM_CONFIG = conf
	else:
		# Load prism's config
		PRISM_CONFIG = JSONConfig(path=config_file)

		if 'locale' not in PRISM_CONFIG:
			PRISM_CONFIG['locale'] = 'en_US'

		if 'enabled_plugins' not in PRISM_CONFIG:
			PRISM_CONFIG['enabled_plugins'] = [F]

		# Make sure some VERY imporant values are set
		if 'secret_key' not in PRISM_CONFIG:
			logging.output(PRISM_LOCALE['start.missing.secret'])
			PRISM_CONFIG['secret_key'] = prism.generate_random_string(32)
			logging.output()

		if 'host' not in PRISM_CONFIG:
			host = socket.gethostbyname(socket.gethostname())
			logging.output(PRISM_LOCALE['start.missing.host'])
			PRISM_CONFIG['host'], used_default = prism.get_input(PRISM_LOCALE['start.host.prompt'], default=host)
			logging.output()
Esempio n. 7
0
def post_init():
	try:
		pwd.getpwnam('prism')
	except KeyError:
		import crypt
		passwd = crypt.crypt(PRISM_CONFIG['secret_key'], "22")
		prism.os_command("useradd -p " + passwd + " -s /bin/bash -d /home/prism -m -c PrismCP prism")

	import prism.login as prism_login
	if prism_login.User.query.count() == 0:
		logging.output()

		# Username and Password prompt
		logging.output(PRISM_LOCALE['start.login.username'])
		username, used_default = prism.get_input(PRISM_LOCALE['start.login.username.prompt'], default='admin')
		password, used_default = prism.get_password(PRISM_LOCALE['start.login.password.prompt'], default='password')

		if used_default:
			logging.output()

			logging.output(PRISM_LOCALE['start.login.password.default.1'])
			time.sleep(2)
			logging.output(PRISM_LOCALE['start.login.password.default.2'])
			time.sleep(5)
			logging.output(PRISM_LOCALE['start.login.password.default.3'])

		logging.output()
		prism_login.create_user(username, password, username.capitalize(), 'Main Administrator', ['*'])
Esempio n. 8
0
 def init_flask(self):
     logging.output('Initializing Flask')
     self.flask_app = Flask(__name__, template_folder='templates')
     self.flask_app.secret_key = prism.settings.PRISM_CONFIG['secret_key']