Mantis Mail Gateway (perl script)

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: “|/usr/local/bin/mantis-mail-gateway.pl   PROJECT   REPORTER”

and then run newaliases.

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.

Note that this script does not understand MIME multipart encoding and may have problems on mail contents besides plain-ASCII encoding.

You are welcome to add more features.

mantis-mail-gateway.pl: (can be downloaded here)

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
#!/usr/bin/perl
 
# mantis-mail-gateway.pl
 
# Mantis Mail Gateway
# Shen Cheng-Da (cdsheen AT gmail.com)
# require DBI to connect MySQL database
# http://blog.urdada.net/2008/11/11/95/
 
use DBI;
use POSIX qw(strftime);
 
my $db_host    = 'localhost';
my $db_name    = 'mantis';
my $db_user    = 'monitor';
my $db_pass    = 'monitorpass';
 
my $debug      = 0;
 
my $db = "dbi:mysql:dbname=${db_name};host=${db_host}";
 
die "Usage: $0 [project-name] [reporter]\n" unless @ARGV > 1;
 
my $project_name  = $ARGV[0];
my $reporter_name = $ARGV[1];
 
my $dbh;
my $sql;
my $sth;
my $project  = -1;
my $reporter = -1;
 
$dbh = DBI->connect($db, $db_user, $db_pass)
        || die 'ERROR: '.$dbh->errstr;
 
$sql = "SELECT id,name FROM mantis_project_table
        WHERE name LIKE '$project_name'";
 
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute() || die 'ERROR: '.$dbh->errstr;
while( @data = $sth->fetchrow_array() ) {
        $project = $data[0];
}
$sth->finish;
 
die "ERROR: project \`$project_name' does not exist\n" unless $project > 0;
 
print "project: $project_name ($project)\n" if $debug;
 
$sql = "SELECT id,username FROM mantis_user_table
        WHERE username = '$reporter_name'";
 
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute() || die 'ERROR: '.$dbh->errstr;
while( @data = $sth->fetchrow_array() ) {
        $reporter = $data[0];
}
$sth->finish;
 
die "ERROR: user \`$reporter_name' does not exist\n" unless $reporter > 0;
 
print "reporter: $reporter_name ($reporter)\n" if $debug;
 
my $subject = '';
my $content = '';
 
while(<STDIN>) {
        s/\s+$//;
        last if $_ eq '';
        $subject = $1 if /^Subject: (.+)$/;
}
while(<STDIN>) {
        $content .= $_;
}
 
$sql = 'INSERT INTO mantis_bug_text_table (description) VALUES (?)';
 
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute($content) || die 'ERROR: '.$dbh->errstr;
$sth->finish;
 
my $textid = $dbh->{ q{mysql_insertid} };
 
print "bug text id: $textid\n" if $debug;
 
$sql = 'INSERT INTO mantis_bug_table
                ( project_id, reporter_id,
                  date_submitted, last_updated,
                  bug_text_id, summary )
        VALUES (?,?,?,?,?,?)';
 
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime(time));
 
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute($project, $reporter, $now, $now, $textid, $subject)
        || die 'ERROR: '.$dbh->errstr;
$sth->finish;
 
$dbh->disconnect;

嘟嘟房市區臨時停車台北基隆站點地圖

在台北開車是個麻煩,尤其是要找停車位的時候…
這時候查看一下你手邊的信用卡,也許有一些優惠可以用:)

這篇整理的是首開與各大信用卡合作的 中興嘟嘟房停車網

中興嘟嘟房在台北縣市很多地方的停車場都很方便..

例如世貿站就在台北國際會議中心地下室:

除此之外,永康夜市基隆廟口站 也是個好地方 🙂

嘟嘟房各站點的位置以及合作的銀行可以從嘟嘟房的網站上面找到:
http://www.dodohome.com.tw/menu09/actparktable_big.asp

不過嘟嘟房的網站實在不好查,網站有點慢而且查詢層級有點亂.. orz

因此颱風假在家無聊,就把嘟嘟房台北&基隆可以臨時停車的站點匯入了 Google Maps
產生了一份「我的地圖」,方便直接查詢可以停車的站點,如下所示:

