日志统计分析程序webalizer添加中文支持

下载源码

1
2
3
4
5
6
7
8
9
wget ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.23-05-src.tar.bz2
tar xvjf cd webalizer-2.23-05-src.tar.bz2
cd webalizer-2.23-05/
apt-get install libgeoip-dev libbz2-dev db4.8-util libdb4.8-dev
apt-get install libgd2-xpm-dev
mkdir /etc/webalizer
cd /etc/webalizer
wget ftp://ftp.mrunix.net/pub/webalizer/geodb/webalizer-geodb-20120901.tgz
tar xvzf webalizer-geodb-20120901.tgz

安装中文字体

1
apt-get install ttf-arphic-uming ttf-arphic-ukai

修改增加中文支持(主要是调用ttf字体的gd函数来生成图片)

由于diff文件比较长,这里只帖出关键的部分。

graphs.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
diff -Nur webalizer-2.23-05-orig/graphs.c webalizer-2.23-05/graphs.c
--- webalizer-2.23-05-orig/graphs.c 2011-01-03 12:51:06.000000000 +0800
+++ webalizer-2.23-05/graphs.c  2012-09-02 13:47:15.000000000 +0800
@@ -75,6 +75,9 @@
 void    init_graph(char *, int, int);
 struct  pie_data *calc_arc(float, float);
 int     ashex2int(char *);
+void my_gdImageString(gdImagePtr, gdFontPtr , int , int , unsigned char *, int );
+void my_gdImageStringUp(gdImagePtr , gdFontPtr , int , int , unsigned char *, int );
+
 
 /* common public declarations */
 
@@ -98,6 +101,27 @@
 
 /*****************************************************************/
 /*                                                               */
+/* Chinese font support by 荒野无灯<huangyewueng@vip.qq.com>     */
+/*                                                               */
+/*****************************************************************/
+
+/**
+ * font_path is extern var defined in webalizer.h and set in webalizer.c
+ */
+void my_gdImageString(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
+{
+   gdImageStringFT(im, 0 , color, font_path, 9 , 0.0, x, y+9, s); //font size is 9
+}
+
+void my_gdImageStringUp(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
+{
+        gdImageStringFT(im, 0 , color, font_path, 9 , -PI/2, x, y-9 , s);
+}

然后把所有的gdImageStringUp替换为my_gdImageStringUp
gdImageString替换为my_gdImageString
再把my_my_替换为my_

再将lang/webalizer_lang.simplified_chinese重新保存为utf-8编码的文件。

为了增加一个“return top":

1
2
3
4
5
6
7
8
9
10
diff -Nur webalizer-2.23-05-orig/output.c webalizer-2.23-05/output.c
--- webalizer-2.23-05-orig/output.c 2011-01-03 12:52:05.000000000 +0800
+++ webalizer-2.23-05/output.c  2012-09-02 14:17:37.000000000 +0800
@@ -223,7 +223,7 @@
       fprintf(out_fp,"%s\n",lptr->string);
       lptr=lptr->next;
    }
-   fprintf(out_fp,"<CENTER>\n<HR>\n<P>\n");
+   fprintf(out_fp,"<CENTER id='nav'>\n<HR>\n<P>\n");
 }

sample.conf

1
2
3
4
5
6
7
8
9
10
+FontPath /usr/share/fonts/truetype/arphic/uming.ttc

 #HTMLHead <META NAME="author" CONTENT="The Webalizer">
 #HTMLHead <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
+HTMLHead <meta http-equiv="content-type" content="text/html; charset=UTF-8">

+HTMLEnd <div style='display:block;position:fixed;bottom:45px;right:200px;height:30px;'>
+HTMLEnd    <a href='#nav' style='color:blue;'>↑Top</a>
+HTMLEnd </div>
HTMLEnd </BODY></HTML>

webalizer.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 int     dump_search  = 0;                     /* Search strings           */
 int     dump_header  = 0;                     /* Dump header as first rec */
 char    *dump_path   = NULL;                  /* Path for dump files      */
+char   *font_path   = "/usr/share/fonts/truetype/arphic/ukai.ttc"; /*default font path */

@@ -1863,6 +1865,7 @@
         case 119: use_flags=1; flag_dir=save_opt(value); break; /* FlagDir  */
         case 120: searchcasei=
                     (tolower(value[0])=='n')?0:1;  break; /* SearchCaseI    */
+       case 121: font_path=save_opt(value); break;  /* Font Path    */
       }
    }
    fclose(fp);


webalizer.h
 extern int     dump_header  ;                 /* Dump header as first rec */
 extern char    *dump_path   ;                 /* Path for dump files      */
+extern char    *font_path   ;                /* Chinese font  for gragh  */

安装

1
2
3
4
5
6
7
8
9
./configure --prefix=/usr \
--sysconfdir=/etc/webalizer \
--enable-dns \
--with-geodb=/etc/webalizer/GeoDB.dat \
--enable-bz2 \
--enable-geoip \
--with-language=simplified_chinese
make
checkinstall

配置

1
cp sample.conf /etc/webalizer/webalizer.conf

Run Webalizer automatically with a cron job

1
2
3
crontab -e
 # Run Webalizer to update Apache Log files.
        * 1 * * *      /usr/bin/webalizer

增加访问限制

使用htpasswd建立用户文件

1
htpasswd -c /etc/apache2/.htpasswd admin

此程序会询问用户"admin"的口令
建立.htaccess文件

1
2
3
4
AuthName admin-only
AuthType Basic
AuthUserFile .htpasswd
require user admin

打好补丁的源码下载

webalizer-2.23-05-hywd-patched.tar.bz2

webalizer-1

webalizer-2

参考文档

PHP开源Apache日志分析工具收集与比较
Webalizer Quick Help
Webalizer中文帮助文件名词解释
发布一个webalizer中文UTF-8汉化及图片修正完全补丁

更多
2 Responses Post a comment
  1. Kayo

    现在没有用 VPS 了,折腾这个没那么方便!

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS