@ -101,14 +101,23 @@ public class yacysearch {
final Switchboard sb = ( Switchboard ) env ;
sb . localSearchLastAccess = System . currentTimeMillis ( ) ;
final boolean authorized = sb . verifyAuthentication ( header ) ;
final boolean searchAllowed = sb . getConfigBool ( SwitchboardConstants . PUBLIC_SEARCHPAGE , true ) | | authorized ;
String authenticatedUserName = null ;
final boolean adminAuthenticated = sb . verifyAuthentication ( header ) ;
final boolean searchAllowed = sb . getConfigBool ( SwitchboardConstants . PUBLIC_SEARCHPAGE , true ) | | adminAuthenticated ;
boolean authenticated = sb . adminAuthenticated ( header ) > = 2 ;
if ( ! authenticated ) {
boolean extendedSearchRights = adminAuthenticated ;
if ( adminAuthenticated ) {
authenticatedUserName = sb . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME , "admin" ) ;
}
if ( ! extendedSearchRights ) {
final UserDB . Entry user = sb . userDB ! = null ? sb . userDB . getUser ( header ) : null ;
authenticated = ( user ! = null & & user . hasRight ( UserDB . AccessRight . EXTENDED_SEARCH_RIGHT ) ) ;
if ( user ! = null ) {
extendedSearchRights = user . hasRight ( UserDB . AccessRight . EXTENDED_SEARCH_RIGHT ) ;
authenticatedUserName = user . getUserName ( ) ;
}
}
final boolean localhostAccess = header . accessFromLocalhost ( ) ;
final String promoteSearchPageGreeting =
( env . getConfigBool ( SwitchboardConstants . GREETING_NETWORK_NAME , false ) ) ? env . getConfig (
@ -118,7 +127,7 @@ public class yacysearch {
// in case that the crawler is running and the search user is the peer admin, we expect that the user wants to check recently crawled document
// to ensure that recent crawl results are inside the search results, we do a soft commit here. This is also important for live demos!
if ( authenticated & & sb . getThread ( SwitchboardConstants . CRAWLJOB_LOCAL_CRAWL ) . getJobCount ( ) > 0 ) {
if ( extendedSearchRights & & sb . getThread ( SwitchboardConstants . CRAWLJOB_LOCAL_CRAWL ) . getJobCount ( ) > 0 ) {
sb . index . fulltext ( ) . commit ( true ) ;
}
final boolean focus = ( post = = null ) ? true : post . get ( "focus" , "1" ) . equals ( "1" ) ;
@ -198,7 +207,7 @@ public class yacysearch {
return prop ;
}
if ( post . containsKey ( "auth" ) & & ! authenticated ) {
if ( post . containsKey ( "auth" ) & & ! extendedSearchRights ) {
/ *
* Access to authentication protected features is explicitely requested here
* but no authentication is provided : ask now for authentication .
@ -209,7 +218,7 @@ public class yacysearch {
prop . authenticationRequired ( ) ;
return prop ;
}
// check for JSONP
if ( post . containsKey ( "callback" ) ) {
final String jsonp = post . get ( "callback" ) + "([" ;
@ -266,7 +275,7 @@ public class yacysearch {
if ( ! global ) {
// we count only searches on the local peer here, because global searches
// are counted on the target peer to preserve privacy of the searcher
if ( authenticated ) {
if ( extendedSearchRights ) {
// local or authenticated search requests are counted separately
// because they are not part of a public available peer statistic
sb . searchQueriesRobinsonFromLocal + + ;
@ -299,7 +308,7 @@ public class yacysearch {
ConcurrentLog . warn ( "LOCAL_SEARCH" , "ACCESS CONTROL: BLACKLISTED CLIENT FROM "
+ client
+ " gets no permission to search" ) ;
} else if ( ! authenticated & & ! localhostAccess & & ! intranetMode ) {
} else if ( ! extendedSearchRights & & ! localhostAccess & & ! intranetMode ) {
// in case that we do a global search or we want to fetch snippets, we check for DoS cases
synchronized ( trackerHandles ) {
final int accInThreeSeconds =
@ -659,7 +668,7 @@ public class yacysearch {
DigestURL . hosthashess ( sb . getConfig ( "search.excludehosth" , "" ) ) ,
MultiProtocolURL . TLD_any_zone_filter ,
client ,
authenticated ,
extendedSearchRights ,
indexSegment ,
ranking ,
header . get ( HeaderFramework . USER_AGENT , "" ) ,
@ -724,7 +733,7 @@ public class yacysearch {
theSearch . resortCachedResults ( ) ;
}
if ( startRecord = = 0 & & authenticated & & ! stealthmode ) {
if ( startRecord = = 0 & & extendedSearchRights & & ! stealthmode ) {
if ( modifier . sitehost ! = null & & sb . getConfigBool ( SwitchboardConstants . HEURISTIC_SITE , false ) ) {
sb . heuristicSite ( theSearch , modifier . sitehost ) ;
}
@ -776,7 +785,7 @@ public class yacysearch {
RequestHeader . FileType . HTML ,
0 ,
theQuery ,
suggestion , true , authenticated ) . toString ( ) ) ;
suggestion , true , extendedSearchRights ) . toString ( ) ) ;
prop . put ( "didYouMean_suggestions_" + meanCount + "_sep" , "|" ) ;
meanCount + + ;
} catch ( final ConcurrentModificationException e ) {
@ -844,7 +853,7 @@ public class yacysearch {
prop . put ( "num-results_globalresults_remoteIndexCount" , Formatter . number ( theSearch . remote_rwi_available . get ( ) + theSearch . remote_solr_available . get ( ) , true ) ) ;
prop . put ( "num-results_globalresults_remotePeerCount" , Formatter . number ( theSearch . remote_rwi_peerCount . get ( ) + theSearch . remote_solr_peerCount . get ( ) , true ) ) ;
final boolean jsResort = global & & authenticated // for now enable JavaScript resorting only for authenticated users as it requires too much resources per search request
final boolean jsResort = global & & extendedSearchRights // for now enable JavaScript resorting only for authenticated users as it requires too much resources per search request
& & ( contentdom = = ContentDomain . ALL | | contentdom = = ContentDomain . TEXT ) // For now JavaScript resorting can only be applied for text search
& & sb . getConfigBool ( SwitchboardConstants . SEARCH_JS_RESORT , SwitchboardConstants . SEARCH_JS_RESORT_DEFAULT ) ;
prop . put ( "jsResort" , jsResort ) ;
@ -854,7 +863,7 @@ public class yacysearch {
* eventually including fetched results with higher ranks from the Solr and RWI stacks * /
prop . put ( "resortEnabled" , ! jsResort & & global & & ! stealthmode & & theSearch . resortCacheAllowed . availablePermits ( ) > 0 ? 1 : 0 ) ;
prop . put ( "resortEnabled_url" ,
QueryParams . navurlBase ( RequestHeader . FileType . HTML , theQuery , null , true , authenticated )
QueryParams . navurlBase ( RequestHeader . FileType . HTML , theQuery , null , true , extendedSearchRights )
. append ( "&startRecord=" ) . append ( startRecord ) . append ( "&resortCachedResults=true" )
. toString ( ) ) ;
@ -893,8 +902,26 @@ public class yacysearch {
prop . put ( "depth" , "0" ) ;
prop . put ( "localQuery" , theSearch . query . isLocal ( ) ? "1" : "0" ) ;
prop . put ( "jsResort_localQuery" , theSearch . query . isLocal ( ) ? "1" : "0" ) ;
final boolean showLogin = sb . getConfigBool ( SwitchboardConstants . SEARCH_PUBLIC_TOP_NAV_BAR_LOGIN ,
SwitchboardConstants . SEARCH_PUBLIC_TOP_NAV_BAR_LOGIN_DEFAULT ) ;
if ( showLogin ) {
if ( authenticatedUserName ! = null ) {
/* Show the name of the authenticated user */
prop . put ( "showLogin" , 1 ) ;
prop . put ( "showLogin_userName" , authenticatedUserName ) ;
} else {
/* Show a login link */
prop . put ( "showLogin" , 2 ) ;
prop . put ( "showLogin_loginURL" ,
QueryParams . navurlBase ( RequestHeader . FileType . HTML , theQuery , null , true , true ) . toString ( ) ) ;
}
} else {
prop . put ( "showLogin" , 0 ) ;
}
}
prop . put ( "focus" , focus ? 1 : 0 ) ; // focus search field
prop . put ( "searchagain" , global ? "1" : "0" ) ;
String former = originalquerystring . replaceAll ( Segment . catchallString , "*" ) ;