10/23/2025

Config squid 5.7

 

Config squid 5.7
คำอธิบาย Authorization ประกอบด้วย 3 ส่วน ใช้ วรรคในการแบ่ง
เช่น
acl web_bypass dstdomain "/etc/squid/web_bypass.txt"

ประกอบด้วย
acl เริ่มต้นด้วยคำสั่ง
web_bypass ตัวแปรที่จะนำไปใช้ในการ allow หรือ denied
"/etc/squid/web_bypass.txt" ค่าที่ต้องการ allow หรือ denied เก็บเป็นไฟล์ หรือใช้ค่า เลยก็ได้
ใช้ค่าเลยเช่น
acl sci_servers dstdomain .sci.com .scivalve.com .alfresco.com


คำสั่ง allow หรือ denied ประกอบด้วย 3 ส่วน ใช้วรรคเป็นตัวแบ่ง เช่น
http_access allow sci_macs

จะขึ้นต้นด้วย http_access เริ่มต้นคำสั่ง
allow จะ allow หรือ denied
sci_macs ตัวแปรที่เก็บค่าไว้ หรือ Fix ค่าไปเลยก็ได้

dstdomain คือ domain ต้องตรงกันกับค่าที่ต้องการ allow หรือ denied
url_regex -i คือ มีคำหรือข้อความนั้นใน ค่าที่ต้องการ allow หรือ denied
rep_mime_type -i mime-type คือชนิดที่ต้องการ เช่น application/x-bittorrent

