30 มี.ค. 2555
Alway the right time to do the right thing
เป็นเวลาที่ถูกต้องเสมอถ้าอยากทำสิ่งที่ถูกต้อง ไม่มีคำว่าสาย ตอนนั้นเรียนมาอย่างแต่ไม่ชอบ อาจารย์ที่สอนบอกอย่างนี้ ชีวิตคนแปลกมากไม่เหมือนการทำธุรกิจและไม่เหมือนการทำอะไรทั้งนั้น ตรงที่มันเริ่มต้นใหม่ได้ทุกวัน จะเริ่มใหม่วันนี้หรือเดี๋ยวนี้ก็ทำได้ทั้งนั้น
http://203.155.220.217/pdd/magazine/07_50/07_04.htm
2 มี.ค. 2555
Install SARG on squid3 at Ubuntu 11.10
| apt-get install sarg |
| cp /etc/sarg/sarg.conf /etc/sarg/sarg.conf.original nano /etc/sarg/sarg.conf |
เอา Comment ออกตามบรรทัดเหล่านี้ครับ:
| access_log /var/log/squid3/access.log #ระบุตำแหน่งที่เก็บ log ของ squid graphs yes output_dir /var/www/squid-reports #เปลี่ยนที่เก็บได้ตามใจเลยครับ |
ต่อไปจะเป็นการสร้างคำสั่งให้ Sarg สร้างรายงานอัตโนมัติ และให้ Cron เป็นตัวเรียก คำสั่ง Sarg ที่เพิ่งสร้างนี้ มารันตามเวลาที่ตั้งไว้:
| nano /usr/sbin/sarg-daily-report |
| TODAY=$(date +%d/%m/%Y) YESTERDAY=$(date –date “1 day ago” +%d/%m/%Y) sarg /var/log/squid/access.log -o /var/www/squid-reports/daily -z -d $YESTERDAY-$TODAY /usr/sbin/squid -k rotate exit 0 |
| nano /usr/sbin/sarg-weekly-report |
| TODAY=$(date +%d/%m/%Y) YESTERDAY=$(date –date “1 month ago” +%d/%m/%Y) sarg /var/log/squid/access.log -o /var/www/squid-reports/monthly -z -d $YESTERDAY-$TODAY /usr/sbin/squid -k rotate exit 0 |
| chmod 755 /usr/sbin/sarg-daily-report chmod 755 /usr/sbin/sarg-weekly-report chmod 755 /usr/sbin/sarg-monthly-report |
และก็มาขั้นตอนการตั้งเวลาสร้างรายงานผ่านทาง Cron:
| crontab -e |
| 00 00 * * * /usr/sbin/sarg-daily-report 00 01 * * 1 /usr/sbin/sarg-weekly-report 03 02 1 * * /usr/sbin/sarg-monthly-report |
ถ้าอยากลองรันเพื่อทดสอบก็พิมพ์คำสั่งตามนี้:
| /usr/sbin/sarg-daily-report /usr/sbin/sarg-weekly-report /usr/sbin/sarg-monthly-report |
| /etc/init.d/cron restart |
สุดท้ายครับวิธีการดูรายงาน :
http://ip_address_server/squid-reports
1 มี.ค. 2555
How to setup Transparent Proxy with Squid3 and dhcp3-server on Ubuntu Oneiric Ocelot
Advantages of setting up Squid as Transparent Proxy include the fact that you don't need to configure all the machines on your LAN to connect to Squid manually. All the traffic would be redirected to the Squid Listening Port automatically and your Ubuntu Box would act like a Router.
Follow these steps to set up a Transparent Proxy Server with Squid3 on Ubuntu 11.10 (Oneiric Ocelot)
1. Install Ubuntu Oneiric Ocelot Server or Desktop on your computer.
2. Change your network interfaces from DHCP to Static
| nano /etc/network/interfaces |
Delete all the text and paste this text in your interfaces file:
| auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.0.12 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.3 auto eth1 iface eth1 inet static address 192.168.2.1 netmask 255.255.255.0 network 192.168.2.0 broadcast 192.168.2.255 |
Where 192.168.0.12 is the IP address of your WAN interface and 192.168.2.1 is the IP address of your LAN interface.
| nano /etc/resolv.conf |
Paste this text in the file that opens up:
| nameserver 127.0.0.1 |
suggests that one is running a local, caching-only name server.
3. Install squid3:
| sudo apt-get install squid3 |
4. Make a backup of your squid.conf for future reference. Squid.conf has nearly all the options listed and it is recommended to go through that file to know more about squid options.
| cp /etc/squid3/squid.conf /etc/squid3/squid.conf.original |
Configure squid3.
| nano /etc/squid3/squid.conf |
Remove all the text and paste this text in your squid.conf file:
| http_port 3128 transparent acl LAN src 192.168.2.0/24 acl localnet src 127.0.0.1/255.255.255.255 # Limited file download < 250 MB reply_body_max_size 250 MB http_access allow LAN http_access allow localnet # No cache anything no_cache deny all |
Where 192.168.2.0/24 is the range of your LAN interface. The last line in that file is defining a cache directory for squid3 to use. Here, the first number denotes the size of cache in MB, 20 GB in this case.
Save and close this file.
6. Restart squid3:
| /etc/init.d/squid3 restart |
7. Edit /etc/sysctl.conf:
| nano /etc/sysctl.conf |
In this file, uncomment the lines that enable packet forwarding for IPv4 and IPv6:
| net.ipv4.ip_forward=1 |
Save and close this file.
8. Define IPTABLE rules for port forwarding.
| nano /etc/fw.proxy |
Paste this text in the file that opens up:
| #!/bin/sh # squid server IP SQUID_SERVER="192.168.2.1" # Interface connected to Internet INTERNET="eth0" # Interface connected to LAN LAN_IN="eth1" # Squid port SQUID_PORT="3128" # DO NOT MODIFY BELOW # Clean old firewall iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X # Load IPTABLES modules for NAT and IP conntrack support modprobe ip_conntrack modprobe ip_conntrack_ftp # For win xp ftp client #modprobe ip_nat_ftp echo 1 > /proc/sys/net/ipv4/ip_forward # Setting default filter policy iptables -P INPUT DROP iptables -P OUTPUT ACCEPT # Unlimited access to loop back iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # Allow UDP, DNS and Passive FTP iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT # set this system as a router for Rest of LAN iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT # unlimited access to LAN iptables -A INPUT -i $LAN_IN -j ACCEPT iptables -A OUTPUT -o $LAN_IN -j ACCEPT # DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT # if it is same system iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT iptables -I INPUT -p tcp -m tcp --dport 53 --syn -j ACCEPT iptables -I INPUT -p tcp -m tcp --dport 82 --syn -j ACCEPT # Algo string iptables -I FORWARD -m string --algo bm --string "BitTorrent" -j DROP iptables -I FORWARD -m string --algo bm --string "BitTorrent protocol" -j DROP iptables -I FORWARD -m string --algo bm --string "peer_id=" -j DROP iptables -I FORWARD -m string --algo bm --string ".torrent" -j DROP iptables -I FORWARD -m string --algo bm --string "announce.php?passkey=" -j DROP iptables -I FORWARD -m string --algo bm --string "torrent" -j DROP iptables -I FORWARD -m string --algo bm --string "announce" -j DROP iptables -I FORWARD -m string --algo bm --string "tracker." -j DROP iptables -I FORWARD -m string --algo bm --string "info_hash" -j DROP iptables -I FORWARD -m string --algo bm --string "/default.ida?" -j DROP #codered virus iptables -I FORWARD -m string --algo bm --string ".exe?/c+dir" -j DROP #nimda virus iptables -I FORWARD -m string --algo bm --string ".exe?/c_tftp" -j DROP #nimda virus # bittorrent key iptables -I FORWARD -m string --string "peer_id" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "BitTorrent" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "BitTorrent protocol" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "bittorrent-announce" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "announce.php?passkey=" --algo kmp --to 65535 -j DROP # DHT keyword iptables -I FORWARD -m string --string "info_hash" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "get_peers" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "announce" --algo kmp --to 65535 -j DROP iptables -I FORWARD -m string --string "announce_peers" --algo kmp --to 65535 -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "info_hash" --algo bm -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "announce" --algo bm -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "torrent" --algo bm -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "sumotracker" --algo bm -j DROP iptables -I INPUT -p tcp -m tcp --dport 22222 --dst $SQUID_SERVER -j ACCEPT iptables -I INPUT -p tcp -m tcp --dport 22222 --dst 192.168.0.12 -j ACCEPT iptables -A INPUT -j LOG --log-level info --log-prefix "INPUT " iptables -A OUTPUT -j LOG --log-level info --log-prefix "OUTPUT " iptables -A FORWARD -j LOG --log-level info --log-prefix "FORWARD " # DROP everything and Log it iptables -A INPUT -j LOG iptables -A INPUT -j DROP |
Save and close this file.
Change Mode
| chmode +x /etc/fw.proxy |
9. Edit /etc/rc.local:
| nano /etc/rc.local |
Paste this text at the end of the file that opens up but before "exit 0":
| /etc/fw.proxy |
Save and close this file.
10. Reboot your server.
If you don't want to go to each machine on your Network and configure it for a Static IP, you can use dhcp3-server to assign Dynamic IPs to all the computers on your LAN and make them forward all there internet traffic to your squid box.
11. Install dhcp3-server:
| apt-get install dhcp3-server |
12. Edit /etc/default/dhcp3-server:
| nano /etc/default/isc-dhcp-server |
Type eth1 in between the quotes in this line:
| INTERFACES="" |
Save and close this file.
13. Make a backup of your original /etc/dhcp/dhcpd.conf:
| cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.original |
14. Edit /etc/dhcp/dhcpd.conf:
| nano /etc/dhcp/dhcpd.conf |
Delete all the text and paste this text in the file that opens up
| ddns-update-style none; log-facility local7; subnet 192.168.2.0 netmask 255.255.255.0 { range 192.168.2.100 192.168.2.200; option domain-name-servers 192.168.2.1; option routers 192.168.2.1; option broadcast-address 192.168.2.255; default-lease-time 600; max-lease-time 7200; } |
We are using True (ISP in Thailand) DNS in this example. You can use your own DNS Server if you've configured one on your network.
Save and close this file.
Make sure all the cables on your network are plugged in and the devices are powered on.
15. Start dhcp3-server:
| service dhcp3-server start |
16. Reboot your server.
| apt-get install bind9 dnsutils |
| nano /etc/bind/named.conf.options |
Delete all the text and paste this text in the file that opens up:
| options { directory "/var/cache/bind"; forwarders { 203.144.207.29; 203.144.207.49; }; auth-nxdomain no; allow-query { any; }; }; |
20 ก.พ. 2555
HOWTO: UBUNTU view Log Boot Messages
| $ sudo nano /etc/default/bootlogd |
The text editor will open, and the following will be show:
| # Run bootlogd at startup ? BOOTLOGD_ENABLE=No |
Change BOOTLOGD_ENABLE to yes
Now, everytime you restart, /var/log/boot will be created
9 ก.พ. 2555
Call Stored Procedure with Parameter By VB.Net
The SqlConnection Object is Handling the part of physical communication between the application and the SQL Server Database. An instance of the SqlConnection class in .NET Framework is supported the Data Provider for SQL Server Database. The SqlConnection instance takes Connection String as argument and pass the value to the Constructor statement. When the connection is established , SQL Commands may be executed, with the help of the Connection Object, to retrieve or manipulate data in the database. Once the Database activities over , Connection should be closed and release the database resources .
The Close() method in SqlConnection class is used to close the Database Connection. The Close method rolls back any pending transactions and releases the Connection from the SQL Server Database.
Imports System.Data.SqlClientThis My Stored Procedure
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim cnn As SqlConnection
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;UserID=UserName;Password=Password"
cnn = New SqlConnection(connetionString)
Try
cnn.Open()
MsgBox("Connection Open ! ")
Dim cmd As New SqlCommand
cmd.Connection = cnn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "search_itemcode"
cmd.Parameters.Add("@PRDocno", SqlDbType.VarChar).Value = CStr(TextBox1.Text)
Dim dr As SqlDataReader = cmd.ExecuteReader
''release resources
cnn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
End Class
ALTER PROCEDURE [dbo].[Search_itemcode]
@PrDocno varchar(15)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @docno varchar(15),@itemcode varchar(15)
-- declare the cursor
DECLARE C CURSOR FOR
select docno,itemcode
from itemprsub
where DocNo = @PrDocno
OPEN C
FETCH C INTO @docno,@itemcode
-- start the main processing loop.
WHILE @@Fetch_Status = 0
BEGIN
EXEC input_last3buy @itemno = @itemcode,@PrDocno = @docno
EXEC input_last6sale @itemcodesale = @itemcode
FETCH C INTO @docno,@itemcode
END
CLOSE C
DEALLOCATE C
EXEC input_MonthName
RETURN
END
5 ก.พ. 2555
ไม่มี IPhone 4s แต่อยากใช้ Siri (Setup Spire Server or Siri Server on Windows 7))
บนโลกอินเตอร์เน็ตก็มี Siri Proxy ไว้บริการฟรีด้วย แต่ผมไม่กล้าที่จะใช้เพราะตอนที่เราติดต่อกับ Siri Proxy (ที่เค้าให้บริการฟรีๆ หรือบางทีก็ต้องจ่ายเงินก่อน) ข้อมูลส่วนตัวของเราก็จะถูกส่งไปด้วยเช่น รายชื่อ Contact, Apple id, SMS, Location พอมาถึงจุดนี้ เรายังจะไปใช้ Proxy ของคนอื่นอีกต่อไปไหมจากที่ผมได้อ่านตามเวบต่างๆ ในการทำ Siri Proxy นี้ จำเป็นต้องมีเครื่อง IPhone 4S จริงๆ มา Copy ข้อมูลเครื่องมาเก็บไว้ที่ Siri Proxy แต่ผมไม่มีนินา แต่โชคดีครับ เดียวนี้ไม่ต้องง้อ IPhone 4S และไม่ต้องทำ Siri Proxy ด้วย เพราะวิธีที่ผมจะเขียนต่อไปนี้ก็คือวิธีการทำ Siri Server หรือ Spire Server ที่ทำหน้าแบบเดียวกับ Apple Server เลย คือเครื่อง IPhone 4 ของเราจะติดต่อกับ Spire Server ที่เรากำลังจะติดตั้งไว้ใช้ที่บ้านเอง หรือจะอธิบายว่า Siri ก็จะคุยกับ Spire Server โดยตรงเลย โดยที่จะไม่ต้องคุยกับ Apple อีกต่อไป Spire Server ซึ่งใช้วิธีการ Speech-to-Text ของ Google ในการแปลคำสั่ง และตอนนี้ยังไม่สมูบรณ์ คือไม่สามารถรับคำสั่งที่ยาวเกิน 10 วินาทีได้ ในอนาคตทางทีมผู้ผลิตก็คงจะมีการพัฒนาต่อไป
ของสำคัญที่ต้องมี (ผมติดตั้งทุกอย่างบน VMWare)
| nano /tmp/siri.sh |
| #!/bin/bash.o # # 64-bit version (if you're running 32-bit delete the "--disable-asm-opt.." # # This script will download all necessary dependencies (and curl) # both for audio handling and for python # Then it will proceed to fetch the SiriServer from # Github and install it, it will then proceed # and generate SSL-certs for both the server and client # Remeber to run Script as root as the installation will fail otherwise # Author of installation script johanberglind # I am not the author nor the creator of the server # mkdir serverfolder cd serverfolder echo "--------- SiriServer Installation Script --------" echo "If you don't have any of the dependencies installed the script will take a while to finish" read -p "Expect atleast 1-2 minutes, Press [ENTER] if you're ready to continue" clear if [ "$(which curl)" != "" ] then echo "Curl is already installed, proceeding" else echo "Downloading and installing Curl" sudo apt-get install curl fi read -p "Press [ENTER] to continue" # Checks for libogg package and if it's already installed scripts moves on to libspeex echo "Checking if Libogg is installed [10%--------]" clear if [ -f /usr/local/lib/libogg.a ] then echo "Libogg is already installed, proceeding to next step" else echo "Not installed, downloading libogg" curl http://downloads.xiph.org/releases/ogg/libogg-1.3.0.zip > libogg-1.3.0.zip unzip libogg-1.3.0.zip cd libogg-1.3.0 echo "Installing libogg" ./configure make sudo make install cd .. fi read -p "Press [ENTER] to continue" # Checks for libspeex and if it's already installed the scripts moves on to checking for flac echo "Checking if Libspeex is installed [-20%--------]" clear if [ -f /usr/local/lib/libspeex.a ] then echo "Libspeex is already installed, proceeding to next step" else echo "Not installed, downloading Libspeex" curl http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz > speex-1.2rc1.tar.gz clear echo "Download complete, unzipping" tar -xf speex-1.2rc1.tar.gz cd speex-1.2rc1 clear # Installing Speex.." echo "Installing Speex... [--30%------]" ./configure make sudo make install cd .. fi read -p "Press [ENTER] to continue" clear # Checks for FLAC and if it's already installed the scripts moves on clear echo "Checking for Flac… [----50%----]" if [ "$(which flac)" != "" ] then echo "FLAC is already installed, proceeding to next step" sudo apt-get install g++ else curl -L http://sourceforge.net/projects/flac/files/flac-src/flac-1.2.1-src/flac-1.2.1.tar.gz/download > flac-1.2.1.tar.gz clear echo "Download complete, unzipping" tar -xf flac-1.2.1.tar.gz clear echo "Installing Libflac.. [-----60%---]" cd flac-1.2.1 ./configure make sudo make install cd .. fi read -p "Press [ENTER] to continue" clear # Downloading and installing necessary python packages and easy_install if they're not already installed if [ "$(which easy_install)" != "" ] then echo "easy_install is installed, proceeding" else echo "Downloading and installing easy_install" sudo apt-get install python-setuptools clear fi clear echo "Installing Python-packages [------70%--]" sudo easy_install biplist sudo apt-get install python-m2crypto sudo easy_install jsonrpclib clear echo "Python installation complete" read -p "Press [ENTER] to continue" echo "Downloading SiriServer from Github... [---------80%-]" curl -L https://github.com/Eichhoernchen/SiriServer/tarball/master > siriserver.tar.gz clear echo "Unzipping" tar -xf siriserver.tar.gz cd Eich* cd gen_certs/ clear echo "Time to generate SSL-certs, what is the IP of the Siriserver (this computer)? [----------90%]" read IP ./gen_certs.sh $IP clear cd .. cp ca.pem ~/Desktop/ clear echo "Ok, now you need to transfer the ca.pem file to your iOS device" echo "I've copied the file to your desktop for easy access" echo "The easiest way is to mail it to yourself and open it on your iOS device" read -p "Press [ENTER] to continue to the next step when you've installed it" clear echo "(NON 4S ONLY) Go ahead and download Spire from Cydia" echo "That should take a while, but once you're done enter your IP in" echo "the settings page of Spire: $IP" read -p "Press [ENTER] to continue to the next step [100%]" clear echo "Starting Siriserver..." echo "Now go ahead and enable Siri in the general-tab in the Settings-app" echo "If everything went smooth, you should be up and running" echo "Try saying: Hello Siri" echo "Press CTRL+C to STOP" sudo python siriServer.py |
| sudo chmod +x /tmp/siri.sh ./siri.sh |
ถ้าทุกอย่างไปได้ดีจะมาค้างตรงที่ข้อความด้านล่างนี้
| INFO INFO __init__ Listening on port 443 |
Step Three: Installing Spire Server certificate to iDevice.
Wolfram Alpha : http://products.wolframalpha.com/developers/
Wordnik : http://developer.wordnik.com/
Weather Wunderground : http://www.wunderground.com/weather/api/
ในส่วนของการใส่หมายเลข Spire Proxy ให้ใส่เป็นหมายเลข IP ของ Siriserver ครับ เช่น https://192.168.1.1 หลังจากนั้นกลับมาที่ Server สั่งให้ Siri ทำงาน
| sudo python siriServer.py |
| INFO handle_accept Incoming connection from ('192.168.1.165', 50197) INFO read_next_object_from_unzipped Received a Ping (1) INFO read_next_object_from_unzipped Returning a Pong (1) INFO read_next_object_from_unzipped Received a Ping (2) INFO read_next_object_from_unzipped Returning a Pong (2) INFO read_next_object_from_unzipped Received a Ping (3) INFO read_next_object_from_unzipped Returning a Pong (3) |
16 ม.ค. 2555
ขั้นตอนการ Untethered Jailbreak IOS 5.0.1
Untethered Jailbreak Redsn0w 0.9.10b4 นี้สามารถใช้ได้กับ iPad 1, iPhone 4/3GS และ iPod Touch 4G/3G
เตรียมเครื่องมือ
Redsnow for Windows to jailbreaking ios 5.0.1
2.2) ต่อสาย iPad หรือ iPhone ที่อัพเกรดเป็น iOS 5.0.1 แล้วกับเครื่องคอมฯ
2.3) ปิดเครื่อง iPad หรือ iPhone ด้วยการกดปุ่ม Power ค้างไว้ 5 วินาทีแล้วสไลด์ตัวเลื่อนบนหน้าจอ
2.4) กดปุ่ม Jailbreak บน Redsn0w 0.9.10b4 แล้วกดปุ่ม Next

- กดปุ่ม Home เพิ่มอีกปุ่มโดยไม่ปล่อยปุ่ม Power 10 วินาที (หน้าจอจะดับเหมือนตอน Restart)
- ปล่อยปุ่ม Power แต่ยังกดปุ่ม Home ค้างไว้อยู่ (หน้าจอจะดำมืดต่อไป ไม่มีอะไรขึ้นมาเลย)

2.7) ติ๊กข้อ Install Cydia แล้วกดปุ่ม Next

