how to add two sip account in pjsip.conf and configure dialplan in extensions.conf

in extensions , add :

 

after configuration , you can register both 6001 and 7001  on your two mobiles ,use 6001 to call 7001  and talk success

a project of TB+radius+asterisk+tiny radius + sql server

  • Telco bridge radious full dictionary :

https://docs.telcobridges.com/tbwiki/Toolpack:RADIUS_CDR_attributes_C

should follow above site ‘s content change tiny-radius ‘s default_dictionary 

once change done ,  you can modify TestClient.java  to check if modify effect  ,

use code like this :

 

  •  tiny radius ‘s request timeout  is in RadiusClient.java

 

during tesing , temp change it to 10 seconds 

How to use sql server jdbc in java application (for win 10)

  •  download  “Microsoft JDBC Driver 6.0 for SQL Server”  from this site :

https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

 

  • 解压后,到这个目录          sqljdbc_6.0.8112.200_enu.tar\sqljdbc_6.0.8112.200_enu\sqljdbc_6.0\enu\jre8

用 command line 执行 :


这是因为maven没有sqljdbc的repository , 必须手动把 sqljdbc42.jar 加到本地的maven repository

此方法来源于 :

https://stackoverflow.com/questions/19537396/missing-artifact-com-microsoft-sqlserversqljdbc4jar4-0

执行成功的标志是: 可以在本地maven repository 看到 sqljdbc

 

  • 然后 ,在 maven 的pom.xml 文件加入dependency

 

  • 需要用到 sql server 时 ,加这句即可

 

  • 各种调用的例子, 包括直接执行sql语句,调用store procedure (带输入和输出参数) , 见这个网址, 例子比较全

https://programmaticponderings.com/2012/08/24/calling-sql-server-stored-procedures-with-java-using-jdbc

 

 


如果要持续的调用sql sp , 就不能每一次都新建connection , 要使用 connection pool  ,  选用 apache 的 dbcp 库 

 

  • 如何引用:  在 pom.xml 加

 

  • 在 package 新建 DataSource.java 文件

 

  • try to call a sp with one input and output parameter

 

from running , you can find when the second trying ,  this code

is much more faster  than the first time .

  •  apache dbcp 的例子见

https://www.javatips.net/blog/dbcp-connection-pooling-example

 

  • basicDataSource 是否已包含pool的特性 ?  已有, 详细解释见:

https://stackoverflow.com/questions/14467480/connection-pooling-with-apache-dbcp

 

 

compile and run tiny radius

  •  先下载 tiny radius 源文件

TinyRadius-1.0

 

  • 打开 eclipse , 导入 现有的maven project
  • 修改 project—> property—> java build path —> libraries  与本机安装的jdk版本一致

  • 修改 pom.xml , 使其内容为 : (build部分需特别注意)

  •  maven —> run as install
  • 编译完copy到centos 6 机器
  • 在 centos 机器目录下新建 lib 目录  copy :  common-logging 1.1.1 和 log4j 1.2.17 去 lib 目录内
  • 执行

     


    如遇报错 :

     

     

    原因是maven自动生成的 MANIFEST.MF 没有 main class 信息google后,有的答案说: 应该在  pom.xml 加这段

    但是试过后还是报同样的错误 ,  继续Google, 发现可以用jar 命令加额外的 manifest 内容到maven自动生成的 jar文件里面去。

    方法是:

a)  新建文本文件 manifest.txt , 内容写:

b)   然后运行

 

‘u’ mean update ,  in this case , do not use ‘c’

  • 至此 , main class 信息终于加到了 MANIFEST.MF 文件

 

  • 附录 :

a) in centos , check file which name include “META” in jar :

 

b)  how to unzip .jar file :   use 7z  upzip

how to recombine extractd files back to .jar file :

in this case ,  folder as such condition

 

 

how centos 6 32bits install essential tools

  •  gnu c++   

 

  • apache+ mysql + php 

From :    https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6

About LAMP

LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.

Set Up

The steps in this tutorial require the user on the virtual private server to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.

Step One—Install Apache

