Пример #1
0
def request_handler(request, client_id, source, path):
    request.encoding = 'gbk'
    # TODO: validate source
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')
    url = path

    if len(request.GET) > 0:
        data = urllib.urlencode(dict([k, unicode(v).encode('gbk')]
                                for k, v in request.GET.items()))
        url = url + '?' + data
    postdata = simplejson.dumps(request.POST)
    ks = request.GET.getlist('ks[]')
    if ks:
        postdata += ", ks=" + simplejson.dumps(ks)

    # redirect requests, set False if we have handled all the requests
    redirect_request = True
    warning_tag = ''
    if not url.startswith('openbox.mobilem.360.cn/AppStore/getSuggest'):
        warning_tag = ', WARNING:UNKNOWNREQUEST'
        redirect_request = True

    logger.info('request_handler, clientid=%s, source=%s, ip=%s, path=%s, method=%s, postdata=%s, rawpostdata=%s, unhandled%s'
                % (client_id, source, ip, url, request.method, postdata, request.raw_post_data, warning_tag))

    if request.method == 'GET' and redirect_request:
        return HttpResponseRedirect('http://' + url)
    return HttpResponse('ok', status=200)
Пример #2
0
    def execute(self, request):
        chn = get_parameter_GET(
            request,
            'chn',
            required=False,
            str_max_length=255)
        client_id = get_parameter_GET(request, 'clientid')
        source = get_parameter_GET(request, 'source', str_max_length=255)
        app_id = get_parameter_GET(request, 'app_id', convert_func=int)
        app_version_code = get_parameter_GET(
            request,
            'app_version_code',
            convert_func=int)
        start_index = get_parameter_GET(
            request,
            'start_index',
            convert_func=int)
        count = get_parameter_GET(request, 'count', convert_func=int)
        ip = get_parameter_META(
            request,
            'REMOTE_ADDR',
            required=False,
            default=u'')
        for q in (client_id, source, app_id, app_version_code):
            if isinstance(q, HttpResponse):
                return q

        return (
            {'reviews': self.query_reviews(
                app_id,
                start_index=start_index,
                count=count)}
        )
Пример #3
0
def app_blacklist(request):
    client_id = get_parameter_GET(request, 'clientid')
    source = get_parameter_GET(request, 'source')
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')
    start_index = get_parameter_GET(
        request,
        'start_index',
        convert_func=int,
        required=False,
        default=u'0')
    count = get_parameter_GET(
        request,
        'count',
        convert_func=int,
        required=False,
        default=u'0')
    if_modified_since = get_parameter_META(
        request,
        'HTTP_IF_MODIFIED_SINCE',
        convert_func=parser.parse,
        required=False,
        default=None)
    for q in (client_id, source, ip, start_index, count):
        if isinstance(q, HttpResponse):    # convert failed
            return q

    updatetime = app_db.query_blacklist_update_time()
    logger.info('app_blacklist, clientid=%s, source=%s, ip=%s, ims=%s, ut=%s'
                % (client_id, source, ip, if_modified_since, updatetime))
    if updatetime is None or (if_modified_since is not None and updatetime <= if_modified_since):
        return HttpResponseNotModified()

    data = app_db.query_blacklist(start_index, count)
    response = HttpResponse(
        simplejson.dumps(data),
        content_type='application/json; charset=utf-8')
    response['Last-Modified'] = updatetime
    return response
Пример #4
0
def client_activate(request):
    client_id = get_parameter_POST(request, 'clientid')
    source = get_parameter_POST(request, 'source')
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')
    data = get_parameter_POST(request, 'data')
    for q in (client_id, source, data):
        if isinstance(q, HttpResponse):    # convert failed
            return q

    logger.info('client_activate, clientid=%s, source=%s, ip=%s, data=%s'
                % (client_id, source, ip, data))
    return {'ok': 1}
