Siga-me manipulável via telefone e via banco de dados no Asterisk

Criação de um sigame que pode posterior manipular via telefone ou interface web

Criar o banco no mysql:

create database asterisk;

use asterisk;

CREATE TABLE IF NOT EXISTS `sigame` (
  `status` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `sigame` (`status`) VALUES (1);

Criar no plano de discagem do asterisk:

/etc/asterisk/extensions.conf


[sigame]

[sigame]


exten => ***,1,goto(sigame,s,1(inicio_sigame))

exten => s,1(inicio_sigame),background(ativa_desativa_sigame)
	
exten => 0,1,playback(fala_zero)
	same => n,goto(sigame_desativado,1)
exten => 1,1,playback(fala_um_sigame)
	same => n,goto(sigame_ativo,1)
exten => 9,1,playback(fala_nove)
	same => n,goto(sigame_consulta,1)

exten => s,2,WaitExten(3)
		same => n,goto(sigame,s,1)
exten => i,1,Playback(opcao_invalida_sigame)
		same => n,goto(sigame,s,1)
exten  => sigame_ativo,1,NooP(Siga-me esta ativado)
		same => n,nocdr()
		same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
		same => n,NoOp(connid = ${connid})
		same => n,MYSQL(Query resultid ${connid} update sigame set status=1)
		same => n,MYSQL(Disconnect ${connid})
		same => n,playback(sigame_ativado)
		same => n,goto(sigame,s,1)
exten => sigame_desativado,1,NooP(Siga-me esta desativado)
		same => n,nocdr()
		same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
		same => n,NoOp(connid = ${connid})
		same => n,MYSQL(Query resultid ${connid} update sigame set status=0)
		same => n,MYSQL(Disconnect ${connid})
		same => n,playback(sigame_desativado)
		same => n,goto(sigame,s,1)
exten  => sigame_consulta,1,NooP(Consulta Siga-me)
		same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
		same => n,NoOp(connid = ${connid})
		same => n,MYSQL(Query resultid ${connid} SELECT status FROM sigame)
		same => n,NoOp(resultid = ${resultid})
		same => n,MYSQL(Fetch fetchid ${resultid} status)
		same => n,NoOp(Variabili = ${fetchid},${status})
		same => n,MYSQL(Clear ${resultid})
		same => n,MYSQL(Disconnect ${connid})
		same => n,noop(Sigame esta com valor --> ${status})


		same => n,GotoIf($["${status}" = "1" ]?sigame_ativo2)
		same => n,GotoIf($["${status}" = "0" ]?sigame_desativado2)
			same => n(sigame_ativo2),NooP(Siga-me esta ativado)
			same => n,nocdr()
			same => n,playback(sigame_ativado2)
			same => n,goto(sigame,s,1)
	same => n(sigame_desativado2),NooP(Siga-me esta desativado)
			same => n,nocdr()
			same => n,playback(sigame_desativado2)
			same => n,goto(sigame,s,1)

[recebe_chamadas]
exten => s,1,Answer(1)
	same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
	same => n,NoOp(connid = ${connid})
	same => n,MYSQL(Query resultid ${connid} SELECT status FROM sigame)
	same => n,NoOp(resultid = ${resultid})
	same => n,MYSQL(Fetch fetchid ${resultid} status)
	same => n,NoOp(Variabili = ${fetchid},${status})
	same => n,MYSQL(Clear ${resultid})
	same => n,MYSQL(Disconnect ${connid})
	same => n,noop(Sigame esta com valor --> ${status})

	  same => n,GotoIf($["${status}" = "1" ]?sigame_ativo)
	  same => n,GotoIf($["${status}" = "0" ]?sigame_desativado)
	  
	  same => n(sigame_ativo),NooP(Siga-me esta ativado)
	  
		same => n,Set(CDR(userfield)=SIGA-ME)
		same => n,Set(CDR(original_dst)=SP VIA SIP)
		same => n,nocdr()
		same => n,playback(conectado)
		same => n,Dial(SIP/10600001366/101&SIP/10600001366/102&SIP/10600001366/103,120,r)
		same => n,Goto(${DIALSTATUS})
			same => n(CONGESTION),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup
			same => n(busy/congestion),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup
			same => n(CHANUNAVAIL),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup
			same => n(BUSY),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup

	  same => n(sigame_desativado),NooP(Siga-me esta desativado)
			same => n,Set(CDR(userfield)=Lig. Recebida)
			;same => n,playback(Conectado)
			same => n,Set(CDR(original_dst)=Ramal 201)
			same => n,Dial(SIP/201,22,Tt)
			same => n,Set(CDR(original_dst)=Ramal 202)
			same => n,Dial(SIP/202,90,Tt)
			;same => n,Queue(Fila,tT,,,600)
			same => n,hangup()


	

Pode-se usar a imaginação para manipular via interface web

Hairpin NAT Reflection mode for port forwards – iptables solution

A.A.A.A is your real ip

iptables -t nat -A PREROUTING -d A.A.A.A -j DNAT --to-destination 192.168.1.200
iptables -t nat -A POSTROUTING -d 192.168.1.200 -s 192.168.1.0/24 -j SNAT --to-source 192.168.1.1

Hairpin nat mikrotik – Acesso na intranet não funciona com direcionamento de portas

by https://wiki.mikrotik.com/wiki/Hairpin_NAT

Hairpin NAT
In the below network topology a web server behind a router is on private IP address space, and the router performs NAT to forward traffic to its public IP address to the web server behind it.

The NAT configuration would look like below:

/ip firewall nat
add chain=dstnat dst-address=1.1.1.1 protocol=tcp dst-port=80 \
action=dst-nat to-address=192.168.1.2
add chain=srcnat out-interface=WAN action=masquerade
When a client out on the Internet with IP address 2.2.2.2 establishes a connection to the web server, the router performs NAT as configured.

the client sends a packet with a source IP address of 2.2.2.2 to a destination IP address of 1.1.1.1 on port tcp/80 to request some web resource.
the router destination NATs the packet to 192.168.1.2 and replaces the destination IP address in the packet accordingly. The source IP address stays the same: 2.2.2.2.
the server replies to the client’s request and the reply packet has a source IP address of 192.168.1.2 and a destination IP address of 2.2.2.2.
the router determines that the packet is part of a previous connection and undoes the destination NAT, and puts the original destination IP address into the source IP address field. The destination IP address is 2.2.2.2, and the source IP address is 1.1.1.1.
The client receives the reply packet it expects, and the connection is established.

When a client on the same internal network as the web server requests a connection to the web server’s public IP address, the connection breaks.

the client sends a packet with a source IP address of 192.168.1.10 to a destination IP address of 1.1.1.1 on port tcp/80 to request some web resource.
the router destination NATs the packet to 192.168.1.2 and replaces the destination IP address in the packet accordingly. The source IP address stays the same: 192.168.1.10.
the server replies to the client’s request. However, the source IP address of the request is on the same subnet as the web server. The web server does not send the reply back to the router, but sends it back directly to 192.168.1.10 with a source IP address in the reply of 192.168.1.2.
The client receives the reply packet, but it discards it because it expects a packet back from 1.1.1.1, and not from 192.168.1.2. As far as the client is concerned the packet is invalid and not related to any connection the client previously attempted to establish.

To fix the issue, an additional NAT rule needs to be introduced on the router to enforce that all reply traffic flows through the router, despite the client and server being on the same subnet. The rule below is very specific to only apply to the traffic that the issue could occur with – if there are many servers the issue occurs with, the rule could be made broader to save having one such exception per forwarded service.

/ip firewall nat
add chain=srcnat src-address=192.168.1.0/24 \
dst-address=192.168.1.2 protocol=tcp dst-port=80 \
out-interface=LAN action=masquerade
Hairpin nat 4.png

With that additional rule, the flow now changes:

the client sends a packet with a source IP address of 192.168.1.10 to a destination IP address of 1.1.1.1 on port tcp/80 to request some web resource.
the router destination NATs the packet to 192.168.1.2 and replaces the destination IP address in the packet accordingly. It also source NATs the packet and replaces the source IP address in the packet with the IP address on its LAN interface. The destination IP address is 192.168.1.2, and the source IP address is 192.168.1.1.
the web server replies to the request and sends the reply with a source IP address of 192.168.1.2 back to the router’s LAN interface IP address of 192.168.1.1.
the router determines that the packet is part of a previous connection and undoes both the source and destination NAT, and puts the original destination IP address of 1.1.1.1 into the source IP address field, and the original source IP address of 192.168.1.10 into the destination IP address field.
The client receives the reply packet it expects, and the connection is established.

However, the web server only ever sees a source IP address of 192.168.1.1 for all requests from internal clients regardless of the internal client’s real IP address. There is no way to avoid this without either using a router that can do application level DNS inspection and can rewrite A records accordingly, or a split DNS server that serves the internal clients the internal server IP address and external clients the external server IP address.

This is called – among other terms – hair pin NAT because the traffic flow has clients enter the router through the same interface it leaves through, which when drawn looks like a hair pin.

Firebird 1.5 no Windows 10 – Restaurando após atualização que o removeu

por Daniel Pozzebon

Copiar a pasta Firebird 1.5 de uma instalação do firebird 1.5
Deixando a mesma estrutura:
C:\\Program Files (x86)\\Firebird\\Firebird_1_5 (e seus respectivos arquivos)
ou
depois que o windows é atualizado a pasta é movida para C:\\Windows.old\\Program Files (x86)

É só copiar novamente a pasta C:\\Program Files (x86)\\Firebird\\Firebird_1_5

Depois executando o CMD (Prompt do DOS) como administrador realizar os seguintes passos:
Estando no diretório bin do Firebird, devemos instalar o serviço e depois colocá-lo em
execução:
Digite: instsvc i –s –a –g
(este comando cria o serviço do Firebird no Windows.)
instsvc sta (Inicia o serviço)

E por último copiar a DLL GDS32.DLL para a pasta C:\\Windows\\Windows\\SysWOW64
Que também foi movida para C:\\Windows.old\\Windows\\SysWOW64.

Montar volume LVM como slave em linux. ERRO “UNKNOWN FILESYSTEM TYPE ‘LVM2_MEMBER'” –

Por Gabriel Fernande em vivaolinux.com.br

Se você tiver mais de uma distro instalada com discos LVMs e desejar ler o conteúdo da partição LVM da outra versão Linux instalada ou até mesmo para simplesmente ler informações de qualquer HD com partições LVM na sua distro atual, provavelmente você tentaria montar a partição com um comando parecido com este:

# mount /dev/sda1 /media/tmp 

Pois é, eu também fiz isto e me deparei com o tal “unknown filesystem type ‘LVM2_member'”.

Para montarmos estes tipos de volumes lógicos, sem alterar qualquer volume lógico e manter funcionando a outra instalação, devemos seguir algumas simples etapas, segue (use usuário root).

Digite o comando no console:

# pvs 

O comando acima deve ter uma saída parecida com esta, exibindo todos os grupos de volumes configurados:

  PV         VG           Fmt  Attr PSize  PFree
  /dev/sda2  vg_fernandes lvm2 a-   74,33G    0 
  /dev/sdb3  vg_fernandex lvm2 a-   74,63G    0

No meu caso o Grupo de Volume (VG – volume group) da minha outra instalação Linux é o vg_fernandex configurado no Volume Físico (PV – physical volume) em /dev/sdb3.

Agora que sabemos que nosso Grupo de Volume é vg_fernandex, utilizaremos o comando abaixo para listar os Volumes Lógicos (LV – logical volumes). Digite o comando no console:

# lvdisplay vg_fernandex 

Este comando deve ter uma saída próxima a esta abaixo, exibindo todos os Volumes Lógicos e suas propriedades:

  --- Logical volume ---
  LV Name                /dev/vg_fernandex/lv_root
  VG Name                vg_fernandex
  LV UUID                4ZjsBJ-VnKQ-xAN3-O0x7-PD1W-Itc4-1q5pZ0
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                69,72 GB
  Current LE             17849
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/vg_fernandex/lv_swap
  VG Name                vg_fernandex
  LV UUID                aCjfhN-rUi3-uy0n-fXEW-TKNG-pit3-f0IYYV
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                4,91 GB
  Current LE             1256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

Neste caso o Volume Lógico que desejamos montar é o /dev/vg_fernandex/lv_root, para isto vamos executar mais um comando:

# mount /dev/vg_fernandex/lv_root /media/outro_hd 

* (/media/outro_hd: não esqueça de criar este ou outro diretório para o destino da montagem antes de efetuar o comando)

Feito, agora seu hd está disponível na sua outra instalação Linux, sem que qualquer configuração do LVM seja alterada.