better Errorhandling for proxyAccounts

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2082 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent 35995cf8c7
commit 9938c252dd

@ -1,3 +1,5 @@
#(limit)#
Your Account is disabled for surfing.
::
Your Timelimit (#[timelimit]# Minutes per Day) is reached.
#(/limit)#

@ -266,6 +266,11 @@ public final class userDB {
public static final String PROXY_RIGHT = "proxyRight";
public static final String BLOG_RIGHT = "blogRight";
public static final int PROXY_ALLOK = 0; //can Surf
public static final int PROXY_ERROR = 1; //unknown error
public static final int PROXY_NORIGHT = 2; //no proxy right
public static final int PROXY_TIMELIMIT_REACHED = 3;
// this is a simple record structure that hold all properties of a user
private Map mem;
private String userName;
@ -367,18 +372,21 @@ public final class userDB {
return (this.mem.containsKey(LAST_ACCESS)?Long.valueOf((String)this.mem.get(LAST_ACCESS)):null);
}
public boolean canSurf(){
//TODO: more returnvalues.
//Exception if false, or CONSTANTS
long timeUsed=this.updateLastAccess(true);
public int surfRight(){
long timeUsed=this.updateLastAccess(true);
if(this.hasProxyRight() == false)
return false;
return ( this.getTimeLimit() == 0 ||
this.getTimeLimit() <= 0 ||
( timeUsed < this.getTimeLimit() )
); //no timelimit or timelimit not reached
return PROXY_NORIGHT;
if(! (this.getTimeLimit() <= 0 || ( timeUsed < this.getTimeLimit())) ){ //no timelimit or timelimit not reached
return PROXY_TIMELIMIT_REACHED;
}
return PROXY_ERROR;
}
public boolean canSurf(){
if(this.surfRight()==PROXY_ALLOK)
return true;
else
return false;
}
public long updateLastAccess(boolean incrementTimeUsed) {
return updateLastAccess(System.currentTimeMillis(), incrementTimeUsed);

@ -322,13 +322,19 @@ public final class httpd implements serverHandler {
entry=switchboard.userDB.proxyAuth(auth, this.clientIP);
}
if(entry != null){
if(entry.canSurf()){
int returncode=entry.surfRight();
if(returncode==userDB.Entry.PROXY_ALLOK){
return true;
}
serverObjects tp=new serverObjects();
tp.put("limit", "0");//time per day
tp.put("limit_timelimit", entry.getTimeLimit());
sendRespondError(this.prop, this.session.out, 403, "Internet-Timelimit reached", new File("proxymsg/proxylimits.inc"), tp, null);
if(returncode==userDB.Entry.PROXY_TIMELIMIT_REACHED){
tp.put("limit", "1");//time per day
tp.put("limit_timelimit", entry.getTimeLimit());
sendRespondError(this.prop, this.session.out, 403, "Internet-Timelimit reached", new File("proxymsg/proxylimits.inc"), tp, null);
}else if(returncode==userDB.Entry.PROXY_NORIGHT){
tp.put("limit", "0");
sendRespondError(this.prop, this.session.out, 403, "Proxy use forbidden", new File("proxymsg/proxylimits.inc"), tp, null);
}
return false;
}
// ask for authenticate

Loading…
Cancel
Save