2011/08/04

Install snort 2.9.0.5 on CentOS 5.5

今天裝Snort 2.9.0.5到CentOS 5.5上,遭遇很多問題。
所以寫這篇紀錄如何安裝。這篇完全用tarball方式安裝,RPM部份請參考(http://forum.icst.org.tw/phpbb/viewtopic.php?f=11&t=20365)。
這邊是安裝好CentOS 5.5並且將全部套件更新到最新版後的安裝方式。

1.事前準備
  1.1 從snort官網下載snort-2.9.0.5.tar.gz, dag-0.5.tar.gz。
  1.2 下載snort的rule,免費的即可,前提是你要先註冊一個帳號。將來有想要升級的話也可以升級上去。
        snortrules-snapshot-2904.tar.gz, snortrules-snapshot-2905.tar.gz
  1.3 到http://www.tcpdump.org 下載libpcap-1.1.1.tar.gz。
  1.4 到http://libdnet.sourceforge.net 下載libdnet-1.11.tar.gz。
  1.5 將snort,dag,libdnet及libpcap解開(請自行到鳥哥那瞭解如何解壓縮),到各自目錄夾。
        通常解開的目錄就是檔案去掉tar.gz的部份。
        例:snort-2.9.0.5.tar.gz解開後目錄名稱為snort-2.9.0.5。
2.開始安裝
  2.1 用瀏覽器打開 Install_Snort_2.8.6_on_CentOS_5.5.pdf
       請依照裡面的 Snort Installation and Setup章節安裝。裡面會要你用yum安裝很多套件。
       安裝完後會到 Making directories and building/installing Snort: 章節。
       接下來的請依順序安裝,不然會有錯誤訊息。
  2.2 安裝libdnet
cd libdnet-1.11
./configure --prefix=/usr
make
make install

  2.3 安裝libpcap
cd libpcap-1.1.1
./configure --prefix=/usr
make
make install

  2.4 安裝dag
cd dag-0.5
./configure --prefix=/usr
make
make install

  2.5 安裝snort
cd snort-2.9.0.5
./configure --with-mysql --enable-dynamicplugin --enable-ipv6 --enable-gre --enable-mpls --enable-targetbased --enable-decoder-preprocessor-rules --enable-ppm --enable-perfprofiling --enable-zlib --enable-active-response --enable-normalizer --enable-reload --enable-react --enable-flexresp3
make
make install

  2.6 接著就接續Making directories and building/installing Snort:後面章節的部份繼續安裝下去。

3. PHP Pear部份
   3.1 安裝php pear

yum -y install php-pear
pear upgrade --force http://download.pear.php.net/package/PEAR-1.9.1.tgz
pear install Numbers_Roman
pear install channel://pear.php.net/Numbers_Words-0.16.2
pear install Image_Color
pear install channel://pear.php.net/Image_Canvas-0.3.2
pear install channel://pear.php.net/Image_Graph-0.7.2


4. adodb
wget http://sourceforge.net/projects/adodb/files/adodb-php5-only/adodb-511-for-php5/adodb511.tgz/download


5. secureideas
wget http://sourceforge.net/projects/secureideas/files/BASE/base-1.4.5/base-1.4.5.tar.gz/download


6. Barnyard2
安裝裡面的網站已經不存在了,現在換到這個https://nodeload.github.com/firnsy/barnyard2/tarball/master。
  6.1 請參閱doc裡面的INSTALL文件
        如果發生 AM_PATH_LIBPRELUDE 錯誤的話,依下面方式處理。

cp snort-2.9.0.5/m4/libprelude.m4 /usr/share/aclocal

snort-2.9.0.5可以改成你實際解開的目錄。
  6.2 之後就./configure --with-mysql --prefix=/usr沒問題的話就可以安裝了

7. 修改snort.conf
     把ipvar部份全部改成var。

全部做完後就可以開始使用Snort了。

2011/06/07

VS2005,VS2008,VS2010 出現automation伺服程式無法產生物件 解決方式

解決方式:
請執行 Regsvr32 scrrun.dll

2011/03/23

用 RadioButtonList 當 UpdatePanel Trigger 時無法正常觸發非同步更新之解法

ASP.NET的RadioButtonList,預設不會作PostBack,但是如果用上AutoPostBack又會跟Page_Load中的IsPostBack有相衝的地方。
所以可以採用下列的方式,就可以讓RadioButtonList作PostBack了。


用 RadioButtonList 當 UpdatePanel Trigger 時無法正常觸發非同步更新之解法
原始問題出處。這問題印象中我好像也碰過幾次,但一直沒有去深究原因,因為要解決並不困難 (容後說明),但今天再度看到有人提問,索性好好了解一下始末。

首先依照原發問者提供的頁面配置及程式碼重現案發現場:

aspx部份

<form id="form1" runat="server">

<div>

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">

</ajaxToolkit:ToolkitScriptManager>

<asp:RadioButtonList ID="rblType" runat="server" OnSelectedIndexChanged="rblType_SelectedIndexChanged"

RepeatDirection="Horizontal" AutoPostBack="true">

<asp:ListItem Value="I" Selected="True">新增新案</asp:ListItem>

<asp:ListItem Value="U">修改新案</asp:ListItem>

<asp:ListItem Value="O">舊案續約</asp:ListItem>

</asp:RadioButtonList>

<asp:UpdatePanel ID="upl" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">

<ContentTemplate>

<asp:Panel ID="pnl" runat="server" Visible="false">

<asp:DropDownList ID="ddlAmtYear" runat="server" Width="320" Height="23" />

</asp:Panel>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTrigger ControlID="rblType" EventName="SelectedIndexChanged" />

</Triggers>

</asp:UpdatePanel>

</div>

</form>


CS部份

protected void rblType_SelectedIndexChanged(object sender, EventArgs e)

{

if (rblType.SelectedValue == "I")

pnl.Visible = false;

else

pnl.Visible = true;

}



程式很單純,判斷 RadioButtonList 的選取值以非同步更新的方式切換 Panel 隱藏 / 顯示,但執行起來果真如發問者所說,RadioButtonList.SelectedIndexChanged 初次引發時,會觸發 UpdatePanel 更新,但接下來再點回去預設選項則不會觸發非同步更新…。

身為一個網頁開發人員,遇到網頁執行結果不如預期時,把網頁開起來檢視原始碼是常用的除錯技巧,不一會兒工夫,看到一個不尋常的地方:

radiobuttonlist_html


如上圖所示,RadioButtonList 預設選取的選項,在 Render 成 HTML 後少了 "onclick=javascript:setTimeout('__doPostBack(\'rblType$0\',\'\')" 這一段,這是設定 RadioButtonList.AutoPostBack 屬性為 true 時,會自動幫每一個選項加上去的,目的是在點選任一選項之後送回 Server 端處理,要命的是預設選取的那一個選項不會加...。

知道原因之後,可以來想怎麼解決了。開頭說過我曾遇過同樣的問題,沒有深究的原因是這問題沒有耽擱到太多時間,所以一直不以為意,其實只要把 RadioButtonList 放到 UpdatePanel 裡面就不會有這樣的問題了,這是比較建議的做法。但真的不想把 RadioButtonList 丟到 UpdatePanel 裡的話也是有解,但要動點手腳,既然預設選取的選項會少指令碼,那我們就手動補上去,比較恰當的時機點是在 RadioButtonList.PreRender 事件處理:

protected void rblType_PreRender(object sender, EventArgs e)

{

RadioButtonList radioButtonList = ((RadioButtonList)sender);



foreach (ListItem li in radioButtonList.Items)

{

// 預設選取的選項加上 onclick 事件指令碼

if (li.Selected)

{

li.Attributes.Add("onclick",

String.Format("javascript:setTimeout('__doPostBack(\\'{0}${1}\\',\\'\\')', 0)",

radioButtonList.UniqueID,

radioButtonList.Items.IndexOf(li)));

}

}

}

在開始上傳前檢查檔案大小(IE僅能檢查圖片)

這篇其實不是單純只能檢查圖片而已,連一般檔案都可以檢查。目前還沒在Safari瀏覽器上實驗過就是了。
2011/3/24 04:18 剛確認了IE如果是圖片以外的檔案,確實要用額外的方式處理。

[JavaScript] 在開始上傳前檢查圖片檔案大小
最近有此功能需求,因此查了些相關的資料,最後在不使用 Flash 及 ActiveX 等技術的情況下,只用JavaScript完成了多瀏覽器的功能實作,在此分享。

目前已測試過的瀏覽器:IE 6 , IE 7 , IE 8 , Firefox , Chrome;另外 Firefox 與 Chrome 的版本須為支援 Html 5 的版本。


以下為 HTML (此部分與 Bryan(不來ㄣ)大大的版本相同 ):
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title>上傳</title>
</head>
<body>
    <form action="upload.asp" method="POST" name="FileForm" enctype="multipart/form-data">
    <div align="center">
        圖片:
    <input type="file" name="file1" size="20" id="file1" />
    <input type="button" value="確定上傳" onclick="checkFile()" /></div>
    </form>
</body>
</html>


以下為 JavaScript:
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
    var fileSize = 0; //檔案大小
    var SizeLimit = 1024; //上傳上限,單位:byte
    function checkFile() {
    var f = document.getElementById("file1");
    //FOR IE
    if ($.browser.msie) {
            var img = new Image();
            img.onload = checkSize;
            img.src = f.value;
        }
        //FOR Firefox,Chrome
        else {
            fileSize = f.files.item(0).size;
            checkSize();
        }
    }
    //檢查檔案大小
    function checkSize() {
        //FOR IE FIX
        if ($.browser.msie) {
            fileSize = this.fileSize;
        }
        if (fileSize > SizeLimit) {
            Message((fileSize / 1024).toPrecision(4), (SizeLimit / 1024).toPrecision(2));
        } else {
            document.FileForm.submit();
        }
    }
    function Message(file, limit) {
        var msg = "您所選擇的檔案大小為 " + file + " kB\n已超過上傳上限 " + limit + " kB\n不允許上傳!"
        alert(msg);
    }
</script>

參考資料:
topcat 姍舞之間的極度凝聚 - [轉貼]上傳檔案前,JavaScript檢查檔案格式、大小:http://www.dotblogs.com.tw/topcat/archive/2009/02/20/7250.aspx (Bryan(不來ㄣ)大大的版本 – For IE)
簡單過生活 - Check 上傳檔案大小:http://iammic.pixnet.net/blog/post/11866034 (iammic大大的版本 – For IE[ActiveX] & Firefox , Chrome)

2010/09/22 更新:
在 o 大大的指正後,將標題略為修改為針對圖片檔案的上傳之檔案大小的檢查,以避免因標題誤導了想找資料的訪客。
另外,在支援 HTML 5 的 Firefox 與 Chrome 的瀏覽器版本上,是可正確抓到各類型檔案大小的;而 IE 瀏覽器仍須透過 Flash 或 ActiveX 等技術才能取得圖片類型以外的檔案大小,在此作以上更正。

2011/02/22

Nagios Plugin Check_SNMP

OS: CentOS 5.5
Nagios: nagios-3.2.3-3.el5.rf.i386
這篇是關於Nagios Plugin Check_SNMP中關於--rate指令的使用方式。
如果你是用YUM或是apt等方式安裝的Nagios,可能在使用check_snmp的--rate選項的時候會發生錯誤。
原因是因為check_snmp在儲存rate的狀態的時候,會除存在/var/check_snmp裡面,而extinfo.cgi確無法在開啟檔案,原因是目錄建立的時候,使用者及群組不是nagios(或你自訂的群組),權限也只有700。
所以將使用者及群組改成nagios(或你自訂的群組),權限也修改成755(或你覺得安全權限)。
裡面如果原本就有檔案的話,也請將使用者及群組改成nagios(或你自訂的群組),權限640即可。想省事一點可以把檔案全砍了,反正重新建立也不會有啥影響。之後重新啟動nagios就會正常。

2011/02/16

CentOS Yum Repo

CentOS預設安裝的Yum有蠻多東西都沒有的。
所以下面是幾個目前常用的repo及安裝方式。

1.remi

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

2.rpmforge

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

3.IUS

wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-8.ius.el5.noarch.rpm
rpm -Uvh ius-release*.rpm


PS:請注意上面是i386版本,若是64bit版的,必須把i386的字串改為x86_64。
PS2:RHEL已經有6版了,但不建議在系統不是6版的狀況下裝6版的repo。
2012/07/02 redhar的域名修正

2011/02/15

Wireshark的cli版 tshark

TShark 1.0.15
Dump and analyze network traffic.
See http://www.wireshark.org for more information.

Copyright 1998-2010 Gerald Combs and contributors.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Usage: tshark [options] ...

Capture interface:
-i name or idx of interface (def: first non-loopback)
-f packet filter in libpcap filter syntax
-s packet snapshot length (def: 65535)
-p don't capture in promiscuous mode
-y link layer type (def: first appropriate)
-D print list of interfaces and exit
-L print list of link-layer types of iface and exit

Capture stop conditions:
-c stop after n packets (def: infinite)
-a ... duration:NUM - stop after NUM seconds
在幾秒後停止
filesize:NUM - stop this file after NUM KB
在檔案大小為幾KB後停止
files:NUM - stop after NUM files
在幾個檔案後停止
Capture output:
-b ... duration:NUM - switch to next file after NUM secs
在幾秒後換新檔案
filesize:NUM - switch to next file after NUM KB
在檔案大小為幾KB後換新檔案
files:NUM - ringbuffer: replace after NUM files
在幾次後後換覆蓋檔案(類似logrotate的功能)
Input file:
-r set the filename to read from (no pipes or stdin!)

Processing:
-R packet filter in Wireshark display filter syntax
-n disable all name resolutions (def: all enabled)
-N enable specific name resolution(s): "mntC"
-d ==, ...
"Decode As", see the man page for details
Example: tcp.port==8888,http
Output:
-w set the output filename (or '-' for stdout)
將抓到的資料存放到 (或輸入 '-' 來輸出到stdout也就是顯示在螢幕上)
-C start with specified configuration profile
-F set the output file type, default is libpcap
an empty "-F" option will list the file types
-V add output of packet tree (Packet Details)
-S display packets even when writing to a file
-x add output of hex and ASCII dump (Packet Bytes)
-T pdml|ps|psml|text|fields
format of text output (def: text)
-e field to print if -Tfields selected (e.g. tcp.port);
this option can be repeated to print multiple fields
-E= set options for output when -Tfields selected:
header=y|n switch headers on and off
separator=/t|/s| select tab, space, printable character as separator
quote=d|s|n select double, single, no quotes for values
-t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first)
-l flush standard output after each packet
-q be more quiet on stdout (e.g. when using statistics)
-X : eXtension options, see the man page for details
-z various statistics, see the man page for details

