问题
I wrote this script but it's not working properly.Anyone can help?
It's supposed to check download limit and download used by a user and then do some action i.e to remove the user from active ppp list but it has some flaws which is that I can't get the actual-profile value in a variable so instead I save the Profile name in Comment with the user manager user account so then I can get the profile name in the variable but that's not how I want it to be..So that's why how to get the actual-profile value in a variable and also there is one problem..Why I can't change the user account profile directly instead I am doing it the long way but in that way I loose the statistics of the user account so any way that I do not lose the statistics of the user account and the job get's done also???
SCRIPT V1.0:
:foreach i in=[/tool user-manager user find] do={
:global uname [/tool user-manager user get $i username];
:global upass [/tool user-manager user get $i password];
:global dused [/tool user-manager user get $i download-used];
:global uprofile [/tool user-manager user get $i comment];
:global dlimit [/tool user-manager profile limitation get [find name="$uprofile"] download-limit];
:if ($dused > $dlimit) do={
/ppp active remove [find name=$uname]
/tool user-manager user set $i disabled=yes
:log warning "$uname account has been disabled due to downloading limit exceeding";
/tool user-manager user remove $i
:log warning "$uname account is removed on package expiring";
/tool user-manager user add customer=admin disabled=no username=$uname password=$upass;
/tool user-manager user create-and-activate-profile $uname customer=admin profile="Expired User";
:log info "$uname account has been created again with expired profile";
}
}
HOW SCRIPT V1.0 WORKS :
It looks for all users who has exceeded their downloading limit past the profile download limit so their account is removed and created back again with Expired profile being assigned to them so they won't be getting internet anymore. But it has one problem which is that I loose the Statistics of the user account when I remove the account.So that's why it's not a good solution.
SCRIPT V2.0 :
:foreach i in=[/tool user-manager user find] do={
:global uname [/tool user-manager user get $i username];
:global upass [/tool user-manager user get $i password];
:global dused [/tool user-manager user get $i download-used];
:global uprofile [/tool user-manager user get $i comment];
:global dlimit [/tool user-manager profile limitation get [find name="$uprofile"] download-limit];
:if ($dused > $dlimit) do={
:global uip [/tool user-manager user get $i ip-address];
:global hostip [:pick $uip 11 14];
/tool user-manager user set $i ip-address="10.10.10.$hostip"
/ppp active remove [find name=$uname]
:log warning "$uname has been assigned to expired ip pool with ip 10.10.10.$hostip";
}
}
HOW SCRIPT V2.0 WORKS :
It looks for all users who has exceeded their downloading limit past the profile download limit and get their static IP and then split the ip into the network address and host address and then adds the expired ip pool network address to it and then adds the host address to that expired ip pool network address and then each user is assigned the ip and hence like that their working internet ip pool is changed into expired pool and hence the statistics are not lost in the process and also they don't get any internet now anymore..! So it's a better solution..but I am looking forward if it can be even made even better than this..! :D
回答1:
- Why you are getting involved in a a wild goose chase?
Why use script for this function? why not assign it directly using user manager? Something like discussed here
... its just to share some thoughts on it, maybe you can further enhance it as per your requirements.
Mikrotik User manager is a nice mini billing system but its not the focus of mikrotik since long. it have its flaws and limitations.
- If you are a commercial entity like ISP/Net_Operator, then I recommend you to use some dedicated billing billing system like freeradius or radius manager which can do the job nicely.
- It can also perform many other fancy functions like sending sms / redirection / and much MORE...
来源:https://stackoverflow.com/questions/42314535/mikrotik-auto-user-manager-user-script-needs-improvement