quinta-feira, 18 de agosto de 2022

Dicas Asterisk

 DICAS ASTERISK - Comandos úteis e arquivos de configuração


O Asterisk é um framework GPL (Gnu Public License), e atualmente a maior plataforma de telefonia IP do mundo. A Lojamundi é especialista em soluções baseadas em Asterisk. Por ser mais que uma central telefônica, você pode encontrar o Asterisk sendo utilizado em portões, câmeras, automação residencial e empresarial em possibilidades quase que infinitas. Tudo depende do conhecimento aplicado e da necessidade a ser suprida. 


Como também somos entusiastas dessa plataforma há mais de 15 anos, vamos apresentar neste artigo alguns comando úteis e arquivos de configuração que podem ser utilizados para gerenciar sua central.


Já conhece nossa consultoria especializada em Telefonia IP


Saiba o que podemos fazer pela telefonia da sua empresa.



INICIAR E PARA O ASTERISK

asterisk

Arrancar o Asterisk

asterisk -c

Iniciar o Asterisk e abrir o console (CLI)

asterisk -r

Ingressar no console remoto

asterisk -rx ‘comando’

Executar o comando sem ingressar no console

stop now

Parar o servidor Asterisk - executado dentro da CLI

stop gracefully

Para o serviço do Asterisk quando todos os canais ativos estiverem ocupados

stop when convenient

Parar o serviço do Asterisk assim que não tiverem mais chamadas ativas. Aceita uma nova chamada

exit 

Sai do console remoto, sem parar o Asterisk




COMANDOS IMPORTANTES - CLI

Set verbose 9

Aumenta a verbose no CLI

Set debug

Aciona o modo debug no CLI

sip show peers

Listar todas contas SIP’s do Asterisk

sip show channels

Listar todos os canais e conexões ativos




AJUDA DENTRO DO CLI

help

Mostrar uma lista de comandos utilizados

help sip

Mostrar uma lista de funcionalidades para o arquivo 

help sip show

Mostrar as opções de visualização do comando sip show

help sip show peers

Mostrar a visão do comando sip show peers


REGEX: vem do termo em inglês regular expression (expressão regular). Uma forma de identificar formas, palavras e padrões de caracteres.

REGEX E EXTENSIONS.CONF

X

Dígitos entre 0-9

Z

Dígitos entre 1-9

N

Dígitos entre 2-9

[5-7]

Dígitos 5,6 e 7

[15-7]

Dígitos 1, 5,6 e 7

.

Qualquer valor numérico ou caracter



EXTENSIONS.CONF

[general]

Configurações gerais do plano de discagem

static=yes

Configuração estática

writeprotect=yes

Não permite alterações do plano de discagem sejam realizadas a partir do console (CLI)

[globals]

Seção de variáveis

VAR2=23

Atribuir valor a uma variável global

[name]

Define um nome contexto. Poderíamos utilizar um contexto chamado de [from-internal] ou simplesmente [joao] 

setGlobal(VAR1=1)

Seta a variável global VAR1 com o valor 1

set(VAR3=Test)

Seta uma variável de canal. Utilizada no plano de discagem corrente

dial(tech/u:p@host)

Conecta com um host / usuário usando um canal

answer()

Abre um canal

hangup()

Encerra um canal

wait(n)

Espera por n segundos

goto(n)

Salta de uma prioridade n na mesma extensão. Goto(100,12) aqui o salto é para extensão e prioridade 12.

gotoif($[ ${X}=1 ]?,1:5)

Salta para prioridade 1 se a variável X for igual a 1. Caso contrário salta para prioridade 5 da extensão

gotoiftime(9:00-17:00|monfri|1-31|*?dia,s,1)

Salta para o contexto dia na extensão s , prioridade 1 caso seja entre 9h:00 e 17h:00. De segunda a sexta.

saynumber()

Nomear um número

sayalpha()

Nomear uma string

saydigits()

Nomear os dígitos

sayunixtime()

Nome data/hora do servidor

voicemail()

Conectar uma chamada ao correio de voz. Utilizar as opções u: unavailble, b: busy e s: gravação

voicemailmain()

Conectar um usuário ao menu principal do sistema de correio de voz 



DIRETÓRIOS E ARQUIVOS

/etc/asterisk

Contém todos os arquivos de configuração

/etc/asterisk/extensions.conf

Arquivo de configuração do plano de discagem

/etc/asterisk/sip.conf

Arquivo de configuração dos canais SIP

/etc/asterisk/iax.conf

Arquivo de configuração dos canais IAX

/etc/asterisk/voicemail.conf

Arquivo de configuração do correios de voz

/usr/lib/asterisk/modules

Contém as bibliotecas, aplicações e módulos

/var/run/asterisk

Contém os dados dos processos

/var/lib/asterisk/sounds

Contém os arquivos de áudio do Asterisk

/var/log/asterisk

Contém os arquivos de registro / logs do Asterisk

/var/spool/asterisk

Contém os arquivos das chamadas



terça-feira, 19 de abril de 2022

segunda-feira, 4 de abril de 2022

Apache com senha

 When setting up a web server, there are often sections of the site that you wish to restrict access to. Web applications often provide their own authentication and authorization methods, but the web server itself can be used to restrict access if these are inadequate or unavailable.


In this guide, we’ll demonstrate how to password protect assets on an Apache web server running on Ubuntu 14.04.


Prerequisites