Miscellaneous:
-h display this help and exit
-v display version info and exit
-o : ... override preference setting

2010/11/17

[PHP]解決網站被 SQL injection 攻擊

其實這個安全性的問題,在目前台灣網站都存在這樣的問題,大家平常用 $_POST,$_GET 用得很順利,但是沒有想過帳號密碼被 SQL injection 破解,當網站被破解了,基本上你損失就是相當嚴重,網路上也有很多攻擊方式,不過這方法是最常被拿出來講的,我自己有一套解決方式,除了比較重要的地方,就是輸入帳號密碼的地方要加強防護之外,加上數字驗證碼,還要 check 帳號的特性,我底下是我驗證帳號密碼機制

if($user_name == '' || $user_passwd == ''){
ErrMsg("帳號或密碼不得空白");
}
if (!preg_match('/^\w+$/', $user_name)){
ErrMsg("請勿攻擊本站台");
}


上面可以解決帳號只能輸入數字加上英文,然後底下在過濾很多特殊字元加上 addslashes 或者是用 mysql_escape_string()

if( !get_magic_quotes_gpc() )
{
if( is_array($_GET) )
{
while( list($k, $v) = each($_GET) )
{
if( is_array($_GET[$k]) )
{
while( list($k2, $v2) = each($_GET[$k]) )
{
$_GET[$k][$k2] = addslashes($v2);
}
@reset($_GET[$k]);
}
else
{
$_GET[$k] = addslashes($v);
}
}
@reset($_GET);
}

if( is_array($_POST) )
{
while( list($k, $v) = each($_POST) )
{
if( is_array($_POST[$k]) )
{
while( list($k2, $v2) = each($_POST[$k]) )
{
$_POST[$k][$k2] = addslashes($v2);
}
@reset($_POST[$k]);
}
else
{
$_POST[$k] = addslashes($v);
}
}
@reset($_POST);
}

if( is_array($_COOKIE) )
{
while( list($k, $v) = each($_COOKIE) )
{
if( is_array($_COOKIE[$k]) )
{
while( list($k2, $v2) = each($_COOKIE[$k]) )
{
$_COOKIE[$k][$k2] = addslashes($v2);
}
@reset($_COOKIE[$k]);
}
else
{
$_COOKIE[$k] = addslashes($v);
}
}
@reset($_COOKIE);
}
}

