Tuesday, January 18, 2011

Roundcube auto-reply plugin: Vacation

Evnironment:
OS: FreeBSD 8.1-RELEASE-p1
roundcube: 0.4.2
vacation: 1.9.9
apache: 1.3.42
php: 5.3.3_2
  1. 前提: roundcube已正常運作。也就是apache, php等基本配件已經處理好了。
  2. 下載Vacation plugin,並解壓縮至/roundcube/plugins/內
    (/usr/local/www/roundcube/plugins/)
  3. 先讀過README與INSTALL兩個檔案,並決定要用哪種driver讓auto-reply的功能運作(這邊會以SSHFTP為例)。
  4. 啟用plugin: 修改/usr/local/www/roundcube/config/main.inc.php檔
    找到$rcmail_config['plugins'] 這行,並加入'vacation'

    // List of active plugins (in plugins/ directory)
    $rcmail_config['plugins'] = array('other_plugins','vacation');

  5. 修改/vacation/config.ini檔,指定driver

    [default]
    driver = "sshftp"
    subject = "Default subject"
    body = "default.txt"
    server = host_name

  6. 修改/vacation/config.ini檔的擁有者 與 執行權限
    # chown $apache_user config.ini
    # chmod 0400 confing.ini

    到目前為止,2-6點是INSTALL.txt內也有列出的幾項工作。
    照著做完之後,在roundcube設定內,就可以看見"休假"的頁籤了。

  7. 不過你可能會遇到點下"休假"的頁籤後畫面就錯誤的狀況,這時候去檢查/roundcube/logs/errors時,可能會有以下錯誤訊息:
    PHP Fatal error: 
    Call to undefined function ssh2_connect() in …/roundcube/plugins/vacation/lib/sshftp.class.php on line ...
  8. 因為要使用PHP的SSH2系列功能時,系統需要有OpenSSL, libssh2, pecl-ssh2三個套件,可從ports安裝,libssh2與pecl-ssh2的位置分別在:
    libssh2: /usr/ports/security/libssh2
    pecl-ssh2:  /usr/ports/security/pecl-ssh2
    分別進入這兩個資料夾,設定並安裝:
    # make config install clean
    完成安裝後,可用phpinfo();網頁檢視SSH模組是否已支援。
    或是檢視/usr/local/etc/php/extensions.ini檔案內是否有此行:
    extension=ssh2.so
  9. 修改/etc/ssh/sshd_config檔
    必須啟用sshd的password authentication方法(sshftp.class.php內的叫用才會成功),找到PasswordAuthentication關進字並修改:

    # Change to yes to enable built-in password authentication.
    PasswordAuthentication yes

  10. 重新啟動sshd
    # /etc/rc.d/sshd restart
  11. 重新啟動apache
    # cd /usr/local/etc/rc.d
    ./apache restart
  12. try it!!

ref:

  1. [PHP] Secure Shell2
  2. [freeBSD] SSHD Man page
Friday, December 03, 2010

修改SharePoint網站之清單"建立者"欄位

Environment
Server: Win2003 + SharePoint Service 3

需求: 當透過WSS UI的「儲存清單為範本」+「包括內容」選項將清單匯出後,再匯入時,所有清單項目的「建立者」欄位都會變成匯入人的名字。如果資訊人員佛心來的想替使用者改掉... 是可以做的,寫程式囉。

利用Microsoft提供的SharePoint API: Microsoft.SharePoint.dll。這支dll可以在SharePoint server上的\\Computer_Name\Drive$\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI 內找到。

