马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
可以做到自动计费,到期前发送邮件通知。
看wiki:
http://wiki.mikrotik.com/wiki/AutomatedBilling
[edit] IntroductionThis script was first written as a small device to send users a bill for their usage at the end of every month. It has since developed into a far more complex system that is now used to almost fully automate Billing, and also send out Usage Warnings to users.
If you find this script helpful, or found a bug, please let me know. Comments or suggestions are welcome as well - Send to admin@qnect.co.za
[edit] Requirements[edit] The Four Scripts Involved[edit] OversightThe first of the scripts, I've called Oversight. This is a very simple script that simply takes a single global variable, and if it's value is True, it'll trigger another script. If it's value is False, it will trigger a completely different script.
You can find the script Oversight here.
[edit] Month EndThe Global variable that I speak of, is determined by our second script, which I call MonthEnd. This script, quite simply, checks if Today (or, more accurately, the date/time at which it is run) is the last day of the month, or not. This script compensates for months with 30 or 31 days, and also compensates for Leapyears in February. This script then returns True or False on the Global variable called "found".
You can find the script MonthEnd here.
[edit] Usage WarningsThe Third script is the UsageWarnings script. The name should say it all. We'll get into the inner workings of this script shortly.
This script basically works by comparing the user's download-used and upload-used counters' sum to the Cap, and extrapolates a Percentage from that. If the percentage is at a certain point, it issues a warning to the user by sending their usage information to their E-mail address. The "usage warning level" is then updated onto the user's profile in User Manager, which tells the script to not issue a warning of the same level again, until they reach a 'higher' usage warning level.
A skeleton version of this is also sent to Accounts E-mail, just for reference. It is particularly handy for 100% Usage warnings, so one can contact the client for possible cap-increase options, or whatever the case may be. The script can also be adapted to send a warning to the Accounts E-mail only if the user has reached 100%, and not all the other warnings.
You can find the script Usage Warnings here.
You can find examples of the Usage Warning E-mails here.
[edit] BillingThe Fourth and final script is Billing. This one is also quite complex, and we'll explain as we go along.
In short, this script uses a loop to pull each user's information individually. For each user, and E-mail is compiled stating their usage, how much they owe us, how much discount they are getting, if any, and what our banking details are for payment.
It sends a second E-mail, which is a skeleton version of the previous one to the Accounts E-mail, stating only the necessary information. This is kept for our records and to keep track of who has paid and who has not.
You can find the Billing Script here.
You can find examples of the Billing E-mails here.
[edit] What You Need To Know Before StartingAs mentioned, this script works on User Manager. It must be installed/running on the same router that is running User Manager.
It requires access to an outgoing E-mail server, either locally or remotely. Currently, it is written for a Remote SMTP server. Your outgoing server also should not require Authorization to relay E-mails.
[edit] User Manager Field RequirementsThis script also requires each and every user to have the following user fields filled in:
/tool user-manager user print- First Name
- Last Name
- E-mail Address
- Pool Name
- Comment Field
[edit] The Pool Name FieldIn this setup, we've used the Pool-name field to specify which one of our wireless packages the user has opted for. This directly translates to a certain amount that the user owes us every month. More about this later.
[edit] The Comment FieldBecause of the limitations in User Manager's database structure, we were forced to enter more than one piece of information into one field.
Example: 1000230007509 Broken Up: 10002 - 3000 - 75 - 09What this means:
- The first 5 Characters is the next Statement/Invoice Number to be issued.
- The following 4 character is the User's data Cap, in Megabytes.
- The next 2 characters is the last "Usage Warning Level" that was issued for this user
- The last 2 characters is the Month in which the last Statement/Invoice was issued.
Although there is a Usage-Limit function in User Manager and routeros, for the purposes of this script, we have chosen to not use it. It is in the planning to implement it.
Please review the Scripts for additional information.
[edit] Known Issues[edit] RouterOS VersionsThis script has given problems under Routeros 2.9.46 and earlier. The problems that we have experienced were no longer there once we upgraded to 3.0rc5. This script also runs on RC6 and RC7.
[edit] Active Sessions Interim UpdateIn the event that the Month-End lapses, and the Billing script is run, the counters in the User Manager are reset. However, if the user is still connected, and has an active session, the interim update of that session will simply logged it's current usage against the User Manager again, regardless of the fact that User Manager's counters were reset.
In this event, it is necessary to either suspend the accounting session, or terminate the active session and therefore force the accounting session to close.
This functionality will be implemented in the next version of this script.
Retrieved from "http://wiki.mikrotik.com/wiki/AutomatedBilling" |