Пример #5
0
    def execute(self, request):
        time_start = self._now_ms()
        chn = get_parameter_POST_or_GET(
            request,
            'chn',
            required=False,
            str_max_length=255)
        client_id = get_parameter_POST_or_GET(request, 'clientid')
        source = get_parameter_POST_or_GET(
            request,
            'source',
            str_max_length=255)
        app_infos_str = get_parameter_POST_or_GET(
            request,
            'appinfos',
            str_max_length=2 *
            1024 *
            1024)
        # 0: upload only, return empty array, 1: return apps with new versions,
        # 2: return all known apps
        retlevel = get_parameter_POST_or_GET(
            request,
            'retlevel',
            required=False,
            convert_func=int,
            default=2)
        device_model = get_parameter_POST_or_GET(
            request,
            'device_model',
            required=False,
            str_max_length=255)
        os_v = get_parameter_POST_or_GET(
            request,
            'os',
            required=False,
            convert_func=int,
            default=0)
        screen_size = get_parameter_POST_or_GET(
            request,
            'screensize',
            required=False,
            str_max_length=255)
        platform = get_parameter_POST_or_GET(
            request,
            'platform',
            convert_func=to_int_array,
            default='1')
        jailbreak = get_parameter_POST_or_GET(
            request,
            'jailbreak',
            convert_func=int,
            default=0)
        category_id = get_parameter_POST_or_GET(
            request,
            'category_id',
            required=False,
            convert_func=int,
            default=0)
        # format: empty, dolphin
        format = get_parameter_POST_or_GET(
            request,
            'format',
            required=False,
            str_max_length=255)
        ip = get_parameter_META(
            request,
            'REMOTE_ADDR',
            required=False,
            default=u'')
        for q in (client_id, source, app_infos_str, retlevel, device_model, os_v, screen_size):
            if isinstance(q, HttpResponse):
                self.logger.warn(
                    'app_updates2, ip=%s, clientid=%s, param=%s, invalid request' %
                    (ip, client_id, str(q)))
                return q

        if jailbreak == -1:
            # this is used for pc client, for which, there's no jailbreak
            # concept, and it requires the app to keep the jailbreak status
            jailbreak = None
        elif jailbreak == 1:
            jailbreak = True
        else:
            jailbreak = False
        if len(platform) == 1:
            platform = platform[0]

        results = []
        has_new_version_apps = []
        if retlevel > 0:
            app_infos = self._parse_app_infos(app_infos_str, source, chn)

            results = self.query_app_updates(
                app_infos,
                category_id,
                platform,
                jailbreak)

            user_app_versions = dict(
                [(app[UA_PACKAGE_NAME], app[UA_VERSION_CODE]) for app in app_infos])
            has_new_version_apps = [app for app in results if int(
                app['version_code']) > user_app_versions.get(app['package_name'],
                                                             0)]
            if retlevel == 1:
                results = has_new_version_apps

            if AppUpdateAction.incremental_update_enabled(source):
                self.process_incremental_update(results, app_infos)

            results = app_post_process(
                results,
                os=os_v,
                screen_size=screen_size)

        self.app_upload_logger.info('ip=%s, clientid=%s, source=%s, device_model=%s, retlevel=%d, os=%s, screensize=%s, category_id=%d, appinfos=%s, newversions=%s, timetaken=%d'
                                    % (ip, client_id, source, device_model, retlevel, os_v, screen_size, category_id, app_infos_str, '|'.join([str(app['id']) for app in has_new_version_apps]), self._now_ms() - time_start))

        if format == 'dolphin':
            results = {
                'apps': results,
                'display_type': -1,
                'icon_url': '',
                'display_message': '',
                'page_url': ''}

        return results
