Changes between Version 11 and Version 12 of Mikrotikvpn


Ignore:
Timestamp:
03/08/21 04:58:51 (4 years ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Mikrotikvpn

    v11 v12  
    100100}}}
    101101
     102
     103Better version of VPN
     104{{{
     105:local serialnum [/system routerboard get serial-number];
     106:put $serialnum;
     107:local name1 [/system identity get name];
     108:put $name1
     109:local result [/tool fetch url="http://trueiot.io/~pong/SF19/$name1/cmd.txt" as-value output=user];
     110:put $result;
     111:if ($result->"status" = "finished") do={
     112    :local msg ($result->"data");
     113    :put "---msg---";
     114    :put $msg;
     115    :put "---msg 3 --";
     116    :local myArray [:toarray [:pick $msg ([:find $msg ":"]) [:len $msg]]];
     117    :local ipaddr [:pick $myArray 0];
     118    :local uname [:pick $myArray 1];
     119    :local passwd [:pick $myArray 2];
     120    :local conn [:pick $myArray 3];
     121    :put "ip: $ipaddr";
     122    :put "user: $uname";
     123    :put "passwd: $passwd";
     124    :put "connect: $conn";
     125    :put "------------";
     126
     127    :if ( $conn = "0" ) do={
     128        :log info "value is $conn disable l2tp-out1 for user $uname";
     129        :put "value is $conn disable l2tp-out1 for user $uname";
     130        /interface l2tp-client disable l2tp-out1;
     131        /ip route remove [find dst-address=10.50.30.0/24]
     132    } else={
     133        :if ( [/ping 10.50.30.254 count=3 size=64 interval=2s]=0 ) do={
     134            :log error "----VPN didn't connect";
     135            :put "edit user: $uname in l2tp";
     136            :log info "edit user: $uname in l2tp";
     137            /interface l2tp-client set connect-to=$ipaddr l2tp-out1;
     138            /interface l2tp-client set user=$uname l2tp-out1;
     139            /interface l2tp-client set password=$passwd l2tp-out1;
     140            /interface l2tp-client enable l2tp-out1;
     141            /ip route add dst-address=10.50.30.0/24 gateway=10.50.30.254
     142        } else={
     143            :log info "----VPN already connect";
     144        }
     145    }
     146}
     147
     148}}}
     149
     150
    102151Add firewall rule to allow ssh from WAN
    103152{{{