找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3054|回复: 7

[脚本] routeros 的计费脚本

[复制链接]
发表于 2007-12-17 19:21:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
可以做到自动计费,到期前发送邮件通知。
看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"
routeros
发表于 2007-12-21 00:48:54 | 显示全部楼层
用心的朋友。用心的人总能找到答案
routeros
回复

使用道具 举报

发表于 2008-4-19 19:57:30 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2008-4-19 21:52:17 | 显示全部楼层
还要建一个邮件server???
routeros
回复

使用道具 举报

发表于 2009-3-26 17:07:32 | 显示全部楼层
谁给翻译一下  弄个中文注释呀
routeros
回复

使用道具 举报

发表于 2009-3-27 18:38:56 | 显示全部楼层
官方网站上有讲。
routeros
回复

使用道具 举报

发表于 2009-3-27 20:07:20 | 显示全部楼层
最好就说明下。如果对我们这些新手来说,是好难看得懂的。
routeros
回复

使用道具 举报

发表于 2010-2-4 16:17:23 | 显示全部楼层
怎么用呀
  这样看不出来呀
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-11-25 09:59 , Processed in 0.090929 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表