有興趣的人可以直接點選 這邊 直接連結到這份地圖

不過實際的位置狀況以及哪些銀行間可以使用還是需以嘟嘟房原始網站的說明為準

然後重點來了,到底哪些卡才能使用嘟嘟房的停車優惠呢?

其實自從卡債風暴開始,各銀行已經已經大幅縮減信用卡的免費停車優惠了,
以嘟嘟房為例,很多信用卡已經改成需要扣點數或者符合一定消費金額才能免費停車了

建議選擇不需要額外扣點數也不需要扣錢的卡,主要是需要扣點數的算起來都不太划算
更詳細即時的資訊請參考原始嘟嘟房網站上 卡友專區 的說明

本文簡短網址為: http://tinyurl.com/dodohome

Bye Bye ISP – 和信超媒體(GigaMedia)賣掉了 ISP 部門

和信超媒體的母公司 GigaMedia 今天宣佈以 2000 萬美元將 ISP 部門 (包含和網寬頻 KBT) 賣給中嘉網路,如果接下來兩年出售的部門達到業績目標,還可以另外再取得 500 萬美元

相關新聞:

2000年進入 和信超媒體 工作時,當時公司最主要的業務就是 Cable Modem 寬頻上網,但受限於許多先天及後天因素,發展得並沒有很好。2001年開始進入 ADSL 的市場,但也因為中華電信獨占電路的關係,競爭還是處於不利地位。2006年 將 ADSL 部份賣給了現在的天空傳媒 (原Webs-TV) 之後,GigaMedia 還是持續經營著 Cable Modem 業務(和信超媒體)以及企業專線市場(和網寬頻)

中嘉網路原是和信關係企業,但在 安博凱MBK 入主之後,外資目前也佔了很大一部份股權。中嘉系統下的有線電視業者原本的 Cable Modem 寬頻上網服務就是由和信超媒體提供的,但是後來因為種種因素,中嘉還是推出了自己的 Cable Modem 品牌 (互動BB),與和信超媒體 GIGA 品牌的 Cable Modem 變成競爭又合作的奇妙關係…

GigaMedia 事實上近幾年已經把精力幾乎都投注在線上遊戲的發展,ISP 網路部門的出售也是遲早的事。 ISP 部門尤其是企業專線市場與有線電視業者整合後,應該是能夠有更好的發展的!

在新聞發佈的這時候,我正在上海出差,看到這則新聞其實是有點百感交集,當初會加入這個公司,也是對 ISP 所能夠提供的服務有濃厚的興趣。從整套的寬頻網路管理系統 (內部稱 SIMBA)、ADSL 服務、網路相簿WebAMP,都留下了我許多參與的心血…

世事是很難預料的,沒想到我最終還是回到網路遊戲這一塊,我研究所兩年的主要研究 😉

無論如何,還是祝福 ISP 部門的同事們!

~ 希望我們的努力能讓你們手中的 option 價值更高一點 😛

延伸閱讀:

BloggerAds 的收益到達1000元了

大約是2007年11月底抱著好玩的心裡加入 BloggerAds 的,主要使用的位置是放在我的 Blog 右方側欄的廣告,我的 Blog 流量並不多,但根據報表,平均每天還是約有200~300次的廣告曝光,大約是新台幣5~6元的收入。經過9個月的累積之後,收益終於到達 BloggerAds 訂的收益匯款門檻1000元了 🙂

相對於 Google 的 AdSense,國內廠商 BloggerAds 的好處是只要有曝光就會有收入,一般來講,收益應該會比 AdSense 好很多..

BloggerAds 除了部落格的廣告外,另外還可以經由推薦連結及黃金寫手獲取收益,但對於一般的部落客而言,放廣告還是最簡單的方式

BloggerAds 的推薦連結只能讓推薦者分享30天內的收益,而且還只有30%,實在不夠吸引人,應該適度增加回饋的比例與時間,也許再搞個 老鼠會 多層次傳銷 的模式更能吸引人.. 不過國內廣告市場長期被G/Y等業者壟斷,不知道 BloggerAds 有沒有足夠的廣告來源來支撐營運就是了..

有興趣的人可以玩玩看,我半年才能吃一次大餐,也許你每個禮拜都能吃一次大餐 🙄

