Community discussions

MikroTik App
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

Cant set ppp secret comment

Wed Mar 08, 2023 4:32 am

Hello sir, im having a trouble setting up the comment for all expired ppp users, here's my code
/ppp secret
:foreach accName in=[find where profile="EXPIRED"] do={
        :local date [/system clock get date]
        :local name [get $accName name]
        :local comm [/ppp secret get [find name=$accName] comment]
        :local prof [/ppp secret get $accName profile]
        :local accNum [:pick $comm ([:find $comm "Number: "] + 8) [:find $comm " Plan:"]]
        :local plan [:pick $comm ([:find $comm "Plan: "] + 6) [:find $comm " Monthly"]]
        :local monthlyBill [:pick $comm ([:find $comm "Bill: "] + 6) [:find $comm " Contact:"]]
        :local contact  [:pick $comm ([:find $comm "Contact: "] + 9) [:find $comm " Date"]]
        :local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last"]]
        :local lastPayment [:pick $comm ([:find $comm "Payment: "] + 9) [:find $comm " Expired"]]
        :local balance [:pick $comm ([:find $comm "Bal: "] + 5) ([:len $comm])]

        :local newComm "Acc Number: $accNum Plan: $plan Monthly Bill: $monthlyBill Contact: $contact Date Installed: $dateInstalled Last Payment: $lastPayment Expired Since: $date Bal: $total"

       set $name comment=$newComm
}
please help me, thankyou!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Cant set ppp secret comment

Wed Mar 08, 2023 10:02 am

A snipplet can not suffice, for example $total is missing and miss also what happen before and later
        :local comm [/ppp secret get [find name=$accName] comment]
->         :local comm [get $accName comment]

        :local prof [/ppp secret get $accName profile]
->        :local prof [get $accName profile]

        set $name comment=$newComm
->        set $accName comment=$newComm

Never use field names as variable names....

Also a nice formatted code help to understand and debug, is not only visual improvement:

fixed code

/ppp secret
:foreach accName in=[find where profile="EXPIRED"] do={
# commented lines are unused
#       :local aName         [get $accName name   ]
#       :local prof          [get $accName profile]
        :local date          [/system clock get date]
        :local comm          [get $accName comment]
        :local accNum        [:pick $comm ([:find $comm "Number: "   ] +  8) [:find $comm " Plan:"  ]]
        :local plan          [:pick $comm ([:find $comm "Plan: "     ] +  6) [:find $comm " Monthly"]]
        :local monthlyBill   [:pick $comm ([:find $comm "Bill: "     ] +  6) [:find $comm " Contact"]]
        :local contact       [:pick $comm ([:find $comm "Contact: "  ] +  9) [:find $comm " Date"   ]]
        :local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last"   ]]
        :local lastPayment   [:pick $comm ([:find $comm "Payment: "  ] +  9) [:find $comm " Expired"]]
#       :local expiredSince  [:pick $comm ([:find $comm "Since: "    ] +  7) [:find $comm " Bal"    ]]
        :local balance       [:pick $comm ([:find $comm "Bal: "      ] +  5) [:len  $comm           ]]

        :local newComm "Acc Number: $accNum \
                              Plan: $plan \
                      Monthly Bill: $monthlyBill \
                           Contact: $contact \
                    Date Installed: $dateInstalled \
                      Last Payment: $lastPayment \
                     Expired Since: $date \
                               Bal: $balance"

        set $accName comment=$newComm
}
This code is corrected only against compiler errors, except $total that probably is defined before or is on reality $balance ???
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

Re: Cant set ppp secret comment

Thu Mar 09, 2023 3:04 am

Thankyou sir rextended , so much amazing! it works, i hope you never get tired of teaching us! long live !!!!
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

Re: Cant set ppp secret comment

Thu Mar 09, 2023 7:57 am

