`

zimbra修改记录分享

    博客分类:
  • java
阅读更多

晚上找到了jetty的日志,终于找到为何jetty没启动成功的原因。(原因是在做文字替换时,把类文件也给替换了,导致服务无法启动)

zimbra系统已经重新跑起来,登陆页面暂时的解决方案:

添加LogLogin.jsp页面。
skyBook在页面中打开:http://172.17.1.14/zimbra/public/LogLogin.jsp ,便能使用邮件系统。
今后通过传递用户名与密码,如:http://172.17.1.14/zimbra/public/LogLogin.jsp?name=12345&psw=abcd ,进行登陆,密码最好通过加密后传输。
并且在skyBook注册用户时,往zimbra数据库添加用户记录,已达到两个系统的用户一致。

 

另外把zimbra这两天的修改的内容记录下,今后修改可以参考:

1.zimbra不紧紧是一个web应用,是一个直接可运行的系统。在14机器结构如下:

/opt/zimbra:

bin/启动zimbra的文件

jetty:zimbra的Web服务器

java:zimbra的Java环境

memcache:缓存

httpd:apache httpd服务器

mysql:数据库

等。

 

启动zimbra命令:

/opt/zimbra/bin/zmcontrol stop

/opt/zimbra/bin/zmcontrol start

 

邮件系统的启动:

/opt/zimbra/bin/zmmailboxdctl stop

/opt/zimbra/bin/zmmailboxdctl start

/opt/zimbra/bin/zmmailboxdctl restart

 

2.zimbra修改内容

2.1 jsp文件:目录为/opt/zimbra/jetty/webapps/zimbra/public/

如修改login.jsp,将图片和商标的html去掉。

其他jsp文件暂时还没细读。

 

2.2 修改国际化中文编码

编码文件路径:zimbra/WEB-INF/classes/messages/*_zh_CN.properties

操作,先将unicode编码的文件转为中文,然后修改后再进行编码
native2ascii -reverse ZaMsg_zh_CN.properties a.txt
修改完a.txt后:
native2ascii a.txt ZaMsg_zh_CN.properties

 

2.3 linux下修改全部文件内容(此文件会替换全部文件夹下的文字。不能在类文件夹上使用,会把class文件的内容也替换掉。导致类文件检验出错)

http://www.zimbra.com 替换为http://www.logerp.com
find -type f | xargs perl -i -pe s%http://www.zimbra.com%http://www.logerp.com%g

 

2.4 skin的修改:

对应skin文件夹下,图标在skin/yahoo/logos,(其中yahoo为你选择的页面样式),每个样式下都有logos文件夹,可以进行替换图片。

 

3.源码

源码需要到网上下载,但是文件比较多,还没有进行编译和调试。

对代码阅读了一下,

 

3.1 skin对应请求为SkinResource.java(servlet),接受css/*,html/*的请求

然后读取后台skin文件夹的配置文件:skin/yahoo/base:

mainfest.xml,skin.css,skin.html,skin.properties

在请求资源时,根据配置文件对内容进行替换。

 

3.2 properties2javascript

国际化通过Props2JsServlet.java实现。

 

4.由于把/webapps/zimbra修改为/webapps/logerp后,需要改动很多文件,故出现了一些问题。导致应用无法启动。
经过排查。是在linux下执行替换文件时,把class文件,jar包里面的文字也改掉了,导致无法无法启动。
通过替换备份的文件。现在已经启动成功。
如果需要修改,请先备份,再做修改。

 

 

5.请求处理流程

 

a.进入/zimbra/进入SetHeadFilter,并转发到/service/user或/service/home请求

b./service/home对应UserServlet

c.UserServlet处理完毕后,调用不同的formater,对应网站就是HtmlFormater,跳转/zimbra/h/rest路径下

d./zimbra/h/rest不是jsp页面,内容是大量jstl,包括自定义jstl,这块代码难以阅读。

e.jstl处理完后返回html,css,js,其中js,css会通过SkinFilter进行替换,支持不同样式与中文

 

 

 

6.zimbra 前端视图

 

zimbra页面大量使用jstl生成页面:

1.jsp页面:部分页面使用jsp页面与标签库,在public/*.jsp,如login.jsp页面

2.jstl,自定义标签库。如h/search,search使用app标签,app:view,app:convListView,app:overView

3.js……

 

今天着重对zimbra的首页进行研究,普通版首页路径:/zimbra/h/search,结合图片说明:

a./h/search代码:

    < c:when test="${context.isConversationSearch}">
        < app:convListView context="${context}"/ >
    < / c:when >

以上使用app:convListView显示页面

 

b.app:convListView对应tag为/WEB-INF/tag/conv/convListView.tag

代码:< app:view mailbox="${mailbox}"

通过app:view显示

 

c.app:view为/WEB-INF/tag/infra/view.tag

view.tag代码使用

app:overView为左侧

 

d.中间内容为:< app:view mailbox="${mailbox}">< / app:view >内部标签

 

 

7.admin用户登陆:https://localhost:7071/zimbraAdmin/

 

zimbra创建新用户流程:
.service/admin/soap/CreateAccountRequest
//创建账户

 

证书导入:
1.keytool -import -file myca.cert -keystore %JAVA_HOME%\jre\lib\security\cacerts -file myca.cert -alias tomcat
2.此时命令行会提示你输入cacerts证书库的密码,你敲入changeit就行了,这是java中cacerts证书库的默认密码,

 

8.获得未读邮件数代码

public int getInbox(String name, String password) throws Exception {
  // 构造请求参数
  HashMap<String, String> map = new HashMap<String, String>();
  map.put("client", "adsf");// 此处不能设置mobile,原因未明
  map.put("loginOp", "login");
  map.put("password", password);
  map.put("username", name);

  StringBuffer bf = new StringBuffer();
  for (Map.Entry<String, String> entry : map.entrySet()) {
   bf.append("&" + entry.getKey() + "="
     + URLEncoder.encode(entry.getValue(), "UTF-8"));
  }
  String query = bf.toString().substring(1);

  // 创建url连接
  URL url = new URL("http://172.17.1.14/zimbra/");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setDoInput(true);
  connection.setDoOutput(true);
  connection.setRequestProperty("Host", "172.17.1.14");
  connection
    .setRequestProperty(
      "User-Agent",
      "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 GTBDFff GTB7.0");
  connection
    .setRequestProperty("Accept",
      "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  connection.setRequestProperty("Accept-Language", "zh-cn,zh;q=0.5");
  connection.setRequestProperty("Accept-Encoding", "deflate");
  connection.setRequestProperty("Accept-Charset",
    "GB2312,utf-8;q=0.7,*;q=0.7");
  connection.setRequestProperty("Keep-Alive", "300");
  connection.setRequestProperty("Connection", "keep-alive");
  connection.setRequestProperty("Referer",
    "http://172.17.1.14/zimbra/?loginOp=logout&client=mobile");
  connection.setRequestProperty("Cookie", "ZM_TEST=true");
  connection.setRequestMethod("POST");

  // 输出数据
  DataOutputStream output = new DataOutputStream(connection
    .getOutputStream());
  output.write(query.getBytes("UTF-8"));
  output.flush();
  output.close();

  // 读取信息
  InputStream in = connection.getInputStream();
  BufferedReader bufferedReader = new BufferedReader(
    new InputStreamReader(in));
  StringBuffer temp = new StringBuffer();
  String line = bufferedReader.readLine();

  while (line != null) {
   temp.append(line).append("\r\n");
   line = bufferedReader.readLine();
  }
  bufferedReader.close();

  String ecod = connection.getContentEncoding();
  if (ecod == null)
   ecod = "UTF-8";

  // 设置cookie
  String cookie = "";
  Map<String, List<String>> headerFields = connection.getHeaderFields();
  for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
   if ("Set-Cookie".equals(entry.getKey())) {
    for (String s : entry.getValue()) {
     cookie = s.substring(0, s.indexOf(";"));
     break;
    }
   }
  }

  // 请求mobile页面
  URL url2 = new URL("http://172.17.1.14/zimbra/m/mofolders");
  HttpURLConnection connection2 = (HttpURLConnection) url2
    .openConnection();
  connection2.setDoInput(true);
  connection2.setDoOutput(true);
  connection2.setRequestProperty("Cookie", "ZM_TEST=true;" + cookie);
  connection2.setRequestMethod("GET");
  // read in each character until end-of-stream is detected
  InputStream in2 = connection2.getInputStream();
  BufferedReader bufferedReader2 = new BufferedReader(
    new InputStreamReader(in2));
  StringBuffer temp2 = new StringBuffer();
  String line2 = bufferedReader2.readLine();

  String info = "";
  while (line2 != null) {
   if (!"".equals(line2.trim())) {
    line2 = new String(line2.trim().getBytes(), ecod);
    // 截取收件箱行
    if (line2.trim().startsWith("收件"))
     info = line2;
    temp2.append(line2).append("\r\n");
   }
   line2 = bufferedReader2.readLine();
  }
  bufferedReader2.close();

  // info = 收件箱(1)
  // 其中1为收件箱未读数
  if (info.indexOf("(") > 0) {
   String num = info.substring(info.indexOf("(") + 1, info
     .indexOf(")"));
   return Integer.parseInt(num);
  } else
   return 0;
 }

 

 

 

 

  • 大小: 39.2 KB
  • 大小: 146 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics