2009-04-08
แก้ปัญหา .NET กับ paradox และมีปัญหากับข้อมูลภาษาไทย
ด้วยความช่วยเหลือจาก pFz จากห้อง #ubuntu-th ( ที่เป็นห้องรวมพลคนรัก ubuntu ในไทย ) ช่วยแก้ไขเลยได้ code ออกมาตามข้างล่างนี้
'กำหนดต้วแปร Encoding Dim DOSenc As EncodingDim UTF8enc As EncodingDim w874 As Encoding
'กำหนดตัวแปร Array byte เพื่อทำการรับค่าจาก ฟังก์ชั่นที่ทำการแปลงข้อความ
Dim UTF8Byte As Byte()Dim DOSByte As Byte()
Dim Datastring As String
' # define DOS encode
DOSenc = Encoding.GetEncoding(437)
' #denfine UTF8 encode
UTF8enc = Encoding.UTF8
' #define Windows-874 encode
w874 = Encoding.GetEncoding(874)
' สมมุติว่า ตัวอักษรที่รับเข้ามา คือ ตัวแปร s นะครับ
UTF8Byte = UTF8enc.GetBytes(s)
' ใช้ฟังก์ชั่น Encoding.Convert แปลง Encoding โดยแปลงจาก UTF8 -> OEM 437
DOSByte = Encoding.Convert(UTF8enc, DOSenc, UTF8Byte)
' จากนั้นใช้ Method GetString เพื่อทำการแปลง Byte ให้กลายเป็น String อีกที สังเกตว่าเราเอา Byte ' ที่ได้จากแปลงคือ OEM 437 มาใส่ให้ Windows-874 encoding แสดงผล
Datastring = w874.GetString(DOSByte)
#class use
System.text.encoding
Howto Syslinux + Norton Ghost เพื่อทำการ บูทผ่านเครือข่าย
เมื่อศุกร์ที่ผ่านได้มีโอกาสมานั่งปรับเพราะคิดว่าเหลือโปรเจ็กต์ที่ค้างๆ อยู่ ซึ่งตอนแรกคิดจะทำเรื่องเมล์แต่พักเอาไว้ก่อนเพราะเจ้าตัวนี้ใช้ทุกครั้ง หากทำมันเสร็จก่อนน่าจะช่วยประหยัดเวลาได้ เลยมานั่งค้นนั่งทำใช้เวลาไปทั้งหมด6 ชั่วโมง ( จริงๆ รวมวันที่เขียนนี้ก็คง 6.20 นาที เพราะมีปัญหากับ TFTP server ต้องมานั่งปรับอีก ) ซอฟต์แวร์ที่ผมใช้นั้นก็คือ NortonGhost Corperate Edition Version 7.5 + Window 2000 AdvanceServer + Syslinux ( PXElinux ) + WMI script + Window TFTP server ช่วยในการติดตั้ง
ทีนี้มาประเดิมปัญหาก่อนว่าเดิมทีหากท่านซื้อไลเซ็นต์ของ NortonGhost จริง มาแล้วเขาจะมีชุดซอฟต์แวร์ที่เป็นตัวจัดการบูทเนตเวิร์ก หรือ PXE เซอร์เวอร์ ชื่อว่า 3com boot service ซึ่งตอนนี้ไม่สามารถหาดาวน์โหลดได้แล้ว เพราะ 3com ได้หยุด support หรือขายไปแล้วจำแน่นอนไม่ได้ ( ความจำไม่ค่อยดีขออภัยด้วยครับ ) เอาล่ะทีนี้ตัว3com boot service เกิดเสียขึ้นมาแล้วไม่มีแผ่นสำรอง - -" เลยต้องหาซอฟต์แวร์ตัวอื่นมาทดแทน แต่จนแล้วจนรอดพยายามหาซอฟต์แวร์แบบนี้ก็ไม่มี หากมีก็รวมอยู่กับตัวโปรดักส์อื่นๆ เลย หรือจะเอา RIS service ของวินโดว์ติดตั้งก็ไม่สนับสนุนอีก ( อาจจะทำได้แต่ผมทำไม่เป็นก็ได้ ) สุดท้ายก็เลยมาลองค้นดู syslinux นี่แหละน่าจะใกล้เคียง โดย syslinux เป็น boot loader สำหรับติดตั้ง Linux จากไฟล์ระบบแบบ FAT ทีนี้ใน packeget เขาแถมซอฟต์แวร์มาให้อีกคือPXEboot ( pxelinux ) ซึ่งผมจะใช้เป็นตัว หลักก็คือ PXElinux นี่แหละครับ สามารถดาวน์โหลดได้จากที่นี่เลย
http://www.kernel.org/pub/linux/utils/boot/syslinux/
เวอร์ชั่นที่ผมใช้อยู่นี้คือ 3.36 โหลดได้จาก
####################### DOWNLOAD Syslinux ##########################
http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.36.zip
จากนั้นทำการ Unzip ออกมาไว้ที่ไหนก็ได้ แต่กรณีของผม ผมเอาไว้ที่ C:\syslinux
มาถึงขั้นตอนต่อไปคือทำการสร้างโฟลเดอร์สำหรับ BOOTP หรือสถานที่เก็บตัวโหลดเดอร์สำหรับบูทผ่านเนตเวิร์ก เพื่อให้ง่ายต่อการจดจำผมสร้างโฟลเดอร์ไว้ที่ Drive C:\ อีกเช่นกันชื่อว่า
c:\TFPBOOT
ทำการสร้างโฟลเดอร์ให้ PXElinux เพื่อใช้ในการเก็บไฟล์คอนฟิกไฟล์สำหรับบูทหน่อย ชื่อโฟลเดอร์ว่า pxelinux.cfg
c:\TFPBOOT\pxelinux.cfgcd c:\TFPBOOT\pxelinux.cfg\
จากนั้นทำการสร้าง "txt file" เพื่อนำมาเป็นคอนฟิกไฟล์สำหรับการบูท ชื่อว่า "default" ( จริงๆ สามารถเปลี่ยนชื่อได้แต่ก็ให้ขึ้นอยู่กับ กฏ การเรียงลำดับชื่อของ pxelinux ( ดูเพิ่มเติมได้ที่ http://syslinux.zytor.com/pxe.php )ถ้าอยากให้ คอนฟิกไฟล์บูทมีผลกับเครื่องใดเครื่องหนึ่งเท่านั้นก็สามารถทำได้โดยอ้างอิงจากข้างต้น ( ดูเพิ่มเติม )
c:\TFTPBOOT\pxelinux.cfg\default
ภายในคอนฟิกไฟล์รายละเอียดเป็นแบบข้างล่างนี้
default bootdos <-- บอก Label default สำหรับทำการ boot คล้ายๆกับ grubprompt 0
label bootdos <-- ทำการสร้าง label section ขึ้นมาชื่อ "bootdos"kernel memdisk <-- ระบุ image kernel ที่ใช้ในการโหลดappend initrd=dc7100.img <-- Chain load ซึ่งสร้างมาจาก floppy image
การเลือกแบบของ Image ในการโหลดสามารถหาอ่านได้จากเอกสารครับ มีทั้ง Image ที่เป็น Linux kenel ด้วยแต่ในกรณีนี้ ผมไม่ต้องการบูท Linux แต่ต้องการให้ตัว Syslinux เป็นตัว chain-loader กับ Ghost floppy imageที่เราสร้างขึ้น ผมเลยเลือกเอา image kernel ที่ชื่อ memdisk ( จากความสามารถตรงนี้สามารถนำไปประยุกต์ให้โหลด OSอื่นๆ ได้ )
สร้างและกำหนด kernel รวมถึงโหลดเดอร์ pxe ด้วย
copy c:\syslinux\memdisk\memdisk c:\TFTPBOOT\memdisk copy c:\syslinux\pxeliux.0 c:\TFTPBOOT\pxeliux.0
ทำการสร้าง image ghost สำหรับบูทผ่านเนตเวิร์ก แต่ต้องไปดาวน์โหลดอุปกรณ์มาก่อนไปโหลดเอา rawrite เวอร์ชั่นGUI มา ( จริงๆ ก็คือ rawritedos แต่มาทำเป็นแบบ GUI ใครเคยติดตั้ง Linux เมื่อก่อนคงรู้จักดี )
################### tool for create floppy image ####################
http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm
เอาแผ่น Ghost floppy ที่เราทำไว้แล้วใส่เข้าไป แล้วให้มันทำการ "read" แล้ว save เก็บเอาไว้ ในที่นี้ผมตั้งชื่อเอาไว้ว่า"dc7100.img" เรียบร้อยสำหรับการทำ image floppy
ตอนนี้ใน folder c:\TFTPBOOT จะมีไฟล์และโฟลเดอร์อยู่ดังนี้
##################### TFTPBOOT folder content #####################
c:\TFTPBOOT\pxelinux.cfg\default <-- config file for pxelinuxc:\TFTPBOOT\pxelinux.0 <--- boot loaer filec:\TFTPBOOT\memdisk <-- kernel loader "memdisk" typec:\TFTPBOOT\dc7100.img <-- floppy image or ghost image boot disk create by"rawritewin"
เอาล่ะส่วน boot server เรียบร้อยแล้วทีนี้มาต่อกันด้วยการกำหนดค่า DHCP ในที่นี่ผมสมมุติว่าท่านได้ทำการสร้าง scope ไฟล์อะไรเรียบร้อยแล้ว เพราะส่วนอื่นๆ ต่อไปนี้จะนำไปใส่ยัง option ของ scope ไฟล์ ส่วนที่เปลี่ยนแปลงมีดังนี้ โดยการ click ขวาที่ "scope option" แล้วเลือก "configure scope " เอาล่ะ option ที่เพิ่มมีดังนี้
################### DHCP scope configure section ####################
option 066 "Boot server Host name" ใส่ค่า "ชื่อของบูทเซอร์เวอร์"option 043 "Vender specific info" ใส่ค่า 01 04 00 00 00 00 ff option 067 "Bootfile Name" ใส่ค่า "ไฟล์ที่เราจะให้ทำการบูท"
เพราะฉะนั้นตอนนี้ ผมจะมีค่าดังข้างล่างนี้จะมีเปลี่ยนก็คือชื่อเครื่องของ boot server ( ทางผู้เขียนแนะนำว่าให้ DHCP server กับTFTP server อยู่ที่เดียวกัน )
option 066 "Boot server Host name" value "gserver"option 043 "Vendor specific info" value 01 04 00 00 00 00 ffoption 067 "Bootfile Name" value "pxeliux.0"
กำหนดออปชั่น classID เพิ่มเติมเพราะ Window 2000/2003 ไม่สนับสนุน option ดังกล่าวโดยการทำผ่าน tool commandlineชื่อว่า netsh
C:\WINDOWS\system32>netshnetsh>dhcpnetsh dhcp>server [server name] *OR* [server IP address]netsh dhcp server>add optiondef 60 PXEClient String 0 comment=PXE supportnetsh dhcp server>set optionvalue 60 STRING PXEClient
restart DHCP service
ทีนี้มาเพิ่มเติมอีกนิดหนึ่ง สำหรับ Howto ที่ผมนำมาอ้างอิงนั้นเขาใช้ "tftpd32" ของ http://tftpd32.jounin.net/ แต่ปัญหามันเกิดขึ้นมาไม่รู้ว่ามาจากอะไร tftpd32 นั้น ช้ามากและรับโหลดพร้อมกันหลายเครื่อง ไม่ได้ เกิดอาการกระตุกหรือค้างไปเลย ผมเลยจำเป็นต้องใช้ TFTP service ของ window แทน แต่ต้องมีการแก้ไขเพื่อเปลี่ยน default โฟลเดอร์ดังนี้ ( เข้าไปเปลี่ยนใน registry )
regedit
ไปที่ key \HKLM\System\CurrentControlSet\Services\TFTPD\Parameters\สร้าง keyDirectory ใส่ค่าสตริงไปเป็น "Directory of BOOTP"หรือDirectory String value "c:\TFTPBOOT\"
สรุปปัญหาที่ทำไม่ได้รอบแรกน่าจะเป็นเพราะว่าขาดออปชั่นการคอนฟิก DHCP ไป ??!! เพราะตอนแรกใช้กับ3com boot service แต่ไม่ work โอเค.ผ่าน หวังคงเป็น idea ให้ใครหลายคนไม่ต้องเสียตังค์ซื้อซอฟต์แวร์เพิ่มเติมหรือปรับปรุงของที่มีอยู่แล้วให้ดีขึ้นนะครับ ตอนหน้าหากไม่มีอะไรก็คงไม่น่าจะพ้นเรื่องการจัดการemail ??
จบครับ ขอขอบคุณแหล่งข้อมูลอ้างอิงข้างล่างนี้เป็นอย่างมากครับ จริงๆ มีอย่างน้อย 30 tab แต่สุดท้ายก็เหลือแค่นี้แหละครับ
################### THANK YOU CREDIT ######################
#Syslinx Homepage site
http://syslinux.zytor.com/
#rawrite GUI version for create img floppy
http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm
#syslinux download
http://www.kernel.org/pub/linux/utils/boot/syslinux/
#Syslinux PXE section describe and Howto
http://syslinux.zytor.com/pxe.php
#Thank you very much for DHCP configure section and idea
http://pxes.sourceforge.net/howtos/ms_only_environment/
php5 + sqlite3 Ubuntu Dapper
แพคเกจและโปรแกรมที่เกี่ยวข้องที่ต้องการติดตั้ง
PDO :: PHP Database Object
sqlite :: sqlite Database
pdo_sqlite :: PDO sqlite support sqlite3
#ติดตั้ง php5 developer file and php configuration script
apt-get install php5-dev
#แก้ไขมาโครไฟล์
vi /usr/lib/php5/build/acinclude.m4
#มาโครที่ชื่อว่า
AC_DEFUN([PHP_ADD_EXTENSION_DEP]
#ที่ท้ายมาโครนี้ ให้เพิ่มบรรทัดนี้เข้าไป
AC_DEFUN([PHP_ADD_EXTENSION_DEP], [])
#อ้างจาก google search
#จากนั้นเมื่อแก้ไขและเซฟแล้ว ก็ทำการดาวน์โหลดและติดตั้ง pdo , pdo_sqlite script จะทำให้โดยอัตโนมัติ
pecl install pdo pdo_sqlite
#หลังจากคอมไพล์แล้วไฟล์ extension จะอยู่ที่ สำหรับเครื่องผมนะ
/usr/lib/php5/20051025/
#แก้ไขไฟล์ php.ini เพื่อเพิ่ม extension เข้าไป **ในกรณีผมใช้กับ php ที่เป็น CLI
vi /etc/php5/cli/php.ini
-- add this --
extension=pdo_sqlite.so
#ติดตั้ง sqlite extension for php5
aptitude install php5-sqlite
#select 'n' answer for downgrade and 'y' for accept #Ready to use!
#คนที่ให้คำแนะนำผม เขาแนะนำให้เปลี่ยนไปเป็น php5.13 แทน 5.12 แทน เห็นแกบอกว่า 5.12 มี bug อยู่พอดีผมอยากแก้ให้ผ่าน ก็ต้องทำด้วยประการละฉะนี้ ซึ่งตอนแรกคิดว่าจะเอา แพคเกจของ edgy มาใช้ซะด้วยซ้ำไป
CREDIT :: special thanks for who support guy in PECL
Linux / Unix Command: ftp
- ftp - Internet file transfer program
SYNOPSISftp [-pinegvd ] [host ] pftp [-inegvd ] [host ]
EXAMPLES
SEE ALSO - Ftp is the user interface to the Internet standard File Transfer Protocol. The program allows a user to transfer files to and from a remote network site.
- -p
- Use passive mode for data transfers. Allows use of ftp in environments where a firewall prevents connections from the outside world back to the client machine. Requires that the ftp server support the PASV command. This is the default now for all clients (ftp and pftp) due to security concerns using the PORT transfer mode. The flag is kept for compatibility only and has no effect anymore.
- -i
- Turns off interactive prompting during multiple file transfers.
- -n
- Restrains ftp from attempting auto-login upon initial connection. If auto-login is enabled, ftp will check the .netrc (see netrc(5)) file in the user's home directory for an entry describing an account on the remote machine. If no entry exists, ftp will prompt for the remote machine login name (default is the user identity on the local machine), and, if necessary, prompt for a password and an account with which to login.
- -e
- Disables command editing and history support, if it was compiled into the ftp executable. Otherwise, does nothing.
- -g
- Disables file name globbing.
- -v
- Verbose option forces ftp to show all responses from the remote server, as well as report on data transfer statistics.
- -d
- Enables debugging.
Options may be specified at the command line, or to the command interpreter.
The client host with which ftp is to communicate may be specified on the command line. If this is done, ftp will immediately attempt to establish a connection to an FTP server on that host; otherwise, ftp will enter its command interpreter and await instructions from the user. When ftp is awaiting commands from the user the prompt `ftp>' is provided to the user. The following commands are recognized by ftp
- ! [command [args ] ]
- Invoke an interactive shell on the local machine. If there are arguments, the first is taken to be a command to execute directly, with the rest of the arguments as its arguments.
- $ macro-name [args ]
- Execute the macro macro-name that was defined with the macdef command. Arguments are passed to the macro unglobbed.
- account [passwd ]
- Supply a supplemental password required by a remote system for access to resources once a login has been successfully completed. If no argument is included, the user will be prompted for an account password in a non-echoing input mode.
- append local-file [remote-file ]
- Append a local file to a file on the remote machine. If remote-file is left unspecified, the local file name is used in naming the remote file after being altered by any ntrans or nmap setting. File transfer uses the current settings for type format mode and structure
- ascii
- Set the file transfer type to network ASCII This is the default type.
- bell
- Arrange that a bell be sounded after each file transfer command is completed.
- binary
- Set the file transfer type to support binary image transfer.
- bye
- Terminate the FTP session with the remote server and exit ftp An end of file will also terminate the session and exit.
- case
- Toggle remote computer file name case mapping during mget commands. When case is on (default is off), remote computer file names with all letters in upper case are written in the local directory with the letters mapped to lower case.
- cd remote-directory
- Change the working directory on the remote machine to remote-directory
- cdup
- Change the remote machine working directory to the parent of the current remote machine working directory.
- chmod mode file-name
- Change the permission modes of the file file-name on the remote sytem to mode
- close
- Terminate the FTP session with the remote server, and return to the command interpreter. Any defined macros are erased.
- cr
- Toggle carriage return stripping during ascii type file retrieval. Records are denoted by a carriage return/linefeed sequence during ascii type file transfer. When cr is on (the default), carriage returns are stripped from this sequence to conform with the UNIX single linefeed record delimiter. Records on non- UNIX remote systems may contain single linefeeds; when an ascii type transfer is made, these linefeeds may be distinguished from a record delimiter only when cr is off.
- delete remote-file
- Delete the file remote-file on the remote machine.
- debug [debug-value ]
- Toggle debugging mode. If an optional debug-value is specified it is used to set the debugging level. When debugging is on, ftp prints each command sent to the remote machine, preceded by the string `-->'
- dir [remote-directory ] [local-file ]
- Print a listing of the directory contents in the directory, remote-directory and, optionally, placing the output in local-file If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving dir output. If no directory is specified, the current working directory on the remote machine is used. If no local file is specified, or local-file is -, output comes to the terminal.
- Print a listing of the directory contents in the directory, remote-directory and, optionally, placing the output in local-file If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving dir output. If no directory is specified, the current working directory on the remote machine is used. If no local file is specified, or local-file is -, output comes to the terminal.
- disconnect
- A synonym for close
- form format
- Set the file transfer form to format The default format is file.
- get remote-file [local-file ]
- Retrieve the remote-file and store it on the local machine. If the local file name is not specified, it is given the same name it has on the remote machine, subject to alteration by the current case ntrans and nmap settings. The current settings for type form mode and structure are used while transferring the file.
- glob
- Toggle filename expansion for mdelete mget and mput If globbing is turned off with glob the file name arguments are taken literally and not expanded. Globbing for mput is done as in csh(1). For mdelete and mget each remote file name is expanded separately on the remote machine and the lists are not merged. Expansion of a directory name is likely to be different from expansion of the name of an ordinary file: the exact result depends on the foreign operating system and ftp server, and can be previewed by doing `mls' remote-files - Note: mget and mput are not meant to transfer entire directory subtrees of files. That can be done by transferring a tar(1) archive of the subtree (in binary mode).
- hash
- Toggle hash-sign (``#'') printing for each data block transferred. The size of a data block is 1024 bytes.
- help [command ]
- Print an informative message about the meaning of command If no argument is given, ftp prints a list of the known commands.
- idle [seconds ]
- Set the inactivity timer on the remote server to seconds seconds. If seconds is ommitted, the current inactivity timer is printed.
- lcd [directory ]
- Change the working directory on the local machine. If no directory is specified, the user's home directory is used.
- ls [remote-directory ] [local-file ]
- Print a listing of the contents of a directory on the remote machine. The listing includes any system-dependent information that the server chooses to include; for example, most UNIX systems will produce output from the command `ls' -l . (See also nlist . If remote-directory is left unspecified, the current working directory is used. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving ls output. If no local file is specified, or if local-file is `- ' the output is sent to the terminal.
- Print a listing of the contents of a directory on the remote machine. The listing includes any system-dependent information that the server chooses to include; for example, most UNIX systems will produce output from the command `ls' -l . (See also nlist . If remote-directory is left unspecified, the current working directory is used. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving ls output. If no local file is specified, or if local-file is `- ' the output is sent to the terminal.
- macdef macro-name
- Define a macro. Subsequent lines are stored as the macro macro-name a null line (consecutive newline characters in a file or carriage returns from the terminal) terminates macro input mode. There is a limit of 16 macros and 4096 total characters in all defined macros. Macros remain defined until a close command is executed. The macro processor interprets `$' and `\' as special characters. A `$' followed by a number (or numbers) is replaced by the corresponding argument on the macro invocation command line. A `$' followed by an `i' signals that macro processor that the executing macro is to be looped. On the first pass `$i' is replaced by the first argument on the macro invocation command line, on the second pass it is replaced by the second argument, and so on. A `\' followed by any character is replaced by that character. Use the `\' to prevent special treatment of the `$'.
- mdelete [remote-files ]
- Delete the remote-files on the remote machine.
- mdir remote-files local-file
- Like dir except multiple remote files may be specified. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving mdir output.
- mget remote-files
- Expand the remote-files on the remote machine and do a get for each file name thus produced. See glob for details on the filename expansion. Resulting file names will then be processed according to case ntrans and nmap settings. Files are transferred into the local working directory, which can be changed with `lcd' directory ; new local directories can be created with `!' mkdir directory .
- mkdir directory-name
- Make a directory on the remote machine.
- mls remote-files local-file
- Like nlist except multiple remote files may be specified, and the local-file must be specified. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving mls output.
- mode [mode-name ]
- Set the file transfer mode to mode-name The default mode is stream mode.
- modtime file-name
- Show the last modification time of the file on the remote machine.
- mput local-files
- Expand wild cards in the list of local files given as arguments and do a put for each file in the resulting list. See glob for details of filename expansion. Resulting file names will then be processed according to ntrans and nmap settings.
- newer file-name [local-file ]
- Get the file only if the modification time of the remote file is more recent that the file on the current system. If the file does not exist on the current system, the remote file is considered newer Otherwise, this command is identical to get
- nlist [remote-directory ] [local-file ]
- Print a list of the files in a directory on the remote machine. If remote-directory is left unspecified, the current working directory is used. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving nlist output. If no local file is specified, or if local-file is -, the output is sent to the terminal.
- Print a list of the files in a directory on the remote machine. If remote-directory is left unspecified, the current working directory is used. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving nlist output. If no local file is specified, or if local-file is -, the output is sent to the terminal.
- nmap [inpattern outpattern ]
- Set or unset the filename mapping mechanism. If no arguments are specified, the filename mapping mechanism is unset. If arguments are specified, remote filenames are mapped during mput commands and put commands issued without a specified remote target filename. If arguments are specified, local filenames are mapped during mget commands and get commands issued without a specified local target filename. This command is useful when connecting to a non- UNIX remote computer with different file naming conventions or practices. The mapping follows the pattern set by inpattern and outpattern [Inpattern ] is a template for incoming filenames (which may have already been processed according to the ntrans and case settings). Variable templating is accomplished by including the sequences `$1', `$2', ..., `$9' in inpattern Use `\' to prevent this special treatment of the `$' character. All other characters are treated literally, and are used to determine the nmap [inpattern ] variable values. For example, given inpattern $1.$2 and the remote file name "mydata.data", $1 would have the value "mydata", and $2 would have the value "data". The outpattern determines the resulting mapped filename. The sequences `$1', `$2', ...., `$9' are replaced by any value resulting from the inpattern template. The sequence `$0' is replace by the original filename. Additionally, the sequence `[seq1 ] ' , Ar seq2 is replaced by [seq1 ] if seq1 is not a null string; otherwise it is replaced by seq2 For example, the command
nmap $1.$2.$3 [$1,$2].[$2,file]
would yield the output filename "myfile.data" for input filenames "myfile.data" and "myfile.data.old", "myfile.file" for the input filename "myfile", and "myfile.myfile" for the input filename ".myfile". Spaces may be included in outpattern as in the example: `nmap $1 sed "s/ *$//" > $1' . Use the `\' character to prevent special treatment of the `$','[','[', and `,' characters.
- ntrans [inchars [outchars ] ]
- Set or unset the filename character translation mechanism. If no arguments are specified, the filename character translation mechanism is unset. If arguments are specified, characters in remote filenames are translated during mput commands and put commands issued without a specified remote target filename. If arguments are specified, characters in local filenames are translated during mget commands and get commands issued without a specified local target filename. This command is useful when connecting to a non- UNIX remote computer with different file naming conventions or practices. Characters in a filename matching a character in inchars are replaced with the corresponding character in outchars If the character's position in inchars is longer than the length of outchars the character is deleted from the file name.
- open host [port ]
- Establish a connection to the specified host FTP server. An optional port number may be supplied, in which case, ftp will attempt to contact an FTP server at that port. If the auto-login option is on (default), ftp will also attempt to automatically log the user in to the FTP server (see below).
- prompt
- Toggle interactive prompting. Interactive prompting occurs during multiple file transfers to allow the user to selectively retrieve or store files. If prompting is turned off (default is on), any mget or mput will transfer all files, and any mdelete will delete all files.
- proxy ftp-command
- Execute an ftp command on a secondary control connection. This command allows simultaneous connection to two remote ftp servers for transferring files between the two servers. The first proxy command should be an open to establish the secondary control connection. Enter the command "proxy ?" to see other ftp commands executable on the secondary connection. The following commands behave differently when prefaced by proxy open will not define new macros during the auto-login process, close will not erase existing macro definitions, get and mget transfer files from the host on the primary control connection to the host on the secondary control connection, and put mput and append transfer files from the host on the secondary control connection to the host on the primary control connection. Third party file transfers depend upon support of the ftp protocol PASV command by the server on the secondary control connection.
- put local-file [remote-file ]
- Store a local file on the remote machine. If remote-file is left unspecified, the local file name is used after processing according to any ntrans or nmap settings in naming the remote file. File transfer uses the current settings for type format mode and structure
- pwd
- Print the name of the current working directory on the remote machine.
- quit
- A synonym for bye
- quote arg1 arg2 ...
- The arguments specified are sent, verbatim, to the remote FTP server.
- recv remote-file [local-file ]
- A synonym for get.
- reget remote-file [local-file ]
- Reget acts like get, except that if local-file exists and is smaller than remote-file local-file is presumed to be a partially transferred copy of remote-file and the transfer is continued from the apparent point of failure. This command is useful when transferring very large files over networks that are prone to dropping connections.
- remotehelp [command-name ]
- Request help from the remote FTP server. If a command-name is specified it is supplied to the server as well.
- remotestatus [file-name ]
- With no arguments, show status of remote machine. If file-name is specified, show status of file-name on remote machine.
- rename [from ] [to ]
- Rename the file from on the remote machine, to the file to
- Rename the file from on the remote machine, to the file to
- reset
- Clear reply queue. This command re-synchronizes command/reply sequencing with the remote ftp server. Resynchronization may be necessary following a violation of the ftp protocol by the remote server.
- restart marker
- Restart the immediately following get or put at the indicated marker On UNIX systems, marker is usually a byte offset into the file.
- rmdir directory-name
- Delete a directory on the remote machine.
- runique
- Toggle storing of files on the local system with unique filenames. If a file already exists with a name equal to the target local filename for a get or mget command, a ".1" is appended to the name. If the resulting name matches another existing file, a ".2" is appended to the original name. If this process continues up to ".99", an error message is printed, and the transfer does not take place. The generated unique filename will be reported. Note that runique will not affect local files generated from a shell command (see below). The default value is off.
- send local-file [remote-file ]
- A synonym for put.
- sendport
- Toggle the use of PORT commands. By default, ftp will attempt to use a PORT command when establishing a connection for each data transfer. The use of PORT commands can prevent delays when performing multiple file transfers. If the PORT command fails, ftp will use the default data port. When the use of PORT commands is disabled, no attempt will be made to use PORT commands for each data transfer. This is useful for certain FTP implementations which do ignore PORT commands but, incorrectly, indicate they've been accepted.
- site arg1 arg2 ...
- The arguments specified are sent, verbatim, to the remote FTP server as a SITE command.
- size file-name
- Return size of file-name on remote machine.
- status
- Show the current status of ftp
- struct [struct-name ]
- Set the file transfer structure to struct-name By default stream structure is used.
- sunique
- Toggle storing of files on remote machine under unique file names. Remote ftp server must support ftp protocol STOU command for successful completion. The remote server will report unique name. Default value is off.
- system
- Show the type of operating system running on the remote machine.
- tenex
- Set the file transfer type to that needed to talk to TENEX machines.
- trace
- Toggle packet tracing.
- type [type-name ]
- Set the file transfer type to type-name If no type is specified, the current type is printed. The default type is network ASCII
- umask [newmask ]
- Set the default umask on the remote server to newmask If newmask is ommitted, the current umask is printed.
- user user-name [password ] [account ]
- Identify yourself to the remote FTP server. If the password is not specified and the server requires it, ftp will prompt the user for it (after disabling local echo). If an account field is not specified, and the FTP server requires it, the user will be prompted for it. If an account field is specified, an account command will be relayed to the remote server after the login sequence is completed if the remote server did not require it for logging in. Unless ftp is invoked with auto-login disabled, this process is done automatically on initial connection to the FTP server.
- Identify yourself to the remote FTP server. If the password is not specified and the server requires it, ftp will prompt the user for it (after disabling local echo). If an account field is not specified, and the FTP server requires it, the user will be prompted for it. If an account field is specified, an account command will be relayed to the remote server after the login sequence is completed if the remote server did not require it for logging in. Unless ftp is invoked with auto-login disabled, this process is done automatically on initial connection to the FTP server.
- verbose
- Toggle verbose mode. In verbose mode, all responses from the FTP server are displayed to the user. In addition, if verbose is on, when a file transfer completes, statistics regarding the efficiency of the transfer are reported. By default, verbose is on.
- ? [command ]
- A synonym for help.
Command arguments which have embedded spaces may be quoted with quote `"' marks.
ABORTING A FILE TRANSFER
To abort a file transfer, use the terminal interrupt key (usually Ctrl-C). Sending transfers will be immediately halted. Receiving transfers will be halted by sending a ftp protocol ABOR command to the remote server, and discarding any further data received. The speed at which this is accomplished depends upon the remote server's support for ABOR processing. If the remote server does not support the ABOR command, an `ftp>' prompt will not appear until the remote server has completed sending the requested file.
The terminal interrupt key sequence will be ignored when ftp has completed any local processing and is awaiting a reply from the remote server. A long delay in this mode may result from the ABOR processing described above, or from unexpected behavior by the remote server, including violations of the ftp protocol. If the delay results from unexpected remote server behavior, the local ftp program must be killed by hand.
FILE NAMING CONVENTIONS
Files specified as arguments to ftp commands are processed according to the following rules.
- If the file name `- ' is specified, the stdin (for reading) or stdout (for writing) is used.
- If the first character of the file name is `' the remainder of the argument is interpreted as a shell command. Ftp then forks a shell, using popen(3) with the argument supplied, and reads (writes) from the stdout (stdin). If the shell command includes spaces, the argument must be quoted; e.g. " ls -lt". A particularly useful example of this mechanism is: dir more.
- Failing the above checks, if ``globbing'' is enabled, local file names are expanded according to the rules used in the csh(1); c.f. the glob command. If the ftp command expects a single local file (.e.g. put ) only the first filename generated by the "globbing" operation is used.
- For mget commands and get commands with unspecified local file names, the local filename is the remote filename, which may be altered by a case ntrans or nmap setting. The resulting filename may then be altered if runique is on.
- For mput commands and put commands with unspecified remote file names, the remote filename is the local filename, which may be altered by a ntrans or nmap setting. The resulting filename may then be altered by the remote server if sunique is on.
FILE TRANSFER PARAMETERS
The FTP specification specifies many parameters which may affect a file transfer. The type may be one of ascii, image (binary), ebcdic, and local byte size (for PDP -10's and PDP -20's mostly). Ftp supports the ascii and image types of file transfer, plus local byte size 8 for tenex mode transfers.
Ftp supports only the default values for the remaining file transfer parameters: mode form and struct
EXAMPLES
ftp abc.xyz.edu
This command will attempt to connect to the ftp server at abc.xyz.edu. If it succeeds, it will ask you to log in using a username and password. Public ftp servers often allow you to log in using the username "anonymous" and your email address as password. Once you are logged in you can get a list of the available ftp commands using the help function:
ftp> help
This lists the commands that you can use to show the directory contents, transfer files, and delete files.
ftp> ls
This command prints the names of the files and subdirectories in the current directory on the remote computer.
ftp> cd customers
This command changes the current directory to the subdirecotry "customers", if it exists.
ftp> cd ..
Changes the current directory to the parent direcotry.
ftp> lcd images
Changes the current directory on the local computer to "images", if it exists.
ftp> ascii
Changes to "ascii" mode for transferring text files.
ftp> binary
Changes to "binary" mode for transferring all files that are not text files.
ftp> get image1.jpg
Downloads the file image1.jpg from the remote computer to the local computer. Warning: If there already is file with the same name it will be overwritten.
ftp> put image2.jpg
Uploads the file image2.jpg from the local computer to the remote computer. Warning: If there already is file with the same name it will be overwritten.
ftp> !ls
A '!' in front will execute the specified command on the local computer. So '!ls' lists the file names and directory names of the current directory on the local computer.
ftp> mget *.jpg
With mget you can download multiple images. This command downloads all files that end with ".jgp".
ftp> mput *.jpg
Uploads all files that end with ".jgp".
ftp> mdelete *.jpg
Deletes all files that end with ".jgp".
ftp> prompt
Turns iteractive mode on or off so that commands on multiple files are executed without user confirmation.
ftp> quit
Exits the ftp program.
SEE ALSO
List of FTP commands for the Microsoft command-line FTP client
Command-line options
As you're starting the program from a DOS prompt:
ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]
- -v - Suppresses verbose display of remote server responses.
- -n - Suppresses auto-login upon initial connection.
- -i - Turns off interactive prompting during multiple file transfers.
- -d - Enables debugging, displaying all ftp commands passed between the client and server.
- -g - Disables filename globbing, which permits the use of wildcard chracters in local file and path names.
- -s:filename - Specifies a text file containing ftp commands; the commands will automatically run after ftp starts. No spaces are allowed in this parameter. Use this switch instead of redirection (>).
- -a - Use any local interface when binding data connection.
- -w:windowsize - Overrides the default transfer buffer size of 4096.
- computer - Specifies the computer name or IP address of the remote computer to connect to. The computer, if specified, must be the last parameter on the line.
Client commands
- ! - Runs the specified command on the local computer
- ? - Displays descriptions for ftp commands
- append - Appends a local file to a file on the remote computer
- ascii - Sets the file transfer type to ASCII, the default
- bell - Toggles a bell to ring after each file transfer command is completed (default = OFF)
- binary - Sets the file transfer type to binary
- bye - Ends the FTP session and exits ftp
- cd - Changes the working directory on the remote computer
- close - Ends the FTP session and returns to the command interpreter
- debug - Toggles debugging (default = OFF)
- delete - Deletes a single file on a remote computer
- dir - Displays a list of a remote directory's files and subdirectories
- disconnect - Disconnects from the remote computer, retaining the ftp prompt
- get - Copies a single remote file to the local computer
- glob - Toggles filename globbing (wildcard characters) (default = ON)
- hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF)
- help - Displays descriptions for ftp commands
- lcd - Changes the working directory on the local computer
- literal - Sends arguments, verbatim, to the remote FTP server
- ls - Displays an abbreviated list of a remote directory's files and subdirectories
- mdelete - Deletes one or more files on a remote computer
- mdir - Displays a list of a remote directory's files and subdirectories
- mget - Copies one or more remote files to the local computer
- mkdir - Creates a remote directory
- mls - Displays an abbreviated list of a remote directory's files and subdirectories
- mput - Copies one or more local files to the remote computer
- open - Connects to the specified FTP server
- prompt - Toggles prompting (default = ON)
- put - Copies a single local file to the remote computer
- pwd - Displays the current directory on the remote computer (literally, "print working directory")
- quit - Ends the FTP session with the remote computer and exits ftp (same as "bye")
- quote - Sends arguments, verbatim, to the remote FTP server (same as "literal")
- recv - Copies a remote file to the local computer
- remotehelp - Displays help for remote commands
- rename - Renames remote files
- rmdir - Deletes a remote directory
- send - Copies a local file to the remote computer (same as "put")
- status - Displays the current status of FTP connections
- trace - Toggles packet tracing (default = OFF)
- type - Sets or displays the file transfer type (default = ASCII)
- user - Specifes a user to the remote computer
- verbose - Toggles verbose mode (default = ON)
2009-04-07
ตัวแปร (Variables)
ตัวแปรจะเป็นชื่อที่ใช้ในการบอกจำนวนหรือปริมาณ ซึ่งสามารถที่จะทำการเปลี่ยนแปลงจำนวนได้ด้วยโปรแกรมคอมพิวเตอร์ การตั้งชื่อตัวแปร จะต้องตั้งชื่อให้แตกต่างไปจากชื่อของตัวแปรอื่นๆ ยกตัวอย่างชื่อของตัวแปร ได้แก่ x, y, peter, num_of_points และ streetnum เป็นต้น โดยปกติการเขียนโปรแกรมที่ดี ควรจะตั้งชื่อตัวแปรให้สอดคล้องกับการทำงานหรือหน้าที่ของตัวแปรนั้นๆ เพราะเมื่อถึงเวลาต้องมาทำการปรับปรุงแก้ไขโปรแกรม จะสามารถทำได้โดยไม่ยากนัก
ในภาษา C หรือ C++ ได้มีกฏในการตั้งชื่อตัวแปรที่สามารถใช้งานได้ดังนี้- ชื่อตัวแปรจะต้องขึ้นต้นด้วยตัวอักษร- ชื่อตัวแปรจะประกอบไปด้วย ตัวอักษร ตัวแลข และ _ ได้เท่านั้น- ชื่อตัวแปรจะต้องไม่ใช่ชื่อ reserved word (ชื่อที่มีการจองไว้แล้ว)
ตัวอย่างของชื่อตัวแปรที่สามารถนำมาใช้ตั้งชื่อได้ ได้แก่length, days_in_year, DataSet1, Profit95, Pressure, first_one
และตัวอย่างของชื่อ ที่ไม่สามารถนำมาใช้เป็นชื่อตัวแปรได้ ยกตัวอย่างเช่นday-in-year, 1data, int, first.val เป็นต้น
reserved word (ชื่อที่มีการจองไว้แล้ว)
Reserved words หรือตัวแปรที่ได้จองไว้แล้วนั้น จะประกอบไปด้วยตัวอักษรตัวเล็กทั้งหมด และจะมีความสำคัญสำหรับภาษา C++ และจะไม่นำมาใช้ด้วยวัตถุประสงค์อื่นๆ ตัวอย่างของ Reserved words ได้แก่ and, bool, break, case, catch, char, class, continue, default, delete, do, double, if , else, enum, export, extern เป็นต้น
นอกจากนี้ในภาษา C หรือ C++ ชื่อตัวแปร ที่ประกอบไปด้วยอักษรเล็ก หรือใหญ่ ก็มีความแตกต่างกัน หรือที่เรียกว่า Case sensitive ยกตัวอย่างเช่น
‘X’ และ ‘x’ เป็นตัวแปรต่างกัน ‘peter’ และ ‘Peter’ เป็นตัวแปรต่างกัน‘bookno1’ และ ‘bookNo1’ เป็นตัวแปรต่างกัน‘XTREME’ และ ‘xtreme’ เป็นตัวแปรต่างกัน‘X1’ และ ‘x1’ เป็นตัวแปรต่างกัน‘int’ และ ‘Int’ เป็นตัวแปรต่างกัน
การกำหนดชนิดของตัวแปร (Declaration of Variables)
ในภาษา C หรือ C++ (และโปรแกรมในภาษาอื่นๆ) ตัวแปรทุกตัวที่จะมีการเรียกใช้ในโปรแกรมจำเป็นต้องมีการกำหนดชนิดของตัวแปรนั้นๆ ก่อนที่จะทำการเรียกใช้ตัวแปร
การกำหนดชนิดของตัวแปรมีวัตถุประสงค์หลัก 2 ประการได้แก่- เป็นการบอกชนิด และตั้งชื่อตัวแปรที่จะเรียกใช้ ชนิดของตัวแปรจะทำให้คอมไพเลอร์สามารถแปลคำสั่งได้อย่างถูกต้อง (ยกตัวอย่างเช่น ใน CPU คำสั่งที่ใช้ในการบวกตัวเลขจำนวนเต็ม 2 จำนวน ย่อมแตกต่างจากคำสั่งที่จะบวกจำนวนจริง 2 จำนวนเข้าด้วยกัน)- ชนิดของตัวแปร ยังเป็นบ่งบอกคอมไพเลอร์ให้ทราบว่าจะต้องจัดเตรียมเนื้อที่ให้กับตัวแปรตัวนั้นมากน้อยเท่าใด และจะจัดวางตัวแปรนั้นไว้แอดเดรส (Address) ไหนที่สามารถเรียกมาใช้ใน code ได้
สำหรับในบทความนี้จะพิจารณาชนิดตัวแปร 4 ชนิดที่ใช้กันมากได้แก่ int, float, bool และ char
int ชนิดตัวแปรที่สามารถแทนค่าจำนวนเต็มได้ทั้งบวกและลบ โดยปกติสำหรับคอมพิวเตอร์ทั่วไป คอมไพเลอร์ จะจองเนื้อที่ 2 ไบต์ สำหรับตัวแปรชนิด int จึงทำให้ค่าของตัวแปรมีค่าตั้งแต่ -32768 ถึง +32768 ตัวอย่างของค่า int ได้แก่ 123 -56 0 5645 เป็นต้น
floatชนิดของตัวแปรที่เป็นตัวแทนของจำนวนจริง หรือตัวเลขที่มีค่าทศนิยม ความละเอียดของตัวเลขหลังจุดทศนิยมขึ้นอยู่กับระบบคอมพิวเตอร์ โดยปกติแล้ว ตัวแปรชนิด float จะใช้เนื้อที่ 4 ไบต์ นั่นคือจะให้ความละเอียดของตัวเลขหลังจุดทศนิยม 6 ตำแหน่ง และมีค่าอยู่ระหว่าง -1038 ถึง +1038ตัวอย่างของค่า float ได้แก่ 16.315 -0.67 31.567
bool ชนิดของตัวแปรที่สามารถเก็บค่าลอจิก จริง (True) หรือ เท็จ (False) ตัวแปรชนิดนี้ เป็นที่รู้จักกันอีกชื่อคือ ตัวแปรบูลีน (Boolean)ตัวอย่างของตัวแปรชนิด bool ได้แก่ 1 0 true false (เมื่อ 1 = true และ 0 = false)
char เป็นชนิดตัวแปรที่เป็นตัวแทนของ ตัวอักษรเพียงตัวเดียว อาจเป็นตัวอักษร ตัวเลข หรือตัวอักขระพิเศษ โดยปกติตัวแปรชนิดนี้จะใช้เนื้อที่เพียง 1 ไบต์ ซึ่งจะให้ตัวอักษรในรูปแบบที่แตกต่างกันได้ถึง 256 ค่า การเขียนรูปแบบของ char หลายๆ ตัว โดยปกติ จะอ้างอิงกับ American Standard Code for Information Interchange (ASCII)ตัวอย่างของตัวแปรชนิด char ได้แก่ '+' 'A' 'a' '*' '7'
การกำหนดชนิดของตัวแปร สามารถเขียนได้อยู่ในรูป type identifier-list; เมื่อ type บ่งบอกชนิดของตัวแปร ส่วน identifier-list เป็นการกำหนดชื่อของตัวแปร ซึ่งอาจจะมีมากกว่า 1 ตัวแปร และจะแยกตัวแปรแต่ละตัวออกจากกันด้วยเครื่องหมาย comma (,) ตัวอย่าง รูปแบบของการกำหนดชนิดของตัวแปร ได้แก่
int i, j, count; float sum, product; char ch; bool passed_exam;
มาถึงตอนนี้ เราก็จะสามารถปรับปรุงการเขียนโปรแกรมแบบง่ายๆ ได้ดังนี้
#include main(){ int its_price; printf("How much is that ? "); scanf("%d", &its_price); printf("oh! %d ?, hmmm...., too expensivenn",its_price);}
จาก code ข้างบน ผู้อ่านจะเห็น %d เมื่อมีการเรียกใช้ฟังก์ชัน scanf และ printf ทั้งนี้ %d จะเป็น format ที่ใช้บ่งบอกชนิดของตำแหน่ง (Place Holders) ที่จะมีการส่งข้อมูล โดยในที่นี้ %d หมายถึงตำแหน่งของจำนวนเต็ม หรือ int นั่นเอง ตัวอย่างของ Place Holders อื่นๆ สามารถแสดงได้ดังตาราง
คราวนี้ลองมาดูตัวอย่างของการใช้ Place Holders
printf("C=%f, F=%f",cel,fah);printf("He wants to score %d goals today",9);
เมื่อ % เป็นการบ่งบอกตำแหน่งเริ่มต้นของ Place Holder จากนั้นตัวอักษร f ตัวแรก จะบ่งบอกถึง ตัวแปรcel ว่ามีค่าเป็นจำนวนจริง (Float) ส่วน f ตัวทีสอง จะบ่งบอกคอมไพเลอร์ว่า ตัวแปร fah ก็มีค่าเป็นจำนวนจริงเช่นกัน
นอกจากนี้ Place holder %d และ %f ยังสามารถใช้กับการกำหนดตำแหน่งตัวเลขตามต้องการได้ ยกตัวอย่างเช่น สมมุติให้ x=235; และ y=6।54321;
การให้กำหนดค่าตัวแปร (Variable Assignment) เราสามารถกำหนดค่าให้กับตัวแปรได้ ด้วยเครื่องหมาย = ยกตัวอย่างเช่น int name; // กำหนดตัวแปร name ที่เก็บค่าจำนวนเต็มname = 23; // กำหนดให้ตัวแปร name มีค่าเป็น 23ในขณะเดียวกัน เราสามารถใช้เครื่องหมาย = ระหว่างตัวแปรกับตัวแปร หรือตัวแปรกับจำนวนใดๆ ได้ อาทิเช่นchange = x1 - x2;
mean = (x1 + x2)/2;
x = x + 1;ตอนนี้เราลองมาเขียนโปรแกรมอย่างง่าย เพื่อทำการแก้ปัญหาทางคณิตศาสตร์ ด้วยการแปลงค่า อุณหภูมิ ในหน่วยของ ฟาเรนไฮต์ เป็น เซลเซียส เมื่ออุณหภูมิในหน่วยฟาเรนไฮต์ มีค่า = 85 และเป็นที่ทราบกันดีว่า ความสัมพันธ์ระหว่าง องศาฟาเรนไฮต์ และ เซลเซียส สามารถเขียนได้อยู่ในรูปของสมการ
การเขียนโปรแกรม เพื่อแก้ปัญหา การแปลงค่า 85 ฟาเรนไฮต์ให้เป็นเซลเซียส สามารถเขียนได้ดังนี้
#include void main(){ float F; float C;
F = 85; C = 5*(F-32)/9; printf("the result is %f",C);}
อีกตัวอย่าง ของโปรแกรม การบวกค่าจำนวนเต็ม 2 จำนวนเข้าด้วยกัน แล้วแสดงผลลัพธ์ออกทางหน้าจอ การเขียนโปรแกรมเพื่อแก้ปัญหานี้ สามารถเขียนได้ดังนี้
#include void main(){ int N1, N2, Sum; printf("please input an integer number : "); scanf("%d",&N1); printf("please input another integer number : "); scanf("%d",&N2);
Sum = N1 + N2; printf("so, %d + %d = %d",N1,N2,Sum);}
จากตัวอย่างการเขียนโปรแกรมข้างต้น จะเห็นว่ามีการคำนวณทางคณิตศาสตร์เข้ามาเกี่ยวข้อง คราวนี้เราลองมาดู การคำนวณในภาษา C กันว่าจะเขียนกันได้อย่างไรบ้าง
พื้นฐานโปรแกรมภาษา C
ฝึกฝนและพัฒนาการเขียนโปรแกรมภาษา CIntroduction to C Programming
การพัฒนาโปรแกรมคอมพิวเตอร์ บางคนก็ว่ายาก บางคนก็ว่าเป็นเรื่องสนุก หลายคนบอกว่า ขอเป็นแค่ผู้ใช้สนุกที่สุด แต่จะมีซักกี่คนที่จะมีใจรักที่จะก้าวไปบนถนนแห่งการพัฒนาฝีมือและฝึกฝนการเขียนโปรแกรมด้วยตัวเอง เพื่อให้มีผู้ที่สนใจนำไปใช้งาน และเพิ่มประสิทธิ์ภาพในการทำงาน และ ความสะดวกสบายๆ ต่างๆมากขึ้น ว่าไปแล้วนักโปรแกรมเมอร์เหล่านี้ ก็ไม่แตกต่างจากผู้ที่ปิดทองหลังพระมากนัก เพราะหลายๆ โปรแกรมที่มีให้ใช้งานกันในปัจจุบัน จะมีใครทราบบ้างไหมว่า ผู้เขียนโปรแกรมเหล่านั้นมีใครกันบ้าง ดังนั้น ผู้ที่คิดจะก้าวมาเป็นนักพัฒนาโปรแกรมมืออาชีพ คงต้องอาศัยใจรักที่จะอยากจะพัฒนา และฝึกฝนฝืมือในการเป็นโปรแกมเมอร์มืออาชีพมาเป็นอันดับหนึ่ง สำหรับบทความนี้จะเริ่มต้นด้วยการสอนให้เข้าใจในหลักการพื้นฐานของการการพัฒนาโปรแกรมในภาษา C ความรู้และความเข้าใจที่จำเป็นต่อการเป็นโปรแกรมเมอร์มืออาชีพในอนาคต เราลองเริ่มมาเรียนรู้กันอย่างคร่าวๆ กันเลยล่ะกัน โดยผู้เขียนจะอธิบายเป็นตอนๆ ทั้งหมด 8 ตอนด้วยกันได้แก่
1. พื้นฐานโปรแกรมภาษา C (Introduction to C Programming)2. การเขียนโปรแกรมทางเลือก (Selection Structures)3. การเขียนโปรแกรมแบบ วนซ้ำ (Repetition & Loop)4. ฟังก์ชัน และการเขียนโปรแกรมแยกเป็นโมดูล (Functions & Modular Programming)5. ตารางอาเรย์ (Arrays)6. ตัวแปรพอยเตอร์ (Pointers)7. ตัวแปรสตริง (String)8. โครงสร้างสตักเจอร์ (Structure)
1. พื้นฐานโปรแกรมภาษา C (Introduction to C Programming)
ก่อนอื่นของแนะนำพื้นฐานเกี่ยวกับคอมพิวเตอร์กันซักนิด ก่อนที่จะเริ่มเรียนรู้ภาษา C กัน หน่วยสำคัญที่สุดของคอมพิวเตอร์ก็คือ หน่วยประมวลผลหรือที่เรียกกันว่า CPU โดยปกติ CPU จะมีภาษาของตัวเองที่เรียกว่า ภาษาเครื่อง (Machine Language) ซึ่งจะเป็นภาษาที่ประกอบไปด้วยเลขฐานสองมากมาย ดังนั้นการที่จะเขียนโปรแกรมควบคุมการทำงานของคอมพิวเตอร์ โดยใช้ภาษาเครื่องโดยตรงนั้นจึงทำได้ยาก จึงได้มีการพัฒนาตัวแปรภาษาเครื่องที่เรียกว่า โปรแกรมภาษาระดับสูงขึ้นมา หรือที่เรียกว่า High Level Languages โดยภาษาในระดับสูงเหล่านี้ จะมีลักษณะรูปแบบการเขียน (Syntax) ที่ทำให้เข้าใจได้ง่ายต่อการสื่อสารกับผู้พัฒนา และถูกออกแบบมาให้ง่ายต่อการใช้งาน และจะเปลี่ยนคำสั่งจากผู้ใช้งาน ไปเป็นเป็นภาษาเครื่อง เพื่อที่จะควบคุมการทำงานของคอมพิวเตอร์ต่อไป ตัวอย่างของโปรแกรมภาษาระดับสูง ได้แก่ COBOL ใช้กันมากสำหรับโปรแกรมทางด้านธุรกิจ, Fortran ใช้กันมากสำหรับการพัฒนาโปรแกรมด้านวิทยาศาสตร์และวิศวกรรมศาสตร์ เพราะง่ายต่อการคำนวณ, Pascal มีใช้กันทั่วไป แต่เน้นสำหรับการพัฒนาเครื่องมือสำหรับการเรียนการสอน, C & C++ ใช้ทั่วไป ปัจจุบันมีผู้เลือกที่จะใช้กันอย่างแพร่หลาย, PROLOG เน้นหนักไปทางด้านงานประเภท AI และ JAVA ใช้ได้ทั่วไป ปัจจุบันเริ่มมีผู้หันมาสนใจกันมากและเพิ่มขึ้นอย่างรวดเร็วคราวนี้เราลองมาเตรียมตัวกันซักนิก ก่อนที่จะลงมือพัฒนาโปรแกรมคอมพิวเตอร์ ขั้นแรก เราต้องศึกษารูปแบบความต้องการของโปรแกรมที่จะพัฒนา จากนั้นก็วิเคราะห์ถึงปัญหาตลอดจนวิธีการแก้ปัญหา จากนั้นจึงนำเอาความคิดในการแก้ปัญหาอย่างเป็นขั้นตอน ไปเขียนในรูปแบบของโปรแกรมภาษาในระดับสูง ซึ่งจะอยู่ในรูปแบบของ Source Program หรือ Source Code จากนั้นเราก็จะใช้ Complier ของภาษาที่เราเลือก มาทำการ Compile Source code หรือกล่าวง่ายๆ คือแปลง Source code ของเราให้เป็นภาษาเครื่องนั่นเอง ซึ่งในขั้นตอนนี้ ผลที่ได้ เราจะเรียกว่า Object code จากนั้น Complier ก็จะทำการ Link หรือเชื่อม Object code เข้ากับฟังก์ชันการทำงานใน Libraries ต่างๆ ที่จำเป็นต่อการใช้งาน แล้วนำไปไว้ในหน่วยความจำ แล้วเราก็จะสามารถ Run เพื่อดูผลของการทำงานโปรแกรมได้ หากโปรแกรมมีข้อผิดพลาด เราก็จะทำการแก้ หรือที่เรียกกันในภาษาคอมพิวเตอร์ว่า การ Debug นั่นเองภาษา C เป็นโปรแกรมภาษาระดับสูง ถูกพัฒนาขึ้นในปี 1972 ที่ AT&T Bell Lab เราสามารถใช้ภาษา C มาเขียนเป็นคำสั่งต่างๆ ที่คอมพิวเตอร์สามารถเข้าใจได้ และกลุ่มของคำสั่งเหล่านี้ เราก็เรียกกันว่า อัลกอริธึม ได้มีผู้ให้คำจำกัดความของคำว่า อัลกอริธึม ว่าเป็น “A precise description of a step-by-step process that is guaranteed to terminate after a finite number of steps with a correct answer for every particular instance of an algorithmic problem that may occur.” สำหรับ Compiler ภาษา C ที่มีในปัจจุบัน มี 2 ค่ายใหญ่ๆ ที่มีผู้คนสนใจใช้กันมากได้แก่ Microsoft และ Borland การใช้งาน Compiler ทั้งสองตัวนี้ สามารถเรียนรู้ได้ไม่ยากนัก เราจึงจะมาเริ่มต้นที่การเขียนโปรแกรมในภาษา C กันเลย เราลองมาเริ่มจากตัวอย่างการเขียน ภาษา C แบบ ง่ายๆ กันก่อนกับโปรแกรม Hello World
#include main(){printf("Hello World !! ");}
บรรทัดแรก #include เป็นการบอกว่าให้ทำการรวม Header file ที่ชื่อว่า stdio।h (.h = header) ซึ่งเป็น header ที่เกี่ยวข้องกับการรับและให้ข้อมูล (Standard Input Output) นอกจาก stdio.h แล้ว ก็ยังมี Header อื่นๆ ที่ผู้พัฒนาสามารถที่จะเรียกใช้งาน Function ที่จำเป็นจาก Header นั้นๆ ได้ อาทิเช่น
บรรทัดถัดมาจะเป็นเครื่องหมาย { ซึ่งเป็นเครื่องหมายบ่งบอกขอบเขตของ Function โดยขอบเขตของฟังก์ชัน จะเปิดและปิดโดยใช้เครื่องหมายเปิด { และเครื่องหมายปิด } ตามลำดับ ภายใน Function main() จะมีคำสั่ง (Statement) printf("Hello World !! "); ซึ่ง printf เป็น Function ในภาษา C ทำหน้าที่ให้โปรแกรม ทำการแสดงผลออกทางหน้าจอว่า Hello World !! และทุกครั้ง ผู้พัฒนาจะต้องทำการจบคำสั่งหรือ Statement ด้วยเครื่องหมาย semi-colon ;
ดังนั้นรูปแบบของการเขียนโปรแกรม จึงเขียนออกมาในรูปแบบดังนี้
// ข้อความที่อยู่ข้างหลังเครื่องหมาย // จะเป็นคำอธิบายโปรแกรม #include void main() { constant declarations; // การกำหนดค่าคงที่ต่างๆ variable declarations; // การกำหนดตัวแปรต่างๆexecutable statements; // คำสั่งการทำงานของโปรแกรม}
การอ่านข้อมูลและการแสดงผล (Input & Output)
รูปแบบการใช้งานฟังก์ชัน printf จะทำการพิมพ์ในรูปแบบที่ เริ่มต้นด้วย Format ที่ต้องการจะพิมพ์ และตามด้วยตัวแปรที่ต้องการพิมพ์ ดังนี้
printf( const char *format [, argument]... );
สำหรับการนำข้อมูลเข้าก็เช่นกัน จะใช้ฟังก์ชัน scanf ซึ่งจะเป็นฟังก์ชันสำหรับอ่านข้อมูลจากคีย์บอร์ด และจะนำข้อมูลที่ User ทำการพิมพ์ไปเก็บไว้ใน argument โดยแต่ละ argument จะต้องเป็นตัวแปรที่เรียกว่า pointer (รายละเอียดจะได้กล่าวต่อไป) และมีชนิดที่ตัวแปรที่สัมพันธ์กับที่ได้กำหนดไว้ใน Format รูปแบบการใช้งานของฟังก์ชัน scanf สามารถเขียนได้ดังนี้
scanf( const char *format [,argument]... );
2009-03-03
การกู้ไฟล์ในระบบ UNIX และ LINUX
คุณเคยลบไฟล์ /etc/passwd หรือไม่ ? คุณเคยใช้คำสั่งนี้หรือไม่ # perl updateDB.pl > ./updateDB.pl ? คุณเคยใช้คำสั่ง rm จนเคยตัวทำให้ลบไฟล์ หรือ ไดเรกทรอรี่ใน Home ของตนเองหรือไม่ คาดว่าผู้ใช้หรือผู้ดูแลระบบ UNIX หรือ LINUX ไม่มากก็น้อยย่อมเจอปัญหานี้ คุณจะทำอย่างไรหละ ?? ถ้าในระบบ windows คุณคงจะไปคลิกที่ไอคอล recycle bin แล้วใช้คำสั่ง restore เพื่อเรียกไฟล์พวกนั้นกลับมา หรือ แม้ใช้โปรแกรม Norton Utility เพื่อกู้คืนไฟล์กับมา แล้วใน UNIX หรือ LINUX จะทำอย่างไรดี ??
ในของระบบโครงสร้างไฟล์ใน UNIX หรือ LINUX จะประกอบด้วย inode ที่เก็บข้อมูลต่างๆ เกี่ยวกับไฟล์ เข่น ตำแหน่งของข้อมูลในดิสก์, ข้อมูลความเป็นเจ้าของ ,สิทธิ ,ขนาดของไฟล์ เป็นต้น เมื่อมีการลบไฟล์ระบบจะไม่มีการลบค่าของ inode ทิ้งแต่จะสร้างสัญลักษณ์ให้เป็นช้อมูลที่ว่างเปล่าแทน ดังนั้นข้อมูลที่ลบไปยังคงอยู่ในระบบ ในบทความนี้จะกล่าวถึงวิธีการของการกู้ไฟล์ในระบบ UNIX และ LINUX
การกู้ข้อมูลในระบบ UNIX
ในระบบ UNIX หรือ LINUX จะใช้ระบบของ device file system ในการติดต่อใช้งานข้อมูลระหว่างระบบและ ดิสก์ [1] เข่น ใน /dev/hda ดังนั้นระบบไฟล์จะทำงานใน device ดังกล่าวจะสามารถมองเป็นรูปแบบของ text ไฟล์ได้ ซึ่งการค้นหาและกู้ไฟล์สามารถใช้คำสั่งที่เกียวกับการค้นหาข้อความได้ เช่น grep, seekcat เป็นต้น รูปแบบทั่วไปของคำสั่งที่ใช้ในการเรียกไฟล์ในระบบ UNIX มีดังนี้
grep -a -B[size before] -A[size after] 'text' /dev/[your_partition]
** grep ต้องเป็นเวอร์ชั่นของ GNU
size before ขนาดของข้อมูลที่ต้องการตัดก่อนหน้าข้อความ 'text'
size after ขนาดของข้อมูลที่ต้องการตัดหลังข้อความ 'text'
your_partition ไฟล์ device ของดิสก์
ในบางครั้งโครงสร้างของไฟล์อาจจะไม่ต่อเนื่องกัน ส่งผลทำให้ข้อมูลที่ได้รับเข้ามาอาจจะไม่ถูกต้องตามความต้องการ ดังนั้นเมื่อได้รับผลมาควรใช้ script perl ในการตัดเอาส่วนที่ไม่ต้องการออก แต่อย่างไรก็ตามข้อมูลในส่วนของ CVS และ RCS ที่เป็นข้อมูลเกี่ยวกับไฟล์ที่ต้องการกู้ยังสามารถนำมาส่วนในการค้นหาได้
การกู้ข้อมูลในระบบ LINUX
ระบบ LINUX จะมีโปรแกรมช่วยในการดีบัก device file system ที่เรียกว่า debugfs ในโปรแกรมจะมีคำสั่ง lsdel เพื่อเรียกดูไฟล์ต่างๆ ที่ถูกลบออกจากระบบ
เช่น
# debugfs /dev/hda6
debugfs 1.19, 13-Jul-2000 for EXT2 FS 0.5b, 95/08/09
debugfs: lsdel
1844 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
749300 1000 100664 27018 2/ 7 Tue May 9 19:08:17 2000
749301 1000 100444 1671 1/ 1 Tue May 9 19:08:17 2000
...... .... ...... .... .. ..........................
944887 1037 100600 597 1/ 1 Sat May 26 18:00:00 2001
717281 1000 100400 1 1/ 1 Sat May 26 18:08:13 2001
32605 1000 100644 15 1/ 1 Sat May 26 18:09:06 2001
จากตัวอย่างโปรแกรมจะแสดงค่าต่างๆ ของ inode หากต้องการนำ output แสดงลงไฟล์ทำได้โดยใช้คำสั่ง
# echo lsdel | debugfs /dev/hda6 > /tmp/lsdel-output
ใช้คำสั่ง dump -p เพื่อนำกู้ข้อมูลตามหมายเลข inode เช่น
debugfs: dump -p <32605> /tmp/recovered_file
ดังนั้นในการใช้งานโปรแกรม debugfs เพื่อกู้ไฟล์คืน นั้นจำเป็นต้องมีข้อมูลของไฟล์ดังนี้
- เจ้าของไฟล์เป็นของใคร
- เมื่อไรที่ไฟล์ถูกลบ
- ค่าประมาณของขนาดของไฟล์
หากไฟล์ที่ต้องการค้นหามีจำนวนมากแล้วผู้ใช้ต้องทำการเขียน script เพื่อช่วยค้นหา และ กู้ไฟล์ที่ต้องการ Recover [3] เป็นโปรแกรมแบบ shell script ที่ช่วยในการค้นหาและกู้ไฟล์ ในระบบ LINUX ให้ง่ายในการใช้งาน โปรแกรมจะอาศัยหลักการทำงานของ โปรแกรม debugfs ผ่านคำถามที่เป็นลำดับขั้นเพื่อการค้นหา ไฟล์ที่ผู้ใช้ต้องการ ซึ่งคำถามคร่าวๆ มีดังนี้
- ชื่อของ Device ของดิสก์
- วัน/เดือน/ปี โดยอาจจะบอกเป็นช่วงได้
- ขนาดสูงสุด และต่ำสุดของไฟล์
- ไอดีของผู้ใช้ (User ID)
- ตัวอักษรที่อยู่ในไฟล์
โปรแกรมจะทำการสรุป ค่าของ inode และรายละเอียดของไฟล์ที่ต้องการกู้และข้อมูลที่กู้มาได้
--------------------------------------------------------------------------------
สรุป
เอกสารนี้เป็นจะกล่าวถึงการกู้ไฟล์ในระบบ UNIX และ LINUX รวมทั้งการแนะนำโปรแกรม recover ที่ช่วยในการกู้ไฟล์ในระบบ LINUX ซึ่งในเอกสารนี้จะเป็นแนวทางแก้ผู้ดูแลระบบในการพัฒนาคำสั่ง หรือ script ย่อยเพื่อช่วยในการสร้าง โปรแกรมในการอำนวยความสะดวกของการกู้ไฟล์ที่สำคัญที่ถูกลบไปได้
--------------------------------------------------------------------------------
เอกสารอ้างอิง
[1] UNIX File System: http://www.isu.edu/departments/comcom/unix/workshop/fstour.html
[2] Tales from the Abyss: UNIX File Recovery: http://www.samag.com/documents/s=1441/sam0111b/0111b.htm
[3] Recover Program: http://recover.sourceforge.net/linux/recover/download.php3.
Secure WuFTP Step-by-Step
รูปที่ 1 การเชื่อมต่อผ่านโพรโตคอล FTP
--------------------------------------------------------------------------------
รูปแบบการให้บริการ FTP
การให้บริการ FTP เซิร์ฟเวอร์ที่อนุญาตให้ทุกคนบนอินเตอร์เน็ตสามารถใช้บริการ FTP บนเซิร์ฟเวอร์ได้เรียกว่า Anonymous FTP server ซึ่งเป็นที่นิยมใช้ในการให้บริการการโอนย้ายไฟล์บนอินเตอร์เน็ตโดยใช้โพรโตคอล FTP และเอกสารในส่วนนี้จะกล่าวเน้นเฉพาะวิธีการปรับปรุง Anonymous FTP server ให้มีความปลอดภัยมากขึ้นเท่านั้น
การให้บริการอีกแบบหนึ่งเป็นบริการที่อนุญาตให้ผู้ใช้บนระบบเท่านั้น สามารถใช้บริการโอนย้ายไฟล์ผ่าน FTP ได้ โดยใช้ล็อกอินและรหัสผ่านเดิมในการเข้าสู่ระบบ เรียกบริการนี้ว่า Real FTP server หรือเรียกได้อีกชื่อหนึ่งว่า Private User-only FTP server ข้อควรระวังคือการโอนย้ายไฟล์ผ่าน FTP มีข้อบกพร่องในเรื่องความปลอดภัยของข้อมูล เพราะใช้การสื่อสารข้อมูลแบบเพลนเท็กซ์ฟหรือข้อมูลในการสื่อสารีไม่มีการเข้ารหัสใดๆ ทำให้สามารถดักจับรหัสผ่านในการเข้าสู่ระบบได้โดยง่าย
การให้บริการแบบ Real FTP server สามารถแยกแบบการให้บริการแบบพิเศษอีกแบบหนึ่งได้ เรียกว่า Guest FTP server ซึ่งเป็นบริการที่จะมีการสร้างบัญชีผู้ใช้พิเศษขึ้นมาคนหนึ่งที่เรียกว่า Guest เพื่อใช้สำหรับการเข้ามาใช้บริการ FTP โดยเฉพาะ ผู้ดูแลระบบสามารถจำกัดจำนวนผู้ใช้บริการนี้ได้โดยแจ้งรหัสผ่านของผู้ใชัพิเศษ Guest ให้กับเฉพาะบุคคลที่อนุญาตเท่านั้นได้
ข้อแตกต่างระหว่างการให้บริการแบบ Real FTP server กับ Guest FTP server คือผู้ใช้ที่สามารถเข้ามาใช้บริการ Real FTP server ได้นั้นนอกจากจะเป็นผู้ใช้ที่มีตัวตนจริงในระบบแล้ว ผู้ใช้คนดังกล่าวยังสามารถเข้าถึงไดเรกทอรีในระบบได้ทุกไดเรกทอรีเหมือนกับการล็อกอินเข้ามาตามปกติ แต่ Guest FTP server จะสามารถกำหนดขอบเขตการเข้าถึงไดเรกทอรีที่กำหนดสำหรับผู้ใช้ Guest เท่านั้นได้ การจำกัดขอบเขตการเข้าถึงไดเรกทอรีในระบบจะช่วยเพิ่มความปลอดภัยให้ FTP server และเรียกวิธีการนี้ว่าการ Chroot และเรียกไดเรกทอรีที่จำกัดให้เข้าถึงได้เฉพาะผู้ใช้ Guest ว่า Chroot environment หรือ Chroot Jail
วิธีการ Chroot ใช้สำหรับการจำกัดขอบเขตการเข้าถึงไดเรกทอรีในระบบ ซึ่งจะช่วยเพิ่มความปลอดภัยให้กับบริการ FTP มากยิ่งขึ้น สามารถนำไปประยุกต์ใช้กับการให้บริการ FTP แบบอื่นได้ทั้งแบบ Anonymous FTP server และ Real FTP server ซึ่งถ้าเป็นแบบ Real FTP server แล้วจะทำให้ผู้ใช้ในระบบไม่สามารถเข้าถึงไดเรกทอรีอื่นได้ เป็นข้อสังเกตในเรื่องความสมดุลระหว่างการทำให้บริการ FTP มีความปลอดภัยมากขึ้นหรือทำให้การใช้งานสะดวกมากขึ้น
อย่างไรก็ตาม เนื่องมาจากข้อบกพร่องของการสื่อสารโดยใช้โพรโตคอล FTP เป็นการสื่อสารที่ไม่ได้มีการเข้ารหัส ถ้าเลี่ยงได้ก็ควรเลี่ยงและไม่แนะนำให้เปิดบริการ FTP ในแบบ Real FTP server และ Guest FTP server เพราะมีอัตราความเสี่ยงสูงที่จะถูกดักจับรหัสผ่านได้ หรือควรเลือกใช้โพรโตคอลที่มีการเข้ารหัสในการโอนย้ายไฟล์เช่น โพรโตคอล Secure FTP หรือ SFTP แทน
--------------------------------------------------------------------------------
ไฟล์ configuration สำหรับการเปิดบริการ Anonymous FTP server บน Red Hat Linux
โปรแกรมที่ใช้เป็นบริการ Anonymous FTP Server ในส่วนนี้จะกล่าวถึงโปรแกรม Wu-FTPd เท่านั้น ซึ่งเป็นโปรแกรม ที่ได้รับความนิยมนำไปใช้งานมากโปรแกรมหนึ่ง เพราะ configuration ไม่ซับซ้อน จะขอไม่กล่าวถึงการติดตั้งโปรแกรม Wu-FTPd บน Red Hat Linux เพราะจะถือว่าผู้ดูแลระบบได้เลือกติดตั้งในขั้นตอนการติดตั้ง Red Hat Linux ไปในขั้นต้นแล้ว หรือผู้ดูแลระบบสามารถติดตั้งโดยใช้ RPM ในภายหลังได้
ไฟล์ configuration ของ Wu-FTPd ใน Red Hat Linux ประกอบด้วย (Wu-FTPd ที่ใช้เป็นตัวอย่าง เลือกวิธีการติดตั้งแบบ RPM)
File name Description
/etc/ftpaccess ไฟล์ configuration หลักของ Wu-FTPd
/etc/ftpusers ฐานข้อมูลผู้ใช้ที่ไม่สามารถเข้ามาใช้บริการ Wu-FTPd ได้
/etc/ftphosts ใช้ในการกำหนด Access Control ให้โฮสใดบ้างที่อนุญาตหรือไม่อนุญาตให้เข้ามาใช้บริการ FTP
/etc/ftpgroups กำหนดกลุ่มในการเข้าถึงบริการ FTP
/etc/ftpconversion เก็บคำสั่งที่ใช้สำหรับการบีบข้อมูลการโอนย้ายไฟล์ผ่าน FTP
ตารางที่ 1 ตารางแสดงไฟล์ configuration ของ Wu-FTPd
มีไฟล์ที่ต้องแก้ไขคือ /etc/ftpaccess และ /etc/ftpusers สำหรับไฟล์อื่นสามารถใช้ค่าดีฟอลต์ที่มาจากติดตั้งได้
--------------------------------------------------------------------------------
โครงสร้าง Chroot Environment สำหรับการให้บริการ Anonymous FTP Server
ข้อดีหนึ่งของการติดตั้งโปรแกรมโดยใช้ RPM ของ Red Hat Linux จะช่วยลดขั้นตอนในการติดตั้งโปรแกรมต่างๆ ได้มาก การติดตั้ง Wu-FTPd โดยใช้ RPM นั้นจะมีโครงสร้าง Chroot Environment ที่สามารถใช้งานได้ทันที
ผู้ดูแลระบบควรจะตรวจสอบให้แน่ใจว่ามีการติดตั้งอย่างถูกต้องหรือไม่ โดยตรวจดูในไฟล์ /etc/passwd ว่ามีฟิลด์นี้หรือไม่
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
ฟิลด์ข้างต้นใช้ในการกำหนดผู้ใช้ที่เป็น Anonymous สำหรับการเข้ามาใช้บริการ FTP ในระบบ และยังบอกให้ทราบถึงไดเรกทอรีที่จะใช้เป็น Chroot Environment ของ FTP Server ข้อดีของโปรแกรม Wu-FTPd คือจะใช้วิธี Chroot จำกัดขอบเขตการเข้าถึงไดเรกทอรีในระบบให้โดยอัตโนมัติ โดยเปลี่ยน Chroot Environment ไว้ตามที่กำหนดในฟืลด์ของผู้ใช้ ftp ในไฟล์ /etc/passwd ซึ่งในที่นี้คือ /var/ftp
--------------------------------------------------------------------------------
กำหนดผู้ใช้ที่อนุญาตให้เข้ามาใช้บริการ Anonymous FTP Server
ไฟล์แรกที่ต้องแก้ไขคือไฟล์ /etc/ftpusers เป็นไฟล์ที่ใช้ในการกำหนดชื่อผู้ใช้ที่ไม่อนุญาตให้เข้ามาใช้บริการ FTP ในระบบได้ หมายถึงชื่อผู้ใช้ที่มีชื่ออยู่ในไฟล์ /etc/ftpusers จะไม่สามารถล็อกอินเข้าใช้บริการ Anonymous FTP Server ได้
การเปิดบริการ Anonymous FTP Server จะอนุญาตให้ผู้ใช้ที่ชื่อ ftp เท่านั้นที่สามารถเข้ามาใช้บริการได้ และไม่อนุญาตให้ผู้ใช้อื่นในระบบเข้ามาได้ วิธีการที่ง่ายและรวดเร็วที่สุดคือนำชื่อผู้ใช้ทุกคนที่อยู่ในไฟล์ /etc/passwd มา และลบชื่อ ftp ออก โดยใช้ตำสั่ง
# cat /etc/passwd | awk -F: '{print $1}' > /etc/ftpusers
แล้วลบคำว่า ftp ออกจากไฟล์ /etc/ftpusers
# cat ftpusers
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
gopher
# ftp
nobody
mailnull
rpm
xfs
rpc
rpcuser
nfsnobody
nscd
ident
radvd
pcap
demo
ntp
who
uptime
--------------------------------------------------------------------------------
แก้ไข File Permission ของ /var/ftp
จากที่ได้กล่าวไปแล้วว่าการติดตั้ง Wu-FTPd โดยใช้ RPM นั้นจะมี Chroot Environment ที่เหมาะสมของ Anonymous FTP อยู่ที่ /var/ftp สิ่งที่ต้องทำเพิ่มคือการกำหนด File Permission ให้เหมาะสมด้วยเพื่อเพิ่มความปลอดภัยให้ Anonymous FTP Server
dr-x--x--x 2 root root 4096 Jul 10 23:11 bin
dr-x--x--x 2 root root 4096 Jul 10 23:06 etc
dr-x--x--x 2 root root 4096 Jul 10 23:06 lib
dr-xr-xr-x 4 root root 4096 Jul 20 16:56 pub
จากนั้นแก้ไข File Permission ของไฟล์ configuration ของ Wu-FTPd ด้วยดังนี้
-rw------- 1 root root 1724 Jul 20 18:09 ftpaccess
-rw------- 1 root root 464 Jun 26 2001 ftpconversions
-rw------- 1 root root 39 Jun 26 2001 ftpgroups
-rw------- 1 root root 104 Jun 26 2001 ftphosts
-rw------- 1 root root 173 Jul 20 16:48 ftpusers
--------------------------------------------------------------------------------
แก้ไขไฟล์ configuration ของ Wu-FTPd
ไฟล์ configuration ของ Wu-FTPd คือ /etc/ftpaccess ตามตัวอย่างนี้ได้ปรับแต่งให้มีความปลอดภัยที่สุดแล้ว ซึ่งสามารถคัดลอกไปใช้ได้
# /etc/ftpaccess
# Don't allow system accounts to log in over ftp
deny-uid %-99 %65534-
deny-gid %-99 %65534-
allow-uid ftp
allow-gid ftp
# Class for FTP server
class demo anonymous 192.168.97.*
# Limit number accounts simultaneous login
limit demo 20 /var/ftp/.too_many.msg
email ftpadmin@demo.thaicert.nectec.or.th
# Login fail times
loginfails 3
# Notify the users of README files at login and when
# changing to a different directory
readme README* login
readme README* cwd=*
# Messages displayed to the user
message /.message.welcome login
message .message cwd=*
# Permission
compress yes all
tar yes all
chmod no anonymous
delete no anonymous
overwrite no anonymous
rename no anonymous
umask no anonymous
# Logging
log commands anonymous
log transfers anonymous inbound,outbound
log security anonymous
# If /etc/shutmsg exists, don't allow logins
# see ftpshut man page
shutdown /etc/shutmsg
# Ask users to use their email address as anonymous
# password
passwd-check rfc822 warn
# We don't want users being able to upload into these areas
upload /var/ftp/* / no
upload /var/ftp/* /etc no
upload /var/ftp/* /bin no
upload /var/ftp/* /lib no
upload /var/ftp/* /pub no
# We'll prevent downloads with noretrieve.
noretrieve /var/ftp/etc
noretrieve /var/ftp/bin
noretrieve /var/ftp/lib
# User restriced
guest-root /var/ftp ftp
guestgroup ftp
restriced-uid ftp
restriced-gid ftp
# Disable Greeting
greeting text ThaiCERT Demo FTP Anonymous Server
signoff text ThaiCERT Demo FTP Anonymous Server Goodbye!
# Others
keepalive yes
noretrieve .notar
# End of Anonymous FTP Demo Server
ตารางที่ 2 ไฟล์ configuration ของ Wu-FTPd
อธิบายเฉพาะส่วนสำคัญได้ดังต่อไปนี้
deny-uid %-99 %65534-
deny-gid %-99 %65534-
allow-uid ftp
allow-gid ftp
อนุญาตให้ผู้ใช้ที่ชื่อ ftp เท่านั้นเข้ามาใช้บริการได้ (เหมือนกับการกำหนดใน /etc/ftpusers)
class demo anonymous 192.168.97.*
กำหนด class เป็นการบอก Wu-FTPd ว่าผู้ใช้ในแบบใดที่สามารถให้บริการได้ สำหรับ Wu-FTPd ได้แบ่ง class ไว้ 3 class คือ real, guest และ anonymous ซึ่งได้อธิบายไปในตอนต้นแล้วว่ามีกี่แบบและมีลักษณะอย่างไร ส่วนคำว่า demo คือชื่อเซิร์ฟเวอร์ และ 192.168.97.* ใช้เพื่อกำหนดว่าไอพีใดอยู่ใน class ใด
limit demo 20 /var/ftp/.too_many.msg
กำหนดจำนวนผู้ใช้ที่สามารถล็อกอินเข้ามาใช้บริการ FTP Server ได้พร้อมกันในเวลาเดียวกัน ในตัวอย่างกำหนดให้มีผู้ใช้สามารถล็อกอินเข้ามาใช้บริการได้พร้อมกันมากที่สุดในเวลาเดียวกันได้ 20 คน ถ้าเข้ามามากกว่าจำนวนที่อนุญาต จะแจ้งเตือนตามข้อความที่อยู่ในไฟล์ /var/ftp/.too_many.msg นอกจากกำหนดจำนวนผู้ใช้แล้ว ยังสามารถกำหนดวันเวลาที่อนุญาตให้เข้ามาใช้บริการได้อีกด้วย ตัวอย่างเช่น
limit demo 20 MoTuWeTh,Fr0000-1800 /var/ftp/.too_many.msg
หมายความว่าสามารถใช้บริการได้ทั้งวันในวันจันทร์ถึงวันพฤหัสบดี ส่วนวันศุกร์เข้ามาได้เฉพาะเวลา 00.00 ถึง 18.00 เท่านั้น และไม่อนุญาตให้เข้ามาใช้บริการในวันวันเสาร์และอาทิตย์ และเข้ามาใช้บริการได้พร้อมกันได้มากที่สุด 20 คน
message /.message.welcome login
message .message cwd=*
กำหนดข้อความในการแสดงผล ข้อความในไฟล์ /var/ftp/.message.welcome จะแสดงตอนเริ่มต้นเมื่อล็อกอินเข้ามาใช้บริการ ส่วนข้อความในไฟล์ .message จะใช้ในการแจ้งรายละเอียดของไดเรกทอรีต่างๆ เมื่อผู้ใช้เข้าสู่ไดเรกทอรีนั้น
compress yes all
tar yes all
chmod no anonymous
delete no anonymous
overwrite no anonymous
rename no anonymous
umask no anonymous
อนุญาตให้ใช้การบีบอัดข้อมูลในขณะโอนย้ายไฟล์ได้ แต่ไม่อนุญาตให้ chmod, delete, overwrite, rename และ umask บนทุกไดเรกทอรีใน Chroot Environment สำหรับ class แบบ anonymous
log commands anonymous
log transfers anonymous inbound,outbound
log security anonymous
กำหนดให้เก็บล็อกของคำสั่งที่ใช้บน FTP Server และข้อมูลการเชื่อมต่อที่เกิดขึ้นไปเก็บไว้ในไฟล์ /var/log/messages และเก็บล็อกการดาวโหลดไฟล์จาก FTP Server ไว้ในไฟล์ /var/log/xferlog
upload /var/ftp/* / no
upload /var/ftp/* /etc no
upload /var/ftp/* /bin no
upload /var/ftp/* /lib no
upload /var/ftp/* /pub no
ไม่อนุญาตให้อัพโหลดไฟล์ขึ้นเซิร์ฟเวอร์ในทุกไดเรกทอรี
noretrieve /var/ftp/etc
noretrieve /var/ftp/bin
noretrieve /var/ftp/lib
ไม่อนุญาตให้แสดงผลไฟล์ในไดเรกทอรี etc/, bin/ และ lib/
guest-root /var/ftp ftp
guestgroup ftp
restriced-uid ftp
restriced-gid ftp
กำหนดให้มีสิทธิ์เป็นผู้ใช้ ftp เท่านั้นเมื่อเข้ามาใช้บริการ Anonymous FTP Server
greeting text ThaiCERT Demo FTP Anonymous Server
signoff text ThaiCERT Demo FTP Anonymous Server Goodbye!
กำหนดข้อความในการตอบรับการเชื่อมต่อ และปิดการเชื่อมต่อการใช้บริการ Anonymous FTP Server โดยปกติแล้วถ้าไม่กำหนดนั้น ข้อความตอบรับการเชื่อมต่อจะเป็นดังนี้ # ftp demo
Connected to demo.thaicert.nectec.or.th.
220 A8-demo1.nectec.or.th FTP server (Version wu-2.6.1-18) ready.
Name (demo:root): ftp
331 Guest login ok, send your complete e-mail address as password.
Password:
เป็นการแสดงตัวตนของโปรแกรมอย่างชัดเจน ใช้โปรแกรมใด เวอร์ชันอะไร และมีชื่อโฮสว่าอะไร การกำหนดข้อความในการตอบรับการเชื่อมต่อจะทำให้ไม่แสดงข้อมูลเหล่านี้ได้
# ftp demo
Connected to demo.thaicert.nectec.or.th.
220 ThaiCERT Demo FTP Anonymous Server
Name (demo:root): ftp
331 Guest login ok, send your complete e-mail address as password.
Password:
--------------------------------------------------------------------------------
เปิดใช้บริการ Anonymous FTP Server ผ่าน xinetd
แก้ไขไฟล์ /etc/xinetd.d/wu-ftpd ให้ xinetd รอรับการเชื่อมต่อผ่านโพรโตคอล FTP
# default: on
# description: The wu-ftpd FTP server serves FTP connections. It uses \
# normal, unencrypted usernames and passwords for authentication.
service ftp
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.ftpd
server_args = -l -a
log_on_success += DURATION USERID
log_on_failure += USERID
nice = 10
only_from = 192.168.97
}
แก้ไขไอพีที่อนุญาตให้สามารถเข้ามาใช้บริการ Anonymous FTP Server ใน only_from ตามต้องการ
จากนั้นรีสตาร์ต xinetd เพื่อให้ใช้ configuration ที่มีการแก้ไขใหม่นี้โดยใช้คำสั่ง
# /etc/rc.d/init.d/xinetd restart
--------------------------------------------------------------------------------
แก้ไข logrotate ให้เหมาะสม
แก้ไขไฟล์ /etc/logrotate.d/ftpd เพื่อให้ logrotate จัดการไฟล์ล็อก /var/log/xferlog ซึ่งเป็นไฟล์ที่เก็บข้อมูลการโอนย้ายไฟล์ที่เกิดขึ้นกับ FTP Server
/var/log/xferlog {
# ftpd doesn't handle SIGHUP properly
nocompress
}
--------------------------------------------------------------------------------
เครื่องมืออำนวยความสะดวกสำหรับ FTP Server
ftpwho
ใช้แสดงผลผู้ใช้ที่เข้ามาใช้บริการ FTP Server ในขณะใดขณะหนึ่ง และข้อมูลของโพรเซสที่เกิดขึ้นจากการเชื่อมต่อด้วย
# ftpwho
Service class demo:
1886 ? SN 0:00 ftpd: 192.168.97.220: ftp: IDLE
1891 ? SN 0:00 ftpd: 192.168.97.220: ftp: IDLE
- 2 users (20 maximum)
ftpcount
คล้ายกับ ftpwho แต่แสดงเฉพาะผู้ใช้ที่เข้ามาเท่านั้น
# ftpcount
Service class demo - 2 users (20 maximum)
Bastille Linux 2.0.4
Bastille เป็นโปรแกรมที่ช่วยเสริมสร้างความแข็งแกร่ง (hardening) ให้กับระบบปฏิบัติการ Red Hat Linux, Debian Linux, Mandrake Linux และ HP-UX โดย Bastille สามารถทำงานได้ใน 2 โหมด ดังต่อไปนี้
interactively mode: หากรัน bastille ในโหมดนี้ ตัวโปรแกรมจะแสดงคำถามจำนวนมาก โดยจะแบ่งเป็นโมดูล ซึ่งในแต่ละคำถามจะมีคำอธิบายประกอบด้วย
non-interactively mode: โหมดนี้เหมาะสำหรับผู้ดูแลระบบที่มีเครื่องในความดูแลจำนวนมาก ทำให้สามารถบันทึกไฟล์ configuration จากเครื่องที่รันในโหมด interactively แล้วนำไปใช้กับเครื่องอื่นได้ ซึ่งจะช่วยประหยัดเวลาได้เป็นอย่างดี
การติดตั้ง Bastille
ดาวน์โหลด Bastille ฉบับ rpm จาก http://www.bastille-linux.org
ใช้คำสั่งดังนี้เพื่อติดตั้ง Bastille
# rpm -ivh Bastille-2.0.4-1.0.i386.rpm
หากต้องการรัน Bastille ในแบบ
GUI: ให้ดาวน์โหลดและติดตั้ง perl-Tk ดังนี้
เลือกดาวน์โหลด perl-Tk เวอร์ชันที่เหมาะสมจาก http://www.bastille-linux.org/perl-rpm-chart.html
ติดตั้ง perl-Tk โดยใช้คำสั่ง
# rpm -ivh perl-Tk.x.x.x.rpm
Text Mode: ให้ดาวน์โหลดและติดตั้ง perl-Curses ดังนี้
เลือกดาวน์โหลด perl-Curses เวอร์ชันที่เหมาะสมจาก http://www.bastille-linux.org/perl-rpm-chart.html
ติดตั้ง perl-Curses โดยใช้คำสั่ง
# rpm -ivh perl-Curses.x.x.x.rpm
ขั้นตอนการใช้งาน Bastille
ล็อกอินเป็น root
ตัดสินใจว่าจะรัน Bastille ในโหมดใด (interactively หรือ non-interactively) ทั้งนี้ผู้ที่รัน Bastille ครั้งแรก จะต้องรันในโหมด interactively เท่านั้น เพื่อสร้าง configuration profile ขึ้นมาก่อน โดยการรัน Bastille ในโหมด interactively นี้จะใช้ระยะเวลาประมาณ 1 ชั่วโมง
คำสั่งที่ใช้ในการรัน Bastille ในแต่ละโหมดคือ
Interactive Mode
เลือก user interface ที่ต้องการใช้งาน
Graphic user interface (GUI) : เป็นโหมดดีฟอลต์ในการรัน Bastille ซึ่งมีข้อดีคือ จะมี progress bar แสดงความคืบหน้าของกระบวนการทั้งหมดให้เห็นตลอด
text-based: เหมาะสำหรับระบบที่ไม่ได้ติดตั้งการแสดงผลแบบกราฟฟิก
รันคำสั่ง bastille โดยหากต้องการรัน Bastille ในโหมด text-based นี้ให้ใช้คำสั่ง # bastille -c หากไม่ระบุออปชันใดๆ จะเป็นการรันในโหมด GUI
จากนั้นต้องตอบคำถามทีละข้อ ซึ่งเป็นส่วนสำคัญและใช้เวลามากที่สุด
บันทึก configuration
สั่งให้การเปลี่ยนแปลงมีผลในทันที (apply changes)
Non-interactive Mode
Bastille ไม่มี default configuration ดังนั้นการที่จะรันในโหมดนี้ได้จะต้องสร้าง configuration profile จากการรันแบบ interactive ก่อน
คัดลอก configuration file (/etc/Bastille/config) ไปยังเครื่องที่ต้องการรันในโหมด non-interactive
ติดตั้ง Bastille ในเครื่องที่ต้องการรันในโหมด non-interactive จากนั้นจึงรัน Bastille โดยใช้คำสั่ง # bastille -b
ภายหลังจากการรัน Bastille แล้ว จะมีการเปลี่ยนแปลงตามคำตอบหรือ configuration ที่ให้ไป ซึ่งผู้ดูแลระบบสามารถตรวจสอบสิ่งที่ Bastille แก้ไขไป โดยดูได้จากล็อกไฟล์
action log: /var/log/Bastille/action-log
error log: /var/log/Bastille/error-log
ส่วนใหญ่แล้ว Bastille จะทำการแก้ไขระบบเอง แต่อาจจะมีบางส่วนที่ Bastille ไม่สามารถแก้ไขเองได้ ผู้ดูแลระบบจะต้องจัดการด้วยตัวเอง ซึ่งผู้ดูแลระบบสามารถตรวจสอบข้อมูลนี้ได้ที่ /var/log/Bastille/TODO
(เพิ่มเติม) ผู้ดูแลระบบสามารถใช้คำสั่ง # bastille -r เพื่อยกเลิกสิ่งที่ Bastille ได้แก้ไขไปทั้งหมด ซึ่งจะทำให้ระบบกลับคืนสู่สภาพก่อนการรัน Bastille
คำแนะนำอื่นๆ
ภายหลังการรัน Bastille แล้วอาจจะทำให้ซอฟต์แวร์ตัวอื่นไม่สามารถทำงานได้ตามปกติ ดังนั้นจึงควรรัน Bastille ทดสอบในเครื่องทดสอบที่มี environment เหมือนเครื่องใช้งานจริงก่อนเสมอ เพื่อป้องกันปัญหาดังกล่าว
เพื่อป้องกันไม่ให้ระบบมีช่องโหว่ ผู้ดูแลระบบจะต้องติดตั้ง patch ล่าสุดสำหรับระบบปฏิบัติการและซอฟต์แวร์ที่ติดตั้งอยู่เสมอ แต่อย่างไรก็ตาม patch ที่ติดตั้งภายหลังอาจจะเป็นตัวทำให้เกิดช่องโหว่ที่ Bastille เคยจัดการให้แล้วอีกครั้ง ดังนั้นจึงควรรัน Bastille ใหม่อีกครั้งภายหลังการติดตั้ง patch เสมอ
Bastille Modules
ข้อมูลดังต่อไปนี้ เป็นตัวอย่างคำถามในการรัน Bastille เวอร์ชัน 2.0.4-1.0 บน Red Hat Linux 8.0 (ค่าที่อยู่ในเครื่องหมาย [] เป็นคำตอบที่เป็น default ของคำถามนั้นๆ)
Module: File Permissions
Q: Would you like to set more restrictive permissions on the administration utilities (linuxconf, fsck, ifconfig, runlevel and portmap) ? [N]
Q: Would you like to disable SUID status for mount/umount? [Y]
Q: Would you like to disable SUID status for ping? [Y]
Q: Would you like to disable SUID status for at? [Y]
Q: Would you like to disable the r-tools? [Y]
Q: Would you like to disable the r-tools (rsh/remsh, rcp, rlogin, rdist, etc.)? [Y]
Q: Would you like to disable SUID status for usernetctl? [Y]
Q: Would you like to disable SUID status for traceroute? [Y]
Module: ACCOUNT SECURITY
Q: Should Bastille disable clear-text r-protocols that use IP-based authentication? [Y]
Q: Would you like to enforce password aging? [Y] (ถ้าตอบ yes จะตั้งเป็น 180 วัน)
Q: Would you like to restrict the use of cron to administrative accounts? [Y]
Q: Do you want to set a default umask? [Y]
Q: What umask would you like to set for users on the system? [077] (สามารถเลือกได้ตั้งแต่ 002, 022, 027, 077
Q: Should we disallow root login on tty's 1-6? [N]
Module: Boot Security
Q: Would you like to password-protect the GRUB prompt? [N]
Q: Would you like to disable CTRL-ALT-DELETE rebooting? [N]
Q: Would you like to password protect single-user mode? [Y]
Module: Secure Inetd Module
Q: Would you like to set a default-deny on TCP Wrappers and xinetd? [N]
Q: Should Bastille ensure the telnet service does not run on this system? [Y]
Q: Should Bastille ensure the FTP service does not run on this system? [Y]
Q: Would you like to display "Authorized Use" messages at log-in time? [Y]
Q: Who is responsible for granting authorization to use this machine? (ให้ใส่ชื่อผู้รับผิดชอบเครื่องนี้ หรือชื่อหน่วยงาน)
Module: Disable User Tools
Q: Would you like to disable the gcc compiler? [N]
Module: Configure Misc PAM
Q: Would you like to put limits on system resource usage? [N]
Q: Should we restrict console access to a small group of user accounts? [N]
Q: Which accounts should be able to login at console? [root]
Module: Logging
Q: Would you like to add additional logging? [Y]
หากตอบ Yes โปรแกรมจะทำการแก้ไข /etc/syslog.conf ดังนี้
############ BASTILLE ADDITIONS BELOW : #################
# Log warning and errors to the new file /var/log/syslog
*.warn;*.err /var/log/syslog
# Log all kernel messages to the new file /var/log/kernel
kern.* /var/log/kernel
# Log all logins to /var/log/loginlog
auth.*;user.*;daemon.none /var/log/loginlog
# Log additional data to the Alt-F7 and Alt-F8 screens (Pseudo TTY 7 and 8)
*.info;mail.none;authpriv.none /dev/tty7
authpriv.* /dev/tty7
*.warn;*.err /dev/tty7
kern.* /dev/tty7
mail.* /dev/tty8
*.* /dev/tty12
########## BASTILLE ADDITIONS CONCLUDED : ###############
Q: Do you have a remote logging host? [N]
Module: Miscellaneous Daemons
Q: Would you like to deactivate NIS server programs? [Y]
Module: Sendmail
Q: Do you want to stop sendmail from running in daemon mode? [Y]
Q: Would you like to run sendmail via cron to process the queue? [N]
Module: DNS
Q: Would you like to chroot named and set it to run as a non-root user? [N]
Module: Apache
Q: Would you like to bind the web server to listen only to the localhost? [N]
Q: Would you like to bind the web server to a particular interface? [N]
Q: Would you like to deactivate the following of symbolic links? [Y]
Q: Would you like to deactivate server-side includes? [Y]
Q: Would you like to disable CGI scripts, at least for now? [Y]
Q: Would you like to disable indexes? [N]
Module: Printing
Q: Would you like to disable printing? [N]
Module: TMPDIR
Q: Would you like to install TMPDIR/TMP scripts? [N]
Module: Firewall
Q: Would you like to run the packet filtering script? [N]
Q: Are you finished answering the questions, i.e. may we make the changes?
หลังจากการรัน Bastille แล้ว ผู้ดูแลระบบควรรีสตาร์ทเครื่องคอมพิวเตอร์ เพื่อให้การแก้ไขทั้งหมดมีผลในทันที (การแก้ไขบางอย่างมีผลในทันทีโดยไม่ต้องรีสตาร์ทเครื่องคอมพิวเตอร์)
Removing Bastille
หากทำการ uninstall Bastille ไปแล้ว จะไม่สามารถแก้ไขระบบให้คืนสู่สภาพก่อนการรัน Bastille ได้ อย่างไรก็ตาม Bastille ยังมี revert-action script เหลืออยู่ในระบบภายหลังการ uninstall ซึ่งสคริปต์ตัวนี้จะช่วย revert สิ่งที่ Bastille ได้กระทำกับไฟล์ต่างๆ (ในระดับของไฟล์เท่านั้น) เช่น แก้ไข permission ของไฟล์ให้กลับคืนสู่สภาพเดิมก่อนการรัน Bastille โดยผู้ดูแลระบบสามารถเรียกใช้งานสคริปต์นี้ได้ที่ /var/log/Bastille/revert
ไฟล์สำคัญที่เกี่ยวข้อง
Description Filename
Configuration file /etc/Bastille/config
Error log /var/log/Bastille/error-log
Action log /var/log/Bastille/action-log
TODO /var/log/Bastille/TODO
Revert actions script /var/log/Bastille/revert/revert-actions
เอกสารอ้างอิง
Bastille Linux, http://www.bastille-linux.org
Bastille Linux: A Walkthrough, Jay Beale , http://www.securityfocus.com/infocus/1414