Community discussions

MikroTik App
 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

adding a lot of ppp secret on mikrotik script

Mon Sep 03, 2007 1:40 am

hi ppl. i need help. how can i add 700 ppp secret on mikrotik. they are in one txt file, which has this format:
username,password,local_address,remote_address,profile,service
i can upload that file on mikrotik FTP, and scrpit, which i need, must read that file, and create ppp secret, using data from that file. can someone help me. version of my mikrotik is 2.9.27.thanks
PS: sorry, my english is very bad :( i hope so, that they understand, what i need.
 
User avatar
omega-00
Forum Guru
Forum Guru
Posts: 1167
Joined: Sat Jun 06, 2009 4:54 am
Location: Australia
Contact:

Re: adding a lot of ppp secret on mikrotik script

Mon Sep 03, 2007 4:48 am

Before anything, why 700 ppp secrets.. sounds like you'd be better off with a small radius server running.

and if so, why not just import them into the user-manager?
 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: adding a lot of ppp secret on mikrotik script

Mon Sep 03, 2007 2:05 pm

ok, im network administrator in one scool, and i have on mikrotik one pppoe server. each of student have one ppp secret to connecting on pppoe server. each of student has own local address, remote address, username and password.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: adding a lot of ppp secret on mikrotik script

Mon Sep 03, 2007 3:29 pm

I assume that information per user is written in one line.
This script will parse file and convert each line it finds to array. From that array data can be easily extracted and passed as parameter to any command:
:global content [/file get [/file find name=filename.txt] contents] ;
:global contentLen [ :len $content ] ;

:local lineEnd 0;
:local line "";
:local lastEnd 0;


:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content 0 $lineEnd] ;
       :set lastEnd $lineEnd ;

       :local tmpArray [:toarray $line] ;
       # here you can add ppp secret
       # if this is the format -> username,password,local_address,remote_address,profile,service
       /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] .... and so on
} while ($lineEnd < $contentLen)
This script don't perform any error checkings:
*) if data is not in this format -> username,password,local_address,remote_address,profile,service - script will fail
 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: adding a lot of ppp secret on mikrotik script

Tue Sep 04, 2007 1:12 pm

this script is not working at me :(:(
:global content [/file get [/file find name=accaunts.txt] contents] ;
:global contentLen [ :len $content ] ;

:local lineEnd 0;
:local line "";
:local lastEnd 0;


:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content 0 $lineEnd] ;
       :set lastEnd $lineEnd ;
       :local tmpArray [:toarray $line] ;
         /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] local address=[:pick $tmpArray 2] remote address=[:pick $tmpArray 3] profile=[:pick $tmpArray 4] service=[:pick $tmpArray 5];
} while ($lineEnd < $contentLen)
what is wrong there???
file has name accaunts.txt and i write in it this:
kolins,sifra,10.10.1.10,192.168.1.10,students,pppoe

when i start this script, it's nothing happening :(:(
can someone help me??? please!!
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: adding a lot of ppp secret on mikrotik script

Tue Sep 04, 2007 3:55 pm

:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line "";
:global lastEnd 0;

:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;

       :local tmpArray [:toarray $line] ;
       :if ( [:pick $tmpArray 0] != "" ) do={
              :put $tmpArray;
              /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] local-address=[:pick $tmpArray 2] remote-address=[:pick $tmpArray 3] profile=[:pick $tmpArray 4] service=[:pick $tmpArray 5];
       }
} while ($lineEnd < $contentLen)

This code works for sure, tested myself.
Note that at the en of each line you must have "\r\n" sequence ( this is default windows newline ); If you have other format modify 9-th line of script according to what you need.

Test file can be created easily:
/file print file="test.txt"
/file set test.txt contents="kolins,sifra,10.10.1.1,192.168.1.1,students,pppoe\r\naaa,bbb,1.1.1.1,2.2.2.2,students,pppoe\r\n"
 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: adding a lot of ppp secret on mikrotik script

Tue Sep 04, 2007 4:55 pm

sorry, it's not working again :( :( :(
when i type this command, i get error message. u can see it on pic.
[admin@STSZav] > /file set accaunti.txt contents="kolins,sifra,10.10.1.1,192.168.1.1,students,pppoe\r\naaa,bbb,1.1.1.1,2.2.2.2,s
tudents,pppoe\r\n"
no such command or directory (set)
[admin@STSZav] > 
You do not have the required permissions to view the files attached to this post.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: adding a lot of ppp secret on mikrotik script

Tue Sep 04, 2007 5:22 pm

You are geting this error probably because you are on 2.9.xx
/file set is available only in 3.0

Also in 3.0 scripting is a lot more improved


you can write file in notepad and then upload to router via ftp


Also it is not recommended to use so many ppp secrets on integrated accounting system.
Use external RADIUS server or Mikrotik UserManager.
 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: adding a lot of ppp secret on mikrotik script

Tue Sep 04, 2007 8:37 pm

OK. I have Mikrotik 2.9.27. Can u help me that i make this configuration: Mikrotik PPPOE SERVER + MIKROTIK USER MANAGER. Is possible that combination on only ONE Mikrotik? Sorry, if i intrude :(
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: adding a lot of ppp secret on mikrotik script

Tue Sep 04, 2007 8:42 pm

Upgrade to latest version, also you will have to get level 6 license if you have more than 10 active sessions
 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: adding a lot of ppp secret on mikrotik script

Wed Sep 05, 2007 12:14 am

i already have level 6 ;)
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: adding a lot of ppp secret on mikrotik script

Wed Sep 05, 2007 9:13 am

 
kolinsb
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: adding a lot of ppp secret on mikrotik script

Mon Apr 06, 2009 9:05 pm

i'm again there, with same problem :( i have mikrotik v3.13 lvl4, but this script didn't work on my mikrotik :( i have test.txt file, and when i run script nothing happens :( now i need same script for add users in user manager, not secrets. i can't change this scipt, because it's not work :( can sameone help me? thanks.
 
mudasir
Member Candidate
Member Candidate
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: adding a lot of ppp secret on mikrotik script

Tue Apr 07, 2009 1:02 am

Hi,

It is very easy only if you have a linux machine available. The following script can help you out.

FPATH="/path/to/dir"
FILE="raw-data-file"
NEW="newfile.rsc

echo "/ppp secret" >> $FPATH/$NEW
cat $FILE | while read users
do

UID=`echo $users | cut-d, -f1`
PASS=`echo $users | cut-d, -f2`
LOC_ADD=`echo $users | cut-d, -f3`
REM_ADD=`echo $users | cut-d, -f4
PROFILE=`echo $users | cut-d, -f5`
SERVICE=`echo $users | cut-d, -f6`

echo "add name=\"$UID\" password=$PASS local-address=$LOC_ADD remote-address=$REM_ADD service=$SERVICE profile=$PROFILE " >> $FPATH/$NEW

done

I do most of my work with linux scripts. So its very easy.

Who is online

Users browsing this forum: flapviv, K0NCTANT1N and 35 guests