1/25/2017

Lightsquid : Lightsquid On Ubuntu 16.04

Lightsquid : Lightsquid On Ubuntu 16.04
ต่อจากติดตั้ง Squid Proxy เสร็จ
http://porpramarn.blogspot.com/2017/01/proxy-ubuntu-1604-squid.html
ติดตั้ง Lightsquid ต่อเพื่อไว้ดูรายงานต่าง ๆ
- downlosd
http://sourceforge.net/projects/lightsquid/files/lightsquid/lightsquid-1.8.tgz

- เอาไว้ทีเครื่องอื่น แล้ว scp หรือ wget เอา
- cd เข้าไปใน Folder ที่ มีไฟล์ ightsquid-1.8.tgz
แตกไฟล์
  1. tar xvzf lightsquid-1.8.tgz

move file ไปไว้ที่ /usr/local/lightsquid
  1. mv lightsquid-1.8 /usr/local/lightsquid

- แก้ lightsquid.cfg
  1. nano /usr/local/lightsquid/lightsquid.cfg

แก้ Path
  1. #path to additional `cfg` files
  2. $cfgpath             ="/var/local/lightsquid";
  3. #path to `tpl` folder
  4. $tplpath             ="/usr/local/lightsquid/tpl";
  5. #path to `lang` folder
  6. $langpath            ="/usr/local/lightsquid/lang";
  7. #path to `report` folder
  8. $reportpath          ="/usr/local/lightsquid/report";
  9. #path to access.log
  10. $logpath             ="/var/log/squid";
  11. #path to `ip2name` folder
  12. $ip2namepath         ="/usr/local/lightsquid/ip2name";
  13.  
  14. $skipurl             = 'sci\.com|192\.168\.2\.';


- check ว่ามี error หรือไม่
  1. /usr/local/lightsquid/check-setup.pl


- สร้าง Link เข้า Web
  1. nano /etc/apache2/conf-available/lightsquid.conf

ใส่ Code เข้าไป
  1. Alias /lightsquid /usr/local/lightsquid/
  2.  
  3. <Directory "/usr/local/lightsquid/">
  4.     Options +Indexes +ExecCGI
  5.     AddHandler cgi-script .cgi .pl
  6.     AllowOverride All
  7.     Order allow,deny
  8.     Allow from all
  9.     Require all granted
  10. </Directory>


- Test เข้า lightsquid ip/lighsquid
  1. 192.168.2.116/lighsquid


Error
client denied by server configuration: /usr/local/lightsquid/

ต้อง run คำสั่ง
  1. a2enmod cgi
  2. a2enconf lightsquid
  3. systemctl restart apache2


- Test เข้า lightsquid ip/lighsquid
  1. 192.168.2.116/lighsquid


Error
Can't locate CGI.pm in @INC (you may need to install the CGI module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/local/lightsquid/index.cgi line 19. BEGIN failed--compilation aborted at /usr/local/lightsquid/index.cgi line 19.


ต้องติดตั้งโปรแกรมเพิ่มเติม
  1. apt-get install libcgi-pm-perl


Thank This Web : https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1410241.html
- Restart apache2
- Test เข้า lightsquid ip/lighsquid

จะเข้าดูได้ ถ้าเข้าไม่ได้ ดู log ว่า Error อะไรใช้คำสั่ง
  1. tail /var/log/apache2/error.log


- ถ้าต้องการดู Graph ด้วย อาจจำเป็นต้องติดตั้ง GD.PM เพิ่มเติมด้วยคำสั่ง
  1. apt-get install libgd-gd2-perl


- ถ้าไม่ต้องการ ให้แก้ $graphreport ใน lightsquid.cfg เป็น
  1. $graphreport = 0


- Generate report
  1. /usr/local/lightsquid/lightparser.pl


- Test เข้า lightsquid ip/lighsquid
- Generate report ทุกวัน
  1. crontab -e

เพิ่ม Code
  1. 0 0 * * * /usr/local/lightsquid/lightparser.pl

หรือ
  1. @daily /usr/local/lightsquid/lightparser.pl


เสร็จการติดตั้ง Lightsquid on ubuntu 16.04

