Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

better Errorhandling for proxyAccounts

allo9938c252ddb2
diff --git a/htroot/proxymsg/proxylimits.inc b/htroot/proxymsg/proxylimits.inc
index a8b452493..c9c079cae 100644
--- a/htroot/proxymsg/proxylimits.inc
+++ b/htroot/proxymsg/proxylimits.inc
@@ -1,3 +1,5 @@
#(limit)#
+Your Account is disabled for surfing.
+::
Your Timelimit (#[timelimit]# Minutes per Day) is reached.
#(/limit)#
diff --git a/source/de/anomic/data/userDB.java b/source/de/anomic/data/userDB.java
index 38540f0a2..11ea457d5 100644
--- a/source/de/anomic/data/userDB.java
+++ b/source/de/anomic/data/userDB.java
@@ -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);
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index ae28a1215..2eb54037b 100644
--- a/source/de/anomic/http/httpd.java
+++ b/source/de/anomic/http/httpd.java
@@ -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