~fkooman/vpn-server-api

d424a41c8d05283e2b5b83dd1e387e4dfc218798 — François Kooman 3 months ago 7e5930f
also log "originating" client IP address
4 files changed, 18 insertions(+), 11 deletions(-)

M CHANGES.md
M composer.lock
M src/Api/ConnectionsModule.php
M tests/Api/ConnectionsModuleTest.php
M CHANGES.md => CHANGES.md +3 -0
@@ 1,5 1,8 @@
# Changelog

## 2.2.12 (...)
- also log "originating" client IP address

## 2.2.11 (2021-07-13)
- write connect/disconnect events to [syslog](https://github.com/eduvpn/documentation/blob/v2/LOGGING.md#syslog)


M composer.lock => composer.lock +7 -7
@@ 150,7 150,7 @@
            "dist": {
                "type": "path",
                "url": "../vpn-lib-common",
                "reference": "82274aa605cd2c3aff51eac083fadcd8ea356653"
                "reference": "2ecabaa745f337a3ddeb1a4fe0fc0464cf0aafc1"
            },
            "require": {
                "ext-curl": "*",


@@ 1014,16 1014,16 @@
        },
        {
            "name": "phpunit/php-file-iterator",
            "version": "2.0.3",
            "version": "2.0.4",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
                "reference": "4b49fb70f067272b659ef0174ff9ca40fdaa6357"
                "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/4b49fb70f067272b659ef0174ff9ca40fdaa6357",
                "reference": "4b49fb70f067272b659ef0174ff9ca40fdaa6357",
                "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/28af674ff175d0768a5a978e6de83f697d4a7f05",
                "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05",
                "shasum": ""
            },
            "require": {


@@ 1062,7 1062,7 @@
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
                "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.3"
                "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.4"
            },
            "funding": [
                {


@@ 1070,7 1070,7 @@
                    "type": "github"
                }
            ],
            "time": "2020-11-30T08:25:21+00:00"
            "time": "2021-07-19T06:46:01+00:00"
        },
        {
            "name": "phpunit/php-text-template",

M src/Api/ConnectionsModule.php => src/Api/ConnectionsModule.php +4 -4
@@ 102,13 102,13 @@ class ConnectionsModule implements ServiceModuleInterface
    {
        $profileId = InputValidation::profileId($request->requirePostParameter('profile_id'));
        $commonName = InputValidation::commonName($request->requirePostParameter('common_name'));
        $originatingIp = InputValidation::ipAddress($request->requirePostParameter('originating_ip'));
        $ip4 = InputValidation::ip4($request->requirePostParameter('ip4'));
        $ip6 = InputValidation::ip6($request->requirePostParameter('ip6'));
        $connectedAt = InputValidation::connectedAt($request->requirePostParameter('connected_at'));

        $userId = $this->verifyConnection($profileId, $commonName);
        $this->storage->clientConnect($profileId, $commonName, $ip4, $ip6, new DateTime(sprintf('@%d', $connectedAt)));
        $this->logger->info(sprintf('CONNECT %s (%s) [%s,%s]', $userId, $profileId, $ip4, $ip6));
        $this->logger->info(sprintf('CONNECT %s (%s) [%s => %s,%s]', $userId, $profileId, $originatingIp, $ip4, $ip6));
    }

    /**


@@ 118,9 118,9 @@ class ConnectionsModule implements ServiceModuleInterface
    {
        $profileId = InputValidation::profileId($request->requirePostParameter('profile_id'));
        $commonName = InputValidation::commonName($request->requirePostParameter('common_name'));
        $originatingIp = InputValidation::ipAddress($request->requirePostParameter('originating_ip'));
        $ip4 = InputValidation::ip4($request->requirePostParameter('ip4'));
        $ip6 = InputValidation::ip6($request->requirePostParameter('ip6'));

        $connectedAt = InputValidation::connectedAt($request->requirePostParameter('connected_at'));
        $disconnectedAt = InputValidation::disconnectedAt($request->requirePostParameter('disconnected_at'));
        $bytesTransferred = InputValidation::bytesTransferred($request->requirePostParameter('bytes_transferred'));


@@ 132,7 132,7 @@ class ConnectionsModule implements ServiceModuleInterface
            $userId = $userCertInfo['user_id'];
        }

        $this->logger->info(sprintf('DISCONNECT %s (%s) [%s,%s]', $userId, $profileId, $ip4, $ip6));
        $this->logger->info(sprintf('DISCONNECT %s (%s) [%s => %s,%s]', $userId, $profileId, $originatingIp, $ip4, $ip6));
    }

    /**

M tests/Api/ConnectionsModuleTest.php => tests/Api/ConnectionsModuleTest.php +4 -0
@@ 68,6 68,7 @@ class ConnectionsModuleTest extends TestCase
                [
                    'profile_id' => 'internet',
                    'common_name' => '12345678901234567890123456789012',
                    'originating_ip' => '1.2.3.4',
                    'ip4' => '10.10.10.10',
                    'ip6' => 'fd00:4242:4242:4242::',
                    'connected_at' => '12345678',


@@ 87,6 88,7 @@ class ConnectionsModuleTest extends TestCase
                [
                    'profile_id' => 'acl',
                    'common_name' => '12345678901234567890123456789012',
                    'originating_ip' => '1.2.3.4',
                    'ip4' => '10.10.10.10',
                    'ip6' => 'fd00:4242:4242:4242::',
                    'connected_at' => '12345678',


@@ 110,6 112,7 @@ class ConnectionsModuleTest extends TestCase
                [
                    'profile_id' => 'acl2',
                    'common_name' => '12345678901234567890123456789012',
                    'originating_ip' => '1.2.3.4',
                    'ip4' => '10.10.10.10',
                    'ip6' => 'fd00:4242:4242:4242::',
                    'connected_at' => '12345678',


@@ 129,6 132,7 @@ class ConnectionsModuleTest extends TestCase
                [
                    'profile_id' => 'internet',
                    'common_name' => '12345678901234567890123456789012',
                    'originating_ip' => '1.2.3.4',
                    'ip4' => '10.10.10.10',
                    'ip6' => 'fd00:4242:4242:4242::',
                    'connected_at' => '12345678',