public function init(Service $service)
 {
     $service->get('/client_connections', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         return new ApiResponse('client_connections', $this->serverManager->connections());
     });
     $service->post('/kill_client', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         $commonName = $request->getPostParameter('common_name');
         InputValidation::commonName($commonName);
         return new ApiResponse('kill_client', $this->serverManager->kill($commonName));
     });
 }
 public function testGetStatus()
 {
     $serverManager = new ServerManager(new InstanceConfig(['instanceNumber' => 1, 'vpnPools' => ['default' => ['name' => 'Default Instance', 'hostName' => 'vpn.example', 'extIf' => 'eth0', 'range' => '10.42.42.0/24', 'range6' => 'fd00:4242:4242::/48', 'dns' => ['8.8.8.8', '2001:4860:4860::8888'], 'routes' => ['192.168.1.0/24', 'fd00:1010:1010::/48']]]]), new TestSocket('connections'), new NullLogger());
     $this->assertSame([['id' => 'default', 'connections' => [['common_name' => 'fkooman_samsung_i9300', 'user_id' => 'fkooman', 'name' => 'samsung_i9300', 'real_address' => '91.64.87.183:43103', 'bytes_in' => 18301, 'bytes_out' => 30009, 'connected_since' => 1451323167, 'virtual_address' => ['fd00:4242:4242::1003', '10.42.42.5']]]]], $serverManager->connections());
 }
Beispiel #3
0
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once sprintf('%s/vendor/autoload.php', dirname(__DIR__));
use SURFnet\VPN\Server\InstanceConfig;
use SURFnet\VPN\Common\Logger;
use SURFnet\VPN\Server\OpenVpn\ServerManager;
use SURFnet\VPN\Server\OpenVpn\ManagementSocket;
use SURFnet\VPN\Common\CliParser;
try {
    $p = new CliParser('Get the connection status of an instance', ['instance' => ['the instance', true, true]]);
    $opt = $p->parse($argv);
    if ($opt->e('help')) {
        echo $p->help();
        exit(0);
    }
    $configFile = sprintf('%s/config/%s/config.yaml', dirname(__DIR__), $opt->v('instance'));
    $config = InstanceConfig::fromFile($configFile);
    $serverManager = new ServerManager($config, new ManagementSocket(), new Logger($argv[0]));
    var_dump($serverManager->connections());
} catch (Exception $e) {
    echo sprintf('ERROR: %s', $e->getMessage()) . PHP_EOL;
    exit(1);
}