User Tools

Site Tools


routeros

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
routeros [2026/07/02 20:32] – protocolrouteros [2026/09/23 14:16] (current) – protocol
Line 64: Line 64:
  
 </code> </code>
 +
 +===== Automatic PPPoE creation local secrets =====
 +<code>
 +
 +{
 +    :put "Starting real-time PPPoE-only log monitor... Press [Ctrl+C] to stop.";
 +    
 +    # Initialize the log pointer to the very last current entry
 +    :local terminalLogID [/log find]
 +    :local lastID ""
 +    :if ([:len $terminalLogID] > 0) do={
 +        :set lastID ($terminalLogID->([:len $terminalLogID] - 1))
 +    }
 +
 +    # Continuous loop
 +    :while (true) do={
 +        # Filter logs containing authentication failure and include "user "
 +        :local logEntries [/log find where message~"authentication failed" and message~"user "]
 +        
 +        :foreach entry in=$logEntries do={
 +            # Process only newer entries than our saved marker
 +            :if ($entry > $lastID) do={
 +                :local logTopics [/log get $entry topics]
 +                
 +                # STRICT TOPIC CHECK: Ensure the log contains the 'pppoe' topic
 +                :if ($logTopics ~ "pppoe") do={
 +                    :local logMsg [/log get $entry message]
 +                    :local logTime [/log get $entry time]
 +                    
 +                    :local startPos ([:find $logMsg "user "] + 5)
 +                    :local endPos [:find $logMsg " authentication failed" $startPos]
 +                    
 +                    :if ($endPos > $startPos) do={
 +                        :local pppoeUser [:pick $logMsg $startPos $endPos]
 +                        
 +                        # Verify if it already exists
 +                        :if ([:len [/ppp secret find where name=$pppoeUser]] = 0) do={
 +                            /ppp secret add name=$pppoeUser password="12345" service=pppoe comment="Auto-created via pppoe log monitor"
 +                            :put "[$logTime] [PPPoE Match] Created user: $pppoeUser"
 +                        } else={
 +                            :put "[$logTime] [PPPoE Match] Missing user '$pppoeUser' detected, but secret already exists."
 +                        }
 +                    }
 +                }
 +                :set lastID $entry
 +            }
 +        }
 +        # 2-second delay before checking the log buffer again
 +        :delay 2s;
 +    }
 +}
 +
 +</code>
 +
routeros.1783035121.txt.gz · Last modified: by protocol