Showing posts with label squid. Show all posts
Showing posts with label squid. Show all posts

Saturday, March 19, 2016

การ Create user สำหรับใช้งาน Squid proxy

              การ Add user squid ผ่านทางหน้า web browser เป็นการอำนวยความสะดวกให้กับ admin หรือ IT support ที่ไม่มีความชำนาญในการใช้ Command line เพื่อเข้าไปจัดการกับระบบ user ใช้งานอินเตอร์เน็ต ส่วนการแอด user ด้วย command line อ่านได้จาก configure-squid3-proxy 
             สิ่งที่ต้องทำคือ ติดตั้ง webmin เพิ่มเข้า ดังนี้
1. install package libnet-ssleay-perl เพื่อใช้ ssl ดังนี้ * หากไม่ต้องการใช้ สามารถข้ามข้อนี้ไปได้เลย
#apt-get install -y libnet-ssleay-perl

2. ไปที่เว็บไซต์ http://www.webmin.com/download.html



ก็อปปี้ Link http://prdownloads.sourceforge.net/webadmin/webmin-1.791.tar.gz แล้วดาวน์โหลด

#wget http://prdownloads.sourceforge.net/webadmin/webmin-1.791.tar.gz
unzip file tar.gz
#tar zvxf http://prdownloads.sourceforge.net/webadmin/webmin-1.791.tar.gz
ติดตั้ง webmin
#sh webmin-1.791/setup.sh
Configure
- Web server port (default 10000): Enter ผ่าน
- Login name (default admin): sysadmin เปลี่ยน user login webmin
Login password: ใส่พาสเวิร์ด 2 ครั้ง
Password again:
- Use SSL (y/n): y เปิดใช้งาน ssl ซึ่งเวลาเรียกใช้งาน https://
- Start Webmin at boot time (y/n): y ให้ใช้งานได้ทุกครั้งที่เปิดเครื่อง

* หากต้องการถอด webmin ให้ใช้คำสั่ง
sh /etc/webmin/uninstall.sh

3. การเรียกใช้งานเปิด Browser แล้วพิมพ์ url: ตัวอย่าง https://proxy:10000/


ใส่ user name and password webmin


4. เมนูด้านซ้าย คลิ๊กไปที่ Server -> Squid Proxy Server


5. คลิ๊กไปที่เมนู Proxy Authentication 



6. คลิ๊ก Add a new proxy user 
7. สร้าง user สำหรับใช้งาน
8. กลับมาที่เมนูสร้าง user จะแสงรายชื่อผู้ใช้งานที่มีอยู่แล้ว และที่เราสร้างใหม่ สำหรับการเพิ่ม ลบ หรือเปลี่ยน password user จะต้องกดปุ่ม Apply Changes ที่มุมบนด้านขวาของจอ เพื่อปรับค่า configure ให้ใช้งานได้ ดูรูปด้านล่าง 

With the right ACLs, access to your proxy server can be limited to the users listed below, taken from the file /etc/squid3/passwd. After adding, deleting or changing a user you must use the Apply Changes link for the modification to take effect.


9. ปิด Browser และเปิดใหม่อีกครั้งเพื่อทดสอบ user ที่เราสร้างขึ้น ที่สำคัญอย่าลืม proxy ให้กับ Browser นั้น ๆ ด้วยนะครับ




Saturday, March 12, 2016

รวมคำสั่งที่ใช้ในการ configure squid3 proxy

Command
#Install
apt-get update ; apt-get install -y squid3 apache2-utils

#configure
mv /etc/squid/squid.conf /etc/squid/squid.conf.bkp --> Backup configure
# แยกเอา comment ออกเหลือไว้เฉพาะค่าคอนนฟิก
grep -Eiv '(^#|^$)' /etc/squid/squid.conf.bkp
or
grep -ve ^# -ve ^$ /etc/squid/squid.conf.bkp > /etc/squid/squid.conf

#Authentication & create new user
touch /etc/squid3/passwd
htpasswd -c /etc/squid3/passwd user

การเช็ค user ที่เราสร้าง
#/usr/lib/squid3/ncsa_auth /etc/squid3/passwd
username password กด Enter
OK  --> Status

#Delete user
*ลบ user ในไฟล์ /etc/squid3/passwd ทิ้ง

#Rotate log file
30 0 * * *    /usr/sbin/squid3 -k rotate

