Example #1
0
 /**
  * This method creates an event vector based on a given request object.
  *
  * @param request The HttpRequest object.
  * @return A Vector containing the events
  */
 private Vector createEventVector(HTTPRequest request) {
   Vector eventVector = new Vector();
   if (request.getQueryValue("mauiEvent") != null) {
     eventVector = StringUtilities.split(".", request.getQueryValue("mauiEvent"));
   }
   return eventVector;
 }
 public void addRequestInfo(String ip, HTTPRequest request) {
   Client client = getClientByIp(ip);
   client.addRequest(request);
   request.setClient(client);
   request.fixTimeSpent();
   requests.add(request);
   boolean isNewRequest = uniqueRequests.add(request);
   if (request.existsRedirect()) {
     Integer count = isNewRequest ? 1 : uniqueRedirects.get(request) + 1;
     uniqueRedirects.put(request, count);
   }
 }
Example #3
0
  /**
   * This method takes care of some special generic Maui events. It should be called before the Maui
   * application handles the event.
   *
   * @param mauiApp Reference to the MauiApplication associated with the events
   * @param eventVector The same event vector that is passed to the Maui app.
   * @param paramHash Hashtable of HTTP parameters
   * @param response The HTTPResponse object which will be sent back to the client
   */
  private void processEvent(
      MauiApplication mauiApp,
      Vector eventVector,
      Hashtable paramHash,
      HTTPRequest request,
      HTTPResponse response) {
    boolean passEventToMauiApp = true;

    try {
      if (eventVector != null && !eventVector.isEmpty()) {
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        // Component events
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        String componentID = (String) eventVector.lastElement();

        // If there are parentheses...
        if (componentID.startsWith("(") && componentID.endsWith(")")) {
          // ... strip them off!
          componentID = componentID.substring(1, componentID.length() - 1);
        }

        //
        //	Strip off prefix - some wml browsers don't like variables that begin with a digit
        //
        if (componentID.startsWith("IDz")) {
          componentID = componentID.substring(3);
        }
        {
          System.err.println("componentID: " + componentID);
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        // Pass events to Maui application
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        // Check for a content-type override
        String contentType = null;
        {
          if ((contentType = request.getQueryValue("contentType")) != null) {
            response.setContentType(contentType);
          } else {
            response.setContentType("x-wap.wml");
          }
        }
        response.setContent(mauiApp.render().getBytes());
      } else {
        response.setContentType("text/vnd.wap.wml");
        response.setContent(mauiApp.render().getBytes());
      }
    } catch (Exception e) {
      response.setContentType(getBaseContentType());
      response.setContent((generateExceptionMessage(e)).getBytes());
      e.printStackTrace(System.err);
    }
  }
Example #4
0
 @Override
 public String runMacro(HTTPRequest httpReq, String parm, HTTPResponse httpResp) {
   final String last = httpReq.getUrlParameter("ROOM");
   if (last == null) return " @break@";
   if (last.length() > 0) {
     final Room R = MUDGrinder.getRoomObject(httpReq, last);
     if (R != null) return clearWebMacros(R.roomID());
   }
   return "";
 }
Example #5
0
  @Override
  public String runMacro(HTTPRequest httpReq, String parm) {
    final java.util.Map<String, String> parms = parseParms(parm);
    boolean finalCondition = false;
    for (String key : parms.keySet()) {
      if (key.length() == 0) continue;
      final String equals = parms.get(key);
      boolean not = false;
      boolean thisCondition = true;
      boolean startswith = false;
      boolean inside = false;
      boolean endswith = false;
      if (key.startsWith("||")) key = key.substring(2);
      if (key.startsWith("<")) {
        startswith = true;
        key = key.substring(1);
      }
      if (key.startsWith(">")) {
        endswith = true;
        key = key.substring(1);
      }
      if (key.startsWith("*")) {
        inside = true;
        key = key.substring(1);
      }

      if (key.startsWith("!")) {
        key = key.substring(1);
        not = true;
      }
      final String check = httpReq.getUrlParameter(key);
      if (not) {
        if ((check == null) && (equals.length() == 0)) thisCondition = false;
        else if (check == null) thisCondition = true;
        else if (startswith) thisCondition = !check.startsWith(equals);
        else if (endswith) thisCondition = !check.endsWith(equals);
        else if (inside) thisCondition = !(check.indexOf(equals) >= 0);
        else if (!check.equalsIgnoreCase(equals)) thisCondition = true;
        else thisCondition = false;
      } else {
        if ((check == null) && (equals.length() == 0)) thisCondition = true;
        else if (check == null) thisCondition = false;
        else if (startswith) thisCondition = check.startsWith(equals);
        else if (endswith) thisCondition = check.endsWith(equals);
        else if (inside) thisCondition = (check.indexOf(equals) >= 0);
        else if (!check.equalsIgnoreCase(equals)) thisCondition = false;
        else thisCondition = true;
      }
      finalCondition = finalCondition || thisCondition;
    }
    if (finalCondition) return "true";
    return "false";
  }
 @Override
 public String runMacro(HTTPRequest httpReq, String parm, HTTPResponse httpResp) {
   final java.util.Map<String, String> parms = parseParms(parm);
   final String last = httpReq.getUrlParameter("GOVERNMENT");
   if (parms.containsKey("RESET")) {
     if (last != null) httpReq.removeUrlParameter("GOVERNMENT");
     return "";
   }
   int lastID = -1;
   for (final ClanGovernment G : CMLib.clans().getStockGovernments()) {
     if ((last == null)
         || ((last.length() > 0) && (CMath.s_int(last) == lastID) && (G.getID() != lastID))) {
       httpReq.addFakeUrlParameter("GOVERNMENT", Integer.toString(G.getID()));
       return "";
     }
     lastID = G.getID();
   }
   httpReq.addFakeUrlParameter("GOVERNMENT", "");
   if (parms.containsKey("EMPTYOK")) return "<!--EMPTY-->";
   return " @break@";
 }
 @Override
 public String runMacro(HTTPRequest httpReq, String parm, HTTPResponse httpResp) {
   final String last = httpReq.getUrlParameter("GOVERNMENT");
   if (last == null) return " @break@";
   if (last.length() > 0) {
     if (CMath.isInteger(last)) {
       final ClanGovernment G = CMLib.clans().getStockGovernment(CMath.s_int(last));
       if (G != null) return clearWebMacros(Integer.toString(G.getID()));
     }
     return clearWebMacros(last);
   }
   return "";
 }
Example #8
0
  public String postFile(URLFetchService us, List<PostObj> postobjlist) throws Exception {
    int index;

    Gson gson;
    String linkID;
    List<String> linkList;
    HTTPRequest req;
    String param;

    gson = new Gson();

    linkID = createUID();
    linkList = new ArrayList<String>();
    for (index = 0; index < postobjlist.size(); index++) {
      linkList.add(postobjlist.get(index).filelink);
    }

    param =
        URLEncoder.encode("postlist", "UTF-8")
            + "="
            + URLEncoder.encode(gson.toJson(postobjlist), "UTF-8")
            + '&'
            + URLEncoder.encode("linkid", "UTF-8")
            + "="
            + URLEncoder.encode(linkID, "UTF-8")
            + '&'
            + URLEncoder.encode("linklist", "UTF-8")
            + "="
            + URLEncoder.encode(gson.toJson(linkList), "UTF-8");
    req =
        new HTTPRequest(
            new URL("http://tnfshmoe.appspot.com/postdf89ksfxsyx9sfdex09usdjksd"), HTTPMethod.POST);
    req.setPayload(param.getBytes());
    us.fetch(req);

    return linkID;
  }
 @Override
 public CacheItem get(HTTPRequest request) {
   Connection connection = getConnection();
   PreparedStatement statement = null;
   try {
     statement = connection.prepareStatement("select * from response where uri = ?");
     statement.setString(1, request.getRequestURI().toString());
     ResultSet rs = statement.executeQuery();
     while (rs.next()) {
       CacheItemHolder holder = mapper.mapRow(rs, connection);
       if (holder.getVary().matches(request)) {
         return holder.getCacheItem();
       }
     }
   } catch (SQLException e) {
     throw new DataAccessException(e);
   } finally {
     JdbcUtil.close(statement);
   }
   return null;
 }
Example #10
0
 /**
  * This method creates a parameter hashtables based on a given request object.
  *
  * @param request The HttpServletRequest object.
  * @return A Hashtable containing the HTTP parameter key/value pairs
  */
 private Hashtable createParamHash(HTTPRequest request) {
   return request.getQueries();
 }
 public void set(HTTPRequest httpReq) {
   set((HTTPPacket) httpReq);
   setSocket(httpReq.getSocket());
 }
Example #12
0
  @Override
  public String runMacro(HTTPRequest httpReq, String parm) {
    final java.util.Map<String, String> parms = parseParms(parm);
    final String last = httpReq.getUrlParameter("JOURNAL");
    if (last == null) return " @break@";
    boolean securityOverride = false;
    if ((Thread.currentThread() instanceof CWThread)
        && CMath.s_bool(((CWThread) Thread.currentThread()).getConfig().getMiscProp("ADMIN"))
        && parms.containsKey("ALLFORUMJOURNALS")) securityOverride = true;

    final MOB M = Authenticate.getAuthenticatedMob(httpReq);
    if ((!securityOverride)
        && (CMLib.journals().isArchonJournalName(last))
        && ((M == null) || (!CMSecurity.isASysOp(M)))) return " @break@";

    final Clan setClan = CMLib.clans().getClan(httpReq.getUrlParameter("CLAN"));
    final JournalsLibrary.ForumJournal journal = CMLib.journals().getForumJournal(last, setClan);
    if (journal == null) return " @break@";

    final StringBuffer str = new StringBuffer("");
    if (parms.containsKey("ISSMTPFORWARD")) {
      @SuppressWarnings("unchecked")
      final TreeMap<String, JournalsLibrary.SMTPJournal> set =
          (TreeMap<String, JournalsLibrary.SMTPJournal>)
              Resources.getResource("SYSTEM_SMTP_JOURNALS");
      final JournalsLibrary.SMTPJournal entry =
          (set != null) ? set.get(last.toUpperCase().trim()) : null;
      final String email =
          ((M != null) && (M.playerStats() != null) && (M.playerStats().getEmail() != null))
              ? M.playerStats().getEmail()
              : "";
      str.append(
              ((entry != null) && (email.length() > 0)) ? Boolean.toString(entry.forward) : "false")
          .append(", ");
    }

    if (parms.containsKey("ISSMTPSUBSCRIBER")) {
      final Map<String, List<String>> lists =
          Resources.getCachedMultiLists("mailinglists.txt", true);
      final List<String> mylist = lists.get(last);
      str.append(
              ((mylist != null) && (M != null))
                  ? Boolean.toString(mylist.contains(M.Name()))
                  : "false")
          .append(", ");
    }

    if (parms.containsKey("SMTPADDRESS")) {
      @SuppressWarnings("unchecked")
      final TreeMap<String, JournalsLibrary.SMTPJournal> set =
          (TreeMap<String, JournalsLibrary.SMTPJournal>)
              Resources.getResource("SYSTEM_SMTP_JOURNALS");
      final JournalsLibrary.SMTPJournal entry =
          (set != null) ? set.get(last.toUpperCase().trim()) : null;
      if ((entry != null) && (entry.forward)) {
        str.append(entry.name.replace(' ', '_') + "@" + CMProps.getVar(CMProps.Str.MUDDOMAIN))
            .append(", ");
      }
    }

    if (parms.containsKey("CANADMIN") || parms.containsKey("ISADMIN"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.ADMIN)).append(", ");

    if (parms.containsKey("CANPOST"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.POST)).append(", ");

    if (parms.containsKey("CANREAD"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.READ)).append(", ");

    if (parms.containsKey("CANREPLY"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.REPLY)).append(", ");

    if (parms.containsKey("ADMINMASK")) str.append("" + journal.adminMask()).append(", ");

    if (parms.containsKey("READMASK")) str.append("" + journal.readMask()).append(", ");

    if (parms.containsKey("POSTMASK")) str.append("" + journal.postMask()).append(", ");

    if (parms.containsKey("REPLYMASK")) str.append("" + journal.replyMask()).append(", ");

    if (parms.containsKey("ID")) str.append("" + journal.NAME()).append(", ");

    if (parms.containsKey("NAME")) str.append("" + journal.NAME()).append(", ");

    if (parms.containsKey("EXPIRE")) str.append("").append(", ");

    final JournalsLibrary.JournalSummaryStats stats = CMLib.journals().getJournalStats(journal);
    if (stats == null) return " @break@";

    if (parms.containsKey("POSTS")) str.append("" + stats.posts).append(", ");

    if (parms.containsKey("THREADS")) str.append("" + stats.threads).append(", ");

    if (parms.containsKey("SHORTDESC")) str.append("" + stats.shortIntro).append(", ");

    if (parms.containsKey("LONGDESC")) str.append("" + stats.longIntro).append(", ");

    if (parms.containsKey("IMAGEPATH")) {
      if ((stats.imagePath == null) || (stats.imagePath.trim().length() == 0))
        str.append(L("images/lilcm.jpg")).append(", ");
      else str.append("" + stats.threads).append(", ");
    }

    String strstr = str.toString();
    if (strstr.endsWith(", ")) strstr = strstr.substring(0, strstr.length() - 2);
    return clearWebMacros(strstr);
  }
 public boolean post(HTTPRequest req) {
   return send(req.toString(), null, -1);
 }
 public boolean post(HTTPRequest req, String bindAddr, int bindPort) {
   return send(req.toString(), bindAddr, bindPort);
 }