You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
11 KiB
207 lines
11 KiB
19 years ago
|
// index.java
|
||
17 years ago
|
// (C) 2004-2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||
18 years ago
|
// first published 2004 on http://www.anomic.de
|
||
|
//
|
||
|
// This is a part of YaCy, a peer-to-peer based web search engine
|
||
19 years ago
|
//
|
||
|
// $LastChangedDate$
|
||
|
// $LastChangedRevision$
|
||
|
// $LastChangedBy$
|
||
20 years ago
|
//
|
||
18 years ago
|
// LICENSE
|
||
13 years ago
|
//
|
||
20 years ago
|
// This program is free software; you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation; either version 2 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
//
|
||
20 years ago
|
// You must compile this file with
|
||
20 years ago
|
// javac -classpath .:../classes index.java
|
||
|
// if the shell's current path is HTROOT
|
||
|
|
||
2 years ago
|
package net.yacy.htroot;
|
||
|
|
||
12 years ago
|
import net.yacy.cora.document.analysis.Classification;
|
||
|
import net.yacy.cora.document.analysis.Classification.ContentDomain;
|
||
14 years ago
|
import net.yacy.cora.protocol.RequestHeader;
|
||
7 years ago
|
import net.yacy.data.UserDB;
|
||
13 years ago
|
import net.yacy.search.Switchboard;
|
||
|
import net.yacy.search.SwitchboardConstants;
|
||
8 years ago
|
import net.yacy.search.schema.CollectionSchema;
|
||
12 years ago
|
import net.yacy.server.serverObjects;
|
||
|
import net.yacy.server.serverSwitch;
|
||
20 years ago
|
|
||
|
public class index {
|
||
|
|
||
16 years ago
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||
|
final Switchboard sb = (Switchboard) env;
|
||
18 years ago
|
final serverObjects prop = new serverObjects();
|
||
13 years ago
|
|
||
|
final String forwardTarget = sb.getConfig(SwitchboardConstants.INDEX_FORWARD, "");
|
||
14 years ago
|
if (forwardTarget.length() > 0) {
|
||
|
// forward the page
|
||
|
prop.put("forward", 1);
|
||
|
prop.put("forward_target", forwardTarget);
|
||
|
return prop;
|
||
|
}
|
||
13 years ago
|
|
||
18 years ago
|
// access control
|
||
7 years ago
|
String authenticatedUserName = null;
|
||
|
final boolean adminAuthenticated = sb.verifyAuthentication(header);
|
||
2 years ago
|
|
||
7 years ago
|
if(adminAuthenticated) {
|
||
|
authenticatedUserName = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin");
|
||
7 years ago
|
} else {
|
||
|
final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null;
|
||
|
if(user != null) {
|
||
|
authenticatedUserName = user.getUserName();
|
||
|
}
|
||
7 years ago
|
}
|
||
2 years ago
|
final boolean authenticated = adminAuthenticated || authenticatedUserName != null;
|
||
7 years ago
|
if (post != null) {
|
||
|
if (post.containsKey("publicPage") && !adminAuthenticated) { // Old style parameter : still in use ?
|
||
|
prop.authenticationRequired();
|
||
|
return prop;
|
||
|
}
|
||
|
if (post.containsKey("auth") && !authenticated) { // search with authentication required
|
||
|
prop.authenticationRequired();
|
||
|
return prop;
|
||
|
}
|
||
|
}
|
||
2 years ago
|
|
||
7 years ago
|
prop.put("authSearch", authenticated);
|
||
2 years ago
|
|
||
13 years ago
|
boolean global = (post == null) ? true : post.get("resource", "global").equals("global");
|
||
13 years ago
|
final boolean focus = (post == null) ? true : post.get("focus", "1").equals("1");
|
||
13 years ago
|
|
||
|
int searchoptions = (post == null) ? 0 : Math.min(1, post.getInt("searchoptions", 0));
|
||
11 years ago
|
if (!sb.getConfigBool("search.options", true)) {
|
||
|
searchoptions = 0;
|
||
2 years ago
|
} else {
|
||
8 years ago
|
// show heuristic hint on search option screen (only if heuristic is ON by config)
|
||
10 years ago
|
prop.put("searchoptions_heuristic", sb.getConfigBool(SwitchboardConstants.HEURISTIC_OPENSEARCH, false));
|
||
8 years ago
|
// show date search options (only if dates_in_content_dts search target field is active)
|
||
|
prop.put("searchoptions_datesincontent", sb.index.fulltext().getDefaultConfiguration().contains(CollectionSchema.dates_in_content_dts));
|
||
11 years ago
|
}
|
||
18 years ago
|
final String former = (post == null) ? "" : post.get("former", "");
|
||
18 years ago
|
final int count = Math.min(100, (post == null) ? 10 : post.getInt("count", 10));
|
||
14 years ago
|
final int maximumRecords = sb.getConfigInt(SwitchboardConstants.SEARCH_ITEMS, 10);
|
||
18 years ago
|
final String prefermaskfilter = (post == null) ? "" : post.get("prefermaskfilter", "");
|
||
17 years ago
|
final String constraint = (post == null) ? "" : post.get("constraint", "");
|
||
18 years ago
|
final int type = (post == null) ? 0 : post.getInt("type", 0);
|
||
13 years ago
|
|
||
|
//final boolean indexDistributeGranted = sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, true);
|
||
11 years ago
|
final boolean indexReceiveGranted = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW_SEARCH, true);
|
||
13 years ago
|
global = global && indexReceiveGranted;
|
||
|
|
||
18 years ago
|
// search domain
|
||
13 years ago
|
Classification.ContentDomain contentdom = ContentDomain.TEXT;
|
||
17 years ago
|
final String cds = (post == null) ? "text" : post.get("contentdom", "text");
|
||
15 years ago
|
if (cds.equals("text")) contentdom = ContentDomain.TEXT;
|
||
|
if (cds.equals("audio")) contentdom = ContentDomain.AUDIO;
|
||
|
if (cds.equals("video")) contentdom = ContentDomain.VIDEO;
|
||
|
if (cds.equals("image")) contentdom = ContentDomain.IMAGE;
|
||
|
if (cds.equals("app")) contentdom = ContentDomain.APP;
|
||
13 years ago
|
|
||
19 years ago
|
// we create empty entries for template strings
|
||
16 years ago
|
String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, "");
|
||
|
if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");
|
||
13 years ago
|
prop.put(SwitchboardConstants.GREETING, promoteSearchPageGreeting);
|
||
16 years ago
|
prop.put(SwitchboardConstants.GREETING_HOMEPAGE, sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
|
||
11 years ago
|
prop.put("topmenu_" + SwitchboardConstants.GREETING_HOMEPAGE, sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
|
||
|
prop.put("topmenu_" + SwitchboardConstants.GREETING_SMALL_IMAGE, sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));
|
||
8 years ago
|
prop.put("topmenu_" + SwitchboardConstants.GREETING_IMAGE_ALT, sb.getConfig(SwitchboardConstants.GREETING_IMAGE_ALT, ""));
|
||
16 years ago
|
prop.put(SwitchboardConstants.GREETING_LARGE_IMAGE, sb.getConfig(SwitchboardConstants.GREETING_LARGE_IMAGE, ""));
|
||
8 years ago
|
prop.put(SwitchboardConstants.GREETING_IMAGE_ALT, sb.getConfig(SwitchboardConstants.GREETING_IMAGE_ALT, ""));
|
||
17 years ago
|
prop.putHTML("former", former);
|
||
|
prop.put("num-results", "0");
|
||
|
prop.put("excluded", "0");
|
||
|
prop.put("combine", "0");
|
||
|
prop.put("resultbottomline", "0");
|
||
19 years ago
|
prop.put("searchoptions", searchoptions);
|
||
13 years ago
|
prop.put("searchoptions_maximumRecords", maximumRecords);
|
||
17 years ago
|
prop.put("searchoptions_count-10", (count == 10) ? "1" : "0");
|
||
|
prop.put("searchoptions_count-50", (count == 50) ? "1" : "0");
|
||
|
prop.put("searchoptions_count-100", (count == 100) ? "1" : "0");
|
||
12 years ago
|
prop.put("searchoptions_resource-select", (sb.peers == null || sb.peers.sizeConnected() == 0 || !indexReceiveGranted) ? 0 : global ? 1 : 2);
|
||
17 years ago
|
prop.put("searchoptions_prefermaskoptions", "0");
|
||
|
prop.putHTML("searchoptions_prefermaskoptions_prefermaskfilter", prefermaskfilter);
|
||
18 years ago
|
prop.put("searchoptions_indexofChecked", "");
|
||
7 years ago
|
prop.put("searchoptions_" + SwitchboardConstants.SEARCH_STRICT_CONTENT_DOM,
|
||
|
sb.getConfigBool(SwitchboardConstants.SEARCH_STRICT_CONTENT_DOM,
|
||
|
SwitchboardConstants.SEARCH_STRICT_CONTENT_DOM_DEFAULT) ? 1 : 0);
|
||
19 years ago
|
prop.put("results", "");
|
||
18 years ago
|
prop.put("type", type);
|
||
19 years ago
|
prop.put("depth", "0");
|
||
14 years ago
|
prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
|
||
13 years ago
|
prop.put("focus", focus ? 1 : 0);
|
||
16 years ago
|
prop.putHTML("constraint", constraint);
|
||
15 years ago
|
prop.put("searchdomswitches", sb.getConfigBool("search.text", true) || sb.getConfigBool("search.audio", true) || sb.getConfigBool("search.video", true) || sb.getConfigBool("search.image", true) || sb.getConfigBool("search.app", true) ? 1 : 0);
|
||
13 years ago
|
prop.put("searchdomswitches_searchoptions", searchoptions);
|
||
7 years ago
|
prop.put("searchdomswitches_searchoptions_authSearch", authenticated);
|
||
15 years ago
|
prop.put("searchdomswitches_searchtext", sb.getConfigBool("search.text", true) ? 1 : 0);
|
||
|
prop.put("searchdomswitches_searchaudio", sb.getConfigBool("search.audio", true) ? 1 : 0);
|
||
|
prop.put("searchdomswitches_searchvideo", sb.getConfigBool("search.video", true) ? 1 : 0);
|
||
|
prop.put("searchdomswitches_searchimage", sb.getConfigBool("search.image", true) ? 1 : 0);
|
||
|
prop.put("searchdomswitches_searchapp", sb.getConfigBool("search.app", true) ? 1 : 0);
|
||
15 years ago
|
prop.put("searchdomswitches_searchtext_check", (contentdom == ContentDomain.TEXT) ? "1" : "0");
|
||
|
prop.put("searchdomswitches_searchaudio_check", (contentdom == ContentDomain.AUDIO) ? "1" : "0");
|
||
|
prop.put("searchdomswitches_searchvideo_check", (contentdom == ContentDomain.VIDEO) ? "1" : "0");
|
||
|
prop.put("searchdomswitches_searchimage_check", (contentdom == ContentDomain.IMAGE) ? "1" : "0");
|
||
|
prop.put("searchdomswitches_searchapp_check", (contentdom == ContentDomain.APP) ? "1" : "0");
|
||
14 years ago
|
prop.put("search.navigation", sb.getConfig("search.navigation", "all") );
|
||
|
prop.put("search.verify", sb.getConfig("search.verify", "iffresh") );
|
||
2 years ago
|
|
||
7 years ago
|
handleTopNavBarLoginSection(header, sb, prop, authenticatedUserName);
|
||
2 years ago
|
|
||
17 years ago
|
// online caution timing
|
||
|
sb.localSearchLastAccess = System.currentTimeMillis();
|
||
13 years ago
|
|
||
18 years ago
|
return prop;
|
||
|
}
|
||
7 years ago
|
|
||
|
/**
|
||
|
* Add any eventually relevant information to generate the proper login link or status in the top navigation bar
|
||
|
* @param header the current request headers
|
||
|
* @param sb the server environment
|
||
|
* @param prop the servlet answer object
|
||
|
* @param authenticatedUserName the name of the currently authenticated user or null
|
||
|
*/
|
||
|
private static void handleTopNavBarLoginSection(final RequestHeader header, final Switchboard sb,
|
||
7 years ago
|
final serverObjects prop, final String authenticatedUserName) {
|
||
7 years ago
|
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);
|
||
2 years ago
|
|
||
7 years ago
|
/* The login link targets the same URL as the current location, just adding the 'auth' parameter to indicates that access to extended search features is desired */
|
||
2 years ago
|
final StringBuilder loginURL = new StringBuilder("index.html?auth");
|
||
7 years ago
|
final String query = header.getQueryString();
|
||
|
if(query != null) {
|
||
|
loginURL.append("&").append(query);
|
||
|
}
|
||
2 years ago
|
|
||
|
|
||
7 years ago
|
prop.put("showLogin_loginURL", loginURL.toString());
|
||
|
}
|
||
|
} else {
|
||
|
prop.put("showLogin", 0);
|
||
|
}
|
||
|
}
|
||
19 years ago
|
}
|