Windows Powershell 1.0

Windows Powershell 1.0 是舍米碗糕?

如果你有常用Windows的cmd.exe你就會非常熟悉Windows Powershell 1.0,
只是它現在功能更強大, 能夠做更多的事情. (據說還可以跟Linux的指令功能不相上下)

微軟官網提到:

Windows PowerShell 是微軟為 Windows 環境所開發的 shell 及腳本語言技術,這項全新的技術提供了豐富的控制與自動化的系統管理能力;而「腳本語言」(scripting languages)則是用來編寫程式的電腦語言。腳本語言通常都有簡單、易學、易用的特性,目的就是希望能讓寫程式的人(開發者)快速完成程式的編寫工 作。

Powershell目前已內建在Windows Server 2008, 你也可以安裝在Windows Server 2003.

Windows PowerShell 可安裝於 Windows XP 以及之後的用戶端或伺服端 Windows 作業系統,包括:

用戶端:Windows XP、Windows XP Service Pack 1、Windows XP Service Pack 2、Windows Vista
伺服端:Windows Server 2003、Windows Server 2003 R2、Windows Server 2003 Service Pack 1

而 Windows PowerShell 除了有 32 位元版本,也還有 x64 和 ia64 等兩個 64 位元版本,可以安裝在這兩種 64 位元 Windows 平台。此外,由於執行 Windows PowerShell 需要 .NET Framework 2.0,因此請先替電腦安裝 .NET Framework 2.0。目前 Windows PowerShell 是為 RC1 階段,官方下載的網址請參閱文後(下載前需經過簡單的註冊手續)。下載回來的檔案是 ZIP 壓縮檔,只要解壓縮並執行副檔名為 .msi 的檔案即可安裝,安裝過程相當簡單,只要依照精靈指示即可順利完成。

他是免費下載的喔~ 如果你有志成為System Administrator, 那Powershell將會是你不能錯過的好幫手.

下載連結:

Documentation:

Cheers~

WIMP vs LAMP

WIMP這個縮寫如果你到wikipedia 去查的話,

他會告訴你這是WIMP stands for “window, icon, menu, pointing device”,

但我最近想到其實我一直習慣用WIMP,

就是 Windows Server 2003 + IIS + MYSQL + PHP,

雖然比起LAMP (Linux + Apache + MYSQL + PHP) 或 WAMP (Windows + Apache + MYSQL + PHP)組合來得遜色,

但使用快一年了也發現它的效能及功能都足夠我用了~

網上關於DEBUG WIMP的資訊其實也不多, 如果以後還發現甚麼再跟大家分享吧~

用phpinfo()看模組時發現沒有MYSQL模組

環境: Windows Server 2003 Enterprise

問題: PHP5 + MYSQL4+ IIS (找不到MYSQL模組)

解決方式: PHP4 + MYSQL4 + IIS

最近在Windows Server 2003灌PHP5 + MYSQL時頻頻遇到PHP讀不到MYSQL模組的問題,

花了不少時間去網上找解決方式, 試了都不成功, 至今原因仍不清楚,

但後來試了裝裝看PHP4的最新版本(不用PHP5), 再跑跑看,

MYSQL的模組就在PHPINFO()出現了! (記得要把php4ts.dll放在C:\Windows\system32\下)

這個文章應該對喜歡把PHP灌在WINDOWS 環境底下的人有用吧.
雖然是治標不治本的辦法(因為沒辦法用PHP5還滿懊惱的)

[MYSQL常見問題] Client does not support authentication protocol requested

個人測試問題發生的背景如下:
環境: Windows Server 2003
先灌MYSQL 5.1 =>OK
再灌PHP4 =>OK
灌PHPMYADMIN =>設定Secret_blowfish OK=>跑的時候出現

Client does not support authentication protocol requested
by server; consider upgrading MySQL client

MYSQL官方的解決方式如下:

MySQL 5.0 uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older (pre-4.1) clients. If you upgrade the server from 4.0, attempts to connect to it with an older client may fail with the following message:

shell> mysql Client does not support authentication protocol requested by server; consider upgrading MySQL client

To solve this problem, you should use one of the following approaches:

  • Upgrade all client programs to use a 4.1.1 or newer client library.
  • When connecting to the server with a pre-4.1 client program, use an account that still has a pre-4.1-style password.
  • Reset the password to pre-4.1 style for each user that needs to use a pre-4.1 client program. This can be done using the SET PASSWORD statement and the OLD_PASSWORD() function:
    mysql> SET PASSWORD FOR
    -> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');

    Alternatively, use UPDATE and FLUSH PRIVILEGES:

    mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
    -> WHERE Host = 'some_host' AND User = 'some_user';
    mysql> FLUSH PRIVILEGES;

    Substitute the password you want to use for “newpwd” in the preceding examples. MySQL cannot tell you what the original password was, so you’ll need to pick a new one.

  • Tell the server to use the older password hashing algorithm:
    1. Start mysqld with the --old-passwords option.
    2. Assign an old-format password to each account that has had its password updated to the longer 4.1 format. You can identify these accounts with the following query:
      mysql> SELECT Host, User, Password FROM mysql.user
      -> WHERE LENGTH(Password) > 16;

      For each account record displayed by the query, use the Host and User values and assign a password using the OLD_PASSWORD() function and either SET PASSWORD or UPDATE, as described earlier.

