<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dada's Blog &#187; 軟體</title>
	<atom:link href="http://blog.urdada.net/category/comp/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.urdada.net</link>
	<description>Just for fun</description>
	<lastBuildDate>Fri, 13 Jan 2012 09:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>噗浪機器人範例程式 - 使用 Plurk API 2.0</title>
		<link>http://blog.urdada.net/2011/10/28/426/</link>
		<comments>http://blog.urdada.net/2011/10/28/426/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 09:04:27 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[軟體]]></category>
		<category><![CDATA[網路科技]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/?p=426</guid>
		<description><![CDATA[這篇文章說明如何用 Plurk API 2.0 自己寫一個噗浪機器人 (本文同步發表於 噗浪官方部落格) 噗浪大部分的機器人仍然使用 Plurk 1.0 撰寫，甚至有一部分機器人使用的是非官方的 API，這篇文章將簡介如何使用 Plurk API 2.0 OAuth 的方式開發機器人程式，同時，這個範例也使用 Plurk Realtime API (Comet Push) 的方式來追蹤時間軸，避免給伺服器帶來過多的負擔 由於 Plurk API 2.0 使用 OAuth 方式，所以啟動機器人之前，您必須先獲得以下四個參數 App Key App Secret Access Token Access Token Secret 獲得 App Key 及 App Secret 的方式很簡單，首先先註冊一個新的噗浪帳號用來跑這個機器人，然後登入新帳號後，開啟以下這個連結： http://www.plurk.com/PlurkApp/ 按下「註冊新的應用服務」，填寫關於你的程式的資料，其中 OAuth callback 保持空白即可 註冊完畢後就可以看到你的應用程式列表 然後按下「編輯」這個按鈕，就可以看到以下畫面： 這邊我們就可以得到 App [...]]]></description>
			<content:encoded><![CDATA[<p>這篇文章說明如何用 <a href="http://www.plurk.com/API" target="_blank">Plurk API 2.0</a> 自己寫一個噗浪機器人</p>
<p>(本文同步發表於 <a href="http://zh.blog.plurk.com/" title="噗浪官方部落格" target="_blank">噗浪官方部落格</a>)</p>
<p>噗浪大部分的機器人仍然使用 Plurk 1.0 撰寫，甚至有一部分機器人使用的是非官方的 API，這篇文章將簡介如何使用 Plurk API 2.0 OAuth 的方式開發機器人程式，同時，這個範例也使用 Plurk Realtime API (Comet Push) 的方式來追蹤時間軸，避免給伺服器帶來過多的負擔</p>
<p>由於 Plurk API 2.0 使用 OAuth 方式，所以啟動機器人之前，您必須先獲得以下四個參數</p>
<ul>
<li>App Key</li>
<li>App Secret</li>
<li>Access Token</li>
<li>Access Token Secret</li>
</ul>
<p>獲得 App Key 及 App Secret 的方式很簡單，首先先註冊一個新的噗浪帳號用來跑這個機器人，然後登入新帳號後，開啟以下這個連結：</p>
<p><a href="http://www.plurk.com/PlurkApp/" target="_blank">http://www.plurk.com/PlurkApp/</a></p>
<p>按下「註冊新的應用服務」，填寫關於你的程式的資料，其中 OAuth callback 保持空白即可</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-11.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-11.png" alt="" title="註冊新的應用服務" width="511" height="392" class="alignnone size-full wp-image-435" /></a></p>
<p>註冊完畢後就可以看到你的應用程式列表</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-2.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-2.png" alt="" title="應用程式列表" width="471" height="113" class="alignnone size-full wp-image-437" /></a></p>
<p>然後按下「編輯」這個按鈕，就可以看到以下畫面：</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-3.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-3.png" alt="" title="應用程式資料" width="511" height="214" class="alignnone size-full wp-image-439" /></a></p>
<p>這邊我們就可以得到 App Key 以及 App Secret 了</p>
<p>接下來要進行 OAuth 的授權驗證來取得 Access Token 及 Access Token Secret</p>
<p>按下「測試工具」來開啟 OAuth 的 Test Console</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-4.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-4.png" alt="" title="Test Console" width="834" height="156" class="alignnone size-full wp-image-441" /></a></p>
<p>首先按下「Get Request Token」來取得暫時的 Request Token，<br />
接下來按下「Open Authorization URL」來開啟授權頁面：</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-5.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-5.png" alt="" title="授權" width="405" height="230" class="alignnone size-full wp-image-442" /></a></p>
<p>按下「是，我要授權」後，會得到一個認證碼：</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-6.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-6.png" alt="" title="認證碼" width="212" height="111" class="alignnone size-full wp-image-444" /></a></p>
<p>把這個六位數的認證碼記下來，然後回到 Test Console，<br />
按下「Get Access Token」，這時會提示您輸入認證碼</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-7.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-7.png" alt="" title="Get Access Token" width="426" height="172" class="alignnone size-full wp-image-445" /></a></p>
<p>把您剛剛記下來的數字填進去，按下「確定」後，<br />
就可以得到永久有效的 Access Token 及 Access Token Secret 了</p>
<p><a href="http://blog.urdada.net/wp-content/uploads/2011/10/bot-8.png" rel="lightbox[426]"><img src="http://blog.urdada.net/wp-content/uploads/2011/10/bot-8.png" alt="" title="所有需要的參數" width="360" height="121" class="alignnone size-full wp-image-446" /></a></p>
<p>然後你就可以開始寫程式了，下面是一個用 Python 寫的噗浪機器人，<br />
把其中 APP_KEY, APP_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET 置換掉即可</p>
<p>這個程式需要使用到 <a href="https://github.com/clsung/plurk-oauth" target="_blank">plurk-oauth</a> 這個 Python library，<br />
請把 plurk_oauth/ 這個目錄下的檔案下載回來跟你的程式放在一起就可以了</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
34
35
36
37
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;"># -*- coding:utf-8 -*-</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> json
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> PlurkAPI <span style="color: #ff7700;font-weight:bold;">import</span> PlurkAPI
&nbsp;
plurk = PlurkAPI<span style="color: black;">&#40;</span><span style="color: #483d8b;">'APP_KEY'</span>, <span style="color: #483d8b;">'APP_SECRET'</span><span style="color: black;">&#41;</span>
plurk.<span style="color: black;">authorize</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'ACCEESS_TOKEN'</span>, <span style="color: #483d8b;">'ACCESS_TOKEN_SECRET'</span><span style="color: black;">&#41;</span>
&nbsp;
comet = plurk.<span style="color: black;">callAPI</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/APP/Realtime/getUserChannel'</span><span style="color: black;">&#41;</span>
comet_channel = comet.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'comet_server'</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&amp;new_offset=%d&quot;</span>
jsonp_re = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'CometChannel.scriptCallback<span style="color: #000099; font-weight: bold;">\(</span>(.+)<span style="color: #000099; font-weight: bold;">\)</span>;<span style="color: #000099; font-weight: bold;">\s</span>*'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
new_offset = -<span style="color: #ff4500;">1</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
    plurk.<span style="color: black;">callAPI</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/APP/Alerts/addAllAsFriends'</span><span style="color: black;">&#41;</span>
    req = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>comet_channel <span style="color: #66cc66;">%</span> new_offset, timeout=<span style="color: #ff4500;">80</span><span style="color: black;">&#41;</span>
    rawdata = req.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    match = jsonp_re.<span style="color: black;">match</span><span style="color: black;">&#40;</span>rawdata<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> match:
        rawdata = match.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
    data = json.<span style="color: black;">loads</span><span style="color: black;">&#40;</span>rawdata<span style="color: black;">&#41;</span>
    new_offset = data.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'new_offset'</span>, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
    msgs = data.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'data'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> msgs:
        <span style="color: #ff7700;font-weight:bold;">continue</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> msg <span style="color: #ff7700;font-weight:bold;">in</span> msgs:
        <span style="color: #ff7700;font-weight:bold;">if</span> msg.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'type'</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">'new_plurk'</span>:
            pid = msg.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'plurk_id'</span><span style="color: black;">&#41;</span>
            content = msg.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'content_raw'</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> content.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hello&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span>:
                plurk.<span style="color: black;">callAPI</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/APP/Responses/responseAdd'</span>,
                              <span style="color: black;">&#123;</span><span style="color: #483d8b;">'plurk_id'</span>: pid,
                               <span style="color: #483d8b;">'content'</span>: <span style="color: #483d8b;">'world'</span>,
                               <span style="color: #483d8b;">'qualifier'</span>: <span style="color: #483d8b;">':'</span> <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>執行方式：</p>
<pre language="shell">
# python my-robot.py
</pre>
<p>這個範例程式作的事情很簡單，就是一個無窮迴圈，首先每次都會先接受所有成為朋友的請求，然後看看有沒有新的噗，如果有新的噗，而且內容有 'hello' 字串的話，就會自動回覆一個 'world' 字串</p>
<p>提醒大家，噗浪並不反對機器人的存在，但使用這個範例程式請注意以下幾點：</p>
<ol>
<li>建議使用新的帳號，不要用原有的帳號</li>
<li>機器人請勿主動去加網友為朋友</li>
<li>機器人請勿去關注(追蹤)任何其他網友</li>
<li>請勿自動回覆未成為機器人的朋友所發的噗</li>
<li>請勿張貼廣告訊息</li>
<li>請注意回覆頻率，以不過度干擾使用者的方式為原則</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2011/10/28/426/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>我愛用的免費軟體 (my favorite freeware)</title>
		<link>http://blog.urdada.net/2009/03/02/148/</link>
		<comments>http://blog.urdada.net/2009/03/02/148/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 14:53:02 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[作業系統]]></category>
		<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/?p=148</guid>
		<description><![CDATA[最近已經快滿三年的 Thinkpad X60 跑得越來越慢，又常常當機，所以找個比較有空的時間就把它重灌 Windows XP Professional，順便作一下筆記 灌好作業系統後，可以先把 ThinkVantage System Update 裝起來，這樣 Thinkpad 相關的驅動程式及軟體都可以直接從這邊更新回來。對了，記得不要裝 Client Security Solution 因為裝了真的是自找麻煩! 另外 System Migration Assistant 和 Rescue and Recovery 我也沒裝.. 接下來就是安裝應用程式了，儘可能都以免費的軟體為主: PicPick 是一個很強大的截圖軟體 XnView 看圖及簡單的圖形處理 Paint.NET 是一個短小精幹的繪圖軟體 FileZilla 支援 FTP 及 SFTP 的檔案傳輸軟體 7-Zip 檔案解壓縮工具 K-Lite Codec Pack 播放各種影音檔案 Adobe Reader 閱讀 PDF 文件 Alcohol 52% Free Edition [...]]]></description>
			<content:encoded><![CDATA[<p>最近已經快滿三年的 Thinkpad X60 跑得越來越慢，又常常當機，所以找個比較有空的時間就把它重灌 Windows XP Professional，順便作一下筆記</p>
<p>灌好作業系統後，可以先把 <a href="http://www-307.ibm.com/pc/support/site.wss/TVSU-UPDATE.html" target=_blank>ThinkVantage System Update</a> 裝起來，這樣 Thinkpad 相關的驅動程式及軟體都可以直接從這邊更新回來。對了，記得不要裝 Client Security Solution 因為裝了真的是自找麻煩! 另外 System Migration Assistant 和 Rescue and Recovery 我也沒裝..</p>
<p>接下來就是安裝應用程式了，儘可能都以免費的軟體為主:</p>
<p><a href="http://picpick.wiziple.net/" target=_blank>PicPick</a> 是一個很強大的截圖軟體<br />
<a href="http://www.xnview.com/" target=_blank>XnView</a> 看圖及簡單的圖形處理<br />
<a href="http://www.paint.net/" target=_blank>Paint.NET</a> 是一個短小精幹的繪圖軟體<br />
<a href="http://filezilla-project.org/" target=_blank>FileZilla</a> 支援 FTP 及 SFTP 的檔案傳輸軟體<br />
<a href="http://7-zip.org/" target=_blank>7-Zip</a> 檔案解壓縮工具<br />
<a href="http://www.free-codecs.com/download/K_lite_codec_pack.htm" target=_blank>K-Lite Codec Pack</a> 播放各種影音檔案<br />
<a href="http://www.adobe.com/tw/products/reader/" target=_blank>Adobe Reader</a> 閱讀 PDF 文件</p>
<p><a href="http://trial.alcohol-soft.com/en/" target=_blank>Alcohol 52% Free Edition</a> 虛擬光碟 (裝免費版的即可, 可選擇不裝贊助軟體)<br />
<a href="http://www.free-av.com/" target=_blank>Avira AntiVir</a> 掃毒軟體<br />
<a href="http://ccollomb.free.fr/unlocker/" target=_blank>Unlocker</a> 強制解鎖<br />
<a href="http://rocketdock.com/" target=_blank>RocketDock</a> 像蘋果的工具列<br />
<a href="http://chewing.csie.net/download/win32/" target=_blank>新酷音輸入法</a> (最新版: 0.3.4.8)</p>
<p>其他網路工具包含:</p>
<ul>
<li><a href="http://pank.org/im/" target=_blank>Messenger</a>
<li><a href="http://www.moztw.org/firefox/" target=_blank>Mozilla Firefox</a>
<li><a href="http://www.skype.com/intl/zh-Hant/" target=_blank>Skype</a>
<li><a href="http://pcman.openfoundry.org/" target=_blank>PCMan Lite</a>
<li><a href="http://www.flickr.com/tools/uploadr/" target=_blank>Flickr Uploadr</a>
</ul>
<p>Google 提供的工具:</p>
<ul>
<li><a href="http://www.google.com/chrome" target=_blank>Google Chrome</a>
<li><a href="http://www.google.com/talk/intl/zh-TW/" target=_blank>Google Talk</a>
<li><a href="http://earth.google.com/intl/zh-TW/" target=_blank>Google Earth</a>
<li><a href="http://picasa.google.com.tw/" target=_blank>Picasa</a>
</ul>
<p>另外微軟的 <a href="http://www.microsoft.com/windowsxp/Downloads/powertoys/Xppowertoys.mspx" target=_blank>PowerToys for Windows XP</a> 也有幾個不錯的小工具:</p>
<ul>
<li>CmdHere
<li>PowerToy Calculator
<li>Tweak UI
</ul>
<p>還有之前微軟有提供一個 Microsoft Chinese Date and Time，是一個我很愛用的農民曆及世界時間工具，但現在微軟似乎把連結拿掉了，不過網路上搜尋一下就找到了</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2009/03/02/148/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mantis Mail Gateway (perl script)</title>
		<link>http://blog.urdada.net/2008/11/11/95/</link>
		<comments>http://blog.urdada.net/2008/11/11/95/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 15:09:26 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2008/11/11/95/</guid>
		<description><![CDATA[This is a simple Mantis Mail Gateway for mail-in tickets. It can be used for alert management for monitoring system. For installation, add the line below to /etc/aliases: bug: "&#124;/usr/local/bin/mantis-mail-gateway.pl &#160; PROJECT &#160; REPORTER" and then run newaliases. The incoming mail will be posted to a Mantis project named 'PROJECT' on behave of user 'REPORTER'. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple Mantis Mail Gateway for mail-in tickets.<br />
It can be used for alert management for monitoring system.</p>
<p>For installation, add the line below to /etc/aliases:</p>
<p><strong>bug:   "|/usr/local/bin/mantis-mail-gateway.pl  &nbsp; PROJECT &nbsp;  REPORTER"</strong></p>
<p>and then run newaliases.</p>
<p>The incoming mail will be posted to a Mantis project named 'PROJECT' on behave of user 'REPORTER'. The mail subject will become the bug summary and the mail content will become the bug description.</p>
<p>Note that this script does not understand MIME multipart encoding and may have problems on mail contents besides plain-ASCII encoding.</p>
<p>You are welcome to add more features.</p>
<p><img src=http://farm4.static.flickr.com/3286/3022458848_b690e23167.jpg /></p>
<p>mantis-mail-gateway.pl: (can be downloaded <a href=http://urdada.net/codings/mantis-mail-gateway.pl>here</a>)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># mantis-mail-gateway.pl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Mantis Mail Gateway</span>
<span style="color: #666666; font-style: italic;"># Shen Cheng-Da (cdsheen AT gmail.com)</span>
<span style="color: #666666; font-style: italic;"># require DBI to connect MySQL database</span>
<span style="color: #666666; font-style: italic;"># http://blog.urdada.net/2008/11/11/95/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> POSIX <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>strftime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$db_host</span>    <span style="color: #339933;">=</span> <span style="color: #ff0000;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$db_name</span>    <span style="color: #339933;">=</span> <span style="color: #ff0000;">'mantis'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$db_user</span>    <span style="color: #339933;">=</span> <span style="color: #ff0000;">'monitor'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$db_pass</span>    <span style="color: #339933;">=</span> <span style="color: #ff0000;">'monitorpass'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$debug</span>      <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$db</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;dbi:mysql:dbname=${db_name};host=${db_host}&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Usage: $0 [project-name] [reporter]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">unless</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">ARGV</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$project_name</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$reporter_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$project</span>  <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$reporter</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$db</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$db_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$db_pass</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT id,name FROM mantis_project_table
        WHERE name LIKE '$project_name'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$project</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;ERROR: project <span style="color: #000099; font-weight: bold;">\`</span>$project_name' does not exist<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$project</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;project: $project_name ($project)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$debug</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT id,username FROM mantis_user_table
        WHERE username = '$reporter_name'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$reporter</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;ERROR: user <span style="color: #000099; font-weight: bold;">\`</span>$reporter_name' does not exist<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$reporter</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;reporter: $reporter_name ($reporter)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$debug</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009966; font-style: italic;">s/\s+$//</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">last</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$_</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span> <span style="color: #b1b100;">if</span> <span style="color: #009966; font-style: italic;">/^Subject: (.+)$/</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'INSERT INTO mantis_bug_text_table (description) VALUES (?)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$textid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span>mysql_insertid<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;bug text id: $textid<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$debug</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'INSERT INTO mantis_bug_table
                ( project_id, reporter_id,
                  date_submitted, last_updated,
                  bug_text_id, summary )
        VALUES (?,?,?,?,?,?)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$now</span> <span style="color: #339933;">=</span> strftime<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'%Y-%m-%d %H:%M:%S'</span><span style="color: #339933;">,</span> <span style="color: #000066;">localtime</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">time</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$project</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$reporter</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$now</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$now</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$textid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$subject</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2008/11/11/95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion pre-commit hook</title>
		<link>http://blog.urdada.net/2008/07/30/88/</link>
		<comments>http://blog.urdada.net/2008/07/30/88/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 16:54:26 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2008/07/30/88/</guid>
		<description><![CDATA[很多人寫完程式要 commit 的時候會偷懶不寫 log，導致有時候要追問題時， 很難得知到底別人改了什麼，這時候裝個 pre-commit hook 還是蠻有用的 下面這個 pre-commit hook 只是很簡單的不允許空白或不含字母的 commit log， 如果需要的話可以很容易擴充加上更多的判斷.. 記得要 chmod 755 喔 [Subversion pre-commit hook to reject commit with empty log] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #!/usr/bin/perl &#160; # pre-commit hook to reject [...]]]></description>
			<content:encoded><![CDATA[<p>很多人寫完程式要 commit 的時候會偷懶不寫 log，導致有時候要追問題時，<br />
很難得知到底別人改了什麼，這時候裝個 pre-commit hook 還是蠻有用的</p>
<p>下面這個 <a href=http://svnbook.red-bean.com/en/1.4/svn.ref.reposhooks.pre-commit.html target=_blank>pre-commit hook</a> 只是很簡單的不允許空白或不含字母的 commit log，<br />
如果需要的話可以很容易擴充加上更多的判斷.. 記得要 chmod 755 喔</p>
<p><strong>[Subversion pre-commit hook to reject commit with empty log]</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pre-commit hook to reject commit with empty log</span>
<span style="color: #666666; font-style: italic;"># remember to chmod 755 on this file</span>
&nbsp;
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Usage: $0 [REPOS] [TXN]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">unless</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">ARGV</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$REPOS</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$TXN</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$svnlook</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/local/bin/svnlook'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$author</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`$svnlook author -t $TXN $REPOS`</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$log</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`$svnlook log -t $TXN $REPOS`</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$log</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">''</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">$log</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^\W+$/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Hello, $author. Empty commit log is not permitted!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>除此之外，對於 pre-commit hook，我還加上了檢查不允許跨 branch 的 commit，<br />
因為一旦有了跨 branch 的 commit，會使得未來需要作 merge 的時候遇到許多麻煩</p>
<p>例如常用的 repository 結構如下:</p>
<p>/trunk/<br />
/branches/helloworld-1.0/<br />
/branches/helloworld-1.1/</p>
<p>要防止使用者同時對兩個以上的 branch (包含 main trunk) 作 commit，<br />
可以把下面這一段程式再加進去 pre-commit 的 hook 中</p>
<p><strong>[Subversion pre-commit hook to reject cross-branch commit]</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
34
35
36
37
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pre-commit hook to reject empty commit log and cross-branch commit</span>
<span style="color: #666666; font-style: italic;"># remember to chmod 755 on this file</span>
&nbsp;
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Usage: $0 [REPOS] [TXN]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">unless</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">ARGV</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$REPOS</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$TXN</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$svnlook</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/local/bin/svnlook'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$author</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`$svnlook author -t $TXN $REPOS`</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$log</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`$svnlook log -t $TXN $REPOS`</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$log</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">''</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">$log</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^\W+$/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Hello, $author. Empty commit log is not permitted!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>DIRS<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$svnlook dirs-changed -t $TXN $REPOS|&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;DIRS&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/^(trunk)\//</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$branches</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elsif</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/^branches\/([^\/]+)/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #0000ff;">$branches</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>DIRS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">%branches</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$c</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Hello, $author. You can't commit to $c branches at the same time!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2008/07/30/88/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSH Escape Character</title>
		<link>http://blog.urdada.net/2008/01/02/73/</link>
		<comments>http://blog.urdada.net/2008/01/02/73/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 13:36:51 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>
		<category><![CDATA[資訊安全]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2008/01/02/73/</guid>
		<description><![CDATA[SSH client 有一個 Escape Character (跳脫字元)，事實上 rsh/rlogin 也有支援 Escape Character (~)，就如同 Ctrl-] 之於 telnet 一樣... SSH client 的 Escape Character 一般跟 rsh/rlogin 一樣設定成 ~，詳細用法可於命令列按 ~? 來取得說明，要注意的是，為了避免影響一般正常的輸入，Escape Character 必須是命令列換行後的第一個按鍵，如果你已經輸入別的按鍵，即使按 backspace 把游標移回開頭處再輸入 Escape Character 也是無效的！請先按 Enter 換行後再輸入吧！ myhost# ~? Supported escape sequences: ~. - terminate connection ~B - send a BREAK to the remote system ~C - [...]]]></description>
			<content:encoded><![CDATA[<p>SSH client 有一個 Escape Character (跳脫字元)，事實上 rsh/rlogin 也有支援 Escape Character (~)，就如同 Ctrl-] 之於 telnet 一樣...</p>
<p>SSH client 的 Escape Character 一般跟 rsh/rlogin 一樣設定成 ~，詳細用法可於命令列按 ~? 來取得說明，要注意的是，為了避免影響一般正常的輸入，Escape Character 必須是<u>命令列換行後的第一個按鍵</u>，如果你已經輸入別的按鍵，即使按 backspace 把游標移回開頭處再輸入 Escape Character 也是無效的！請先按 Enter 換行後再輸入吧！</p>
<pre class=mono>
myhost# ~?
Supported escape sequences:
~.  - terminate connection
~B  - send a BREAK to the remote system
~C  - open a command line
~R  - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~#  - list forwarded connections
~&#038;  - background ssh (when waiting for connections to terminate)
~?  - this message
~~  - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
</pre>
<p>最常用的 Escape Character 就是 ~. 以及 ~^Z 這兩個：</p>
<p>~. 是直接切斷目前的 SSH 連線，如果你遇到遠端機器沒有反應時，可用此方式來切斷連線</p>
<p>~^Z (~ 及 Ctrl-Z) 則是把目前的 SSH 連線先 suspend，一般可用來回到原來機器上處理一些事情，若要再回去，輸入 fg 即可</p>
<p>問題來了，假設你從 HOST1 先 SSH 到 HOST2，然後再從 HOST2 SSH 到 HOST3</p>
<p>HOST1 ===1===> HOST2 ===2===> HOST3</p>
<p>如果你在 HOST3 的 terminal 下輸入 ~. 的話，你會直接切斷上面的第一段連線回到 HOST1 的 terminal，當然這樣的話第二段連線也一併 bye-bye 了！如果只是想切斷第二段連線回到 HOST2 該怎麼作呢？</p>
<p>這時候 ~~ 就發揮作用了，你只要輸入 ~~. 就可以切斷第二段連線了</p>
<p>以此累推，輸入 N 個 Escape Character 代表對第 N 段連線送出 Escape Character</p>
<p>最後，若不想用 ~ 當作跳脫字元，可於命令列用 -e 修改，例如把 SSH 跳脫字元改成 #：</p>
<pre class=mono>
ssh -e "#" myhost.mydomain.com
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2008/01/02/73/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script: 取得 FreeBSD CVSUP 的更新狀態</title>
		<link>http://blog.urdada.net/2007/12/24/69/</link>
		<comments>http://blog.urdada.net/2007/12/24/69/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 15:52:43 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2007/12/24/69/</guid>
		<description><![CDATA[這是今年1月寫的 script... 用來監控各大 FreeBSD CVSUP mirror 網站的檔案更新程度， 提供服務的網址是 http://ftp.giga.net.tw/cvsup.php 內容其實很簡單，下面把程式放出來，有興趣的人歡迎免費拿去修改使用 == 原理說明: CVS 不像 Subversion 一樣可以很容易知道目前 repository 中的最新版本為何， 必須要把每個檔案檢查一遍才有辦法知道最新的版本是什麼... 不過在 FreeBSD Source CVS 下面，每次 commit 都會有 commit log 可經由 CVSUP 取得， 因此我們可以利用 CVSROOT-*/commitlogs/* 這幾個檔案來判斷目前 source tree 的狀態.. 只要把這幾個檔案經由 CVSUP 取出來就可以大致知道該伺服器的目前保存的最新版本是哪一個了 == 第一個是一個 Perl script，主要是連結到各大 FreeBSD CVSUP 網站取得相關資訊存下來 後面則附上一個 PHP script，可以把這些資訊用 HTML 表格方式呈現出來 check-cvsup.pl 1 2 [...]]]></description>
			<content:encoded><![CDATA[<p>這是今年1月寫的 script...  用來監控各大 FreeBSD CVSUP mirror 網站的檔案更新程度，<br />
提供服務的網址是 <a href=http://ftp.giga.net.tw/cvsup.php target=_blank>http://ftp.giga.net.tw/cvsup.php</a></p>
<p><img src="http://farm3.static.flickr.com/2057/2134694712_0811886762.jpg" alt="" /></p>
<p>內容其實很簡單，下面把程式放出來，有興趣的人歡迎免費拿去修改使用</p>
<p>==<br />
原理說明:</p>
<p><a href=http://www.nongnu.org/cvs/ target=_blank>CVS</a> 不像 <a href=http://subversion.tigris.org/ target=_blank>Subversion</a> 一樣可以很容易知道目前 repository 中的最新版本為何，<br />
必須要把每個檔案檢查一遍才有辦法知道最新的版本是什麼...</p>
<p>不過在 FreeBSD Source CVS 下面，每次 commit 都會有 commit log 可經由 CVSUP 取得，<br />
因此我們可以利用 CVSROOT-*/commitlogs/* 這幾個檔案來判斷目前 source tree 的狀態..<br />
只要把這幾個檔案經由 CVSUP 取出來就可以大致知道該伺服器的目前保存的最新版本是哪一個了<br />
==</p>
<p>第一個是一個 Perl script，主要是連結到各大 FreeBSD CVSUP 網站取得相關資訊存下來<br />
後面則附上一個 PHP script，可以把這些資訊用 HTML 表格方式呈現出來</p>
<p>check-cvsup.pl</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check the update status for CVSUP servers</span>
<span style="color: #666666; font-style: italic;"># BSD license</span>
<span style="color: #666666; font-style: italic;"># Shen Cheng-Da (cdsheen AT gmail.com)</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> POSIX <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>strftime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">DNS</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Time<span style="color: #339933;">::</span><span style="color: #006600;">HiRes</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span> gettimeofday tv_interval <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@servers</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span> cvsup<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup1<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup2<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org 
                cvsup3<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup4<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup5<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org 
                cvsup6<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup7<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup8<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org 
                cvsup9<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup10<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup11<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org 
                cvsup12<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup13<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org cvsup14<span style="color: #339933;">.</span>tw<span style="color: #339933;">.</span>freebsd<span style="color: #339933;">.</span>org <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dir</span>    <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/home/cvsup-monitor'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$cvsup</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/local/bin/cvsup'</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$base</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/base'</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$log</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/check.log'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">chdir</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$dir</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;ERROR: Can not change to directory [$dir]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">mkdir</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$base</span><span style="color: #339933;">,</span> 0755 <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">unless</span> <span style="color: #339933;">-</span>d <span style="color: #0000ff;">$base</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@files_src</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span> CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>CVSROOT CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>bin
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>etc CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>contrib
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>gnu CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>games
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>include CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>lib
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>release CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>sys
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>sbin CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>share
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>tools CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>user
                CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>usrbin CVSROOT<span style="color: #339933;">-</span>src<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>usrsbin <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@files_ports</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span> CVSROOT<span style="color: #339933;">-</span>ports<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>CVSROOT
                        CVSROOT<span style="color: #339933;">-</span>ports<span style="color: #339933;">/</span>commitlogs<span style="color: #339933;">/</span>ports <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$includes</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$f</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@files_src</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$includes</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot; -i $f&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$f</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@files_ports</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$includes</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot; -i $f&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span> LOG<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;$log&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$resolver</span> <span style="color: #339933;">=</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">DNS</span><span style="color: #339933;">::</span><span style="color: #006600;">Resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">usevc</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">udp_timeout</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">tcp_timeout</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">retrans</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">retry</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">persistent_tcp</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$server</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@servers</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$resolver</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$server</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'A'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">@ipaddr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@cname</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$query</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$rr</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">answer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$rr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">type</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'A'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #000066;">print</span> LOG <span style="color: #ff0000;">&quot;$server =&gt; [A] &quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$rr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">address</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                                <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@ipaddr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$rr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">address</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                        <span style="color: #b1b100;">elsif</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$rr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">type</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'CNAME'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #000066;">print</span> LOG <span style="color: #ff0000;">&quot;$server =&gt; [CNAME] &quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$rr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">cname</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                                <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@cname</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$rr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">cname</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #0000ff;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ipaddr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$ipaddr</span> <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'|'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@ipaddr</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cname</span>  <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'|'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@cname</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #0000ff;">$ibase</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$base/$server&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">mkdir</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$ibase</span><span style="color: #339933;">,</span> 0755 <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">unless</span> <span style="color: #339933;">-</span>d <span style="color: #0000ff;">$ibase</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">mkdir</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;$ibase/SRC&quot;</span><span style="color: #339933;">,</span> 0755 <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">unless</span> <span style="color: #339933;">-</span>d <span style="color: #ff0000;">&quot;$ibase/SRC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$cvsup -h $ip -L 0 -b $ibase -r 0 $includes supfile&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #0000ff;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>gettimeofday<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$elapsed</span> <span style="color: #339933;">=</span> tv_interval<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$time_start</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066;">printf</span> LOG <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$server =&gt; cvsup on $ip elapsed %.2fs<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$time_elapsed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">unless</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$?</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$mt_src</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$mt_ports</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$f</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@files_src</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #0000ff;">$t</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">stat</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;$ibase/SRC/$f&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #0000ff;">$mt_src</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$t</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$t</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$mt_src</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$f</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@files_ports</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #0000ff;">$t</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">stat</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;$ibase/SRC/$f&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #0000ff;">$mt_ports</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$t</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$t</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$mt_ports</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span> REC<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;$ibase/last-commit.txt&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">printf</span> REC<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$mt_src,$mt_ports,%.2f,$ipaddr,$cname&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$elapsed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>REC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066;">printf</span> LOG <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$server =&gt; SRC: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                        strftime<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%Y/%m/%d %H:%M:%S&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066;">localtime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$mt_src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">printf</span> LOG <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$server =&gt; PORTS: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                        strftime<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%Y/%m/%d %H:%M:%S&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066;">localtime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$mt_ports</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>LOG<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>supfile:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">*default prefix=SRC
*default release=cvs delete use-rel-suffix
*default compress
&nbsp;
cvsroot-src
cvsroot-ports</pre></div></div>

<p>cvsup.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;style type=&quot;text/css&quot;&gt;
  td       { font-size: 12px; vertical-align: top }
  td.head  { background: #FFFFC0 }
  td.c     { background: #E0E0FF }
  td.red   { background: #FFE0E0 }
  td.green { background: #E0FFE0 }
&lt;/style&gt;
&lt;table border=1 cellspacing=0 cellpadding=2&gt;
&lt;tr&gt;&lt;td class=head&gt;Server Name&lt;/td&gt;&lt;td class=head&gt;IP&lt;/td&gt;
&lt;td class=head&gt;CNAME&lt;/td&gt;&lt;td class=head&gt;latest commit of src&lt;/td&gt;
&lt;td class=head&gt;latest commit of ports&lt;/td&gt;
&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span>
        <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/home/cvsup-monitor'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$servers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
              <span style="color: #0000ff;">'cvsup.tw.freebsd.org'</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'cvsup1.tw.freebsd.org'</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'cvsup2.tw.freebsd.org'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'cvsup3.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup4.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup5.tw.freebsd.org'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'cvsup6.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup7.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup8.tw.freebsd.org'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'cvsup9.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup10.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup11.tw.freebsd.org'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'cvsup12.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup13.tw.freebsd.org'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cvsup14.tw.freebsd.org'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$check</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$time_format</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'%Y/%m/%d %H:%M:%S'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$latest_src</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$latest_ports</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$servers</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$server</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dir</span>/base/<span style="color: #006699; font-weight: bold;">$server</span>/last-commit.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$latest_src</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #000088;">$latest_src</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$latest_ports</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #000088;">$latest_ports</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$servers</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$server</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$src</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ports</span><span style="color: #339933;">,</span> <span style="color: #000088;">$elapsed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ipaddr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$aliases</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$ipaddr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ipaddr</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$aliases</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$aliases</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$aliases</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #000088;">$aliases</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&amp;nbsp;'</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=c&gt;<span style="color: #006699; font-weight: bold;">$server</span>&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=c&gt;<span style="color: #006699; font-weight: bold;">$ipaddr</span>&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=c&gt;<span style="color: #006699; font-weight: bold;">$aliases</span>&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$src</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$latest_src</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=green&gt;&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$src</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$check</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=red&gt;&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">else</span>
                                <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=c&gt;&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">print</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$time_format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ports</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$latest_ports</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=green&gt;&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ports</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$check</span> <span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=red&gt;&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">else</span>
                                <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;  &lt;td class=c&gt;&quot;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">print</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$time_format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ports</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#                       print &quot;  &lt;td align=right&gt;$elapsed s&lt;/td&gt;\n&quot;;
</span>                        <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/table&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2007/12/24/69/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Subversion: revert a commit [時光倒轉]</title>
		<link>http://blog.urdada.net/2007/11/07/63/</link>
		<comments>http://blog.urdada.net/2007/11/07/63/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 15:09:31 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2007/11/07/63/</guid>
		<description><![CDATA[使用 Subversion 偶而就會遇到有人不小心把一堆不該存在的檔案 commit 進來了，這在去年寫的一篇「svndumpflter with wildcards support ?」有提到從歷史記憶中去除個別檔案的方式 但如果你能即時發現最新的一個(或幾個) commit(s) 的任何更動都是不該發生的（通常就是有人做了蠢事），那麼在有其他正常人繼續 commit 之前，其實是有蠻好的挽救機會的 假設你的 repository 名稱是 foobar，最新的 revision number 是 r105，但是你即時發現 r101 ~ r105 都是某人亂搞的結果，那麼在 r106 commit 之前，應該還有機會把時光倒轉到 r100 那時清純未受污染的狀態.. 廢話不多說，下面是作法 # cd /home/svn # svnadmin create foobar.new # svnadmin dump -r0:100 foobar &#124; svnadmin load --force-uuid foobar.new # mv foobar foobar.old # mv [...]]]></description>
			<content:encoded><![CDATA[<p>使用 <a href=http://subversion.tigris.org/ target=_blank>Subversion</a> 偶而就會遇到有人不小心把一堆不該存在的檔案 commit 進來了，這在去年寫的一篇「<a href=http://blog.urdada.net/2006/10/06/64/ target=_blank>svndumpflter with wildcards support ?</a>」有提到從歷史記憶中去除個別檔案的方式</p>
<p>但如果你能即時發現最新的一個(或幾個) commit(s) 的任何更動都是不該發生的（通常就是有人做了蠢事），那麼在有其他正常人繼續 commit 之前，其實是有蠻好的挽救機會的 <img src='http://blog.urdada.net/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' /> </p>
<p>假設你的 repository 名稱是 foobar，最新的 revision number 是 r105，但是你即時發現 r101 ~ r105 都是某人亂搞的結果，那麼在 r106 commit 之前，應該還有機會把時光倒轉到 r100 那時清純未受污染的狀態..</p>
<p>廢話不多說，下面是作法</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># cd /home/svn
# svnadmin create foobar.new
# svnadmin dump -r0:100 foobar | svnadmin load --force-uuid foobar.new
# mv foobar foobar.old
# mv foobar.new foobar</pre></div></div>

<p>做完以上動作後再把該設的權限弄好，hooks 下的東西 copy 回去就可以了</p>
<p>如果有其他人在這段動作完成前 checkout 了 r101~r105 之間的版本，就跟他們說他們看到鬼了，請他們砍掉 source tree 重新 checkout 一份吧 <img src='http://blog.urdada.net/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' />  </p>
<p>上面這段作法最重要的地方是 <strong>--force-uuid</strong> 這個選項，沒有加這個選項會使得回復的 repository 的 UUID 跟原本的不同，進而導致之前已經 checkout 的 working copy 都會認不得新的 repository！</p>
<p>如果還來不及作上述動作，就有其他正常人 commit 東西進來了，其實也不會很麻煩，反正做完回復動作後，統統當作沒發生過，再叫作蠢事的人請一頓飯，拜託其他人把新的修改再改一次就好了</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2007/11/07/63/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Access Subversion with Apache Proxy Module</title>
		<link>http://blog.urdada.net/2007/10/11/59/</link>
		<comments>http://blog.urdada.net/2007/10/11/59/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 05:32:05 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2007/10/11/59/</guid>
		<description><![CDATA[由於網路架構的問題，我們有時會設計讓不同網段必須透過 Proxy 才能存取 Subversion Repository，但是為此架設一個獨立的 Proxy Server （如 squid）實在太麻煩，利用 Apache 內建的 mod_proxy / mod_proxy_http 功能有時候會讓工作簡化很多 ProxyRequests Off &#60;Proxy *&#62; Order deny,allow Deny from all &#60;/Proxy&#62; ProxyVia On 為了安全性考量，如同上面的設定，我們先把所有 Proxy 的存取關掉，然後依據需要開放特定目錄來允許 Proxy 例如我們想把對 /svn 的存取導向到 http://svn.domain/svn，那麼設定內容就會變成： &#60;VirtualHost *:80&#62; ProxyPass /svn http://svn.domain/svn ProxyPassReverse /svn http://svn.domain/svn &#60;Location /svn&#62; &#60;Limit OPTIONS PROPFIND GET REPORT MKACTIVITY PROPPATCH PUT CHECKOUT MKCOL [...]]]></description>
			<content:encoded><![CDATA[<p>由於網路架構的問題，我們有時會設計讓不同網段必須透過 Proxy 才能存取 <a href="http://subversion.tigris.org/" target=_blank>Subversion</a> Repository，但是為此架設一個獨立的 Proxy Server （如 <a href="http://www.squid-cache.org/" target=_blank>squid</a>）實在太麻煩，利用 <a href=http://httpd.apache.org/ target=_blank>Apache</a> 內建的 <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html" target=_blank>mod_proxy</a> / <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy_http.html" target=_blank>mod_proxy_http</a> 功能有時候會讓工作簡化很多</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">ProxyRequests Off
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Proxy</span> *<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    Order deny,allow
    Deny from all
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Proxy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
ProxyVia On</pre></div></div>

<p>為了安全性考量，如同上面的設定，我們先把所有 Proxy 的存取關掉，然後依據需要開放特定目錄來允許 Proxy</p>
<p>例如我們想把對 /svn 的存取導向到 http://svn.domain/svn，那麼設定內容就會變成：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VirtualHost</span> *:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    ProxyPass /svn http://svn.domain/svn
    ProxyPassReverse /svn http://svn.domain/svn
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Location</span> /svn<span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Limit</span> OPTIONS PROPFIND GET REPORT MKACTIVITY PROPPATCH PUT CHECKOUT</span>
<span style="color: #009900;"> MKCOL MOVE COPY DELETE LOCK UNLOCK MERGE<span style="color: #000000; font-weight: bold;">&gt;</span></span>
          Order Deny,Allow
          Allow from all
          Satisfy Any
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Limit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>裡面最重要的就是 &lt;Limit OPTIONS PROPFIND... &gt; 這一行（這一整行不能分成兩行，Copy-Paste時請注意），因為 Subversion 會用到除了 HTTP GET / POST 以外的一些特殊 Method，因此必須設定讓 HTTP 的 Proxy Module 允許這些 Methods 通過，才能讓 Subversion 正常運作</p>
<p>另外建議修改 Allow from all 這一行，改成僅允許特定 IP 來連結，也可強化系統的安全性</p>
<p>參考資料： <a href="http://silmor.de/49" target=_blank>Subversion behind an Apache Reverse Proxy</a> （不過裡面的設定方式跟我上面提供的有一點點小小差異）</p>
<p>如果你還是想用 squid 來解決問題，那您可以參考 Subversion 網站上面的 <a href="http://subversion.tigris.org/faq.html#proxy" target=_blank>FAQ</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2007/10/11/59/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MSN Messenger 7.5 強迫升級</title>
		<link>http://blog.urdada.net/2007/09/13/55/</link>
		<comments>http://blog.urdada.net/2007/09/13/55/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 00:32:35 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>
		<category><![CDATA[電腦資訊]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2007/09/13/55/</guid>
		<description><![CDATA[一早起來發現 MSN Messenger 7.5 無法登入了... 不升級就無法登入了！ 我還是比較喜歡用 7.5 的介面，尤其 Messenger Plus! 的自訂暱稱的功能只支援 7.5，而我又不想用 8.0 以後內建但殘廢的自訂暱稱功能... 而且我的聯絡人已經上百個了，懶得一個一個還要作轉換，所以能撐多久就撐多久... 要讓 7.5 免除升級困擾，請先把 MSN Messenger 關閉，然後開啟我的電腦，打開 C:\Program Files\MSN Messenger\ 資料夾，在 msnmsgr.exe上面按滑鼠右鍵選內容： 選擇「相容性」，然後把「以相容性模式執行這個程式」打勾，再從選單中選擇「Windows 2000」後按「確定」即可 然後執行 MSN Messenger 後，就可以正常登入了 這方法不曉得可以用多久就是了... 目前唯一的缺點是，系統列上面的圖示變得有點難看，只能裝作看不見了...]]></description>
			<content:encoded><![CDATA[<p>一早起來發現 MSN Messenger 7.5 無法登入了...</p>
<p> <img src="http://static.zooomr.com/images/3235028_495e6d7224_o.gif" /></p>
<p>不升級就無法登入了！</p>
<p>我還是比較喜歡用 7.5 的介面，尤其 <a href="http://www.msgpluslive.net/download/old/" target="_blank">Messenger Plus!</a> 的<strong>自訂暱稱</strong>的功能只支援 7.5，而我又不想用 8.0 以後內建但殘廢的自訂暱稱功能...  而且我的聯絡人已經上百個了，懶得一個一個還要作轉換，所以能撐多久就撐多久...</p>
<p>要讓 7.5 免除升級困擾，請先把 MSN Messenger 關閉，然後開啟我的電腦，打開 C:\Program Files\MSN Messenger\ 資料夾，在 <strong>msnmsgr.exe</strong>上面按滑鼠右鍵選內容：</p>
<p><img src="http://static.zooomr.com/images/3235027_70000a7702_o.gif" /></p>
<p>選擇「相容性」，然後把「以相容性模式執行這個程式」打勾，再從選單中選擇「Windows 2000」後按「確定」即可</p>
<p>然後執行 MSN Messenger 後，就可以正常登入了</p>
<p>這方法不曉得可以用多久就是了...</p>
<p>目前唯一的缺點是，系統列上面的圖示變得有點難看，只能裝作看不見了...</p>
<p><img src="http://static.zooomr.com/images/3235026_9f8692643c_m.jpg" height="32" width="240" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2007/09/13/55/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>svndumpfilter with wildcards support ?</title>
		<link>http://blog.urdada.net/2006/10/06/64/</link>
		<comments>http://blog.urdada.net/2006/10/06/64/#comments</comments>
		<pubDate>Fri, 06 Oct 2006 04:59:09 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2006/10/06/64/</guid>
		<description><![CDATA[Subversion 的 svnadmin obliterate 功能一直沒有實作出來，這實在是有點麻煩，尤其是當負責管理一個 repository 時，常常就會有人把 *.exe, *.obj, *.lib, *.a 統統給 commit 進去了.... 然後你就會發現整個 repository 長大的速度越來越快，就算事後用 svn delete 把它砍掉還是無濟於事，因為那已經成為無法抹滅的歷史了 雖然可以事先設定 svn:ignore 來解決，不過偶而還是會有漏網之魚，官方提供的解決方法是使用 svndumpfiler 來把不要的檔案徹底從歷史記憶中濾除 # svnadmin create REPOS2 # svnadmin dump REPOS1 &#124; svndumpfilter exclude XX.exe &#124; svnadmin load REPOS2 這方法當然沒有 svnadmin obliterate 好，不過也是目前狀況下不得不的作法 但是這個方法最大的問題在於 svndumpfilter 無法接受 wildcards (萬用字元)，也就是你無法指定 svndumpfilter exclude '*.exe' 所以，萬一不小心遇上了機車的狀況，你可能要一個一個把檔名找出來濾掉 XD [...]]]></description>
			<content:encoded><![CDATA[<p><a href=http://subversion.tigris.org/ target=_blank>Subversion</a> 的 <a href=http://subversion.tigris.org/faq.html#removal target=_blank>svnadmin obliterate</a> 功能一直沒有實作出來，這實在是有點麻煩，尤其是當負責管理一個 repository 時，常常就會有人把 *.exe, *.obj, *.lib, *.a 統統給 commit 進去了....</p>
<p>然後你就會發現整個 repository 長大的速度越來越快，就算事後用 svn delete 把它砍掉還是無濟於事，因為那已經成為無法抹滅的歷史了</p>
<p>雖然可以事先設定 svn:ignore 來解決，不過偶而還是會有漏網之魚，官方提供的<a href=http://subversion.tigris.org/faq.html#removal target=_blank>解決方法</a>是使用 svndumpfiler 來把不要的檔案徹底從歷史記憶中濾除<br />
<strong><br />
# svnadmin create REPOS2<br />
# svnadmin dump REPOS1 | svndumpfilter exclude XX.exe | svnadmin load REPOS2<br />
</strong><br />
這方法當然沒有 svnadmin obliterate 好，不過也是目前狀況下不得不的作法</p>
<p>但是這個方法最大的問題在於 svndumpfilter 無法接受 wildcards (萬用字元)，也就是你無法指定 svndumpfilter exclude '*.exe'</p>
<p>所以，萬一不小心遇上了機車的狀況，你可能要一個一個把檔名找出來濾掉 XD</p>
<p>所以不久前就想辦法修改了 svndumpfilter 的程式，把它加上直接濾除特定副檔名檔案的功能...</p>
<p><b>[patch to subversion/svndumpfilter/main.c]</b><br />
(the filename with leading dot will be matched against filename extension)</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">---</span> subversion<span style="color: #339933;">/</span>svndumpfilter<span style="color: #339933;">/</span>main.<span style="color: #202020;">c</span>.<span style="color: #202020;">orig</span>
<span style="color: #339933;">+++</span> subversion<span style="color: #339933;">/</span>svndumpfilter<span style="color: #339933;">/</span>main.<span style="color: #202020;">c</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">111</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">111</span><span style="color: #339933;">,</span><span style="color: #0000dd;">12</span> @@
       pfx_len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>pfx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>path_len <span style="color: #339933;">&lt;</span> pfx_len<span style="color: #009900;">&#41;</span>
         <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
<span style="color: #339933;">-</span>      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strncmp<span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> pfx<span style="color: #339933;">,</span> pfx_len<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+</span>      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> pfx<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'.'</span> <span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+</span>      <span style="color: #009900;">&#123;</span>
<span style="color: #339933;">+</span>        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> strncmp<span style="color: #009900;">&#40;</span> path<span style="color: #339933;">+</span>path_len<span style="color: #339933;">-</span>pfx_len<span style="color: #339933;">,</span> pfx<span style="color: #339933;">,</span> pfx_len <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+</span>          <span style="color: #b1b100;">return</span> TRUE<span style="color: #339933;">;</span>
<span style="color: #339933;">+</span>      <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">+</span>      <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strncmp <span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> pfx<span style="color: #339933;">,</span> pfx_len<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
         <span style="color: #b1b100;">return</span> TRUE<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">1257</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">1262</span><span style="color: #339933;">,</span><span style="color: #0000dd;">8</span> @@
             style<span style="color: #339933;">,</span> and absolute. <span style="color: #339933;">*/</span>
        SVN_INT_ERR<span style="color: #009900;">&#40;</span>svn_utf_cstring_to_utf8<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>prefix<span style="color: #339933;">,</span> os<span style="color: #339933;">-&gt;</span>argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> pool<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        prefix <span style="color: #339933;">=</span> svn_path_internal_style<span style="color: #009900;">&#40;</span>prefix<span style="color: #339933;">,</span> pool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">-</span>       prefix <span style="color: #339933;">=</span> svn_path_join<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #339933;">,</span> prefix<span style="color: #339933;">,</span> pool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">+</span>       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> prefix<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'.'</span> <span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+</span>          prefix <span style="color: #339933;">=</span> svn_path_join<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #339933;">,</span> prefix<span style="color: #339933;">,</span> pool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        APR_ARRAY_PUSH<span style="color: #009900;">&#40;</span>opt_state.<span style="color: #202020;">prefixes</span><span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> prefix<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>
這個 patch 有點投機取巧，因為我懶得真的去實作 wildcards，我需要的功能只要能濾除指定的副檔名就可以了...</p>
<p>所以這個 patch 把原來 svndumpfilter include/exclude 後面接的檔名參數作特殊判斷，只要第一字元是小數點，就當作要去 match 的副檔名，因此，要濾除 *.exe 只要這樣作就可以了:<br />
<strong><br />
# svnadmin create REPOS2<br />
# svnadmin dump REPOS1 | svndumpfilter exclude .exe | svnadmin load REPOS2<br />
</strong><br />
剛好看到前幾天也有人寫了個 <a href="http://www.nabble.com/-PATCH----svndumpfilter---add-wildcard-matchinv-t2362313.html"  target=_blank>PATCH</a> 讓 svndumpfilter 完全支援 wildcards... 不過我沒試過，相信不久的將來應該會被整合進正式版本中</p>
<p>當然最希望還是 svmadmin obliterate 能早日被支援，就不用這麼辛苦了</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2006/10/06/64/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在 FreeBSD 下安裝 MySQL 4.1 ...</title>
		<link>http://blog.urdada.net/2005/06/05/45/</link>
		<comments>http://blog.urdada.net/2005/06/05/45/#comments</comments>
		<pubDate>Sun, 05 Jun 2005 15:19:17 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2005/06/05/45/</guid>
		<description><![CDATA[在 FreeBSD 下面用 ports 安裝 MySQL 4.1 如果你只要用 UTF-8 的話就算了，但是如果還是有使用 BIG5 的話.. 安裝 make 的時候，記得要加上 WITH_CHARSET=big5 以下當作筆記，紀錄 MySQL database server / FreeBSD 的安裝流程： 安裝資料庫： cd /usr/ports/databases/mysql41-server/ make WITH_CHARSET=big5 install 接下來加入這一行在 /etc/rc.conf 裡面： mysql_enable="YES" 如果想指定不同的資料庫存放位置的話，可以在 /etc/rc.conf 內加上： mysql_dbdir="/home/mysql" 記得這個目錄要先建立，owner 及 group 都要是 mysql，然後就可以啟動 MySQL 了： /usr/local/etc/rc.d/mysql-server.sh start 再來要設定 root 密碼（假設密碼是 dada）： /usr/local/bin/mysqladmin -u root password 'dada' [...]]]></description>
			<content:encoded><![CDATA[<p><font face="Georgia">在 FreeBSD 下面用 ports 安裝 MySQL 4.1</font></p>
<p><font face="Georgia">如果你只要用 <span style="font-weight: bold">UTF-8</span> 的話就算了，但是如果還是有使用 <span style="font-family: courier new; font-weight: bold">BIG5</span> 的話..<br />
安裝 make 的時候，記得要加上 <strong>WITH_CHARSET=<span style="font-family: courier new">big5</span></strong></font></p>
<p><font face="Georgia">以下當作筆記，紀錄 MySQL database server / FreeBSD 的安裝流程：</font></p>
<p>安裝資料庫：</p>
<pre class="tiny">cd  /usr/ports/databases/mysql41-server/
make  <strong>WITH_CHARSET=big5</strong>  install</pre>
<p>接下來<font face="Georgia">加入這一行在 /etc/rc.conf 裡面：</font></p>
<p><font face="Georgia">mysql_enable="YES"</font></p>
<p><font face="Georgia">如果想指定不同的資料庫存放位置的話，可以在 /etc/rc.conf 內加上：</font></p>
<p><font face="Georgia">mysql_dbdir="/home/mysql"</font></p>
<p><font face="Georgia">記得這個目錄要先建立，owner 及 group 都要是 mysql，然後就可以啟動 MySQL 了：</font></p>
<p><font face="Georgia">/usr/local/etc/rc.d/mysql-server.sh   start</font></p>
<p><font face="Georgia">再來要設定 root 密碼（假設密碼是 dada）：</font></p>
<p><font face="Georgia">/usr/local/bin/mysqladmin   -u   root   password   <span class="000370410-09112004"> 'dada'</span></font></p>
<p><font face="Georgia"><span class="000370410-09112004">然後我們先進入 MySQL 的交談式介面，在命令列下執行：</span></font></p>
<p><font face="Georgia">/usr/local/bin/mysql   -u   root   -p</font></p>
<p><font face="Georgia"><span class="000370410-09112004"></span></font><br />
問密碼的時候就輸入您在前一步驟設定的密碼</p>
<p><font face="Georgia">接下來首要任務當然是讓 phpMyAdmin 能連線囉，</font>假設我們要為 phpMyAdmin 建立的一個連線帳號名稱為 giga  密碼為  virtual，在大於符號後面輸入：</p>
<p><font face="Georgia"><span class="000370410-09112004">GRANT   ALL   PRIVILEGES   ON   *.*   TO   '<strong>giga</strong>'@'<strong>localhost</strong>'</span></font></p>
<p><font face="Georgia"><span class="000370410-09112004">IDENTIFIED   BY   '<strong>virtual</strong>'   WITH   GRANT   OPTION;</span></font></p>
<p><font face="Georgia"><br />
這邊是假設你的 Web Server 跟 MySQL 在同一台機器上，如果不是的話，請把 <strong>localhost</strong> 改成 Web Server 的 hostname 或 IP<br />
</font><br />
完成後輸入 <font face="Georgia">exit</font> 可離開交談介面</p>
<p>然後到你的 <font face="Georgia">Web Server </font>上面，安裝 <font face="Georgia">phpMyAdmin</font>：</p>
<pre class="tiny">cd /usr/ports/databases/phpmyadmin
make install</pre>
<p>設定 phpMyAdmin：</p>
<p>vi  /usr/local/www/phpMyAdmin/config.inc.php</p>
<p>設定以下數值：</p>
<p>$cfg['Servers'][$i]['auth_type'] = '<strong>http</strong>'</p>
<p>如果你的 Web Server 跟 MySQL 不在同一台機器上，請把下面這一行的 <strong>localhost</strong> 改掉：</p>
<p>$cfg['Servers'][$i]['host'] = '<strong>localhost</strong>'</p>
<p>接下來改 httpd.conf   (以 apache2 為例)：</p>
<p>vi   /usr/local/etc/apache2/httpd.conf</p>
<p>加入以下幾行</p>
<pre class="tiny">Alias      /mysql/       "/usr/local/www/phpMyAdmin"

&lt;Directory    "/usr/local/www/phpMyAdmin"&gt;
Options  MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 192.168.0.1
Allow from 192.168.0.2
&lt;/Directory&gt;</pre>
<p>以上是設定只允許兩個 IP 連線，請依據你的需求更改，最後重新啟動 Web Server：</p>
<pre class="tiny">/usr/local/etc/rc.d/apache2.sh   stop
/usr/ocal/etc/rc.d/apache2.sh   start</pre>
<p>然後就可以用瀏覽器連到：</p>
<p>http://your.web.server/mysql/</p>
<p>輸入之前建立給 phpMyAdmin 用的帳號密碼就應該可以進去了..</p>
<p>成功進去後就可以開始做你想做的事了！</p>
<p>上面步驟以上所建立給 phpMyAdmin 用的帳號，會擁有全部的權限，建議可以做一些調整，拿掉不需要的部分，這樣的調整可以在 phpMyAdmin 的<strong>權限頁面</strong>中直接完成</p>
<p>另外，如果你有兩台 MySQL Server，想要設定 MySQL 的 Replication 功能，<br />
請參考之前寫的另外一篇文章「<a href="http://blog.urdada.net/2005/03/25/29/" target="_blank">Replication of MySQL database</a>」</p>
<p>另外，如果要用 PHP 連接 MySQL 4.1，使用 <span style="font-family: courier new; font-weight: bold">BIG5</span> 編碼的資料庫，記得在連線後執行：</p>
<pre class="tiny"><strong>$charset = mysql_query( "SET  NAMES  'big5'", $dblink);</strong></pre>
<p>或者直接在 my.cnf 中加入底下這行（如果你確定所有的 DB 都是使用 BIG5 編碼的話）：</p>
<pre class="tiny">init_connect='SET  NAMES  big5'</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2005/06/05/45/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一個顯示農曆及世界時間的好工具!</title>
		<link>http://blog.urdada.net/2005/04/04/19/</link>
		<comments>http://blog.urdada.net/2005/04/04/19/#comments</comments>
		<pubDate>Mon, 04 Apr 2005 14:10:48 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2005/04/04/19/</guid>
		<description><![CDATA[Microsoft Chinese Date &#38; Time Utility 發現微軟提供了一個顯示日期(農曆/國曆/世界時間)的小工具... 蠻好用的，可以顯示農曆及自選四個世界各地時間，還會考慮日光節約時間 下載網址: http://www.microsoft.com/globaldev/outreach/dnloads/ICalClkSetup.mspx 2009/04/10 補充: 微軟好像拿掉這個程式了，請搜尋 "Microsoft Chinese Date Time" 去找網路上的下載點]]></description>
			<content:encoded><![CDATA[<p><font face="Tahoma" size="4">Microsoft Chinese Date &amp; Time  Utility<br />
</font><br />
發現微軟提供了一個顯示日期(農曆/國曆/世界時間)的小工具... 蠻好用的，可以顯示農曆及自選四個世界各地時間，還會考慮日光節約時間</p>
<p>下載網址:  <a href="http://www.microsoft.com/globaldev/outreach/dnloads/ICalClkSetup.mspx">http://www.microsoft.com/globaldev/outreach/dnloads/ICalClkSetup.mspx</a><br />
<img src="http://static.zooomr.com/images/2744290_f0907fadcc.jpg" height="280" width="500" /></p>
<p>2009/04/10 補充:</p>
<p>微軟好像拿掉這個程式了，請搜尋 "<a href="http://www.google.com.tw/search?q=Microsoft+Chinese+Date+%26+Time" target=_blank>Microsoft Chinese Date Time"</a> 去找網路上的下載點</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2005/04/04/19/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replication of MySQL database</title>
		<link>http://blog.urdada.net/2005/03/25/29/</link>
		<comments>http://blog.urdada.net/2005/03/25/29/#comments</comments>
		<pubDate>Fri, 25 Mar 2005 07:55:49 +0000</pubDate>
		<dc:creator>dada</dc:creator>
				<category><![CDATA[軟體]]></category>

		<guid isPermaLink="false">http://blog.urdada.net/2005/03/25/29/</guid>
		<description><![CDATA[MySQL database 自 3.23.15 版以後就支援 Replication 功能，使用 Replication 可以拿來當備援及作流量分散 其實設定十分簡單，整理設定方法說明如下: 假設 Master 是 A (192.168.100.1) ， Slave 是 B (192.168.100.2) ，要複製的 database 為 hello [步驟一] A 機器上面.. 首先編輯 /etc/my.cnf，加入下列幾行 [mysqld] server-id=1 log-bin binlog-do-db=hello log-bin 是告訴 MySQL server 把 Binary Log 機制啟動，把對 hello 這個 DB 的所有更動 LOG 紀錄下來，然後才有辦法讓 Slave 過來同步 接下來重新啟動 MySQL server [步驟二] 使用 phpMyAdmin [...]]]></description>
			<content:encoded><![CDATA[<p><span class="346281508-04112004"><font face="Georgia">MySQL database 自 <font face="新細明體">3.23.15 版以後就</font>支援 Replication 功能，</font></span><span class="346281508-04112004"><font face="Georgia">使用 Replication  可以拿來當備援及作流量分散</font></span></p>
<p><font face="Georgia">其實設定十分簡單，整理設定方法說明如下<span class="346281508-04112004">:</span></font></p>
<p><span class="346281508-04112004"><font face="Georgia">假設 Master 是 A (<font color="#0000ff">192.168.100.1</font>)  ，  Slave 是 B (<font color="#0000ff">192.168.100.2</font>) ，要複製的 database 為 <font color="#0000ff"><strong>hello</strong></font></font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font face="Georgia"><strong>[步驟一]</strong> A  機器上面..</font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font face="Georgia">首先編輯  /etc/my.cnf，加入下列幾行</font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font color="#000080"><font face="Georgia"><strong>[mysqld]<br />
server-id=1<br />
log-bin</strong><span class="484011514-20112004"><font color="#000000"> </font></span></font></font></span></p>
<p><span class="346281508-04112004"><font size="-0"><font face="Georgia"><span class="484011514-20112004"><font color="#000080"><strong>binlog-do-db=<font color="#0000ff">hello</font></strong> </font></span></font></font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font face="Georgia">log-bin 是告訴 MySQL server  把 Binary Log 機制啟動，把對<span class="484011514-20112004">  hello 這個 DB 的</span>所有更動  LOG 紀錄下來，然後才有辦法讓 Slave  過來同步</font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font face="Georgia">接下來重新啟動 MySQL  server</font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia"><strong>[步驟二</strong></font></span></span><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia"><strong>]</strong></font></span></span></p>
<p><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia">使用 phpMyAdmin 連接到  A，增加一個連線帳號，要擁有 replication 的權限，記得要設定正確的來源位址  </font></span><span class="346281508-04112004"><font face="Georgia">(假設是帳號: <font color="#0000ff">replication</font>  密碼: <font color="#0000ff">simba</font>)</font></span></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia"><strong>[步驟三]</strong></font></span></span></p>
<p><span class="346281508-04112004"><font face="Georgia">把 A 機器的 /home/mysql/ (或是  /var/db/)  tar 下來，並於 B 機器上面回存，</font></span></p>
<p><span class="346281508-04112004"><font face="Georgia">這個步驟是要讓一開始 B 擁有和 A  相同的資料，後續的複製工作才有辦法進行</font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia"><strong>[步驟四]</strong></font></span></span></span></p>
<p><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia">B  機器上面..</font></span></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font face="Georgia">編輯  /etc/my.cnf，加入下列幾行</font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font color="#000080" face="Georgia"><strong>[mysqld]<br />
master-host=<font color="#0000ff">192.168.100.1</font><br />
master-user=<font color="#0000ff">replication</font><br />
master-password=<font color="#0000ff">simba<br />
</font>master-port=3306<br />
server-id=2<br />
master-connect-retry=60<br />
replicate-do-db=<font color="#0000ff">hello<br />
</font>log-slave-updates</strong></font></span></p>
<p><span class="346281508-04112004"></span></p>
<p><span class="346281508-04112004"><font face="Georgia"><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia"><strong>[步驟五]</strong></font></span></span></font></span></p>
<p><font face="Georgia">重新啟動<span class="346281508-04112004"> B 上面的 MySQL  database</span></font></p>
<p><font face="Georgia"><span class="346281508-04112004"><span class="346281508-04112004"><font face="Georgia"><strong>[步驟六]</strong></font></span></span></font></p>
<p><font face="Georgia">測試在<span class="346281508-04112004"> A 上面的 hello database  內建立一個 table，然後去 B 看看是否有相同的 table 出現</span></font></p>
<p><font face="Georgia"><span class="346281508-04112004"></span></font></p>
<p><font face="Georgia"><span class="346281508-04112004"><span class="484011514-20112004"><strong>HINT:</strong> 若有多個 DB 要做 Replication 的話，分別指定多行  <span class="346281508-04112004"><font face="Georgia"><span class="484011514-20112004"><font color="#000080"><strong>binlog-do-db  </strong></font></span></font></span></span></span></font><span class="346281508-04112004"><font face="Georgia">及<span class="484011514-20112004"> <strong><font color="#000080">replicate-do-db  </font></strong></span></font></span><span class="346281508-04112004"><font face="Georgia"><span class="484011514-20112004">即可<br />
</span></font></span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.urdada.net/2005/03/25/29/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