Apache is a free open source software which runs over 50% of the world’s web servers.

To install apache, open terminal and type in this command:

Once it installs, you can start apache running on your VPS:

That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://12.34.56.789). The page should display the words “It works!” like this.

How to find your Server’s IP address

You can run the following command to reveal your server’s IP address.

Step Two—Install MySQL

MySQL is a powerful database management system used for organizing and retrieving data on a virtual server

To install MySQL, open terminal and type in these commands:

During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install.

Once it is done installing, you can set a root MySQL password:

The prompt will ask you for your current root password.

Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.

Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

Step Three—Install PHP

PHP is an open source web scripting language that is widely used to build dynamic webpages.

To install PHP on your virtual private server, open terminal and type in this command:

Once you answer yes to the PHP prompt, PHP will be installed.

PHP Modules

PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:

Terminal then will display the list of possible modules. The beginning looks like this:

To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.

Once you decide to install the module, type:

You can install multiple libraries at once by separating the name of each module with a space.

Congratulations! You now have LAMP stack on your droplet!

We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):

Step Four—RESULTS: See PHP on your Server

Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:

Add in the following line:

Then Save and Exit.

Restart apache so that all of the changes take effect on your virtual server:

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php

It should look similar to this.

 

  •  supervisor

after install ,  use this command to check if success and version

 

supervisor 是一个C/S 的管理工具, 所以要先启动 supervisord , 这个是服务端 。

—————————–

然后, 打开 /etc/supervisord.conf 文件 ,  在 supervisorctl 这个section  之后加入要管理的程序名称,路径等。

复制代码

因为改了 conf 文件, 所以还要执行

—————————–

对于 run.sh , 首先要给执行权限

内容开头不要忘了加上  shebang , 否则会引起这个错误

run.sh的全文是

—————————–

最后执行客户端 supervisorctl

在 supervisorctl 环境下 ,执行

 

 

如果没正常启动, 可以在 supervisorctl 环境下用这个命令看启动日志


 

Linux funcs list which can be used in c program

 

 

 

FuncName

func name require inc example explain
geteuid() int i =geteuid();  geteuid就是get essensial user id,获取有效用户id。每一个用户都有一个id,root用户id为0,普通用户id为1000以上。
 getpid()  int i =getpid()  返回当前进程ID

how to config pjsip.conf to accept zoiper call for asterisk 13

Very important , since asterisk 12 ,  use chan_pjsip  instead of chan_sip module 

  • config file location   : /etc/asterisk/pjsip.conf

/////////////////////*******************   此部分为旧方法 ,asterisk 12 之前用

make a copy of sip.conf   :

mv /etc/asterisk/sip.conf /etc/asterisk/sip.conf.ori

make a new sip.conf

[general]
context=internal
allowguest=no
allowoverlap=no
bindport=5060
srvlookup=no
disallow=all
allow=ulaw
alwaysauthreject=yes
canreinvite=no
nat=yes
session-timers=refuse
localnet=192.168.1.0/255.255.255.0


[7001]
type=friend
host=dynamic
secret=*****
context=internal


[7002]
type=friend
host=dynamic
secret=*****
context=internal

make a backup file of extensions :

mv /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.ori

/////////////////////*******************   此部分为旧方法 ,asterisk 12 之前用

 

  • 把 pjsip.conf 的以下代码取消注释


[transport-udp]
type=transport
protocol=udp ;udp,tcp,tls,ws,wss
bind=0.0.0.0


[6001]
type=endpoint
transport=transport-udp
context=from-internal
disallow=all
allow=ulaw
allow=gsm
auth=6001
aors=6001


[6001]
type=auth
auth_type=userpass
password=************
username=6001


[6001]
type=aor
max_contacts=1
;contact=sip:6001@192.0.2.1:5060

 

然后重启 aterisk :   /etc/init.d/asterisk restart

查状态 : /etc/init.d/asterisk status

如果显示: asterisk (pid ***) is running…     即为正常

此时, 就可以用zoiper 登陆到asterisk

 

参考资料 :

https://wiki.asterisk.org/wiki/display/AST/res_pjsip+Configuration+Examples

