Community discussions

MUM Europe 2020
 
multipath
newbie
Topic Author
Posts: 43
Joined: Fri Sep 17, 2010 4:42 pm

Change user password if equals....

Sat Jan 22, 2011 5:31 am

Hello, would someone be so kind as to help me figure out why this script is not working? It's suppose to find all names in the user table and then check them against the users found in the payment table. If they are equal and payment table has result-msg="Timed Out" then set the password in the user table = to "NPD". Thank you for any light you can shed on the problem.
{:local counter                   
:local counterii                       
:local chk      
:local chkii
:foreach counter in=[/tool user-manager user find] do={:set chk [:pick [/tool user-manager user get $counter value=name] 0 50]}
:foreach counterii in=[/tool user-manager payment find where result-msg="Timed Out"] do={:set chkii [:pick [/tool user-manager payment get $counterii value=user] 0 50]}
:if ($chkii=$chk) do={/tool user-manager user set $counter password="NPD"}
}
Last edited by multipath on Sun Jan 23, 2011 6:12 am, edited 2 times in total.
 
multipath
newbie
Topic Author
Posts: 43
Joined: Fri Sep 17, 2010 4:42 pm

Re: Change user password if equals....

Sun Jan 23, 2011 5:03 am

Made a little progress. I changed my script so it can be directly pasted into the terminal window. At the end it wants me to put } and hit enter to finish the script. When the script exits I get this error: "invalid value for argument numbers" I went through each line checking the $variables with :put $var and the error must be coming from the very last line.
:if ($chkii=$chk) do={/tool user-manager user set $counter password="NPD"}
I know this is the weekend but I would welcome any ideas on how to search for the payment:user and user:name fields to be equal. Not sure why $counter is not holding the record number if the two variables are equal.
 
multipath
newbie
Topic Author
Posts: 43
Joined: Fri Sep 17, 2010 4:42 pm

Re: Change user password if equals....

Mon Jan 24, 2011 7:41 pm

Any suggestions at all?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Change user password if equals....

Tue Jan 25, 2011 11:38 am

try to check :typeof for these two variables $chkii=$chk
 
multipath
newbie
Topic Author
Posts: 43
Joined: Fri Sep 17, 2010 4:42 pm

Re: Change user password if equals....

Tue Jan 25, 2011 12:54 pm

Thanks Janisk. After staying up all night, I just got the script to perform right. Here is the final code which I think works.
{:local counter " "
:local check " "

:foreach counter in=[/tool user-manager payment find] do={:set check [:pick [/tool user-manager payment get $counter value=trans-status] 0 8]
:if ($check="approved") do={ } else={:if ([/tool user-manager payment get $counter trans-status] ="started") do={
:if ((([/system clock get time] + 06:00:00) -[:pick [/tool user-manager payment get $counter trans-start] 12 20]) >00:30:00) do={
/tool user-manager payment set $counter trans-status="timeout" result-msg="Timed Out" trans-end=([/system clock get date] . " " . ([/system clock get time] + 06:00:00))}
}}}

# Showing where step two begins.

{:local counteri " "            
:local counterii " "
:local counteriii " "
:local countervi " "
:local chk " "    
:local chkii " "

:foreach counteri in=[/tool user-manager user find] do={:set chk [:pick [/tool user-manager user get $counteri value=name] 0 25]}
:foreach counterii in=[/tool user-manager payment find where result-msg="Timed Out"] do={:set chkii [:pick [/tool user-manager payment get $counterii value=user] 0 25]}
:foreach counteriii in=[/tool user-manager user find where name=$chkii] do={[/tool user-manager user set password="NPD" $counteriii]}
:foreach countervi in=[/ip hotspot active find where user=$chkii] do={[/ip hotspot active remove $countervi]}
}

# Showing where step three begins.

{:local counti
:local chei
:foreach counti in=[/tool user-manager payment find] do={
:set chei [:pick [/tool user-manager payment get $counti result-msg] 0 9]
:if ($chei=" ") do={
} else={
:if ([/tool user-manager payment get $counti result-msg] ="Timed Out") do={/tool user-manager payment set $counti result-msg="Fixed"}
}}
}
}
The reason for this script is the Userman sign-up works great. People sign-up and if they don't complete the purchase the account is never setup with a valid profile. However, if a current user logs into the Usermanager and clicks purchase. A new profile is automatically created as the user is redirected to Paypal. If the user then exits the Paypal page without paying, they can sign back in with the new profile. This script will catch those users going to Paypal and not completing the purchase. (This is on the routeros x86 version 5 rc4 beta.)

Update:
This script is working so far. I set it to run every 10 min, been working fine all day.

If someone wants to suggest improvements, I'm open to suggestions. If anyone knows how to remove a profile from a user in userman that would be ideal instead of changing the password. This is better than nothing though.
Last edited by multipath on Mon Feb 07, 2011 10:20 pm, edited 1 time in total.
 
tchus
Member Candidate
Member Candidate
Posts: 111
Joined: Tue Jan 25, 2011 12:08 am

Re: Change user password if equals....

Sun Jan 30, 2011 1:54 pm

Very clever fix.
I've had this same instance, where one user was able to continue online doing the same thing you mentioned.
I'm using the same Beta version on one of my test hotspots. Going to change back to something else, as it's very unstable.
You think this issue is specific to this beta version only?
 
multipath
newbie
Topic Author
Posts: 43
Joined: Fri Sep 17, 2010 4:42 pm

Re: Change user password if equals....

Tue Feb 01, 2011 6:29 am

No, I had this same issue on v4.11 with userman-test as well.

Who is online

Users browsing this forum: No registered users and 17 guests