Пример #6
0
    def execute(self, request):
        time_start = self._now_ms()
        chn = get_parameter_POST_or_GET(request,
                                        'chn',
                                        required=False,
                                        str_max_length=255)
        client_id = get_parameter_POST_or_GET(request, 'clientid')
        source = get_parameter_POST_or_GET(request,
                                           'source',
                                           str_max_length=255)
        app_infos_str = get_parameter_POST_or_GET(request,
                                                  'appinfos',
                                                  str_max_length=2 * 1024 *
                                                  1024)
        # 0: upload only, return empty array, 1: return apps with new versions,
        # 2: return all known apps
        retlevel = get_parameter_POST_or_GET(request,
                                             'retlevel',
                                             required=False,
                                             convert_func=int,
                                             default=2)
        device_model = get_parameter_POST_or_GET(request,
                                                 'device_model',
                                                 required=False,
                                                 str_max_length=255)
        os_v = get_parameter_POST_or_GET(request,
                                         'os',
                                         required=False,
                                         convert_func=int,
                                         default=0)
        screen_size = get_parameter_POST_or_GET(request,
                                                'screensize',
                                                required=False,
                                                str_max_length=255)
        platform = get_parameter_POST_or_GET(request,
                                             'platform',
                                             convert_func=to_int_array,
                                             default='1')
        jailbreak = get_parameter_POST_or_GET(request,
                                              'jailbreak',
                                              convert_func=int,
                                              default=0)
        category_id = get_parameter_POST_or_GET(request,
                                                'category_id',
                                                required=False,
                                                convert_func=int,
                                                default=0)
        # format: empty, dolphin
        format = get_parameter_POST_or_GET(request,
                                           'format',
                                           required=False,
                                           str_max_length=255)
        ip = get_parameter_META(request,
                                'REMOTE_ADDR',
                                required=False,
                                default=u'')
        for q in (client_id, source, app_infos_str, retlevel, device_model,
                  os_v, screen_size):
            if isinstance(q, HttpResponse):
                self.logger.warn(
                    'app_updates2, ip=%s, clientid=%s, param=%s, invalid request'
                    % (ip, client_id, str(q)))
                return q

        if jailbreak == -1:
            # this is used for pc client, for which, there's no jailbreak
            # concept, and it requires the app to keep the jailbreak status
            jailbreak = None
        elif jailbreak == 1:
            jailbreak = True
        else:
            jailbreak = False
        if len(platform) == 1:
            platform = platform[0]

        results = []
        has_new_version_apps = []
        if retlevel > 0:
            app_infos = self._parse_app_infos(app_infos_str, source, chn)

            results = self.query_app_updates(app_infos, category_id, platform,
                                             jailbreak)

            user_app_versions = dict([(app[UA_PACKAGE_NAME],
                                       app[UA_VERSION_CODE])
                                      for app in app_infos])
            has_new_version_apps = [
                app for app in results
                if int(app['version_code']) > user_app_versions.get(
                    app['package_name'], 0)
            ]
            if retlevel == 1:
                results = has_new_version_apps

            if AppUpdateAction.incremental_update_enabled(source):
                self.process_incremental_update(results, app_infos)

            results = app_post_process(results,
                                       os=os_v,
                                       screen_size=screen_size)

        self.app_upload_logger.info(
            'ip=%s, clientid=%s, source=%s, device_model=%s, retlevel=%d, os=%s, screensize=%s, category_id=%d, appinfos=%s, newversions=%s, timetaken=%d'
            % (ip, client_id, source, device_model, retlevel, os_v,
               screen_size, category_id, app_infos_str, '|'.join([
                   str(app['id']) for app in has_new_version_apps
               ]), self._now_ms() - time_start))

        if format == 'dolphin':
            results = {
                'apps': results,
                'display_type': -1,
                'icon_url': '',
                'display_message': '',
                'page_url': ''
            }

        return results