https://wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip

https://wiki.asterisk.org/wiki/display/AST/Configuring+res_pjsip

 

asterisk 所有加载的module 都存在 /usr/lib/asterisk/modules

自带的prompt 在  :  /var/lib/asterisk/sounds/en

asterisk -rvvv 开启 cli 调试模式

 

asterisk + google voice : https://hobbiesbytwinclouds.wordpress.com/2017/01/23/set-up-a-google-voice-telephone-server-based-on-asterisk-pbx-in-15-minutes/


如何播一个prompt ? 

 

编辑 extensions.conf

添加:

session name [from-internal] 要与上文 6001 的名字相同

这几句的意思是 , 当有注册进来的号码拨打 7001 时 , 先 answer , 再 播一段prompt , prompt 的名字叫 : cancelled , 播完挂断。


 

how to make two zoiper talk to each other 

https://stackoverflow.com/questions/31959287/asterisk-13-hangup-both-sip-channels-when-bridge-is-destroyed

 

dialplan basic tutorial :

http://www.softpanorama.org/Multimedia/Voip/Asterisk/dialplan_basics.shtml

 

solution is  :   edit extensions.conf

add:

 


 

how to  call to real mobile number ? 

 

需要 可用的 sip trunk  ,  并在 asterisk 配置

 

 


国内对asterisk二次开发的软件:  asterCC

 

how to decode and encode from .g729 file

how to decode :

 

从 http://downloads.asterisk.org/pub/telephony/sounds/releases/   

下载 .g729 文件


解压后 , 下载 ffmpeg 的最新版本  ffmpeg-20180507-29eb1c5-win64-static , 这个是不用安装的


在 command line 进入 ffmpeg的bin目录, 执行

ffmpeg.exe -i “vm-message.g729” “vm729ToWav.wav”

即可将 g729文件解码为wav 文件, 并可以在 windows media player 播放。

———————————————————————————————–

how to encode :

 

到这个网址 :

https://www.digium.com/products/ivr/audio-converter

按图中选择

 

注意源文件尽量要小, 我是把MP3剪切出1分钟,再用格式工厂转换为rate = 11025 的单声道 , 最终wav文件大小为 1.3 M

点 convert 即可完成编码为 g729

 

 

 

 

 

 

 

 

 

(Copy) install asterisk on centos 6 32bit

Copy From  :

http://asteriskpro.blogspot.com/2017/07/how-to-install-asterisk-13-and- pjsip-on.html

上地址已失效, 现改为

How to Install Asterisk 13 and PJSIP on CentOS 6

Step 1 – Setup the environment

The first step is to install the dependencies required to build the PJSIP libraries and Asterisk 13. Using the CentOS yum package manager we’ll update all currently installed packages to their latest version and then install some of the most common dependencies for Asterisk and PJSIP.
PJSIP 已经取代 SIP 成为默认模块, SIP 转移到 extended support

The kernel-devel package we install next could be slightly ahead of the kernel actually in use on your system. This is why we did a yum update first. If the kernel has been updated, be sure to reboot before moving forward. More information about the kernel-devel packages available for CentOS can be found here. The following command will install several packages that are needed to compile and install PJSIP and Asterisk.

NOTE:If you encounter an issue resolving the dependencies check out the fantastic install_prereq tool shipped with the Asterisk tarball. Located in the contrib/scripts directory of the Asterisk source directory that will be unpacked in step 3.

Step 2 – Install pjproject

Next you will download and install the pjproject sip library directly from pjsip.org. But first we’ll change directories to work in the /usr/src directory.

This will create the pjproject-2.3 directory. Change to this directory and run the following set of commands to build and install the pjproject sip library.

This command must be modified when using a 32-bit operating system. Just remove the --libdir=/usr/lib64option from the command. The other options may be different depending on how you want to use Asterisk. More information about these options can be found on the Asterisk wiki or by running the command ./configure --help. The next four commands will build, install and link the pjsip libraries.

And finally this next command will verify the pjsip libraries have been dynamically linked.

Your output should look something like this:
pjsip-liblink

