2005-10-05 18:35:05 +02:00
|
|
|
// Steering.java
|
2005-04-07 21:19:42 +02:00
|
|
|
// -----------------------
|
|
|
|
// 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-05 18:35:05 +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
|
|
|
|
|
2007-07-02 17:16:05 +02:00
|
|
|
import java.io.File;
|
|
|
|
|
2012-06-26 00:08:25 +02:00
|
|
|
import net.yacy.cora.protocol.Domains;
|
2010-08-23 14:32:02 +02:00
|
|
|
import net.yacy.cora.protocol.HeaderFramework;
|
|
|
|
import net.yacy.cora.protocol.RequestHeader;
|
2009-12-02 23:56:28 +01:00
|
|
|
import net.yacy.kelondro.logging.Log;
|
2011-09-25 18:59:06 +02:00
|
|
|
import net.yacy.peers.operation.yacyRelease;
|
|
|
|
import net.yacy.search.Switchboard;
|
2005-05-05 07:36:42 +02:00
|
|
|
import de.anomic.server.serverObjects;
|
|
|
|
import de.anomic.server.serverSwitch;
|
2005-04-07 21:19:42 +02:00
|
|
|
|
|
|
|
public class Steering {
|
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch ss) {
|
2005-10-05 18:35:05 +02:00
|
|
|
if (post == null || ss == null) { return new serverObjects(); }
|
2007-01-04 23:03:32 +01:00
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
final Switchboard sb = (Switchboard) ss;
|
2007-01-04 23:03:32 +01:00
|
|
|
final serverObjects prop = new serverObjects();
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "0"); //no information submitted
|
2005-04-07 21:19:42 +02:00
|
|
|
|
2012-06-26 00:08:25 +02:00
|
|
|
final String requestIP = post.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, Domains.LOCALHOST);
|
2011-11-25 15:09:25 +01:00
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
// handle access rights
|
2011-11-25 15:09:25 +01:00
|
|
|
if (!sb.verifyAuthentication(header)) {
|
2009-12-02 23:56:28 +01:00
|
|
|
Log.logInfo("STEERING", "log-in attempt for steering from " + requestIP);
|
2012-05-24 13:24:31 +02:00
|
|
|
prop.authenticationRequired();
|
2005-12-07 01:36:05 +01:00
|
|
|
return prop;
|
2005-04-07 21:19:42 +02:00
|
|
|
}
|
2005-10-05 18:35:05 +02:00
|
|
|
|
|
|
|
if (post.containsKey("shutdown")) {
|
2009-12-02 23:56:28 +01:00
|
|
|
Log.logInfo("STEERING", "shutdown request from " + requestIP);
|
2010-09-14 11:13:28 +02:00
|
|
|
sb.terminate(10, "shutdown request from Steering; ip = " + requestIP);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "3");
|
2011-11-25 15:09:25 +01:00
|
|
|
|
2005-10-05 18:35:05 +02:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (post.containsKey("restart")) {
|
2009-12-02 23:56:28 +01:00
|
|
|
Log.logInfo("STEERING", "restart request from " + requestIP);
|
2009-05-02 14:12:22 +02:00
|
|
|
yacyRelease.restart();
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "4");
|
2011-11-25 15:09:25 +01:00
|
|
|
|
2005-04-07 21:19:42 +02:00
|
|
|
return prop;
|
|
|
|
}
|
2011-11-25 15:09:25 +01:00
|
|
|
|
2007-07-02 17:16:05 +02:00
|
|
|
if (post.containsKey("update")) {
|
2009-12-02 23:56:28 +01:00
|
|
|
Log.logInfo("STEERING", "update request from " + requestIP);
|
2011-12-06 22:05:22 +01:00
|
|
|
final boolean devenvironment = new File(sb.getAppPath(), ".git").exists();
|
2008-08-02 14:12:04 +02:00
|
|
|
final String releaseFileName = post.get("releaseinstall", "");
|
2010-09-02 21:24:22 +02:00
|
|
|
final File releaseFile = new File(sb.getDataPath(), "DATA/RELEASE/".replace("/", File.separator) + releaseFileName);
|
2010-07-10 20:03:07 +02:00
|
|
|
if ((!devenvironment) && (releaseFileName.length() > 0) && (releaseFile.exists())) {
|
2009-05-02 14:12:22 +02:00
|
|
|
yacyRelease.deployRelease(releaseFile);
|
2007-07-02 17:16:05 +02:00
|
|
|
}
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("info", "5");
|
2008-09-19 13:45:11 +02:00
|
|
|
prop.putHTML("info_release", releaseFileName);
|
2011-11-25 15:09:25 +01:00
|
|
|
|
2007-07-02 17:16:05 +02:00
|
|
|
return prop;
|
|
|
|
}
|
2005-10-05 18:35:05 +02:00
|
|
|
return prop;
|
2005-04-07 21:19:42 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 22:41:15 +02:00
|
|
|
}
|