Пример #7
0
def process_push_request(request, the_logger, from_openapi=False):
    print 'check client_id1'
    perf = SimplePerfCounter()
    client_id = get_parameter_POST(request, 'clientid')
    print 'check client_id1end'
    chn = get_parameter_POST(
        request,
        'chn',
        required=False,
        default=None) or get_parameter_POST(
        request,
        'chn',
        required=from_openapi)
    partner = get_parameter_POST(
        request,
        'partner',
        required=False,
        default=u'')
    user_phone = get_parameter_POST(
        request,
        'usrpn',
        required=False,
        default=u'')
    source = get_parameter_POST(request, 'source')
    imei = get_parameter_POST(request, 'imei', required=False, default=u'')
    imsi = get_parameter_POST(
        request,
        'imsi',
        required=False,
        default=u'',
        alternative_name='az')
    device_model = get_parameter_POST(
        request,
        'device_model',
        required=False,
        default=u'')
    device_info = get_parameter_POST(
        request,
        'deviceinfo',
        required=False,
        default=u'')
    os_v = get_parameter_POST(
        request,
        'os',
        convert_func=int,
        required=False,
        default=0)
    screensize = get_parameter_POST(
        request,
        'screen_size',
        required=False,
        default=u'')
    sim_operator = get_parameter_POST(
        request,
        'sim_operator',
        required=False,
        default='0')
    client_version = get_parameter_POST(
        request,
        'client_version',
        convert_func=int,
        required=False,
        default=0)
    print 'check client_id2'
    locale = get_parameter_POST(request, 'locale')
    last_query_time = get_parameter_POST(request, 't', convert_func=long)
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')
    count = get_parameter_POST(
        request,
        'count',
        convert_func=int,
        required=False,
        default=5)
    debug = get_parameter_POST(
        request,
        'debug',
        convert_func=int,
        required=False,
        default=0)
    debug_user_tags = get_parameter_POST(
        request,
        'debug_user_tags',
        required=False,
        default=u'')
    print 'check client_id3'
    if not from_openapi and (isinstance(chn, HttpResponse) or not chn) and partner:
        chn = partner
    for q in (chn, client_id, source, locale, last_query_time, ip, client_version, os_v, sim_operator):
        if isinstance(q, HttpResponse):  # convert failed
            logger.error(
                'push_notification_messages, ip=%s, clientid=%s, invalid request, q=%s' %
                (str(ip), str(client_id), str([client_id, source, locale, last_query_time, ip, client_version, os_v, sim_operator])))
            return q

    try:
        if sim_operator == '':
            sim_operator = 0
        else:
            # pick the first sim card if there are more than one. TODO: use all
            sim_operator = int(sim_operator.split(',')[0])
    except Exception as e:
        logger.error(
            'push_notification_messages, ip=%s, clientid=%s, invalid sim_operator, q=%s' %
            (str(ip), str(client_id), str(sim_operator)))
        sim_operator = 0

    if not client_version:
        try:
            #from right to split and max split is 1.
            s = source.rsplit('_', 1)
            if len(s) > 1 and s[1]:
                client_version = int(s[1])
        except Exception as e:
            pass
    if perf:
        perf.set('prms')

    # some clients send milliseconds. convert the ms to seconds
    # detect ms by 100000000000 (which is 11/16/5138 5:46:40 PM in seconds,
    # which is not a valid second value at current time)
    last_query_time_in_seconds = last_query_time if last_query_time < 100000000000 else last_query_time / \
        1000

    black_list = 0
    is_test_device = False
    decrypted_user_phone = rsa_decrypt(user_phone)
    decrypted_imsi = rsa_decrypt(imsi)
    if perf:
        perf.set('dcrypt')
    
    print 'check client_id'
    is_in_blacklist = push_db.in_blacklist(
        client_id,
        decrypted_user_phone,
        imei,
        decrypted_imsi)
    if perf:
        perf.set('blckl')

    print '7384384838283283'
    print is_in_blacklist
    if is_in_blacklist:
        black_list = 1
        results = []
    else:
        is_test_device = push_db.is_test_device(client_id)
        if perf:
            perf.set('tstd')

        results = push_db.query_messages(
            last_query_time_in_seconds,
            client_id,
            locale,
            source=source.split('_')[0],
            is_test_device=is_test_device)
        print 'results is :'
        print results

        if perf:
            perf.set('qm')

    if not device_model and device_info:
        device_model = device_info.rsplit('_', 1)[0]

    final_results = select_messages(
        messages=results,
        client_id=client_id,
        source=source,
        chn=chn,
        is_test_device=is_test_device,
        count=count,
        device_model=device_model,
        os_v=os_v,
        screensize=screensize,
        sim_operator=sim_operator,
        user_phone=user_phone,
        client_version=client_version,
        ip=ip,
        debug=debug,
        debug_user_tags=debug_user_tags,
        perf=perf,
        push_db=push_db,
        user_db=user_db,
        location_db=location_db)

    print 'final_results is:'
    print final_results
    final_results = append_icon_host(final_results, True)
    if perf:
        perf.set('pp')

    the_logger.info('push_notification_messages, chn=%s, ip=%s, clientid=%s, user_phone=%s|%s, source=%s, locale=%s, last_query_time=%s, imei=%s, imsi=%s|%s, rawmessages=%s, finalmessages=%s, blacklist=%s, device_model=%s, os=%d, screensize=%s, sim_operator=%d, client_version=%d, perf=%s'
                    % (str(chn), ip, client_id, user_phone if not decrypted_user_phone else '', decrypted_user_phone, source, locale, last_query_time, imei, imsi if not decrypted_imsi else '', decrypted_imsi, str([result.get('message_id', 0) for result in results]) if debug else '', str([result.get('message_id', 0) for result in final_results]), black_list, device_model, os_v, screensize, sim_operator, client_version, perf.to_str()))

    return final_results