ส่วนที่ 1 Authorization
  1. forwarded_for on
  2. request_header_access Allow allow all
  3. request_header_access Authorization allow all
  4. request_header_access WWW-Authenticate allow all
  5. request_header_access Proxy-Authorization allow all
  6. request_header_access Proxy-Authenticate allow all
  7. request_header_access Cache-Control allow all
  8. request_header_access Content-Encoding allow all
  9. request_header_access Content-Length allow all
  10. request_header_access Content-Type allow all
  11. request_header_access Date allow all
  12. request_header_access Expires allow all
  13. request_header_access Host allow all
  14. request_header_access If-Modified-Since allow all
  15. request_header_access Last-Modified allow all
  16. request_header_access Location allow all
  17. request_header_access Pragma allow all
  18. request_header_access Accept allow all
  19. request_header_access Accept-Charset allow all
  20. request_header_access Accept-Encoding allow all
  21. request_header_access Accept-Language allow all
  22. request_header_access Content-Language allow all
  23. request_header_access Mime-Version allow all
  24. request_header_access Retry-After allow all
  25. request_header_access Title allow all
  26. request_header_access Connection allow all
  27. request_header_access Proxy-Connection allow all
  28. request_header_access User-Agent allow all
  29. request_header_access Cookie allow all
  30. request_header_access All deny all
  31.  
  32. ################## Start SCI ################################
  33. #acl sci-mac arp 90:21:55:02:6c:e2
  34. acl sci_macs arp "/etc/squid/MAC.lst"
  35. http_access allow sci_macs
  36.  
  37. acl sci_servers dstdomain .sci.com .scivalve.com .alfresco.com
  38. always_direct allow sci_servers
  39. http_access allow sci_servers
  40.  
  41. #Google
  42. acl googles dstdomain .google.com
  43. #always_direct allow googles
  44. http_access allow googles
  45.  
  46. #hotmail
  47. acl HM_SERVER dstdomain .msn.com .hotmail.com .passport.com .live.com .outlook.live.com .outlook.office.net .scivalve.com
  48. http_access allow HM_SERVER
  49.  
  50. acl web_bypass dstdomain "/etc/squid/web_bypass.txt"
  51. http_access allow web_bypass
  52.  
  53. acl GoodSites dstdomain "/etc/squid/goodsites.txt"
  54. #acl GoodSites url_regex -i "/etc/squid/goodsites.txt"
  55. http_access allow GoodSites
  56.  
  57. acl webblocked url_regex -i '/etc/squid/webblocked.txt'
  58. #acl webblocked dstdomain '/etc/squid/webblocked.txt'
  59. http_access deny webblocked
  60. #deny_info denied.html webblocked
  61.  
  62. acl TorrentFiles rep_mime_type -i mime-type application/x-bittorrent
  63. http_reply_access deny TorrentFiles
  64. deny_info TCP_RESET TorrentFiles
  65.  
  66. auth_param basic program /usr/lib/squid/basic_ldap_auth -v 3 -b "cn=Users,dc=sci,dc=com" -D CN=ldap-user,CN=Users,DC=SCI,DC=COM -w PASSWORD -f "(&(sAMAccountName=%s)(objectClass=person)(memberof=CN=InetAllow,OU=SCI,DC=SCI,DC=COM))" -h dc04.sci.com
  67. acl ldap-auth proxy_auth REQUIRED
  68.  
  69. #external_acl_type InetGroup %LOGIN /usr/lib/squid3/ext_wbinfo_group_acl
  70.  
  71. #acl InetAccessFree external InetGroup FreeNet
  72. #http_access allow InetAccessFree
  73.  
  74. acl webblocked_tmp dstdomain '/etc/squid/webblocked_tmp.txt'
  75. acl day_am time 08:00-11:59
  76. acl day_pm time 13:00-17:39
  77. acl day_ot time 18:00-20:59
  78. acl day_after time 21:00-23:59
  79. acl day_before time 00:00-05:59
  80. http_access deny webblocked_tmp day_am
  81. http_access deny webblocked_tmp day_pm
  82. http_access deny webblocked_tmp day_ot
  83. http_access deny webblocked_tmp day_after
  84. http_access deny webblocked_tmp day_before
  85.  
  86. acl domain_blocked dstdomain '/etc/squid/webblocked_https.txt'
  87. http_reply_access deny domain_blocked day_am
  88. http_reply_access deny domain_blocked day_pm
  89. http_reply_access deny domain_blocked day_ot
  90. http_reply_access deny domain_blocked day_after
  91. http_reply_access deny domain_blocked day_before
  92. http_access deny CONNECT domain_blocked day_am
  93. http_access deny CONNECT domain_blocked day_pm
  94. http_access deny CONNECT domain_blocked day_ot
  95. http_access deny CONNECT domain_blocked day_after
  96. http_access deny CONNECT domain_blocked day_before
  97.  
  98. http_access allow ldap-auth
  99. #SCI End 
  100.  

ส่วนที่ 2 localnet และ ports
  1. #Start SCI
  2. acl localnet src 192.168.0.0/24 192.168.100.0/24 192.168.2.0/24
  3. acl SSL_ports port 995          #mail.scivalve.com new
  4. acl SSL_ports port 8443         #scivalve.com new
  5. acl SSL_ports port 443
  6. acl SSL_ports port 993
  7. acl SSL_ports port 2222         # SCI: for hosting
  8. acl SSL_ports port 6301         # gpsiam
  9.  
  10. acl Safe_ports port 80          # http
  11. acl Safe_ports port 110         # SCI: POP3
  12. acl Safe_ports port 587         # SCI: smtp
  13. acl Safe_ports port 25          # SCI: smtp
  14. #End SCI


ส่วนที่ 3 Log Server
  1. #SCI Start Sent Log Squid To Log Server
  2. #Sent To access.log file.
  3. access_log /var/log/squid/access.log squid
  4.  
  5. #Sent To Log Server.
  6. logformat squid %tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
  7. access_log tcp:192.168.2.108:514 squid
  8. #SCI End

9/25/2025

Proxmox : upgrade PVE version from 8 to 9

 1.ตรวจสอบว่ามีปัญหาในการ upgrade หรือไม่ แล้วแก้ไขรายการที่ fail ให้ผ่านก่อน
มีสีเหลืองได้ แต่ถ้าสีแดงต้องแก้ก่อน

  1. pve8to9

2.Shutdown VM และ CT ทั้งหมด
3.ตรวจสอบสถานะปัจจุบัน
  1. apt update
  2. apt dist-upgrade
  3. pveversion


4.แก้ไข Repositories ให้เป็นตัวใหม่ ต้องแก้ตัวนี้ให้เป็นตัวใหม่ก่อน เพราะตอน update ยังใช้ sources นี้อยู่
  1. sed -i 's/bookworm/trixie/g' /etc/apt/sources.list


5. สร้างไฟล์ Repositories ที่ต้องใช้สำหรับ Version ใหม่
  1. cat > /etc/apt/sources.list.d/pve-enterprise.sources << EOF
  2. Types: deb deb-src
  3. URIs: http://mirror.kku.ac.th/debian/
  4. Suites: trixie
  5. Components: main non-free-firmware
  6. Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
  7.  
  8. Types: deb deb-src
  9. URIs: http://security.debian.org/debian-security/
  10. Suites: trixie-security
  11. Components: main non-free-firmware
  12. Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
  13.  
  14. Types: deb deb-src
  15. URIs: http://mirror.kku.ac.th/debian/
  16. Suites: trixie-updates
  17. Components: main non-free-firmware
  18. Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
  19. EOF

6.update+upgrade
apt update
apt dist-upgrade
จะมีข้อความให้ตอบ
ตอบ q enter
ตอบ Yes เฉพาะ /etc/lvm/lvm.conf
นอกนั้น No ทั้งหมด

7. ปิด sources.list เดิมไม่ได้ใช้ ใส่ # ไว้
  1. nano /etc/apt/sources.list


หรือปิดผ่านหน้า GUI ใน Nodes --> pve --> Repositories

ที่มา : https://pve.proxmox.com/wiki/Upgrade_from_8_to_9

 

หากมีปัญหาหรือ Error ให้กลับไปใช้ Kernel เดิม แล้วทำการ แก้ไขเริ่มต้น upgrade ใหม่
1. ดูว่าใช้ kernel ไหนอยู่

  1. uname -a

Linux pve44 6.8.12-15-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-15 (2025-09-12T11:02Z) x86_64 GNU/Linux

2. list ดู kernel
  1. proxmox-boot-tool kernel list

แล้วย้อนกลับไปที่ kernel เก่า
  1. proxmox-boot-tool kernel pin 6.8.12-15-pve --next-boot

3. reboot
แล้วแก้ไขทำการเริ่ม upgrade ใหม่

เมื่อ upgrade ได้แล้ว ต้อง unpin kernel เพื่อให้ใช้ kernel ล่าสุด
  1. proxmox-boot-tool kernel unpin 
  1. proxmox-boot-tool kernel list
  1. uname -a

 

9/23/2025

Ubuntu 18.04 Samba share เข้า terminal ภาษาไทยไม่แสดง

 Ubuntu 18.04 Samba share เข้า terminal ภาษาไทยไม่แสดง

ตั้งตั้งค่า locales
1. คำสั่ง

  1. dpkg-reconfigure locales

2. เลือก
th_TH.UTF-8 UTF-8

 


 

Home Assistant with Docker กล้อง ONVIF แจ้งเตือนเข้า Rocketchat

 *** หาต้องการให้แสดงรูป ต้องใช้ url
