예제 #1
0
 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));
     });
 }
예제 #2
0
 public function init(Service $service)
 {
     $service->get('/user_groups', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-user-portal']);
         $userId = $request->getQueryParameter('user_id');
         InputValidation::userId($userId);
         $groupMembership = [];
         foreach ($this->groupProviders as $groupProvider) {
             $groupMembership = array_merge($groupMembership, $groupProvider->getGroups($userId));
         }
         return new ApiResponse('user_groups', $groupMembership);
     });
 }
예제 #3
0
 public function init(Service $service)
 {
     $service->get('/log', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         $dateTime = $request->getQueryParameter('date_time');
         InputValidation::dateTime($dateTime);
         $dateTimeUnix = strtotime($dateTime);
         $ipAddress = $request->getQueryParameter('ip_address');
         InputValidation::ipAddress($ipAddress);
         return new ApiResponse('log', $this->get($dateTimeUnix, $ipAddress));
     });
     $service->get('/stats', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         $statsFile = sprintf('%s/stats.json', $this->dataDir);
         return new ApiResponse('stats', FileIO::readJsonFile($statsFile));
     });
 }
예제 #4
0
 public function init(Service $service)
 {
     $service->get('/server_pools', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         $responseData = [];
         foreach (array_keys($this->instanceConfig->v('vpnPools')) as $poolId) {
             $poolConfig = new PoolConfig($this->instanceConfig->v('vpnPools', $poolId));
             $responseData[$poolId] = $poolConfig->v();
         }
         return new ApiResponse('server_pools', $responseData);
     });
     $service->get('/server_pool', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         $poolId = $request->getQueryParameter('pool_id');
         InputValidation::poolId($poolId);
         $poolConfig = new PoolConfig($this->instanceConfig->v('vpnPools', $poolId));
         return new ApiResponse('server_pool', $poolConfig->v());
     });
 }
예제 #5
0
 public function init(Service $service)
 {
     $service->get('/disabled_common_names', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         return new ApiResponse('disabled_common_names', $this->commonNames->getDisabled());
     });
     $service->post('/disable_common_name', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         $commonName = $request->getPostParameter('common_name');
         InputValidation::commonName($commonName);
         $this->logger->info(sprintf('disabling common_name "%s"', $commonName));
         return new ApiResponse('disable_common_name', $this->commonNames->setDisabled($commonName));
     });
     $service->post('/enable_common_name', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         $commonName = $request->getPostParameter('common_name');
         InputValidation::commonName($commonName);
         $this->logger->info(sprintf('enabling common_name "%s"', $commonName));
         return new ApiResponse('enable_common_name', $this->commonNames->setEnabled($commonName));
     });
 }
예제 #6
0
 public function init(Service $service)
 {
     // DISABLED
     $service->get('/disabled_users', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         return new ApiResponse('disabled_users', $this->users->getDisabled());
     });
     $service->get('/is_disabled_user', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         $userId = $request->getQueryParameter('user_id');
         InputValidation::userId($userId);
         return new ApiResponse('is_disabled_user', $this->users->isDisabled($userId));
     });
     $service->post('/disable_user', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         $userId = $request->getPostParameter('user_id');
         InputValidation::userId($userId);
         $this->logger->info(sprintf('disabling user "%s"', $userId));
         return new ApiResponse('disable_user', $this->users->setDisabled($userId));
     });
     $service->post('/enable_user', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         $userId = $request->getPostParameter('user_id');
         InputValidation::userId($userId);
         $this->logger->info(sprintf('enabling user "%s"', $userId));
         return new ApiResponse('enable_user', $this->users->setEnabled($userId));
     });
     // OTP_SECRETS
     $service->get('/has_otp_secret', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
         $userId = $request->getQueryParameter('user_id');
         InputValidation::userId($userId);
         return new ApiResponse('has_otp_secret', $this->users->hasOtpSecret($userId));
     });
     $service->post('/set_otp_secret', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-user-portal']);
         $userId = $request->getPostParameter('user_id');
         InputValidation::userId($userId);
         $otpSecret = $request->getPostParameter('otp_secret');
         InputValidation::otpSecret($otpSecret);
         return new ApiResponse('set_otp_secret', $this->users->setOtpSecret($userId, $otpSecret));
     });
     $service->post('/delete_otp_secret', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-admin-portal']);
         $userId = $request->getPostParameter('user_id');
         InputValidation::userId($userId);
         return new ApiResponse('delete_otp_secret', $this->users->deleteOtpSecret($userId));
     });
     // VOOT_TOKENS
     $service->get('/has_voot_token', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-user-portal', 'vpn-admin-portal']);
         $userId = $request->getQueryParameter('user_id');
         InputValidation::userId($userId);
         return new ApiResponse('has_voot_token', $this->users->hasVootToken($userId));
     });
     $service->post('/set_voot_token', function (Request $request, array $hookData) {
         Utils::requireUser($hookData, ['vpn-user-portal']);
         $userId = $request->getPostParameter('user_id');
         InputValidation::userId($userId);
         $vootToken = $request->getPostParameter('voot_token');
         InputValidation::vootToken($vootToken);
         return new ApiResponse('set_voot_token', $this->users->setVootToken($userId, $vootToken));
     });
 }