2009年11月30日 星期一

Tomcat自動Reload Servlet

  1. 修改conf/servler.xml,並在host的tag內加入以下設定。
          <context debug="0" docbase="YourAP" path="/YourAP" reloadable="true"/>


VMware修改MAC Adress

  1. 找到目錄下的.vmx檔
  2. 找到該檔內的二行程式                                                                                                      ethernet0.addressType = "generated"
    ethernet0.generatedAddress = "00:00:00:87:65:43"

  3. 將這二行程式替換成                                                                                                 ethernet0.addressType = "static"
    ethernet0.address = "00:00:00:87:65:44"


2009年11月29日 星期日

Tomcat上設定SSL雙向驗證

1. 在Server.xml裡SSL的Connector tag內加入clientAuth="true"這個屬性,此屬性表示所有走SSL的Client都需驗證它的憑證是否為Server所信任的。
<Connector port="4443" minSpareThreads="5" maxSpareThreads="475" enableLookups="true"
 disableUploadTimeout="true" acceptCount="500" maxThreads="1000" scheme="https"
 secure="true" SSLEnabled="true" keystoreFile="/.keystore"
 keystorePass="admin123" sslProtocol="TLS" URIEncoding="UTF-8" clientAuth="true"
 truststoreFile="/.keystore" truststorePass="admin123" truststoreType="JKS" />
        PS. JKS為Java Key Store,也可以用另一種類型PKCS12

2. 若在Server.xml無設定truststoreFile屬性等相關資訊時,則Client只要使用任何正確的憑證即可進入網頁。

3. 若要限定Client的憑證是特定CA所發出的憑證,則需要設定truststoreFile屬性等相關資訊。並將所信任的CA的憑證,利用keytool匯入到truststoreFile(此範例為.keystore)。


2009年11月25日 星期三

Cross Site Scripting(OWASP A2)

1. 攻擊手法
    利用網站發佈Script,而且這些Script是其它使用者也會看的到,進而達到跨網站攻擊。
    攻擊者通常會利用此手法來劫持其它使用者的sessions、或是重新導向到惡意網站。

2.


3. 如何防止XSS
      a. 利用在Cookie內設定HttpOnly來減少系統發生XSS的可能性。
          因為在Cookie內設定HttpOnly之後此Cookie就無法透過Javascipt去讀取。


A phrasal Verbs

1. A phrasal Verbs:由動詞加介系統所組成的一個動詞,而且很難從它的動詞去猜它的真正的意思。

2. Example:
     put sth away:物歸回位
     hang sth up:將東西掛上
   


2009年11月24日 星期二

98年9-10月統一發票中獎號碼

98年9月、10月統一發票中獎號碼
特獎
43815568
50850911
91018779
頭獎
13001495
13240479
97429353


Unvalidated Redirects and Forwards(OWASP A8)

1. 攻擊手法
     攻擊者利用網站未經過驗證的Redirect和Forward進行攻擊。
         a.  未經過驗證的Redirect:攻擊者可以利用此弱點欺騙使用者點選連結並重新導向到惡意網址。
              Example: http://www.google.com/redirect.jsp?url=hacker.com/malware.exe
         b.  未經過驗證的Forward:攻擊者可能會利用此弱點跳過存取控制,直接連結到管理功能頁
              面。
             Example: http://www.google.com/forward.jsp?fwd=admin.jsp

2. 自我網站檢查
        a.  檢查所有可以帶有參數的Redirect和Forward,是否有驗證參數的功能。

3. 如何預防
        a. 簡單的避免使用 Redirect和Forward。
        b. 若要使用,不要把使用者輸入的參數當作決定目的端的一部分。
        c. 若無法避免,則需要驗證使用者輸入的參數。


Google App Engine(GAE) - 檔案上傳

1. GAE的檔案上傳需使用Apache的FileUpload的套件

2. 範例程式如下:
ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iterator = upload.getItemIterator(request);
        while (iterator.hasNext()) {
            FileItemStream item = iterator.next();
            //判斷是否為一般Form的文字資料,還是檔案
            if (item.isFormField()) {
                if (item.getFieldName().equals("icon.name")) {
                    InputStream i = item.openStream();
                    byte[] b = new byte[i.available()];
                    i.read(b);
                    icon.setName(new String(b));
                }
            } else {
                InputStream i = item.openStream();
                byte[] b = new byte[i.available()];
                i.read(b);
                icon.setFile(new Blob(b));
            }
        }


可數名詞、不可數名詞(Countable, uncountable)

1. 可數名詞(Countable)
    a lot of,too many, many, some, a few

2. 不可數名詞(Uncountable)
    a lot of, too much, some, a little


