2005-04-07 21:19:42 +02:00
|
|
|
// SettingsAck_p.java
|
|
|
|
// -----------------------
|
|
|
|
// part of YaCy
|
2008-07-20 19:14:51 +02:00
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
2005-04-07 21:19:42 +02:00
|
|
|
// first published on http://www.anomic.de
|
|
|
|
// Frankfurt, Germany, 2004, 2005
|
2005-10-17 17:46:12 +02:00
|
|
|
//
|
|
|
|
// $LastChangedDate$
|
|
|
|
// $LastChangedRevision$
|
|
|
|
// $LastChangedBy$
|
2005-04-07 21:19:42 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2005-05-12 19:50:45 +02:00
|
|
|
// You must compile this file with
|
2005-04-07 21:19:42 +02:00
|
|
|
// javac -classpath .:../Classes SettingsAck_p.java
|
|
|
|
// if the shell's current path is HTROOT
|
|
|
|
|
2005-11-15 16:03:15 +01:00
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.SocketException;
|
2005-05-24 17:47:50 +02:00
|
|
|
import java.util.HashMap;
|
2005-05-17 10:25:04 +02:00
|
|
|
import java.util.Iterator;
|
2006-03-07 09:33:28 +01:00
|
|
|
import java.util.StringTokenizer;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.PatternSyntaxException;
|
2005-07-04 13:09:48 +02:00
|
|
|
|
2010-04-08 02:11:32 +02:00
|
|
|
import net.yacy.kelondro.data.meta.DigestURI;
|
2009-10-10 01:22:22 +02:00
|
|
|
import net.yacy.kelondro.order.Base64Order;
|
|
|
|
import net.yacy.kelondro.order.Digest;
|
2009-10-10 03:14:19 +02:00
|
|
|
import net.yacy.kelondro.util.DateFormatter;
|
|
|
|
import net.yacy.kelondro.util.Formatter;
|
2009-10-10 01:22:22 +02:00
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
import de.anomic.http.server.HTTPDemon;
|
|
|
|
import de.anomic.http.server.HTTPDProxyHandler;
|
2009-10-11 23:29:18 +02:00
|
|
|
import de.anomic.http.server.RequestHeader;
|
2009-07-19 22:37:44 +02:00
|
|
|
import de.anomic.search.Switchboard;
|
2005-07-04 13:09:48 +02:00
|
|
|
import de.anomic.server.serverCore;
|
2005-05-05 07:36:42 +02:00
|
|
|
import de.anomic.server.serverObjects;
|
|
|
|
import de.anomic.server.serverSwitch;
|
|
|
|
import de.anomic.yacy.yacyCore;
|
|
|
|
import de.anomic.yacy.yacySeed;
|
2005-05-17 10:25:04 +02:00
|
|
|
import de.anomic.yacy.yacySeedUploader;
|
2005-04-07 21:19:42 +02:00
|
|
|
|
|
|
|
public class SettingsAck_p {
|
|
|
|
|
2008-05-03 11:06:00 +02:00
|
|
|
private static boolean nothingChanged = false;
|
2005-06-03 04:43:35 +02:00
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
2005-04-07 21:19:42 +02:00
|
|
|
// return variable that accumulates replacements
|
2008-08-02 14:12:04 +02:00
|
|
|
final serverObjects prop = new serverObjects();
|
2009-07-19 22:37:44 +02:00
|
|
|
final Switchboard sb = (Switchboard) env;
|
2005-04-07 21:19:42 +02:00
|
|
|
|
2008-03-25 21:40:54 +01:00
|
|
|
// get referer for backlink
|
2010-04-08 02:11:32 +02:00
|
|
|
final DigestURI referer = header.referer();
|
|
|
|
prop.put("referer", (referer == null) ? "Settings_p.html" : referer.toNormalform(true, true));
|
2005-04-07 21:19:42 +02:00
|
|
|
//if (post == null) System.out.println("POST: NULL"); else System.out.println("POST: " + post.toString());
|
|
|
|
|
|
|
|
if (post == null) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "1");//no information submitted
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// admin password
|
|
|
|
if (post.containsKey("adminaccount")) {
|
|
|
|
// read and process data
|
2008-08-02 14:12:04 +02:00
|
|
|
final String user = post.get("adminuser");
|
|
|
|
final String pw1 = post.get("adminpw1");
|
|
|
|
final String pw2 = post.get("adminpw2");
|
2005-04-07 21:19:42 +02:00
|
|
|
// do checks
|
|
|
|
if ((user == null) || (pw1 == null) || (pw2 == null)) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "1");//error with submitted information
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
if (user.length() == 0) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "2");//username must be given
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
if (!(pw1.equals(pw2))) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "3");//pw check failed
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
// check passed. set account:
|
2009-07-19 22:37:44 +02:00
|
|
|
env.setConfig(HTTPDemon.ADMIN_ACCOUNT_B64MD5, Digest.encodeMD5Hex(Base64Order.standardCoder.encodeString(user + ":" + pw1)));
|
2005-04-07 21:19:42 +02:00
|
|
|
env.setConfig("adminAccount", "");
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "5");//admin account changed
|
|
|
|
prop.putHTML("info_user", user);
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// proxy password
|
|
|
|
if (post.containsKey("proxyaccount")) {
|
2005-11-15 16:03:15 +01:00
|
|
|
/*
|
|
|
|
* set new port
|
|
|
|
*/
|
2008-08-02 14:12:04 +02:00
|
|
|
final String port = post.get("port");
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.putHTML("info_port", port);
|
2005-11-15 16:03:15 +01:00
|
|
|
if (!env.getConfig("port", port).equals(port)) {
|
|
|
|
// validation port
|
2008-08-02 14:12:04 +02:00
|
|
|
final serverCore theServerCore = (serverCore) env.getThread("10_httpd");
|
2005-11-15 16:03:15 +01:00
|
|
|
try {
|
2008-08-02 14:12:04 +02:00
|
|
|
final InetSocketAddress theNewAddress = theServerCore.generateSocketAddress(port);
|
|
|
|
final String hostName = theNewAddress.getHostName();
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info_restart", "1");
|
|
|
|
prop.put("info_restart_ip",(hostName.equals("0.0.0.0"))? "localhost" : hostName);
|
|
|
|
prop.put("info_restart_port", theNewAddress.getPort());
|
2005-11-15 16:03:15 +01:00
|
|
|
|
|
|
|
env.setConfig("port", port);
|
|
|
|
|
2008-05-19 22:51:09 +02:00
|
|
|
theServerCore.reconnect(5000);
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final SocketException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "26");
|
2005-12-08 23:22:41 +01:00
|
|
|
return prop;
|
2005-11-15 16:03:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info_restart", "0");
|
2005-11-15 16:03:15 +01:00
|
|
|
}
|
2005-06-16 09:28:07 +02:00
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
// read and process data
|
2008-06-06 18:01:27 +02:00
|
|
|
String filter = (post.get("proxyfilter")).trim();
|
2005-10-07 15:49:07 +02:00
|
|
|
String use_proxyAccounts="";
|
|
|
|
if(post.containsKey("use_proxyaccounts")){
|
|
|
|
//needed? or set to true by default?
|
2008-06-06 18:01:27 +02:00
|
|
|
use_proxyAccounts = ((post.get("use_proxyaccounts")).equals("on") ? "true" : "false" );
|
2005-10-07 15:49:07 +02:00
|
|
|
}else{
|
|
|
|
use_proxyAccounts = "false";
|
|
|
|
}
|
2005-04-07 21:19:42 +02:00
|
|
|
// do checks
|
2005-12-08 23:22:41 +01:00
|
|
|
if ((filter == null) || (use_proxyAccounts == null)) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "1");//error with submitted information
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
2005-10-07 15:49:07 +02:00
|
|
|
/*if (user.length() == 0) {
|
2005-04-07 21:19:42 +02:00
|
|
|
prop.put("info", 2);//username must be given
|
|
|
|
return prop;
|
2005-10-07 15:49:07 +02:00
|
|
|
}*/
|
|
|
|
/*if (!(pw1.equals(pw2))) {
|
2005-04-07 21:19:42 +02:00
|
|
|
prop.put("info", 3);//pw check failed
|
|
|
|
return prop;
|
2005-10-07 15:49:07 +02:00
|
|
|
}*/
|
2006-03-07 09:33:28 +01:00
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
if (filter.length() == 0) filter = "*";
|
2006-03-07 09:33:28 +01:00
|
|
|
else if (!filter.equals("*")){
|
|
|
|
// testing proxy filter
|
|
|
|
int patternCount = 0;
|
|
|
|
String patternStr = null;
|
|
|
|
try {
|
2008-08-02 14:12:04 +02:00
|
|
|
final StringTokenizer st = new StringTokenizer(filter,",");
|
2006-03-07 09:33:28 +01:00
|
|
|
while (st.hasMoreTokens()) {
|
|
|
|
patternCount++;
|
|
|
|
patternStr = st.nextToken();
|
|
|
|
Pattern.compile(patternStr);
|
|
|
|
}
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final PatternSyntaxException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "27");
|
|
|
|
prop.putHTML("info_filter", filter);
|
|
|
|
prop.put("info_nr", patternCount);
|
|
|
|
prop.putHTML("info_error", e.getMessage());
|
|
|
|
prop.putHTML("info_pattern", patternStr);
|
2006-03-07 09:33:28 +01:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
// check passed. set account:
|
|
|
|
env.setConfig("proxyClient", filter);
|
2005-10-07 15:49:07 +02:00
|
|
|
env.setConfig("use_proxyAccounts", use_proxyAccounts);//"true" or "false"
|
|
|
|
if (use_proxyAccounts.equals("false")){
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "6");//proxy account has changed(no pw)
|
|
|
|
prop.putHTML("info_filter", filter);
|
2005-10-07 15:49:07 +02:00
|
|
|
} else {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "7");//proxy account has changed
|
2005-10-07 15:49:07 +02:00
|
|
|
//prop.put("info_user", user);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.putHTML("info_filter", filter);
|
2005-10-07 15:49:07 +02:00
|
|
|
}
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2005-06-09 11:44:07 +02:00
|
|
|
// http networking
|
|
|
|
if (post.containsKey("httpNetworking")) {
|
|
|
|
|
|
|
|
// set transparent proxy flag
|
2009-07-19 22:37:44 +02:00
|
|
|
HTTPDProxyHandler.isTransparentProxy = post.containsKey("isTransparentProxy");
|
|
|
|
env.setConfig("isTransparentProxy", HTTPDProxyHandler.isTransparentProxy ? "true" : "false");
|
|
|
|
prop.put("info_isTransparentProxy", HTTPDProxyHandler.isTransparentProxy ? "on" : "off");
|
2005-06-09 11:44:07 +02:00
|
|
|
|
|
|
|
// setting the keep alive property
|
2009-07-19 22:37:44 +02:00
|
|
|
HTTPDemon.keepAliveSupport = post.containsKey("connectionKeepAliveSupport");
|
|
|
|
env.setConfig("connectionKeepAliveSupport", HTTPDemon.keepAliveSupport ? "true" : "false");
|
|
|
|
prop.put("info_connectionKeepAliveSupport", HTTPDemon.keepAliveSupport ? "on" : "off");
|
2005-06-09 11:44:07 +02:00
|
|
|
|
2006-02-16 10:20:57 +01:00
|
|
|
// setting via header property
|
|
|
|
env.setConfig("proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")?"true":"false");
|
|
|
|
prop.put("info_proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")? "on" : "off");
|
|
|
|
|
2006-06-29 18:01:03 +02:00
|
|
|
// setting X-Forwarded-for header property
|
|
|
|
env.setConfig("proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")?"true":"false");
|
|
|
|
prop.put("info_proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")? "on" : "off");
|
|
|
|
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "20");
|
2005-06-09 11:44:07 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2006-10-09 12:24:54 +02:00
|
|
|
// server access
|
2005-04-07 21:19:42 +02:00
|
|
|
if (post.containsKey("serveraccount")) {
|
2006-12-01 21:59:24 +01:00
|
|
|
|
2006-10-09 12:24:54 +02:00
|
|
|
// static IP
|
2008-06-06 18:01:27 +02:00
|
|
|
String staticIP = (post.get("staticIP")).trim();
|
2007-01-13 12:00:50 +01:00
|
|
|
if (staticIP.startsWith("http://")) {
|
|
|
|
if (staticIP.length() > 7) { staticIP = staticIP.substring(7); } else { staticIP = ""; }
|
|
|
|
} else if (staticIP.startsWith("https://")) {
|
|
|
|
if (staticIP.length() > 8) { staticIP = staticIP.substring(8); } else { staticIP = ""; }
|
|
|
|
}
|
2008-06-29 20:35:15 +02:00
|
|
|
// TODO IPv6 support!
|
2007-01-13 12:00:50 +01:00
|
|
|
if (staticIP.indexOf(":") > 0) {
|
|
|
|
staticIP = staticIP.substring(0, staticIP.indexOf(":"));
|
|
|
|
}
|
2006-12-01 21:59:24 +01:00
|
|
|
if (staticIP.length() == 0) {
|
|
|
|
serverCore.useStaticIP = false;
|
|
|
|
} else {
|
|
|
|
serverCore.useStaticIP = true;
|
2006-10-09 12:24:54 +02:00
|
|
|
}
|
2009-05-28 16:26:05 +02:00
|
|
|
if (yacySeed.isProperIP(staticIP) == null) sb.peers.mySeed().setIP(staticIP);
|
2006-10-09 12:24:54 +02:00
|
|
|
env.setConfig("staticIP", staticIP);
|
2006-12-01 21:59:24 +01:00
|
|
|
|
2006-10-09 12:24:54 +02:00
|
|
|
// server access data
|
2008-06-06 18:01:27 +02:00
|
|
|
String filter = (post.get("serverfilter")).trim();
|
2006-03-08 09:45:46 +01:00
|
|
|
/*String user = (String) post.get("serveruser");
|
2005-04-07 21:19:42 +02:00
|
|
|
String pw1 = (String) post.get("serverpw1");
|
2006-03-08 09:45:46 +01:00
|
|
|
String pw2 = (String) post.get("serverpw2");*/
|
2005-04-07 21:19:42 +02:00
|
|
|
// do checks
|
|
|
|
if (filter == null) {
|
|
|
|
//if ((filter == null) || (user == null) || (pw1 == null) || (pw2 == null)) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "1");//error with submitted information
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
2006-03-08 09:45:46 +01:00
|
|
|
/* if (user.length() == 0) {
|
2005-04-07 21:19:42 +02:00
|
|
|
prop.put("info", 2);//username must be given
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
if (!(pw1.equals(pw2))) {
|
|
|
|
prop.put("info", 3);//pw check failed
|
|
|
|
return prop;
|
2006-03-08 09:45:46 +01:00
|
|
|
}*/
|
2005-04-07 21:19:42 +02:00
|
|
|
if (filter.length() == 0) filter = "*";
|
2006-03-07 09:33:28 +01:00
|
|
|
else if (!filter.equals("*")){
|
|
|
|
// testing proxy filter
|
|
|
|
int patternCount = 0;
|
|
|
|
String patternStr = null;
|
|
|
|
try {
|
2008-08-02 14:12:04 +02:00
|
|
|
final StringTokenizer st = new StringTokenizer(filter,",");
|
2006-03-07 09:33:28 +01:00
|
|
|
while (st.hasMoreTokens()) {
|
|
|
|
patternCount++;
|
|
|
|
patternStr = st.nextToken();
|
|
|
|
Pattern.compile(patternStr);
|
|
|
|
}
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final PatternSyntaxException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "27");
|
|
|
|
prop.putHTML("info_filter", filter);
|
|
|
|
prop.put("info_nr", patternCount);
|
|
|
|
prop.putHTML("info_error", e.getMessage());
|
|
|
|
prop.putHTML("info_pattern", patternStr);
|
2006-03-07 09:33:28 +01:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
// check passed. set account:
|
|
|
|
env.setConfig("serverClient", filter);
|
|
|
|
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "8");//server access filter updated
|
2006-03-08 09:45:46 +01:00
|
|
|
//prop.put("info_user", user);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.putHTML("info_filter", filter);
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
2005-10-31 13:25:40 +01:00
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
if (post.containsKey("proxysettings")) {
|
2005-10-22 15:28:04 +02:00
|
|
|
|
|
|
|
/* ====================================================================
|
|
|
|
* Reading out the remote proxy settings
|
|
|
|
* ==================================================================== */
|
2008-08-02 14:12:04 +02:00
|
|
|
final boolean useRemoteProxy = post.containsKey("remoteProxyUse");
|
|
|
|
final boolean useRemoteProxy4Yacy = post.containsKey("remoteProxyUse4Yacy");
|
|
|
|
final boolean useRemoteProxy4SSL = post.containsKey("remoteProxyUse4SSL");
|
2005-10-22 15:28:04 +02:00
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
final String remoteProxyHost = post.get("remoteProxyHost", "");
|
|
|
|
final String remoteProxyPortStr = post.get("remoteProxyPort", "");
|
2005-10-22 15:28:04 +02:00
|
|
|
int remoteProxyPort = 0;
|
2005-04-07 21:19:42 +02:00
|
|
|
try {
|
2005-10-22 15:28:04 +02:00
|
|
|
remoteProxyPort = Integer.parseInt(remoteProxyPortStr);
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final NumberFormatException e) {
|
2005-10-22 15:28:04 +02:00
|
|
|
remoteProxyPort = 3128;
|
2005-04-07 21:19:42 +02:00
|
|
|
}
|
2005-10-22 15:28:04 +02:00
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
final String remoteProxyUser = post.get("remoteProxyUser", "");
|
|
|
|
final String remoteProxyPwd = post.get("remoteProxyPwd", "");
|
2005-10-22 15:28:04 +02:00
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
final String remoteProxyNoProxyStr = post.get("remoteProxyNoProxy", "");
|
2005-12-05 00:51:28 +01:00
|
|
|
//String[] remoteProxyNoProxyPatterns = remoteProxyNoProxyStr.split(",");
|
2005-10-22 15:28:04 +02:00
|
|
|
|
|
|
|
/* ====================================================================
|
|
|
|
* Storing settings into config file
|
|
|
|
* ==================================================================== */
|
|
|
|
env.setConfig("remoteProxyHost", remoteProxyHost);
|
|
|
|
env.setConfig("remoteProxyPort", Integer.toString(remoteProxyPort));
|
2005-10-27 13:28:37 +02:00
|
|
|
env.setConfig("remoteProxyUser", remoteProxyUser);
|
|
|
|
env.setConfig("remoteProxyPwd", remoteProxyPwd);
|
2005-10-22 15:28:04 +02:00
|
|
|
env.setConfig("remoteProxyNoProxy", remoteProxyNoProxyStr);
|
|
|
|
env.setConfig("remoteProxyUse", (useRemoteProxy) ? "true" : "false");
|
|
|
|
env.setConfig("remoteProxyUse4Yacy", (useRemoteProxy4Yacy) ? "true" : "false");
|
|
|
|
env.setConfig("remoteProxyUse4SSL", (useRemoteProxy4SSL) ? "true" : "false");
|
|
|
|
|
|
|
|
/* ====================================================================
|
|
|
|
* Enabling settings
|
|
|
|
* ==================================================================== */
|
2010-05-26 02:01:16 +02:00
|
|
|
sb.initRemoteProxy();
|
2005-10-22 15:28:04 +02:00
|
|
|
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "15"); // The remote-proxy setting has been changed
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2005-06-17 10:45:44 +02:00
|
|
|
if (post.containsKey("seedUploadRetry")) {
|
2005-07-27 15:38:46 +02:00
|
|
|
String error;
|
2008-05-06 01:13:47 +02:00
|
|
|
if ((error = yacyCore.saveSeedList(sb)) == null) {
|
2005-07-27 15:38:46 +02:00
|
|
|
// trying to upload the seed-list file
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "13");
|
|
|
|
prop.put("info_success", "1");
|
2005-07-27 15:38:46 +02:00
|
|
|
} else {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "14");
|
|
|
|
prop.putHTML("info_errormsg",error.replaceAll("\n","<br>"));
|
|
|
|
env.setConfig("seedUploadMethod","none");
|
2005-06-17 10:45:44 +02:00
|
|
|
}
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2005-07-27 15:38:46 +02:00
|
|
|
if (post.containsKey("seedSettings")) {
|
2009-10-09 16:44:20 +02:00
|
|
|
// get the currently used uploading method
|
2008-08-02 14:12:04 +02:00
|
|
|
final String oldSeedUploadMethod = env.getConfig("seedUploadMethod","none");
|
|
|
|
final String newSeedUploadMethod = post.get("seedUploadMethod");
|
2009-05-28 16:26:05 +02:00
|
|
|
final String oldSeedURLStr = sb.peers.mySeed().get(yacySeed.SEEDLIST, "");
|
2008-08-02 14:12:04 +02:00
|
|
|
final String newSeedURLStr = post.get("seedURL");
|
2005-07-27 15:38:46 +02:00
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
final boolean seedUrlChanged = !oldSeedURLStr.equals(newSeedURLStr);
|
2005-07-27 15:38:46 +02:00
|
|
|
boolean uploadMethodChanged = !oldSeedUploadMethod.equals(newSeedUploadMethod);
|
|
|
|
if (uploadMethodChanged) {
|
|
|
|
uploadMethodChanged = yacyCore.changeSeedUploadMethod(newSeedUploadMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seedUrlChanged || uploadMethodChanged) {
|
|
|
|
env.setConfig("seedUploadMethod", newSeedUploadMethod);
|
2009-05-28 16:26:05 +02:00
|
|
|
sb.peers.mySeed().put(yacySeed.SEEDLIST, newSeedURLStr);
|
2005-05-17 10:25:04 +02:00
|
|
|
|
2005-07-27 15:38:46 +02:00
|
|
|
// try an upload
|
|
|
|
String error;
|
2008-05-06 01:13:47 +02:00
|
|
|
if ((error = yacyCore.saveSeedList(sb)) == null) {
|
2005-05-23 12:10:51 +02:00
|
|
|
// we have successfully uploaded the seed-list file
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info_seedUploadMethod", newSeedUploadMethod);
|
|
|
|
prop.putHTML("info_seedURL",newSeedURLStr);
|
|
|
|
prop.put("info_success", newSeedUploadMethod.equalsIgnoreCase("none") ? "0" : "1");
|
|
|
|
prop.put("info", "19");
|
2005-05-23 11:12:20 +02:00
|
|
|
} else {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "14");
|
|
|
|
prop.putHTML("info_errormsg", error.replaceAll("\n","<br>"));
|
2005-09-26 12:36:42 +02:00
|
|
|
env.setConfig("seedUploadMethod","none");
|
2005-05-17 10:25:04 +02:00
|
|
|
}
|
2005-07-27 15:38:46 +02:00
|
|
|
return prop;
|
2005-05-17 10:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through the available seed uploaders to see if the
|
|
|
|
* configuration of one of them has changed
|
|
|
|
*/
|
2008-08-02 14:12:04 +02:00
|
|
|
final HashMap<String, String> uploaders = yacyCore.getSeedUploadMethods();
|
|
|
|
final Iterator<String> uploaderKeys = uploaders.keySet().iterator();
|
2005-10-05 12:45:33 +02:00
|
|
|
while (uploaderKeys.hasNext()) {
|
2009-10-09 16:44:20 +02:00
|
|
|
// get the uploader module name
|
2008-08-02 14:12:04 +02:00
|
|
|
final String uploaderName = uploaderKeys.next();
|
2005-05-17 10:25:04 +02:00
|
|
|
|
2005-05-23 12:10:51 +02:00
|
|
|
|
2005-05-17 10:25:04 +02:00
|
|
|
// determining if the user has reconfigured the settings of this uploader
|
|
|
|
if (post.containsKey("seed" + uploaderName + "Settings")) {
|
|
|
|
nothingChanged = true;
|
2008-08-02 14:12:04 +02:00
|
|
|
final yacySeedUploader theUploader = yacyCore.getSeedUploader(uploaderName);
|
|
|
|
final String[] configOptions = theUploader.getConfigurationOptions();
|
2005-05-17 10:25:04 +02:00
|
|
|
if (configOptions != null) {
|
|
|
|
for (int i=0; i<configOptions.length; i++) {
|
2008-08-02 14:12:04 +02:00
|
|
|
final String newSettings = post.get(configOptions[i],"");
|
|
|
|
final String oldSettings = env.getConfig(configOptions[i],"");
|
2008-08-20 10:37:39 +02:00
|
|
|
// bitwise AND with boolean is same as logic AND
|
2005-05-17 10:25:04 +02:00
|
|
|
nothingChanged &= newSettings.equals(oldSettings);
|
|
|
|
if (!nothingChanged) {
|
|
|
|
env.setConfig(configOptions[i],newSettings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-23 11:12:20 +02:00
|
|
|
if (!nothingChanged) {
|
2005-05-23 12:10:51 +02:00
|
|
|
// if the seed upload method is equal to the seed uploader whose settings
|
|
|
|
// were changed, we now try to upload the seed list with the new settings
|
|
|
|
if (env.getConfig("seedUploadMethod","none").equalsIgnoreCase(uploaderName)) {
|
2005-07-27 15:38:46 +02:00
|
|
|
String error;
|
2008-05-06 01:13:47 +02:00
|
|
|
if ((error = yacyCore.saveSeedList(sb)) == null) {
|
2005-05-23 12:10:51 +02:00
|
|
|
|
|
|
|
// we have successfully uploaded the seed file
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "13");
|
|
|
|
prop.put("info_success", "1");
|
2005-07-27 15:38:46 +02:00
|
|
|
} else {
|
2005-05-23 12:10:51 +02:00
|
|
|
// if uploading failed we print out an error message
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "14");
|
|
|
|
prop.putHTML("info_errormsg",error.replaceAll("\n","<br>"));
|
2005-05-23 12:10:51 +02:00
|
|
|
env.setConfig("seedUploadMethod","none");
|
|
|
|
}
|
2005-05-17 10:25:04 +02:00
|
|
|
} else {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "13");
|
|
|
|
prop.put("info_success", "0");
|
2005-05-23 11:12:20 +02:00
|
|
|
}
|
2005-05-17 10:25:04 +02:00
|
|
|
} else {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "13");
|
|
|
|
prop.put("info_success", "0");
|
2005-05-17 10:25:04 +02:00
|
|
|
}
|
2005-05-23 11:12:20 +02:00
|
|
|
return prop;
|
|
|
|
}
|
2005-04-07 21:19:42 +02:00
|
|
|
}
|
|
|
|
|
2005-06-29 11:50:48 +02:00
|
|
|
/*
|
|
|
|
* Message forwarding configuration
|
|
|
|
*/
|
|
|
|
if (post.containsKey("msgForwarding")) {
|
|
|
|
env.setConfig("msgForwardingEnabled",post.containsKey("msgForwardingEnabled")?"true":"false");
|
2008-06-06 18:01:27 +02:00
|
|
|
env.setConfig("msgForwardingCmd",post.get("msgForwardingCmd"));
|
|
|
|
env.setConfig("msgForwardingTo",post.get("msgForwardingTo"));
|
2005-06-29 11:50:48 +02:00
|
|
|
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "21");
|
2005-06-29 11:50:48 +02:00
|
|
|
prop.put("info_msgForwardingEnabled", post.containsKey("msgForwardingEnabled") ? "on" : "off");
|
2008-09-19 13:45:11 +02:00
|
|
|
prop.putHTML("info_msgForwardingCmd", post.get("msgForwardingCmd"));
|
2008-06-06 18:01:27 +02:00
|
|
|
prop.putHTML("info_msgForwardingTo", post.get("msgForwardingTo"));
|
2005-06-29 11:50:48 +02:00
|
|
|
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2006-09-09 17:06:49 +02:00
|
|
|
// Crawler settings
|
|
|
|
if (post.containsKey("crawlerSettings")) {
|
|
|
|
|
2009-10-09 16:44:20 +02:00
|
|
|
// get Crawler Timeout
|
2008-06-06 18:01:27 +02:00
|
|
|
String timeoutStr = post.get("crawler.clientTimeout");
|
2006-09-09 17:06:49 +02:00
|
|
|
if (timeoutStr==null||timeoutStr.length()==0) timeoutStr = "10000";
|
|
|
|
|
2006-09-11 10:26:39 +02:00
|
|
|
int crawlerTimeout;
|
2006-09-09 17:06:49 +02:00
|
|
|
try {
|
2010-01-11 00:09:48 +01:00
|
|
|
crawlerTimeout = Integer.parseInt(timeoutStr);
|
2006-09-11 10:26:39 +02:00
|
|
|
if (crawlerTimeout < 0) crawlerTimeout = 0;
|
|
|
|
env.setConfig("crawler.clientTimeout", Integer.toString(crawlerTimeout));
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final NumberFormatException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "29");
|
2008-09-19 13:45:11 +02:00
|
|
|
prop.putHTML("info_crawler.clientTimeout",post.get("crawler.clientTimeout"));
|
2006-09-09 17:06:49 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2009-10-09 16:44:20 +02:00
|
|
|
// get maximum http file size
|
2008-06-06 18:01:27 +02:00
|
|
|
String maxSizeStr = post.get("crawler.http.maxFileSize");
|
2010-03-10 09:55:29 +01:00
|
|
|
if (maxSizeStr==null||maxSizeStr.length()==0) maxSizeStr = "-1";
|
2006-09-09 17:06:49 +02:00
|
|
|
|
2006-09-11 10:26:39 +02:00
|
|
|
long maxHttpSize;
|
2006-09-09 17:06:49 +02:00
|
|
|
try {
|
2010-01-11 00:09:48 +01:00
|
|
|
maxHttpSize = Integer.parseInt(maxSizeStr);
|
2008-06-24 21:11:27 +02:00
|
|
|
if(maxHttpSize < 0) {
|
|
|
|
maxHttpSize = -1;
|
|
|
|
}
|
2006-09-11 10:26:39 +02:00
|
|
|
env.setConfig("crawler.http.maxFileSize", Long.toString(maxHttpSize));
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final NumberFormatException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "30");
|
2008-09-19 13:45:11 +02:00
|
|
|
prop.putHTML("info_crawler.http.maxFileSize",post.get("crawler.http.maxFileSize"));
|
2006-09-09 17:06:49 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2009-10-09 16:44:20 +02:00
|
|
|
// get maximum ftp file size
|
2008-06-06 18:01:27 +02:00
|
|
|
maxSizeStr = post.get("crawler.ftp.maxFileSize");
|
2010-03-10 09:55:29 +01:00
|
|
|
if (maxSizeStr==null||maxSizeStr.length()==0) maxSizeStr = "-1";
|
2006-09-09 17:06:49 +02:00
|
|
|
|
2006-09-11 10:26:39 +02:00
|
|
|
long maxFtpSize;
|
2006-09-09 17:06:49 +02:00
|
|
|
try {
|
2010-01-11 00:09:48 +01:00
|
|
|
maxFtpSize = Integer.parseInt(maxSizeStr);
|
2006-09-11 10:26:39 +02:00
|
|
|
env.setConfig("crawler.ftp.maxFileSize", Long.toString(maxFtpSize));
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final NumberFormatException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "31");
|
2008-09-19 13:45:11 +02:00
|
|
|
prop.putHTML("info_crawler.ftp.maxFileSize",post.get("crawler.ftp.maxFileSize"));
|
2006-09-09 17:06:49 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2010-03-10 09:55:29 +01:00
|
|
|
maxSizeStr = post.get("crawler.smb.maxFileSize");
|
|
|
|
if (maxSizeStr==null||maxSizeStr.length()==0) maxSizeStr = "-1";
|
|
|
|
|
|
|
|
long maxSmbSize;
|
|
|
|
try {
|
|
|
|
maxSmbSize = Integer.parseInt(maxSizeStr);
|
2010-05-25 14:54:57 +02:00
|
|
|
env.setConfig("crawler.smb.maxFileSize", Long.toString(maxSmbSize));
|
2010-03-10 09:55:29 +01:00
|
|
|
} catch (final NumberFormatException e) {
|
|
|
|
prop.put("info", "31");
|
|
|
|
prop.putHTML("info_crawler.smb.maxFileSize",post.get("crawler.smb.maxFileSize"));
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2010-05-25 14:54:57 +02:00
|
|
|
maxSizeStr = post.get("crawler.file.maxFileSize");
|
|
|
|
if (maxSizeStr==null||maxSizeStr.length()==0) maxSizeStr = "-1";
|
|
|
|
|
|
|
|
long maxFileSize;
|
|
|
|
try {
|
|
|
|
maxFileSize = Integer.parseInt(maxSizeStr);
|
|
|
|
env.setConfig("crawler.file.maxFileSize", Long.toString(maxFileSize));
|
|
|
|
} catch (final NumberFormatException e) {
|
|
|
|
prop.put("info", "31");
|
|
|
|
prop.putHTML("info_crawler.file.maxFileSize",post.get("crawler.file.maxFileSize"));
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2006-09-09 17:06:49 +02:00
|
|
|
// everything is ok
|
2009-01-30 16:33:00 +01:00
|
|
|
prop.put("info_crawler.clientTimeout",(crawlerTimeout==0) ? "0" :DateFormatter.formatInterval(crawlerTimeout));
|
2009-01-31 02:06:56 +01:00
|
|
|
prop.put("info_crawler.http.maxFileSize",(maxHttpSize==-1)? "-1":Formatter.bytesToString(maxHttpSize));
|
|
|
|
prop.put("info_crawler.ftp.maxFileSize", (maxFtpSize==-1) ? "-1":Formatter.bytesToString(maxFtpSize));
|
2010-05-25 14:54:57 +02:00
|
|
|
prop.put("info_crawler.smb.maxFileSize", (maxSmbSize==-1) ? "-1":Formatter.bytesToString(maxSmbSize));
|
|
|
|
prop.put("info_crawler.file.maxFileSize", (maxFileSize==-1) ? "-1":Formatter.bytesToString(maxFileSize));
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "28");
|
2006-09-09 17:06:49 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2005-05-03 11:47:56 +02:00
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
// nothing made
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "1");//no information submitted
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|