Changes between Initial Version and Version 1 of Mikrotikvpn


Ignore:
Timestamp:
02/28/21 10:05:09 (4 years ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Mikrotikvpn

    v1 v1  
     1= Mikrotik VPN =
     2
     3We want Mikrotik to make l2tp connect to server when it check the webserver. [[br]]
     41. Web server site
     52. VPN server
     63. l2tp Mikrotik client
     7
     8On Web server, we need to edit file '''out.txt''' for any vpn client to check the connect need or not.
     9
     10{{{
     11#!sh
     12/home/krit/public_html/Tmp/D4410D3300C8
     13[krit@mini D4410D3300C8]$ cat out2.txt
     14trueiot.io, tonic11, vpnPassw0rd, 1,
     15[krit@mini D4410D3300C8]$
     16}}}
     17In above, vpn server=trueiot.io, vpn username=tonic11, passwd=vpnPassw0rd, connect enable=1 (to disable connection this value will be 0) [[br]]
     18
     19
     20
     21VPN with l2tp config script
     22{{{
     23#!sh
     24 5   name="http_get_5" owner="admin" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
     25     dont-require-permissions=no last-started=feb/27/2021 00:36:10 run-count=10 source=
     26       {
     27             :local serialnum [/system routerboard get serial-number];
     28             :put $serialnum;
     29             :local result [/tool fetch url="http://192.168.5.1/~krit/Tmp/$serialnum/out2.txt" as-value output=user];
     30             :put $result;
     31             :local msg ($result->"data");
     32             :put "---msg---";
     33             :put $msg;
     34             :put "---msg 3 --";
     35             :local myArray [:toarray [:pick $msg ([:find $msg ":"]) [:len $msg]]];
     36             :local ipaddr [:pick $myArray 0];
     37             :local uname [:pick $myArray 1];
     38             :local passwd [:pick $myArray 2];
     39             :local conn [:pick $myArray 3];
     40             :put "ip: $ipaddr";
     41             :put "user: $uname";
     42             :put "passwd: $passwd";
     43             :put "connect: $conn";
     44             :put "------------";
     45             :local serialnum [/system routerboard get serial-number];
     46             :put $serialnum;
     47             :if ($result->"status" = "finished") do={                                           
     48                :if ( $conn = "0" ) do={
     49                    :log info "value is $conn disable l2tp-out1 for user $uname";     
     50                    :put "value is $conn disable l2tp-out1 for user $uname";
     51                    /interface l2tp-client disable l2tp-out1;
     52                } else={             
     53                    :put "edit user: $uname in l2tp";
     54                    :log info "edit user: $uname in l2tp";
     55                    /interface l2tp-client set connect-to=$ipaddr l2tp-out1;
     56                    /interface l2tp-client set user=$uname l2tp-out1;
     57                    /interface l2tp-client set password=$passwd l2tp-out1;
     58                    /interface l2tp-client enable l2tp-out1;
     59                 }
     60              }                       
     61       }
     62
     63[admin@MikroTik] >
     64}}}