1. squid3 -v = show version
2. ps aux|grep squid = check process squid
3. squid3 -z = create swap directory
4. squid 3 -k reconfigure = update configure immediately
5. service squid3 restart = restart service
6. view squid log
    6.1 tail -f /var/log/squid3/access.log
    6.2 tail -f /var/log/squid3/access.log | grep user ดูเฉพาะ user คนนี้
    6.3 tail -f /var/log/squid3/access.log | grep -oE 'http.*'

** แก้ไขปัญหา squid3 ออกเว็บไซต์ www.google.com ไม่ได้
ให้เพิ่ม dns_v4_first on เข้าไปแล้ว service squid3 restart เปิดได้แล้ว
Ref: squid3-cant-access-google-com-or-bing-com


custome squid log

ปรับแต่ง access.log ใน squid เพื่อให้แสดงวันที่ด้วย ดังนี้

Setting Maximum Download Size

Ref. linuxquestions.org




ตัวอย่าง

Old




New



Such as when an allstaff email goes out saying "check this site out..."
  • TCP_MISS/200 means that the requested document was not in the cache but it could fetch it OK from the web server. The direct at the end says that the file was fetched from the webserver.
  • TCP_IMS_HIT/304 means that the client asked if the file has changed, and squid checked its date/time on the webserver and found it had not changed, so it gave a copy of the file to the client out of its local cache.
Ref: imrgill.com
การปรับแต่ง log ให้เอาชื่อ user Authen ขึ้นมาก่อน
อันเก่าเรียง ตาม date, repornse time, ip, website, user login, ....



อันใหม่เรียง date, response time, user login, ....
ให้แก้ไขโดยนำ %un ขึ้นมาก่อน %>a
*สามารถใส่คำ เช่น user=[%un] ได้ดังรูปด้านล่าง



ตรวจสอบ log ดูภาพด้านล่าง
log formate code



Log format codes  

Field name syntax keys:
     {} modifier or argument. Also used to specify header names
     >  request (client)
     <  reply (server)
     a  address
     A  address name
     h  all headers
     i  ident
     p  port
     r  request line (no query)
     t  time
     u  user
     l  local address/port (where request was accepted)

Add caption






Squid Format
Ref. trafficserver.apache.org



 






1
    cqtq The client request timestamp in Squid format; the time of the client request in seconds since January 1, 1970 UTC (with millisecond resolution).
2
    ttms The time Traffic Server spent processing the client request; the number of milliseconds between the time the client established the connection with Traffic Server and the time Traffic Server sent the last byte of the response back to the client.
3
    chi The IP address of the client’s host machine.
4

    crc/pssc The cache result code; how the cache responded to the request: HIT, MISS, and so on. Cache result codes are described here.

        The proxy response status code (the HTTP response status code from

    Traffic Server to client).
5
    psql The length of the Traffic Server response to the client in bytes, including headers and content.
6
    cqhm The client request method: GET, POST, and so on.
7
    cquc The client request canonical URL; blanks and other characters that might not be parsed by log analysis tools are replaced by escape sequences. The escape sequence is a percentage sign followed by the ASCII code number of the replaced character in hex.
8
    caun The username of the authenticated client. A hyphen (-) means that no authentication was required.
9
    phr/pqsn The proxy hierarchy route; the route Traffic Server used to retrieve the object.

    The proxy request server name; the name of the server that fulfilled the request. If the request was a cache hit, then this field contains a hyphen (-).
10
    psct The proxy response content type; the object content type taken from the Traffic Server response header.

Monday, March 7, 2016

how to install squid proxy with Authentication

For install and configure
 --------------------การติดตั้ง-------------------------------------
ติดตั้ง squid proxy ด้วยคำสั่ง
apt-get update ; apt-get install -y squid3 apache2-utils

การแก้ไขค่าคอนฟิก โดยให้ตัดเอาเครื่องหมาย #comment ออกเหลือแต่ค่า configure อย่างเดียว ใช้คำสั่งต่อไปนี้

mv /etc/squid/squid.conf /etc/squid/squid.conf.bkp --> Backup configure

grep -Eiv '(^#|^$)' /etc/squid/squid.conf.bkp
or
grep -ve ^# -ve ^$ /etc/squid/squid.conf.bkp > /etc/squid/squid.conf