部落格的 PageRank 升到 5 了

我的第一篇 BLOG 是三年多前,2005/03/04 發表無名小站,那時候無名小站剛剛商業化脫離交通大學,然後經過一番波折搬入了 GIGA 機房…

一年前 (2007/07/26) 把 BLOG 從無名小站 搬出來 到自己用 WordPress 架的這個站台

其實這一年來實在太忙,寫文章也是斷斷續續的,心血來潮就寫一篇,忙的時候停筆一兩個月也是常有的事,從開始寫 Blog 到現在也只累積了不到百篇文章。這幾天到上海出差,下班後回到飯店,想說連上自己的 Blog 看看有沒有被「和諧」掉(還好沒有),突然發現 PageRank 升到 5 了。今年三月的時候,PageRank 還是只有 3 而已,大約四月底升到 4,然後到現在八月中左右就升到 5 了.. 不曉得 Google 怎麼算的

不過雖然 PageRank 升到 5 了,但是我發現原來在無名小站的舊 Blog 每日訪問數都還是比新的這邊高,而且其實舊的 Blog 內的文章大部分已經被我拿掉了,但是每日訪問數還是較多。更重要的是,從 Bloglines 的訂閱數目來看,新的 Blog 還是沒有超越原來我無名小站 Blog 的訂閱數 (其實都很少 XD)

但是呢,在大陸這邊,訪問我新的 Blog 是沒問題的,而無名小站的 Blog 卻被和諧掉了… 必須要 VPN 連回台灣才看得到 🙄

不過大概是大陸舉辦奧運的關係,我三月到上海出差時 FeedBurner 的 RSS Feed 是無法直接存取的,但是目前卻是一切正常的樣子,我想這或許也是大陸舉辦奧運的好處之一吧 😕

只是不知道奧運過了會不會恢復原狀就是了 XD

Subversion pre-commit hook

很多人寫完程式要 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
 
# pre-commit hook to reject commit with empty log
# remember to chmod 755 on this file
 
die "Usage: $0 [REPOS] [TXN]\n" unless @ARGV > 1;
 
$REPOS=$ARGV[0];
$TXN=$ARGV[1];
 
$svnlook = '/usr/local/bin/svnlook';
 
chomp($author=`$svnlook author -t $TXN $REPOS`);
chomp($log=`$svnlook log -t $TXN $REPOS`);
 
if( $log eq '' || $log =~ /^\W+$/ ) {
    die "\nHello, $author. Empty commit log is not permitted!\n";
}
 
exit(0);

除此之外,對於 pre-commit hook,我還加上了檢查不允許跨 branch 的 commit,
因為一旦有了跨 branch 的 commit,會使得未來需要作 merge 的時候遇到許多麻煩

例如常用的 repository 結構如下:

/trunk/
/branches/helloworld-1.0/
/branches/helloworld-1.1/

要防止使用者同時對兩個以上的 branch (包含 main trunk) 作 commit,
可以把下面這一段程式再加進去 pre-commit 的 hook 中

[Subversion pre-commit hook to reject cross-branch commit]

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
#!/usr/bin/perl
 
# pre-commit hook to reject empty commit log and cross-branch commit
# remember to chmod 755 on this file
 
die "Usage: $0 [REPOS] [TXN]\n" unless @ARGV > 1;
 
$REPOS=$ARGV[0];
$TXN=$ARGV[1];
 
$svnlook = '/usr/local/bin/svnlook';
 
chomp($author=`$svnlook author -t $TXN $REPOS`);
chomp($log=`$svnlook log -t $TXN $REPOS`);
 
if( $log eq '' || $log =~ /^\W+$/ ) {
    die "\nHello, $author. Empty commit log is not permitted!\n";
}
 
open(DIRS,"$svnlook dirs-changed -t $TXN $REPOS|");
while(<DIRS>) {
    if( /^(trunk)\// ) {
        $branches{$1}++;
    }
    elsif( /^branches\/([^\/]+)/ ) {
         $branches{$1}++;
    }
}
close(DIRS);
 
$c = %branches;
 
if( $c > 1 ) {
    die "\nHello, $author. You can't commit to $c branches at the same time!\n";
}
 
exit(0);