2009年11月23日 星期一

解決VMware與Hamachi無法共存的問題


1. 在VMware開啟Virtural Network Editor



2. 選擇Automatic Bridging



3. 將Hamachi網路介面加入自動排除的介面之一



4. 最後按下確定按鈕



Google App Engine 實作

  1. UrPosition:與朋友分享自己目前的所在位置,可以透過web介面看到所有朋友在Google Map上的位置。
  2. 單字搜尋:單字搜尋引擎,你可以只要輸入部分的字元即可,例如你想要查詢所有包含"dis"的單字。那你只要輸入dis即可,系統會將所有有包含"dis"的單字都列出來。
  3. 線上白板:為了方便儲存一些文字訊息所寫出來的一個小程式,你可以提個一個名稱以建立一個新的白板,或是利用已建立的名稱來對這個白板的內容做一個維護。






Necessary & Suggestion

1. Necessary (must, have to, need to)
      You must be at least 18 to drink.

2. Not Necessary(don't must, don't have to, don't need to)
       You don't have to be 20 to drink.

3. Suggestion(should, ought to, had better)
       You should ware some jackets.
       You had better ware sunglasses in the US. (strong suggestion)

4. Not Suggestion(Shouldn't, had better not)
       You shouldn't take too much money.

5. Not Allow(mustn't)
       You mustn't eat food in MRT station.


2009年11月21日 星期六

Java keytool 基本指令介紹

1. 匯入憑證到keystore
      keytool –import –alias xxx –file xxx.cer –keystore .keystore

2. 查詢keystore的內容
      keytool –list –v –keystore .keystore

3. 刪除keystore內的其中一個憑證
      keytool –delete –alias xxx –keystore .keystore

4. 產生金錀對(RSA為非對稱加密的演算法)
      keytool -genkey -alias xxx -keyalg RSA -keystore .keystore

5. 產生憑證申請檔
      keytool -certreq -alias xxx -file certreq.txt -keystore .keystore
 
6. 查詢PKCS12類型keystore的內容
      keytool –list –v –keystore .keystore -storetype pkcs12

7. 建立一個含有私鑰的keystore
      keytool -genkey -alias keyAlias -keyalg RSA -keystore keystore.jks

8. 修改keystore的密碼
      keytool -storepasswd -new newPassword -keystore keystore.jks


2009年11月20日 星期五

Direct Web Remoting(DWR)簡介

DWR可以在Web Application上直接處理XMLHttpRequest,因此你可以在 有的架構下利用DWR來產生Ajax的
效果。而且DWR非常簡單,只要再web.xml加入DRW的Servlet並新增一個dwr.xml的設定檔。就可以直接在Client端
利用Javascript直接呼叫Server端的Java方法。
以下建構一個簡單的例子,在Client端輸入一串字串,Servler端在收到這一個字串後,回傳Client端輸入的字串並回傳
Server端目前系統時間。


1. 下載dwr.jar檔。


2. 在web.xml加入DRW的Servlet。
<servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>
            org.directwebremoting.servlet.DwrServlet
    </servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>


3. 在WEB-INF下新增一個dwr.xml的設定檔。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
    <allow>
        <create creator="new" javascript="AjFuns">
            <param name="class" value="tw.nicky.dwr.AjaxFunctions"/>
       </create>
    </allow>
</dwr>



4. 建立AjaxFunctions.class(此類別就是用戶端要呼叫的類別)
package tw.nicky.dwr;
import java.util.Date;
public class AjaxFunctions {
    public String getEchoTime(String msg) {
        String result = "";
        result = result + "your input: "+msg+" ";
        result = result + "server time: "+new Date();
        return result;
    }
}




5.最後建立呈現在用戶端的網頁()
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>dwr_example</title>
        <script type='text/javascript' src='dwr/interface/AjFuns.js'></script>
        <script type='text/javascript' src='dwr/engine.js'></script>
        <script type='text/javascript'>
            function getEchoTime(){
                var msg = document.getElementById("msg").value;
                AjFuns.getEchoTime(msg,function(ret){
                    document.getElementById("results").innerHTML = ret;
                });

            }
        </script>
    </head>
    <body>
        <input type="text" id="msg">
        <input type="button" value="確定" onClick="getEchoTime()">
        <div id="results">
        </div>
    </body>
</html>


2009年11月19日 星期四

Google App Engine(GAE) - 在GAE上使用Struts2

1. 建立一個Listener實作ServletContextListener, HttpSessionListener, HttpSessionAttributeListener
public class InitListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

   public InitListener() {
   }

   public void contextInitialized(ServletContextEvent sce) {
      OgnlRuntime.setSecurityManager(null);
   }
}



2. 修改web.xml,加入此listener
<listener>
   <listener-class>tw.nicky.listener.InitListener</listener-class>
</listener>


3. 支援:Tiles、後端驗證、@InputConfig、@SkipValidation

4. 不支援:Struts2 FileUpload


Google App Engine(GAE) - 利用Remote api上傳大量資料到DataStore

1. 安裝Google App Engine(Python) 目前只有python版本支援Remote api。

2. 安裝Python 2.5,目前Google App Engine只支援到2.5版。

3. 建立app.yaml檔。

application: app-name #你的app名稱
version: 2 #你的app版本
runtime: python
api_version: 1

handlers:

- url: /remote_api

script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin


4. 上傳此app.yaml檔到你的App Engine。(youdir是存放app.yaml的目錄)
    C:\Program Files\Google\google_appengine\appcfg.py update yourdir/

5. 撰寫上傳資料的程式。
from google.appengine.ext import db
from google.appengine.tools import bulkloader

class PersonData(db.Model): #PersonData為kind Name()
    id = db.StringProperty()
    age = db.StringProperty()
    name = db.StringProperty()
    address = db.StringProperty()
    email = db.StringProperty()

class Loader(bulkloader.Loader):
    def __init__(self):
        bulkloader.Loader.__init__(self, 'PersonData',
                                   [('id', str),
                                   ('age', str),
                                   ('name', lambda x: unicode(x, 'utf-8')) #有中文字部分需設定為UTF8編碼
                                   ('address', lambda x: unicode(x, 'utf-8'))
                                   ('email', str)
                                   ])

loaders = [Loader]


6. 製作資料CSV檔(資料欄位以半形逗號隔開)。
1,43,劉的華,台北市信義區,gae@gmail.com

1,41,張學有,台北市信義區,gae@gmail.com


7. 將資料上傳到App Engine(config_file:上傳資料的程式 filename:資料CSV檔 kind:需與程式內的kind name一致)。
    C:\Program Files\Google\google_appengine\appcfg.py upload_data --config_file=Loader.py --filename=PersonData.csv --kind=PersonData


as...as的用法

1. as adv./adj. as
       Taipei isn't as beautiful as Hualien.

2. as [many, few] count noun as
       Hualien hasn't as many cars as Taipei.
       Taipei hasn't as few cars as Hualien.

3. as [much, little] noncount noun as
       Hualien hasn't as much pollution as Taipei.
       Taipei hasn't as little pollution as Hualien.


現在完成式(Prsent Perfect)

1. 過去到現在的經驗
   *  Have you ever been to Japan? 
   *  Have you been to Japan before?

2. 是否已完成
   * Have you eaten dinner yet? 
   * Have you already eaten dinner?

3. 從過去到現在都還是
   * How long have you been a student?


2009年11月18日 星期三

Google App Engine(GAE) - Eclipse plugin安裝步驟

1. 執行Eclipse Software Update。


2. 選擇Available Software按下Add Site。

 

3. 在Location輸入 http://dl.google.com/eclipse/plugin/3.4。

 

4. 勾選你要安裝的plug in,並按下Install按鈕。

 

5. 選擇你要安裝的Plugin。

 

6. 安裝完成之前,工具列會多出三個按鈕分別是建立Goole App Engine專案、建立Google Web Toolkit專案及上傳程式碼到Google App Engine上。

 

 

 

 

 



Android學習筆記 - Android相關網站

  1. Android官方網站
  2. 台灣Android論壇
  3. 深入淺出 Android:一個很好的入門文件
  4. DroidDraw:設計Android版面必備的網站
  5. Android應用程式集:上面有介紹很多Android的軟體
  6. Android JavaDoc:就是Android API的JavaDoc在查API的時候很好用
  7. Android Mobile01討論群組:介紹Android的一些軟體 
  8. Jollen 的 Android 教學 
  9. ysl 的程式天堂 - Android 應用開發 ‧ 研究 ‧ 與諮詢
  10. 昭佑.天翔


2009年11月17日 星期二

Android學習筆記 - 建立AVD模擬器

1. 到android-sdk安裝目錄下的tools資料夾

2. 利用tools資料夾android指令進行安裝及查看目前的模擬器

3. android指令介紹
    a. 查看target列表
        android list target
    b. 查看avd模擬器列表
        android list avd
    c. 建立一個模擬器
        android create avd --target 1 --name emu1 --sdcard 500M
        (target為此模擬器要使用的targetId)

4. adb指令介紹
    a. 在模擬器上安裝apk檔
        adb install xxx.apk
    b. 在模擬器上移除某個apk檔
        adb shell rm xxx.apk
    c. 查看系統log記錄
        adb logcat