diff --git a/htroot/User.html b/htroot/User.html new file mode 100644 index 000000000..8f1aa2c17 --- /dev/null +++ b/htroot/User.html @@ -0,0 +1,23 @@ + + + +YaCy '#[clientname]#': User Page +#[metas]# + + +#[header]# +

+

User Page


+#(logged-in)# +You are not logged in. +:: +You are currently logged in as #[username]#.
+(Identified by #(identified-by)#IP::Username/Password#(/identified-by)#)
+
+ +
+#(/logged-in)# + +#[footer]# + + diff --git a/htroot/User.java b/htroot/User.java new file mode 100644 index 000000000..0d2fa893f --- /dev/null +++ b/htroot/User.java @@ -0,0 +1,85 @@ +//User.java +//----------------------- +//part of the AnomicHTTPD caching proxy +//(C) by Michael Peter Christen; mc@anomic.de +//first published on http://www.anomic.de +//Frankfurt, Germany, 2004 +// +//This File is contributed by Alexander Schier +//last major change: 12.11.2005 +// +//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 Message.java +//if the shell's current path is HTROOT + +import de.anomic.data.userDB; +import de.anomic.http.httpHeader; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; + +public class User{ + + + public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { + serverObjects prop = new serverObjects(); + plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard(); + userDB.Entry entry=null; + + //default values + prop.put("logged_in", 0); + entry=sb.userDB.proxyAuth(((String) header.get(httpHeader.AUTHORIZATION, "xxxxxx"))); + if(entry != null){ + prop.put("logged-in_identified-by", 1); + }else{ + entry=sb.userDB.ipAuth(((String)header.get("CLIENTIP", "xxxxxx"))); + if(entry != null){ + prop.put("logged-in_identified-by", 0); + } + } + if(entry != null){ + prop.put("logged-in", 1); + prop.put("logged-in_username", entry.getUserName()); + } + if(post!= null && post.containsKey("logout") && entry != null){ + entry.logout(((String)header.get("CLIENTIP", "xxxxxx"))); + prop.put("logged-in", 0); + } + // return rewrite properties + return prop; + } +} diff --git a/source/de/anomic/data/userDB.java b/source/de/anomic/data/userDB.java index 0a85b9ec9..57ff3c9be 100644 --- a/source/de/anomic/data/userDB.java +++ b/source/de/anomic/data/userDB.java @@ -161,6 +161,7 @@ public final class userDB { auth=codings.decodeBase64String(auth); }catch(StringIndexOutOfBoundsException e){} //no valid Base64 String[] tmp=auth.split(":"); + System.out.println("proxyAuth: "+auth); if(tmp.length == 2){ entry=this.getEntry(tmp[0]); if( entry != null && entry.getMD5EncodedUserPwd().equals(serverCodings.encodeMD5Hex(auth)) ){ @@ -171,6 +172,10 @@ public final class userDB { return null; } return entry; + }else{ //wrong/no auth, so auth is removed from browser + try{ + entry.setProperty(Entry.LOGGED_OUT, "false"); + }catch(IOException e){} } } return null; @@ -194,6 +199,7 @@ public final class userDB { * @param ip the IP of the User */ public Entry ipAuth(String ip) { + System.out.println("ipAuth: "+ip); if(this.ipUsers.containsKey(ip)){ String user=(String)this.ipUsers.get(ip); Entry entry=this.getEntry(user); @@ -401,12 +407,20 @@ public final class userDB { return (this.mem.containsKey(ADMIN_RIGHT)?((String)this.mem.get(ADMIN_RIGHT)).equals("true"):false); } public boolean isLoggedOut(){ + System.out.println("isLoggedOut:"+this.mem.get(LOGGED_OUT)); return (this.mem.containsKey(LOGGED_OUT)?((String)this.mem.get(LOGGED_OUT)).equals("true"):false); } - public void logout(){ + public void logout(String ip){ try{ setProperty(LOGGED_OUT, "true"); + if(ipUsers.containsKey(ip)){ + ipUsers.remove(ip); + } }catch(IOException e){} + System.out.println("Logout: "+ip); + } + public void logout(){ + logout("xxxxxx"); } public String toString() {