Ejemplo n.º 1
0
def system_users():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    return listing(request, None, User.select(),
                   'system_users', 'system_manage_users',
                   user=user)
Ejemplo n.º 2
0
def system_sites(errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    return listing(request, None, Site.select(),
                   'all_sites', 'manage_sites',
                   user=user)
Ejemplo n.º 3
0
def system_queue():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    queue = Queue.select().order_by(Queue.site.asc(), Queue.blog.asc(),
                                    Queue.job_type.asc(),
                                    Queue.date_touched.desc())

    return listing(request, None, queue, 'queue', 'system_queue', user=user)
Ejemplo n.º 4
0
def site_info():
    '''
    Route for site installation information
    '''
    user = auth.is_logged_in(request)
    admin = auth.is_sys_admin(user)
    from core.ui import system
    return system.system_info()
Ejemplo n.º 5
0
def site_info():
    '''
    Route for site installation information
    '''
    user = auth.is_logged_in(request)
    admin = auth.is_sys_admin(user)
    from core.ui import system
    return system.system_info()
Ejemplo n.º 6
0
def system_log():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    log = Log.select().order_by(Log.date.desc(), Log.id.desc())

    return listing(request, None, log,
               'system_log', 'system_log',
               user=user)
Ejemplo n.º 7
0
def system_plugins(errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    plugins = Plugin.select()

    return listing(request, None, plugins,
                   'plugins', 'system_plugins',
                   user=user)
Ejemplo n.º 8
0
def system_list_themes():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    from core.models import Theme

    return listing(request, None, Theme.select().order_by(Theme.id),
                   'themes_site', 'system_manage_themes',
                   user=user,
                   )
Ejemplo n.º 9
0
def system_queue():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    queue = Queue.select().order_by(Queue.site.asc(), Queue.blog.asc(), Queue.job_type.asc(),
        Queue.date_touched.desc())

    return listing(request, None, queue,
               'queue', 'system_queue',
               user=user)
Ejemplo n.º 10
0
def system_users():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    return listing(request,
                   None,
                   User.select(),
                   'system_users',
                   'system_manage_users',
                   user=user)
Ejemplo n.º 11
0
def system_sites(errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    return listing(request,
                   None,
                   Site.select(),
                   'all_sites',
                   'manage_sites',
                   user=user)
Ejemplo n.º 12
0
def register_plugin(plugin_path):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    from core.plugins import register_plugin, PluginImportError
    try:
        new_plugin = register_plugin(plugin_path)
    except PluginImportError as e:
        return (str(e))
    return ("Plugin " + new_plugin.friendly_name + " registered.")
Ejemplo n.º 13
0
def register_plugin(plugin_path):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    from core.plugins import register_plugin, PluginImportError
    try:
        new_plugin = register_plugin(plugin_path)
    except PluginImportError as e:
        return (str(e))
    return ("Plugin " + new_plugin.friendly_name + " registered.")
Ejemplo n.º 14
0
def system_plugins(errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    plugins = Plugin.select()

    return listing(request,
                   None,
                   plugins,
                   'plugins',
                   'system_plugins',
                   user=user)
Ejemplo n.º 15
0
def system_theme_download(theme_id):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    from core.models import Theme
    theme = Theme.load(theme_id)

    import shutil, tempfile, os
    from core.libs.bottle import static_file
    with tempfile.TemporaryDirectory() as temp_zipdir:
        zip_filename = 'theme_{}'.format(theme.id)
        shutil.make_archive(os.path.join(temp_zipdir, zip_filename), 'zip', theme.path)
        return static_file('{}.zip'.format(zip_filename), root=temp_zipdir, download=True)
Ejemplo n.º 16
0
def system_list_themes():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    from core.models import Theme

    return listing(
        request,
        None,
        Theme.select().order_by(Theme.id),
        'themes_site',
        'system_manage_themes',
        user=user,
    )
Ejemplo n.º 17
0
def plugin_settings(plugin_id, errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    plugin = Plugin.get(Plugin.id == plugin_id)

    tags = template_tags(user=user)

    tpl = template('system/plugin',
                   plugin_ui=plugin.ui(),
                   search_context=(search_contexts['sites'], None),
                   menu=generate_menu('system_plugin_data', plugin),
                   **tags.__dict__)

    return tpl
Ejemplo n.º 18
0
def system_theme_download(theme_id):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    from core.models import Theme
    theme = Theme.load(theme_id)

    import shutil, tempfile, os
    from core.libs.bottle import static_file
    with tempfile.TemporaryDirectory() as temp_zipdir:
        zip_filename = 'theme_{}'.format(theme.id)
        shutil.make_archive(os.path.join(temp_zipdir, zip_filename), 'zip',
                            theme.path)
        return static_file('{}.zip'.format(zip_filename),
                           root=temp_zipdir,
                           download=True)
Ejemplo n.º 19
0
def plugin_settings(plugin_id, errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    plugin = Plugin.get(Plugin.id == plugin_id)

    tags = template_tags(
        user=user)

    tpl = template('system/plugin',
        plugin_ui=plugin.ui(),
        search_context=(search_contexts['sites'], None),
        menu=generate_menu('system_plugin_data', plugin),
        **tags.__dict__)

    return tpl
Ejemplo n.º 20
0
def system_theme_data(theme_id):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    from core.models import Theme
    theme = Theme.load(theme_id)

    tags = template_tags(user=user)

    tags.report = ['Theme title: {}'.format(theme.title),
        'Theme description: {}'.format(theme.description),
        'Theme directory: {}'.format(theme.json),
        '<hr>',
        '<a href="{}/download">Download an archive of this theme</a>'.format(theme.id)
        ]

    return report(tags, 'system_theme_data', theme)
Ejemplo n.º 21
0
def system_theme_data(theme_id):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    from core.models import Theme
    theme = Theme.load(theme_id)

    tags = template_tags(user=user)

    tags.report = [
        'Theme title: {}'.format(theme.title),
        'Theme description: {}'.format(theme.description),
        'Theme directory: {}'.format(theme.json), '<hr>',
        '<a href="{}/download">Download an archive of this theme</a>'.format(
            theme.id)
    ]

    return report(tags, 'system_theme_data', theme)
Ejemplo n.º 22
0
def system_info():

    # alt. implementation, less boilerplate?
    # user, permission = auth.is_sys_admin()

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    tags = template_tags(
        user=user)

    python_list = []
    environ_list = []
    settings_list = []

    # Generate interpreter info
    import os
    data = os.environ.__dict__['_data']
    for n in data:
        environ_list.append((n, data[n]))

    # List all settings variables
    import settings
    s_dict = settings.__dict__
    for n in s_dict:
        if n is not '__builtins__':
            settings_list.append((n, s_dict[n]))

    # List all plugins

    tpl = template('ui/ui_system_info',
        menu=generate_menu('system_info', None),
        search_context=(search_contexts['sites'], None),
        environ_list=sorted(environ_list),
        settings_list=sorted(settings_list),
        **tags.__dict__)

    return tpl
Ejemplo n.º 23
0
def system_info():

    # alt. implementation, less boilerplate?
    # user, permission = auth.is_sys_admin()

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    tags = template_tags(user=user)

    python_list = []
    environ_list = []
    settings_list = []

    # Generate interpreter info
    import os
    data = os.environ.__dict__['_data']
    for n in data:
        environ_list.append((n, data[n]))

    # List all settings variables
    import settings
    s_dict = settings.__dict__
    for n in s_dict:
        if n is not '__builtins__':
            settings_list.append((n, s_dict[n]))

    # List all plugins

    tpl = template('ui/ui_system_info',
                   menu=generate_menu('system_info', None),
                   search_context=(search_contexts['sites'], None),
                   environ_list=sorted(environ_list),
                   settings_list=sorted(settings_list),
                   **tags.__dict__)

    return tpl
Ejemplo n.º 24
0
def system_new_user():

    from core.models import db

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    nav_tabs = None
    status = None

    from core.models import User

    if request.method == 'POST':

        new_name = request.forms.getunicode('user_name')
        new_email = request.forms.getunicode('user_email')
        new_password = request.forms.getunicode('user_password')
        new_password_confirm = request.forms.getunicode(
            'user_password_confirm')

        from core.error import UserCreationError

        from core.libs import peewee

        # TODO: make this into a confirmation function a la what we did with blog settings

        new_user = User(name=new_name,
                        email=new_email,
                        password=new_password,
                        password_confirm=new_password_confirm)

        try:
            new_user.save_pwd()

        except UserCreationError as e:
            status = utils.Status(
                type='danger',
                no_sure=True,
                message='There were problems creating the new user:'******'danger',
                no_sure=True,
                message='There were problems creating the new user:'******'The new user\'s email or username is the same as another user\'s. Emails and usernames must be unique.'
                ])

        except Exception as e:
            raise e
        else:
            db.commit()
            from settings import BASE_URL
            return redirect(BASE_URL + '/system/user/{}'.format(new_user.id))

    else:
        new_user = User(name='', email='', password='')

    tags = template_tags(user=user)
    tags.status = status

    tpl = template('edit/user_settings',
                   edit_user=new_user,
                   menu=generate_menu('system_create_user', new_user),
                   search_context=(search_contexts['sites'], None),
                   nav_tabs=nav_tabs,
                   nav_default='basic',
                   **tags.__dict__)

    return tpl
Ejemplo n.º 25
0
def system_delete_theme(theme_id):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    # TODO: attach an installing user to the theme
    # allow that user to delete

    tags = template_tags(user=user)
    from core.models import Theme
    from settings import BASE_URL
    from core.utils import Status

    theme = Theme.load(theme_id)

    if request.forms.getunicode('confirm') == user.logout_nonce:

        from settings import THEME_FILE_PATH  # , _sep
        import shutil, os
        shutil.rmtree(os.path.join(THEME_FILE_PATH, theme.json))

        theme.delete_instance()

        status = Status(
            type='success',
            close=False,
            message='''
Theme <b>{}</b> was successfully deleted from the system.</p>
'''.format(theme.for_log),
            action='Return to theme list',
            url='{}/system/themes'.format(
                BASE_URL)
)

    else:

        m1 = '''You are about to remove theme <b>{}</b>. <b>THIS ACTION CANNOT BE UNDONE.</b></p>
'''.format(theme.for_display)
        blogs_with_theme = Blog.select().where(
            Blog.theme == theme_id)
        if blogs_with_theme.count() > 0:
            used_in = []
            for n in blogs_with_theme:
                used_in.append("<li>{}</li>".format(n.for_display))
            m2 = '''<p>This theme is in use by the following blogs:<ul>{}</ul>
Deleting this theme may <i>break these blogs entirely!</i></p>
'''.format(
                ''.join(used_in))
        else:
            m2 = ''

        status = Status(
            type='warning',
            close=False,
            message=m1 + m2,
            url='{}/system/theme/{}/delete'.format(
                BASE_URL, theme.id),
            yes={'id':'delete',
                'name':'confirm',
                'label':'Yes, I want to delete this theme',
                'value':user.logout_nonce},
            no={'label':'No, don\'t delete this theme',
                'url':'{}/system/themes'.format(
                BASE_URL)}
            )

    tags.status = status

    return report(tags, 'system_delete_theme', theme)
Ejemplo n.º 26
0
def system_new_user():

    from core.models import db

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    nav_tabs = None
    status = None

    from core.models import User

    if request.method == 'POST':

        new_name = request.forms.getunicode('user_name')
        new_email = request.forms.getunicode('user_email')
        new_password = request.forms.getunicode('user_password')
        new_password_confirm = request.forms.getunicode('user_password_confirm')

        from core.error import UserCreationError

        from core.libs import peewee

        # TODO: make this into a confirmation function a la what we did with blog settings

        new_user = User(
            name=new_name,
            email=new_email,
            password=new_password,
            password_confirm=new_password_confirm)

        try:
            new_user.save_pwd()

        except UserCreationError as e:
            status = utils.Status(
                type='danger',
                no_sure=True,
                message='There were problems creating the new user:'******'danger',
                no_sure=True,
                message='There were problems creating the new user:'******'The new user\'s email or username is the same as another user\'s. Emails and usernames must be unique.']
                )


        except Exception as e:
            raise e
        else:
            db.commit()
            from settings import BASE_URL
            return redirect(BASE_URL + '/system/user/{}'.format(new_user.id))

    else:
        new_user = User(name='',
            email='',
            password='')

    tags = template_tags(user=user)
    tags.status = status

    tpl = template('edit/user_settings',
        edit_user=new_user,
        menu=generate_menu('system_create_user', new_user),
        search_context=(search_contexts['sites'], None),
        nav_tabs=nav_tabs,
        nav_default='basic',
        **tags.__dict__
        )

    return tpl
Ejemplo n.º 27
0
def system_log():
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    log = Log.select().order_by(Log.date.desc(), Log.id.desc())

    return listing(request, None, log, 'system_log', 'system_log', user=user)
Ejemplo n.º 28
0
def system_delete_theme(theme_id):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    # TODO: attach an installing user to the theme
    # allow that user to delete

    tags = template_tags(user=user)
    from core.models import Theme
    from settings import BASE_URL
    from core.utils import Status

    theme = Theme.load(theme_id)

    if request.forms.getunicode('confirm') == user.logout_nonce:

        from settings import THEME_FILE_PATH  # , _sep
        import shutil, os
        shutil.rmtree(os.path.join(THEME_FILE_PATH, theme.json))

        theme.delete_instance()

        status = Status(type='success',
                        close=False,
                        message='''
Theme <b>{}</b> was successfully deleted from the system.</p>
'''.format(theme.for_log),
                        action='Return to theme list',
                        url='{}/system/themes'.format(BASE_URL))

    else:

        m1 = '''You are about to remove theme <b>{}</b>. <b>THIS ACTION CANNOT BE UNDONE.</b></p>
'''.format(theme.for_display)
        blogs_with_theme = Blog.select().where(Blog.theme == theme_id)
        if blogs_with_theme.count() > 0:
            used_in = []
            for n in blogs_with_theme:
                used_in.append("<li>{}</li>".format(n.for_display))
            m2 = '''<p>This theme is in use by the following blogs:<ul>{}</ul>
Deleting this theme may <i>break these blogs entirely!</i></p>
'''.format(''.join(used_in))
        else:
            m2 = ''

        status = Status(type='warning',
                        close=False,
                        message=m1 + m2,
                        url='{}/system/theme/{}/delete'.format(
                            BASE_URL, theme.id),
                        yes={
                            'id': 'delete',
                            'name': 'confirm',
                            'label': 'Yes, I want to delete this theme',
                            'value': user.logout_nonce
                        },
                        no={
                            'label': 'No, don\'t delete this theme',
                            'url': '{}/system/themes'.format(BASE_URL)
                        })

    tags.status = status

    return report(tags, 'system_delete_theme', theme)