<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>How to Config &#187; Development</title>
	<atom:link href="http://www.howtoconfig.com/category/development/feed" rel="self" type="application/rss+xml" />
	<link>http://www.howtoconfig.com</link>
	<description>how to config - how to configure</description>
	<lastBuildDate>Fri, 29 Apr 2011 09:52:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>IPTables statefull firewall for Linux</title>
		<link>http://www.howtoconfig.com/os/ubuntu/iptables_statefull_firewall_linux_debian_centos.html</link>
		<comments>http://www.howtoconfig.com/os/ubuntu/iptables_statefull_firewall_linux_debian_centos.html#comments</comments>
		<pubDate>Tue, 23 Mar 2010 11:04:18 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[INPUT]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=87</guid>
		<description><![CDATA[หายไปนานครับ วันี้เอาเรื่องเก่าๆมาหากินใหม่ IPTables ที่ทำๆอยู่ทุกวันนี้แหละครับ พอดีทำ Shell Script ทิ้งไว้เลยเอามาแจกจ่ายให้เพื่อนๆเอาไปใช้งาน หลายๆคนถามว่าทำไมต้องเขียนเอง ก็เหตุผลง่ายๆครับ เราเขียนเองเรารู้ทุกๆ rules ที่มันทำงานอย่างไร เวลาเกิดปัญหา เราสามารถแก้ไขปัญหาได้ รวดเร็ว มาดูความสามารถของ script firewall ตัวนี้ครับ ความสามารถ: &#8211; State full firewall &#8211; สามารถกำหนด Interface ที่ทำงานได้ &#8211; สามารถกำหนด VIP IP ได้ &#8211; สามารถกำหนด Band IP ได้ &#8211; มีการเก็บ Log ลง syslog &#8211; ป้องกันการ Scan port ได้ &#8211; ป้องกัน IP Spoofig &#8211; ป้องกัน [...]]]></description>
			<content:encoded><![CDATA[<p>     หายไปนานครับ วันี้เอาเรื่องเก่าๆมาหากินใหม่ IPTables ที่ทำๆอยู่ทุกวันนี้แหละครับ พอดีทำ Shell Script ทิ้งไว้เลยเอามาแจกจ่ายให้เพื่อนๆเอาไปใช้งาน   หลายๆคนถามว่าทำไมต้องเขียนเอง   ก็เหตุผลง่ายๆครับ   เราเขียนเองเรารู้ทุกๆ rules ที่มันทำงานอย่างไร เวลาเกิดปัญหา เราสามารถแก้ไขปัญหาได้ รวดเร็ว  มาดูความสามารถของ script firewall ตัวนี้ครับ</p>
<p>ความสามารถ:<br />
  &#8211; State full  firewall<br />
  &#8211; สามารถกำหนด Interface ที่ทำงานได้<br />
  &#8211; สามารถกำหนด VIP IP ได้<br />
  &#8211; สามารถกำหนด Band IP ได้<br />
  &#8211; มีการเก็บ Log ลง syslog<br />
  &#8211; ป้องกันการ Scan port ได้<br />
  &#8211; ป้องกัน IP Spoofig<br />
  &#8211; ป้องกัน SSH Attatch<br />
<span id="more-87"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># rc.firewall - Initial IP Firewall</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">INET_IFACE</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span>
&nbsp;
<span style="color: #007800;">IP_ALLOW</span>=<span style="color: #ff0000;">&quot;61.19.249.66&quot;</span>
<span style="color: #007800;">IP_BAND</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #007800;">ICMP_ALLOW</span>=<span style="color: #ff0000;">&quot;0 3 5 11&quot;</span>
<span style="color: #007800;">TCP_ALLOW</span>=<span style="color: #ff0000;">&quot;22 25 53 80 8000 90 3128 20001&quot;</span> 
<span style="color: #007800;">UDP_ALLOW</span>=<span style="color: #ff0000;">&quot;53&quot;</span>
&nbsp;
<span style="color: #007800;">FTP_PORT</span>=<span style="color: #ff0000;">&quot;1024:65335&quot;</span>
<span style="color: #007800;">FTP_ENABLE</span>=<span style="color: #000000;">1</span>
&nbsp;
&nbsp;
<span style="color: #007800;">SSH_ATTACH</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">SSH_HITCOUNT</span>=<span style="color: #000000;">5</span>
<span style="color: #007800;">SSH_PORT</span>=<span style="color: #000000;">22</span>
&nbsp;
<span style="color: #007800;">PORTSCAN_CHECK</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">SPOOFINGIP_CHECK</span>=<span style="color: #000000;">1</span>
&nbsp;
<span style="color: #007800;">LOGLEVEL</span>=<span style="color: #ff0000;">&quot;DEBUG&quot;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Load IPTables Modules</span>
<span style="color: #666666; font-style: italic;">#</span>
modprobe ip_conntrack
modprobe ip_conntrack_ftp
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Reset IPTables</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> <span style="color: #660033;">-t</span> nat
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span> <span style="color: #660033;">-t</span> nat
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Create separate chains for ICMP, TCP and UDP to traverse</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> vip_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> band_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> icmp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> tcp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> udp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> log_attach
&nbsp;
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> DROP_TRAFFIC
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Drop packet</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> DROP_TRAFFIC <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-j</span> REJECT <span style="color: #660033;">--reject-with</span> tcp-reset 
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> DROP_TRAFFIC <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">-j</span> REJECT <span style="color: #660033;">--reject-with</span> icmp-port-unreachable
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Log Attack</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> log_attach <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;Attack:&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> log_attach <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># VIP IPaddress</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> ip <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$IP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vip_packets <span style="color: #660033;">-s</span> <span style="color: #007800;">$ip</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Band IPaddress</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> ip <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$IP_BAND</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> band_packets <span style="color: #660033;">-s</span> <span style="color: #007800;">$ip</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># ICMP rules</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> icmp <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$ICMP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> icmp_packets <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--icmp-type</span> <span style="color: #007800;">$icmp</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># TCP rules</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> port <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$TCP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> tcp_packets <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$port</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># UDP rules</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> port <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$UDP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> udp_packets <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$port</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># INPUT chain</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ALL <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> log_attach
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Rules for incoming packets from the internet</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SPOOFINGIP_CHECK</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> spoofing_check
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 169.254.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 172.16.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 224.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 224.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 240.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 240.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 239.255.255.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 255.255.255.255 <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> spoofing_check
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SSH_ATTACH</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> sshattach_check
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> sshattach_check <span style="color: #660033;">-m</span> recent <span style="color: #660033;">--set</span> <span style="color: #660033;">--name</span> SSH
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> sshattach_check <span style="color: #660033;">-m</span> recent <span style="color: #660033;">--update</span> <span style="color: #660033;">--seconds</span> <span style="color: #000000;">60</span> <span style="color: #660033;">--hitcount</span> <span style="color: #007800;">$SSH_HITCOUNT</span> <span style="color: #660033;">--name</span> SSH <span style="color: #660033;">-j</span> log_attach
&nbsp;
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #007800;">$SSH_PORT</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> sshattach_check
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Port scan</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PORTSCAN_CHECK</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> check-flags
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;NMAP:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;XMAS:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;XMAS-PSH:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;NULL_SCAN:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;SYN/RST:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;SYN/FIN:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> check-flags
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FTP_ENABLE</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;">#Allow FTP traffic (Control)</span>
        iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-j</span> ACCEPT
        iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;">#Allow FTP traffic (Data)</span>
        iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> ACCEPT
        iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> vip_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> band_packets
&nbsp;
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> icmp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> tcp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> udp_packets
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Default policy</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC</pre></div></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fubuntu%2Fiptables_statefull_firewall_linux_debian_centos.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/ubuntu/iptables_statefull_firewall_linux_debian_centos.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>แก้ปัญหา REMOTE_ADDR ใน Reverse Proxy</title>
		<link>http://www.howtoconfig.com/development/remote_addr-http_x_forwarded_for-reverse-proxy.html</link>
		<comments>http://www.howtoconfig.com/development/remote_addr-http_x_forwarded_for-reverse-proxy.html#comments</comments>
		<pubDate>Wed, 18 Feb 2009 17:58:37 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Reverse Proxy]]></category>
		<category><![CDATA[Web Server]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=74</guid>
		<description><![CDATA[สวัสดีครับ วันนี้จิบเบียร์แล้วก็มานั้งทบทวนเรื่องงานที่ทำ  พอดีมีเรื่องเล็กๆน้่อยๆ ที่ผมเองทำและน่าจะเป็นประโยช์กับเพื่อนๆ  เกี่ยวกับการตั้ง Reverse Proxy กับปัญหา เรื่อง IP ที่ show ใน app ของเรา ปกติเวลาเราเขียน Apps หรือ พวกฟรี Webboard ทั้งหลายจะมีการ Check IP จาก $_SERVER['REMOTE_ADDR'] และ $_SERVER['HTTP_X_FORWARDED_FOR']  หากเจอตัวแปล HTTP_X_FORWARDED_FOR   ระบบจะทำการ Record  IP จาก  HTTP_X_FORWARDED_FOR ด้วย   แต่หากว่าบางโปรแกรมที่เขียน จะเก็บแค่   REMOTE_ADDR  ทำให้ IP ที่แสดงในโปรแกรมของเรา  เป็น IP ของ Reverse Proxy แทน Client IP:  203.146.1.1 Proxy IP: 192.168.1.100 Web IP: [...]]]></description>
			<content:encoded><![CDATA[<p>สวัสดีครับ วันนี้จิบเบียร์แล้วก็มานั้งทบทวนเรื่องงานที่ทำ  พอดีมีเรื่องเล็กๆน้่อยๆ ที่ผมเองทำและน่าจะเป็นประโยช์กับเพื่อนๆ  เกี่ยวกับการตั้ง Reverse Proxy กับปัญหา เรื่อง IP ที่ show ใน app ของเรา</p>
<p>ปกติเวลาเราเขียน Apps หรือ พวกฟรี Webboard ทั้งหลายจะมีการ Check IP จาก</p>
<p>$_SERVER['REMOTE_ADDR'] และ $_SERVER['HTTP_X_FORWARDED_FOR']  หากเจอตัวแปล HTTP_X_FORWARDED_FOR   ระบบจะทำการ Record  IP จาก  HTTP_X_FORWARDED_FOR ด้วย   แต่หากว่าบางโปรแกรมที่เขียน จะเก็บแค่   REMOTE_ADDR  ทำให้ IP ที่แสดงในโปรแกรมของเรา  เป็น IP ของ Reverse Proxy แทน<br />
<span id="more-74"></span></p>
<p>Client IP:  203.146.1.1<br />
Proxy IP: 192.168.1.100<br />
Web IP: 192.168.1.1</p>
<p>[Client] ===&gt; [Revert Proxy] ===&gt; [Web Server]</p>
<p>เมื่อ Web Server  ได้รับ Request   Header จะได้ดั่งนี้</p>
<p>$_SERVER['REMOTE_ADDR'] = 192.168.1.100<br />
$_SERVER['HTTP_X_FORWARDED_FOR']  = 203.146.1.1</p>
<p>ทางแก้ง่ายนิดเดียวครับ  แก้ที่ System ไม่ต้องไปขอร้องให้ Programmer แก้ไขโค๊ดแต่อย่างใด  ทางออกอยู่ที่ PHP ครับ    โดย PHP จะมี Parameter อยู่ 2 ตัวคือauto_prepend_file และ auto_append_file</p>
<p>auto_prepend_file จะกำหนดว่า ก่อนที่จะรันไฟล์ php ทุกๆครั้ง จะทำการรันไฟล์นี้ก่อน ส่วน auto_append_file  คือเมื่อทำการรันไฟล์ php ใดๆเสร็จแล้ว จะมารันไฟล์ ที่เรากำหนด      เมื่อเรารู้ดั่งนี้แล้ว  เ้ราก็มาดูโค๊ดแก้ปัญหาเรื่อง Rever Proxy &amp; REMOTE_IP  ได้เลยครับ</p>
<p>1.  ให้เราไปกำหนดที่  php.ini   ใส่พารามิเตอร์  auto_prepend_file &#8220;/etc/php-prepend.php&#8221;</p>
<p>2. แก้ไขไฟล์  /etc/php-prepend.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$real_ip</span>    <span style="color: #339933;">=</span> session_getip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ip</span>        <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span>                    <span style="color: #339933;">=</span> <span style="color: #000088;">$real_ip</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> session_getip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CLIENT_IP&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CLIENT_IP&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Code ดั่งกล่าว  จะทำการ ดึง IP ที่  HTTP_X_FORWARDED   มาไว้ยัง $real_ip และทำการกำหนดให้  REMOTE_ADDR = $real_ip   ทำให้ app ทั่วไปทีเราเขียนขึ้น ไม่ต้องทำการแก้ไข Code แต่อย่างใด</p>
<p>ป.ล.    ส่วนของ prepend และ append  สามารถนำไปใช้งานได้หลายรูปแบบมากกว่านี้เอาไว้โอกาศหน้า ผมจะมาเขียนบอกเล่าให้เพื่อนๆ ได้อ่านต่อไปครับ <img src='http://www.howtoconfig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fremote_addr-http_x_forwarded_for-reverse-proxy.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/remote_addr-http_x_forwarded_for-reverse-proxy.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; 2 Way Encrypt by PKI</title>
		<link>http://www.howtoconfig.com/development/php-2way-encrypt-pki-openssl.html</link>
		<comments>http://www.howtoconfig.com/development/php-2way-encrypt-pki-openssl.html#comments</comments>
		<pubDate>Fri, 16 Jan 2009 15:31:14 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[PKI]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=61</guid>
		<description><![CDATA[ช่วงนี้ขยันครับกะจะปั่นบาความใหม่ๆสะหน่อย หลังจากไม่ได้เขียนมาสะนาน  วันนี้เอาเรื่องเกี่ยวกับ Developer บ้างผมเองเป็นทั้ง System,  Programing   เลยยกเรื่องการเ้ข้ารหัสข้อมูลที่เป็นแบบ  2 way คือสามารถ เข้ารหัส และถอดกลับมาได้  และมีความปลอดภัยสูง มาพูดเรื่อง PKI ก่อนนะครับ   ส่วนตัวผมเองไม่ได้เรื่อง IT มาเรื่อง PKI  ผมเองก็ได้แต่อ่านๆจากในเน็ต แล้วก็นำมาเล่าสู่กันฟัง    ท่าสามารถหาข้อมูลที่ลึงมากกว่านี้ได้จาก Link ข้างล่าง    &#8220;Public key infrastructure&#8221;  คือการเข้ารหัสข้อมูล โดยใช้  กุญแจ 2 ลูกคือ   Public Key และ Private Key       หากเราเข้ารหัสข้อมูลโดยใช้  Private Key     เราก็ต้องถอดรหัสโดยใช้  Public Key     ในทางกลับกัน ถ้าเข้ารหัสด้วย Public Key ก็ต้องใช้ Private Key ถอดรหัสเท่านั้น ทีนี้มาพูดถึงความปลอดภัย   ตัว [...]]]></description>
			<content:encoded><![CDATA[<p>ช่วงนี้ขยันครับกะจะปั่นบาความใหม่ๆสะหน่อย หลังจากไม่ได้เขียนมาสะนาน  วันนี้เอาเรื่องเกี่ยวกับ Developer บ้างผมเองเป็นทั้ง System,  Programing   เลยยกเรื่องการเ้ข้ารหัสข้อมูลที่เป็นแบบ  2 way คือสามารถ เข้ารหัส และถอดกลับมาได้  และมีความปลอดภัยสูง</p>
<p><img class="alignleft size-medium wp-image-62" title="PKI " src="http://www.howtoconfig.com/content/uploads/2009/01/pki-300x181.png" alt="PKI " width="300" height="181" /> มาพูดเรื่อง PKI ก่อนนะครับ   ส่วนตัวผมเองไม่ได้เรื่อง IT มาเรื่อง PKI  ผมเองก็ได้แต่อ่านๆจากในเน็ต แล้วก็นำมาเล่าสู่กันฟัง    ท่าสามารถหาข้อมูลที่ลึงมากกว่านี้ได้จาก Link ข้างล่าง    &#8220;Public key infrastructure&#8221;  คือการเข้ารหัสข้อมูล โดยใช้  กุญแจ 2 ลูกคือ   Public Key และ Private Key       หากเราเข้ารหัสข้อมูลโดยใช้  Private Key     เราก็ต้องถอดรหัสโดยใช้  Public Key     ในทางกลับกัน ถ้าเข้ารหัสด้วย Public Key ก็ต้องใช้ Private Key ถอดรหัสเท่านั้น</p>
<p>ทีนี้มาพูดถึงความปลอดภัย   ตัว PKI เองสามารถเลือก bit การเข้ารหัสได้ตามที่เราต้องการ ตั้งแต่ 512, 1024, 2048  และสามารถเข้ารหัวได้สูงกว่านี้   ทำให้เป็นการยากที่จะถอดรหัสได้    ทุกๆวันนี้เราเองก็ใช้เทคโนโลยีนี้แทบทุกวัน โดยที่เราไม่รู้ตัว  อย่างบัตร SmartCard เองก็ใช้ PKI ในการเข้ารหัส หรือ Card UBC  เองก็ใช้เช่นกัน    อีกตัวอย่างคือ   เวลาเข้าเว็บไซด์ผ่าน https   ระหว่าง Web Server และ Browser ก็จะมีการเข้ารหัสข้อมูล โดยใช้เทคโนโลยี PKI    ในการเข้ารหัสเช่นกัน</p>
<p><span id="more-61"></span></p>
<p>ทีนี้มาพูดถึงแนวทางเอาไปใช้งานกับ PHP     ในการณี้ทีเรามีข้อมูลที่เราต้องการเข้ารหัส  และต้องสามารถถอดรหัสกลับมาได้ด้วย  เราสามารถเอา PKI เข้ามาแก้ไขปัญหาดั่งกล่าวได้    โดยการสร้าง Private Key และ Publick Key  ในการถอดรหัส   แต่มีข้อแม้ว่า Key ดั่งกล่าวต้องไม่หาย   ถ้าหาย ก็บอกลา Data ที่คุณเข้ารหัสไว้ได้เลย</p>
<p>ตัวอย่าง ผมมีข้อมูลที่ต้องส่งผ่านหน้า Web โดยการ Redirect ผ่าน URL  ไปยังอีกเว็บหนึ่ง โดยที่ผมไม่ต้องการให้ใครสามารถเปิดข้อมูลได้  ผมจะทำการ  Encryt ข้อมูลโดยใช้ Public Key ของเว็บตรงข้าม และ เว็บตรงข้ามต้องใช้ Private Key  เท่านั้นในการ Decrypt ข้อมูล</p>
<p>1.  สร้าง Private Key และ Pubkic Key  ผ่่าน Command Line</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-out</span> private.key <span style="color: #000000;">2048</span>
openssl rsa -pubout  <span style="color: #000000; font-weight: bold;">&amp;</span>lt; private.key  <span style="color: #000000; font-weight: bold;">&amp;</span>gt; public.key</pre></div></div>

<p>2.  ทำการสร้าง Code PHP  Function</p>
<pre>&lt;?php
function EncryptData($source)
{
	$fp=fopen( "public.key","r");
	$pub_key=fread($fp,8192);
	fclose($fp);
	openssl_get_publickey($pub_key);
	openssl_public_encrypt($source,$crypttext,$pub_key);
	return(base64_encode($crypttext));
}

function DecryptData($source)
{
	$fp=fopen( "private.key","r");
	$priv_key=fread($fp,8192);
	fclose($fp);
	$res = openssl_get_privatekey($priv_key);
	$decoded_source = base64_decode($source);
	openssl_private_decrypt($decoded_source,$newsource,$res);
	return($newsource);
}
?&gt;</pre>
<p>การนำไปใช้งาน  ท่านสามารถเอา  ใช้ PHP เรียก Function  ดั่งกล่าว เพื่อ Encrypt และ Decrypt ได้เลยครับ</p>
<p>Refer:</p>
<p>http://en.wikipedia.org/wiki/Public_key_infrastructure</p>
<p>http://thaicert.nectec.or.th/paper/encryption/sshl.php</p>
<p>http://www.google.co.th/search?hl=th&#038;q=Public+key+infrastructure&#038;btnG=%E0%B8%84%E0%B9%89%E0%B8%99%E0%B8%AB%E0%B8%B2&#038;meta=cr%3DcountryTH</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fphp-2way-encrypt-pki-openssl.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/php-2way-encrypt-pki-openssl.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Check Transparent Proxy</title>
		<link>http://www.howtoconfig.com/os/debian/check-transparent-proxy.html</link>
		<comments>http://www.howtoconfig.com/os/debian/check-transparent-proxy.html#comments</comments>
		<pubDate>Mon, 01 Sep 2008 05:18:35 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Transparent]]></category>
		<category><![CDATA[TransparentProxy]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=43</guid>
		<description><![CDATA[คือมี case ที่ต้องทำ transparent proxy ครับ  แต่ว่าเวลา proxy มีปัญหา ผมอยากให้ทำการ ปลด proxy ออกเอง  ผมเลยเขียน shell script  มาเพื่อทำการ ตรวจสอบว่า proxy ทำได้หรือเปล่า ถ้าทำงานได้ ก็จะเพิ่ม iptables  ทำการสร้าง DNAT  ไปยังเครื่อง Proxy ครับ หลักกาารง่ายๆคือ  จะใช้ curl แล้ว set proxy เป็นเครื่อง Proxy ที่เรากำหนด   เสร็จแล้วก็ให้ curl ทำการ connect ไปยัง web ปลายทาง   ถ้า connect ได้ content ที่ return มาจาก curl จะมากกว่า 0    และทำให้ [...]]]></description>
			<content:encoded><![CDATA[<p>คือมี case ที่ต้องทำ transparent proxy ครับ  แต่ว่าเวลา proxy มีปัญหา ผมอยากให้ทำการ ปลด proxy ออกเอง  ผมเลยเขียน shell script  มาเพื่อทำการ ตรวจสอบว่า proxy ทำได้หรือเปล่า ถ้าทำงานได้ ก็จะเพิ่ม iptables  ทำการสร้าง DNAT  ไปยังเครื่อง Proxy ครับ</p>
<p><span id="more-43"></span></p>
<p>หลักกาารง่ายๆคือ  จะใช้ curl แล้ว set proxy เป็นเครื่อง Proxy ที่เรากำหนด   เสร็จแล้วก็ให้ curl ทำการ connect ไปยัง web ปลายทาง   ถ้า connect ได้ content ที่ return มาจาก curl จะมากกว่า 0    และทำให้ script เพิ่ม iptables  เข้าไปครับผม</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	Check Proxy	v.10</span>
<span style="color: #666666; font-style: italic;">#	By Auttasak Wongkitta</span>
<span style="color: #666666; font-style: italic;">#	http://howtoconfig.com</span>
&nbsp;
<span style="color: #007800;">PROXY</span>=<span style="color: #ff0000;">&quot;192.168.100.254:3128&quot;</span>
<span style="color: #007800;">URL</span>=<span style="color: #ff0000;">&quot;http://manager.co.th&quot;</span>
<span style="color: #007800;">LINUX_IP</span>=<span style="color: #ff0000;">&quot;192.168.100.254&quot;</span>
<span style="color: #007800;">LINUX_IF</span>=<span style="color: #ff0000;">&quot;eth2.1&quot;</span>
&nbsp;
<span style="color: #007800;">RESULT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>curl <span style="color: #660033;">-x</span> <span style="color: #007800;">$PROXY</span>  <span style="color: #007800;">$URL</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">USEPROXY</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-L</span> PREROUTING <span style="color: #660033;">-n</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$PROXY</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RESULT</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$USEPROXY</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-D</span> PREROUTING <span style="color: #660033;">-i</span> <span style="color: #007800;">$LINUX_IF</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #007800;">$LINUX_IP</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> http <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to</span> <span style="color: #007800;">$PROXY</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$USEPROXY</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-i</span> <span style="color: #007800;">$LINUX_IF</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #007800;">$LINUX_IP</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> http <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to</span> <span style="color: #007800;">$PROXY</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fdebian%2Fcheck-transparent-proxy.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/debian/check-transparent-proxy.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>พรบ. การกระทำความผิดเกี่ยวกับคอมพิวเตอร์ &#8211; Revert Proxy Log Rotate</title>
		<link>http://www.howtoconfig.com/os/debian/revert_proxy_log_rotate.html</link>
		<comments>http://www.howtoconfig.com/os/debian/revert_proxy_log_rotate.html#comments</comments>
		<pubDate>Sat, 23 Aug 2008 19:19:50 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Revert]]></category>
		<category><![CDATA[Rotate]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[พรบ]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=39</guid>
		<description><![CDATA[ตามที่ พรบ  ได้กำหนดให้ &#8220;ผู้ให้บริการ&#8221; เก็บ log การใช้บริการ   โชคดีที่ผมมี Revert Proxy วางไว้หน้า Web Server  ทำให้สามารถเก็บ Log ได้ง่ายหน่อย   ตัว script ที่ผมเขียนนี้ จะทำการ rotate log และ compress log ไว้    ใน version ต่อไป จะทำการ ftp ไปไว้ยัง Log Server  อื่น แทนครับ #!/bin/sh # #    Howtoconfig.com #    Squid Log Rotate v0.1 #    By Mr. Auttasak Wongkitta &#160; SQUID_CONF=&#34;/etc/squid/squid.conf&#34; COMPRESS=yes LOG=&#34;/var/log/backup_log&#34; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>ตามที่ พรบ  ได้กำหนดให้ &#8220;ผู้ให้บริการ&#8221; เก็บ log การใช้บริการ   โชคดีที่ผมมี Revert Proxy วางไว้หน้า Web Server  ทำให้สามารถเก็บ Log ได้ง่ายหน่อย   ตัว script ที่ผมเขียนนี้ จะทำการ rotate log และ compress log ไว้    ใน version ต่อไป จะทำการ ftp ไปไว้ยัง Log Server  อื่น แทนครับ <img src='http://www.howtoconfig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-39"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#    Howtoconfig.com</span>
<span style="color: #666666; font-style: italic;">#    Squid Log Rotate v0.1</span>
<span style="color: #666666; font-style: italic;">#    By Mr. Auttasak Wongkitta</span>
&nbsp;
<span style="color: #007800;">SQUID_CONF</span>=<span style="color: #ff0000;">&quot;/etc/squid/squid.conf&quot;</span>
<span style="color: #007800;">COMPRESS</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #007800;">LOG</span>=<span style="color: #ff0000;">&quot;/var/log/backup_log&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###############################</span>
<span style="color: #007800;">DATE</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">&quot;+%Y%m%d-%H&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">HOSTNAME</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">hostname</span> -s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SQUID_PATH</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">whereis</span> squid <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #007800;">SQUID_LOG</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$SQUID_CONF</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^access_log&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$SQUID_LOG</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; * Error : access_log not found!!!&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #007800;">SQUID_LOG_NEW</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$SQUID_LOG</span>-<span style="color: #007800;">$HOSTNAME</span>-<span style="color: #007800;">$DATE</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###############################</span>
Log<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">local</span> LogText;
<span style="color: #007800;">LogText</span>=<span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%d/%m/%y %T&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #ff0000;">&quot;   &quot;</span> <span style="color: #007800;">$LogText</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$LOG</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">###############################</span>
<span style="color: #666666; font-style: italic;">###############################</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
Log <span style="color: #ff0000;">&quot;--------------------------------------------&quot;</span>
Log <span style="color: #ff0000;">&quot;Squid log rotate - startup&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
Log <span style="color: #ff0000;">&quot;Rotate Log&quot;</span>
<span style="color: #007800;">$SQUID_PATH</span> <span style="color: #660033;">-k</span> rotate
Log <span style="color: #ff0000;">&quot;done&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
Log <span style="color: #ff0000;">&quot;Loop check <span style="color: #007800;">$SQUID_LOG</span>.0&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$SQUID_LOG</span>.0 <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>;
<span style="color: #000000; font-weight: bold;">done</span>
Log <span style="color: #ff0000;">&quot;done&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
Log <span style="color: #ff0000;">&quot;Move <span style="color: #007800;">$SQUID_LOG</span>.0 <span style="color: #007800;">$SQUID_LOG_NEW</span>&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$SQUID_LOG</span>.0 <span style="color: #007800;">$SQUID_LOG_NEW</span>
Log <span style="color: #ff0000;">&quot;done&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$SQUID_LOG_NEW</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
Log <span style="color: #ff0000;">&quot;MD5 Sum : <span style="color: #007800;">$SQUID_LOG_NEW</span>&quot;</span>
<span style="color: #007800;">SQUID_MD5</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>md5sum <span style="color: #007800;">$SQUID_LOG_NEW</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Log <span style="color: #ff0000;">&quot;Checksum : <span style="color: #007800;">$SQUID_MD5</span>&quot;</span>
Log <span style="color: #ff0000;">&quot;done&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$COMPRESS</span>==<span style="color: #ff0000;">'yes'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
Log <span style="color: #ff0000;">&quot;Compress log <span style="color: #007800;">$SQUID_LOG_NEW</span>&quot;</span>
<span style="color: #007800;">SIZE_OLD</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-sh</span> <span style="color: #007800;">$SQUID_LOG_NEW</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> jpcf <span style="color: #007800;">$SQUID_LOG_NEW</span>.tar.bz2 <span style="color: #007800;">$SQUID_LOG_NEW</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #007800;">SIZE_NEW</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-sh</span> <span style="color: #007800;">$SQUID_LOG_NEW</span>.tar.bz2 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Log <span style="color: #ff0000;">&quot;Compress from <span style="color: #007800;">$SIZE_OLD</span> -&amp;gt; <span style="color: #007800;">$SIZE_NEW</span>&quot;</span>
Log <span style="color: #ff0000;">&quot;done&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$SQUID_LOG_NEW</span>.tar.bz2 <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
Log <span style="color: #ff0000;">&quot;Remove file : <span style="color: #007800;">$SQUID_LOG_NEW</span>&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$SQUID_LOG_NEW</span>
Log <span style="color: #ff0000;">&quot;done&quot;</span>
Log <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
Log <span style="color: #ff0000;">&quot;&quot;</span>
Log <span style="color: #ff0000;">&quot;End&quot;</span></pre></div></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fdebian%2Frevert_proxy_log_rotate.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/debian/revert_proxy_log_rotate.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ลบ ^M (CTRL-M) ออกจากไฟล์ หรือแทนที่ด้วย  ด้วย VIM</title>
		<link>http://www.howtoconfig.com/development/remove-ctrl-m-with-vim-editor.html</link>
		<comments>http://www.howtoconfig.com/development/remove-ctrl-m-with-vim-editor.html#comments</comments>
		<pubDate>Tue, 10 Jun 2008 10:43:58 +0000</pubDate>
		<dc:creator>กวิน ชัยเลิศ</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CTRL-M]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[^M]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/development/%e0%b8%a5%e0%b8%9a-m-ctrl-m-%e0%b8%ad%e0%b8%ad%e0%b8%81%e0%b8%88%e0%b8%b2%e0%b8%81%e0%b9%84%e0%b8%9f%e0%b8%a5%e0%b9%8c-%e0%b8%ab%e0%b8%a3%e0%b8%b7%e0%b8%ad%e0%b9%81%e0%b8%97%e0%b8%99%e0%b8%97.html</guid>
		<description><![CDATA[เพื่อนๆ คงจะเคยประสบปัญหากับ source code หรือ text file ที่เต็มไปด้วย ^M (CTRL-M) โดยที่เราไม่ต้องการจะเห็นมัน ผมมีวิธีลบ ^M ออกไปจาก file ด้วย VIM (editor เทพ!) มาแนะนำครับ ตัวอย่าง file ที่เต็มไปด้วย ^M ลบ ^M ออกจากไฟล์ :%s/^M//g แทนที่ ^M ด้วย :%s/^M/\r/g *ให้พิมพ์ CRTL-V ตามด้วย CTRL-M จึงจะเป็น ^M ที่ถูกต้อง สำหรับ VIM for Windows ต้องใช้ CTRL-Q แทน CRTL-V ครับ ตัวอย่าง file ที่ถูกแทนที่ด้วย]]></description>
			<content:encoded><![CDATA[<p>เพื่อนๆ คงจะเคยประสบปัญหากับ source code หรือ text file ที่เต็มไปด้วย ^M (CTRL-M) โดยที่เราไม่ต้องการจะเห็นมัน</p>
<p>ผมมีวิธีลบ ^M ออกไปจาก file ด้วย VIM (editor เทพ!) มาแนะนำครับ <img src='http://www.howtoconfig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>ตัวอย่าง file ที่เต็มไปด้วย ^M<br />
<img class="alignnone size-full image-46" title="vim-control-m" src="http://kawin.chailerd.com/content/uploads/2008/06/control-m.gif" alt="vim-control-m" width="668" height="505" /></p>
<p><span id="more-21"></span><br />
ลบ ^M ออกจากไฟล์</p>

<div class="wp_syntax"><div class="code"><pre class="genero" style="font-family:monospace;"><span style="color: #008000;">:%</span>s<span style="color: #008000;">/^</span>M<span style="color: #008000;">//</span>g</pre></div></div>

<p>แทนที่ ^M ด้วย</p>

<div class="wp_syntax"><div class="code"><pre class="genero" style="font-family:monospace;"><span style="color: #008000;">:%</span>s<span style="color: #008000;">/^</span>M<span style="color: #008000;">/</span>\r<span style="color: #008000;">/</span>g</pre></div></div>

<p><span style="color: #ff0000;">*ให้พิมพ์ CRTL-V ตามด้วย CTRL-M จึงจะเป็น ^M ที่ถูกต้อง<br />
สำหรับ VIM for Windows ต้องใช้ CTRL-Q แทน CRTL-V ครับ</span></p>
<p>ตัวอย่าง file ที่ถูกแทนที่ด้วย<br />
<img class="alignnone size-full image-47" title="remove-control-m" src="http://kawin.chailerd.com/content/uploads/2008/06/remove-control-m.gif" alt="remove-control-m" width="668" height="505" /></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fremove-ctrl-m-with-vim-editor.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/remove-ctrl-m-with-vim-editor.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Split MySQL Query แยก RO/RW</title>
		<link>http://www.howtoconfig.com/development/mysql-query-split-ro-rw-mysql_query.html</link>
		<comments>http://www.howtoconfig.com/development/mysql-query-split-ro-rw-mysql_query.html#comments</comments>
		<pubDate>Sat, 07 Jun 2008 20:43:05 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=20</guid>
		<description><![CDATA[วันนี้มีปัญหาขึ้นมาครับ เนื่องจาก MySQL Cluster ที่ใช้งบานนั้นลองทดสอบความเร็วแล้วสู้ MySQL แล้วใช้ Local Engine ไม่ได้เลย งานนี้เลยต้องหาทางออกครับ ผมเลยไปมอง เรื่อง MySQL Replication หลังจาก Setup และ Tuning เสร็จ ก็มาลองทดสอบความเร็ว มัน Query เร็วกว่า MySQL Cluster หลายเท่าเลยครับ ทีนี้ก็มาดูเรื่อง Codeing ปัญหาคือมันเป็นโปรแกรมที่เค้าเขียนมานานละ ผมเข้าไปแก้อะไรไม่ค่อยได้ หรือถ้าแก้จริงๆ อยาจจะเป็น Bug อีกก็ได้ คิดไปๆมาๆ อ่าเจอทางออกแล้ว ปัญหา MySQL Cluster ช้า ต้องไปใช้ MySQL Replication แทน แก้ Code ลำบาก เพระา code ค่อนข้างมาก Query ต้องเร็วและเพิ่ม MySQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้มีปัญหาขึ้นมาครับ เนื่องจาก MySQL Cluster ที่ใช้งบานนั้นลองทดสอบความเร็วแล้วสู้ MySQL แล้วใช้ Local Engine ไม่ได้เลย  งานนี้เลยต้องหาทางออกครับ  ผมเลยไปมอง เรื่อง MySQL Replication  หลังจาก Setup และ Tuning เสร็จ ก็มาลองทดสอบความเร็ว  มัน Query เร็วกว่า MySQL Cluster หลายเท่าเลยครับ</p>
<p>ทีนี้ก็มาดูเรื่อง Codeing  ปัญหาคือมันเป็นโปรแกรมที่เค้าเขียนมานานละ ผมเข้าไปแก้อะไรไม่ค่อยได้ หรือถ้าแก้จริงๆ อยาจจะเป็น Bug อีกก็ได้  คิดไปๆมาๆ อ่าเจอทางออกแล้ว</p>
<p>ปัญหา</p>
<ul>
<li> MySQL Cluster ช้า ต้องไปใช้ MySQL Replication แทน</li>
<li> แก้ Code ลำบาก เพระา code ค่อนข้างมาก</li>
<li> Query ต้องเร็วและเพิ่ม MySQL Server ได้ในอนาคต</li>
</ul>
<p>ทางแก้</p>
<ul>
<li> MyQL-Proxy    ส่วนนี้ผมลองเอามาใช้แล้วครับ ลอง Query ดูมันก็ยังช้ากว่า Connect เข้า DB ตรงๆถึง 5 &#8211; 10 เท่า</li>
<li> Edit Query      ผมเลือกทางนี้ครับ แต่มันมีวิธีลักไก่หน่อย</li>
</ul>
<p>แนวคิดคือต้องไม่ไปยุ่งกะ Code มาก ผมเลยทำการสร้าง php function ใหม่ขึ้นมาครับ โดยทำหน้าที่ check sql ก่อนที่จะ Query  ว่าเป็น SELECT, UPDATE, INSERT, DELETE  แล้วให้ function ที่สร้างขึ้นมา เลือกที่จะไป query กะ mysql เครื่องไหน</p>
<p>1. สร้าง function mysql_do_query</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mysql_do_query<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count_rw</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$conn_ro</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count_rw</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count_ro</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">ereg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^SELECT(.*)&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$count_ro</span><span style="color: #339933;">++;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$conn_ro</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$count_rw</span><span style="color: #339933;">++;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>2. ทำการ edit *.php  แล้วทำการ replace mysql_query -&gt; mysql_do_query  โดยผมใช้ คำสั่ง sed ใน shell script  เพื่อแก้ไขไฟล์</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">for</span> fl <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>.php; <span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$fl</span> <span style="color: #007800;">$fl</span>.old
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/mysql_query/mysql_query/g'</span> <span style="color: #007800;">$fl</span>.old <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$fl</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$fl</span>.old
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>เสร็จแล้วก็รันครับ  shell script จะทำการ find หา *.php แล้วทำการเปลี่ยน function ให้  ต่อไปเวลา ให้ programmer เขียน codeing ก็ให้ทำการ ใช้ function mysql_do_query()  แทนครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fmysql-query-split-ro-rw-mysql_query.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/mysql-query-split-ro-rw-mysql_query.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Script Backup MySQL</title>
		<link>http://www.howtoconfig.com/development/shell-script/shell-script-backup-mysql.html</link>
		<comments>http://www.howtoconfig.com/development/shell-script/shell-script-backup-mysql.html#comments</comments>
		<pubDate>Sat, 31 May 2008 09:43:41 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Shell script]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[LIMIT]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=9</guid>
		<description><![CDATA[สวัสดีครับผม ว่าแล้ววันนี้ก็เขียน shell script ง่ายๆ เพื่อ backup mysql ลง NFS ที่ผม map ไว้ โดย script ที่เขียนขึ้นมานั้น จะมีข้อดีก็ตรงการตั้งเวลาในการลบ data เก่าทิ้งได้ #!/bin/sh &#160; export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin &#160; BACKUP_SRC=”/usr/home/mysql” BACKUP_DST=”/data/backup/mysql” LIMIT=7d &#160; ######################################## HOSTNAME=`uname -n` DATE=`date +%Y%m%d` DATE_DELETE=`date -v-${LIMIT} +%Y%m%d` BACKUP_LOG=”${BACKUP_DST}/backup.log” ######################################## &#160; echo “=============================” &#62;&#62; ${BACKUP_LOG} echo `date` &#62;&#62; ${BACKUP_LOG} echo -n “delete expire backup data..” &#62;&#62; ${BACKUP_LOG} [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">สวัสดีครับผม ว่าแล้ววันนี้ก็เขียน shell script ง่ายๆ เพื่อ backup mysql ลง NFS ที่ผม map ไว้ โดย script ที่เขียนขึ้นมานั้น จะมีข้อดีก็ตรงการตั้งเวลาในการลบ data เก่าทิ้งได้</p>

<div class="wp_syntax"><div class="code"><pre class="genero" style="font-family:monospace;"><span style="color: #008080;">#!/bin/sh</span>
&nbsp;
export PATH<span style="color: #008000;">=/</span>sbin<span style="color: #008000;">:/</span>bin<span style="color: #008000;">:/</span>usr<span style="color: #008000;">/</span>sbin<span style="color: #008000;">:/</span>usr<span style="color: #008000;">/</span>bin<span style="color: #008000;">:/</span>usr<span style="color: #008000;">/</span>local<span style="color: #008000;">/</span>sbin<span style="color: #008000;">:/</span>usr<span style="color: #008000;">/</span>local<span style="color: #008000;">/</span>bin<span style="color: #008000;">:/</span>root<span style="color: #008000;">/</span>bin
&nbsp;
BACKUP_SRC<span style="color: #008000;">=</span>”<span style="color: #008000;">/</span>usr<span style="color: #008000;">/</span>home<span style="color: #008000;">/</span>mysql”
BACKUP_DST<span style="color: #008000;">=</span>”<span style="color: #008000;">/</span>data<span style="color: #008000;">/</span>backup<span style="color: #008000;">/</span>mysql”
LIMIT<span style="color: #008000;">=</span>7d
&nbsp;
<span style="color: #008080;">########################################</span>
HOSTNAME<span style="color: #008000;">=</span>`uname <span style="color: #008000;">-</span>n`
<span style="color: #008000;">DATE</span><span style="color: #008000;">=</span>`<span style="color: #008000;">date</span> <span style="color: #008000;">+%</span>Y<span style="color: #008000;">%</span>m<span style="color: #008000;">%</span>d`
DATE_DELETE<span style="color: #008000;">=</span>`<span style="color: #008000;">date</span> <span style="color: #008000;">-</span>v<span style="color: #008000;">-</span>$<span style="color: #008080; font-style: italic;">{LIMIT}</span> <span style="color: #008000;">+%</span>Y<span style="color: #008000;">%</span>m<span style="color: #008000;">%</span>d`
BACKUP_LOG<span style="color: #008000;">=</span>”$<span style="color: #008080; font-style: italic;">{BACKUP_DST}</span><span style="color: #008000;">/</span>backup.<span style="color: #0600FF;">log</span>”
<span style="color: #008080;">########################################</span>
&nbsp;
echo “<span style="color: #008000;">=============================</span>” <span style="color: #008000;">&gt;&gt;</span> $<span style="color: #008080; font-style: italic;">{BACKUP_LOG}</span>
echo `<span style="color: #008000;">date</span>` <span style="color: #008000;">&gt;&gt;</span> $<span style="color: #008080; font-style: italic;">{BACKUP_LOG}</span>
echo <span style="color: #008000;">-</span>n “<span style="color: #0600FF;">delete</span> expire backup data..” <span style="color: #008000;">&gt;&gt;</span> $<span style="color: #008080; font-style: italic;">{BACKUP_LOG}</span>
rm <span style="color: #008000;">-</span>rf $BACKUP_DST<span style="color: #008000;">/</span>mysql<span style="color: #008000;">-</span>$DATE_DELETE <span style="color: #FF0000;">1</span><span style="color: #008000;">&gt;</span> <span style="color: #008000;">/</span>dev<span style="color: #008000;">/</span><span style="color: #0600FF;">null</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&gt;</span> <span style="color: #008000;">/</span>dev<span style="color: #008000;">/</span><span style="color: #0600FF;">null</span>
echo ” done” <span style="color: #008000;">&gt;&gt;</span> $<span style="color: #008080; font-style: italic;">{BACKUP_LOG}</span>
&nbsp;
echo <span style="color: #008000;">-</span>n “backup <span style="color: #0600FF;">database</span>..” <span style="color: #008000;">&gt;&gt;</span> $<span style="color: #008080; font-style: italic;">{BACKUP_LOG}</span>
cp <span style="color: #008000;">-</span>Rp $BACKUP_SRC $BACKUP_DST<span style="color: #008000;">/</span>$DATE
echo ” done” <span style="color: #008000;">&gt;&gt;</span> $<span style="color: #008080; font-style: italic;">{BACKUP_LOG}</span></pre></div></div>

<p style="text-align: left;">การทำงานของ script คือ ระบบจะทำการหาวันปัจจุบัน และวันที่ expire &#8220;<span style="font-weight: bold; font-size: 8pt; vertical-align: baseline; text-transform: none; font-style: normal; font-family: Tahoma; font-variant: normal; text-decoration: none;">DATE_DELETE=`date -v-${LIMIT} +%Y%m%d`</span>&#8221; โดยจะลบวันจากปัจจุบันไปอีก 7 วัน แล้วก็ค่อย Delete ทิ้งครับผม ส่วนของวัน สามารถแก้่ไขได้ครับ เป็น 7d, 1m (1เดือน) ประมาณนี้ครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fshell-script%2Fshell-script-backup-mysql.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/shell-script/shell-script-backup-mysql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เปลี่ยน view source editor ของ IE</title>
		<link>http://www.howtoconfig.com/development/change-internet-explorer-view-source-editor.html</link>
		<comments>http://www.howtoconfig.com/development/change-internet-explorer-view-source-editor.html#comments</comments>
		<pubDate>Fri, 30 May 2008 10:46:49 +0000</pubDate>
		<dc:creator>กวิน ชัยเลิศ</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=7</guid>
		<description><![CDATA[เทคนิคสำหรับเปลี่ยน view source editor ของ IE (Windows Internet Exploper) Run regedit HKEY_LOCAL_MACHINE &#124;- Software &#124;&#8211; Microsoft &#124;&#8212; Internet Explorer &#124;&#8212;- View Source Editor &#124;&#8212;&#8211; Editor Name (Default) = C:\Program Files\Vim\vim71\gvim.exe สร้างไฟล์ใหม่ชื่อ change-defaut-viewer.reg แล้ว copy ในข้อความข้างล่างนี้ไปใช้ 1 2 3 4 &#34;C:\\Program Files\\Vim\\vim71\\gvim.exe&#34; สำหรับบรรทัดสุดท้าย ให้เปลี่ยนเป็นที่อยู่ของ editor ที่ต้องการใช้สำหรับ view source *แล้วพบกลับเทคนิคการใช้งาน VIM ที่นี่ &#8230; เร็วๆ นี้ครับ]]></description>
			<content:encoded><![CDATA[<p>เทคนิคสำหรับเปลี่ยน view source editor ของ IE (Windows Internet Exploper)</p>
<p><span style="text-decoration: underline;">R</span>un <strong>regedit</strong></p>
<p>HKEY_LOCAL_MACHINE<br />
|- Software<br />
|&#8211; Microsoft<br />
|&#8212; Internet Explorer<br />
|&#8212;- View Source Editor<br />
|&#8212;&#8211; Editor Name (Default) = C:\Program Files\Vim\vim71\gvim.exe</p>
<p>สร้างไฟล์ใหม่ชื่อ change-defaut-viewer.reg แล้ว copy ในข้อความข้างล่างนี้ไปใช้</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #ff0000;">&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Program Files<span style="color: #000099; font-weight: bold;">\\</span>Vim<span style="color: #000099; font-weight: bold;">\\</span>vim71<span style="color: #000099; font-weight: bold;">\\</span>gvim.exe&quot;</span></pre></td></tr></table></div>

<p>สำหรับบรรทัดสุดท้าย ให้เปลี่ยนเป็นที่อยู่ของ editor ที่ต้องการใช้สำหรับ view source</p>
<p>*แล้วพบกลับเทคนิคการใช้งาน VIM ที่นี่ &#8230; เร็วๆ นี้ครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fchange-internet-explorer-view-source-editor.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/change-internet-explorer-view-source-editor.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