Note

In older versions of PHP, the mysql extension does not support the authentication protocol in MySQL 4.1.1 and higher. This is true regardless of the PHP version being used. If you wish to use the mysql extension with MySQL 4.1 or newer, you may need to follow one of the options discussed above for configuring MySQL to work with old clients. The mysqli extension (stands for “MySQL, Improved”; added in PHP 5) is compatible with the improved password hashing employed in MySQL 4.1 and higher, and no special configuration of MySQL need be done to use this MySQL client library. For more information about the mysqli extension, see http://php.net/mysqli.

It may also be possible to compile the older mysql extension against the new MySQL client library. This is beyond the scope of this Manual; consult the PHP documentation for more information. You also be able to obtain assistance with these issues in our MySQL with PHP forum.

For additional background on password hashing and authentication, see Section 5.4.9, “Password Hashing as of MySQL 4.1”.

後來試了之後就可以RUN了, 如果各位也遇到這個情況不妨試試.

主要是針對不同的帳戶, 可能是版本的問題, 只要設定OLD_PASSWORD, 再FLUSH一次MYSQL應該就沒問題了.

原文可參考: http://dev.mysql.com/doc/refman/5.0/en/old-client.html

MySQL進行資料庫搬移時遇到的編碼問題

當我們要把一個MYSQL的資料庫輸出,
搬移到另一臺機器的MYSQL時,
如果是全英文的資料庫還好, 最怕的是遇到中文字編碼的問題.
如果欄位是VARCHAR的dataType, 搬移後用網頁顯示時會是” ??? “..
相信是因為big5跟UTF-8之間轉換所造成的問題.
我的解決方式是把相關的資料格式從VARCHAR 變成 BLOB.
中文字就能正常顯示了.

這樣做的缺點是資料格式若是BLOB則會減低效率,
而且用PHP函式對中文字作字串處理時會有問題.

僅供參考囉~

Json 是舍米?

如果有用PHPINFO的人都會常常看到JSON這個模組吧? 究竟JSON是甚麼呢?

看了以下的文章, 你就會恍然大悟了:

三分鐘告訴你甚麼是JSON,

http://secretgeek.net/json_3mins.asp

另外JSON的官網:

http://www.json.org

簡單的來說Json就是一種資料結構,
他類似XML, 能夠存放資料, 可再用程式語言去讀取他..
XML與JSON得比較可以參考上面的文章~

.NET FRAMEWORK 為自己的程式設定Security Permission

為了避免使用者取得他們不應該存取的資料,

.NET FRAMEWORK提供了安全性的物件, 限制使用者的存取權限.
這跟Windows本身的帳戶安全性有些不同, 是針對程式而言.

SecurityAction 屬性有三種:

  • RequestMinimum(M) 正常執行的最小權限
  • RequestOptional(O) 可有可無的權限
  • RequestRefuse(R) 絕對不能有的權限

*P = Security Policy (也就是Enterprise, Machine, User三者的交集)

最終權限的決定放程式為:  (P 交 ((M 聯 O) – R))

以下範例顯示:只允許使用者存取特定的資料表, 如果不是指定的資料表, 就無法執行程式:

注: RequestOptional, Unrestricted應設為False, 才表示不允許給予其他的權限; 如果設為True, 則表示沒有限制, 所有權限的給了(很危險, 容易造成駭客的入侵).

Imports System.Security.Permissions
Imports System.Data.SqlClient

<Assembly: UIPermission(SecurityAction.RequestMinimum, Window:=UIPermissionWindow.SafeTopLevelWindows)>
<Assembly: SqlClientPermission(SecurityAction.RequestMinimum, _
         ConnectionString:=”server=.;database=pubs;integrated security=true”)>

<Assembly: SecurityPermission(SecurityAction.RequestOptional, Unrestricted:=False)>

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cn As New SqlConnection(TextBox1.Text)
        Try
            cn.Open()
            MessageBox.Show(“連線成功”)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

End Class

方法的權限安全種類:

有六種SecurityAction 可用再宣告式或命令式安全性

  • Assert
  • Demand
  • InheritanceDemand
  • LinkDemand
  • PermitOnly
  • Deny

Imports System.Security.Permissions
Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    <FileIOPermission(SecurityAction.Demand)> _
    Sub CreateFile()
        Try
            File.CreateText(“C:\test\b.txt”)
            MessageBox.Show(“b.txt has been created”)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    ‘DENY表示不允許使用這個METHOD
    <FileIOPermission(SecurityAction.Deny, Write:=”C:\test”)> _
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CreateFile()
    End Sub

    ‘SecurityAction.Demand的另一種寫法
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim fp As New FileIOPermission(FileIOPermissionAccess.Write, “C:\test”)
        fp.Demand()
        CreateFile()
    End Sub
End Class