上面那段,可以避免利用特殊字元做 SQL injection 攻擊,這部份程式碼是我去 trace PHPBB2 code 裡面寫的^^。

文章來源:[PHP]解決網站被 SQL injection 攻擊

2010/11/14

Payeasy的ssl憑證過期

剛無聊去逛payeasy的網站,意外發現他的ssl憑證過期了,雖說剛過期沒不到兩週,不過很明顯的應該是嚴重的管理疏失。
這幾天要是有人因此有所損失的話,該怎麼處理呢?
寄件者 Blogger 圖片

2010/11/12

如何Windows2003中建立智能DNS服务器

如何Windows2003中建立智能DNS服务器(BIND,附配置文件下载) - [Windows]


版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明

http://iamsam.blogbus.com/logs/29402246.html




前言

 随着原中国电信集团按南北地域分家,新的中国电信和网通集团随即成立,互联网的骨干网也被一分为二了,北有网通、南有电信。从此,细心的网民可以发现,有些经常访问的网站速度一下子慢了下来,有时候还有访问不到的情况出现。例如北方地区的网络用户访问中国网通的服务器会非常快,而访问中国电信的服务器时,感觉非常慢。这种现象不仅影响了网站的访问量,更严重的是它直接影响了一些经营性网站的经济效益。据分析,产生这个问题的根本原因是中国电信分家之后,电信与网通之间的互连存在问题。虽然信息产业部已经在规划南北互通计划,但在今后相当长的一段时期内,南北方网互连的问题还会长期存在。

解决方案

智能DNS策略解析很好的解决了上面所述的问题。DNS策略解析最基本的功能是可以智能的判断访问您网站的用户,然后根据不同的访问者把您的域名分别解析成不同的IP地址。如访问者是网通用户,DNS策略解析服务器会把你的域名对应的网通IP地址解析给这个访问者。如果用户是电信用户,DNS策略解析服务器会把您域名对应的电信IP地址解析给这个访问者。

 智能DNS策略解析还可以给你的多个主机实现负载均衡,这时来自各地的访问流量会比较平均的分布到你的每一个主机上。

软件的相关资源

官方网站: http://www.bind.com/



最新版本: 9.3.2 http://www.isc.org/index.pl?/sw/bind/view/?release=9.3.2-P2



帮助文档: http://www.isc.org/sw/bind/



配置文件样例: http://www.bind.com/bind.html





实施步骤:

1。 WINDOWS 2003 服务器

2。使用BIND9做智能DNS,自动根据客户端IP来判断,网通的用户解析出网通的IP,电信的解析出电信IP

测试做的域名

www.dnsany.com

电信IP 60.171.45.152

网通IP 220.248.236.152

电信用户PING www.dnsany.com会解析到60.171.45.152

网通用户PING www.dnsany.com会解析到220.248.236.152

配置步骤:

1.BIND 9.3.2

http://ftp.isc.org/isc/bind9/9.3.2-P2/BIND9.3.2-P2.zip

2. 安装BIND 9 .3.2

解压到一个临时目录,而后运行 BINDInstall.exe,一直默认安装就行了,不需要更改什么设置。

默认安装到 \windows\system32\dns目录下

3.配置

运行CMD进入安装目录(\windows\system32\dns)下面的bin目录,而后运行

rndc-confgen -a (运行完成后会在etc目录下生成rndc.key)

rndc-confgen > ..\etc\rndc.conf

进入etc目录,用 notepad 新建 named.conf 复制下面的内容,注意把rndc.conf中# Use with the following in named.conf, adjusting the allow list as needed: 以后的内容复制到named.conf文件中,去掉全面的#。

named.conf

######################named.conf############################



acl "trust-lan" { 127.0.0.1/8; 10.0.0.0/24;};

options {

directory "C:\WINDOWS\system32\dns\etc";

recursion no;

version "0.0.0";

allow-transfer { "trust-lan";};

allow-notify { "trust-lan"; };

auth-nxdomain no;

forwarders { 60.171.45.171;60.171.45.150;};



};



#这一段内容拷贝来自rndc.conf

key "rndc-key" {

algorithm hmac-md5;

secret "p30d5VTh6iP+QBiVsEI0lw==";

};



controls {

inet 127.0.0.1 port 953

allow { 127.0.0.1; } keys { "rndc-key"; };

};

#注意在C:\WINDOWS\system32\dns\log\ 下建dns_warnings.txt dns_logs.txt

logging {

channel warning

{ file "C:\WINDOWS\system32\dns\log\dns_warnings.txt" versions 3 size 1240k;

severity warning;

print-category yes;

print-severity yes;

print-time yes;

};

channel general_dns

{ file "C:\WINDOWS\system32\dns\log\dns_logs.txt" versions 3 size 1240k;

severity info;

print-category yes;

print-severity yes;

print-time yes;

};

category default { warning; };

category queries { general_dns; };

};

#将网通的地址范围数据

include "cnc.conf";

# 判断如果是网通的地址范围,则会执行此处,调用网通的解析

view "view_cnc" {

match-clients { CNC; };

zone "." {

type hint;

file "named.root";

};



zone "0.0.127.IN-ADDR.ARPA" {

type master;

file "localhost.rev";

};



include "master/cnc.def";

};



view "view_any" {

match-clients { any; };

zone "." {

type hint;

file "named.root";

};



zone "0.0.127.IN-ADDR.ARPA" {

type master;

file "localhost.rev";

};



include "master/telecom.def";

};



###################### named.conf############################

用notepad 新建 cnc.conf复制下面的内容



###################### cnc.conf############################

# jul/14/2006 09:44:25 by coolice

# software id = EFTB-IZN

#

acl "CNC" {

58.16.0.0/16;

58.17.0.0/17;

60.12.0.0/16;

222.163.128.0/17;

219.235.56.194;

};

###################### cnc.conf############################

用notepad 新建 named.root复制下面的内容



###################### named.root############################

; This file holds the information on root name servers needed to

; initialize cache of Internet domain name servers

; (e.g. reference this file in the "cache . "

; configuration file of BIND domain name servers).

;

; This file is made available by InterNIC

; under anonymous FTP as

; file /domain/named.root

; on server FTP.INTERNIC.NET

; -OR- RS.INTERNIC.NET

;

; last update: Jan 29, 2004

; related version of root zone: 2004012900

;

;

; formerly NS.INTERNIC.NET

;

. 3600000 IN NS A.ROOT-SERVERS.NET.

A.ROOT-SERVERS.NET. 3600000 A 198.41.0.4

;

; formerly NS1.ISI.EDU

;

. 3600000 NS B.ROOT-SERVERS.NET.

B.ROOT-SERVERS.NET. 3600000 A 192.228.79.201

;

; formerly C.PSI.NET

;

. 3600000 NS C.ROOT-SERVERS.NET.

C.ROOT-SERVERS.NET. 3600000 A 192.33.4.12

;

; formerly TERP.UMD.EDU

;

. 3600000 NS D.ROOT-SERVERS.NET.

D.ROOT-SERVERS.NET. 3600000 A 128.8.10.90

;

; formerly NS.NASA.GOV

;

. 3600000 NS E.ROOT-SERVERS.NET.

E.ROOT-SERVERS.NET. 3600000 A 192.203.230.10

;

; formerly NS.ISC.ORG

;

. 3600000 NS F.ROOT-SERVERS.NET.

F.ROOT-SERVERS.NET. 3600000 A 192.5.5.241

;

; formerly NS.NIC.DDN.MIL

;

. 3600000 NS G.ROOT-SERVERS.NET.

G.ROOT-SERVERS.NET. 3600000 A 192.112.3***

;

