Keep It Simple, Stupid.

荒野无灯weblog

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

下载源码

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

安装中文字体

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

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

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

graphs.c

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 荒野无灯     */
+/*                                                               */
+/*****************************************************************/
+
+/**
+ * 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":

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,"
\n
\n

\n"); + fprintf(out_fp,"

sample.conf

+FontPath /usr/share/fonts/truetype/arphic/uming.ttc

 #HTMLHead 
 #HTMLHead 
+HTMLHead 

+HTMLEnd 
+HTMLEnd ↑Top +HTMLEnd
HTMLEnd

webalizer.c

 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  */

安装

./configure --prefix=/usr \
--sysconfdir=/etc/webalizer \
--enable-dns \
--with-geodb=/etc/webalizer/GeoDB.dat \
--enable-bz2 \
--enable-geoip \
--with-language=simplified_chinese
make
checkinstall

配置

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

Run Webalizer automatically with a cron job

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

增加访问限制

使用htpasswd建立用户文件

htpasswd -c /etc/apache2/.htpasswd admin

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

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汉化及图片修正完全补丁

Tagged in : webalizer

All Comments (0)
Gravatar image
No Comments