irontec / zsugar

Zimbra SugarCRM integration zimlet (unmaintained, see README)
3 stars 8 forks source link

Zimbra 8.5 does not support JSP servlet by default #2

Closed youwe closed 10 years ago

youwe commented 10 years ago

It keeps saying that the authentification failed. We tryed LDAP login details and the admin login details.

youwe commented 10 years ago

Here is some extra info. Exact error message: Incorrect Authentication. zsugar 1.4.12

Zimbra version 8.5.0 SugarCRM CE 6.5.12

It looks like its not connecting to sugarcrm at all when we look at the crm server logs.

Kaian commented 10 years ago

Hi Rob!

I should improve authentication messages....

Thanks!

youwe commented 10 years ago

Before we can do this we need to finish our sync. This will take a few more days. After this is done then we can follow the steps below and see if that helps. Will get back to you shortly.

Thanks

Op 15 sep. 2014, om 11:25 heeft Kaian notifications@github.com het volgende geschreven:

Hi Rob!

I should improve authentication messages....

Did you restart the zimbra mailbox after the zimlet inslatation. It proxys request through a JSP that requires restart after first installation. Can Zimbra machine reach your Mantis? What URL are you using? IP or FQDN? Do you know how to debug the request with Chrome Inspector or Firebug? Thanks!

— Reply to this email directly or view it on GitHub.

youwe commented 10 years ago

We tried to restart already. Did not worked. We are calling the direct web url of sugarcrm. Does it need an IP?

It tries to make the call with: http://sugar.ourdomain.nl/service/v2/rest.php

And username + md5 hashed password.

However the response is this: <% /*

<% // Get Post data String input_type = request.getParameter("input_type"); String method = request.getParameter("method"); String response_type = request.getParameter("response_type"); String rest_data = request.getParameter("rest_data"); String sugar_url = request.getParameter("sugar_url"); String encoding = request.getCharacterEncoding(); if (encoding == null) encoding = "UTF-8";

// Special Treatment for set_note_attachment REST method
if ( method.equals("set_note_attachment")){
    // Parse attachment URL
            int beg = rest_data.indexOf("file\":");
            int end = rest_data.indexOf("related_module_id\":");
    String attUrl = rest_data.substring(beg+7,end-3);
    String prefix = rest_data.substring(0,beg+7);
    String sufix  = rest_data.substring(end-3);

      try
      {
    // Download the file to the local temporary path
    String dirPath = System.getProperty("java.io.tmpdir", "/tmp");
    String filePath = dirPath + "/zsugar_att_" + System.currentTimeMillis();
    File readFile = new File (filePath);
    FileOutputStream readFileStream = new FileOutputStream(readFile.getPath());

    // Get Post Cookies
    javax.servlet.http.Cookie reqCookie[] = request.getCookies();
    org.apache.commons.httpclient.Cookie[] clientCookie = new org.apache.commons.httpclient.Cookie[reqCookie.length];
    String hostName = request.getServerName () + ":" + request.getServerPort();

    for (int i=0; i<reqCookie.length; i++) {
            javax.servlet.http.Cookie cookie = reqCookie[i];
            clientCookie[i] = new org.apache.commons.httpclient.Cookie (hostName,cookie.getName(), cookie.getValue(),"/",null,false);
        }

    // Get Connection State
    HttpState state = new HttpState();
    state.addCookies (clientCookie);

    // Create a HTTP client with the actual state 
    HttpClient srcClient = new HttpClient();
    Enumeration headerNamesImg = request.getHeaderNames();
        while(headerNamesImg.hasMoreElements()) {
            String headerNameImg = (String)headerNamesImg.nextElement();
            srcClient.getParams().setParameter(headerNameImg, request.getHeader(headerNameImg));
    }
    srcClient.setState (state);

    // Convert the URL
    int paramsbeg = attUrl.indexOf("id=")-1;
    String filename = attUrl.substring(0, paramsbeg);
    String getparam = attUrl.substring(paramsbeg, attUrl.length());
    attUrl = URIUtil.encodePath(filename, "ISO-8859-1") + getparam;
    //out.println(attUrl);

    // Download the Image
    GetMethod get = new GetMethod (attUrl);
    get.setFollowRedirects (true);
    srcClient.getHttpConnectionManager().getParams().setConnectionTimeout (10000);
    srcClient.executeMethod(get);

    // Copy the image to a local temporaly file
    ByteUtil.copy(get.getResponseBodyAsStream(), false, readFileStream, false);
    readFileStream.close();

    // Read the temporary file and output its Base64-values
    BufferedInputStream base64In = new BufferedInputStream(new FileInputStream(readFile.getPath()));

    int lineLength = 12288;
    byte[] buf = new byte[lineLength/4*3];

    while(true) {
          int len = base64In.read(buf);
          if (len <= 0) break;
          prefix += new String(Base64Coder.encode(buf, 0, len));
    }
    base64In.close();

    // Update prameter rest_data with the binary data of the file
    rest_data = prefix + sufix;

  } catch (Exception e) { 
    out.println("A problem occurried while handling attachment file:"+e.getMessage());
  }
}

  // Create a HTTP client to foward REST petition
  HttpClient client = new HttpClient();
  Enumeration headerNames = request.getHeaderNames();
  while(headerNames.hasMoreElements()) {
    String headerName = (String)headerNames.nextElement();
client.getParams().setParameter(headerName, request.getHeader(headerName));
//out.println(headerName+":"+request.getHeader(headerName));
  }
  client.getParams().setParameter("http.protocol.expect-continue", true);

  BufferedReader br = null;

  // Set the input data for POST method
  PostMethod pmethod = new PostMethod(sugar_url);

  org.apache.commons.httpclient.methods.multipart.Part[] parts = {
    new org.apache.commons.httpclient.methods.multipart.StringPart("input_type",input_type, encoding),
    new org.apache.commons.httpclient.methods.multipart.StringPart("method", method, encoding),
    new org.apache.commons.httpclient.methods.multipart.StringPart("response_type", response_type, encoding),
    new org.apache.commons.httpclient.methods.multipart.StringPart("rest_data", rest_data, encoding)};

  try{
pmethod.setRequestEntity(new org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity(parts, pmethod.getParams()));
    int returnCode = client.executeMethod(pmethod);

    if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            out.println("The Post method is not implemented by this URI");
            // still consume the response body
            pmethod.getResponseBodyAsString();
    } else {
            br = new BufferedReader(new InputStreamReader(pmethod.getResponseBodyAsStream()));
            String readLine;
    // Write the respone body
            while(((readLine = br.readLine()) != null)) {
           out.println(readLine); 
            }
    }

  } catch (Exception e) {
    out.println(e);
  } finally {
    pmethod.releaseConnection();
    if(br != null) try { br.close(); } catch (Exception fe) {}
 }

Op 15 sep. 2014, om 11:25 heeft Kaian notifications@github.com het volgende geschreven:

Hi Rob!

I should improve authentication messages....

Did you restart the zimbra mailbox after the zimlet inslatation. It proxys request through a JSP that requires restart after first installation. Can Zimbra machine reach your Mantis? What URL are you using? IP or FQDN? Do you know how to debug the request with Chrome Inspector or Firebug? Thanks!

— Reply to this email directly or view it on GitHub.

Kaian commented 10 years ago

Hi!

SugarCRM IP is not a must if zimbra can resolve it.

That code is the proxy (redirect.jsp) code and It should no be in a Response o.o Try accesing, you should get a 500 Server Error Response, not the JSP source code...

https://zimbra.yourdoumain.com/service/zimlet/com_irontec_zsugar/redirect.jsp

Kaian commented 10 years ago

Hi Rob!

I'm reading some notes about 8.5 and it seems JSP is disabled by default.

Disable JSP servlet in default webapp configuration;
leave it enabled only in /zimbra and /zimbraAdmin webapps

Add zimbraZimletJspEnabled attribute to turn on/off JSP compilation 
for /zimlet webapp. Disabled (false) by default.

So it must be enabled. I don't have a Zimbra 8.5 installed so I can not test, but after some digging, you can change it from the shell and restart again (change the server name, of course):

root@zimbra8-dev:~# su - zimbra 
zimbra@zimbra8-dev:~$ zmprov gs zimbra8-dev.irontec.com | grep zimbraZimletJspEnabled
 (should be FALSE)
zimbra@zimbra8-dev:~$ zmprov ms zimbra8-dev.irontec.com zimbraZimletJspEnabled TRUE
zimbra@zimbra8-dev:~$ zmcontrol restart
youwe commented 10 years ago

We need to wait until our batch sync is finished. Probably this weekend. We can then try the solution suggested. Will get back shortly.

Op 16 sep. 2014, om 18:46 heeft Kaian notifications@github.com het volgende geschreven:

Hi Rob!

I'm reading some notes about 8.5 and it seams JSP is disabled by default.

Disable JSP servlet in default webapp configuration; leave it enabled only in /zimbra and /zimbraAdmin webapps

Add zimbraZimletJspEnabled attribute to turn on/off JSP compilation for /zimlet webapp. Disabled (false) by default. So it must be enabled. I don't have a Zimbra 8.5 installed so I can not test, but after some digging, you can change it from the shell and restart again (change the server name, of course):

root@zimbra8-dev:~# su - zimbra zimbra@zimbra8-dev:~$ zmprov gs zimbra8-dev.irontec.com | grep zimbraZimletJspEnabled (should be FALSE) zimbra@zimbra8-dev:~$ zmprov ms zimbra8-dev.irontec.com zimbraZimletJspEnabled TRUE zimbra@zimbra8-dev:~$ zmcontrol restart — Reply to this email directly or view it on GitHub.

youwe commented 10 years ago

Yes. It works. We had to activate the JSP servlet. We also found out that the extension uses the IP of the users and not the IP of the zimbra server. Which makes it a bit more difficult to whitelist just the zimbra server on sugarcrm. Is there a solution for this at the moment?

Op 16 sep. 2014, om 18:46 heeft Kaian notifications@github.com het volgende geschreven:

Hi Rob!

I'm reading some notes about 8.5 and it seams JSP is disabled by default.

Disable JSP servlet in default webapp configuration; leave it enabled only in /zimbra and /zimbraAdmin webapps

Add zimbraZimletJspEnabled attribute to turn on/off JSP compilation for /zimlet webapp. Disabled (false) by default. So it must be enabled. I don't have a Zimbra 8.5 installed so I can not test, but after some digging, you can change it from the shell and restart again (change the server name, of course):

root@zimbra8-dev:~# su - zimbra zimbra@zimbra8-dev:~$ zmprov gs zimbra8-dev.irontec.com | grep zimbraZimletJspEnabled (should be FALSE) zimbra@zimbra8-dev:~$ zmprov ms zimbra8-dev.irontec.com zimbraZimletJspEnabled TRUE zimbra@zimbra8-dev:~$ zmcontrol restart — Reply to this email directly or view it on GitHub.

Kaian commented 10 years ago

Umm that's strange, the servlet is making the http request to the SugarCRM server so the origin IP should be the Zimbra one.

I had some quick tests in our dev environment and I receive the POST /sugarcrm//service/v2/rest.php from the Zimbra address....