https://rocket.scivalve.com
- หากใช้ IP จะเห็น รูปได้เครื่องอยู่ในวง network เดียวกัน
- ใช้ chat.scivalve.com ใน app จะไม่เห็น เพราะ app ชี้ url ไปที่ rocket.scivalve.com
ให้ใช้ rocket.scivalve.com จะเห็นทั้งในหมด
ขึ้นตอน
1. Add integration ONVIF ถ้ากล้องอยู่วงเดียวกันกับ HA จะเจอเลย ถ้าไม่เจอ Add Manual Port 10080
2. Add กล้องสำหรับ view เข้า Dashboard ไว้ดู By entity แล้วเลือก Profile กล้องที่ต้องการ
*** หาวิธีส่งรูปตรง ๆ จาก HA แล้วไม่ได้ ติดปัญหา กล้องไม่มี function ที่ snap เป็น jpg จึงทำไม่ได้ ****
แก้ปัญหาโดย เขียน code python save ลง docker แล้วให้ HA เรียกใช้ python ส่งแจ้งเตือนเข้า Rocketchat
3. สร้างไฟล์ python ที่ Home Assistant
ไว้ที่ /HA/snapshot.py
Code

  1. #!/usr/bin/env python3
  2. import requests
  3.  
  4. url = "http://xxx.xx.xx.xx:8080/snapshot.cgi?user=xxx&pwd=xxx"
  5. res = requests.get(url, stream=True)
  6.  
  7. if res.status_code == 200:
  8.     #with open("/HA/www/snapshot.jpg", "wb") as f:
  9.     with open("/config/www/snapshot.jpg", "wb") as f:
  10.        for chunk in res.iter_content(1024):
  11.             f.write(chunk)
  12.  
  13.     url = "http://xxx.xx.xx.xx:3000/api/v1/rooms.upload/RoomId"
  14.     #url = "https://chat.scivalve.com/api/v1/rooms.upload/RoomId"
  15.     headers = {
  16.         "X-Auth-Token": "xxx",
  17.         "X-User-Id": "xxx"
  18.     }
  19.    
  20.     files = {
  21.         #"file": ("snapshot.jpg", open("/HA/www/snapshot.jpg", "rb"), "image/jpeg")
  22.         "file": ("snapshot.jpg", open("/config/www/snapshot.jpg", "rb"), "image/jpeg")
  23.     }
  24.  
  25.     data = {
  26.         "msg": "พบการเคลื่อนไหวจากกล้อง SERVER A"
  27.     }
  28.  
  29.     response = requests.post(url, headers=headers, files=files, data=data)
  30.     #print(response.text)
  31.     #print("Snapshot saved")
  32. else:
  33.     print("Error:", res.status_code)


***สำคัญไฟล์ ที่ save และส่ง ต้องใช้ใน /config/ เพื่อให้รูปได้จริง หากไว้ใน /HA/ จะ run คำสั่ง python ตรง ๆ ได้ แต่เมื่อ Home Assistant เรียกใช้จะส่งรูปไม่ได้ ***
RoomId หาได้จาก คำสั่ง
  1. curl -H "X-Auth-Token: xxx" \
  2.      -H "X-User-Id: xxx" \
  3.      http://xxx.xxx.xx.xx:3000/api/v1/rooms.info?roomName=ชื่อห้อง

เช่น
  1. curl -H "X-Auth-Token: xxx" \
  2.      -H "X-User-Id: xxx" \
  3.      http://xxx.xxx.xx.xx:3000/api/v1/rooms.info?roomName=Test