- copy report จากเครื่องเดิม มาใส่เครื่องใหม่ จะได้มีข้อมูลเก่าไว้ดู
ที่เครื่องเก่า
  1. cd /usr/local/lightsquid

scp ทั้งหมด folder report
  1. scp -r report/ sa@192.168.2.116:/home/sa


ที่เครื่องใหม่
- copy folder report ไปไว้ใน /usr/local/lightsquid/
  1. cp -r report/ /usr/local/lightsquid/


- เข้าดู lightsquid จะมีข้อมูลเก่าขึ้นมา
http://192.168.2.116/lightsquid/index.cgi

- copy folder it และไฟล์ it*.* ที่อยู่ใน folder lightsquid จากเครื่องเก่าไปเครื่องใหม่ เพื่อเข้าดูหน้า CHECK IP ว่าชื่อใครมีใช้ที่ ip ใดบ้าง
ที่เครื่องเก่า
  1. scp -r it/ sa@192.168.2.116:/home/sa

  1. scp it* sa@192.168.2.116:/home/sa


ที่เครื่องใหม่ copy ไฟล์เข้าไปไว้ /usr/local/lightsquid/
  1. cp -r it/ /usr/local/lightsquid/

  1. cp it* /usr/local/lightsquid/

- cd เข้า folder lightsquid
  1. cd /usr/local/lightsquid/

http://porpramarn.blogspot.com/2016/11/lightsquid-edit-file-and-use-phpmysql.html

- แก้ไฟล์ html สำหรับแสดงผลหน้า web ที่ /usr/local/lightsquid/tpl/base เพิ่มข้อความแก้ไขรูปแบบของ html
เช่น index.html เพื่อให้มี link คลิกไปดูหน้า php ที่สร้างขึ้นได้ เพิ่ม
  1. <TD width="33%" align="center"><FONT size="-1"><A HREF="it.php">CHECK IP</A></FONT></TD>


- ที่ folder ip2name ให้ copy ไฟล์ ip2name.simple --> ip2name.simpleNew แก้ Code เป็นดังนี้เพื่อให้ Show IP และชื่อร่วมกัน (ไม่ใช้ไฟล์เดิมร่วมกันเพราะมีปัญหาเรื่อง Link และไม่สามารถดูภาพรวมทั้งหมดเฉพาะชื่อได้จึงต้องแยก)
  1. #contributor: esl
  2. #do nothing
  3. #simple version
  4.  
  5. sub StartIp2Name() {
  6. }
  7.  
  8. sub Ip2Name($$$) {
  9.   # $Lhost,$user,$Ltimestamp
  10.   my $Lhost=shift;
  11.   my $user =shift;
  12.   #return $user.":".$Lhost
  13.   return $user.":".$Lhost if ($user ne "-"); #return user if defined !!!!!
  14.   #return $user if ($user ne "-"); #return user if defined !!!!!
  15.   return $Lhost;
  16. }
  17.  
  18. sub StopIp2Name() {
  19. }
  20.  
  21. #warning !!!
  22. 1;


- Run คำสั่ง สร้าง Report โดยใช้คำสั่ง
/usr/local/lightsquid/it_lightparser.pl

- นำคำสั่งไปใส่ใน crontab -e เพื่อจะให้ run auto กำหนดวันตามที่เราต้องการ เช่น
  1. 0 0,13 * * * /usr/local/lightsquid/it_lightparser.pl


-ติดตั้ง mysql
  1. sudo apt-get install mysql-server


- ติดตั้ง phpmyadmin และ Program ที่ต้องใช้ร่วมกับ phpmyadmin
  1. sudo apt-get install phpmyadmin php-mbstring php-gettext


- เข้า phpmyadmin สร้าง database it_report แล้วนำ database จากเครื่องเก่ามา imports เข้า
ถ้าไม่มีข้อมูลหรือไม่แสดงผล หรือมี error ต่าง ๆ ให้เข้าดู log ของ apache2
  1. tail /var/log/apache2/error.log

แล้วแก้ตามที่มี error เช่น คำสั่ง split ใช้งานไม่ได้แล้วให้แก้เป็น explode แทน
แล้วทดลองเข้า http://192.168.2.116/lightsquid/it.php

No comments:

Post a Comment