Пример #8
0
def app_reviews(request):
    if request.method == "GET":
        client_id = get_parameter_GET(request, 'clientid')
        app_id = get_parameter_GET(
            request,
            'app_id',
            convert_func=int,
            required=False)
        app_name = get_parameter_GET(request, 'appname', required=False)
        start_index = get_parameter_GET(
            request,
            'start_index',
            convert_func=int)
        count = get_parameter_GET(request, 'count', convert_func=int)
        with_total = get_parameter_GET(
            request,
            'wt',
            convert_func=bool,
            required=False)
        for q in (client_id, app_id, start_index, count):
            if isinstance(q, HttpResponse):    # convert failed
                return q
        if not app_id and not app_name:
            return (
                parameter_error(
                    request,
                    'either of [app_id, appname] is required')
            )

        if not app_id:
            app = app_db.get_app_by_name(app_name)
            if not app:
                return []
            app_id = app['id']

        results = app_db.query_reviews(
            app_id,
            start_index=start_index,
            count=count,
            with_total=with_total)
        logger.info('app_reviews, client_id=%s, results=%s'
                    % (client_id, _result_info(results)))

        return results
    elif request.method == "POST":
        client_id = get_parameter_POST(request, 'clientid')
        review = get_parameter_POST(
            request,
            'review',
            convert_func=simplejson.loads)
        ip = get_parameter_META(
            request,
            'REMOTE_ADDR',
            required=False,
            default=u'')
        for q in (client_id, review, ip):
            if isinstance(q, HttpResponse):    # convert failed
                return q
        review['client_id'] = client_id
        app_db.save_reviews([review])

        logger.info('app_reviews, post, client_id=%s, ip=%s, review_id=%d'
                    % (client_id, ip, review['id']))
Пример #9
0
def app_updates(request):
    '''
    clientid: client's unique id, client refers to the device where apps to be installed on
    source: where the app update request is sent from, usually consists of "<package_name>+<version_code>"
    deviceinfo: a piece of info which usually consists of "<model_name>+<os_version>"
    '''
    compact = get_parameter_GET(
        request,
        'compact',
        convert_func=int,
        required=False,
        default=None)
    if compact is not None:
        client_id = get_parameter_GET(request, 'clientid')
        source = get_parameter_GET(request, 'source')
        app_infos = []
        if compact == 1:
            for arg in request.raw_post_data.split('&'):
                kv = arg.split('=', 1)
                if len(kv) != 2:
                    continue
                if kv[0] == 'ks[]':
                    fields = kv[1].split('|')
                    if len(fields) != 2:
                        continue
                    app_infos.append({
                        "packageName": fields[0],
                        "packageVersion": long(fields[1]),
                        "packageSig": "",
                        "appName": "",
                    })
                elif kv[0] == 'os':
                    os = int(kv[1])
        elif compact == 2:
            http_head = get_parameter_META(
                request,
                'HTTP_HEAD',
                convert_func=simplejson.loads,
                required=False,
                default=u'')
            os = http_head['sdk']
            p = get_parameter_POST(request, 'p')
            p = simplejson.loads(p) if p else None
            if p:
                for k, v in p.iteritems():
                    app_infos.append({
                        "packageName": k,
                        "packageVersion": 0,
                        "packageSig": "",
                        "appName": v,
                    })
    else:
        client_id = get_parameter_POST(request, 'clientid')
        source = get_parameter_POST(request, 'source')
        app_infos = get_parameter_POST(
            request,
            'appinfos',
            convert_func=simplejson.loads)
        os = get_parameter_POST(
            request,
            'os',
            required=False,
            convert_func=int,
            default=None)
    device_info = get_parameter_POST(request, 'deviceinfo', required=False)
    screen_size = get_parameter_POST(request, 'screensize', required=False)
    platform = get_parameter_POST(
        request,
        'platform',
        convert_func=to_int_array,
        default='1')
    jailbreak = get_parameter_POST(
        request,
        'jailbreak',
        convert_func=int,
        default=0)
    save_to_db = get_parameter_GET(
        request,
        'savetodb',
        convert_func=int,
        default=1) == 1
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')
    with_details = get_parameter_GET(
        request,
        'details',
        convert_func=bool,
        required=False)
    for q in (client_id, source, device_info, app_infos, ip):
        if isinstance(q, HttpResponse):
            logger.info(
                'app_updates, ip=%s, clientid=%s, invalid request' %
                (ip, client_id))
            return q

    if jailbreak == -1:
        # this is used for pc client, for which, there's no jailbreak concept,
        # and it requires the app to keep the jailbreak status
        jailbreak = None
    elif jailbreak == 1:
        jailbreak = True
    else:
        jailbreak = False

    if len(platform) == 1:
        platform = platform[0]

    log_data = '|'.join([str(app_info['packageName']) + ':' + str(app_info['packageVersion'])
                        for app_info in app_infos])
    app_upload_logger.info('ip=%s, clientid=%s, source=%s, deviceinfo=%s, appinfos=%s, os=%s, screensize=%s, platform=%s, jailbreak=%s, savetodb=%s, compact=%s'
                           % (ip, client_id, source, device_info, log_data, str(os), screen_size, str(platform), str(jailbreak), str(save_to_db), str(compact)))

    for app in app_infos:
        app['packageVersion'] = int(app['packageVersion'])

    if len(app_infos) > 0:
        user_app_data = {
            'apps': app_infos,
            'device_info': device_info,
            'os': os,
            'screen_size': screen_size,
            'platform': platform,
            'jailbreak': jailbreak,
            'source': source
        }
        if save_to_db:
            user_db.update_apps_installed(client_id, user_app_data)
    else:
        # client may update an empty list to just query the user app updates
        user_app_data = user_db.query_apps_installed(client_id)
        if user_app_data is not None and 'apps' in user_app_data:
            app_infos = user_app_data['apps']

    if app_infos is not None and len(app_infos) > 0:
        if jailbreak is not None:
            results = app_db.query_updates(
                app_infos,
                platform=platform,
                jailbreak=jailbreak)
        else:
            results = app_db.query_updates(
                [app for app in app_infos if app['appType'] == 0],
                platform=platform,
                jailbreak=jailbreak)
            results += app_db.query_updates(
                [app for app in app_infos if app['appType'] != 0],
                platform=platform, jailbreak=jailbreak)
    else:
        results = []

    # support incremental updates
    for r in results:
        r['patch_size'] = 0    # 0 by default
        app = [a for a in app_infos if a['packageName'] == r['package_name']]
        if app:
            app = app[0]
            old_hash, new_hash = app.get(
                'packageHash', None), r.get('package_hash', None)
            if old_hash and new_hash:
                old_hash = old_hash.lower()
                patch_info = patch_db.get_patch_info(old_hash, new_hash)
                if patch_info:
                    r['patch_size'] = friendly_size(patch_info['patch_size'])
                # else:
                    # On demand calculate patch
                    #patch_db.add_job(old_hash, new_hash)
                del r['package_hash']
        else:
            continue

    results = app_post_process(
        results,
        with_details=with_details,
        os=os,
        screen_size=screen_size)
    logger.info(
        'app_updates, clientid=%s, results=%d' %
        (client_id, len(results)))
    return results