จะได้ _id คือ room id
{"room":{"_id":"xxx","fname":"Test"
{"room":{"_id":"xxx","fname":"IT_Notification",

4. configuration.yaml สำหรับเรียกใช้ python เพิ่ม
  1. shell_command:
  2.    send_snapshot: "python3 /config/snapshot.py"
  3.  


5. automation.yaml เพิ่ม
  1. - id: motion_alert_server_a
  2.   alias: "แจ้งเตือน SERVER A พร้อมส่งรูป"
  3.   trigger:
  4.     - platform: state
  5.       entity_id: binary_sensor.ip_camera_cell_motion_detection
  6.       to: "on"
  7.   action:
  8.     - service: shell_command.send_snapshot

9/18/2025

ส่งค่าอุณหภูมิจาก Pi ไป Home Assistant แบบ Docker

 ส่งค่าอุณหภูมิจาก Pi ไป Home Assistant แบบ Docker

ต่อจาก
https://intranet.scivalve.com/blog.php?u=281&b=2051

1. ตัว HA ลงแบบ Docker ก็ต้อง Mosquitto ด้วย Docker container
1.1. สร้างโฟลเดอร์เก็บ config/data/log ของ Mosquitto:

  1. mkdir -p /HA/mosquitto/config /HA/mosquitto/data /HA/mosquitto/log

1.2. สร้างไฟล์ config
  1. nano /HA/mosquitto/config/mosquitto.conf

1.3. ใส่ค่า
แบบใช้ได้หมด ไม่ต้องใส่ use password ไม่ปลอดภัย
  1. persistence true
  2. persistence_location /mosquitto/data/
  3. log_dest file /mosquitto/log/mosquitto.log
  4.  
  5. allow_anonymous true
  6. listener 1883

แบบตั้ง user password
  1. persistence true
  2. persistence_location /mosquitto/data/
  3. log_dest file /mosquitto/log/mosquitto.log
  4.  
  5. allow_anonymous false
  6. password_file /mosquitto/config/password.txt
  7. listener 1883


1.4. สร้าง user ด้วยคำสั่ง
docker run --rm -it \
  1.  -v /HA/mosquitto/config:/mosquitto/config \
  2.   eclipse-mosquitto mosquitto_passwd -c /mosquitto/config/password.txt hauserXXXXX

มันจะถาม password ให้คุณใส่ → เก็บไว้ใน /HA/mosquitto/config/password.txt

1.5. รัน container Mosquitto:
  1. docker run -d \
  2.   --name mosquitto \
  3.   -p 1883:1883 \
  4.   -p 9001:9001 \
  5.   -v /HA/mosquitto/config:/mosquitto/config \
  6.   -v /HA/mosquitto/data:/mosquitto/data \
  7.   -v /HA/mosquitto/log:/mosquitto/log \
  8.   eclipse-mosquitto


1.6. Restart Mosquitto
  1. docker restart mosquitto


1.7. ทดสอบ ที่เครื่อง HA Run
  1. mosquitto_sub -h localhost -p 1883 -u "hauser" -P "รหัสผ่าน" -t "#"


1.8. ที่เครื่องเรา ติดตั้ง
  1. apt install mosquitto-clients -y

แล้วลองส่งค่าไป
  1. mosquitto_pub -h 192.168.2.5 -p 1883 -u "xxx" -P "xxxx" -t "test/topic" -m "Hello MQTT"
  1. mosquitto_pub -h 192.168.2.5 -p 1883 -u "xxx" -P "xxxx" -t "hass/sensor/temperature" -m "27"

ที่ Terminal ของ HA จะต้องเห็นข้อความ Hello MQTT

1.9. ที่ เครื่อง HA เพิ่ม ที่ไฟล์ configuration.yaml เป็น Sensor และรอรับค่า MQTT
  1. mqtt:
  2.   sensor:
  3.     - name: "Server Temp."
  4.       state_topic: "hass/sensor/temperature"
  5.       value_template: "{{ value_json.temperature }}"
  6.       unit_of_measurement: "°C"
  7.  
  8.     - name: "Server Hum."
  9.       state_topic: "hass/sensor/temperature"
  10.       value_template: "{{ value_json.humidity }}"
  11.       unit_of_measurement: "%"


1.10. เข้า Setting --> Devices & Services Add integration MQTT เข้าไปด้วย
ใส่ IP User Password

1.11. ที่เครื่อง pi ทดลอง run python Code temp2mqtt.2.5.py
  1. #!/usr/bin/python3
  2. import sys
  3. import Adafruit_DHT
  4.  
  5. import time, json
  6. import RPi.GPIO as GPIO
  7. import paho.mqtt.client as mqtt
  8.  
  9. import requests
  10.  
  11. # Config
  12. MQTT_BROKER = "192.168.2.5"   # IP ของ Home Assistant
  13. MQTT_PORT = 1883
  14. MQTT_USER = "xx"
  15. MQTT_PASSWORD = "xx"
  16. MQTT_TOPIC = "hass/sensor/temperature"
  17.  
  18. SENSOR = Adafruit_DHT.AM2302  # หรือ DHT11 แล้วแต่ที่ใช้
  19. PIN = 4  # GPIO ที่ต่อ sensor
  20.  
  21. # Connect MQTT
  22. client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
  23. client.username_pw_set(MQTT_USER, MQTT_PASSWORD)
  24. client.connect(MQTT_BROKER, MQTT_PORT, 60)
  25.  
  26. # Try to grab a sensor reading.  Use the read_retry method which will retry up
  27. # to 15 times to get a sensor reading (waiting 2 seconds between each retry).
  28. humidity, temperature = Adafruit_DHT.read_retry(SENSOR, PIN)
  29.  
  30. # Un-comment the line below to convert the temperature to Fahrenheit.
  31. # temperature = temperature * 9/5.0 + 32
  32.  
  33. from datetime import datetime
  34. if humidity is not None and temperature is not None:
  35.    print('Temp={0:0.1f}*  Humidity={1:0.1f}%  Date={2}'.format(temperature, humidity, datetime.today().strftime('%Y-%m-%d %H:%M:%S')))
  36.    payload = {
  37.         "temperature": round(temperature, 2),
  38.         "humidity": round(humidity, 2)
  39.    }
  40.    #print('{0}'.format(json.dumps(payload)))
  41.    client.publish(MQTT_TOPIC, json.dumps(payload))
  42.  


แก้ Code ให้ส่ง MQTT ไป 2 เครื่อง
  1. #!/usr/bin/python3
  2. import Adafruit_DHT
  3. import time, json
  4. from datetime import datetime
  5. import paho.mqtt.client as mqtt
  6.  
  7. # Config broker 1
  8. MQTT_BROKER1   = "192.168.0.187"
  9. MQTT_PORT1     = 1883
  10. MQTT_USER1     = "xxx"
  11. MQTT_PASSWORD1 = "xxx"
  12. BROKER1_TOPIC  = "hass/sensor/temperature"
  13.  
  14. # Config broker 2
  15. MQTT_BROKER2   = "192.168.2.5"
  16. MQTT_PORT2     = 1883
  17. MQTT_USER2     = "xxx"
  18. MQTT_PASSWORD2 = "xxx"
  19. BROKER2_TOPIC  = "hass/sensor/temperature"
  20.  
  21. SENSOR = Adafruit_DHT.AM2302
  22. PIN = 4
  23.  
  24. # อ่านค่าจาก DHT
  25. humidity, temperature = Adafruit_DHT.read_retry(SENSOR, PIN)
  26.  
  27. if humidity is not None and temperature is not None:
  28.     payload = {
  29.         "temperature": round(temperature, 2),
  30.         "humidity": round(humidity, 2)
  31.     }
  32.  
  33.     print(f"Publish: {payload} at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
  34.  
  35.     # ส่งไป broker 1
  36.     client1 = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
  37.     client1.username_pw_set(MQTT_USER1, MQTT_PASSWORD1)
  38.     client1.connect(MQTT_BROKER1, MQTT_PORT1, 60)
  39.     client1.publish(BROKER1_TOPIC, json.dumps(payload))
  40.     client1.disconnect()
  41.  
  42.     # ส่งไป broker 2
  43.     client2 = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
  44.     client2.username_pw_set(MQTT_USER2, MQTT_PASSWORD2)
  45.     client2.connect(MQTT_BROKER2, MQTT_PORT2, 60)
  46.     client2.publish(BROKER2_TOPIC, json.dumps(payload))
  47.     client2.disconnect()