Mikrotik自动用户管理器用户脚本需要改进 [英] Mikrotik auto user-manager user script needs improvement

查看:133
本文介绍了Mikrotik自动用户管理器用户脚本需要改进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个脚本,但是不能正常工作.有人可以帮忙吗?

I wrote this script but it's not working properly.Anyone can help?

应该检查用户的下载限制和下载,然后执行一些操作,即从活动的ppp列表中删除用户,但是它存在一些缺陷,即我无法在变量中获取实际配置文件的值因此,我改为使用用户管理器用户帐户在评论"中保存配置文件名称,这样我就可以在变量中获取配置文件名称,但这不是我想要的方式.因此,这就是为什么要在变量中获取实际配置文件值的原因.变量,还有一个问题..为什么我不能直接更改用户帐户配置文件,我却做了很长的路要走,但是那样我会松散用户帐户的统计信息,因此我不会丢失任何统计信息用户帐户的数量和工作也完成了??

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";
}
}

如何编写V1.0作品:

它将查找所有超过下载限制且超过配置文件下载限制的用户,以便删除他们的帐户,并在分配了过期配置文件的情况下重新创建帐户,以使他们不再能够访问Internet. 但这有一个问题,就是删除帐户时我会丢失用户帐户的统计信息.这就是为什么它不是一个好的解决方案的原因.

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";
}
}

如何编写V2.0作品:

它将查找所有超出下载限制且超过配置文件下载限制的用户,并获取其静态IP,然后将ip分为网络地址和主机地址,然后向其中添加过期的ip池网络地址,然后添加主机地址到该过期的IP池网络地址,然后为每个用户分配ip,因此就像他们的工作Internet ip池更改为过期的IP池一样,因此在该过程中不会丢失统计信息,并且他们也不会得到任何信息现在上网了..! 因此,这是一个更好的解决方案..但是我期待它是否可以做得更好. :D

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

推荐答案

  • 为什么要参与野鹅追逐?

    • 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用户管理器是一个不错的小型计费系统,但长期以来,它并不是mikrotik的重点.它有缺陷和局限性.

      Mikrotik User manager is a nice mini billing system but its not the focus of mikrotik since long. it have its flaws and limitations.

      如果您是像ISP/Net_Operator这样的商业实体,那么我建议您使用一些专用的计费系统,例如 freeradius 或radius manager,它们可以很好地完成这项工作.

      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...

      这篇关于Mikrotik自动用户管理器用户脚本需要改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