meta data for this page
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
| Ambos lados da revisão anterior Revisão anterior Próxima revisão | Revisão anterior | ||
| integracao_mikrotik [2020/05/08 12:39] djol | integracao_mikrotik [2023/12/26 16:40] (atual) | ||
|---|---|---|---|
| Linha 5: | Linha 5: | ||
| * **AUC** - Porta do accounting, se o SGP for LOCAL a porta é padrão 1812 se for Nuvem consultar SUPORTE. | * **AUC** - Porta do accounting, se o SGP for LOCAL a porta é padrão 1812 se for Nuvem consultar SUPORTE. | ||
| * **ACC** - Porta do authentication, se o SGP for LOCAL a porta é padrão 1813 se for Nuvem consultar SUPORTE. | * **ACC** - Porta do authentication, se o SGP for LOCAL a porta é padrão 1813 se for Nuvem consultar SUPORTE. | ||
| - | * **IP** - IP que o SGP responde (público). | + | * **LINKDOSGP** - URL do SGP (ex: http://meusgplocal.com.br:8000 ou https://meusgpnuvem.sgp.net.br) | 
| + | * **TOKEN** - Token mikrotik do SGP. | ||
| * **RADIUS** - IP que o SGP responde, em caso de Nuvem será o IP que responde ou o gateway da VPN fornecida pelo suporte. | * **RADIUS** - IP que o SGP responde, em caso de Nuvem será o IP que responde ou o gateway da VPN fornecida pelo suporte. | ||
| * **BLQ** - Porta em que a página de bloqueio será exibida se o SGP for LOCAL é padrão 6403. Consulte a [[tabela_variaveis|tabela de variáveis]] para ver o conteúdo da pagina. | * **BLQ** - Porta em que a página de bloqueio será exibida se o SGP for LOCAL é padrão 6403. Consulte a [[tabela_variaveis|tabela de variáveis]] para ver o conteúdo da pagina. | ||
| Linha 17: | Linha 18: | ||
| <code> | <code> | ||
| - | :global USERVPN "USUÁRIO_DA_VPN" | ||
| - | /system backup save name=BACKUP_ANTES_DO_SGP | ||
| - | /export file=BACKUP_ANTES_DO_SGP | ||
| - | :global PASSVPNUSER "SENHA_DA_VPN_E_USUÁRIO" | ||
| - | :global AUC "1812" | ||
| - | :global ACC "1813" | ||
| - | :global RADIUS "IP_DO_RADIUS" | ||
| - | :global TOKENAQUI "TOKEN_GERADO_NO_SGP" | ||
| - | :global LINKDOSGP "URL_DO_SGP" | ||
| - | :global IP "IP_DA_URL" | ||
| - | :global AVS "6402" | ||
| - | :global BLQ "6403" | ||
| - | /ip firewall address-list  | ||
| - | add address=$IP list=SITES-LIBERADOS | ||
| - | add address=208.67.222.222 list=SITES-LIBERADOS | ||
| - | add address=208.67.222.220 list=SITES-LIBERADOS | ||
| - | add address=8.8.8.8 list=SITES-LIBERADOS | ||
| - | add address=8.8.4.4 list=SITES-LIBERADOS | ||
| - | add address=1.1.1.1 list=SITES-LIBERADOS | ||
| - | add address=10.24.0.0/20 list=BLOQUEADOS | ||
| - | /ip firewall filter  | ||
| - | add action=drop chain=forward dst-address-list=!SITES-LIBERADOS src-address-list=BLOQUEADOS comment="SGP REGRAS" | ||
| - | /ip firewall filter | ||
| - | add chain=forward connection-mark=BLOQUEIO-AVISAR action=add-src-to-address-list \ | ||
| - | address-list=BLOQUEIO-AVISADOS address-list-timeout=2h comment="SGP REGRAS" dst-address=$IP dst-port=$AVS protocol=tcp | ||
| - | /ip firewall nat | ||
| - | add action=accept chain=srcnat comment="NAO FAZER NAT PARA O IP DO RADIUS" \ | ||
| - | dst-address=$RADIUS dst-port="$AUC-$ACC,3799" protocol=udp | ||
| - | add action=masquerade chain=srcnat comment="SGP REGRAS" src-address-list=\ | ||
| - | BLOQUEADOS | ||
| - | add action=dst-nat chain=dstnat comment="SGP REGRAS" dst-address-list=\ | ||
| - | !SITES-LIBERADOS dst-port=80,443 log-prefix="" protocol=tcp \ | ||
| - | src-address-list=BLOQUEADOS to-addresses=$IP to-ports=$BLQ | ||
| - | add action=dst-nat chain=dstnat comment="SGP REGRAS" connection-mark=\ | ||
| - | BLOQUEIO-AVISAR log-prefix="" protocol=tcp to-addresses=$IP to-ports=$AVS | ||
| - | # Aviso bloqueio  | ||
| - | /ip firewall mangle | ||
| - | add chain=prerouting connection-state=new src-address-list=BLOQUEIO-AVISAR protocol=tcp dst-port=80 \ | ||
| - | action=mark-connection new-connection-mark=BLOQUEIO-VERIFICAR passthrough=yes comment="SGP REGRAS" | ||
| - | add chain=prerouting connection-mark=BLOQUEIO-VERIFICAR src-address-list=!BLOQUEIO-AVISADOS \ | ||
| - | action=mark-connection new-connection-mark=BLOQUEIO-AVISAR comment="SGP REGRAS" | ||
| - | /system scheduler | ||
| - | add interval=1h name=sgp-aviso on-event=sgp-aviso policy=\ | ||
| - | ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=\ | ||
| - | may/29/2017 start-time=01:00:00 | ||
| - | /system script | ||
| - | add name=sgp-aviso policy=\ | ||
| - | ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":log info\ | ||
| - | \_\"sgp aviso\";\r\ | ||
| - | \n/file remove [find where name=sgp_aviso.rsc]\r\ | ||
| - | \n/tool fetch url=\"$LINKDOSGP/ws/mikrotik/aviso/pendencia/\?token=$TOKENAQUI&app=mikrotik\" dst-path=sgp_aviso.rsc;\r\ | ||
| - | \n:delay 30s\r\ | ||
| - | \nimport file-name=sgp_aviso.rsc;" | ||
| - | \n:delay 10s\r\ | ||
| - | \n/ip firewall address-list set timeout=00:30:00 [/ip firewall address-list find list=BLOQUEIO-AVISAR]" | ||
| - | /system ntp client set enabled=yes primary-ntp=200.160.0.8 | ||
| - | /system clock set time-zone-name=America/Recife | ||
| - | /radius incoming set accept=yes | ||
| - | /ip service | ||
| - | set api disabled=no port=3540 | ||
| - | set www disabled=no port=8008 | ||
| - | /user aaa set use-radius=yes | ||
| - | /ppp aaa set interim-update=5m use-radius=yes | ||
| - | /interface pppoe-server server set authentication=pap [ find where .id!=999] | ||
| - | /interface pppoe-server server set one-session-per-host=no [find .id!=999] | ||
| - | /tool graphing set page-refresh=300 store-every=5min | ||
| - | /tool graphing interface add allow-address=0.0.0.0/0 disabled=no interface=all store-on-disk=yes | ||
| - | /tool graphing queue add allow-address=0.0.0.0/0 allow-target=yes disabled=no simple-queue=all store-on-disk=yes | ||
| - | /tool graphing resource add allow-address=0.0.0.0/0 disabled=no store-on-disk=yes | ||
| - | /snmp community add addresses=$RADIUS name=SGP-GRAPHICs | ||
| - | /snmp set enabled=yes trap-community=SGP-GRAPHICs trap-version=2 | ||
| - | /system logging set 0 action=memory disabled=no prefix="" topics=info,!account | ||
| - | /radius | ||
| - | add comment="RADIUS SGP" secret=sgp@radius service=ppp,dhcp,login address=$RADIUS accounting-port=$ACC authentication-port=$AUC \ | ||
| - | timeout=00:00:03 | ||
| - | /user add name=SGP comment="USUARIO QUE O SERVIDOR SGP ACESSA A RB" group=full password=$PASSVPNUSER | ||
| - | /interface sstp-client add connect-to=($IP.":4433") user=$USERVPN password=$PASSVPNUSER name="SGP-SSTP"\ | + | :global AUC "1812" | 
| - | disabled=no profile=default-encryption | + | :global ACC "1813" | 
| + | :global AVS "6402" | ||
| + | :global BLQ "6403" | ||
| + | :global PASSVPNUSER "PASSWORD_FORT" | ||
| + | :global RADIUS "IP DO RADIUS" | ||
| + | :global TOKEN "TOKEN MIKROTIK" | ||
| + | :global LINKDOSGP "http://x.x.x.x:8000" | ||
| + | :global IPSGP "IP DO SGP" | ||
| + | |||
| + | :global NAS "IP_DO_NAS" | ||
| + | |||
| + | |||
| + | /system backup save name=BACKUP_ANTES_DO_SGP | ||
| + | /export file=BACKUP_ANTES_DO_SGP_TXT | ||
| + | # REGRAS DE AVISO E BLOQUEIO | ||
| + | /system ntp client set enabled=yes primary-ntp=200.160.0.8 | ||
| + | /system clock set time-zone-name=America/Recife | ||
| + | /radius incoming set accept=yes | ||
| + | /ip service set api disabled=no port=3540 address="$RADIUS,$IPSGP" | ||
| + | /user aaa set use-radius=yes | ||
| + | /ppp aaa set interim-update=5m use-radius=yes | ||
| + | /snmp community disable public | ||
| + | /snmp community add addresses="$RADIUS,$IPSGP" name=SGP-GRAPHICs | ||
| + | /snmp set enabled=yes trap-community=SGP-GRAPHICs trap-version=2 | ||
| + | /user add name=SGP comment="NAO MUDAR SENHA E NÃO ALERAR NADA, USUARIO QUE O SERVIDOR SGP ACESSA A RB" \ | ||
| + | group=full password=$PASSVPNUSER | ||
| + | /system logging set 0 action=memory disabled=no prefix="" topics=info,!account | ||
| + | /radius | ||
| + | add comment="RADIUS SGP" secret=sgp@radius service=ppp,dhcp address=$RADIUS accounting-port=$ACC \ | ||
| + | authentication-port=$AUC timeout=00:00:03 src-address=$NAS | ||
| + | |||
| + | # REGRAS DE AVISO E BLOQUEIO | ||
| + | |||
| + | /ip firewall address-list | ||
| + | add address=$RADIUS list=SITES-LIBERADOS | ||
| + | add address=$IPSGP list=SITES-LIBERADOS | ||
| + | add address=208.67.222.222 list=SITES-LIBERADOS | ||
| + | add address=208.67.222.220 list=SITES-LIBERADOS | ||
| + | add address=8.8.8.8 list=SITES-LIBERADOS | ||
| + | add address=8.8.4.4 list=SITES-LIBERADOS | ||
| + | add address=1.1.1.1 list=SITES-LIBERADOS | ||
| + | add address=10.24.0.0/20 list=BLOQUEADOS | ||
| + | |||
| + | /ip firewall filter | ||
| + | add chain=forward connection-mark=BLOQUEIO-AVISAR action=add-src-to-address-list \ | ||
| + | address-list=BLOQUEIO-AVISADOS address-list-timeout=00:01:00 comment="SGP REGRAS" dst-address=$IPSGP \ | ||
| + | dst-port=$AVS protocol=tcp | ||
| + | /ip firewall nat | ||
| + | add action=masquerade chain=srcnat comment="SGP REGRAS" dst-address-list=\ | ||
| + | SITES-LIBERADOS src-address-list=BLOQUEADOS | ||
| + | add action=dst-nat chain=dstnat comment="SGP REGRAS" dst-address-list=\ | ||
| + | !SITES-LIBERADOS dst-port=80,443 log-prefix="" protocol=tcp \ | ||
| + | src-address-list=BLOQUEADOS to-addresses=$IPSGP to-ports=$BLQ | ||
| + | add action=dst-nat chain=dstnat comment="SGP REGRAS" connection-mark=\ | ||
| + | BLOQUEIO-AVISAR log-prefix="" protocol=tcp to-addresses=$IPSGP to-ports=$AVS | ||
| + | /ip firewall mangle | ||
| + | add chain=prerouting connection-state=new src-address-list=BLOQUEIO-AVISAR protocol=tcp dst-port=80,443 \ | ||
| + | action=mark-connection new-connection-mark=BLOQUEIO-VERIFICAR passthrough=yes comment="SGP REGRAS" | ||
| + | add chain=prerouting connection-mark=BLOQUEIO-VERIFICAR src-address-list=!BLOQUEIO-AVISADOS \ | ||
| + | action=mark-connection new-connection-mark=BLOQUEIO-AVISAR comment="SGP REGRAS" | ||
| + | /ip firewall raw | ||
| + | add action=notrack chain=output comment="SGP NAO FAZER NAT PARA O RADIUS" \ | ||
| + | dst-address=$RADIUS dst-port="$AUC-$ACC,3799" protocol=udp | ||
| + | add action=drop chain=prerouting comment="SGP BLOQUEIO" dst-address-list=\ | ||
| + | !SITES-LIBERADOS src-address-list=BLOQUEADOS | ||
| + | /system scheduler | ||
| + | add interval=4h name=sgp-aviso on-event=sgp-aviso policy=\ | ||
| + | ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=01:00:00 disabled=yes | ||
| + | /system script | ||
| + | add name=sgp-aviso policy=\ | ||
| + | ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":log info\ | ||
| + | \_\"sgp aviso\";\r\ | ||
| + | \n/file remove [find where name=sgp_aviso.rsc]\r\ | ||
| + | \n/tool fetch url=\"$LINKDOSGP/ws/mikrotik/aviso/pendencia/\\?token=$TOKEN&app=mikrotik\" dst-path=sgp_aviso.rsc;\r\ | ||
| + | \n:delay 30s\r\ | ||
| + | \nimport file-name=sgp_aviso.rsc;\r\ | ||
| + | \n:delay 10s;\r\ | ||
| + | \n/ip firewall address-list set timeout=00:15:00 [/ip firewall address-list find list=BLOQUEIO-AVISAR]";\ | ||
| + | |||
| + | # CONFIGURACAO IPv6 MIKROTIK | ||
| + | |||
| + | :global versao [/system package get number=0 version ]; :global versao2 [:pick $versao 0 [:find "$versao" "." -3]]; | ||
| + | :delay 2s | ||
| + | :put $versao2 | ||
| + | :if ($versao2=7) do={ | ||
| + | :global ipv6 [/ipv6 settings get disable-ipv6] | ||
| + | :if ($ipv6=false) do={ | ||
| + | :log info "############\nTEM IPV6 HABILITADO NESSA RB - CONFIGURAR VARIAVEIS E SCRIPT NO PROFILE\n############" | ||
| + | :log info "CONFIGURANDO O POOL DE BLOQUEIO IPv6" | ||
| + | /ipv6 pool add name=bloqueiov6pd prefix-length=64 prefix=2001:DB9:100::/40 | ||
| + | /ipv6 pool add name=bloqueiov6prefix prefix-length=64 prefix=2001:DBA:900::/40  | ||
| + | } else={ | ||
| + | :log info "############\nNAO TEM IPV6 HABILITADO NESSA RB\n############" | ||
| + | } | ||
| + | } else={ | ||
| + | :if ($versao2=6) do={ | ||
| + | :global ipv6 [/system package get ipv6 disabled ] | ||
| + | :if ($ipv6=false) do={ | ||
| + | :log info "############\nTEM IPV6 HABILITADO NESSA RB - CONFIGURAR VARIAVEIS E SCRIPT NO PROFILE\n############" | ||
| + | :log info "CONFIGURANDO O POOL DE BLOQUEIO IPv6" | ||
| + | /ipv6 pool add name=bloqueiov6pd prefix-length=64 prefix=2001:DB9:100::/40 | ||
| + | /ipv6 pool add name=bloqueiov6prefix prefix-length=64 prefix=2001:DBA:900::/40  | ||
| + | } else={ | ||
| + | :log info "############\nNAO TEM IPV6 HABILITADO NESSA RB\n############" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | # CRIAR BACKUP DOS PPPoEs | ||
| + | |||
| + | :global wurl "ws/mikrotik/login/local" | ||
| + | /system script | ||
| + | add name=sgp_login_local owner=SGP policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":global filename \"sgp_login_local.txt\";\r\ | ||
| + | \n/file remove [/file find name=\$filename]\r\ | ||
| + | \n/tool fetch url=\"$LINKDOSGP/$wurl/\\?token=$TOKEN&app=mikrotik&nas=$NAS&disabled=1\" duration=30 dst-path=\$filename;\r\ | ||
| + | \n:delay 32s;\r\ | ||
| + | \n/import file-name=\$filename;" | ||
| + | /system scheduler | ||
| + | add disabled=no interval=6h name=sgp_login_local on-event=sgp_login_local policy=\ | ||
| + | ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=12:00:00 | ||
| + | /tool netwatch | ||
| + | add comment="ATIVAR O SECRETS CASO O RADIUS PARE" disabled=yes \ | ||
| + | down-script="/ppp secret ; :foreach i in [ find comment~\"SGP:\ | ||
| + | \" ] do={ enable \$i }; /ppp active; :foreach p in [find \\ radius=no comment~\"SGP:\"] do=\ | ||
| + | { remove \$p; :delay 1};" host=$RADIUS interval=3m timeout=10000ms \ | ||
| + | up-script="/ppp secret ; :foreach i in [ find comment~\"SGP:\" ] do={ disa\ | ||
| + | ble \$i }; /ppp active; :foreach p in [find \\ radius=no comment~\"SGP:\"] do={ remove \$p;\ | ||
| + | \_:delay 1};" | ||
| + | :log print where message="TEM IPV6 HABILITADO NESSA RB - CONFIGURAR VARIAVEIS E SCRIPT NO PROFILE" or message="NAO TEM IPV6 HABILITADO NESSA RB" | ||
| + | |||
| + | #Script Integração | ||
| + | #Systema de Gerenciamento de provedores - SGP | ||
| Linha 102: | Linha 157: | ||
| Feito isso, acesse o menu **Administração >> Cadastros >> Radius(NAS)**, clique nem **Cadastrar NAS** no canto superior direito da página e preencha o formulário de acordo com as configurações do MikroTik. | Feito isso, acesse o menu **Administração >> Cadastros >> Radius(NAS)**, clique nem **Cadastrar NAS** no canto superior direito da página e preencha o formulário de acordo com as configurações do MikroTik. | ||
| - | {{ :captura_de_tela_de_2018-12-28_13-39-29.png |}} | + | {{ :cadastronas.png?600 |}} | 
| {{ :captura_de_tela_de_2018-12-28_14-03-57.png |}} | {{ :captura_de_tela_de_2018-12-28_14-03-57.png |}} | ||
| - | Para verificar a se a conexão ocorreu como esperado, click em **Opções** na NAS cadastrada e escolha a opção **Verificar Sessões**. | ||
| - | {{ :captura_de_tela_de_2018-12-28_14-16-58.png |}} | ||
| - | Se tudo deu certo, a seguinte página irá ser exibida. Caso contrário, verifique os passos novamente e contate a central de atendimentos. | + | <html> | 
| + | |||
| + | <head> | ||
| + | <meta charset="UTF-8" /> | ||
| + | <meta name="viewport" content="width=device-width, user-scalable=0" /> | ||
| + | |||
| + | <style type="text/css"> | ||
| + | |||
| + | p { | ||
| + | text-align: center; | ||
| + | } | ||
| + | |||
| + | |||
| + | img{ | ||
| + | display: block; | ||
| + | margin: 0px auto; | ||
| + | -webkit-box-shadow: 9px 7px 5px rgba(50, 50, 50, 0.5); | ||
| + | --moz-box-shadow:  9px 7px 5px rgba(50, 50, 50, 0.5); | ||
| + | -box-shadow:  9px 7px 5px rgba(50, 50, 50, 0.5); | ||
| + | } | ||
| + | |||
| + | </style> | ||
| + | |||
| + | </head>  | ||
| + | |||
| + | |||
| + | <body> | ||
| + | |||
| + | <p>Para verificar se a conexão ocorreu como esperado, click no <b> ícone da engrenagem</b> localizada ao lado do IP do NAS. </p> | ||
| + | |||
| + | <img id="shadow-box" src="http://wiki.sgp.net.br/lib/exe/fetch.php?media=nas:verificar_sessoes_1.png" alt="verificar sessoes 1"> | ||
| + | <br><br> | ||
| + | |||
| + | <p>Caso a comunicação via API do SGP ao NAS esteja correta, irá ser exibida a seguinte mensagem da imagem abaixo em uma nova aba do navegador. Caso contrário, verifique os passos novamente e contate a central de atendimentos.</p> | ||
| + | <br> | ||
| + | |||
| + | <img id="shadow-box" src="http://wiki.sgp.net.br/lib/exe/fetch.php?media=nas:nas_ok_.png" alt="NAS OK">  | ||
| + | |||
| + | |||
| + | </body> | ||
| + | </html> | ||
