private function makeRequest($requestMethod, $pathInfo, array $getData = [], array $postData = []) { $response = $this->service->run(new Request(['SERVER_PORT' => 80, 'SERVER_NAME' => 'vpn.example', 'REQUEST_METHOD' => $requestMethod, 'REQUEST_URI' => sprintf('/%s', $pathInfo), 'SCRIPT_NAME' => '/index.php'], $getData, $postData)); return json_decode($response->getBody(), true); }
$service->addAfterHook('no_cache', new NoCacheHook()); // Authentication $authMethod = $config->v('authMethod'); $tpl->addDefault(['authMethod' => $authMethod]); $session = new Session($request->getServerName(), $request->getRoot(), $config->v('secureCookie')); switch ($authMethod) { case 'MellonAuthentication': $service->addBeforeHook('auth', new MellonAuthenticationHook($config->v('MellonAuthentication', 'attribute'))); break; case 'FormAuthentication': $tpl->addDefault(['_show_logout' => true]); $service->addBeforeHook('auth', new FormAuthenticationHook($session, $tpl)); $service->addModule(new FormAuthenticationModule($config->v('FormAuthentication'), $session, $tpl)); break; default: throw new RuntimeException('unsupported authentication mechanism'); } // vpn-server-api $serverClient = new ServerClient(new GuzzleHttpClient(['defaults' => ['auth' => [$config->v('apiUser'), $config->v('apiPass')]]]), $config->v('apiUri')); $service->addBeforehook('two_factor', new TwoFactorHook($session, $tpl, $serverClient)); // two factor module $twoFactorModule = new TwoFactorModule($serverClient, $session, $tpl); $service->addModule($twoFactorModule); $adminPortalModule = new AdminPortalModule($tpl, $serverClient); $service->addModule($adminPortalModule); $service->run($request)->send(); } catch (Exception $e) { $logger->error($e->getMessage()); $response = new HtmlResponse($e->getMessage(), 500); $response->send(); }