Check for configured base URL as well

Signed-off-by: Julius Härtl <jus@bitgrid.net>
pull/101/head
Julius Härtl 2018-12-03 12:10:03 +01:00
rodzic 03d0259460
commit 0f69a61a09
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4C614C6ED2CDE6DF
2 zmienionych plików z 34 dodań i 16 usunięć

Wyświetl plik

@ -147,10 +147,7 @@ class NavigationController extends Controller {
'firstrun' => false,
'setup' => false,
'isAdmin' => \OC::$server->getGroupManager()->isAdmin($this->userId),
'cliUrl' => $this->config->getSystemValue(
'overwrite.cli.url', \OC::$server->getURLGenerator()
->getBaseUrl()
)
'cliUrl' => $this->getCliUrl()
]
];
@ -195,7 +192,6 @@ class NavigationController extends Controller {
}
private function setupCloudAddress(): string {
return '';
$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
$cloudAddress = rtrim($this->config->getSystemValue('overwrite.cli.url', ''), '/');
@ -209,6 +205,15 @@ class NavigationController extends Controller {
return '';
}
private function getCliUrl() {
$url = rtrim($this->urlGenerator->getBaseUrl(), '/');
$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
if (!$frontControllerActive) {
$url .= '/index.php';
}
return $url;
}
/**
* Display the navigation page of the Social app.
*

Wyświetl plik

@ -29,20 +29,25 @@ use OCP\Http\Client\IClientService;
use OCP\ICache;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
class CheckService {
private $cache;
private $config;
private $clientService;
private $request;
private $urlGenerator;
const CACHE_PREFIX = 'social_check_';
public function __construct(ICache $cache, IConfig $config, IClientService $clientService, IRequest $request) {
public function __construct(ICache $cache, IConfig $config, IClientService $clientService, IRequest $request, IURLGenerator $urlGenerator) {
$this->cache = $cache;
$this->config = $config;
$this->clientService = $clientService;
$this->request = $request;
$this->urlGenerator = $urlGenerator;
}
public function checkDefault(): array {
@ -65,19 +70,27 @@ class CheckService {
if ($state === true) {
return true;
}
try {
$url = $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . '/.well-known/webfinger';
$response = $this->clientService->newClient()->get($url);
if ($response->getStatusCode() === Http::STATUS_OK) {
$this->cache->set(self::CACHE_PREFIX . 'wellknown', 'true', 3600);
return true;
}
} catch (\GuzzleHttp\Exception\ClientException $e) {
} catch (\Exception $e) {
$address = $this->config->getAppValue('social', 'address', '');
if ($address !== '' && $this->requestWellKnown($address)) {
return true;
}
if ($this->requestWellKnown($this->request->getServerProtocol() . '://' . $this->request->getServerHost())) {
return true;
}
if ($this->requestWellKnown($this->urlGenerator->getBaseUrl())) {
return true;
}
return false;
}
private function requestWellKnown($base) {
try {
$url = \OC::$server->getURLGenerator()->getBaseUrl() . '/.well-known/webfinger';
$url = $base . '/.well-known/webfinger';
$response = $this->clientService->newClient()->get($url);
if ($response->getStatusCode() === Http::STATUS_OK) {
$this->cache->set(self::CACHE_PREFIX . 'wellknown', 'true', 3600);