; formerly AOS.ARL.ARMY.MIL

;

. 3600000 NS H.ROOT-SERVERS.NET.

H.ROOT-SERVERS.NET. 3600000 A 128.63.2.53

;

; formerly NIC.NORDU.NET

;

. 3600000 NS I.ROOT-SERVERS.NET.

I.ROOT-SERVERS.NET. 3600000 A 192.36.148.17

;

; operated by VeriSign, Inc.

;

. 3600000 NS J.ROOT-SERVERS.NET.

J.ROOT-SERVERS.NET. 3600000 A 192.58.128.30

;

; operated by RIPE NCC

;

. 3600000 NS K.ROOT-SERVERS.NET.

K.ROOT-SERVERS.NET. 3600000 A 193.0.14.129

;

; operated by ICANN

;

. 3600000 NS L.ROOT-SERVERS.NET.

L.ROOT-SERVERS.NET. 3600000 A 198.32.64.12

;

; operated by WIDE

;

. 3600000 NS M.ROOT-SERVERS.NET.

M.ROOT-SERVERS.NET. 3600000 A 202.12.27.33

; End of File



###################### named.root############################

新建master文件夹 并在里面新建cnc 和 telecom 文件夹

进入masrer文件夹 用notepad 新建cnc.def 和telecom.def

###################### cnc.def############################

zone "dnsany.com" {

type master;

file "C:\WINDOWS\system32\dns\etc\master\cnc\dnsany.com.txt";

};

###################### cnc.def############################

###################### telecom.def############################

zone "dnsany.com" {

type master;

file "C:\WINDOWS\system32\dns\etc\master\telecom\dnsany.com.txt";

};

###################### telecom.def############################

分别进入cnc和telecom文件夹建立dnsany.com.txt文件

#########################cnc\dnsany.com.txt##############################

$TTL 3600

$ORIGIN dnsany.com.