但是,如果你覺得把他複製出來到自己本機開發那就錯了。這麼做應該會遇到「無法載入檔案或組件或其相依性的其中之一」的錯誤,就像這篇SharePoint Forums上的討論,請直接在裝有SharePoint Service的server上做開發.. 如果有測試機器是再好不過的,就可以參考這篇文章(Can we update the values of “Created By”, "Modified By” columns in SharePoint lists?)直接在Visual Studio上參考上述組件做開發。

如果你正好沒有測試環境,而且也無法在production上安裝VisualStudio這麼龐大的怪物的話,就參考這篇文章(Updating the “Created By” and "Modified By” Columns in SharePoint lists using POWERSHELL)。沒錯! 就是用POWERSHELL。這也是我用的方法。

script:

   1:  # Get the SharePoint Assembly 


   2:  # You will need to run this on the SharePoint Server


   3:  [Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 


   4:   


   5:  # create a new object called $SPSite


   6:  # Make sure you have the last “/” in the url on the site 


   7:  # allow $SPWeb to be the OpenWeb from the site


   8:  $SPSite = New-Object Microsoft.SharePoint.SPSite("http://server-name/")


   9:  $SPWeb = $SPSite.OpenWeb() 


  10:   


  11:  # Get the list ModifyCreatedBy 


  12:  $SPList = $SPWeb.Lists["ListName"] 


  13:   


  14:  # Get the Collection of the List Items


  15:  $SPListItemCollection = $SPList.Items 


  16:   


  17:  # iterate the Collection


  18:  foreach ($ListItem in $SPListItemCollection) 


  19:  {


  20:   


  21:    # The user in this case was UserA with id of 8 from the SPWeb users 


  22:    $SPFieldUserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($SPWeb,8,"UserA") 


  23:   


  24:    $ListItem["Author"] = $SPFieldUserValue


  25:   


  26:    # Note: Editor will be the account that you are running the Powershell under unless you update Editor as well 


  27:    # ListItem["Editor"] = $SPFieldUserValue


  28:   


  29:    $ListItem.Update() 


  30:  } 


  31:   


  32:  $SPWeb.Update() 


  33:   


  34:  # Still TODO Disposes, Error Checking, Change to take Parameters, etc


  35:   



 
上面的script是改了整個指定清單的建立者欄位,如果你還需要先判斷是那些文件,可以參考一下MSDN Library看看SPListItem還有哪些properities可以用。若是powershell語法不熟的話(尤其他又喜歡跟一般語法同.... 特別是比較運算子...),請參考reference#4, #5,或自行google。



嗯.. 大概就以上資訊,即可作業!!



Ref:




  1. [SharePoint Forums] Could not find Microsoft.SharePoint.Library.dll


  2. [MSDN Blog] Can we update the values of “Created By”, "Modified By” columns in SharePoint lists?


  3. [MSDN Blog] Updating the “Created By” and "Modified By” Columns in SharePoint lists using POWERSHELL


  4. [TechNet 技術文件庫] Running Windows PowerShell Scripts


  5. [賴榮樞的軟體資訊誌] scripting_PowerShell tag


  6. [MSDN Library] Microsoft.SharePoint Namespace

Monday, November 15, 2010

poppassd + roundcube on FreeBSD

最近因為被roundcube的美貌所吸引,所以正在考慮是否拿它來當webmail。roundcube最大的特點就是: 相當美+相當陽春。

紀錄一下poppassd跟roundcube怎麼搭配,讓使用者可以在web介面上直接改密碼,而不需要登入freebsd系統.. roundcube的安裝部分就不介紹了,直接來poppassd的部分。

Environment:
OS: FreeBSD 8.1-RELEASE-p1
roundcube: 0.4.2
poppassd: 4.0_3

STEP1: Install poppassd

# cd /usr/ports/mail/poppassd/
# make install clean

By default, you can find the binary in /usr/local/libexec

STEP2: Startup setting

# man poppassd

Modify /etc/inetd.conf AND /etc/services AND /etc/syslog.conf as describe in the man page.

STEP3: Auto-start inetd when reboot
Modify /etc/rc.conf AND add:

# inetd

inetd_enable="YES"

STEP4: restart inetd

# /etc/rc.d/inetd restart

 

STEP5: Config roundcube plugin
Modify /usr/local/www/roundcube/plugins/password/config.inc.php

// Select a driver to use, see README for more driver name

$rcmail_config['password_driver'] = 'poppassd';

STEP6: Add roundcube plugin
Modify /usr/local/www/roundcube/config/main.inc.php

// List of active plugins (in plugins/ directory)
$rcmail_config['plugins'] = array('password');

STEP FINAL: Restart roundcube and apache

 

Ref:

  1. [FRESH ports] poppassd
  2. Poppassd – Installation and Management Guide
  3. roundcube wiki – plugins/password
Thursday, October 21, 2010

iSCSI target crash when selecting ‘Device’ node

OS: Windows Storage Server 2003 R2
iSCSI target version: 3.1.3412

如題,一個很久以前就注意到的問題,不過因為沒有急迫性,就一直不理他XD。這兩天因為要整理一些空間出來用,只好處理一下。

於是找到一篇HP論壇裡的討論串,裡面有人提到是微軟的一個更新造成的...

請找KB973507

這個更新是2009/8/11出來的,如果有人遇到同樣的問題,大概也是這個時點之後,把這個更新移除後重開機,iSCSI target就可以正常使用了~

另外也有一份文件提到:

Issue: Installing Microsoft security update KB973507 results in the Microsoft iSCSI Software Target not displaying
iSCSI target devices when the Devices node is selected in the iSCSI Target management console.

Ref:

  1. [HP IT Resource Center Forums] AiO 600 - problem with Microsoft iSCSI target snapin
  2. [pdf] HP StorageWorks P4000 Unified NAS Gateway Release Notes
Thursday, September 30, 2010

Oracle shutdown hangs: forgot the ‘immediate’ option

一個簡單的小問題,不過還滿常發生的=   =||

一般需要關閉資料庫時,都會下'shutdown immediate’指令,有了immediate選項,Oracle不需等待所有連線關閉。反之,若只有下'shutdown'指令,也就是'shutdown normal',Oracle就會等到所有連線都結束後才關閉,通常都關不下來... 這時候就算又開了新的連線想重下指令,都會收到類似"Not connected to Oracle"這類的訊息.. 這時候!!

可以另外開一個新連線這麼做:

SQL> conn sys as sysdba
輸入密碼:
連線至閒置的執行處理.
SQL> startup force
已啟動 ORACLE 執行處理.
……(資料庫已掛載./資料庫已開啟.)
SQL> shutdown immediate

這樣就可以成功的把資料庫關下來囉~

另一邊原本正在shutdown的視窗可能會看見如下過程:

SQL> shutdown
ORA-03113: 通訊通道上出現 EOF

SQL> ^F^D
SP2-0042: 未知的命令 "" - 此行的剩餘部份被略過不予處理

完工!

Thursday, September 16, 2010

office: 使用萬用字元進行尋找/取代作業

今天發現office的尋找功能還滿強大的,介紹一些使用萬用字元搜尋/取代的方法:首先最基本的就是要會打開「尋找及取代」的視窗XD,在「更多(M)>>」選項裡把「使用萬用字元(U)」選項給勾起來。

  • 尋找符合「HH:MM:SS」的時間格式: 最簡易且不嚴謹的寫法可以用「??:??:??」。「?」表示任何單一字元,所以如果你的文件裡有「AA:BB:CC」這樣的字串,它也會符合尋找目標,但卻不符合我們只想尋找時間格式的目的。所以可以改寫成「[0-9]{2}:[0-9]{2}:[0-9]{2}」,就是三組「[0-9]{2}」被兩個冒號隔開來,其中「[0-9]」表示0到9之間的其中一個數字,「{2}」表示前一個字元或運算式必須出現2次。所以利用三組「[0-9]{2}」與冒號就可以找出符合的格式。
  • 在找到的「HH:MM:SS」時間格式前後加上「*」: 這時候就要需要取代功能的搭配了。在取代的頁籤裡,「取代為」的表示式該怎麼寫呢? 我希望找到所有的符合的時間格式並在他前後加上星號,卻不希望更改了時間的值。一開始嘗試用「*[0-9]{2}:[0-9]{2}:[0-9]{2}*」,結果他就把所有時間格式整個直接取代成「*[0-9]{2}:[0-9]{2}:[0-9]{2}*」的字樣OTZ。正確做法應該是把尋找目標寫成「([0-9]{2}):([0-9]{2}):([0-9]{2})」, 取代寫成「*\1:\2:\3*」。「\1」, 「\2」, 「\3」依序代表尋找目標的三組括號裡的值! 這個技巧主要用在你真正的目的不是「取代」,而是利用尋找到的目標再做一些位置上的變化或像此處加上其他字元符號的應用。

以上兩個就是今天有用到的精隨啦~ 當然還有很多種變化,像是{2,}則表示前面的字元或運算式至少要出現2次,若是{2,4}就表示前面的字元或運算式須出現2-4次。另外在不使用萬用字元的情況下也可用「代碼」來尋找特殊的格式或字元:

  • 將空白行去除: 搜尋目標以「^p^p」表示(記得不必勾「使用萬用字元(U)」)。一個「^p」表示一個換行符號,兩個「^p^p」就會空一行,所以將「^p^p」取代為「^p」,就可以將空白行去掉了。

其他還有許多用法請參閱reference。

 

Ref:

  1. Office產品支援中心: 尋找及取代文字或其他項目

Tags