2014年9月2日 星期二

[Linux] 透過 alias 與 virtual 機制建立 no-reply @ hostname 帳號 @ Postfix 2.9.6, Ubuntu 12.04

新增一筆 alias 用來導向 /dev/null

$ grep alias_maps /etc/postfix/main.cf
alias_maps = hash:/etc/aliase
$ sudo vim /etc/aliases
...
devnull: /dev/null
...


採用 virtual account 新增 no-reply 帳號:

$ grep virtual_alias_maps /etc/postfix/main.cf
$ sudo vim /etc/postfix/main.cf
virtual_alias_maps = hash:/etc/postfix/virtual

$ sudo vim /etc/postfix/virtual
no-reply@hostname devnull

$ sudo newaliases
$ sudo postmap /etc/postfix/virtual
$ sudo postfix reload
postfix/postfix-script: refreshing the Postfix mail system


至於測試方式,就直接連他寄信看看:

$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 hostname ESMTP Postfix (Ubuntu)
HELO localhost
250 hostname
mail from:<root@localhost>
250 2.1.0 Ok
rcpt to:<no-reply@hostname>
250 2.1.0 Ok
quit
221 2.0.0 Bye
Connection closed by foreign host.


如果出現 451 4.3.0 <no-reply@hostname>: Temporary lookup failure ,請記得翻一下 /var/log/mail.err ,若是單純 error: open database /etc/postfix/virtual.db: No such file or directory 問題,記得跑一下 sudo postmap /etc/postfix/virtual 即可。

2014年8月28日 星期四

[Python] Google App Engines 發送 POST 與 JSON-RPC

初始資料:

url = 'http://server/cgi'
data = {
"arg1" : "val1",
"arg2" : "val2"
}


發送 POST:

import urllib
from google.appengine.api import urlfetch
post_data = urllib.urlencode(data)
response = urlfetch.fetch(url=url,payload=post_data,method=urlfetch.POST,headers={'Content-Type': 'application/x-www-form-urlencoded'})


發送 JSONRPC:

import urllib2
headers = {
"Content-Type": "application/json"
}
post_data = json.dumps(data)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req).read()

2014年8月27日 星期三

[PHP] Mantis Plugin 開發筆記 @ Mantis 1.2.17

由於公司管理者熟悉 Mantis 系統,最近挑了 Mantis 來做類似 Customer Relationship Management (CRM) 服務,接著很容易碰到 User Group 的需求,這是在系統本身不存在的功能。

在網路上找了許久,有發現 User Group 相關的 Plugin,但是拿出來搭配最新版 Mantis 1.2.17 時,出現很多 Link 失效、或是某些表單送出時,導向回來失敗等。由於 trace/fix 完就等於把整個 plugin 做完了,就順便把 Mantis Plugin 開發筆記起來 Orz

首先,在 Mantis 架構下,有提供 Plugin 開發機制,提供在系統任何一個端點加入 Event Notification 架構,透過這個 notification 導入 Plugin 程式碼,以 User Group 來說,就是管理者在編輯使用者帳號時,希望也有張表可以查看目前使用者歸屬的 User Group Management,以及簡易的編輯、刪除等。

其中 Mantis Event 架構可以查詢:mantis/core/event_api.php,而 Mantis Plugin 架構可參考:mantis/core/plugin_api.php。開發 Mantis Plugin 文件,請參考這份:Building a Plugin,看完大概也了解了。

整體流程:
  1. 寫個 class ExamplePlugin extends MantisPlugin 
  2. 定義 plugin 需要的 db schema
  3. 綁定 event 串接自己定義的 function
其他心得:
  • 若 plugin db schema 想要變更時,除了刪除既定存在的外,還需要去刪除 mantis_config_table 裡頭的記錄,例如刪掉 config_id 等價於自己 plugin 名稱才行。如此一來,plugin 重新安裝時,才會重新建立對應的 table

2014年8月25日 星期一

[PHP] Mantis Email Notification Settings @ Ubuntu 12.04

在 Ubuntu 12.04 透過 apt-get 安裝後,配置好系統管理後,又手動把它生成 Mantis 1.2.17 了。預設 Mantis 是有啟動 Email Notification,包含新增帳號後,還要由對方 email 去設定密碼等。對於 Email Notification 的設定,如事件通知的寄信者資訊等,都是直接更改 /path/mantis/config_inc.php。

可以參考 http://www.mantisbt.org/manual/admin.config.email.htmlhttp://www.mantisbt.org/manual/admin.customize.email.html,簡易筆記:

//$g_enable_email_notification = OFF;
$g_mail_receive_own = OFF;
$g_default_notify_flags = array(
'reporter' => ON,
'handler' => ON,
'monitor' => ON,
'bugnotes' => ON,
'threshold_min' => NOBODY,
'threshold_max' => NOBODY
);

//
// Select the method to mail by: PHPMAILER_METHOD_MAIL for use of mail() function, PHPMAILER_METHOD_SENDMAIL for sendmail (or postfix), PHPMAILER_METHOD_SMTP for SMTP. Default is PHPMAILER_METHOD_MAIL.
//
$g_phpMailer_method = PHPMAILER_METHOD_MAIL;
$g_smtp_host = 'localhost';
$g_smtp_username = '';
$g_smtp_password = '';
$g_administrator_email = 'admin@example.com';
$g_from_email = 'noreply@example.com';
$g_from_name = 'Mantis Bug Tracker';

2014年8月24日 星期日

iOS 開發筆記 - UICollectionView resize after device rotation

最近在把玩 UICollectionView 並著手處理 resize 的時機點,經 StackOverflow - Change UICollectionViewCell size on different device orientations 的討論,純 coding without storyboard 時,需處理兩件事:

  • - (CGSize)collectionView:layout:sizeForItemAtIndexPath:
  • - (void)didRotateFromInterfaceOrientation:

就像在 UITableViewController 時,告訴 ViewController 這個 UITableViewCell 到底有多高,只是在 UICollectionViewCell 時,還能定義有多寬;在 didRotateFromInterfaceOrientation 事件中,則是告訴 UIViewController 更新畫面。

只是單純上述兩者並無法改變已經存在的 UICollectionViewCell ,對於已經存在的,必須強制處理,簡言之,需要再多幾件事:

  • 在 - (void)didRotateFromInterfaceOrientation: 時,請記得重新定義 UICollectionView frame 資訊,並且使用 [yourCollectionView reloadData] 的方式重繪資料
  • 在 - (UICollectionViewCell *)collectionView:cellForItemAtIndexPath: 中,若每一個 UICollectionViewCell 並非有規則的,則需要動態偵測並重新設定 frame 資訊
如此一來,就能達到 auto resize 的效果了 Orz  若沒這麼龜毛,大概用一下 Storyboard 就解掉了 XD