@ IN SOA ns.joysp.com. root. joysp.com.(

2006111520 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

;

@ IN NS ns.joysp.com.

@ IN A 220.248.236.152

www IN A 220.248.236.152

* IN A 220.248.236.152

;

;end

#########################cnc\dnsany.com.txt##############################

#########################telecom\dnsany.com.txt##############################

$TTL 3600

$ORIGIN dnsany.com.

@ IN SOA ns.joysp.com. root. joysp.com.(

2006111520 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

;

@ IN NS ns.joysp.com.

@ IN A 60.171.45.152

www IN A 60.171.45.152

* IN A 60.171.45.152

;

;end

#########################telecom\dnsany.com.txt##############################

全部配置完成后,可以进入Windows 服务管理器,找到那个叫 ISC Bind的服务,而后属性更改登陆为本地系统用户选择启动,如果出现错误,请打开你的事件查看器,到应用程序部分看看什么错误。如果没有问题,则已经运行起来了。

3.测试

运行CMD,而后输入: nslookup

C:\>nslookup

Default Server: ns.ahhfptt.net.cn

Address: 202.102.192.68



> server 60.171.45.152

Default Server: [60.171.45.152]

Address: 60.171.45.152



> set type=any

> dnsany.com

Server: [60.171.45.152]

Address: 60.171.45.152



dnsany.com

primary name server = ns.joysp.com

responsible mail addr = root.592365.com

serial = 2005121213

refresh = 3600 (1 hour)

retry = 900 (15 mins)

expire = 68400 (19 hours)

default TTL = 15 (15 secs)

dnsany.com nameserver = ns.joysp.com

dnsany.com internet address = 60.171.45.152



说明DNS服务器解析正常!



说明下dnsany.com.txt

#########################cnc\dnsany.com.txt##############################

$TTL 3600

$ORIGIN dnsany.com.

@ IN SOA ns.joysp.com. root. joysp.com.(

2006111520 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

;

@ IN NS ns.joysp.com.

@ IN MX 0 mail.

@ IN A 220.248.236.152

www IN A 220.248.236.152

webserver IN CNAME www

mail IN A 220.248.236.152

* IN A 220.248.236.152

;

;end

#########################cnc\dnsany.com.txt##############################

第一行是TTL设定,生存时间记录字段。它以秒为单位定义该资源记录中的信息存放在高速缓存中的时间长度。这里定义为604800秒,也就是1周.

第二行是$ORIGIN设定,说明下面的记录出自何处.请您加倍留意最后的一个小小数点"."

然后,第三行,是一个 SOA 记录的设定,在这里我们看到一个特殊字符 @ ,它就是 ORIGIN 的意思,也就是刚刚所定义的$ ORIGIN dnsany.com. 的内容,您可以写成 dnsany.com. 也可以用 @ 来代替。

假如这个文件前面没有定义 $ ORIGIN 的话, 那這个 @ 的值就以 named.conf 里的 zone .

接着 SOA 后面,指定了这个区域的授权主机和管理者的信箱,这里分别是"joysp.com." 和"root.joysp.com."。我们平时使用的信箱通常是“user@host”这样的格式,但因为@在 DNS 记录中是个保留字符,所以在 SOA 中就用“.”来代替了@。目前这个信箱是 "root@joysp.com."。

接下来的 SOA 设置,是被括在“( )”之间的 5 组数字,主要作为和 slave 服务器同步 DNS 资料所使用的资料:

Serial:其格式通常会是“年月日+修改次序”(但也不一定如此,您自己能够记得就行)。当 slave 要进行资料同步的时候,会比较这个号码。如果发现在这里的号码比它那边的数值“大”,就进行更新,否则忽略。不过设 serial 有一个地方您要留意:不能超过 10 位数字!

Refresh:这里是是告诉 slave 要隔多久要进行资料同步(是否同步要看 Serial 的比较结果)。

Retry:如果 slave 在进行更新失败后,要隔多久再进行重试。

Expire:这是记录逾期时间:当 slave 一直未能成功与 master 取得联系,那到这里就放弃 retry,同时这里的资料也将标识为过期(

expired )。

Minimum:这是最小默认 TTL 值,如果您在前面没有用“$TTL”来定义,就会以此值为准。

请注意:SOA 记录中这对 “ ( ) ”符号之第一个 “ (”括号一定要和 SOA 写在同一行,而不能用 Enter 断行到下一行去,而且其左边最好有一个空格键或 tab 建。而最后一个 “ )”括号也不能写在注解符号 “ ;”的右边。 置 DNS 的 RR 记录档,其格式要求非常严格,我们丝毫不能掉以轻心。比方说:如果句子不是以空格键、Tab 键、 或注解符号 ( ; )开头,也不在 SOA 的 “ ( ) ”之内,则表示要定义一个“新记录项 (Entry) ”;如果句子是以空格键或 tab 键开始的话,其设置被视为上一个“记录项”的内容。所以,如果您要为“同一个记录项”定义多个记录设置,而不想重复打字,您倒可以偷懒:在接着它的后面几行用空白或 Tab 来缩排就可以了。

NS表明负责dnsany.com.这个域的Name Server是ns.joysp.com这台主机

MX记录标明发往mail域的邮件由mail.dnsany.com这台服务器接收

A记录标明了IP地址和域名之间的对应关系











后记

DNS智能策略解析还可以给你的多个主机实现负载均衡,这时来自各地的访问流量会比较平均的分布到你的每一个主机上。

只需要在相应的CNC TELECOM文件中加@ www记录

#########################cnc\dnsany.com.txt##############################

$TTL 3600

$ORIGIN dnsany.com.

@ IN SOA ns.joysp.com. root. joysp.com.(

2006111520 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

;

@ IN NS ns.joysp.com.

@ IN A 220.248.236.152

@ IN A 220.248.236.153

@ IN A 220.248.236.154

@ IN A 220.248.236.155

www IN A 220.248.236.152

www IN A 220.248.236.153

www IN A 220.248.236.154

www IN A 220.248.236.155

* IN A 220.248.236.152

;

;end

#########################cnc\dnsany.com.txt##############################

#########################telecom\dnsany.com.txt##############################

$TTL 3600

$ORIGIN dnsany.com.

@ IN SOA ns.joysp.com. root. joysp.com.(

2006111520 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

;

@ IN NS ns.joysp.com.

@ IN A 60.171.45.152

@ IN A 60.171.45.153

@ IN A 60.171.45.154

@ IN A 60.171.45.155

www IN A 60.171.45.152

www IN A 60.171.45.153

www IN A 60.171.45.154

www IN A 60.171.45.155

* IN A 60.171.45.152

;

;end

#########################telecom\dnsany.com.txt##############################







C:\Documents and Settings\coolice>cd \



C:\>nslookup

Default Server: ns.ahhfptt.net.cn

Address: 202.102.192.68

>server ns.joysp.com

> set q=a

> dnsany.com

Server: ns.joysp.com

Address: 60.171.45.152



Non-authoritative answer:

Name: dnsany.com

Addresses: 60.171.45.152, 60.171.45.153, 60.171.45.154, 60.171.45.155



配置文件下载: http://iamsam.blogbus.com/files/12218213130.zip


官方配置文件示例:

http://www.bind.com/?path=dns

用Bind9架设自己的智能DNS

用Bind9架设自己的智能DNS

by ProdigYu on Oct.20, 2010, under CDN

中国的南北网络问题,是许多做网站的人的心病
除了使用双通或者多通机房以外,还可以通过多台镜像服务器的方法来提高用户的访问速度
但是,如果使用的双通机房并不是单IP的,或者使用多台镜像的做法,就会面临多个不同的服务器IP的问题
最早的时候,很多镜像服务器都是使用不同的域名的,比如说www1和www2,或者www和cnc
这样的做法,对用户相当不友好,而且不方便推广,比如说,你要告诉朋友一个网站,还要问他是什么线路才能给网址吗,或者可能你还不知道这个网站有一个专为网通的线路所设置的镜像
用统一的域名,然后根据用户的线路自动判断引导到不同的镜像服务器,正是智能DNS的功用(智能DNS其实是CDN的其中一部分,是最前端的部分)

现在还是有一些地方使用多域名,比如说下载网站的下载镜像服务器,因为智能DNS有一定的缺陷(并不一定选择到正确的线路,下面说),也提供给用户自由选择线路的权利

目前也有一些公司提供智能DNS解释服务,把你的域名NS指到他们服务器,然后输入网通和电信服务器的IP就ok了
也有一些公司提供比较完整的CDN服务,比如比较出名的就是chinacache,不少中型网站是使用他们的服务

最初的bind是不支持通过来源选择不同的ip的,因此只能通过iptables的辅助来实现智能DNS,方法也很简单,在DNS服务器上面启动两份bind,都不要用默认的端口,两份分别解析不同的线路,然后再用iptables将默认端口的DNS请求根据来源IP发送到不同的bind实例
这种方法缺点很明显,需要多个bind实例,如果需要更多的线路解释那就还要再开bind实例,另外iptables对来源的解释也会导致iptables太多规则

现在的bind支持了根据来源选择的功能,我不确定是不是bind9的新特性,不过bind9是重写过的,相比漏洞百出的bind8来说,稳定和安全很多,以下的配置以bind9为基础

我使用的是CentOS,由于bind服务没有其他服务(比如apache,squid)要求那么高,所以也没有必要自己编译一份,我是用过yum安装的,版本不是最新的稳定版

装好之后,可以用过/etc/init.d/named start成功启动服务
有一个文件named.conf出现在/etc下,就是bind的主config文件,我们只要改动他
(我只说明智能DNS实现部分,其他的bind设置自行修改,呵呵)
另外一个小技巧,可以通过/usr/sbin/named -g -u named来启动bind,可以立刻看到输出信息,方便调试

我们是通过bind9的view功能来分离判断的
首先,我们需要一份网通的IP列表,这是一份在网上流传的列表,呵呵

acl “CNC” {
58.16.0.0/16;
58.17.0.0/17;
58.17.128.0/17;
58.18.0.0/16;
58.19.0.0/16;
58.20.0.0/16;
58.21.0.0/16;
58.22.0.0/15;
58.240.0.0/15;
58.242.0.0/15;
58.244.0.0/15;
58.246.0.0/15;
58.248.0.0/13;
60.0.0.0/13;
60.8.0.0/15;
60.10.0.0/16;
60.11.0.0/16;
60.12.0.0/16;
60.13.0.0/18;
60.13.128.0/17;
60.14.0.0/15;
60.16.0.0/13;
60.24.0.0/14;
60.30.0.0/16;
60.31.0.0/16;
60.208.0.0/13;
60.216.0.0/15;
60.218.0.0/15;
60.220.0.0/14;
61.48.0.0/13;
61.133.0.0/17;
61.134.96.0/19;
61.134.128.0/17;
61.135.0.0/16;
61.137.128.0/17;
61.138.0.0/17;
61.138.128.0/18;
61.139.128.0/18;
61.148.0.0/15;
61.156.0.0/16;
61.159.0.0/18;
61.161.0.0/18;
61.161.128.0/17;
61.162.0.0/16;
61.163.0.0/16;
61.167.0.0/16;
61.168.0.0/16;
61.176.0.0/16;
61.179.0.0/16;
61.181.0.0/16;
61.182.0.0/16;
61.189.0.0/17;
125.32.0.0/16;
125.40.0.0/13;
202.96.0.0/18;
202.96.64.0/21;
202.96.72.0/21;
202.97.128.0/18;
202.97.224.0/21;
202.97.240.0/20;
202.98.0.0/21;
202.98.8.0/21;
202.99.64.0/19;
202.99.96.0/21;
202.99.128.0/19;
202.99.160.0/21;
202.99.168.0/21;
202.99.176.0/20;
202.99.208.0/20;
202.99.224.0/21;
202.99.232.0/21;
202.99.240.0/20;
202.102.128.0/21;
202.102.224.0/21;
202.102.232.0/21;
202.106.0.0/16;
202.107.0.0/17;
202.108.0.0/16;
202.110.0.0/17;
202.111.128.0/18;
203.93.8.0/24;
203.93.192.0/18;
210.13.128.0/17;
210.14.160.0/19;
210.14.192.0/19;
210.15.32.0/19;
210.15.96.0/19;
210.15.128.0/18;
210.21.0.0/16;
210.52.128.0/17;
210.53.0.0/17;
210.53.128.0/17;
210.74.96.0/19;
210.74.128.0/19;
210.82.0.0/15;
218.8.0.0/14;
218.12.0.0/16;
218.21.128.0/17;
218.24.0.0/14;
218.56.0.0/14;
218.60.0.0/15;
218.67.128.0/17;
218.68.0.0/15;
218.104.0.0/14;
219.154.0.0/15;
219.156.0.0/15;
219.158.0.0/17;
219.158.128.0/17;
219.159.0.0/18;
220.252.0.0/16;
221.0.0.0/15;
221.2.0.0/16;
221.3.0.0/17;
221.3.128.0/17;
221.4.0.0/16;
221.5.0.0/17;
221.5.128.0/17;
221.6.0.0/16;
221.7.0.0/19;
221.7.32.0/19;
221.7.64.0/19;
221.7.96.0/19;
221.8.0.0/15;
221.10.0.0/16;
221.11.0.0/17;
221.11.128.0/18;
221.11.192.0/19;
221.12.0.0/17;
221.12.128.0/18;
221.13.0.0/18;
221.13.64.0/19;
221.13.96.0/19;
221.13.128.0/17;
221.14.0.0/15;
221.192.0.0/15;
221.194.0.0/16;
221.195.0.0/16;
221.196.0.0/15;
221.198.0.0/16;
221.199.0.0/19;
221.199.32.0/20;
221.199.128.0/18;
221.199.192.0/20;
221.200.0.0/14;
221.204.0.0/15;
221.206.0.0/16;
221.207.0.0/18;
221.207.64.0/18;
221.207.128.0/17;
221.208.0.0/14;
221.212.0.0/16;
221.213.0.0/16;
221.216.0.0/13;
222.128.0.0/14;
222.132.0.0/14;
222.136.0.0/13;
222.160.0.0/15;
222.162.0.0/16;
222.163.0.0/19;
222.163.32.0/19;
222.163.64.0/18;
222.163.128.0/17;
};

如果觉得有哪些部分不是很准确的话,可以自行修改

由于这个部分太长了,所以写在一个专门的文件然后include进named.conf比较容易维护
例如,我们把上面这段配置保存为cnc_acl.conf
然后在named.conf写入

include “/data/named/cnc_acl.conf”;

即可

接下来就是view的配置,假设域名是xyz.com,呵呵

view “view_cnc” {
match-clients { CNC; };
zone “xyz.com” {
type master;
file “/data/named/cnc_xyz”;
};
};

view “view_any” {
match-clients { any; };
zone “xyz.com” {
type master;
file “/data/named/any_xyz”;
};
};

就这样就足够了

然后我们需要cnc\_xyz和any_xyz两个具体的zone file
两个文件基本是一模一样的,就是指向不同的ip

$TTL 2h
xyz.com. IN SOA ns.xyz.com. root.xyz.com. (
20071022
2h
40m
1w
2h
)

this6.com. IN NS ns.xyz.com.
this6.com. IN MX 1 mail.xyz.com.
ns IN A 1.1.1.1
mail IN A 1.1.1.1

www IN A 1.1.1.1

根据不同的线路把www指向不同的IP即可
这样,我们就实现了自己的智能DNS

后话,目前许多大型网站都是用这个来实现不同的线路来源访问不同的镜像,甚至还做到地区级别,例如,在佛山机房部署了一台镜像服务器,就将广东省的访问都指向这台服务器
另外,刚刚提到智能DNS也有缺陷,这里详细描述一下,bind9通过用户的来源IP来返回不同的解释IP,而实际上,并不是实际用户直接访问我们的 DNS,而是用户所使用的DNS(比如说广州ADSL用户的默认DNS)负责访问我们的DNS,网通的DNS就保存有我们网通的IP,如果用户自行修改了 DNS,比如说电信的用户硬要用网通的DNS,或者网通的用户使用国外的DNS(比如opendns之类的),就会导致判断失误

2010/11/03

修改vim的編碼

vim ~/.vimrc 後 i 寫入 enc=utf-8 \n fenc=utf-8 :wq

2010/11/02

[Linux] 在 windows底下讀寫linux

« [Linux] cwRsync [rsync for windows] SSH 加密異地備份
Ubuntu Edgy Release KDE 桌面環境 »
[Linux] 在 windows底下讀寫linux

Dec 15th, 2006 by appleboy 參觀者:9,215Views 機器人:1,295Views
推到 Twitter!
推到 Plurk!
推到 Facebook!

剛剛在ptt看到的,一連串討論

□ XP 認得 ext2/ext3 磁區嗎 ?

裡面有很多文章 寫的不錯,可以提供出來

問題:

想問一下,我有一個移動式硬碟 60G
所以只能format 成 NTFS or ext2/ext3

而在 Linux 下, 目前支援 NTFS 讀寫可能要另外掛 package…

所以想問,那 Windows XP 是否支援 ext2 / ext3
ext3好像不行, 因為剛剛在 Linux 下 format成 ext3了
並備份了一些東東,到進到了Windows XP底下好像認不得了,

想問,ext2 在 Windows XP 底下,OK嗎…
xp認得嗎?

解法如下

作者 wyocbu@kkcity.com.tw (wyocbu),

以前下載過一個商業軟體 Paragon Mount Everything
http://www.mount-everything.com/

印象中好像可以讀寫 ext3

作者 ogre0403 (肚子餓)

只要讀的話 試試這個 應該是free的
http://www.chrysocome.net/explore2fs
寫的話應該不行

作者 alpe (薛丁格的貓)

http://www.fs-driver.org/

IFS Drivewrs 讀寫可… 不過中文編碼就…

作者 adolf.bbs@cd.twbbs.org (蘇怡華 有人要死了),

> http://ext2fsd.sf.net/
> ext2 可讀可寫
> ext3 唯讀

其實這類的driver都可以正常寫ext3
只是把journal關掉而已…

http://pank.org/blog/archives/000621.html


作者 jlovet (阿我真是猜不透XD)

ext2 跟 ext3是相容的檔案系統
在只支援ext2的OS上面mount ext3可以正常讀寫
只是會略過journal

關於ntfs-3g的測試…網站上面就有了…
http://www.ntfs-3g.org/performance.html

Ubuntu 掛載 Windows 分割區

Ubuntu 6.10 (Edgy):
deb http://givre.cabspace.com/ubuntu/ edgy main
deb http://ntfs-3g.sitesweetsite.info/ubuntu/ edgy main
deb http://flomertens.keo.in/ubuntu/ edgy main

Ubuntu 6.06 (Dapper Drake):
deb http://givre.cabspace.com/ubuntu/ dapper main main-all
deb http://ntfs-3g.sitesweetsite.info/ubuntu/ dapper main main-all
deb http://flomertens.keo.in/ubuntu/ dapper main main-all

然後執行以下指令更新 repositories 及安裝 ntfs-3g:

wget http://flomertens.keo.in/ubuntu/givre_key.asc -O- | sudo apt-key add -
wget http://givre.cabspace.com/ubuntu/givre_key.asc -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install ntfs-3g

http://www.real-blog.com/linux-bsd-notes/290


文章來源

Ubuntu 9.10 增加 / 設定 語系(Locale)

Ubuntu 9.10 增加 / 設定 語系(Locale)

語系增加在 Debian / Ubuntu Linux 上, 都是編輯 /etc/locale.gen 此檔案, 再執行 locale-gen 即可.

在 Ubuntu Linux 9.10 後, /etc/locale.gen 這個檔案不見了, 設上去也沒有用, 於是來找找新的設定法.
Locales 設定

* 由 "man locale-gen" 可以找到新的設定位置: /var/lib/locales/supported.d/*
* cat /var/lib/locales/supported.d/local # 可以看到目前設定語系

zh_TW.UTF-8 UTF-8

Locales 增加

要增加語系可以有下述兩種做法: (註: 語系列表可見: /usr/share/i18n/SUPPORTED)

1. 手動加入語系
* vim /var/lib/locales/supported.d/zh # 隨意新增一個檔案(zh 這個檔名可隨意命名)

zh_CN.UTF-8 UTF-8
zh_SG.UTF-8 UTF-8
zh_HK.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8

2. 使用 locale-gen 加入語系

1. sudo locale-gen zh_TW
2. sudo locale-gen zh_TW.UTF-8
3. cat /var/lib/locales/supported.d/local # 加入完成後, 可於此檔案看到資訊

重新建立 Locales

上述設定完成後, 執行重新建立的動作.

1. sudo locale-gen # 執行即可
2. 完成可見: ls /usr/lib/locale # 語系檔資料庫.

原始來源

2010/11/01

PHP Check and Validate

<?php

class check{

var $bench_start = 0;

function check(){
}

function check_int($value){
$help = (int)$value;
if(strcmp($help, $value)){
return false;
}
else{
return true;
}
}

function check_empty($value, $type = 1){
if($type == 0){
if(empty($value)){
return true;
}
else{
return false;
}
}
else{
if(!empty($value) || $value == "0"){
return true;
}
else{
return false;
}
}
}

function get_max($value_arr){
$max = $value_arr[0];
$i = 0;
$arr_index = $i;
foreach($value_arr as $val){
if($val > $max){
$max = $val;
$arr_index = $i;
}
$i++;
}
$return["arr_index"] = $arr_index;
$return["max_val"] = $max;
return $return;
}

function get_min($value_arr){
$min = $value_arr[0];
$i = 0;
$arr_index = $i;
foreach($value_arr as $val){
if($val < $min){
$min = $val;
$arr_index = $i;
}
$i++;
}
$return["arr_index"] = $arr_index;
$return["min_val"] = $min;
return $return;
}

function max($value, $max){
if($value > $max){
return false;
}
else{
return true;
}
}

function min($value, $min){
if($value < $min){
return false;
}
else{
return true;
}
}

function max_strlen($string, $max){
if(strlen($string) > $max){
return false;
}
else{
return true;
}
}

function min_strlen($string, $min){
if(strlen($string) < $min){
return false;
}
else{
return true;
}
}

function check_email($value){
$reg_exp="^($-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~�])+@($-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~�]+\\.)+$a-zA-Z]{2,6}\$";
$is_valid = eregi($reg_exp, $value);
if(!$is_valid){
return false;
}
else{
return true;
}
}

function check_plz($value, $check_strlen = 1){
$help = $value;
$first_letter = substr($value, 0, 1);
$is_null = false;
if(!strcmp($first_letter, "0")){
$is_null = true;
}
$plz= (int)$value;
if($is_null){
$plz = "0".$plz;
}
switch($check_strlen){
case 1:
if(strcmp($plz, $help) || strlen($plz) <5){
return false;
}
else{
return true;
}
break;
case 0:
if(strcmp($plz, $help)){
return false;
}
else{
return true;
}
break;
default:
echo "False type for check_strlen";
}
}

function sum($val_array = array(), $sum_val){
$sum = 0;
foreach($val_array as $val){
$sum += $val;
}
if($sum == $sum_val){
return true;
}
else{
return false;
}
}

function check_date($date){
$d = explode(".", $date);
if(strlen(@$d$2]) > 2){
@$d$2] = substr($d$2], strlen($d$2]) - 2 , 2);
}
if(checkdate(@$d$1], @$d$0], @$d$2])){
return true;
}
else{
return false;
}
}

function german_chars($string){
$string = str_replace("A", "&Auml;", $string);
$string = str_replace("O", "&Ouml;", $string);
$string = str_replace("U", "&Uuml;", $string);
$string = str_replace("a", "&auml;", $string);
$string = str_replace("o", "&ouml;", $string);
$string = str_replace("u", "&uuml;", $string);
$string = str_replace("s", "&szlig;", $string);
$string = str_replace("e", "&eacute;", $string);
return $string;
}

function is_hostname($url){
// (type of stream )(domain ).(tld )
$reg_exp = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)*($a-z]{1,}$\w-.]{0,}).($a-z]{2,6})$/i";
if(!preg_match($reg_exp, $url, $result)){
return false;
}
return true;
}

function is_url($url){
// (type of stream )(domain ).(tld )(scriptname or dirs )
$reg_exp = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)($a-z]{1,}$\w-.]{0,}).($a-z]{2,6})(\/{1}$\w_]{1}$\/\w-&?=_%]{0,}(.{1}$\/\w-&?=_%]{0,})*)*$/i";
if(!preg_match($reg_exp, $url, $result)){
return false;
}
return true;
}

function base_convert($num, $from){
$result["binary"] = base_convert($num, $from, 2);
$result["octal"] = base_convert($num, $from, 8);
$result["decimal"] = base_convert($num, $from, 10);
$result["hex"] = base_convert($num, $from, 16);
return $result;
}

function random_nr($min = 0, $max = 100000000000000){
return (mt_rand($min, $max));
}

function random_text($prefix = "generate_random_id"){
return md5(uniqid($prefix));
}

function microtime(){
$time = microtime();
$time = explode(" ", $time);
return $time[1] + $time[0];
}

function start_benchmark(){
$GLOBALS["bench_start_time"] = check::microtime();
}

function stop_benchmark(){
$GLOBALS["bench_end_time"] = check::microtime();
$time = $GLOBALS["bench_end_time"] - $GLOBALS["bench_start_time"];
$time = explode(".", $time);
$time[1] = substr($time[1], 0, 4);
$days = 0;
$hours = 0;
$mins = 0;
$seconds = $time[0];
while($seconds > 60){
$mins++;
$seconds -= 60;
}
while($mins > 60){
$hours++;
$mins -= 60;
}
while($hours > 24){
$days++;
$hours -= 24;
}
$durability = $days." 耗時 ".$hours." 時 ".$mins." 分 ".$seconds.".".$time[1]." 秒";
echo "<br><b>腳本時間: ".$durability."</b>";
}

function debug($array, $blank=0, $echo_class=0){
$multi = false;
if(is_object($array) && !$echo_class){
echo "<b>調試的對象: ".get_class($array)."</b><br>";
$multi = true;
}
if(is_array($array) && !$echo_class){
echo "<b>調試一個陣列</b><br>";
$multi = true;
}
if(!$multi && !$echo_class){
echo "<b>單變數調試</b><br>";
echo $array;
}
else{
$blanks = "";
for($i=0; $i<$blank; $i++){
$blanks .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
while(list($key, $val) = each ($array)){
if(is_array($val) || is_object($val)){
if(is_object($val)){
echo $blanks.$key." => "."<b>".$val." ".get_class($val)."</b><br>";
}
else{
echo $blanks.$key." => "."<b>".$val."</b><br>";
}
debug($val, $blank+1, 1);
}
else{
echo $blanks.$key." => ".$val."<br>";
}
}
}
}

function object_info($object){
$methods = get_class_methods(get_class($object));
$vars = get_class_vars(get_class($object));
echo "<b>概述對象類:".get_class($object)."</b><br>";
echo "<b>父類:".get_parent_class($object)."</b><br>";
echo "<b>概述方法類:<br></b>";
foreach($methods as $method){
echo "&nbsp;&nbsp;&nbsp;&nbsp;".$method."<br>";
}
echo "<b>概述變量類: (名稱 => 預設值)<br></b>";
foreach($vars as $var => $val){
echo "&nbsp;&nbsp;&nbsp;&nbsp;".$var." => ".$val."<br>";
}
}
}
?>



<?php
/**
* Validation class for validation of misc strings
*
* @author Sven Wagener <wagener_at_indot_de>
* @include Funktion:_include_
*/
class validate{
var $country_code;
var $string;

/**
* Regular expressions for postcode of the following countries
* at = austria
* au = australia
* ca = canada
* de = german
* ee = estonia
* nl = netherlands
* it = italy
* pt = portugal
* se = sweden
* uk = united kingdom
* us = united states
**/
var $pattern_postcode=array(
'at'=>'^$0-9]{4,4},
'au'=>'^$2-9]$0-9]{2,3},
'ca'=>'^$a-zA-Z].$0-9].$a-zA-Z].\s$0-9].$a-zA-Z].$0-9].',
'de'=>'^$0-9]{5,5},
'ee'=>'^$0-9]{5,5},
'nl'=>'^$0-9]{4,4}\s$a-zA-Z]{2,2},
'it'=>'^$0-9]{5,5},
'pt'=>'^$0-9]{4,4}-$0-9]{3,3},
'se'=>'^$0-9]{3,3}\s$0-9]{2,2},
'uk'=>'^($A-Z]{1,2}$0-9]{1}$0-9A-Z]{0,1}) ?($0-9]{1}$A-Z]{1,2}),
'us'=>'^$0-9]{5,5}$\-]{0,1}$0-9]{4,4}'

);

var $pattern_email='^($a-zA-Z0-9_\-\.]+)@((\$0-9]{1,3}\.$0-9]{1,3}\.$0-9]{1,3}\.)|(($a-zA-Z0-9\-]+\.)+))($a-zA-Z]{2,4}|$0-9]{1,3})(\]?)$ ';
var $pattern_ip='($0-9]{1,3}\.$0-9]{1,3}\.$0-9]{1,3}\.$0-9]{1,3})';
var $pattern_url='^(http|ftp)://(www\.)?.+\.(com|net|org);

/**
* The constructor of the validation class
* @param string $string the string which have to be validated
* @desc The constructor of the validation class
*/
function validate($string){
$this->string=$string;
}

/**
* Validates the string if it consists of alphabetical chars
* @param int $num_chars the number of chars in the string
* @param string $behave defines how to check the string: min, max or exactly number of chars
* @desc Validates the string if it consists of alphabetical chars
*/
function alpha($num_chars,$behave){
if($behave=="min"){
$pattern="^$a-zA-Z]{".$num_chars.",}$";
}else if ($behave=="max"){
$pattern="^$a-zA-Z]{0,".$num_chars."}$";
}else if ($behave=="exactly"){
$pattern="^$a-zA-Z]{".$num_chars.",".$num_chars."}$";
}
return ereg($pattern,$this->string);
}

/**
* Validates the string if it consists of lowercase alphabetical chars
* @param int $num_chars the number of chars in the string
* @param string $behave defines how to check the string: min, max or exactly number of chars
* @desc Validates the string if it consists of lowercase alphabetical chars
*/
function alpha_lowercase($num_chars,$behave){
if($behave=="min"){
$pattern="^$a-z]{".$num_chars.",}$";
}else if ($behave=="max"){
$pattern="^$a-z]{0,".$num_chars."}$";
}else if ($behave=="exactly"){
$pattern="^$a-z]{".$num_chars.",".$num_chars."}$";
}
return ereg($pattern,$this->string);

}

/**
* Validates the string if it consists of uppercase alphabetical chars
* @param int $num_chars the number of chars in the string
* @param string $behave defines how to check the string: min, max or exactly number of chars
* @desc Validates the string if it consists of uppercalse alphabetical chars
*/
function alpha_uppercase($num_chars,$behave){
if($behave=="min"){
$pattern="^$A-Z]{".$num_chars.",}$";
}else if ($behave=="max"){
$pattern="^$A-Z]{0,".$num_chars."}$";
}else if ($behave=="exactly"){
$pattern="^$A-Z]{".$num_chars.",".$num_chars."}$";
}
return ereg($pattern,$this->string);

}

/**
* Validates the string if it consists of numeric chars
* @param int $num_chars the number of chars in the string
* @param string $behave defines how to check the string: min, max or exactly number of chars
* @desc Validates the string if it consists of numeric chars
*/
function numeric($num_chars,$behave){
if($behave=="min"){
$pattern="^$0-9]{".$num_chars.",}$";
}else if ($behave=="max"){
$pattern="^$0-9]{0,".$num_chars."}$";
}else if ($behave=="exactly"){
$pattern="^$0-9]{".$num_chars.",".$num_chars."}$";
}
return ereg($pattern,$this->string);
}

/**
* Validates the string if it consists of alphanumerical chars
* @param int $num_chars the number of chars in the string
* @param string $behave defines how to check the string: min, max or exactly number of chars
* @desc Validates the string if it consists of alphanumerical chars
*/
function alpha_numeric($num_chars,$behave){
if($behave=="min"){
$pattern="^$0-9a-zA-Z]{".$num_chars.",}$";
}else if ($behave=="max"){
$pattern="^$0-9a-zA-Z]{0,".$num_chars."}$";
}else if ($behave=="exactly"){
$pattern="^$0-9a-zA-Z]{".$num_chars.",".$num_chars."}$";
}
return ereg($pattern,$this->string);
}

/**
* Validates the string if its a valid postcode
* @param string $country_code the country code for the country of the postcode (de,en)
* @desc Validates the string if its a valid postcode
*/
function postcode($country_code){
if(array_key_exists($country_code,$this->pattern_postcode)){
return ereg($this->pattern_postcode$country_code],$this->string);
}else{
return false;
}
}

/**
* Validates the string if its a valid email address
* @desc Validates the string if its a valid email adress
*/
function email(){
return ereg($this->pattern_email,$this->string);
}

/**
* Validates the string if its a valid ip address
* @desc Validates the string if its a valid ip address
*/
function ip_address(){
return ereg($this->pattern_ip,$ip);
}

/**
* Validates the string if its a valid URL
* @desc Validates the string if its a valid URL
*/
function url(){
return ereg($this->pattern_url,$ip);
}
}
?>

2010/08/23

Rsyslog Template for Fortigate Traffic


CREATE TABLE IF NOT EXISTS `Fortigate` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`log_time` datetime NOT NULL,
`log_id` int(10) unsigned NOT NULL,
`type` varchar(20) NOT NULL,
`subtype` varchar(20) NOT NULL,
`pri` varchar(20) NOT NULL,
`fwver` varchar(20) NOT NULL,
`vd` varchar(20) NOT NULL,
`msg` varchar(100) NOT NULL,
`action` varchar(20) NOT NULL,
`rem_ip` varchar(15) NOT NULL,
`loc_ip` varchar(15) NOT NULL,
`rem_port` int(10) unsigned NOT NULL,
`loc_port` int(10) unsigned NOT NULL,
`out_intf` varchar(20) NOT NULL,
`cookies` varchar(40) NOT NULL,
`user` varchar(20) NOT NULL,
`group` varchar(20) NOT NULL,
`xauth_user` varchar(20) NOT NULL,
`xauth_group` varchar(20) NOT NULL,
`vpn_tunnel` varchar(20) NOT NULL,
`status` varchar(20) NOT NULL,
`init` varchar(20) NOT NULL,
`mode` varchar(20) NOT NULL,
`dir` varchar(20) NOT NULL,
`stage` int(10) unsigned NOT NULL,
`role` varchar(20) NOT NULL,
`result` varchar(20) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

$template fortigate, "insert into Fortigate (log_time,log_id,type,subtype,pri,fwver,vd,msg,action,rem_ip,loc_ip,rem_port,loc_port,out_intf,cookies,user,group,xauth_user,xauth_group,vpn_tunnel,status,init,mode,dir,stage,role,result) values ('%timegenerated:::date-mysql%','%msg:R,ERE,1,BLANK:log_id=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:type=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:subtype=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:pri=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:fwver=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:vd=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:msg=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:action=([a-zA-Z0-9]+)--end%',%msg:R,ERE,1,BLANK:rem_ip=([0-9]+.[0-9]+.[0-9]+.[0-9]+)--end%,'%msg:R,ERE,1,BLANK:loc_ip=([0-9]+.[0-9]+.[0-9]+.[0-9]+)--end%',%msg:R,ERE,1,ZERO:rem_port=([0-9]+)--end%,%msg:R,ERE,1,ZERO:loc_port=([0-9]+)--end%,
'%msg:R,ERE,1,BLANK:out_intf=([a-zA-Z0-9_]+)--end%',%msg:R,ERE,1,BLANK:cookies=([a-zA-Z0-9]+)--end%,'%msg:R,ERE,1,BLANK:user=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:group=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:xauth_user=([a-zA-Z0-9]+)--end%',%msg:R,ERE,1,BLANK:xauth_group=([a-zA-Z0-9]+)--end%,
%msg:R,ERE,1,BLANK:vpn_tunnel=([a-zA-Z0-9]+)--end%,'%msg:R,ERE,1,BLANK:status=([a-zA-Z0-9]+)--end%',%msg:R,ERE,1,BLANK:init=([a-zA-Z0-9]+)--end%,'%msg:R,ERE,1,BLANK:mode=([a-zA-Z0-9]+)--end%',%msg:R,ERE,1,BLANK:dir=([a-zA-Z0-9]+)--end%,'%msg:R,ERE,1,BLANK:stage=([a-zA-Z0-9]+)--end%',%msg:R,ERE,1,BLANK:role=([a-zA-Z0-9]+)--end%,%msg:R,ERE,1,BLANK:result=([a-zA-Z0-9]+)--end%)", SQL



CREATE TABLE IF NOT EXISTS `Fortigate2` (
`ID` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`log_time` DATETIME NOT NULL ,
`log_id` INT( 10 ) UNSIGNED NOT NULL ,
`type` VARCHAR( 20 ) NOT NULL ,
`subtype` VARCHAR( 20 ) NOT NULL ,
`pri` VARCHAR( 20 ) NOT NULL ,
`vd` VARCHAR( 20 ) NOT NULL ,
`msg` VARCHAR( 100 ) NOT NULL ,
`action` VARCHAR( 20 ) NOT NULL ,
`user` VARCHAR( 20 ) NOT NULL ,
`status` VARCHAR( 20 ) NOT NULL ,
`reason` VARCHAR( 20 ) NOT NULL ,
`ui` VARCHAR( 20 ) NOT NULL ,
PRIMARY KEY ( `ID` ))
ENGINE = MYISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT =1;

$template fortigate2, "insert into Fortigate2 (log_time,log_id,type,subtype,pri,vd,msg,action,user,status,reason) values ('%timegenerated:::date-mysql%','%msg:R,ERE,1,BLANK:log_id=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:type=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:subtype=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:pri=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:vd=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:msg=([a-zA-Z0-9() .]+)--end%','%msg:R,ERE,1,BLANK:action=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:user="([a-zA-Z0-9]"+)--end%','%msg:R,ERE,1,BLANK:status=([a-zA-Z0-9]+)--end%','%msg:R,ERE,1,BLANK:reason=([a-zA-Z0-9"_]+)--end%')", SQL

2010/08/17

Dialogic 卡片安裝步驟

http://www.dialogic.com/support/helpweb/divasvr/InbuiltDrivers.aspx

2010/08/15

修改遠端桌面的port

Windows XP『遠端桌面』功能預設以編號3389連接埠作訊息傳輸,但可因應需要而進行修改︰啟動Regedit
,到路徑HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp
中DWORD值PortNumber,把數值由3389改為任何的數值便可,然後重新開機。

2010/08/14

ASP.NET AJAX 1.0 M$版

http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&displaylang=en