Ejemplo n.º 1
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # init workflow
    wf = tools.get("wf", 'comment_edit')
    p['workflow'] = workflow.init(wf, host, index)

    # load comment
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # comment_id
    comment_id = tools.get("id")
    p['comment'] = next((x for x in p['post']['comment'] if x['id'] == comment_id), None)
    if not p['comment']:
        return tools.alert('not valid comment_id - {}'.format(comment_id))

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['name']] = field['id']

    # update comment
    p['comment']['updated'] = es.now()
    p['comment']['updated_by'] = p['login']
    p['comment']['comment'] = tools.get("comment")

    es.update(host, index, 'post', post_id, p['post'])
    es.flush(host, index)

    return tools.redirect(request.referrer)
Ejemplo n.º 2
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load notification
    notification_id = p['nav'][-1]
    p['notification'] = es.get(host, index, 'notification', notification_id)
    if not p['notification']:
        return tools.alert(
            'not valid notification id - {}'.format(notification_id))

    # save notification
    if request.method == "POST":
        doc = {
            'header': tools.get('header'),
            'message': tools.get('message'),
            'recipients': tools.get('recipients'),
            'condition': tools.get('condition'),
            'workflow': tools.get('workflow')
        }
        es.update(host, index, 'notification', notification_id, doc)
        es.flush(host, index)

        return tools.redirect("{}/notification/edit/{}".format(
            p['url'], notification_id))

    return render_template("post/notification/edit.html", p=p)
