好久没关注Webalizer,因为n年没更新了,但日前不经意间看到他出2.20-01了,而且还一个月了有。
看看2.20-01新增加的功能,当然你可以看这里 ftp://ftp.mrunix.net/pub/webalizer/CHANGES
Fix就先不说了,我认为比较重要的是下面的2个,其他看说CHANGES。
Added GeoIP support
Added IPv6 support
我对IPv6不是很感冒,估计不是这几年能实行的。
GeoIP ,我本来用的是 Geolizer ,一个patch。应该是同等功效吧。
接下来编译安装吧。
./configure –prefix=/usr/local/webalizer \
–enable-static \
–enable-geoip \
–with-gd=/usr/local/gd2/include \
–with-gdlib=/usr/local/gd2/lib \
–with-png=/usr/local/include \
–with-pnglib=/usr/local/lib \
–with-geoip=/usr/local/include \
–with-geoiplib=/usr/local/lib \
–with-language=simplified_chinese
中文还是有问题,图片等地方还是不行,还是用英文吧!
你一定要用中文的,那也行,参考:[原创]ANSI(GB2312)编码全中文支持的WEBALIZER版本,GD库 GB2312折衷支持。
原理很简单,整理仅仅把图片里面的文字转换成utf-8编码,然后利用freetype的 gdImageStringFT 函数里换原来 gd 的gdImageString 和 gdImageStringUp 来绘图。
简单使用如下,编辑 graphs.c 文件。
最前面加:
#include <iconv.h>
#define OUTLEN 255
最后面加:
int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen)
{
iconv_t cd;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset,from_charset);
if (cd==0) return -1;
memset(outbuf,0,outlen);
if (iconv(cd,pin,&inlen,pout,&outlen)==-1) return -1;
iconv_close(cd);
return 0;
}
void gdImageString(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
{
char out[OUTLEN];
code_convert(“gb2312″,”utf-8”,s,strlen(s),out,OUTLEN);
gdImageStringFT(im, 0 , color, “/usr/local/share/fonts/msyh.ttf”, 9 , 0.0, x, y+9, out);
}
void gdImageStringUp(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
{
char out[OUTLEN];
code_convert(“gb2312″,”utf-8”,s,strlen(s),out,OUTLEN);
gdImageStringFT(im, 0 , color, “/usr/local/share/fonts/msyh.ttf”, 9 , -PI/2, x, y-9 , out);
}
我这里用的是微软雅黑的字体,你也可以使用别的中文字体,请自己替换。
另:如果你编译gd的时候没有把 freetype 编译进去是不行的。如果编译 gd 的时候是动态的话,编译 webalizer 也要动态了。去掉 –enable-static
配置 Webalizer:
下载 GeoIP 数据:
cd /usr/local/share/GeoIP
wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
gunzip -f GeoIP.dat.gz
配置 webalizer.conf 文件:
cp webalizer.conf.sample webalizer.conf
编辑 webalizer.conf
启用 GeoIP,并设置 GeoIP.dat
GeoIP yes
GeoIPDatabase /usr/local/share/GeoIP/GeoIP.dat
怎么用,我就不说了,网上也有很文档,中文英文的都有,大家可以自己看下。