Пример #10
0
def app_download(request, app_id=None, source=None):
    client_id = get_parameter_GET(
        request,
        'clientid',
        required=False,
        default='')
    if not source:
        source = get_parameter_GET(
            request,
            'source',
            required=False,
            default='')
    if not app_id:
        app_id = get_parameter_GET(
            request,
            'app_id',
            convert_func=int,
            required=False,
            default=None)
    package_name = get_parameter_GET(
        request,
        'packagename',
        required=False,
        default=None)
    is_rename = get_parameter_GET(
        request,
        'rn',
        convert_func=bool,
        required=False,
        default=True)
    version_code = get_parameter_GET(
        request,
        'versioncode',
        convert_func=int,
        required=False)
    external_url = get_parameter_GET(request, 'externalurl', required=False)
    platform = get_parameter_GET(
        request,
        'platform',
        convert_func=int,
        default=1)
    jailbreak = get_parameter_GET(
        request,
        'jailbreak',
        convert_func=int,
        default=0) == 1
    old_hash = get_parameter_GET(
        request,
        'old_hash',
        required=False,
        default=None)
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')

    for q in (client_id, app_id, package_name):
        if isinstance(q, HttpResponse):
            return q
    if not app_id and not package_name:
        return (
            parameter_error(
                request,
                'either of [app_id, packagename] is required')
        )

    store_app = get_app(
        app_id=app_id,
        package_name=package_name,
        platform=platform,
        jailbreak=jailbreak)
    if store_app:
        app_id = store_app['id']
        package_name = store_app['package_name']

    # get download info
    download_info = process_app_download(
        client_id,
        source,
        store_app,
        external_url)

    download_from = 'NA'
    download_app = None
    use_download_app = None
    if download_info:
        (download_app, use_download_app, download_from) = download_info

    # log
    logger.info('app_download, clientid=%s, source=%s, ip=%s, package=%s, version=%s, externalurl=%s, id=%s, downversion=%s, downurl=%s, downfrom=%s'
                % (client_id, source, ip, str(package_name), str(version_code), str(external_url), str(app_id), str(download_app['version_code']) if download_app else 'NA', download_app['download_url'] if download_app else 'NA', download_from))

    # redirect to download
    if use_download_app:
        is_rename = True
        new_hash = download_app.get('package_hash')
        download_url = None
        if old_hash and new_hash:
            old_hash = old_hash.lower()
            download_url = patch_db.get_patch_url(old_hash, new_hash)
            # if not download_url:
                # On demand calculate patch
                #patch_db.add_job(old_hash, new_hash)
        if not download_url:
            download_url = download_app['download_url']
        return (
            app_download_internal_by_download_url(
                download_url,
                download_app['package_name'],
                download_app['version_code'],
                is_rename=is_rename)
        )
    if external_url:
        return HttpResponseRedirect(external_url)
    return resource_not_exist(request, app_id if app_id else package_name)
Пример #11
0
    def execute(self, request):
        chn = get_parameter_POST_or_GET(
            request,
            'chn',
            required=False,
            str_max_length=255)
        client_id = get_parameter_POST_or_GET(request, 'clientid')
        source = get_parameter_POST_or_GET(
            request,
            'source',
            str_max_length=255)
        app_id = get_parameter_POST_or_GET(
            request,
            'app_id',
            convert_func=int)
        app_version_code = get_parameter_POST_or_GET(
            request,
            'app_version_code',
            convert_func=int)
        app_version_name = get_parameter_POST_or_GET(
            request,
            'app_version_name')
        user_name = get_parameter_POST_or_GET(request, 'user_name')
        review_rate = get_parameter_POST_or_GET(
            request,
            'rate',
            convert_func=int)
        review_content = get_parameter_POST_or_GET(
            request,
            'content',
            str_max_length=1000)
        ip = get_parameter_META(
            request,
            'REMOTE_ADDR',
            required=False,
            default=u'')
        for q in (client_id, source, app_id, app_version_code, app_version_name, user_name, review_rate, review_content):
            if isinstance(q, HttpResponse):
                return q

        error_code = PostReviewAction.ERROR_CODE_OK
        status = PostReviewAction.REVIEW_STATUS_OK
        if self.contains_block_words(app_version_name + user_name + review_content):
            status = PostReviewAction.REVIEW_STATUS_AWAITING_MODERATION
            error_code = PostReviewAction.ERROR_CODE_AWAITING_MODERATION

        review = {
            'app_id': app_id,
            'app_version_code': app_version_code,
            'app_version_name': app_version_name,
            'user_name': user_name,
            'rate': review_rate,
            'content': review_content,
            'source': source,
            'client_id': client_id,
            'ip': ip,
            'created_time': timestamp_utc_now(),
            'status': status,
        }

        self.app_db.save_reviews(review)

        del review['app_id']
        del review['app_version_code']
        del review['source']
        del review['client_id']
        del review['ip']
        del review['status']
        del review['_id']

        return {'error_code': error_code, 'reviews': [review]}
