From ef912811f10935f5f913ee0e7e1f5ebc41ae5bea Mon Sep 17 00:00:00 2001 From: theli Date: Thu, 19 Oct 2006 16:07:59 +0000 Subject: [PATCH] *) adding new soap service for peer administration - configure dht transfer properties - configure remote proxy - configure peer name / peer port - configure admin username + pwd - get peer version information - set/get peer configuration settings - shutdown peer *) new function to get the opensearch description via soap call git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2816 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../de/anomic/soap/services/AdminService.java | 427 ++++++++++++++++++ .../anomic/soap/services/SearchService.java | 38 ++ source/de/anomic/soap/services/admin.wsdl | 289 ++++++++++++ source/de/anomic/soap/services/search.wsdl | 30 ++ 4 files changed, 784 insertions(+) create mode 100644 source/de/anomic/soap/services/AdminService.java create mode 100644 source/de/anomic/soap/services/admin.wsdl diff --git a/source/de/anomic/soap/services/AdminService.java b/source/de/anomic/soap/services/AdminService.java new file mode 100644 index 000000000..0957a69ff --- /dev/null +++ b/source/de/anomic/soap/services/AdminService.java @@ -0,0 +1,427 @@ +//AdminService.java +//------------------------ +//part of YaCy +//(C) by Michael Peter Christen; mc@anomic.de +//first published on http://www.anomic.de +//Frankfurt, Germany, 2005 +// +//this file was contributed by Martin Thelian +//last major change: $LastChangedDate$ by $LastChangedBy$ +//Revision: $LastChangedRevision$ +// +//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 +// +//Using this software in any meaning (reading, learning, copying, compiling, +//running) means that you agree that the Author(s) is (are) not responsible +//for cost, loss of data or any harm that may be caused directly or indirectly +//by usage of this softare or this documentation. The usage of this software +//is on your own risk. The installation and usage (starting/running) of this +//software may allow other people or application to access your computer and +//any attached devices and is highly dependent on the configuration of the +//software which must be done by the user of the software; the author(s) is +//(are) also not responsible for proper configuration and usage of the +//software, even if provoked by documentation provided together with +//the software. +// +//Any changes to this file according to the GPL as documented in the file +//gpl.txt aside this file in the shipment you received can be done to the +//lines that follows this copyright notice here, but changes must not be +//done inside the copyright notive above. A re-distribution must contain +//the intact and unchanged copyright notice. +//Contributions and changes to the program code must be marked as such. + + +package de.anomic.soap.services; + +import java.util.ArrayList; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.axis.AxisFault; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.anomic.http.httpRemoteProxyConfig; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverCore; +import de.anomic.server.serverObjects; +import de.anomic.soap.AbstractService; +import de.anomic.yacy.yacyCore; +import de.anomic.yacy.yacySeed; + +public class AdminService extends AbstractService { + + private static final String TEMPLATE_CONFIG_XML = "xml/config_p.xml"; + private static final String TEMPLATE_VERSION_XML = "xml/version.xml"; + + /** + * This function can be used to set a configuration option + * @param key the name of the option + * @param value the value of the option as String + * @throws AxisFault if authentication failed + */ + public void setConfigProperty(String key, String value) throws AxisFault { + // Check for errors + if ((key == null)||(key.length() == 0)) throw new IllegalArgumentException("Key must not be null or empty."); + + // extracting the message context + extractMessageContext(true); + + // add key to switchboard + if (value == null) value = ""; + this.switchboard.setConfig(key,value); + } + + /** + * This function can be used to set multiple configuration option + * @param keys an array containing the names of all options + * @param values an array containing the values of all options + * @throws AxisFault if authentication failed + * @throws IllegalArgumentException if key.length != value.length + */ + public void setProperties(String[] keys, String values[]) throws AxisFault{ + // Check for errors + if ((keys == null)||(keys.length == 0)) throw new IllegalArgumentException("Key array must not be null or empty."); + if ((values == null)||(values.length == 0)) throw new IllegalArgumentException("Values array must not be null or empty."); + if (keys.length != values.length) throw new IllegalArgumentException("Invalid input. " + keys.length + " keys but " + values.length + " values received."); + + // extracting the message context + extractMessageContext(true); + + for (int i=0; i < keys.length; i++) { + // get the key + String nextKey = keys[i]; + if ((nextKey == null)||(nextKey.length() == 0)) throw new IllegalArgumentException("Key at position " + i + " was null or empty."); + + // get the value + String nextValue = values[i]; + if (nextValue == null) nextValue = ""; + + // save the value + this.switchboard.setConfig(nextKey,nextValue); + } + } + + /** + * This function can be used to geht the value of a single configuration option + * @param key the name of the option + * @return the value of the option as string + * @throws AxisFault if authentication failed + */ + public String getConfigProperty(String key) throws AxisFault { + // Check for errors + if ((key == null)||(key.length() == 0)) throw new IllegalArgumentException("Key must not be null or empty."); + + // extracting the message context + extractMessageContext(true); + + // get the config property + return this.switchboard.getConfig(key,null); + } + + /** + * This function can be used to query the value of multiple configuration options + * @param keys an array containing the names of the configuration options to query + * @return an array containing the values of the configuration options as string + * @throws AxisFault if authentication failed + */ + public String[] getConfigProperties(String[] keys) throws AxisFault { + // Check for errors + if ((keys == null)||(keys.length== 0)) throw new IllegalArgumentException("Key array must not be null or empty."); + + // extracting the message context + extractMessageContext(true); + + // get the properties + ArrayList returnValues = new ArrayList(keys.length); + for (int i=0; i < keys.length; i++) { + String nextKey = keys[i]; + if ((nextKey == null)||(nextKey.length() == 0)) throw new IllegalArgumentException("Key at position " + i + " was null or empty."); + + returnValues.add(this.switchboard.getConfig(nextKey,null)); + } + + // return the result + return (String[]) returnValues.toArray(new String[keys.length]); + } + + + /** + * Returns the current configuration of this peer as XML Document + * @return a XML document of the following format + *
+     * <?xml version="1.0"?>
+     * <settings>
+     *   <option>
+	 *     <key>option-name</key>
+	 *     <value>option-value</value>
+	 *   </option>
+	 * </settings>
+     * 
+ * + * @throws AxisFault if authentication failed + * @throws Exception + */ + public Document getConfigPropertyList() throws Exception { + // extracting the message context + extractMessageContext(true); + + // generating the template containing the network status information + byte[] result = writeTemplate(TEMPLATE_CONFIG_XML, new serverObjects()); + + // sending back the result to the client + return this.convertContentToXML(result); + } + + /** + * Returns detailed version information about this peer + * @return a XML document of the following format + *
+     * <?xml version="1.0"?>
+     * <version>
+     *	  <number>0.48202791</number>
+     *	  <svnRevision>2791</svnRevision>
+     *	  <buildDate>20061017</buildDate>
+	 * </version>
+     * 
+ * @throws AxisFault if authentication failed + * @throws Exception + */ + public Document getVersion() throws Exception { + // extracting the message context + extractMessageContext(true); + + // generating the template containing the network status information + byte[] result = writeTemplate(TEMPLATE_VERSION_XML, new serverObjects()); + + // sending back the result to the client + return this.convertContentToXML(result); + } + + /** + * This function can be used to configure the peer name + * @param newName the new name of the peer + * @throws AxisFault if authentication failed or peer name was not accepted + */ + public void setPeerName(String newName) throws AxisFault { + // Check for errors + if ((newName == null)||(newName.length() == 0)) throw new IllegalArgumentException("The peer name must not be null or empty."); + + // extracting the message context + extractMessageContext(true); + + // get the previous name + String prevName = this.switchboard.getConfig("peerName", ""); + if (prevName.equals("newName")) return; + + // take a look if there is already an other peer with this name + yacySeed oldSeed = yacyCore.seedDB.lookupByName(newName); + if (oldSeed != null) throw new AxisFault("Other peer '" + oldSeed.getName() + "/" + oldSeed.getHexHash() + "' with this name found"); + + // name must not be too short + if (newName.length() < 3) throw new AxisFault("Name is too short"); + + // name must not be too long + if (newName.length() > 80) throw new AxisFault("Name is too long."); + + // check for invalid chars + for (int i = 0; i < newName.length(); i++) { + if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_".indexOf(newName.charAt(i)) < 0) + throw new AxisFault("Invalid char at position " + i); + } + + // use the new name + this.switchboard.setConfig("peerName", newName); + } + + /** + * Changes the port the server socket is bound to. + * + * Please not that after the request was accepted the server waits + * a timeout of 5 seconds before the server port binding is changed + * + * @param newPort the new server port + * @throws AxisFault if authentication failed + */ + public void setPeerPort(int newPort) throws AxisFault { + if (newPort <= 0) throw new IllegalArgumentException("Invalid port number"); + + // extracting the message context + extractMessageContext(true); + + // get the old value + int oldPort = (int) this.switchboard.getConfigLong("port", 8080); + if (oldPort == newPort) return; + + // getting the server thread + serverCore theServerCore = (serverCore) this.switchboard.getThread("10_httpd"); + + // store the new value + this.switchboard.setConfig("port", newPort); + + // restart the port listener + // TODO: check if the port is free + theServerCore.reconnect(5000); + } + + /** + * This function can be enabled the usage of an already configured remote proxy + * @param enableProxy true to enable and false to disable remote proxy usage + * @throws AxisFault if authentication failed or remote proxy configuration is missing + */ + public void enableRemoteProxy(boolean enableProxy) throws AxisFault { + // extracting the message context + extractMessageContext(true); + + // check for errors + String proxyHost = this.switchboard.getConfig("remoteProxyHost", ""); + if (proxyHost.length() == 0) throw new AxisFault("Remote proxy hostname is not configured"); + + String proxyPort = this.switchboard.getConfig("remoteProxyPort", ""); + if (proxyPort.length() == 0) throw new AxisFault("Remote proxy port is not configured"); + + // store the new state + plasmaSwitchboard sb = (plasmaSwitchboard) this.switchboard; + sb.setConfig("remoteProxyUse",Boolean.toString(enableProxy)); + sb.remoteProxyConfig = httpRemoteProxyConfig.init(sb); + } + + /** + * This function can be used to configured another remote proxy that should be used by + * yacy as parent proxy. + * If a parameter value is null then the current configuration value is not + * changed. + * + * @param enableRemoteProxy to enable or disable remote proxy usage + * @param proxyHost the remote proxy host name + * @param proxyPort the remote proxy user name + * @param proxyUserName login name for the remote proxy + * @param proxyPwd password to login to the remote proxy + * @param noProxyList a list of addresses that should not be accessed via the remote proxy + * @param useProxy4YaCy specifies if the remote proxy should be used for the yacy core protocol + * @param useProxy4SSL specifies if the remote proxy should be used for ssl + * + * @throws AxisFault if authentication failed + */ + public void setRemoteProxy( + Boolean enableRemoteProxy, + String proxyHost, + Integer proxyPort, + String proxyUserName, + String proxyPwd, + String noProxyList, + Boolean useProxy4YaCy, + Boolean useProxy4SSL + ) throws AxisFault { + // extracting the message context + extractMessageContext(true); + + if (proxyHost != null) + this.switchboard.setConfig("remoteProxyHost", proxyHost); + + if (proxyPort != null) + this.switchboard.setConfig("remoteProxyPort", proxyPort.toString()); + + if (proxyUserName != null) + this.switchboard.setConfig("remoteProxyUser", proxyUserName); + + if (proxyPwd != null) + this.switchboard.setConfig("remoteProxyPwd", proxyPwd); + + if (noProxyList != null) + this.switchboard.setConfig("remoteProxyNoProxy", noProxyList); + + if (useProxy4YaCy != null) + this.switchboard.setConfig("remoteProxyUse4Yacy", useProxy4YaCy.toString()); + + if (useProxy4SSL != null) + this.switchboard.setConfig("remoteProxyUse4SSL", useProxy4SSL.toString()); + + // enable remote proxy usage + if (enableRemoteProxy != null) this.enableRemoteProxy(enableRemoteProxy.booleanValue()); + } + + /** + * Shutdown this peer + * @throws AxisFault if authentication failed + */ + public void shutdownPeer() throws AxisFault { + // extracting the message context + extractMessageContext(true); + + this.switchboard.setConfig("restart", "false"); + + // Terminate the peer in 3 seconds (this gives us enough time to finish the request + ((plasmaSwitchboard)this.switchboard).terminate(3000); + } + + public void setTransferProperties( + Boolean indexDistribution, + Boolean indexDistributeWhileCrawling, + Boolean indexReceive, + Boolean indexReceiveBlockBlacklist + ) throws AxisFault { + // extracting the message context + extractMessageContext(true); + + // index Distribution on/off + if (indexDistribution != null) { + this.switchboard.setConfig("allowDistributeIndex", indexDistribution.toString()); + } + + // Index Distribution while crawling + if (indexDistributeWhileCrawling != null) { + this.switchboard.setConfig("allowDistributeIndexWhileCrawling", indexDistributeWhileCrawling.toString()); + } + + // Index Receive + if (indexReceive != null) { + this.switchboard.setConfig("allowReceiveIndex", indexReceive.toString()); + } + + // block URLs received by DHT by blocklist + if (indexReceiveBlockBlacklist != null) { + this.switchboard.setConfig("indexReceiveBlockBlacklist", indexReceiveBlockBlacklist.toString()); + } + } + + public Document getTransferProperties() throws AxisFault, ParserConfigurationException { + // extracting the message context + extractMessageContext(true); + + // creating XML document + Element xmlElement = null; + Document xmlDoc = createNewXMLDocument("transferProperties"); + Element xmlRoot = xmlDoc.getDocumentElement(); + + xmlElement = xmlDoc.createElement("allowDistributeIndex"); + xmlElement.appendChild(xmlDoc.createTextNode(Boolean.toString(this.switchboard.getConfigBool("allowDistributeIndex",true)))); + xmlRoot.appendChild(xmlElement); + + xmlElement = xmlDoc.createElement("allowDistributeIndexWhileCrawling"); + xmlElement.appendChild(xmlDoc.createTextNode(Boolean.toString(this.switchboard.getConfigBool("allowDistributeIndexWhileCrawling",true)))); + xmlRoot.appendChild(xmlElement); + + xmlElement = xmlDoc.createElement("allowReceiveIndex"); + xmlElement.appendChild(xmlDoc.createTextNode(Boolean.toString(this.switchboard.getConfigBool("allowReceiveIndex",true)))); + xmlRoot.appendChild(xmlElement); + + xmlElement = xmlDoc.createElement("indexReceiveBlockBlacklist"); + xmlElement.appendChild(xmlDoc.createTextNode(Boolean.toString(this.switchboard.getConfigBool("indexReceiveBlockBlacklist",true)))); + xmlRoot.appendChild(xmlElement); + + return xmlDoc; + } +} diff --git a/source/de/anomic/soap/services/SearchService.java b/source/de/anomic/soap/services/SearchService.java index 6986c8af1..243770e07 100644 --- a/source/de/anomic/soap/services/SearchService.java +++ b/source/de/anomic/soap/services/SearchService.java @@ -69,6 +69,7 @@ public class SearchService extends AbstractService private static final String TEMPLATE_SEARCH = "yacysearch.soap"; private static final String TEMPLATE_URLINFO = "ViewFile.soap"; private static final String TEMPLATE_SNIPPET = "xml/snippet.xml"; + private static final String TEMPLATE_OPENSEARCH = "opensearchdescription.xml"; /** @@ -265,4 +266,41 @@ public class SearchService extends AbstractService } } + /** + * Returns the OpenSearch-Description of this peer + * @return a XML document of the following format: + *
+	* <?xml version="1.0" encoding="UTF-8"?>
+	* <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+	*   <ShortName>YaCy/peerName</ShortName>
+	*   <LongName>YaCy.net - P2P WEB SEARCH</LongName>
+	*   <Image type="image/gif">http://ip-address:port/env/grafics/yacy.gif</Image>
+	*   <Image type="image/vnd.microsoft.icon">http://ip-address:port/env/grafics/yacy.ico</Image>
+	*   <Language>en-us</Language>
+	*   <OutputEncoding>UTF-8</OutputEncoding>
+	*   <InputEncoding>UTF-8</InputEncoding>
+	*   <AdultContent>true</AdultContent>
+	*   <Description>YaCy is a open-source GPL-licensed software that can be used for stand-alone search engine installations or as a client for a multi-user P2P-based web indexing cluster. This is the access to peer 'peername'.</Description>
+	*   <Url type="application/rss+xml" template="http://ip-address:port/yacysearch.rss?search={searchTerms}&Enter=Search" />
+	*   <Developer>See http://developer.berlios.de/projects/yacy/</Developer>
+	*   <Query role="example" searchTerms="yacy" />
+	*   <Tags>YaCy P2P Web Search</Tags>
+	*   <Contact>See http://ip-address:port/ViewProfile.html?hash=localhash</Contact>
+	*   <Attribution>YaCy Software &copy; 2004-2006 by Michael Christen et al., YaCy.net; Content: ask peer owner</Attribution>
+	*   <SyndicationRight>open</SyndicationRight>
+	* </OpenSearchDescription>
+	* 
+ * @throws Exception + */ + public Document getOpenSearchDescription() throws Exception { + // extracting the message context + extractMessageContext(false); + + // generating the template containing the network status information + byte[] result = writeTemplate(TEMPLATE_OPENSEARCH, new serverObjects()); + + // sending back the result to the client + return this.convertContentToXML(result); + } + } diff --git a/source/de/anomic/soap/services/admin.wsdl b/source/de/anomic/soap/services/admin.wsdl new file mode 100644 index 000000000..605a053d7 --- /dev/null +++ b/source/de/anomic/soap/services/admin.wsdl @@ -0,0 +1,289 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/de/anomic/soap/services/search.wsdl b/source/de/anomic/soap/services/search.wsdl index 45487c073..6fd7cd4c1 100644 --- a/source/de/anomic/soap/services/search.wsdl +++ b/source/de/anomic/soap/services/search.wsdl @@ -9,10 +9,17 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + + + + + + + @@ -22,6 +29,7 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + @@ -31,6 +39,7 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + @@ -40,6 +49,7 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + @@ -49,11 +59,17 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + + + + + + @@ -63,6 +79,7 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + @@ -72,6 +89,7 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + @@ -81,6 +99,7 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + @@ -90,6 +109,17 @@ Built on Nov 16, 2004 (12:19:44 EST)--> + + + + + + + + + + +