예제 #1
0
    def process_response(self, request, response):
        try:
            self.app = resolve(request.path).namespace
        except Resolver404:
            return response

        if DEBUG_ENABLED:
            return response
        if response.has_header('location'):
            if response['location'].startswith('/'):
                response['location'] = re.sub(r'/([^/]+)(.*)', self.handle_location, response['location'])
            elif response['location'].startswith('http://hub.neusoft.edu.cn/'):
                response['location'] = re.sub(r'http://hub.neusoft.edu.cn/([^/]+)(.*)', self.handle_hub, response['location'])
            return response
        if not hasattr(response, 'content'):
            return response

        response.content = re.sub(r'http://hub.neusoft.edu.cn/([^/]+)([^"]+)', self.handle_hub, response.content)
        response.content = re.sub(r'<link([^>]*)href="/([^"]*)"([^>]*)>', self.handle_link, response.content)
        response.content = re.sub(r'<script([^>]*)src="/([^"]*)"([^>]*)>', self.handle_script, response.content)
        response.content = re.sub(r'<a([^>]*)href="/([^/]+)([^"]*)"([^>]*)>', self.handle_a, response.content)
        response.content = re.sub(r'<form([^>]*)action="/([^/]+)([^"]*)"([^>]*)>', self.handle_form, response.content)
        response.content = re.sub(r'<img([^>]*)src="/([^/]+)([^"]*)"([^>]*)>', self.handle_img, response.content)

        response.content = re.sub('iptv.we.neusoft.edu.cn', 'iptv.neusoft.edu.cn', response.content)
        if not get_geo(request)[0]:
            response.content = re.sub('mirror.we.neusoft.edu.cn', 'mirrors.neusoft.edu.cn', response.content)

        return response
예제 #2
0
    def process_response(self, request, response):
        try:
            self.app = resolve(request.path).namespace
        except Resolver404:
            return response

        if DEBUG_ENABLED:
            return response
        if response.has_header('location'):
            if response['location'].startswith('/'):
                response['location'] = re.sub(r'/([^/]+)(.*)', self.handle_location, response['location'])
            elif response['location'].startswith('http://hub.neusoft.edu.cn/'):
                response['location'] = re.sub(r'http://hub.neusoft.edu.cn/([^/]+)(.*)', self.handle_hub, response['location'])
            return response
        if not hasattr(response, 'content'):
            return response

        response.content = re.sub(r'http://hub.neusoft.edu.cn/([^/]+)([^"]+)', self.handle_hub, response.content)
        response.content = re.sub(r'<link([^>]*)href="/static/([^"]*)"([^>]*)>', self.handle_link, response.content)
        response.content = re.sub(r'<script([^>]*)src="/static/([^"]*)"([^>]*)>', self.handle_script, response.content)
        response.content = re.sub(r'<a([^>]*)href="/([^/]+)([^"]*)"([^>]*)>', self.handle_a, response.content)
        response.content = re.sub(r'<form([^>]*)action="/([^/]+)([^"]*)"([^>]*)>', self.handle_form, response.content)
        response.content = re.sub(r'<img([^>]*)src="/([^/]+)([^"]*)"([^>]*)>', self.handle_img, response.content)

        if get_geo(request):
            response.content = re.sub('mirrors.neusoft.edu.cn', 'mirror.we.neusoft.edu.cn', response.content)
            response.content = re.sub('iptv.we.neusoft.edu.cn', 'iptv.neusoft.edu.cn', response.content)

        return response
예제 #3
0
def get_navbar(request):
    if get_geo(request)[0]:
        items = cache.get('navbar_items__intranet')
        if not items:
            items = NavbarItem.objects.filter(intranet=True).order_by('order')
            cache.set('navbar_items__intranet', items, 600)
    else:
        items = cache.get('navbar_items__internet')
        if not items:
            items = NavbarItem.objects.filter(internet=True).order_by('order')
            cache.set('navbar_items__internet', items, 600)

    navbar_items = []
    for item in items:
        navbar_items.append({
            'key': item.key,
            'title': item.title,
            'url': reverse(item.key + ':index')
        })

    result = get_environment(request)
    result.update({'navbar_items': navbar_items})
    result.update({'active_item': resolve(request.path).namespace})

    return result
예제 #4
0
def get_environment(request):
    result = dict()
    result.update({'open_server': OPEN_SERVER})
    result.update({'html5': 'Mozilla/5.0' in request.META.get('HTTP_USER_AGENT', '')})
    network, name = get_geo(request)
    result.update({'intranet': network != ''})

    return result
예제 #5
0
def get_name(request):
    if request.user.is_authenticated():
        try:
            return request.user.profile.nickname
        except:
            return request.user.username
    else:
        address = get_geo(request)[0]
        if not address:
            return '访客'
        elif address in ['faculty', 'administration']:
            return '老师'
        elif address[:6] == 'server':
            return '朋友'
        else:
            return '同学'
