Skip to content

Commit

Permalink
Add skosmos:trustedProxies option
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Nov 29, 2019
1 parent 1285266 commit 5bfa6cf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
skosmos:serviceName "Skosmos @ Biblioteksentralen" ;
# customize the base element. Set this if the automatic base url detection doesn't work. For example setups behind a proxy.
# skosmos:baseHref "http://fuseki_cache/80/" ;
skosmos:trustedProxies ( "172.104.146.109" ) ;
# interface languages available, and the corresponding system locales
skosmos:languages (
[ rdfs:label "nb" ; rdf:value "nb_NO.utf8" ]
Expand All @@ -59,7 +60,7 @@
skosmos:feedbackSender "" ;
# email address to set as the envelope sender for feedback messages
skosmos:feedbackEnvelopeSender "" ;
# whether to display the ui language selection as a dropdown (useful for cases where there are more than 3 languages)
# whether to display the ui language selection as a dropdown (useful for cases where there are more than 3 languages)
skosmos:uiLanguageDropdown false ;
# whether to enable the spam honey pot or not, enabled by default
skosmos:uiHoneypotEnabled true ;
Expand Down
3 changes: 2 additions & 1 deletion config.ttl.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
skosmos:serviceName "Skosmos" ;
# customize the base element. Set this if the automatic base url detection doesn't work. For example setups behind a proxy.
# skosmos:baseHref "http://localhost/Skosmos/" ;
# skosmos:trustedProxies ( "IP1" "IP2" ) ;
# interface languages available, and the corresponding system locales
skosmos:languages (
[ rdfs:label "fi" ; rdf:value "fi_FI.utf8" ]
Expand All @@ -59,7 +60,7 @@
skosmos:feedbackSender "" ;
# email address to set as the envelope sender for feedback messages
skosmos:feedbackEnvelopeSender "" ;
# whether to display the ui language selection as a dropdown (useful for cases where there are more than 3 languages)
# whether to display the ui language selection as a dropdown (useful for cases where there are more than 3 languages)
skosmos:uiLanguageDropdown false ;
# whether to enable the spam honey pot or not, enabled by default
skosmos:uiHoneypotEnabled true ;
Expand Down
14 changes: 10 additions & 4 deletions controller/Controller.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Symfony\Component\HttpFoundation\Request as HttpRequest;

/**
* Handles all the requests from the user and changes the view accordingly.
*/
Expand Down Expand Up @@ -84,10 +86,14 @@ protected function negotiateFormat($choices, $accept, $format)

private function guessBaseHref()
{
// TODO: Could we refactor the Skosmos Request class to extend Symfony Request?
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$host = $request->getSchemeAndHttpHost();
$port = $request->getPort();
// Q: Could we refactor the Request class to extend Symfony Request rather than wrapping it?
HttpRequest::setTrustedProxies(
$this->model->getConfig()->getTrustedProxies(),
HttpRequest::HEADER_X_FORWARDED_ALL
);
$httpRequest = HttpRequest::createFromGlobals();
$host = $httpRequest->getSchemeAndHttpHost();
$port = $httpRequest->getPort();

# Test this?
# $baseUrl = $request->getBaseUrl();
Expand Down
15 changes: 15 additions & 0 deletions model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,19 @@ public function getCollationEnabled()
{
return $this->getBoolean('skosmos:sparqlCollationEnabled', FALSE);
}

/**
* @return array
*/
public function getTrustedProxies()
{
$trustedProxies = array();
$trustedProxiesResource = $this->getResource()->getResource("skosmos:trustedProxies");
if ($trustedProxiesResource) {
foreach ($trustedProxiesResource as $resource) {
$trustedProxies[] = $resource->getValue();
}
}
return $trustedProxies;
}
}
5 changes: 5 additions & 0 deletions tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function testGetBaseHref()
$this->assertEquals("http://tests.localhost/Skosmos/", $this->config->getBaseHref());
}

public function testGetTrustedProxies()
{
$this->assertEquals(["1.2.3.4"], $this->config->getTrustedProxies());
}

public function testGetLanguages()
{
$this->assertEquals(array('en' => 'en_GB.utf8'), $this->config->getLanguages());
Expand Down
2 changes: 2 additions & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
skosmos:serviceName "Skosmos being tested" ;
# customize the base element. Set this if the automatic base url detection doesn't work. For example setups behind a proxy.
skosmos:baseHref "http://tests.localhost/Skosmos/" ;
# setting a trusted proxy allows for correct automatic url generation behind a proxy
skosmos:trustedProxies ( "1.2.3.4" ) ;
# interface languages available, and the corresponding system locales
skosmos:languages ( [ rdfs:label "en" ; rdf:value "en_GB.utf8" ] ) ;
# how many results (maximum) to load at a time on the search results page
Expand Down

0 comments on commit 5bfa6cf

Please sign in to comment.