Sir rextended i change some of the code, but the problem i does not work? ive been so dumb, cant figure out what could be wrong
my goal here is when expired since = "blank" then add current date, else rewrite the date since it was expired
/ppp secret
:foreach accName in=[find where profile="EXPIRED"] do={
# commented lines are unused
#       :local aName         [get $accName name   ]
#       :local prof          [get $accName profile]
        :local date          [/system clock get date]
        :local comm          [get $accName comment]
        :local accNum        [:pick $comm ([:find $comm "Number: "   ] +  8) [:find $comm " Plan:"  ]]
        :local plan          [:pick $comm ([:find $comm "Plan: "     ] +  6) [:find $comm " Monthly"]]
        :local monthlyBill   [:pick $comm ([:find $comm "Bill: "     ] +  6) [:find $comm " Contact"]]
        :local contact       [:pick $comm ([:find $comm "Contact: "  ] +  9) [:find $comm " Date"   ]]
        :local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last"   ]]
        :local lastPayment   [:pick $comm ([:find $comm "Payment: "  ] +  9) [:find $comm " Expired"]]
        :local expiredSince  [:pick $comm ([:find $comm "Since: "    ] +  7) [:find $comm " Bal:"   ]]
        :local balance       [:pick $comm ([:find $comm "Bal: "      ] +  5) [:len  $comm           ]]

    :if ($expiredSince = "") do={

        :local newComm "Acc Number: $accNum \
                              Plan: $plan \
                      Monthly Bill: $monthlyBill \
                           Contact: $contact \
                    Date Installed: $dateInstalled \
                      Last Payment: $lastPayment \
                     Expired Since: $date \
                               Bal: $balance"

        set $accName comment=$newComm

    } else={

        :local newComm "Acc Number: $accNum \
                              Plan: $plan \
                      Monthly Bill: $monthlyBill \
                           Contact: $contact \
                    Date Installed: $dateInstalled \
                      Last Payment: $lastPayment \
                     Expired Since: $expiredSince \
                               Bal: $balance"

        set $accName comment=$newComm
    }

        
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Cant set ppp secret comment

Thu Mar 09, 2023 10:24 am

Is not needed to duplicate all the string creation and
set $accName comment=$newComm
just write it one time at the end of if /else

If :pick not find any to pick, return nil, instead of one empty string,
nil can not be copared with empty string "", not work.

You add : after Bal because some field can be confused? i suppose

revised code

/ppp secret
:foreach accName in=[find where profile="EXPIRED"] do={
# commented lines are unused
#       :local aName         [get $accName name   ]
#       :local prof          [get $accName profile]
        :local comm          [get $accName comment]
        :local accNum        [:pick $comm ([:find $comm "Number: "   ] +  8) [:find $comm " Plan:"  ]]
        :local plan          [:pick $comm ([:find $comm "Plan: "     ] +  6) [:find $comm " Monthly"]]
        :local monthlyBill   [:pick $comm ([:find $comm "Bill: "     ] +  6) [:find $comm " Contact"]]
        :local contact       [:pick $comm ([:find $comm "Contact: "  ] +  9) [:find $comm " Date"   ]]
        :local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last"   ]]
        :local lastPayment   [:pick $comm ([:find $comm "Payment: "  ] +  9) [:find $comm " Expired"]]
        :local expiredSince  [:pick $comm ([:find $comm "Since: "    ] +  7) [:find $comm " Bal:"   ]]
        :local balance       [:pick $comm ([:find $comm "Bal: "      ] +  5) [:len  $comm           ]]

        :if ([:typeof $expiredSince] != "str") do={
            :set expiredSince [/system clock get date]
        }

        :local newComm "Acc Number: $accNum \
                              Plan: $plan \
                      Monthly Bill: $monthlyBill \
                           Contact: $contact \
                    Date Installed: $dateInstalled \
                      Last Payment: $lastPayment \
                     Expired Since: $expiredSince \
                               Bal: $balance"

        set $accName comment=$newComm
}
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

Re: Cant set ppp secret comment

Thu Mar 09, 2023 5:30 pm

Thankyou again Sir! now it works !!!
 
Rubens0184
just joined
Posts: 1
Joined: Wed Jun 14, 2023 3:17 pm

Re: Cant set ppp secret comment

Wed Jun 14, 2023 3:50 pm

Hello
I need help to integrate my payment solution to mikrotic to generate automaticaly the tickets.
 
hunterleouser
just joined
Posts: 3
Joined: Wed Jun 14, 2023 12:15 am

Re: Cant set ppp secret comment

Thu Jun 15, 2023 1:54 am

Sir rextended please help me too here is my problem

this is what will be in the scheduler On event
:local secretName "15_36_0";
:local expirationDateTime [/system scheduler get [find name=my_house] comment];

:if ([:len $expirationDateTime] > 0) do={
  :local expirationDate [:pick $expirationDateTime 0 10];
  :local expirationTime [:pick $expirationDateTime 11 19];
  :local currentTime [/system clock get date];

  :if ($expirationDate <= $currentTime) do={
    /ppp secret set [find name=$secretName] profile=lablab;
    /ppp active remove [find name=$secretName];
    /system scheduler disable [find name=my_house];
    :log info ("Scheduler [my_house] has expired. Profile changed to [lablab] and PPP connection removed.");
  }
}


This is what is in the comment
06/14/2023 05:01:00
what this should do. is it will run every 5 minutes. extract comment date info in the scheduler comment section, and compare it to current date&time. if the comment is lesser it will disable remove and change profile of the said PPP and disable the current schedule. but its not working please help
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Cant set ppp secret comment

Thu Jun 15, 2023 6:35 am

Ask ChatGPT for help, since you like it so much.
I don't even consider that shit.

viewtopic.php?p=1007642#p1007642
viewtopic.php?p=1007818#p1007818

And I don't even reply to those who spam the forum.
 
hunterleouser
just joined
Posts: 3
Joined: Wed Jun 14, 2023 12:15 am

Re: Cant set ppp secret comment

Thu Jun 15, 2023 6:44 pm

Thank you rextended. and its not wrong to ask chatgpt for help.. cause i dont know anything about mikrotik, but im trying.
I apologize for the spam post guys. had been little desperate to have an answer. tried to delete some for it not to spam but it doesn't allow me

Who is online

Users browsing this forum: No registered users and 8 guests