Takze tu to mate vseko to co daval skrebon + bwusage.sql
http://rapidshare.de/files/31605690/ip_accounting.zip
Ja to mam momentalne na ms viertual pc - slackware 10.2, a Lammp, kedze sa mi nexcele este parat z apache, php a sql - tu to mam all-in-one
Postup:
Porebujeme:
Apache
PHP4
Perl 5.x
MySQL server
DBD:
LWP:
Net:
........................................
Vsetko z ip_accounting.zip nakopirujeme do htdocs resp. zlozky urcenej pre web. To ze mate nainstalovane mysql, apache a php beriem ako samozrejmost :)
1. Kedze tieto veci: DBD:, LWP:, Net:, nebyvaju standarne v linuxe treba ich instalovat:
root@lin:/#cpan - ak mate cistu instalaciu, bude pytat nainstalovat este nejake veci. Takze pri otazke y/n dame "y"
2. root@lin:/#cpan> install DBD: -
3. root@lin:/#cpan> install LWP: -
4. Test LWP:: perl -MLWP::Simple -e 'getprint "http://www.fament.com";'
5. Pokial prebehne nacitanie stranky v html kode, a nevyhodi chybu vsetko ok
6. root@lin:/#cpan> install Net: - davame default nastavenia
7. teraz mame nainstalovane vseky potrebne perl moduly
8. Konfiguracia MK:
/ip accounting set enabled=yes
/ip accounting set threshold=2048
/ip accounting web-access set accessible-via-web=yes
/ip accounting web-access set address=x.x.x.x/32 - zadame ip z linux pc ktory bude zbierat data
9. Pomocou phpmyadmin, ale niecoho co vam je blizsie vytvorime novu databazu kde nahramame bwusage.sql
10. konfiguracia acctcol.pl:
# Script configuration #
# -------------------- #
# There is just a few things that needs to be configured #
# before script is ready for use. #
# #
# Edit the variables below #
# #
# Database configuration #
# #
$database = "bwusage"; - tu zadaje nazov DB
$intable = "inbound";
$outtable = "outbound";
$localtable = "local";
$tmpdown = "tmpdown";
$tmpup = "tmpup";
$tmplocal = "tmplocal";
$hostname = "localhost";
$user = "login"; - login samozrejme
$password = "strasnezloziteheslo"; - a heslo pre pristup
# IP or dns name of your mikrotik router #
# if your running the webservice on differnt port then add #
# to the host string. For example #
# mikrotik.fament.com #
$ip = "10.10.10.1"; - ip MK, popripade port pre pristup cez www
# here you provide a list of your local IPs written in CIDR #
# format ie network address 192.168.0.0 with netmask #
# 255.255.255.0 should be written as 192.168.0.0/24 #
# so if you have 2 local network 192.168.0.0/24 and 1.4.5.0/24 #
# you would write them as (192.168.0.0/24,1.4.5.0/24) #
# the local ips will tell the script into which database we #
# we will be dumping data into depending if it's inbound or #
# outbound traffic. #
@localnet = ('10.0.0.0/8','192.168.0.0/16','195.47.53.128/25'); - rozsah ip pre ktore sa maju vytvarat grafy
# Time between accounting collections in minutes #
# If you specify a value to high and/or your threshold is set #
# to low then you will miss accounting data. Easiest to check #
# this is to run this script in the foreground and turn on #
# debugging and if you rows equals threshold then your missing #
# or risk missing accounting data. #
$seconds = "300"; - cas opakovania
# Debugging option #
# Off = 0 #
# Stats = 1 #
# Stats + sql statments = 2 #
$debugging = "0"; - pokial date 1 - tak vam vypise velkost a pocet riadkov nacianych z MK, pokial 2 tak vypise aj IP spojenia
11. Konfiguracia dailyacctsum.pl
# Script configuration #
# -------------------- #
# There is just a few things that needs to be configured #
# before script is ready for use. #
# #
# Edit the variables below #
# #
# Database configuration #
# #
$database = "bwusage";
$intable = "inbound";
$outtable = "outbound";
$dailyin = "dailyin";
$dailyout = "dailyout";
$localtable = "local";
$hostname = "localhost";
$user = "loginmeno";
$password = "strasnezloziteheslo";
# Debugging option #
# Off = 0 #
# Stats = 1 #
# Stats + sql statments = 2 #
$debugging = "0";
- prakticky to iste co u acctcol.pl
12. idealne cez shell v zlozke spustime ./acctcol.pl
Malo by to vyzerat takto:
82.41.169.12 user * -> 10.111.222.44 user * 214 bytes in 2 packets sent
dstip = localnet
select * from tmpdown where datahost='10.111.222.44'
updating row. download host = 10.111.222.44
update tmpdown set datacount=datacount+214 , packetcount=packetcount+2 where datahost='10.111.222.44'
select * from tmpdown where datahost='10.111.222.44'
10.111.222.44 user * -> 64.221.175.67 user * 150 bytes in 3 packets sent
srcip = localnet
dstip != localnet
select * from tmpup where datahost='10.111.222.44'
updating row. upload host = 10.111.222.44
update tmpup set datacount=datacount+150 , packetcount=packetcount+3 where datahost='10.111.222.44'
select * from tmpup where datahost='10.111.222.44'
1157148274
2048 rows
-------------------
........
Mozme este skonrolovat ci sa nachadzaju v sql db pozadovane data, pokial ano vse funguje ok...
13. V adresary graf => index.php, si takisto nastavime pristupy do Mysql
$connection = mysql_connect("localhost","[b]login[/b]","[b]zloziteheslo[/b]") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("[b]bwusage[/b]") or die ("Unable to select requested database.");
14. uz len nastavime cron:
acctcol.pl - sa odporuca pustat kazdych 2-5min
dailyacctsum.pl - kazdy den o polnoci
15. sledujeme ako nam pribudaju data
..:: Takze som to tu napisal trochu polopatisticky, dufam ze to nebudenikomu vadit ::..