To get started, you will need access to an Ubuntu 14.04 server environment. You will need a non-root user with sudo privileges in order to perform administrative tasks. To learn how to create such a user, follow our Ubuntu 14.04 initial server setup guide.


Install the Apache Utilities Package

In order to create the file that will store the passwords needed to access our restricted content, we will use a utility called htpasswd. This is found in the apache2-utils package within the Ubuntu repositories.


Update the local package cache and install the package by typing this command. We will take this opportunity to also grab the Apache2 server in case it is not yet installed on the server:


sudo apt-get update

sudo apt-get install apache2 apache2-utils


Create the Password File

We now have access to the htpasswd command. We can use this to create a password file that Apache can use to authenticate users. We will create a hidden file for this purpose called .htpasswd within our /etc/apache2 configuration directory.


The first time we use this utility, we need to add the -c option to create the specified file. We specify a username (sammy in this example) at the end of the command to create a new entry within the file:


sudo htpasswd -c /etc/apache2/.htpasswd sammy


You will be asked to supply and confirm a password for the user.


Leave out the -c argument for any additional users you wish to add:


sudo htpasswd /etc/apache2/.htpasswd another_user


If we view the contents of the file, we can see the username and the encrypted password for each record:


cat /etc/apache2/.htpasswd


Output

sammy:$apr1$lzxsIfXG$tmCvCfb49vpPFwKGVsuYz.

another_user:$apr1$p1E9MeAf$kiAhneUwr.MhAE2kKGYHK.

Configure Apache Password Authentication

Now that we have a file with our users and passwords in a format that Apache can read, we need to configure Apache to check this file before serving our protected content. We can do this in two different ways.


The first option is to edit the Apache configuration and add our password protection to the virtual host file. This will generally give better performance because it avoids the expense of reading distributed configuration files. If you have this option, this method is recommended.


If you do not have the ability to modify the virtual host file (or if you are already using .htaccess files for other purposes), you can restrict access using an .htaccessfile. Apache uses.htaccess` files in order to allow certain configuration items to be set within a file in a content directory. The disadvantage is that Apache has to re-read these files on every request that involves the directory, which can impact performance.


Choose the option that best suits your needs below.


Configuring Access Control within the Virtual Host Definition

Begin by opening up the virtual host file that you wish to add a restriction to. For our example, we’ll be using the 000-default.conf file that holds the default virtual host installed through Ubuntu’s apache package:


sudo nano /etc/apache2/sites-enabled/000-default.conf


Inside, with the comments stripped, the file should look similar to this:


/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Authentication is done on a per-directory basis. To set up authentication, you will need to target the directory you wish to restrict with a <Directory ___> block. In our example, we’ll restrict the entire document root, but you can modify this listing to only target a specific directory within the web space:


/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined


    <Directory "/var/www/html">

    </Directory>

</VirtualHost>

Within this directory block, specify that we wish to set up Basic authentication. For the AuthName, choose a realm name that will be displayed to the user when prompting for credentials. Use the AuthUserFile directive to point Apache to the password file we created. Finally, we will require a valid-user to access this resource, which means anyone who can verify their identity with a password will be allowed in:


/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined


    <Directory "/var/www/html">

        AuthType Basic

        AuthName "Restricted Content"

        AuthUserFile /etc/apache2/.htpasswd

        Require valid-user

    </Directory>

</VirtualHost>

Save and close the file when you are finished. Restart Apache to implement your password policy:


sudo service apache2 restart


The directory you specified should now be password protected.


Configuring Access Control with .htaccess Files

If you wish to set up password protection using .htaccess files instead, you should begin by editing the main Apache configuration file to allow .htaccess files:


sudo nano /etc/apache2/apache2.conf


Find the <Directory> block for the /var/www directory that holds the document root. Turn on .htaccess processing by changing the AllowOverride directive within that block from “None” to “All”:


/etc/apache2/apache2.conf

. . .


<Directory /var/www/>

    Options Indexes FollowSymLinks

    AllowOverride All

    Require all granted

</Directory>


. . .

Save and close the file when you are finished.


Next, we need to add an .htaccess file to the directory we wish to restrict. In our demonstration, we’ll restrict the entire document root (the entire website) which is based at /var/www/html, but you can place this file in any directory you wish to restrict access to:


sudo nano /var/www/html/.htaccess


Within this file, specify that we wish to set up Basic authentication. For the AuthName, choose a realm name that will be displayed to the user when prompting for credentials. Use the AuthUserFile directive to point Apache to the password file we created. Finally, we will require a valid-user to access this resource, which means anyone who can verify their identity with a password will be allowed in:


/var/www/html/.htaccess

AuthType Basic

AuthName "Restricted Content"

AuthUserFile /etc/apache2/.htpasswd

Require valid-user

Save and close the file. Restart the web server to password protect all content in or below the directory with the .htaccess file:


sudo service apache2 restart


Confirm the Password Authentication

To confirm that your content is protected, try to access your restricted content in a web browser. You should be presented with a username and password prompt that looks like this:


[Image: Apache2 password prompt]


If you enter the correct credentials, you will be allowed to access the content. If you enter the wrong credentials or hit “Cancel”, you will see the “Unauthorized” error page:


[Image: Apache2 unauthorized error]


Conclusion

You should now have everything you need to set up basic authentication for your site. Keep in mind that password protection should be combined with SSL encryption so that your credentials are not sent to the server in plain text. To learn how to create a self-signed SSL certificate to use with Apache, follow this guide. To learn how to install a commercial certificate, follow this guide.

RECOVER SENHA UBUNTU