Ejemplo n.º 1
0
 public static Element getConfig() {
   if (config == null) {
     try {
       config =
           Document.fromStream(ActionServlet.class.getResourceAsStream("resources/config.xml"))
               .getRootElement();
       System.out.println("Config loaded from resources");
     } catch (Exception ex) {
       System.out.println("WARNING: config resource not found: using STATIC config!");
       config = new Element("config");
       String vmtemp = "/var/lib/tomcat6/webapps/osdx_keyserver/vm_templates";
       System.out.println("vmtemplatepath: " + vmtemp);
       config.addContent("vmtemplatepath", vmtemp);
       Element eDB = new Element("db");
       eDB.addContent("name", "jdbc:postgresql://localhost:5432/keyserverdb");
       eDB.addContent("user", "keyserver");
       eDB.addContent("password", "oo0oo_keyserverDBpassword_..Q..");
       eDB.addContent("data_path", "/home/neo/db_data");
       config.addContent(eDB);
     }
   }
   return config;
 }
Ejemplo n.º 2
0
  // doGet, doPost delegate to this method
  @SuppressWarnings("unchecked")
  public void doPGU(HttpServletRequest request, HttpServletResponse response, String method) {
    initVelocity();

    // parse command and arguments from request path
    String pathinfo = request.getPathInfo();
    if (pathinfo == null) {
      pathinfo = "";
    }

    System.out.println("REQUEST: " + pathinfo);

    String cmd = null;

    StringTokenizer kk = new StringTokenizer(pathinfo, "/");
    int i = 0;
    Vector[] args = {new Vector<String>(), new Vector<String>()};
    if (kk.countTokens() != 0) {
      cmd = kk.nextToken();
      while (kk.hasMoreTokens()) {
        String kkk = URLDecoder.decode(kk.nextToken());
        System.out.println("[" + method + "] PATHINFO[" + i + "]: " + kkk);
        args[i % 2].add(kkk);
        i++;
      }
    }

    // Default-cmd == index
    if (cmd == null || cmd.equals("")) {
      cmd = "index";
    }

    if ("keyinfo".equals(cmd)) {
      handleKeyInfo(request, response, method, cmd, args);
    } else if ("keygraph".equals(cmd)) {
      handleKeyGraph(request, response, method, cmd, args);
    } else if ("index".equals(cmd)) {
      RenderVelocityAction action = new RenderVelocityAction(request, response, method, "index.vm");
      handleAction(action, cmd, args, request);
    } else if ("echo".equals(cmd)) {
      RenderVelocityAction action = new RenderVelocityAction(request, response, method, "echo.vm");
      handleAction(action, cmd, args, request);
    } else if ("ajax_nodes_edges".equals(cmd)) {

      Element res = new Element("nodes_edges");
      // add key
      String keyid = getValueString("keyid", args);
      if (keyid != null) {
        System.out.println("ajax_nodes_edges:: keyid=" + keyid);
        Vector<String> keyids = new Vector<String>();
        // key basics
        OSDXKey key = getBackend().getKey(keyid);
        if (key != null) {
          res.addContent(key.getSimplePubKeyElement());
          keyids.add(key.getKeyID());

          // add keylogs and fromKeys
          Vector<KeyLog> logs = getBackend().getKeyLogsToID(key.getKeyID());
          if (logs != null && logs.size() > 0) {
            for (KeyLog l : logs) {
              if (!keyids.contains(l.getKeyIDFrom())) {
                OSDXKey fromkey = getBackend().getKey(l.getKeyIDFrom());
                if (fromkey != null) {
                  res.addContent(fromkey.getSimplePubKeyElement());
                  keyids.add(fromkey.getKeyID());
                }
              }
              res.addContent(l.toElement(false));
            }
          }
        }
      }
      response.setContentType("text/xml");
      try {
        PrintWriter out = response.getWriter();
        out.println(Document.buildDocument(res).toStringCompact());
        out.flush();
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }