0. BackgroundAbout two years ago, before a relatively small but developing network, in which I, by fate, turned out to be a system administrator, the task was to introduce a new billing. The requirements turned out to be simple and rather banal for those places where the Internet costs not a penny and far from everyone is willing to pay for unlimited money:
- The ability to create megabyte tariff plans and unlimited
- The ability to record traffic by destinations (free-city-country-world)
- Free solution (the word opensource was not interesting then)
- Sane web user interface and administrator
- The possibility of expanding the functionality for the future
- Support for various payment systems (in particular, were interested in payment with top-up cards
Out of a large number of candidates, there are only two abruptly left:
NeTAMS and
ABillS .
After a detailed review, NeTAMS was also dropped - his methods of work were certainly not suitable for me, and it was noticeably felt that billing was just a module for him. Moreover, the user web-interface, to put it mildly, did not work. Having no alternatives, I proceeded to install ABillS.
Perhaps I will refrain from telling all the twists and turns of learning a new software, and offer you the quintessence of my knowledge of installing the best, in my opinion, opensource billing.
1. InstallationIn this post, I will consider installing exclusively for FreeBSD, moreover, version 7.0 (the installation on 6.x has minor, but different). If you are the lucky owner of Linux on the server - I advise you to refer to
this article by the Glooom
haber man .
1.1 Cooking the coreSince billing is still quite a serious system, I prefer to use all functions used in the work in the core rather than in the modules. Therefore, we add the following options to our kernel build configuration:
options NETGRAPH # NETGRAPH
options NETGRAPH_IPFW # ng_ipfw
options LIBALIAS # ng_nat
options NETGRAPH_NAT # ng_nat
options NETGRAPH_NETFLOW # ng_netflow
### MPD ###
options NETGRAPH_SPLIT
options NETGRAPH_KSOCKET
options NETGRAPH_SOCKET
options NETGRAPH_BPF
options NETGRAPH_IFACE
options NETGRAPH_MPPC_ENCRYPTION
options NETGRAPH_PPP
options NETGRAPH_PPTPGRE
options NETGRAPH_TCPMSS
options NETGRAPH_VJC
options NETGRAPH_TEE
options NETGRAPH_CAR
### --- ###
options IPFIREWALL #ipfw.
options IPFIREWALL_VERBOSE #
options IPFIREWALL_FORWARD # transparent-proxy
options IPFIREWALL_DEFAULT_TO_ACCEPT #
1.2 ng_nat and all-all-allUnfortunately at the moment we can not provide each user with a real IP. Therefore, I had the task of organizing NAT. After reviewing the existing options, the choice fell on ng_nat + ng_ipfw.
To begin with, we add the following lines in
/etc/rc.conf
:
gateway_enable="YES" # :)
firewall_enable="YES" # ipfw
firewall_script="/usr/scripts/ipfw_load.sh" #
Create a file
/usr/script/ipfw_load.sh
with the following contents:
#!/bin/sh
fwcmd="/sbin/ipfw"
ngctl="/usr/sbin/ngctl"
ext_if="re0" #
ext_ip="1.2.3.4" # IP NAT'
# ng_nat
${ngctl} mkpeer ipfw: nat 60 out
${ngctl} name ipfw:60 nat
${ngctl} connect ipfw: nat: 61 in
${ngctl} msg nat: setaliasaddr ${ext_ip}
#
${fwcmd} -f flush #
# ( 127)
${fwcmd} table 127 flush #
${fwcmd} table 127 add 10.39.0.0/16 # ip
# loopback
${fwcmd} add 00001 allow ip from any to any via lo0
# NAT
${fwcmd} add 00003 netgraph 61 all from any to ${ext_ip} in via ${ext_if}
# - - NAT
${fwcmd} add 60021 netgraph 60 ip from "table(127)" to any
In this script, we organize NAT users with IP 10.39.0.0/16 to IP 1.2.3.4. All this is implemented on the tables, because sometimes it becomes necessary to NAT non-contiguous ranges.
')
1.3 Required softwareFor the normal operation of billing, I use the following software (all of the ports):
- apache22 (version is a matter of taste)
- flow-tools (a set of utilities for collecting netflow streams)
- freeradius (RADIUS server)
- mpd5 (we will use it as a VPN server)
- mysql-server, mysql-client (appointment, I hope, no need to explain)
- p5-DBD-mysql (to access mysql from Perl)
- p5-Digest-MD4, p5-Digest-SHA1 (used for encryption in billing) sudo (some commands will need to be run from an un-privileged user)
The default configuration offered by FreeBSD is fine with me. The only thing is to build mpd5 with ng_car from ports, if you still decide to install it on FreeBSD 6.x.
1.4 Installing ABillS
Despite the fact that anyone in their right mind and sober memory will choose a stable branch for such a serious system as billing, I strongly advise against this. The fact is that in the author’s understanding, stable is a “relatively stable release” and even errors found in it are corrected in current and not stable. On personal experience, I will say that for 1.5 years I used the current branch in my work without any problems.
Therefore, go for the current!
# cd /usr/local/
# cvs -d:pserver:anonymous @ abills.cvs.sourceforge.net:/cvsroot/abills login
# cvs -z3 -d:pserver:anonymous @ abills.cvs.sourceforge.net:/cvsroot/abills checkout -r rel-0-4 abills
# ln -s /usr/local/abills /usr/abills
I did the last line, because the /usr/abills
folder is often found in the config /usr/abills
while in BSD ABillS I set it in /usr/local/abills
.
Now go to the libexec
folder. There we will find the file config.pl.default
which we copy into config.pl
- it will become the basis for our future configuration.
2. Configuration
Setting ABillS "from and to" is a complex process, inevitably associated with reading source codes. And the thing is that the documentation posted on the site is hopelessly behind the version in CVS. In many ways, the author’s reluctance to update the documentation is due to the fact that installing and configuring ABillS is one of its sources of income. Moreover, a package of “complete” documentation is offered for only $ 300. But I can not judge him - I did not see him.
Fortunately, the standard configs that come with ABillS will suffice to solve our problems (although this is not the author himself advertises). We will use his gifts. In this article, I consider the situation when all services (mysql, radius and netflow collector) are on the same machine, but I am sure that it will not be difficult for the reader to change the settings for several systems in which case.
2.1. RADIUS
So, without further ado, let's take a look at the ABillS contrib / freeradius folder and copy the freeradius folder (by default / usr / local / etc / raddb) the acct_users, clients.conf, eap.conf, rlm_perl.conf users
. rlm_perl.conf
don’t forget to rename the rlm_perl.conf file to radiusd.conf, and enter the IP and password for access to the radius in the clients.conf file ( In the example, the values ​​127.0.0.1 and radsecret will be used ).
In order for the speed limit to work by means of MPD, which we are going to use, we will add a dictionary for MPD to the end of the dictionary:
VENDOR mpd 12341
ATTRIBUTE mpd-rule 1 string mpd
ATTRIBUTE mpd-pipe 2 string mpd
ATTRIBUTE mpd-queue 3 string mpd
ATTRIBUTE mpd-table 4 string mpd
ATTRIBUTE mpd-table-static 5 string mpd
ATTRIBUTE mpd-filter 6 string mpd
ATTRIBUTE mpd-limit 7 string mpd
ATTRIBUTE mpd-drop-user 154 integer mpd
This completes the setup. Run the radiusd -X
and carefully read the output for errors. If there are no errors, we add the magic line radiusd_enable="YES"
to /etc/rc.conf
and start the radius as a daemon.
2.2 MPD
Version 5 of MPD was chosen for one simple reason - it was in it that the developers finally introduced the concept of a template, eliminating the need to copy the same lines 1000 times.
The config I have provided allows you to connect with or without mppe + mppc (hi Windows).
startup:
# MPD
set user xanf somepass admin
# MPD
# ABillS
set console self 127.0.0.1 5005
set console open
# -.
set web self 0.0.0.0 5006
set web open
#IP , netflow
set netflow peer 127.0.0.1 9996
set netflow self 127.0.0.1 9990
set netflow timeouts 15 15
set netflow hook 9000
default:
load pptp_server
pptp_server:
# . IP RADIUS
set ippool add pool1 10.39.0.1 10.39.255.255
create bundle template B
set iface idle 1800
#"" TCP/IP Microsoft
set iface enable tcpmssfix
#
set iface enable netflow-in
set iface enable netflow-out
set ipcp yes vjcomp
#VPN Server IP
#
# " ".
# *nix-
# IP VPN
set ipcp ranges 172.16.0.1/32 ippool pool1
set ipcp dns 172.16.0.1
set bundle enable compression
set ccp yes mppc
set mppc yes e40
set mppc yes e128
set mppc yes stateless
set bundle yes crypt-reqd
create link template L pptp
set link action bundle B
set link enable multilink
set link yes acfcomp protocomp
set link no pap chap
set link enable chap
set link yes crypt-reqd
set link mtu 1460
# IP MPD
#
set pptp self 10.37.254.253
set link enable incoming
#IP, RADIUS-
set radius server 127.0.0.1 radsecret 1812 1813
set radius timeout 10
set auth acct-update 300
set auth enable radius-auth
set auth enable radius-acct
set radius retries 3
MPD setup is complete. Do not forget to add the line mpd_enable="YES"
to /etc/rc.conf
Attention! If your system behaves unstably and dies with a “double fault”, be sure to update the kernel sources. In the latest version this problem has already been solved. My PR kern / 125314 about this
2.3 Configure Netflow Collector
First of all, a few words why Netflow was chosen from all the traffic counting options:
- Standard solution - MPD can then be easily replaced with Mikrotik or a hardware VPN server (for example, CISCO)
- The IPN + Netflow bundle solves two problems of the free version of ABillS - withdrawing money from the user’s account is made only at the end of the session and the session is broken at the time interval
First of all, you need to create links in ABillS itself.
# cd /usr/abills/libexec/
# ln -s ../Abills/modules/Ipn/trafdstats trafdstats
# ln -s ../Abills/modules/Ipn/traffic2sql traffic2sql
We give rights to the user flowtools on the folder in which to collect traffic
#chown flowtools /usr/local/abills/var/log/ipn/
If the /usr/local/abills/var/log/ipn
does not exist, create it
Editing /etc/rc.conf
flow_capture_enable="YES"
flow_capture_datadir="/usr/local/abills/var/log/ipn/"
flow_capture_port="9996"
flow_capture_flags="-S 5 -n 1300 -N 0 -d 5"
The only parameter we are interested in is -n 1300
- the rotation of logs will be 1300 times a day, which is about one minute.
2.4 Configuring Apache
Setting up the web interface is so trivial that I allow myself to just bring the working config and say that to generate certificates you can use the sslcerts.sh
script in the contrib folder of ABillS.
<VirtualHost 0.0.0.0:443>
SSLEngine on
SSLOptions +StrictRequire
SSLProtocol -all +TLSv1 +SSLv3
SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:+HIGH:+MEDIUM
SSLCertificateFile /usr/local/abills/Certs/server.crt
SSLCertificateKeyFile /usr/local/abills/Certs/server.key
SSLVerifyClient none
SSLProxyEngine off
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
DocumentRoot /usr/local/abills/cgi-bin
ServerName stat.example.com
#ServerAlias com
ServerAdmin xanf@example.com
ErrorLog /var/log/error_log
TransferLog /var/log/access_log
Alias / "/usr/local/abills/cgi-bin/"
<Directory "/usr/local/abills/cgi-bin">
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_CGI_AUTHORIZATION:%1]
Options Indexes ExecCGI SymLinksIfOwnerMatch
AddHandler cgi-script .cgi
Options Indexes ExecCGI FollowSymLinks
AllowOverride none
DirectoryIndex index.cgi
Order allow, deny
Allow from all
<Files ~ "\. (Db | log) $">
Order allow, deny
Deny from all
#Admin interface
<Directory "/ usr / local / abills / cgi-bin / admin">
AddHandler cgi-script .cgi
Options Indexes ExecCGI FollowSymLinks
AllowOverride none
DirectoryIndex index.cgi
order deny, allow
allow from all
In the case of receiving the 500th error, be sure to look at error.log - almost certainly either something with a database, or Perl is missing some module.
2.5 Configuring ABillSHere we come to the most delicious. Nevertheless, I will allow myself not to dwell in detail on all the features. The resulted configs will allow to receive efficient system in the minimum time.
Download the billing files to the created database named abills
# mysql -D abills < abills.sql
# mysql -D abills < db/Ipn.sql
The second file activates the IPN extension, which we will use
First of all, we modify the config.pl
@MODULES = ('Dv',
'Abon',
# 'Docs',
'Sqlcmd',
'Ipn',
# 'Cards');
);
Ipn module is important for us to calculate traffic. The Cards module is paid ($ 60), so I left it commented out.
$conf{default_language}='russian'; # - :)
$conf{default_charset}='windows-1251';
$conf{periodic_check}='yes';
$conf{IPN_DEPOSIT_OPERATION}=1; # IPN
$conf{IPN_USERMENU}=1; #
Also note
$conf{IPN_FW_START_RULE}
and
$conf{IPN_FW_STOP_RULE}
. Here you can specify scripts that are executed when opening and closing the connection. You can ignore any
$conf{IPN_FW_FIRST_RULE}
- we will organize the cutting of speed with another method. After unsuccessful experiments, I personally refused to control the firewall from ABillS and therefore, in principle, I do not use the
linkupdown
script that
linkupdown
with ABillS.
One effective method for limiting the speed of clients when using MPD is to return the corresponding filters in the RADIUS Start packet. Thus, for example, to create a limit on the tariff plan 64, it is sufficient to include the following line in the RADIUS parameters of this tariff plan:
mpd-limit+=out#1=all shape 64000 pass,mpd-limit+=in#1=all shape 64000 pass
In this case, the speed limit will be performed via the ng_car node, which, as my practice has shown, is much more efficient than cutting with ipfw + dummynet.
Unfortunately, for unknown reasons, ABillS out of the box incorrectly handles the "+ =" operator in the tariff plans. To correct this annoying misunderstanding, find the following lines in Auth.pm:
$RAD_PAIRS->{"$left"} =~ s/\"//g;
$RAD_PAIRS->{"$left"}="\"". $RAD_PAIRS->{"$left"} .",$right\"";
}
else {
$RAD_PAIRS->{"$left"}="\"$right\"";
}
and replace with the following:
$RAD_PAIRS->{"$left"} =~ s/\"//g;
push( @ {$RAD_PAIRS->{"$left"} }, $right );
}
else {
$RAD_PAIRS->{"$left"}= [ $right ];
}
After this, ABillS will correctly transfer attributes in the "+ =" format.
It now remains to log in to the ABillS admin panel with the abills username and password and in the “System” - “NAS” section (aka “System -” Access Servers "in the Russian version) create a new NAS with the type“ mpd4 ”and address“ 127.0. 0.1: 5005 "
NAS will receive a number (most likely it will be "1"). Now open crontab and enter the following line into it:
*/5 * * * * /usr/local/abills/libexec/traffic2sql 1
flowdir=/usr/local/abills/var/log/ipn
Do not forget to replace 1 with the number of your NAS. Now all traffic data of your users will be taken into account by billing.
You can also add calls to periodic scripts in crontab:
1 0 * * * root /usr/abills/libexec/periodic daily
1 0 * * * root /usr/abills/libexec/periodic monthly
Do not make a
billd -all
to Cron as recommended by management. In our case, it is not needed — and moreover, harmful — it will disassociate users at the boundaries of the time intervals.
This completes the basic setup, and your VPM server should be ready to go.
3. Personal impressions - a barrel of honeyI have been using ABillS as a battle server for over 2 years now. During this time, not a single serious failure occurred, and the total downtime probably did not add up to 2 hours, of which an hour is the transition to new versions of billing. Only once, on New Year's Eve, due to a minor error, billing began to drop all users on time-limit. It took me 15 minutes to eliminate this error.
In general, the system provides very convenient reports on users, all the necessary information is stored in the database, a lot of different modules make life easier - only pleasant impressions. Our friends bought
UTM and had more problems with it, even if they had paid support
4. Personal impressions - a spoon of tarHowever, ABillS is not perfect. I don’t use a lot of functionality (linkupdown, periodic-scripts) at all, but rather I use my own “substitutes”, because the authors do not suit me for one reason or another.
Sometimes current makes stupid enough mistakes. So after one of the updates (on average, we update the billing every six months), users with a loan lost the ability to go online because of the wrong “>” sign when checking the credit limit of the tariff plan and the user. Traffic2sql itself works in its original form rather slowly (
patch on the ABillS forum ), and when dynamically issuing IP from the pool, traffic may not be considered correctly (
bugreport + patch on the ABillS forum ).
Also, once I turned on the Msgs module, which provides the basic functionality of “contacting technical support” from billing, two days later I was horrified to find that no tags are cut in messages at all, which allows for example using the IFRAME to change the tariff plan to the user as an administrator will look at his message.
This is especially sad for the reason that 95% of the modules that “appear” for ABillS are not cheap commercial orders, which are then issued “for everyone”.
DISCLAIMER instead of an epilogue Everything written above is my personal experience in using this system. My opinion is purely subjective, I do not guarantee the absolute correctness and smoothness of the proposed solutions. Also I, like any person, could be wrong. If you have something to supplement and improve this article - I am always glad to constructive criticism in the comments or email (there is a profile)