Skip to content

Commit

Permalink
added basic configuration menu for 1-2-3 set-up. This is not finished…
Browse files Browse the repository at this point in the history
… and needs an authorization mechanism. Do not use in production.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1788 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Mar 1, 2006
1 parent 574543f commit bec1a8e
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 0 deletions.
37 changes: 37 additions & 0 deletions htroot/ConfigAdvanced_p.html
@@ -0,0 +1,37 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>YaCy '#[clientname]#': Advanced Config</title>
#%env/templates/metas.template%#
<script>
<!--
function element_clicked(element){
document.getElementById("key").value=element.id;
document.getElementById("value").value=element.value;
}
-->
</script>
</head>
<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
#%env/templates/header.template%#
#%env/templates/submenuConfig.template%#
<br><br>
<h2>Advanced Config</h2>
<p>
Here are all configuration options from YaCy.<br>
You can change anything, but some options need a restart, and some options can crash YaCy, if wrong values are used.
For explanation please look into yacy.init
</p>
<select name="options" size="25" style="width: 600">
#{options}#<option id="#[key]#" value="#[value]#" onclick="element_clicked(this)">#[key]#: #[value]#</option>
#{/options}#
</select><br>
<form action="Config_p.html" method="POST">
<input type="text" id="key" name="key" size="40">:<input type="text" id="value" name="value" size="40">
<input type="Submit" value="Save">
</form>

#%env/templates/footer.template%#
</body>
</html>
</html>
93 changes: 93 additions & 0 deletions htroot/ConfigAdvanced_p.java
@@ -0,0 +1,93 @@
// ConfigGeneric_p.java
// -----------------------
// part of YaCy
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
// This File is contributed by Alexander Schier
//
// $LastChangedDate: 2005-09-13 00:20:37 +0200 (Di, 13 Sep 2005) $
// $LastChangedRevision: 715 $
// $LastChangedBy: borg-0300 $
//
// 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.

// You must compile this file with
// javac -classpath .:../classes Config_p.java
// if the shell's current path is HTROOT

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import de.anomic.http.httpHeader;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;

public class ConfigAdvanced_p {

public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
int count=0;
Iterator keys = env.configKeys();
String key="";

//change a Key
if(post != null && post.containsKey("key") && post.containsKey("value")){
key=(String)post.get("key");
final String value=(String)post.get("value");
if(!key.equals("")){
env.setConfig(key, value);
}
}

final List list = new ArrayList(250);
while(keys.hasNext()){
list.add(keys.next());
}
Collections.sort(list);
keys = list.iterator();
while(keys.hasNext()){
key = (String) keys.next();
prop.put("options_"+count+"_key", key);
prop.put("options_"+count+"_value", env.getConfig(key, "ERROR"));
count++;
}

prop.put("options", count);
return prop;
}

}
47 changes: 47 additions & 0 deletions htroot/ConfigBasic.html
@@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>YaCy '#[clientname]#': Advanced Config</title>
#%env/templates/metas.template%#
<script>
<!--
function element_clicked(element){
document.getElementById("key").value=element.id;
document.getElementById("value").value=element.value;
}
-->
</script>
</head>
<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
#%env/templates/header.template%#
#%env/templates/submenuConfig.template%#
<br>
<h2>Basic Configuration</h2>
<p>
Your YaCy Peer needs some basic information to operate properly
</p>

<form action="ConfigBasic.html" method="post" enctype="multipart/form-data">
<ol>
<li>#(statusName)#<img src="/env/grafics/excl.png">Your peer name has not been customized; please set your own peer name::<img src="/env/grafics/check.png">You have a nice peer name#(/statusName)#<br>
Peer Name: <input type="text" name="peername" value="#[defaultName]#" size="16" maxlength="32"><br></li>
<li>#(statusPassword)#<img src="/env/grafics/excl.png">Please set a password for your peer to protect your settings::<img src="/env/grafics/check.png">Password is set#(/statusPassword)#<br>
Peer User: <input type="text" name="adminuser" value="#[defaultUser]#" size="16" maxlength="32"><br>
Peer Password: <input type="text" name="adminpw1" value="" size="16" maxlength="32"><br>
Peer Password: <input type="text" name="adminpw2" value="" size="16" maxlength="32"><br></li>
<li>#(statusPort)#<img src="/env/grafics/excl.png">Your peer cannot be reached from outside; please open your firewall for this port and/or set a virtual server option in your router to allow connections on this port::<img src="/env/grafics/check.png">Your peer can be reached by other peers#(/statusPort)#<br>
Peer Port: <input type="text" name="port" value="#[defaultPort]#" size="5" maxlength="5"><br></li>
</ol>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="set" value="Set Configuration">
</form>