Ejemplo n.º 3
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # init workflow
    wf = tools.get("wf", 'comment')
    p['workflow'] = workflow.init(wf, host, index)

    # for workflow actions
    p["post"] = es.get(host, index, 'post', tools.get("post_id"))
    if not p["post"]:
        return tools.alert('post id is not valid- {}'.format(
            tools.get("post_id")))

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec(p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit:
            pass
        except Exception, e:
            return "{}\n{}".format(e.message, traceback.format_exc())
Ejemplo n.º 4
0
def get(p):
    index = tools.get('index')
    id = tools.get('id')
    if not index or not id:
        return tools.alert('invalid id or index')

    # find config with matching index
    configs = es.list(p['host'], 'core_nav', 'config',
        "name:'index' AND value:'{}'".format(index))
    if not len(configs) > 0:
        return tools.alert('site not found')

    # get site id
    navigation_id = configs[0]['id'].split('_')[0]
    navigation = es.get(p['host'], 'core_nav', 'navigation', navigation_id)
    site = es.get(p['host'], 'core_nav', 'site', navigation['site_id'])

    # form url
    url = '{}/{}'.format(site.get('name'), navigation.get('name'))
    url = "{}/post/view/{}".format(url, id)
    # when navigation or site is empty then it contains double slash 
    url = url.replace("//", "/")
    url = urlparse.urljoin(request.url_root, url)

    return tools.redirect(url)
Ejemplo n.º 5
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load comment
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # comment_id
    comment_id = tools.get("id")
    p['comment'] = next(
        (x for x in p['post']['comment'] if x['id'] == comment_id), {})
    if not p['comment']:
        return tools.alert('not valid comment_id - {}'.format(comment_id))

    # init workflow
    wf = tools.get('wf', 'comment_delete')
    p['workflow'] = workflow.init(wf, host, index)

    # remove comment
    p['post']['comment'].remove(p['comment'])

    es.update(host, index, 'post', post_id, p['post'])
    es.flush(host, index)

    return tools.redirect(request.referrer)
Ejemplo n.º 6
0
def post(p):

    # get login Process
    login_modules = get_login_modules(p)

    # try all login process until succeeds
    for login in login_modules:
        # find which auth module to use
        path = "web.modules.auth.services.{}".format(
            tools.get_conf(p['host'], '-1', 'auth', 'LDAP'))
        mod = importlib.import_module(path)
        if mod.authenticate(login['configuration'], tools.get('login'),
                            tools.get('password')):

            # when authentication is successful

            # remember me
            if tools.get('remember'):
                # session will live for 31 days
                session.permanent = True
            else:
                session.permanent = False

            # save user_id in session
            session['user'] = tools.get('login')

            return tools.redirect(get_return_url())

    # ending up here means login failed
    p['message'] = "Login Failed. Check your login name and password."
    return render_template("auth/default.html", p=p)
Ejemplo n.º 7
0
def get(p):
    if p['c']['intro'] and not tools.get('q'):
        return render_template(app.jinja_env.from_string(p['c']['intro']), p=p)

    host = p['c']['host']
    index = p['c']['index']
    # debug
    p['debug'] = tools.get('debug', '')
    # search keyword
    p["q"] = tools.get('q', p['c']['query'])
    # pagination
    p["from"] = int(tools.get('from', 0))
    p["size"] = int(tools.get('size', p['c']['page_size']))
    # sort
    p['sort_field'] = tools.get('sort_field', p['c']['sort_field'])
    p['sort_dir'] = tools.get('sort_dir', p['c']['sort_dir'])

    # fields
    p['fields'] = tools.get('fields')

    # init workflow
    wf = tools.get('wf', 'search')
    p['workflow'] = workflow.init(wf, host, index)

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec(p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit:
            pass
        except Exception, e:
            raise
Ejemplo n.º 8
0
def get(p):

    es.create(p['host'], 'core_task', 'task', '', {
        'navigation_id': p['navigation']['id'],
        'name': tools.get('name'),
        'runat': tools.get('runat', 'anywhere'),
        'description': tools.get('description')
    })
    es.flush(p['host'], 'core_task')

    return tools.redirect(request.referrer)
Ejemplo n.º 9
0
def get(p):
    # url shall exist
    if not tools.get('url'): return tools.alert("url is missing")

    # create new reverse proxy rule
    doc = {
        'url': tools.get('url')
    }
    es.create(p['host'], 'core_proxy', 'public', '', doc)
    es.flush(p['host'], 'core_proxy')

    return tools.redirect(request.referrer)
Ejemplo n.º 10
0
def get(p):
    # Save Email Configuration
    if request.method == "POST":
        set_conf(p['host'], {
            'gmail_id': tools.get('gmail_id'),
            'gmail_pw': tools.get('gmail_pw')
        })
        return tools.redirect(request.referrer)

    # Display Email Configuration
    p['conf'] = get_conf(p['host'])
    return render_template("admin/email/default.html", p=p)
Ejemplo n.º 11
0
def get(p):
    # get data source list
    query = 'navigation_id:{}'.format(p['navigation']['id'])
    option = 'size=10000'
    p['ds_list'] = es.list(p['host'], 'core_data', 'datasource', query, option)

    p['ds'] = {}
    if tools.get('id'):
        p['ds'] = es.get(p['host'], 'core_data', 'datasource', tools.get('id'))
    if not p['ds'] and len(p['ds_list']):
        p['ds'] = p['ds_list'][0]

    return render_template("dataservice/default.html", p=p)
Ejemplo n.º 12
0
def get(p):

    # create new site
    site = {
        'order_key': tools.get('order_key'),
        'name': tools.get('name'),
        'display_name': tools.get('display_name'),
        'description': tools.get('description')
    }
    es.create(p['host'], 'core_nav', 'site', '', site)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Ejemplo n.º 13
0
def get(p):
    # create new login module
    doc = {
        "type": tools.get('type'),
        "name": tools.get('name'),
        "description": tools.get('description'),
        "priority": tools.get('priority'),
        "configuration": tools.get('configuration')
    }
    es.create(p['host'], 'core_nav', 'login_module', '', doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Ejemplo n.º 14
0
def get(p):
    # load instance
    instance_id = p['nav'][-1]
    p['instance'] = es.get(p['host'], 'core_task', 'instance', instance_id)
    if not p['instance']:
        return tools.alert('invalid instance id - {}'.format(instance_id))

    # Search Keyword
    search_keyword = tools.get("search[value]") + "*"

    # Length of the result
    length = tools.get("length")
    if not length: length = 10

    # Offset of the result
    start = tools.get("start")
    if not start: start = 0

    # draw
    draw = tools.get("draw")
    if not draw: draw = 0

    # Apply Search Keyword
    query = "instance_id:{} AND {}".format(instance_id, search_keyword)

    option = 'from={}&size={}&sort=created:desc'.format(start, length)
    # search results
    search_result = es.list(p['host'], 'core_task', 'log', query, option)

    # Get Total number of records
    total = es.count(p['host'], 'core_task', 'log')
    filter_total = es.count(p['host'], 'core_task', 'log', query)

    # Form header
    DataTableJson = {}
    DataTableJson = {
        # draw - this is handshake id which maps the request - response async maps from JS
        "draw":
        int(draw),
        "recordsTotal":
        total,
        "recordsFiltered":
        filter_total,
        "data":
        [[log['action'], log['message'], log['status'], log['created']]
         for log in search_result]
    }

    # Return in JSON format
    return json.dumps(DataTableJson)
Ejemplo n.º 15
0
def post(p):
    host = p['c']['host']
    index = p['c']['index']

    # get all submitted fields
    p['post'] = {}
    p['original'] = {}
    for field in request.form:
        field_info = p['field_map'][field]
        value = tools.get(field)
        # if object then convert to json object
        if field_info['handler'] == "object":
            if value:
                p["post"][field_info['id']] = json.loads(value)
        elif value:
            p["post"][field_info['id']] = value

    ######################################################
    # validate
    if p['workflow'] and p['workflow'].get('validation'):
        try:
            exec(p['workflow']['validation'], globals())
            ret = validation(p)
            if ret != True and ret: return ret
        except SystemExit:
            pass
        except Exception, e:
            raise
Ejemplo n.º 16
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # send out empty post to be compatible with edit form
    p['post'] = {}

    # init workflow
    wf = tools.get("wf", 'create')
    p['workflow'] = workflow.init(wf, host, index)

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['id']] = field

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec(p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit:
            pass
        except Exception, e:
            raise
Ejemplo n.º 17
0
def get(p):
    # check if site_id is passed
    p['site_id'] = tools.get('site_id')
    if not p['site_id']: return tools.alert('site id is missing')

    if request.method == "POST":
        # save custom navigation
        p['site'] = {'navigation': tools.get('navigation')}
        es.update(p['host'], 'core_nav', 'site', p['site_id'], p['site'])
        es.flush(p['host'], 'core_nav')

    # load site
    p['site'] = es.get(p['host'], 'core_nav', 'site', p['site_id'])
    if not p['site']: return tools.alert('site id is not valid')

    return render_template("admin/customize/default.html", p=p)
Ejemplo n.º 18
0
def get(p):
    id = tools.get('id')
    # delete
    es.delete(p['host'], 'core_data', 'datasource', id)
    es.flush(p['host'], 'core_data')

    return tools.redirect(request.referrer)
Ejemplo n.º 19
0
def get(p):
    # get list of roles
    query = "site_id:{}".format(p['site']['id'])
    option = "size=10000&sort=name:asc"
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    # selected role
    role_id = p['nav'][-1]
    p['role'] = es.get(p['host'], 'core_nav', 'role', role_id)
    if not p['role']:
        p['role'] = p['role_list'][0]

    # get permission
    permission_id = "{}_{}".format(p['role']['id'], p['navigation']['id'])
    p['permission'] = es.get(p['host'], 'core_nav', 'permission', permission_id)

    if request.method == "POST":
        doc = { "operations": [x for x in tools.get('operations', []) if x] }

        if not p['permission']:
            # create permission
            es.create(p['host'], 'core_nav', 'permission', permission_id, doc)
        else:
            # edit permission
            es.update(p['host'], 'core_nav', 'permission', permission_id, doc)
        es.flush(p['host'], 'core_nav')

        return tools.redirect(request.referrer)


    return render_template("post/permission/default.html", p=p)
Ejemplo n.º 20
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # load post
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    p['original'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # init workflow
    wf = tools.get('wf', 'edit')
    p['workflow'] = workflow.init(wf, host, index)

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['id']] = field

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec (p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit: pass
        except Exception, e:
            raise
Ejemplo n.º 21
0
def set(p):
    # get host and index from the global config
    h = tools.get_conf(p['host'], p['navigation']['id'], 'host',
                       'http://localhost:9200')
    n = tools.get_conf(p['host'], p['navigation']['id'], 'index', '')

    set_conf(h, n, 'name', tools.get('name'))
    set_conf(h, n, 'description', tools.get('description'))
    set_conf(h, n, 'upload_dir', tools.get('upload_dir'))
    set_conf(h, n, 'allowed_exts', tools.get('allowed_exts'))
    set_conf(h, n, 'page_size', tools.get('page_size'))
    set_conf(h, n, 'query', tools.get('query'))
    set_conf(h, n, 'sort_field', tools.get('sort_field'))
    set_conf(h, n, 'sort_dir', tools.get('sort_dir'))
    set_conf(h, n, 'keep_history', tools.get('keep_history'))
Ejemplo n.º 22
0
def get(p):
    # load rule
    rev_proxy_id = p['nav'][-1]
    rev_proxy = es.get(p['host'], 'core_proxy', 'rev_proxy', rev_proxy_id)
    if not rev_proxy:
        return tools.alert('not valid rev_proxy id - {}'.format(rev_proxy_id))


    # edit role
    doc = {
        'inc_url': tools.get('inc_url'),
        'out_url': tools.get('out_url'),
        'auth_method': tools.get('auth_method'),
        'header': tools.get('header')
    }
    es.update(p['host'], 'core_proxy', 'rev_proxy', rev_proxy_id, doc)
    es.flush(p['host'], 'core_proxy')

    return tools.redirect(request.referrer)
Ejemplo n.º 23
0
def get_return_url():
    url = tools.get('url')
    # try to go to the previous page
    if not url: url = request.referrer
    # if the previous page is auth then go to root
    if url and url.endswith('/auth'): url = '/'
    # if there is no previous page then go to root site
    if not url: url = '/'

    return url
Ejemplo n.º 24
0
def get(p):
    # load site
    site_id = p['nav'][-1]
    p['site'] = es.get(p['host'], 'core_nav', 'site', site_id)
    if not p['site']:
        return tools.alert('not valid site id - {}'.format(site_id))

    # update site
    doc = {
        'name': tools.get('name'),
        'display_name': tools.get('display_name'),
        'description': tools.get('description'),
        'is_displayed': tools.get('is_displayed'),
        'order_key': tools.get('order_key')
    }
    es.update(p['host'], 'core_nav', 'site', site_id, doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Ejemplo n.º 25
0
def get(p):
    # load login module
    login_module_id = p['nav'][-1]
    login_module = es.get(p['host'], 'core_nav', 'login_module', login_module_id)
    if not login_module:
        return tools.alert('not valid login module id - {}'.format(login_module_id))

    # update new login module
    doc = {
        "type": tools.get('type'),
        "name": tools.get('name'),
        "description": tools.get('description'),
        "priority": tools.get('priority'),
        "configuration": tools.get('configuration')
    }
    es.update(p['host'], 'core_nav', 'login_module', login_module_id, doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Ejemplo n.º 26
0
def get(p):
    p['site_id'] = tools.get('site_id')
    if not p['site_id']: return tools.alert('site id is missing')

    # role list
    query = 'site_id:{}'.format(p['site_id'])
    option = 'size=1000&sort=name:asc'
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    return render_template("admin/role/default.html", p=p)
Ejemplo n.º 27
0
def get(p):
    start = request.url.find("/file/view/") + 11
    finish = request.url.rfind("?") if tools.get("id") else len(request.url)
    filename = request.url[start:finish]
    if filename.startswith("."):
        return "error"

    id = tools.get('id')
    shortname = jinja.filename(filename, id)

    if tools.get('download'):
        return send_from_directory(p['c']['upload_dir'],
                                   filename,
                                   as_attachment=True,
                                   attachment_filename=shortname)

    return send_from_directory(p['c']['upload_dir'],
                               filename,
                               as_attachment=False)
Ejemplo n.º 28
0
def get(p):
    # load task
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('task not found - {}'.format(task_id))

    # Create Schedule
    doc = {
        "task_id": task_id,
        "dayofmonth": tools.get("dayofmonth", 'None'),
        "dayofweek": tools.get("dayofweek", 'None'),
        "hour": tools.get("hour", 'None'),
        "minute": tools.get("minute", 'None')
    }
    es.create(p['host'], 'core_task', 'schedule', '', doc)
    es.flush(p['host'], 'core_task')

    return tools.redirect(request.referrer)
Ejemplo n.º 29
0
def get(p):
    # load task
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('task not found - {}'.format(task_id))

    if request.method == "POST":
        es.update(
            p['host'], 'core_task', 'task', task_id, {
                'navigation_id': p['navigation']['id'],
                'name': tools.get('name'),
                'runat':
                tools.get('runat') if tools.get('runat') else 'anywhere',
                'description': tools.get('description')
            })
        es.flush(p['host'], 'core_task')

        return tools.redirect(request.referrer)

    # load action list
    # when there are no records then the task fails to run
    option = ''
    if es.count(p['host'], 'core_task', 'action'):
        option = 'size=10000&sort=order_key:asc'

    query = 'task_id:{}'.format(p['task']['id'])
    p['action_list'] = es.list(p['host'], 'core_task', 'action', query, option)
    for action in p['action_list']:
        action['module'] = es.get(p['host'], 'core_task', 'module',
                                  action['module_id'])

    # load schedule list
    query = 'task_id:{}'.format(p['task']['id'])
    p['schedule_list'] = es.list(p['host'], 'core_task', 'schedule', query)

    # load task module List
    option = 'size=10000&sort=description:asc'
    p['task_module_list'] = es.list(p['host'], 'core_task', 'module', '*',
                                    option)

    return render_template("task/task/edit.html", p=p)
Ejemplo n.º 30
0
def get(p):
    # load site
    site_id = p['nav'][-1]
    p['selected_site'] = es.get(p['host'], 'core_nav', 'site', site_id)
    if not p['selected_site']:
        return tools.alert('not valid site id - {}'.format(site_id))
    # name shall exist
    if not tools.get('name'): return tools.alert("name can't be empty")

    # create new site
    doc = {
        'site_id': p['selected_site']['id'],
        'users': tools.get('users'),
        'name': tools.get('name'),
        'description': tools.get('description')
    }
    es.create(p['host'], 'core_nav', 'role', '', doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)