:if ($CToday < $Today) do={:if (!) do={disable $i;/ip hotspot active remove }} else={:if () do={enable $i}}
#:if (($CToday-5) < $Today) do={执行的操作…}
具体操作要自己加进去的。 5.15可用# 脚本作者: Mxso
# Email: mxsogm@gmail.com
# QQ/TM: 84046811
# 脚本版本: 1.02 (真正意义上的日期对比)
# 版本日期: 2010年4月4日
# 适用系统: RouterOS 3.x - 4.6 (2.x未测试)
# 脚本功能: 对PPP及Hotspot用户期限操作;此脚本的实例对用户状态(禁用/启用)进行设置及剔除到期在线用户,添加其他功能可参考下面例子
# 其他功能: 通过注释添加system scheduler星期制的禁用启用,注释格式:第一位是星期日,第二位是星期一,以此类推,E为启用,D为禁用
# 例:代表只有周六日启用该scheduler,这个刚好相反,只有星期一至五启用该scheduler;
# 注意:被设置状态(启用/禁用)的scheduler运行时间不能调整到刚好00:00:00,因为00:00:00刚好在执行此脚本,未能00:00:00就设置好状态
# 添加用户注释日期格式:
# 例1:"张三到期"(双引号里面为注释内容,[]里面为日期八位数字),
# 例2:"李四[+365]到期",[+365]指当前日期加365天,在下次调用脚本时注释将自动变为"李四[八位当前日期+365]到期",
# 假设当前日期为2010年4月4日立即调用脚本注释内容将变为"李四到期",也就是2010年4月4日的365天后到期
# 例3:支持累加运算,假设将近到期,用户续费可以在后面添加+X天,这里加180天
#获取公元至今日( $Today 变量为公元至今已过的天数)
:local Date ;:local Year ([:pick $Date 7 11]-1)
:local Month ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $Date 0 3]])
:local Day [:pick $Date 4 6];:if ([:pick $Date 4 5] = 0) do={:set Day [:pick $Date 5 6]};:set Day ($Day-1)
:local leapyear 0,31,59,90,120,151,181,212,243,273,304,334,0,31,60,91,121,152,182,213,244,274,305,335
:global Today ($Year*365+$Year/4);:if (($Year-$Year/4*4) != 3) do={:set Today ($Today+[:pick $leapyear $Month]+$Day)} else={:set Today ($Today+[:pick $leapyear ($Month+12)]+$Day)}
:local Ccomment;:local lc;:local rc;:local Exp;:local js;:local pcl;:local CYear;:local CMonth;:local CDay;:local CToday
#利用公元天数计算今天是星期几,0代表星期日
:global Week ($Today-$Today/7*7)
:log info ("今天是星期" . $Week)
#以下处理scheduler脚本
/system scheduler
:foreach i in= do={
:set Ccomment ;:set lc [:find $Ccomment "["];:set rc [:find $Ccomment "]"]
:if ([:typeof $lc]="num" && [:typeof $rc]="num" && ($lc+1+$Week)<$rc) do={
:set Exp [:pick $Ccomment ($lc+1+$Week)]
:if ($Exp="e"||$Exp="E"||$Exp="1") do={:if () do={enable $i}}
:if ($Exp="d"||$Exp="D"||$Exp="0") do={:if (!) do={disable $i}}
}}
#以下处理PPP脚本
#/ppp secret
#:foreach i in= do={
#:set Ccomment ;:set lc [:find $Ccomment "["];:set rc [:find $Ccomment "]"]
#:if ([:typeof $lc]="num" && [:typeof $rc]="num" && $lc<$rc) do={
#:set Exp [:pick $Ccomment ($lc+1) $rc];:set js 0;:set pcl;:set CYear;:set CMonth;:set CDay;:set CToday 0
#:if ([:pick $Exp 0 1]!="+" && [:len $Exp]>7 && [:typeof [:tonum [:pick $Exp 0 8]]]="num") do={
#:set CYear ([:pick $Exp 0 4]-1);:set CToday ($CYear*365+$CYear /4)
#:set CMonth [:pick $Exp 4 6];:if ([:pick $Exp 4 5] = 0) do={ :set CMonth [:pick $Exp 5 6]};:set CMonth ($CMonth-1)
#:set CDay [:pick $Exp 6 8];:if ([:pick $Exp 6 7] = 0) do={ :set CDay [:pick $Exp 7 8]};:set CDay ($CDay-1)
#:if (($CYear-$CYear/4*4) != 3) do={:set CToday ($CToday+[:pick $leapyear $CMonth]+$CDay)} else={:set CToday ($CToday+[:pick $leapyear ($CMonth+12)])}}
#:set pcl [:find $Exp "+"];:if ([:typeof $pcl]="num" && ($pcl>7 || $pcl=0) && ([:len $Exp]-1)>$pcl) do={
#:if ($pcl = 0) do={:set CToday $Today;:set CYear ($Year+1);:set CMonth ($Month+1);:set CDay ($Day+1)
#:if ([:len $CMonth]<2) do={:set CMonth ("0" . $CMonth)};:if ([:len $CDay]<2) do={:set CDay ("0" . $CDay)}
#set $i comment=([:pick $Ccomment 0 $lc] . "[" .($CYear . $CMonth . $CDay) . [:pick $Exp $pcl [:len $Exp]] . "]" . [:pick $Ccomment ($rc+1) [:len #$Ccomment]])}
#:while ([:typeof [:find $Exp "+"]]="num") do={
#:set Exp [:pick $Exp ($pcl+1) [:len $Exp]];:set pcl [:find $Exp "+"];:if ([:typeof $pcl]!="num") do={:set pcl [:len $Exp]}
#:set js ($js+[:tonum [:pick $Exp 0 $pcl]])};:set CToday ($CToday+$js)}
#本操作例子:设置PPP用户状态(禁用并剔除和启用)
#:if ($CToday < $Today) do={:if (!) do={disable $i;/ppp active remove ]}} else={:if () do={enable $i}}
#根据需要可添加或替换对用户的操作,假设提前5天,则在条件:if (($CToday-5) < $Today) do={执行通知操作…}
#:if (($CToday-5) < $Today) do={执行通知操作…}
#
#}}
#
#以下处理Hotspot脚本
/ip hotspot user
:foreach i in= do={
:set Ccomment ;:set lc [:find $Ccomment "["];:set rc [:find $Ccomment "]"]
:if ([:typeof $lc]="num" && [:typeof $rc]="num" && $lc<$rc) do={
:set Exp [:pick $Ccomment ($lc+1) $rc];:set js 0;:set pcl;:set CYear;:set CMonth;:set CDay;:set CToday 0
:if ([:pick $Exp 0 1]!="+" && [:len $Exp]>7 && [:typeof [:tonum [:pick $Exp 0 8]]]="num") do={
:set CYear ([:pick $Exp 0 4]-1);:set CToday ($CYear*365+$CYear /4)
:set CMonth [:pick $Exp 4 6];:if ([:pick $Exp 4 5] = 0) do={ :set CMonth [:pick $Exp 5 6]};:set CMonth ($CMonth-1)
:set CDay [:pick $Exp 6 8];:if ([:pick $Exp 6 7] = 0) do={ :set CDay [:pick $Exp 7 8]};:set CDay ($CDay-1)
:if (($CYear-$CYear/4*4) != 3) do={:set CToday ($CToday+[:pick $leapyear $CMonth]+$CDay)} else={:set CToday ($CToday+[:pick $leapyear ($CMonth+12)])}}
:set pcl [:find $Exp "+"];:if ([:typeof $pcl]="num" && ($pcl>7 || $pcl=0) && ([:len $Exp]-1)>$pcl) do={
:if ($pcl = 0) do={:set CToday $Today;:set CYear ($Year+1);:set CMonth ($Month+1);:set CDay ($Day+1)
:if ([:len $CMonth]<2) do={:set CMonth ("0" . $CMonth)};:if ([:len $CDay]<2) do={:set CDay ("0" . $CDay)}
set $i comment=([:pick $Ccomment 0 $lc] . "[" .($CYear . $CMonth . $CDay) . [:pick $Exp $pcl [:len $Exp]] . "]" . [:pick $Ccomment ($rc+1) [:len $Ccomment]])}
:while ([:typeof [:find $Exp "+"]]="num") do={
:set Exp [:pick $Exp ($pcl+1) [:len $Exp]];:set pcl [:find $Exp "+"];:if ([:typeof $pcl]!="num") do={:set pcl [:len $Exp]}
:set js ($js+[:tonum [:pick $Exp 0 $pcl]])};:set CToday ($CToday+$js)}
#本操作例子:设置Hotspot用户状态(禁用并剔除和启用)
:if ($CToday < $Today) do={:if (!) do={disable $i;/ip hotspot active remove ]}} else={:if () do={enable $i}}
#:if (($CToday-5) < $Today) do={执行的操作…}
}}
这脚本我也测试过 也发过贴,这脚本HOT好像真不能用到期禁用,到期提示功能! 你的问题解决了。看帖子:
http://bbs.routerclub.com/forum.php?mod=viewthread&tid=60414&extra=
页:
[1]