การสร้าง user สำหรับเข้าใช้งานอินเตอร์เน็ต  For debian
touch /etc/squid3/passwd
htpasswd -c /etc/squid3/passwd user
ใส่ password 2 ครั้ง

การเช็ค user ที่เราสร้าง
#/usr/lib/squid3/ncsa_auth /etc/squid3/passwd
username password กด Enter
OK  --> Status

----------------------------------------------------------------------

----------------file squid--------------------------------------
1. Authentication
2. Block website

------Start-------
# Access Control Options
#-----------------------
#
acl QUERY urlpath_regex -i cgi-bin \? \.php$ \.asp$ \.shtml$ \.cfm$ \.cfml$ \.phtml$ \.php3$ localhost
acl all src
acl localhost src 127.0.0.1/32 ::1
acl localnet src 192.168.1.0/24 # Internal network
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl forbidden dstdomain "/etc/squid3/block_website"
http_access deny forbidden
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl manager proto cache_object
acl purge method PURGE
acl CONNECT method CONNECT

#Authentication
# -------------
#
auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/passwd
#auth_param basic credentialsttl 30 minutes
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
auth_param basic realm Squid proxy-caching web server for Lee Moyoon system
acl ncsa proxy_auth REQUIRED
http_access allow ncsa

#
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow localnet
http_access deny all
#
# Network Option
# ------------
#
http_port 3128
#
# Option which affect the cache size
# ===============
#
cache_mem 8 MB
maximum_object_size_in_memory 32 KB
memory_replacement_policy heap GDSF
cache_replacement_policy heap LFUDA
cache_dir ufs /var/cache/squid 1000 16 256
maximum_object_size 100 MB
cache_swap_low 95
cache_swap_high 99
#
# Option for tuning the cache
# =====================
#
cache deny QUERY
refresh_pattern ^ftp: 1440 20% 10080 reload-into-ims
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i \.(gif|png|jp?g|ico|bmp|tiff?)$ 10080 95% 43200 override-expire override-lastmod reload-into-ims ignore-no-cache ignore-private
refresh_pattern -i \.(rpm|cab|deb|exe|msi|msu|zip|tar|xz|bz|bz2|lzma|gz|tgz|rar|bin|7z|doc?|xls?|ppt?|pdf|nth|psd|sis)$ 10080 90% 43200 override-expire override-lastmod reload-into-ims ignore-no-cache ignore-private
refresh_pattern -i \.(avi|iso|wav|mid|mp?|mpeg|mov|3gp|wm?|swf|flv|x-flv|axd)$ 43200 95% 432000 override-expire override-lastmod reload-into-ims ignore-no-cache ignore-private
refresh_pattern -i \.(html|htm|css|js)$ 1440 75% 40320
refresh_pattern -i \.index.(html|htm)$ 0 75% 10080
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 1440 90% 10080
#
quick_abort_min 0 KB
quick_abort_max 0 KB
quick_abort_pct 100
store_avg_object_size 13 KB
#
# HTTP Option
# ==========
vary_ignore_expire on
#
# ANONIMITY OPTIONS
# ===============
#
request_header_access From deny all
request_header_access Server deny all
request_header_access Link deny all
request_header_access Via deny all
request_header_access X-Forwarded-For deny all
#
------End--------

สร้างไฟล์ block_website /etc/squid/block_website

root@proxy:/etc/squid3# cat block_website
.twitter.com
.pinterest.com
.cyberciti.biz


ปรับใช้งาน squid ด้วยคำสั่ง
squid3 -k reconfigure

Reference: adilmehmoodbutt
----------------------------------------------------------------------

1. tecmint.com
Base on debian
* เว็บไซต์ไทย
ireallyhost.com
* การปรับแต่ง cach
rmutsv.ac.th/blogs
* Transparent proxy
topcomputer.co.th

2. wiki.squid-cache.org
Permit some time, All day
Ext.

acl foo proxy_auth REQUIRED
acl bar proxy_auth lisa sarah frank joe
acl daytime time 08:00-17:00
http_access allow foo daytime
http_access allow bar
http_access deny all

3. switchroot.com
For create file Create a NCSA password

4.linode.com
Base on Ubuntu
Ext. command

sudo htpasswd /etc/squid3/squid_passwd user1

5.arashmilani.com
Base on CentOS 6.5
Ext. command

sudo htpasswd -d /etc/squid/squid_passwd john