anonymize example

            $net = '1';
            $this->sBasketData[CartKey::AMOUNT_WITH_TAX_NUMERIC] = $this->sBasketData[CartKey::AMOUNT_NET_NUMERIC];
            $this->sShippingcostsNumeric = $this->sShippingcostsNumericNet;
            $taxfree = '1';
        }

        $partner = $this->getPartnerCode(
            $this->sUserData['additional']['user']['affiliate']
        );

        $ip = Shopware()->Container()->get(IpAnonymizerInterface::class)
            ->anonymize(
                (string) Shopware()->Container()->get('request_stack')->getCurrentRequest()->getClientIp()
            );
        $orderParams = [
            'ordernumber' => $orderNumber,
            'userID' => $this->sUserData['additional']['user']['id'],
            'invoice_amount' => $this->sBasketData[CartKey::AMOUNT_WITH_TAX_NUMERIC],
            'invoice_amount_net' => $this->sBasketData[CartKey::AMOUNT_NET_NUMERIC],
            'invoice_shipping' => (float) $this->sShippingcostsNumeric,
            'invoice_shipping_net' => (float) $this->sShippingcostsNumericNet,
            'invoice_shipping_tax_rate' => isset($this->sBasketData[CheckoutKey::SHIPPING_COSTS_TAX_PROPORTIONAL]) ? 0 : ($this->sBasketData[CheckoutKey::SHIPPING_COSTS_TAX] ?? 0),
            'ordertime' => new Zend_Db_Expr('NOW()'),
            
'invalid proxy wildcard' => ['192.168.20.13', '*'],
            'invalid proxy missing netmask' => ['192.168.20.13', '0.0.0.0'],
            'invalid request IP with invalid proxy wildcard' => ['0.0.0.0', '*'],
        ];
    }

    /** * @dataProvider anonymizedIpData */
    public function testAnonymize($ip$expected)
    {
        $this->assertSame($expected, IpUtils::anonymize($ip));
    }

    public static function anonymizedIpData()
    {
        return [
            ['192.168.1.1', '192.168.1.0'],
            ['1.2.3.4', '1.2.3.0'],
            ['2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603::'],
            ['2a01:198:603:10:396e:4789:8e99:890f', '2a01:198:603:10::'],
            ['::1', '::'],
            ['0:0:0:0:0:0:0:1', '::'],
            [
if (!$data->getValue()) {
            return;
        }

        if ($this->configService->get(self::CONFIG_KEY)) {
            yield $field->getStorageName() => $data->getValue();

            return;
        }

        yield $field->getStorageName() => IPUtils::anonymize($data->getValue());
    }

    public function decode(Field $field, mixed $value): ?string
    {
        return $value;
    }
}

    public function createLogAction(Request $request)
    {
        $this->front->Plugins()->Json()->setRenderer(true);

        try {
            $params = $request->request->all();
            $params['key'] = html_entity_decode($params['key']);

            $ip = $this->ipAnonymizer->anonymize($request->getClientIp());

            $logModel = new Log();
            $logModel->fromArray($params);
            $logModel->setDate(new DateTime('now'));
            $logModel->setIpAddress($ip);
            $logModel->setUserAgent($request->server->get('HTTP_USER_AGENT', 'Unknown'));

            $this->em->persist($logModel);
            $this->em->flush();

            $data = $this->em->toArray($logModel);

            

    public function refreshCurrentUsers(Enlight_Controller_Request_Request $request)
    {
        $sql = ' INSERT INTO s_statistics_currentusers (remoteaddr, page, `time`, userID, deviceType) VALUES (?, ?, NOW(), ?, ?)';

        $ip = $this->get(IpAnonymizerInterface::class)->anonymize($request->getClientIp());

        Shopware()->Db()->query($sql[
            $ip,
            $request->getParam('requestPage', $request->getRequestUri()),
            empty(Shopware()->Session()->get('sUserId')) ? 0 : (int) Shopware()->Session()->get('sUserId'),
            $request->getDeviceType(),
        ]);
    }

    /** * Refresh visitor log * * @throws Exception * * @return void */

        $this->ipAnonymizer = $ipAnonymizer;
        $this->doAnonymize = $config->get('anonymizeIp');
    }

    /** * {@inheritdoc} */
    public function anonymize($ip)
    {
        if ($this->doAnonymize) {
            return $this->ipAnonymizer->anonymize($ip);
        }

        return $ip;
    }
}
$names = explode(';', $this->_elements[$key]['name']);
                $content = str_replace(
                    ['{sVars.' . $names[0] . '}', '{sVars.' . $names[1] . '}'],
                    [$value[0]$value[1]],
                    $content
                );
            } else {
                $content = str_replace('{sVars.' . $this->_elements[$key]['name'] . '}', $value$content);
            }
        }

        $ip = $this->get(IpAnonymizerInterface::class)->anonymize($this->Request()->getClientIp());

        $content = str_replace(
            ['{sIP}', '{sDateTime}', '{sShopname}'],
            [$ipdate('d.m.Y h:i:s')Shopware()->Config()->get('shopName')],
            $content
        );

        return strip_tags($content);
    }
}
$orderId = $this->createOrderWithRemoteAddress($remoteAddress);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('orderId', $orderId));

        $result = $this->getContainer()->get('order_customer.repository')
            ->search($criteria, Context::createDefaultContext())
            ->first();

        static::assertNotEmpty($result);
        static::assertNotSame($remoteAddress$result->getRemoteAddress());
        static::assertSame(IPUtils::anonymize($remoteAddress)$result->getRemoteAddress());
    }

    public function testRemoteAddressSerializerNoAnonymize(): void
    {
        $this->setConfig(true);

        $remoteAddress = '127.0.0.1';
        $orderId = $this->createOrderWithRemoteAddress($remoteAddress);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('orderId', $orderId));

        
public function testUpdateRemoteAddressByLogin(): void
    {
        $email = Uuid::randomHex() . '@example.com';

        $customerId = $this->login($email);

        $remoteAddress = $this->browser->getRequest()->getClientIp();

        $customer = $this->fetchCustomerById($customerId);

        static::assertNotSame($customer->getRemoteAddress()$remoteAddress);
        static::assertSame($customer->getRemoteAddress(), IpUtils::anonymize((string) $remoteAddress));
    }

    private function login(string $email): string
    {
        $customerId = $this->createCustomer($email);

        $this->browser->request('POST', '/store-api/account/login', [
            'username' => $email,
            'password' => 'shopware',
        ]);

        
Home | Imprint | This part of the site doesn't use cookies.