예제 #6
0
def get_name(request):
    if request.user.is_authenticated():
        try:
            return request.user.profile.nickname
        except:
            return request.user.username
    else:
        address = get_geo(request)[0]
        if not address:
            return '访客'
        elif address in ['faculty', 'administration']:
            return '老师'
        elif address[:6] == 'server':
            return '朋友'
        else:
            return '同学'
예제 #7
0
def get_more_list(request):
    app = NavbarItem.objects.filter(key=get_app(request))
    results = []

    if get_geo(request)[0]:
        more_list = NavbarMore.objects.filter(app=app).filter(intranet=True).order_by('order')
    else:
        more_list = NavbarMore.objects.filter(app=app).filter(internet=True).order_by('order')

    for more in more_list:
        results.append({
            'key': more.key,
            'title': more.title,
            'subtitle': more.subtitle,
            'content': markdown(more.content),
        })

    return results
예제 #8
0
    def get_context_data(self, **kwargs):
        context = super(FileView, self).get_context_data(**kwargs)
        context.update(get_navbar(self.request))
        context.update({'id': urlsafe_base64_encode(kwargs['object'].id.bytes)})
        context.update({'key': signer.sign(get_value(self.request, kwargs['object'].id)).replace(':', '')[-33:]})
        context.update({'ip': str(get_ip(self.request))})
        context.update({'geo': get_geo(self.request)[1]})
        context.update({'speed': get_speed(self.request)})

        mimetype = kwargs['object'].mime
        if mimetype == 'application/x-iso9660-image':
            mimeicon = 'cd'
        elif mimetype.startswith('video'):
            mimeicon = 'film'
        else:
            mimeicon = 'file'
        context.update({'mimeicon': mimeicon})

        return context
예제 #9
0
def get_more_list(request):
    app = NavbarItem.objects.filter(key=get_app(request))
    results = []

    if get_geo(request)[0]:
        more_list = NavbarMore.objects.filter(app=app).filter(
            intranet=True).order_by('order')
    else:
        more_list = NavbarMore.objects.filter(app=app).filter(
            internet=True).order_by('order')

    for more in more_list:
        results.append({
            'key': more.key,
            'title': more.title,
            'subtitle': more.subtitle,
            'content': markdown(more.content),
        })

    return results
예제 #10
0
def get_navbar(request):
    if get_geo(request)[0]:
        items = cache.get('navbar_items__intranet')
        if not items:
            items = NavbarItem.objects.filter(intranet=True).order_by('order')
            cache.set('navbar_items__intranet', items, 600)
    else:
        items = cache.get('navbar_items__internet')
        if not items:
            items = NavbarItem.objects.filter(internet=True).order_by('order')
            cache.set('navbar_items__internet', items, 600)

    navbar_items = []
    for item in items:
        navbar_items.append({'key': item.key, 'title': item.title, 'url': reverse(item.key + ':index')})

    result = get_environment(request)
    result.update({'navbar_items': navbar_items})
    result.update({'active_item': resolve(request.path).namespace})

    return result
예제 #11
0
def get_services(request):
    services = []

    if get_geo(request=request):
        more_services = cache.get('more_services__intranet')
        if not more_services:
            more_services = NavbarMore.objects.filter(app='www').filter(intranet=True).order_by('order')
            cache.set('more_services__intranet', more_services, 600)
    else:
        more_services = cache.get('more_services__internet')
        if not more_services:
            more_services = NavbarMore.objects.filter(app='www').filter(internet=True).order_by('order')
            cache.set('more_services__internet', more_services, 600)

    for more_service in more_services:
        services.append({
            'key': more_service.key,
            'title': more_service.title,
            'subtitle': more_service.subtitle,
            'content': markdown(more_service.content),
        })

    return services
예제 #12
0
    def get_context_data(self, **kwargs):
        context = super(FileView, self).get_context_data(**kwargs)
        context.update(get_navbar(self.request))
        context.update(
            {'id': urlsafe_base64_encode(kwargs['object'].id.bytes)})
        context.update({
            'key':
            signer.sign(get_value(self.request,
                                  kwargs['object'].id)).replace(':', '')[-33:]
        })
        context.update({'ip': str(get_ip(self.request))})
        context.update({'geo': get_geo(self.request)[1]})
        context.update({'speed': get_speed(self.request)})

        mimetype = kwargs['object'].mime
        if mimetype == 'application/x-iso9660-image':
            mimeicon = 'cd'
        elif mimetype.startswith('video'):
            mimeicon = 'film'
        else:
            mimeicon = 'file'
        context.update({'mimeicon': mimeicon})

        return context
예제 #13
0
def validate_ip(request):
    return get_geo(request)[:6] == 'server'