Beispiel #1
1
 public void setContent(byte[] cntnt) throws Exception {
   StringBuffer sb = new StringBuffer(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
   sb.append(OK_HDR);
   sb.append("Content-Type: ");
   sb.append(contentType);
   if (!isHTTP11 || !keepAlive || isMessages) {
     sb.append("\r\nConnection: close\r\nProxy-Connection: close");
   } else {
     sb.append("\r\nConnection: Keep-Alive\r\nProxy-Connection: Keep-Alive");
     sb.append("\r\nContent-Length: ");
     sb.append(cntnt.length);
   }
   sb.append("\r\n\r\n");
   sb.trimToSize();
   CharBuffer cb = CharBuffer.wrap(sb.toString());
   ByteBuffer tempBuffer;
   try {
     tempBuffer = Charset.forName("iso-8859-1").newEncoder().encode(cb);
   } catch (CharacterCodingException cce) {
     Server.debug(this, "prepareForSending: ", cce, Server.MSG_ERROR, Server.LVL_MINOR);
     try {
       tempBuffer = ByteBuffer.wrap(cb.toString().getBytes(Server.srv.DEFAULT_CHARSET));
     } catch (Exception e) {
       Server.debug(this, "prepareForSending: ", e, Server.MSG_ERROR, Server.LVL_MAJOR);
       throw e;
     }
   }
   this.buf = ByteBuffer.allocate(tempBuffer.capacity() + cntnt.length);
   this.buf.put(tempBuffer.array());
   this.buf.put(cntnt);
   this.buf.flip();
 }
Beispiel #2
1
 /** renders the template and wraps it to a full httpresponse */
 public void renderTemplate(IRequest req) {
   if (tpl == null) {
     if (this.ts == null) ts = Server.srv.templatemanager.getTemplateSet("default");
     tpl = ts.getTemplate(tName);
     if (tpl == null) tpl = ts.getTemplate("not_found");
   }
   if (tpl.isRedirect()) {
     this.setRedirectTo(tpl.getDestination(), req.getCookieDomain());
     return;
   }
   if (!nocache
       && !nostore
       && !tpl.hasToBeRendered(
           req.getProperty("if-none-match"),
           HttpDateParser.parseDate(req.getProperty("if-modified-since")))) {
     StringBuffer sb = new StringBuffer(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
     sb.append(IResponseHeaders.NOT_MODIFIED);
     sb.trimToSize();
     prepareForSending(CharBuffer.wrap(sb.toString()));
     return;
   }
   String cntnt = tpl.render(req);
   if (cntnt == null || cntnt.length() < 1) {
     Server.log(
         this,
         "renderTemplate: rendered template has no content",
         Server.MSG_STATE,
         Server.LVL_MAJOR);
     resCode = NOCONTENT_CODE;
     StringBuffer sb = new StringBuffer();
     sb.append("<html><body><b>The requested page could not be displayed!<br><br>Reason:</b> ");
     if (tpl == null) {
       sb.append("No template given");
     } else {
       sb.append("Template '");
       sb.append(tpl.getName());
       sb.append("' has not been found on this server.");
     }
     sb.append("</body></html>");
     wrap(sb.toString(), req.getCookieDomain());
     return;
   }
   nocache = tpl.notCacheable();
   //      if (nocache)
   //          Server.log (this, "not cacheable", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
   wrap(cntnt, tpl.getEtag(), req.getCookieDomain());
 }
Beispiel #3
0
  public void add(User u) {
    u.addMembership(this.key, this);

    // add addedStates and remove removedStates to/from this users permissionmap
    int pMap = u.getPermissionMap();
    pMap = pMap | addedStates;
    pMap = pMap - (pMap & removedStates);
    Server.log(
        "[" + this.key + "]",
        "setting user-state-map for user " + u.getName() + " to value " + pMap,
        Server.MSG_AUTH,
        Server.LVL_VERY_VERBOSE);
    u.setPermission(pMap);

    int dpMap = u.getDefaultMembershipPermissionMap();
    dpMap = dpMap | addedDefaultStates;
    dpMap = dpMap - (dpMap & removedDefaultStates);
    Server.log(
        "[" + this.key + "]",
        "setting user-defaultmembership-state-map for user " + u.getName() + " to value " + dpMap,
        Server.MSG_AUTH,
        Server.LVL_VERY_VERBOSE);
    u.setDefaultMembershipPermission(dpMap);

    if (dpMap > 0 && dpMap != pMap) {
      Server.log(
          "[" + this.key + "]",
          "setting user-defaultstate-map for user " + u.getName() + " to value " + dpMap,
          Server.MSG_AUTH,
          Server.LVL_VERY_VERBOSE);
      u.setDefaultPermissionMap(dpMap);
    }
    if (mayUseTemplateset != null) u.mayUseTemplateset(mayUseTemplateset);
  }
Beispiel #4
0
 private CmdListBan checkVersion() {
   String freecsversion = Server.getVersion().substring(4, 12);
   int v = new Integer(freecsversion).intValue();
   if (v >= 20100304) {
     return this;
   }
   Server.log(this, "Wrong Chatversion", Server.MSG_ERROR, Server.LVL_MAJOR);
   return null;
 }
Beispiel #5
0
 public ContentContainer() {
   if (Server.TRACE_CREATE_AND_FINALIZE)
     Server.log(
         this,
         "++++++++++++++++++++++++++++++++++++++++CREATE",
         Server.MSG_STATE,
         Server.LVL_VERY_VERBOSE);
 }
Beispiel #6
0
 public void finalize() {
   if (Server.TRACE_CREATE_AND_FINALIZE)
     Server.log(
         this,
         "----------------------------------------FINALIZED",
         Server.MSG_STATE,
         Server.LVL_VERY_VERBOSE);
 }
Beispiel #7
0
 /**
  * prepares the response for sending if a template is set, it will be rendered if no charbuffer is
  * present, even after rendering the template, there is nothing to send and prepareForSending will
  * just return
  */
 public void prepareForSending(CharBuffer cb) {
   if (cb == null || cb.length() < 1) return;
   try {
     buf = Charset.forName("iso-8859-1").newEncoder().encode(cb);
     return;
   } catch (CharacterCodingException cce) {
     Server.debug(this, "prepareForSending: ", cce, Server.MSG_ERROR, Server.LVL_MINOR);
   }
 }
Beispiel #8
0
 public void remove(User u) {
   members.remove(u);
   if (members.size() == 0) {
     callKey = new Vector<CallMembershipObject>();
     Server.log(
         this.key,
         "reset callkey for Membership " + this.key,
         Server.MSG_STATE,
         Server.LVL_VERBOSE);
   }
 }
Beispiel #9
0
 public boolean isMobileBrowser(String BrowserAgent) {
   if (BrowserAgent == null) return false;
   StringBuilder c_input = new StringBuilder(Server.srv.MOBILE_BROWSER_REGEX);
   c_input.trimToSize();
   Pattern p = Pattern.compile(c_input.toString().toLowerCase());
   Matcher m = p.matcher(BrowserAgent.toLowerCase());
   if (m.find()) {
     Server.log(
         this,
         "found Mobile Browser [" + m.group() + "] (" + BrowserAgent + ")",
         Server.MSG_TRAFFIC,
         Server.LVL_VERBOSE);
     return true;
   } else return false;
 }
Beispiel #10
0
 public boolean canUseTemplateset(TemplateSet t) {
   if (Server.srv.DEFAULT_TEMPLATESET == null || t == null) return true;
   StringBuffer defaultTs = new StringBuffer(Server.srv.DEFAULT_TEMPLATESET);
   if (defaultTs != null) {
     StringTokenizer st = new StringTokenizer(defaultTs.toString(), ",");
     while (st.hasMoreTokens()) {
       StringBuilder templateName = new StringBuilder(st.nextToken());
       if (templateName.toString().equals(t.getName())) return true;
     }
   }
   if (Server.DEBUG) {
     StringBuffer scn = new StringBuffer();
     scn.append(" can not use Template ");
     scn.append(t.getName());
     Server.log(this, scn.toString(), Server.MSG_TRAFFIC, Server.LVL_MINOR);
   }
   return false;
 }
Beispiel #11
0
 /**
  * append the cookie-header-field to the given StringBuffer
  *
  * @param sb the stringbuffer to append the cookie-header-field
  * @return the stringbuffer with the cookie-header-field appended
  */
 public StringBuffer appendCookie(StringBuffer sb, String CookieDomain) {
   if (cookie == null || CookieDomain == null) return sb;
   sb.append("\r\n");
   sb.append("Set-Cookie: FreeCSSession=");
   sb.append(cookie);
   sb.append("; path=/;");
   if (Server.srv.COOKIE_DOMAIN != null) {
     if (Server.DEBUG)
       Server.log(
           "[ContenCointainer]",
           "append FreecsSession = " + CookieDomain,
           Server.MSG_TRAFFIC,
           Server.LVL_VERY_VERBOSE);
     sb.append(" Domain=");
     sb.append(CookieDomain);
   }
   return sb;
 }
Beispiel #12
0
 public void prepareForSending(CharBuffer hdr, CharBuffer cntnt) {
   if (hdr == null || hdr.capacity() < 1) return;
   try {
     ByteBuffer hdrBytes = Charset.forName("iso-8859-1").newEncoder().encode(hdr);
     ByteBuffer cntntBytes =
         Charset.forName(Server.srv.DEFAULT_CHARSET).newEncoder().encode(cntnt);
     buf = ByteBuffer.allocate(hdrBytes.capacity() + cntntBytes.capacity());
     buf.put(hdrBytes);
     buf.put(cntntBytes);
     buf.flip();
   } catch (Exception e) {
     Server.debug(
         this,
         "Exception during prepareForSending(hdr/cntnt)",
         e,
         Server.MSG_ERROR,
         Server.LVL_MAJOR);
   }
 }
Beispiel #13
0
  public String checkTName(User u, String name) {
    if (Server.srv.getProperty("costum.userAgent") == null) return name;

    String browseragent = name;
    if (u != null && u.getUserAgent() != null) {
      browseragent = u.getUserAgent();
    } else return name;

    boolean defaultFile = true;
    String ta[] = Server.srv.getProperty("costum.userAgent").split(",");
    Vector<String> tempAgent = new Vector<String>();
    for (int i = 0; i < ta.length; i++) {
      tempAgent.add(ta[i].trim().toLowerCase());
    }
    int fn = 0;
    int found = 0;
    for (Enumeration<String> e = tempAgent.elements(); e.hasMoreElements(); ) {
      StringBuilder customAgent = new StringBuilder((String) e.nextElement());
      fn++;
      if (browseragent.toLowerCase().indexOf(customAgent.toString().toLowerCase()) >= 0) {
        defaultFile = false;
        Server.log(
            this,
            "Found Browser '" + customAgent + "'(" + u.getUserAgent() + ")",
            Server.MSG_STATE,
            Server.LVL_VERBOSE);
        found = fn;
        continue;
      } else {
        if (u != null && u.getUserAgent() != null)
          Server.log(
              this,
              "Browser '" + customAgent + "' not found(" + u.getUserAgent() + ")",
              Server.MSG_STATE,
              Server.LVL_VERBOSE);
      }
      customAgent = null;
    }
    StringBuilder fName = null;
    if (defaultFile) {
      return name;
    } else {
      fName = new StringBuilder(name).append("_custom").append(found);
      if (ts == null || u == null | u.getName() == null) return name;
      tpl = ts.getTemplate(fName.toString());
      if (tpl == null) {
        Server.log(
            this,
            u.getTemplateSet() + " File " + fName + " not found",
            Server.MSG_STATE,
            Server.LVL_VERBOSE);
        fName = new StringBuilder(name).append("_custom");
        tpl = ts.getTemplate(fName.toString());
      }
      if (tpl == null) {
        Server.log(
            this,
            u.getTemplateSet() + " File " + fName + " not found- loading default input File",
            Server.MSG_ERROR,
            Server.LVL_MAJOR);
        return name;
      }
    }
    return fName.toString();
  }
Beispiel #14
0
  private void init(Properties p) {
    if (p == null) return;
    boolean checkNamePrefix = false,
        checkNameSuffix = false,
        checkStringRepresentation = false,
        checkAddedStates = false,
        checkRemovedStates = false,
        checkAddedDefaultStates = false,
        checkRemovedDefaultStates = false,
        checkDisplayDefaultVipRighttitle = false,
        checkDisplayDefaultModGuestTitle = false,
        checkListedAsOnlinevip = false,
        checkUserTimeout = false,
        checkMayUseTemplateset = false,
        checkPrivatemessageStore = false;
    for (Iterator<Object> i = p.keySet().iterator(); i.hasNext(); ) {
      String currKey = (String) i.next();
      if (currKey.equalsIgnoreCase("usernameprefix")) {
        namePrefix = p.getProperty(currKey);
        checkNamePrefix = true;
      } else if (currKey.equalsIgnoreCase("usernamesuffix")) {
        nameSuffix = p.getProperty(currKey);
        checkNameSuffix = true;
      } else if (currKey.equalsIgnoreCase("stringrepresentation")) {
        stringRepresentation = p.getProperty(currKey);
        checkStringRepresentation = true;
      } else if (currKey.equalsIgnoreCase("addstates")) {
        String val = p.getProperty(currKey);
        String[] states = val.split(",");
        addedStates = 0;
        for (int j = 0; j < states.length; j++) {
          addedStates = addedStates | UserManager.resolveState(states[j]);
        }
        checkAddedStates = true;
      } else if (currKey.equalsIgnoreCase("removestates")) {
        String val = p.getProperty(currKey);
        String[] states = val.split(",");
        removedStates = 0;
        for (int j = 0; j < states.length; j++) {
          removedStates = removedStates | UserManager.resolveState(states[j]);
        }
        checkRemovedStates = true;
      } else if (currKey.equalsIgnoreCase("adddefaultstates")) {
        String val = p.getProperty(currKey);
        String[] states = val.split(",");
        addedDefaultStates = 0;
        for (int j = 0; j < states.length; j++) {
          addedDefaultStates = addedDefaultStates | UserManager.resolveState(states[j]);
        }
        checkAddedDefaultStates = true;
      } else if (currKey.equalsIgnoreCase("removedefaultstates")) {
        String val = p.getProperty(currKey);
        String[] states = val.split(",");
        removedDefaultStates = 0;
        for (int j = 0; j < states.length; j++) {
          removedDefaultStates = removedDefaultStates | UserManager.resolveState(states[j]);
        }
        checkRemovedDefaultStates = true;
      } else if (currKey.equalsIgnoreCase("displaydefaultviprighttitle")
          && p.getProperty(currKey).equalsIgnoreCase("true")) {
        displayDefaultVipRighttitle = true;
        checkDisplayDefaultVipRighttitle = true;
      } else if (currKey.equalsIgnoreCase("displaydefaultmodguesttitle")
          && p.getProperty(currKey).equalsIgnoreCase("false")) {
        displayDefaultModGuestTitle = false;
        checkDisplayDefaultModGuestTitle = true;
      } else if (currKey.equalsIgnoreCase("listedasonlinevip")
          && p.getProperty(currKey).equalsIgnoreCase("false")) {
        listedAsOnlinevip = false;
        checkListedAsOnlinevip = true;
      } else if (currKey.equalsIgnoreCase("usertimeout")) {
        try {
          Integer o = new Integer(p.getProperty(currKey));
          userTimeout = o.longValue();
        } catch (NumberFormatException n) {
          Server.log(
              "[Membership]",
              "clear userTimeout for Membership " + this.getName() + " " + n,
              Server.MSG_ERROR,
              Server.LVL_MAJOR);
          userTimeout = 0;
        }
        checkUserTimeout = true;
      } else if (currKey.equalsIgnoreCase("mayusetemplateset")) {
        mayUseTemplateset = p.getProperty(currKey);
        checkMayUseTemplateset = true;
      } else if (currKey.equalsIgnoreCase("privatemessageStore")) {
        try {
          Integer o = new Integer(p.getProperty(currKey));
          privatemessageStore = o.intValue();
        } catch (NumberFormatException n) {
          privatemessageStore = 0;
          Server.log(
              "[Membership]",
              "clear privatemessageStore for Membership " + this.getName() + " " + n,
              Server.MSG_ERROR,
              Server.LVL_MAJOR);
        }
        checkPrivatemessageStore = true;
      }
    }

    if (!checkNamePrefix) namePrefix = null;
    if (!checkNameSuffix) nameSuffix = null;
    if (!checkStringRepresentation) stringRepresentation = null;
    if (!checkAddedStates) addedStates = 0;
    if (!checkRemovedStates) removedStates = 0;
    if (!checkAddedDefaultStates) addedDefaultStates = 0;
    if (!checkRemovedDefaultStates) removedDefaultStates = 0;
    if (!checkDisplayDefaultVipRighttitle) displayDefaultVipRighttitle = false;
    if (!checkDisplayDefaultModGuestTitle) displayDefaultModGuestTitle = true;
    if (!checkListedAsOnlinevip) listedAsOnlinevip = true;
    if (!checkUserTimeout) userTimeout = 0;
    if (!checkMayUseTemplateset) mayUseTemplateset = null;
    if (!checkPrivatemessageStore) privatemessageStore = 0;
  }
Beispiel #15
0
 public boolean execute(MessageState msgState, String param) {
   if (isPunished(msgState)) return false;
   if (param.length() < 1) {
     msgState.msgTemplate = "error.su.noArg";
     msgState.sender.sendMessage(msgState.mp);
     return false;
   }
   msgState.targetGroup = msgState.sender.getGroup();
   Group sg = msgState.sender.getGroup();
   if (sg == null) return false;
   boolean mayChangeRights = msgState.sender.hasRight(IUserStates.MAY_CHANGE_RIGHT);
   if (!mayChangeRights && !sg.usrIsSu(msgState.sender)) {
     msgState.msgTemplate = "error.noRight.noSuVipAdmin";
     msgState.sender.sendMessage(msgState.mp);
     return false;
   }
   if (param.indexOf(" ") > -1 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) {
     msgState.msgTemplate = "error.mass.noRight.noVipAdmin";
     msgState.sender.sendMessage(msgState.mp);
     return false;
   }
   msgState.useRenderCache = false;
   GroupUserList gul = new GroupUserList();
   Vector<User> found = getMultibleUsers(msgState, param);
   for (Iterator<User> i = found.iterator(); i.hasNext(); ) {
     User cu = (User) i.next();
     if (cu.hasRight(IUserStates.ROLE_GOD)) {
       msgState.msgTemplate = "error.noRight.isAdmin";
       msgState.usercontext = cu;
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       continue;
     } else if (cu.hasRight(IUserStates.ROLE_VIP)) {
       msgState.msgTemplate = "error.noRight.isVip";
       msgState.usercontext = cu;
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       continue;
     } else if (cu.hasRight(IUserStates.ROLE_ASSHOLE)) {
       msgState.msgTemplate = "error.su.noRight";
       msgState.usercontext = cu;
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       continue;
     }
     if (!mayChangeRights && !msgState.sender.getGroup().equals(cu.getGroup())) {
       msgState.msgTemplate = "error.noRight.noVipAdmin";
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       continue;
     }
     if (cu.getMembership(sg.getSuForbiddenMembership()) != null) {
       msgState.msgTemplate = "error.noRight.isSuForbiddenMembership";
       msgState.usercontext = cu;
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       continue;
     }
     if (cu.getGroup() == null // user is currently changing groups...
         || cu.getGroup().usrIsSu(cu)) {
       i.remove();
       continue;
     }
     if (cu.getGroup().hasState(IGroupState.ENTRANCE)
         && !mayChangeRights
         && sg.suUserCount() >= Server.srv.MAX_SUUSERS_PER_STARTGROUP) {
       msgState.msgTemplate = "error.su.tooManyForStartgroup";
       msgState.param = String.valueOf(Server.srv.MAX_SUUSERS_PER_STARTGROUP);
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       while (i.hasNext()) {
         //    Object o = i.next();
         i.remove();
       }
       break;
     }
     msgState.usrList = null;
     if (setSuRight(msgState, cu, true)) {
       msgState.usercontext = cu;
       gul.addUser(cu, null);
       if (found.size() > 1) {
         msgState.msgTemplate = "message.su.personal";
         cu.sendMessage(msgState.mp);
       }
       StringBuffer sb = new StringBuffer();
       sb.append(msgState.sender.getName());
       sb.append(" gave su-rights to user ");
       sb.append(cu.getName());
       sb.append(" in group ");
       sb.append(cu.getGroup().getRawName());
       Server.log(this, sb.toString(), Server.MSG_STATE, Server.LVL_MINOR);
     } else if (!sg.usrIsSu(msgState.sender) && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) {
       User u = msgState.usercontext;
       msgState.usercontext = cu;
       msgState.msgTemplate = "error.noRight.noSuVipAdmin";
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       msgState.usercontext = u;
     } else if (!isSu(msgState.sender, cu.getGroup(), msgState)) {
       if (msgState.usrList != null) { // user doesn't have apropriate membership
         msgState.targetGroup = cu.getGroup();
         if (msgState.usrList.length > 1) {
           msgState.msgTemplate = "error.membership.notMember.many";
         } else {
           msgState.msgTemplate = "error.membership.notMember";
         }
         msgState.usercontext = cu;
         msgState.sender.sendMessage(msgState.mp);
         i.remove();
         continue;
       }
     } else {
       User u = msgState.usercontext;
       msgState.usercontext = cu;
       msgState.msgTemplate = "error.noRight.deactivated";
       msgState.sender.sendMessage(msgState.mp);
       i.remove();
       msgState.usercontext = u;
     }
   }
   if (found.size() == 0) return false;
   if (found.size() == 1) {
     msgState.msgTemplate = "message.su.singular";
     msgState.usercontext = (User) found.get(0);
     Group g = msgState.usercontext.getGroup();
     g.sendMessage(msgState.mp);
     if (!msgState.sender.getGroup().equals(g)) {
       msgState.msgTemplate = "message.su.confirm.singular";
       msgState.sender.sendMessage(msgState.mp);
     }
     return true;
   }
   msgState.msgTemplate = "message.su.confirm.plural";
   msgState.usrList = found.toArray();
   msgState.sender.sendMessage(msgState.mp);
   gul.sendMessage(msgState, "message.su", false);
   return true;
 }