<b>What You should do next:</b>
#(nextStep)#
Your basic configuration is complete, you can start searching, start your own crawl, or just monitor at the network page what the other peers are doing.::
Your Peer name is a default name; please set another peer name. If this does not work, the name is probably taken by someone else. Please try to choose another one.::
You did not set a user name and/or a password. Some pages are protected by passwords. You should set a password here to secure your yacy peer.::
You did not open a port in your firewall or your router does not forward the server port to your peer. This is needed if you want to fully participate in the YaCy network. You can also use your peer without opening your peer, but this is not recomended.
#(/nextStep)#
#%env/templates/footer.template%#
</body>
</html>
138 changes: 138 additions & 0 deletions htroot/ConfigBasic.java
@@ -0,0 +1,138 @@
// ConfigBasic_p.java
// -----------------------
// part of YaCy
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2006
// Created 28.02.2006
//
// $LastChangedDate: 2005-09-13 00:20:37 +0200 (Di, 13 Sep 2005) $
// $LastChangedRevision: 715 $
// $LastChangedBy: borg-0300 $
//
// 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.

// You must compile this file with
// javac -classpath .:../classes ConfigBasic_p.java
// if the shell's current path is HTROOT

import de.anomic.http.httpHeader;
import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.server.serverCodings;
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;

public class ConfigBasic {

public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
// return variable that accumulates replacements
serverObjects prop = new serverObjects();

//yacyCore.peerPing();

// password settings
String user = (post == null) ? "" : (String) post.get("adminuser", "");
String pw1 = (post == null) ? "" : (String) post.get("adminpw1", "");
String pw2 = (post == null) ? "" : (String) post.get("adminpw2", "");

// peer name settings
String peerName = (post == null) ? "" : (String) post.get("peername", "");

// port settings
String port = (post == null) ? "8080" : (String) post.get("port", "8080");

// admin password
if ((user.length() > 0) && (!(pw1.equals(pw2)))) {
// check passed. set account:
env.setConfig("adminAccountBase64MD5", serverCodings.encodeMD5Hex(kelondroBase64Order.standardCoder.encodeString(user + ":" + pw1)));
env.setConfig("adminAccount", "");
}

// check if peer name already exists
yacySeed oldSeed = yacyCore.seedDB.lookupByName(peerName);
if ((oldSeed == null) || (env.getConfig("peerName", "").equals(peerName))) {
// the name is new
boolean nameOK = (peerName.length() <= 80);
for (int i = 0; i < peerName.length(); i++) {
if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_".indexOf(peerName.charAt(i)) < 0)
nameOK = false;
}
if (nameOK) {
// set values
env.setConfig("peerName", peerName);
}
}

// check port
if (!env.getConfig("port", port).equals(port)) {
// validate port
serverCore theServerCore = (serverCore) env.getThread("10_httpd");
env.setConfig("port", port);
theServerCore.reconnect();
}

// check if values are proper
boolean properName = (env.getConfig("peerName","").length() > 0) && (env.getConfig("peerName","0").charAt(0) > '9');
boolean properPW = (env.getConfig("adminAccount", "").length() == 0) && (env.getConfig("adminAccountBase64MD5", "").length() > 0);
boolean properPort = yacyCore.seedDB.mySeed.isSenior();

prop.put("statusName", (properName) ? 1 : 0);
prop.put("statusPassword", (properPW) ? 1 : 0);
prop.put("statusPort", (properPort) ? 1 : 0);
if (properName) {
if (properPW) {
if (properPort) {
prop.put("nextStep", 0);
} else {
prop.put("nextStep", 3);
}
} else {
prop.put("nextStep", 2);
}
} else {
prop.put("nextStep", 1);
}

// set default values
prop.put("defaultName", env.getConfig("peerName", ""));
prop.put("defaultUser", "admin");
prop.put("defaultPort", env.getConfig("port", "8080"));

return prop;
}

}
11 changes: 11 additions & 0 deletions htroot/env/templates/submenuConfig.template
@@ -0,0 +1,11 @@
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="SubMenu">
<tr height="10"><td colspan="3" class="MenuHeader">&nbsp;Peer Configuration Menu</td></tr>
<tr height="2"><td colspan="3"></td></tr>
<tr class="TableHeader">
<td width="50%" class="MenuSubItem">&nbsp;<img border="0" src="/env/grafics/lock.gif" align="top">&nbsp;
<a href="/ConfigBasic.html" class="MenuItemLink">Basic Configuraion</a>&nbsp;</td>
<td class="MenuSubSpacer"></td>
<td width="50%" class="MenuSubItem">&nbsp;<img border="0" src="/env/grafics/lock.gif" align="top">&nbsp;
<a href="/ConfigAdvanced_p.html" class="MenuItemLink">Advanced Configuration</a>&nbsp;</td>
</tr>
</table>

0 comments on commit bec1a8e

Please sign in to comment.