示例#1
0
def bucket_web_for_independent_domain(web_path=''):
    # 跟 bucket web 一样, 但是呈现的是独立域名, 放到最后被 app.route 添加,以避免影响其它 view 的逻辑
    # 系统自带的前端资源
    if re.match("/(_system|admin|service|bucket)/", request.path):
        abort(
            404,
            "custom url is not allowed to startswith (_system|admin|service|bucket)"
        )
    frontend_response = send_static_frontend_resource()
    if frontend_response:
        return frontend_response
    if not web_path and not get_buckets_size():
        # 还没有 bucket 的时候,允许用户进行安装的操作
        return p_redirect("/__create_bucket?code=admin")
    bucket = get_bucket_from_request()
    if bucket:
        if request.path in ['/robot.txt', '/robots.txt']:
            if not get_bucket_private_config(
                    bucket, "enable_web_robots", default=True):
                # 禁用爬虫
                robot_content = 'User-agent: *\nDisallow: /'
                return Response(robot_content, mimetype='text/plain')
        if request.url.startswith("http://") and get_bucket_private_config(
                bucket, "enable_https_force_redirect", default=False):
            # 强制跳转 https, 不用永久 301 code,避免用户自己切换后不成功
            return redirect(request.url.replace('http://', 'https://', 1),
                            code=302)
        set_site_in_request(get_bucket_site_configs(bucket))
        return render_bucket(bucket, web_path)
    else:
        abort(404, 'no bucket found')


################# for web pages ends ##########
示例#2
0
def get_bucket_for_file_manager():
    bucket = get_bucket_in_request_context() or request.values.get('bucket')
    if not bucket:
        bucket = get_bucket_from_request()
    if not is_bucket_login(bucket=bucket):
        abort(401)
    if not bucket:
        abort(404)
    return bucket
示例#3
0
def show_wiki_tag_fallback(tag):
    bucket = get_bucket_from_request()
    if not bucket:
        abort(404)
    set_bucket_in_request_context(bucket)
    wiki_root = get_wiki_root(bucket)
    if wiki_root:
        new_url = "/wiki/tag/%s?type=wiki_link" % tag
    else:
        new_url = "/tag/%s?type=wiki_link" % tag
    return redirect(new_url)
示例#4
0
def show_wiki_link_fallback(post_path):
    bucket = get_bucket_from_request()
    if not bucket:
        abort(404)
    if "?" in request.url:
        url_GET_part = request.url.split("?")[-1]
        post_path = "%s?%s" % (post_path, url_GET_part)
    wiki_root = get_wiki_root(bucket)
    post_doc = get_post_with_greed(url_body=post_path)
    if not post_doc:
        return abort(404, "post is not found")
    if wiki_root:
        post_url = get_wiki_url_for_doc(wiki_root, post_doc)
    else:
        post_url = get_doc_url(post_doc)
    if not post_url:
        return abort(404, "post is not found, post_url get failed")
    else:
        return redirect(post_url)
示例#5
0
文件: my.py 项目: zhiiker/FarBox
def render_markdown_page(path=""):
    # cache it
    bucket = get_bucket_from_request()
    set_bucket_in_request_context(bucket)
    try:  # memcache 的获取,也可能会出错, 概率很低
        cached_response = get_response_from_memcache()
        if cached_response:
            return cached_response
    except:
        pass

    if path in ["about", "links", "contact"]:
        md_doc = get_markdown_record_by_path_prefix(bucket, path)
        show_site_nav = True
    else:
        md_doc = None
        show_site_nav = False

    return render_api_template_as_response("page_user_markdown_page.jade",
                                           md_doc=md_doc,
                                           show_site_nav=show_site_nav)
示例#6
0
def do_get_smart_scss_url(scss_filepath, **kwargs):
    # 根据其内容内的变量名,进行替换处理;
    #  总是要读取源文件的,不然不知道是否要重新编译; 由于页面本身的缓存逻辑,性能影响有限
    # filename.scss -> filename-xxxxxxxxxxxx.css
    ext = os.path.splitext(scss_filepath)[-1]
    if ext not in [".less", ".scss"]:
        return scss_filepath  #ignore

    prefix_name = get_prefix_name_from_source_filepath(scss_filepath)
    filename = get_md5(get_md5(kwargs.keys()) +
                       get_md5(kwargs.values())) + '.css'
    filepath = '/_cache/scss/%s-%s' % (prefix_name, filename)

    bucket = get_bucket_in_request_context() or get_bucket_from_request()
    if not bucket:
        return scss_filepath  # ignore

    if has_record_by_path(bucket, path=filepath):
        # 缓存的文件已经存在了
        return filepath

    raw_content = ""
    if scss_filepath.startswith("/fb_static/"):
        raw_content = get_static_raw_content(scss_filepath)
    else:
        bucket = get_bucket_in_request_context()
        if bucket:
            raw_content = get_raw_content_by_path(bucket=bucket,
                                                  path=scss_filepath)
    if not raw_content:
        return scss_filepath  #ignore

    css_content = replace_vars_in_scss(raw_content=raw_content,
                                       new_vars=kwargs,
                                       compile_scss=True)
    sync_file_by_server_side(bucket=bucket,
                             relative_path=filepath,
                             content=css_content)

    return filepath
示例#7
0
def get_logined_bucket(check=True):
    logined_bucket_checked = get_logined_bucket_checked_in_request()
    if logined_bucket_checked:
        logined_bucket_in_g = get_logined_bucket_in_request()
        if logined_bucket_in_g:
            return logined_bucket_in_g
    utoken = get_cookie('utoken') or ''
    if '-' not in utoken:
        return None
    bucket_in_cookie, login_key_in_cookie = utoken.split('-', 1)
    if check:  # 要校验数据库里的 login token
        if not is_bucket_login(bucket_in_cookie):
            return None

    # 增加一个限制,只有 bucket 对应的 domain 下才允许登录,避免使用者混淆了
    if check and request.host not in WEBSITE_DOMAINS:
        bucket_from_domain = get_bucket_from_request(hit_admin_bucket=False)
        if bucket_from_domain and bucket_from_domain != bucket_in_cookie:
            admin_bucket = get_admin_bucket()
            if admin_bucket == bucket_in_cookie:
                return bucket_in_cookie
            else:
                return None
    return bucket_in_cookie
示例#8
0
def show_bucket_theme():
    bucket = request.values.get("bucket") or get_bucket_from_request()
    return show_bucket_pages_configs_by_web_api(bucket)