and next revision:
It remove users, which registered thru PayPal, but not buy any profile, every time loaded this script and registered users never active after 1 month.
# Date: 03/06/2011
# Revised: 22/02/2013
# Revised: 01/08/2013
# Author: Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx
# Script version (V.2)
# File: cleanUserManager
# Tested on: RouterOS version 6.2
#
# Description: Deletes Mikrotik User-Manager accounts whos not active more or equal 3 month.
# Accounts which are not yet activated are skipped but removed if not activated 1 month.
# You must to add to account comment creation date by hand or by script.
# Accounts which have valid profile are skipped.
# A summary of all accounts skipped, deleted and kept is displayed in the end of the cycle to
# console screen and to log.
#
# Notes:
# This script work if NTP package is installed.
# This script can be run either from WinBox or from console.
# -- If console is used, all processing details will be shown, and a summary of operations in the end.
# -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
# sent to log.
#
# Use: In Winbox, go to System > Script, create a new script, name it cleanUserManager and paste
# this whole document in it. Click Apply and OK.
#
# Syntax: To run the script, from terminal enter "/system script run cleanUserManager" without quotes.
if ([/system ntp client get status]="synchronized") do={
:global iterator 0
:global deleted 0
:global skipped 0
:global kept 0
/tool user-manager user print brief without-paging
:global counter [/tool user-manager user print count-only]
:do {
:local thisDate
:local thisYear
:local thisDay
:local thisMonth
:local thisSeen
:local thisProfile
:local thisOwner
:local thisCredit
:local creditYear
:local creditDay
:local creditMonth
:local expireMonth
:local comment
:local creditName
:set thisDate [/system clock get date]
:set thisYear [:pick $thisDate 7 11]
:set thisDay [:pick $thisDate 4 6]
:set thisMonth [:pick $thisDate 0 3]
:if ($thisMonth="jan") do { :set thisMonth "01"}
:if ($thisMonth="feb") do { :set thisMonth "02"}
:if ($thisMonth="mar") do { :set thisMonth "03"}
:if ($thisMonth="apr") do { :set thisMonth "04"}
:if ($thisMonth="may") do { :set thisMonth "05"}
:if ($thisMonth="jun") do { :set thisMonth "06"}
:if ($thisMonth="jul") do { :set thisMonth "07"}
:if ($thisMonth="aug") do { :set thisMonth "08"}
:if ($thisMonth="sep") do { :set thisMonth "09"}
:if ($thisMonth="oct") do { :set thisMonth "10"}
:if ($thisMonth="nov") do { :set thisMonth "11"}
:if ($thisMonth="dec") do { :set thisMonth "12"}
:local thisSeen [/tool user-manager user get $iterator last-seen]
:local thisProfile [/tool user-manager user get $iterator actual-profile]
:local thisOwner [/tool user-manager user get $iterator customer]
:set creditName [/tool user-manager user get $iterator name]
:set comment [/tool user-manager user get $iterator comment]
:if ([:len $thisProfile]!=0) do {
:put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
:set skipped ($skipped+1) } else {
:if ($thisSeen = "never") do {
:set creditYear [:pick $comment 7 11]
:set creditDay [:pick $comment 4 6]
:set creditMonth [:pick $comment 0 3]
#2)
:if ($creditMonth="jan") do { :set creditMonth "02";:set expireMonth "feb"}
:if ($creditMonth="feb") do { :set creditMonth "03";:set expireMonth "mar"}
:if ($creditMonth="mar") do { :set creditMonth "04";:set expireMonth "apr"}
:if ($creditMonth="apr") do { :set creditMonth "05";:set expireMonth "may"}
:if ($creditMonth="may") do { :set creditMonth "06";:set expireMonth "jun"}
:if ($creditMonth="jun") do { :set creditMonth "07";:set expireMonth "jul"}
:if ($creditMonth="jul") do { :set creditMonth "08";:set expireMonth "aug"}
:if ($creditMonth="aug") do { :set creditMonth "09";:set expireMonth "sep"}
:if ($creditMonth="sep") do { :set creditMonth "10";:set expireMonth "oct"}
:if ($creditMonth="oct") do { :set creditMonth "11";:set expireMonth "nov"}
:if ($creditMonth="nov") do { :set creditMonth "12";:set expireMonth "dec"}
:if ($creditMonth="dec") do { :set creditMonth "03";:set expireMonth "jan";:set creditYear ($creditYear+1)}
#2)
:set thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)
:if ($creditYear>$thisYear) do {
:put {"Username ". $creditName . " is not yet activated and expires on ".$thisCredit . " Skipping ..."};
:set skipped ($skipped+1)} else {
:if ($creditYear<$thisYear) do {
/tool user-manager user remove $creditName;
:put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
:set deleted ($deleted+1) } else {
:if ($creditMonth>$thisMonth) do {
:put {"Username ". $creditName . " is not yet activated and expires on ".$thisCredit . " Skipping ..."};
:set skipped ($skipped+1)} else {
:if ($creditMonth<($thisMonth)) do {
/tool user-manager user remove $creditName;
:put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
:set deleted ($deleted+1) } else {
:if ($creditDay>=$thisDay) do {
:put {"Username ". $creditName . " is not yet activated and expires on ".$thisCredit . " Skipping ..."};
:set skipped ($skipped+1)} else {
/tool user-manager user remove $creditName;
:put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
:set deleted ($deleted+1) }
}
}
}
}
} else {
:set creditYear [:pick $thisSeen 7 11]
:set creditDay [:pick $thisSeen 4 6]
:set creditMonth [:pick $thisSeen 0 3]
#1)
:if ($creditMonth="jan") do { :set creditMonth "04";:set expireMonth "apr"}
:if ($creditMonth="feb") do { :set creditMonth "05";:set expireMonth "may"}
:if ($creditMonth="mar") do { :set creditMonth "06";:set expireMonth "jun"}
:if ($creditMonth="apr") do { :set creditMonth "07";:set expireMonth "jul"}
:if ($creditMonth="may") do { :set creditMonth "08";:set expireMonth "aug"}
:if ($creditMonth="jun") do { :set creditMonth "09";:set expireMonth "sep"}
:if ($creditMonth="jul") do { :set creditMonth "10";:set expireMonth "oct"}
:if ($creditMonth="aug") do { :set creditMonth "11";:set expireMonth "nov"}
:if ($creditMonth="sep") do { :set creditMonth "12";:set expireMonth "dec"}
:if ($creditMonth="oct") do { :set creditMonth "01";:set expireMonth "jan";:set creditYear ($creditYear+1)}
:if ($creditMonth="nov") do { :set creditMonth "02";:set expireMonth "feb";:set creditYear ($creditYear+1)}
:if ($creditMonth="dec") do { :set creditMonth "03";:set expireMonth "mar";:set creditYear ($creditYear+1)}
#1)
:set thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)
:if ($creditYear>$thisYear) do {
:put {"Kept username ".$creditName." which expires on ".$thisCredit };
:set kept ($kept+1) } else {
:if ($creditYear<$thisYear) do {
/tool user-manager user remove $creditName;
:put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
:set deleted ($deleted+1) } else {
:if ($creditMonth>$thisMonth) do {
:put {"Kept username " . $creditName . " which expires on " . $thisCredit};
:set kept ($kept+1) } else {
:if ($creditMonth<($thisMonth)) do {
/tool user-manager user remove $creditName;
:put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
:set deleted ($deleted+1) } else {
:if ($creditDay>=$thisDay) do {
:put {"Kept username " . $creditName . " which expires on " . $thisCredit};
:set kept ($kept +1) } else {
/tool user-manager user remove $creditName;
:put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
:set deleted ($deleted+1) }
}
}
}
}
}
}
:set iterator ($iterator+1)
} while=($iterator!=$counter)
:put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
:put {"Records processed: \t" . $counter}
:put {"\n\rDeleted usernames: \t" . $deleted}
:put {"Skipped usernames: \t" . $skipped}
:put {"Kept usernames:\t\t" . $kept}
:put {"\n\r_________________________________\n\r"}
:log info ("\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
:log info ("Records processed: \t" . $counter)
:log info ("\n\rDeleted usernames: \t" . $deleted)
:log info ("Skipped usernames: \t" . $skipped)
:log info ("Kept usernames: \t\t" . $kept)
:log info ("\n\r________________________________\n\r")
}
#END OF FILE
You can edit path marked 1) to change how long account saved in UM DB
and path marked 2) to change how long never active account saved in UM DB.
Load this script from scheduler:
/system scheduler
add interval=1d name=cleanUserManager on-event=cleanUserManager policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=\
dec/08/2010 start-time=02:00:00
Script example for account add with adding date to comment:
(It completed for Lithuania - you can use Google to translate)
<?php
namespace PEAR2\Net\RouterOS;
include_once '../../src/php/PEAR2/Autoload.php';include '../param.common.php';
//../include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
?>
<title>Priseregistravimas.</title>
<html>
<head>
<title>Priseregistravimas</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv='Content-Language' content='lt' />
<meta http-equiv='content-style-type' content='text/css' />
<link rel="stylesheet" type="text/css" href="../css.css">
</head>
<?php
if(trim($_POST['email'])=='') {
die("Neįrašėte emailą! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['name'])=='Jūsų abonento vardas.') {
die("Neįrašėte savo vartotojo vardą! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['name'])=='') {
die("Neįrašėte savo vartotojo vardą! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['password'])=='') {
die("Neįrašėte savo slaptažodį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['password1'])=='') {
die("Neįrašėte pakartotinai slaptažodį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['phone'])=='') {
die("Neįrašėte savo telefono numerį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['phone'])=='Jūsų telefono numeris.') {
die("Neįrašėte savo telefono numerį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
include 'check-phone.php';
$txt1 = 'added by ';
$first = $_POST['first-name'];
$txt2 = ' ';
$last = $_POST['last-name'];
$txt3 = ' !';
if ('' === $_POST['first-name'])
{
$comment = $txt2.'added by User!';
} else {
$comment = $txt2.$txt1.$first.$txt2.$last.$txt3;
}
if (isset($_POST['password']) && isset($_POST['password1'])) {
if ($_POST['password'] !== $_POST['password1']) {
echo "Slaptažodžiai nesutampa.<br>";
} else {
$client = new Client($host,$admin,$pass);
$printRequest = new Request('/tool user-manager user print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(Query::where('name', $_POST['name']));
$userId = $client->sendSync($printRequest)->getArgument('.id');
if (null !== $userId ) {
echo "Vartotojas {$_POST['name']} jau egzistuoja.<br>";
} else {
$printRequest = new Request('/tool user-manager user print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(Query::where('phone', $_POST['phone']));
$userPh = $client->sendSync($printRequest)->getArgument('.id');
if (null !== $userPh ) {
echo "Vartotojas turintis numerį {$_POST['phone']} egzistuoja.<br>";
} else {
try {$printRequest = new Request('/system clock print');
$printRequest->setArgument('.proplist','date');
$date = $client->sendSync($printRequest)->getArgument('date');
$comment = $date.$comment;
$addRequest = new Request('/tool user-manager user add');
$addRequest->setArgument('customer',gsm);
$addRequest->setArgument('name',$_POST['name']);
$addRequest->setArgument('first-name',$_POST['first-name']);
$addRequest->setArgument('last-name',$_POST['last-name']);
$addRequest->setArgument('location',$_POST['location']);
$addRequest->setArgument('email',$_POST['email']);
$addRequest->setArgument('password',$_POST['password']);
$addRequest->setArgument('phone',$_POST['phone']);
$addRequest->setArgument('disabled',no);
$addRequest->setArgument('comment', $comment);
$addRequest->setArgument('shared-users',1);
if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) {
echo "Error when added '{$_POST['name']}'. Neteisingas e-mail formatas.<br>";
} else {
echo "Comment: '{$comment}'. Vartotojas'{$_POST['name']}' sėkmingai sukurtas!.";
echo "<br />Aktivuoti paslaugą:<a href='../../payment/plan.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}'> Spausk čia!</a>";
}
} catch(Exception $e) {
echo $e;
}
}
}
}
}
echo "<br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&location={$_POST['location']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}'> atgal</a>";
?>
You can see my interface for user add, payment and etc. here
Free Net (Lithuanian)
If You have any questions, be free to ask.