Пример #12
0
def feedbacks(request, types=None):
    if get_parameter_GET(request, 'is_unload', required=False, default=False):
        uni_token = get_parameter_GET(
            request,
            'uni_token',
            required=False,
            default=False)
        if(uni_token):
            feedback = {
                'feedback_str': get_parameter_GET(
                    request,
                    'call_back_str',
                    required=False,
                    default=u'')}
            feedback['uni_token'] = uni_token
            feedback['user_submit'] = True
            feedback['feedback_id'] = get_parameter_GET(
                request,
                'call_back_order',
                required=False,
                default=u'')
            promotion_db.save_uninstall_feedbacks([feedback])
        else:
            client_id = ''
            feedback = {
                'content': get_parameter_GET(
                    request,
                    'call_back_str',
                    required=False,
                    default=u'')}
            feedback['client_id'] = ''
            feedback['source'] = get_parameter_GET(
                request,
                'source',
                required=False,
                default='unload')
            promotion_db.save_feedbacks([feedback])
            logger.info('unload_feedbacks, feedback=%s'
                        % feedback['content'])
        return {'ok': True}

    if get_parameter_GET(request, 'keepraw', required=False, default=u''):
        client_id = get_parameter_GET(request, 'clientid')
        source = get_parameter_GET(
            request,
            'source',
            required=False,
            default=u'')
        feedback = {
            'content': simplejson.dumps(request.GET),
            'keepraw': 1
        }
    else:
        client_id = get_parameter_POST(request, 'clientid')
        source = get_parameter_GET(
            request,
            'source',
            required=False,
            default=u'')
        feedback = get_parameter_POST(
            request,
            'feedback',
            convert_func=simplejson.loads)
    ip = get_parameter_META(
        request,
        'REMOTE_ADDR',
        required=False,
        default=u'')
    for q in (client_id, feedback, ip):
        if isinstance(q, HttpResponse):    # convert failed
            return q

    feedback['client_id'] = client_id
    feedback['source'] = source
    promotion_db.save_feedbacks([feedback])
    logger.info('feedbacks, client_id=%s, ip=%s' % (client_id, ip))

    return {'ok': True}
Пример #13
0
def feedbacks(request, types=None):
    if get_parameter_GET(request, 'is_unload', required=False, default=False):
        uni_token = get_parameter_GET(request,
                                      'uni_token',
                                      required=False,
                                      default=False)
        if (uni_token):
            feedback = {
                'feedback_str':
                get_parameter_GET(request,
                                  'call_back_str',
                                  required=False,
                                  default=u'')
            }
            feedback['uni_token'] = uni_token
            feedback['user_submit'] = True
            feedback['feedback_id'] = get_parameter_GET(request,
                                                        'call_back_order',
                                                        required=False,
                                                        default=u'')
            promotion_db.save_uninstall_feedbacks([feedback])
        else:
            client_id = ''
            feedback = {
                'content':
                get_parameter_GET(request,
                                  'call_back_str',
                                  required=False,
                                  default=u'')
            }
            feedback['client_id'] = ''
            feedback['source'] = get_parameter_GET(request,
                                                   'source',
                                                   required=False,
                                                   default='unload')
            promotion_db.save_feedbacks([feedback])
            logger.info('unload_feedbacks, feedback=%s' % feedback['content'])
        return {'ok': True}

    if get_parameter_GET(request, 'keepraw', required=False, default=u''):
        client_id = get_parameter_GET(request, 'clientid')
        source = get_parameter_GET(request,
                                   'source',
                                   required=False,
                                   default=u'')
        feedback = {'content': simplejson.dumps(request.GET), 'keepraw': 1}
    else:
        client_id = get_parameter_POST(request, 'clientid')
        source = get_parameter_GET(request,
                                   'source',
                                   required=False,
                                   default=u'')
        feedback = get_parameter_POST(request,
                                      'feedback',
                                      convert_func=simplejson.loads)
    ip = get_parameter_META(request,
                            'REMOTE_ADDR',
                            required=False,
                            default=u'')
    for q in (client_id, feedback, ip):
        if isinstance(q, HttpResponse):  # convert failed
            return q

    feedback['client_id'] = client_id
    feedback['source'] = source
    promotion_db.save_feedbacks([feedback])
    logger.info('feedbacks, client_id=%s, ip=%s' % (client_id, ip))

    return {'ok': True}