diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index a5703e5e..d111e69e 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -51,6 +51,7 @@ class DisplayAction implements ActionInterface return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'This bridge is not whitelisted']), 400); } + // Disable proxy (if enabled and per user's request) if ( Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge') diff --git a/actions/FrontpageAction.php b/actions/FrontpageAction.php index c72dfd57..6ab18d29 100644 --- a/actions/FrontpageAction.php +++ b/actions/FrontpageAction.php @@ -4,6 +4,8 @@ final class FrontpageAction implements ActionInterface { public function __invoke(Request $request): Response { + $token = $request->attribute('token'); + $messages = []; $activeBridges = 0; @@ -20,19 +22,21 @@ final class FrontpageAction implements ActionInterface $body = ''; foreach ($bridgeClassNames as $bridgeClassName) { if ($bridgeFactory->isEnabled($bridgeClassName)) { - $body .= BridgeCard::render($bridgeClassName, $request); + $body .= BridgeCard::render($bridgeClassName, $token); $activeBridges++; } } - // todo: cache this renderered template? - return new Response(render(__DIR__ . '/../templates/frontpage.html.php', [ - 'messages' => $messages, - 'admin_email' => Configuration::getConfig('admin', 'email'), - 'admin_telegram' => Configuration::getConfig('admin', 'telegram'), - 'bridges' => $body, - 'active_bridges' => $activeBridges, - 'total_bridges' => count($bridgeClassNames), + $response = new Response(render(__DIR__ . '/../templates/frontpage.html.php', [ + 'messages' => $messages, + 'admin_email' => Configuration::getConfig('admin', 'email'), + 'admin_telegram' => Configuration::getConfig('admin', 'telegram'), + 'bridges' => $body, + 'active_bridges' => $activeBridges, + 'total_bridges' => count($bridgeClassNames), ])); + + // TODO: The rendered template could be cached, but beware config changes that changes the html + return $response; } } diff --git a/config.default.ini.php b/config.default.ini.php index c6b0779d..c23372d9 100644 --- a/config.default.ini.php +++ b/config.default.ini.php @@ -86,8 +86,8 @@ telegram = "" donations = true [proxy] - -; Sets the proxy url (i.e. "tcp://192.168.0.0:32") +; The HTTP proxy to tunnel requests through +; https://curl.se/libcurl/c/CURLOPT_PROXY.html ; "" = Proxy disabled (default) url = "" diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php index 27285558..f270c1a3 100644 --- a/lib/BridgeCard.php +++ b/lib/BridgeCard.php @@ -2,7 +2,7 @@ final class BridgeCard { - public static function render(string $bridgeClassName, Request $request): string + public static function render(string $bridgeClassName, ?string $token): string { $bridgeFactory = new BridgeFactory(); @@ -14,10 +14,15 @@ final class BridgeCard $description = $bridge->getDescription(); $contexts = $bridge->getParameters(); - if (Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge')) { + // Checkbox for disabling of proxy (if enabled) + if ( + Configuration::getConfig('proxy', 'url') + && Configuration::getConfig('proxy', 'by_bridge') + ) { + $proxyName = Configuration::getConfig('proxy', 'name') ?: Configuration::getConfig('proxy', 'url'); $contexts['global']['_noproxy'] = [ - 'name' => 'Disable proxy (' . (Configuration::getConfig('proxy', 'name') ?: Configuration::getConfig('proxy', 'url')) . ')', - 'type' => 'checkbox' + 'name' => sprintf('Disable proxy (%s)', $proxyName), + 'type' => 'checkbox', ]; } @@ -47,8 +52,6 @@ final class BridgeCard CARD; - $token = $request->attribute('token'); - if (count($contexts) === 0) { // The bridge has zero parameters $card .= self::renderForm($bridgeClassName, '', [], $token); diff --git a/lib/http.php b/lib/http.php index 0d21b958..d1043b33 100644 --- a/lib/http.php +++ b/lib/http.php @@ -113,6 +113,7 @@ final class CurlHttpClient implements HttpClient if ($config['proxy']) { curl_setopt($ch, CURLOPT_PROXY, $config['proxy']); } + if (curl_setopt_array($ch, $config['curl_options']) === false) { throw new \Exception('Tried to set an illegal curl option'); }