Step 3 – Install Asterisk 13

Now we’ll download and install the latest Certified-Asterisk 13.1 branch from source. First we’ll change directory up one level to /usr/src.

Then we’ll use the wget command to download the tarball from downloads.asterisk.org.

(注 :in 2018 -5- 8 , 实际可下载的文件已经改为了 
asterisk-certified-13.18-current.tar.gz  , 下文中的 certified-asterisk-13.1-certified  也应该用 
asterisk-certified-13.18-cert3  替代   )
Next the tar command will unpack the Asterisk source code into a new directory named certified-asterisk-13.1-certified. Then we’ll go to the new directory.

The next set of commands will build and install Asterisk. Remember to skip the --libdir=/usr/lib64 option for 32-bit versions of CentOS. In that case just run the command ./configure.

Next you will run the make menuselect command. This step will verify if the pjsip channel driver dependencies have been successfully installed.

Use the arrow keys to navigate to “Resource Modules” in the left column, about halfway down the list. Press the right arrow key and then scroll down until you see the list of modules beginning with “res_pjsip_”. If these modules have “XXX” to the left of their name then the dependencies have not been met. You’ll need to go back to the /usr/src/pjproject directory, run the “make distclean” command and start over carefully looking for any error messages and proceed from there. If you see [*] instead of XXX then the res_pjsip module’s dependencies have been met and you can proceed to the next steps. Your menuselect screen should look like this:
menuselect-pjsip
(注: 因为是 putty 登陆, 图形界面看不到 , 直接运行的 ./configure  ,
发现缺少 jansson 库 , 显示 
asterisk configure: error: *** JSON support not found
去 /usr/src
执行: wget http://www.digip.org/jansson/releases/jansson-2.5.tar.gz
              tar -zxf jansson-2.5.tar.gz
              cd jansson*

          ldconfig

再回到 asterisk 目录下 :    ./configure     )

If you want Asterisk to start at boot time use the following command to setup the Asterisk service.

And finally, run the command “service asterisk start” to immediately begin the Asterisk service without the need to reboot first. Now you’re ready to begin configuring the PJSIP channel driver on your freshly installed instance of Asterisk 13. If you run into an issue with these instructions feel free to leave a comment on this post, check the official Asterisk forums or reach out to the Asterisk community for help.

 


如何看asterisk service 的状态 :

去 /usr/src/asterisk-certified-13.18-cert3 目录下,执行:

不限制目录, 哪里执行都可以

/etc/init.d/asterisk status

重启是 :  /etc/init.d/asterisk restart

启动 /etc/init.d/asterisk start

停止 /etc/init.d/asterisk stop

 


安装后遇到的问题 :

当执行 /etc/init.d/asterisk status 时, 显示:  asterisk dead but subsys locked

如果去 /usr/sbin , 执行 ./asterisk -vvvc , 会显示:

asteriskerror while loading shared librarieslibjansson.so.4: cannot open shared object file: No such file or directory.

 

这是因为 asterisk 找不到 jansson 的 so 文件 。

解决办法是 :  先找 libjansson.so.4 在哪  , 

执行 find / -name “libjansson.so.4

结果是:

/usr/src/jansson-2.5/src/.libs/libjansson.so.4
/usr/local/lib/libjansson.so.4

所以 , 再执行 :

echo /usr/local/lib> /etc/ld.so.conf.d/asterisk.conf

最后 :

Reload shared library; run the below command.

/sbin/ldconfig

 


至此, asterisk 已经可以正常运行

执行 /etc/init.d/asterisk status , 会看到

asterisk (pid 9312) is running…

执行 ps aux | grep asterisk , 看到


root 2245 0.0 0.2 5260 2156 pts/0 S May07 0:02 /bin/sh /usr/sbin/safe_asterisk
root 9312 0.7 2.8 68360 30016 pts/0 Sl 00:25 0:05 /usr/sbin/asterisk -f -vvvg -c
root 9412 0.0 0.1 4480 2068 pts/0 S+ 00:36 0:00 grep asterisk

执行  service –status-all ,  可以看到 asterisk 也在运行 。