<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pbxer</title>
	<atom:link href="http://www.pbxer.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pbxer.com</link>
	<description>Build your own PBX</description>
	<lastBuildDate>Mon, 04 Jul 2011 15:08:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Simple shell script to block failed ssh attempts</title>
		<link>http://www.pbxer.com/simple-shell-script-to-block-failed-ssh-attempts/</link>
		<comments>http://www.pbxer.com/simple-shell-script-to-block-failed-ssh-attempts/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 15:19:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=170</guid>
		<description><![CDATA[Your pbx needs to be accessible by ssh, but it's annoying have your log files filled with failed access attempts. Here's how to block the script kiddies...]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s annoying having scripts and bots attempting to ssh into your pbx server. If you have proper passwords they don&#8217;t stand a chance of getting in, but it&#8217;s not satisfying to ignore them while they create load and clutter up your log files with failed login messages.</p>
<p>There are many tools out there to monitor and block IP addresses that repeatedly attempt to connect. My needs were:</p>
<ul>
<li>low memory (memory is precious on a VPS)</li>
<li>simple</li>
<li>customizable</li>
</ul>
<p>After wasting time installing various complicated python and perl scripts, I found a clever use of <tt><strong>awk</strong></tt> that counts matches in a log file and I put together this simple shell script:</p>
<div class="filename">scan-secure.sh</div>
<pre class="content">
#!/bin/sh

# scan /var/log/secure for ssh attempts
# use iptables to block the bad guys

# Looking for attempts on existing and non-existing users. For example:
# Nov  2 22:44:07 pbxer sshd[28318]: Failed password for root from 74.143.42.70 port 52416 ssh2
# Nov  3 00:06:57 pbxer sshd[31767]: Failed password for invalid user mat3 from 192.203.145.200 port 35841 ssh2

tail -1000 /var/log/secure | awk '/sshd/ &#038;&#038; /Failed password for/ { if (/invalid user/) try[$13]++; else try[$11]++; }
END { for (h in try) if (try[h] > 4) print h; }' |
while read ip
do
	# note: check if IP is already blocked...
	/sbin/iptables -L -n | grep $ip > /dev/null
	if [ $? -eq 0 ] ; then
		# echo "already denied ip: [$ip]" ;
		true
	else
		# echo "Subject: denying ip: $ip" | /usr/sbin/sendmail notify@email.com
		logger -p authpriv.notice "*** Blocking SSH attempt from: $ip"
		/sbin/iptables -I INPUT -s $ip -j DROP
	fi
done
</pre>
<p><tt>awk</tt> does all the <b>magic</b>. It grabs relevant lines, splits the lines into tokens, stores IP addresses in a hash  and counts how many times they were seen, and finally outputs all IP addresses that were seen more than four times.</p>
<p>For the first few days, it&#8217;s interesting to receive an email when IP addresses are banned. Add your email and comment out that line.</p>
<p>Once you&#8217;re sure that the script is working how you&#8217;d like, you can add it to cron so that it runs every few minutes. I found that every two minutes works for me.</p>
<div class="cmd">crontab -e</div>
<pre class=""># scan the secure log every 2 minutes
*/2 * * * * /root/scan-secure.sh</pre>
<p>After a few months you might find that the iptables are started to get cluttered.</p>
<div class="onlycmd">iptables -L -n</div>
<p>You can clean them out by &#8220;flushing&#8221; them.</p>
<div class="onlycmd">iptables -F</div>
<p>Now sleep tight knowing that people aren&#8217;t continually coming by to see if you locked your doors.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/simple-shell-script-to-block-failed-ssh-attempts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Asterisk Security: Use iptables to Block the Bad Guys</title>
		<link>http://www.pbxer.com/asterisk-security-use-iptables-to-block-nasty-hosts/</link>
		<comments>http://www.pbxer.com/asterisk-security-use-iptables-to-block-nasty-hosts/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 14:31:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=165</guid>
		<description><![CDATA[Having your asterisk server on the public internet saves you from dealing with NAT/firewall issues, but means you will have people wandering by and testing to see if your doors are locked. This article outlines how to block IP addresses that attempt to break into your system.
]]></description>
			<content:encoded><![CDATA[<p>Having your asterisk server on the public internet, people will try to use your phone system for free.</p>
<p>One technique is for scripts simply to look for any accounts with easy to guess usernames and passwords. It&#8217;s easy to spot these attempts in the log files. Just look for any &#8220;Fail&#8221; messages:</p>
<div class="cmd">grep &#8220;Fail&#8221; /var/log/asterisk/messages</div>
<pre class="output">[Jun 18 07:42:15] NOTICE[31682] chan_sip.c: Failed to authenticate user "MeucciSolutions" <sip:MeucciSolutions@74.55.157.130>;tag=as6f2c0dfb
[Jun 18 07:49:45] NOTICE[31682] chan_sip.c: Failed to authenticate user "MeucciSolutions" <sip:MeucciSolutions@74.55.157.130>;tag=as51af5dba
[Jun 18 09:02:47] NOTICE[31682] chan_sip.c: Failed to authenticate user "MeucciSolutions" <sip:MeucciSolutions@74.55.157.130>;tag=as3c4e5e5b
[Jun 18 09:57:09] NOTICE[31682] chan_sip.c: Failed to authenticate user "MeucciSolutions" <sip:MeucciSolutions@74.55.157.130>;tag=as22d69494
...
</pre>
<p>As you can see, some joker at 74.55.157.130 tried several times to authenticate on my server. Now, I have passwords that are not easy to guess, but still I&#8217;d prefer to block them from even getting to my asterisk server. Linux has a built-in firewall and it is possible to simply reject any packets from this IP address.</p>
<div class="onlycmd">iptables -I INPUT -s 74.55.157.130 -j DROP</div>
<p>That translates to: If any packets come from this particular IP address (source), ignore (drop) them.</p>
<p>To view (list) all the blocked IP addresses:</p>
<div class="cmd">iptables -n -L</div>
<pre class="output">Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  74.55.157.130        0.0.0.0/0</pre>
<p>This is tedious to remember, so I created a small perl script.</p>
<div class="filename">block-ip.pl</div>
<pre class="content">
#!/usr/bin/perl

# block jerks

$ip = $ARGV[0];

if ($ip == '') { print "\nUsage: $0 [IP]\n\n"; exit; } 

if ($ip !~ /\d+\.\d+\.\d+\.\d+/) { print "error: expected an IP address\n\n"; exit; }

`iptables -I INPUT -s $ip -j DROP`;

print "Future requests from ip [$ip] will be ignored.\n";
print "To view all blocked IPs: iptables -L \n";</pre>
<p><b>Be careful with using iptables. It is surprisingly easy to block your own ip address, which will lock you out of your own server!</b></p>
<p>The drawback to this approach is that you need to manually check the log file. I suggest a cronjob to scan the log files and send you an email if there are repeated attempts from a particular IP address.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/asterisk-security-use-iptables-to-block-nasty-hosts/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Recording Phone Calls</title>
		<link>http://www.pbxer.com/recording-phone-calls/</link>
		<comments>http://www.pbxer.com/recording-phone-calls/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 20:06:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Recipe]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[callmonitor]]></category>
		<category><![CDATA[callrecording]]></category>
		<category><![CDATA[pbx]]></category>
		<category><![CDATA[VOIP]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=154</guid>
		<description><![CDATA[Recording calls on a PBX is easy, since the audio is already in a digital form. This article outlines three ways to setup call recording (or "call monitoring" in asterisk-speak). ]]></description>
			<content:encoded><![CDATA[<p>Recording calls on a PBX is easy, since the audio is already in digital form. The quality is the same as what you hear, so while it&#8217;s not radio broadcast quality, it&#8217;s good enough for note taking or simply to document a call.</p>
<p>There are various commands to record calls on asterisk, but the easiest is <tt>MixMonitor</tt>. It records both sides of the conversation and then merges them together into a single wav file.</p>
<p>Below are some ways to use <tt>MixMonitor</tt> in your PBX. All of these approaches rely on the following macro in your dialplan.</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="content">
[macro-automon]
exten => s,1,Set(MONITOR_FILENAME=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)})
; exten => s,n,Playback(beep) ; optional - hear when recording starts
exten => s,n,MixMonitor(${MONITOR_FILENAME}.wav,b)
</pre>
<h3>1. Record All Calls</h3>
<p>This might be overkill &#8211; and could be dangerous/expensive/embarassing if a hacker gets into your server gets access to your business or personal phone calls. To minimize the risk, and reduce diskspace, you should remove all recorded calls that are older than a week.</p>
<p>To record you need to call the macro for all incoming and outgoing calls. Assuming you want to record all calls from the phone &#8216;aastra1&#8242;, your dialplan would look like&#8230;</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="content">
[aastra1]
exten => _XX.,1,Noop(Outbound call to: ${EXTEN})
exten => _XX.,n,Macro(automon) ; start monitor
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN})
</pre>
<p>For incoming calls, you need to call the macro before ringing the local extension with the <tt>Dial</tt> command.</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="content">
[incoming]
exten => 2,1,Noop(Dialing aastra1);
exten => 2,n,Macro(automon) ; start monitor
exten => 2,n,Dial(SIP/aastra1,20) ; 20 secs
exten => 2,n,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => 2-NOANSWER,1,Voicemail(20,us) ; If unavailable, send to voicemail w/ unavail announce
exten => 2-NOANSWER,n,Playback(vm-goodbye)
exten => 2-NOANSWER,n,Hangup
exten => 2-BUSY,1,Voicemail(${MACRO_EXTEN},bs) ; If busy, send to voicemail w/ busy announce
exten => 2-BUSY,n,Playback(vm-goodbye)
exten => 2-BUSY,n,Hangup
exten => _2-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
</pre>
<p>To clear out files that are older than 7 days, you&#8217;ll need a cronjob.</p>
<div class="cmd">crontab -l</div>
<pre class="output">
# remove old recordings at 8am
0 8 * * * /usr/bin/find /var/spool/asterisk/monitor/ -mtime +7 -exec /bin/rm '{}' \;
</pre>
<p>Note: you can edit your crontab with the command:</p>
<div class="onlycmd">crontab -e</div>
<h3>2. Record on Demand</h3>
<p>The idea is that if you want to record, you can press a key combination such as <span class="digit">*</span> <span class="digit">1</span> to start recording.</p>
<p>First, You activate the key combination in the features configuration file.</p>
<div class="excerpt">/etc/asterisk/features.conf</div>
<pre class="content">
[applicationmap]
automon =>*1,self,Macro,automon
</pre>
<p>Next, you need to set the <tt>DYNAMIC_FEATURES</tt> variable before dialing and pass the &#8216;w&#8217; or &#8216;W&#8217; option to the <tt>Dial</tt> command. (Note: <a href="http://www.voip-info.org/wiki/view/Asterisk+cmd+Dial">The documentation</a> says a capital &#8216;W&#8217; allows the caller to start monitoring and the lowercase &#8216;w&#8217; allows the callee to start monitoring. I&#8217;ve found that both &#8216;w&#8217; and &#8216;W&#8217; allow the caller to start monitoring and the callee cannot start monitoring. If you have more insight into this, I&#8217;d love to hear it.)</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="contents">
[incoming]
exten => 2,1,Noop(Dialing aastra1);
exten => 2,n,Set(DYNAMIC_FEATURES=automon) ;; enable monitoring
exten => 2,n,Dial(SIP/aastra1,20,w) ; w = callee can start monitoring ; note: doesn't work!

[aastra1]
exten => _XX.,1,Noop(Outbound call to: ${EXTEN})
exten => _XX.,n,Set(DYNAMIC_FEATURES=automon) ;; enable monitoring
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN},W) ;; W = caller can start monitoring
</pre>
<p>The main drawback to this approach is that you need to be speaking with the person before recording, so you might miss a few seconds at the start. Also, if you don&#8217;t have the beep in the automon macro, you can&#8217;t be sure if the recording is actually working unless you&#8217;re looking at the asterisk console output while talking.</p>
<h3>3. Use a dialing prefix to Trigger Recording</h3>
<p>To automatically record a call, I found that adding a prefix to the dialed number was a simple solution. All that is required is a simple modification of the dialplan to handle the prefix. (I used &#8217;00&#8242;).</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="contents">
[aastra1]
exten => _XX.,1,Noop(Normal Outbound call to: ${EXTEN}")
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN})

exten => _00X.,1,Noop(Recording outbound call to: ${EXTEN})
exten => _00X.,n,Macro(automon)
exten => _00X.,n,Dial(SIP/lesnet_peer/1${EXTEN:2},60) ; :2 = removes 00 prefix from number
exten => _00X.,n,Hangup
</pre>
<p>The recording files can all be found in <tt>/var/spool/asterisk/monitor/</tt>. For example:</p>
<div class="cmd">ls /var/spool/asterisk/monitor/</div>
<pre class="output">
20080917-120735-4165551212.wav		20080917-122353-4165551212.wav
20080917-120746-4165551212.wav		20080917-125437-4165551212.wav
</pre>
<p>Have fun. Oh, and you might want to read up on the legal issues surround recording phone calls in your area before rolling out this feature on your PBX.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/recording-phone-calls/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Finally, an elegant way to get a Distinctive Ring on the Aastra 9133i</title>
		<link>http://www.pbxer.com/finally-an-elegant-way-to-get-a-distinctive-ring-on-the-aastra-9133i/</link>
		<comments>http://www.pbxer.com/finally-an-elegant-way-to-get-a-distinctive-ring-on-the-aastra-9133i/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 18:28:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[9133i]]></category>
		<category><![CDATA[aastra]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[distinctive ring]]></category>
		<category><![CDATA[ringtones]]></category>
		<category><![CDATA[SIPAddHeader]]></category>
		<category><![CDATA[VOIP]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=145</guid>
		<description><![CDATA[A simple SIP header gives distictive rings on the Aastra 9133i without having to setup multiple lines.]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s important for phone to ring differently. Maybe you want your &#8220;work&#8221; number to sound different than your &#8220;home&#8221; number. Maybe two people share a phone and you don&#8217;t want people answering calls that aren&#8217;t for them.</p>
<p>To get distinctive rings on the Aastra 9133i, I had to use multiple lines. The phone supports up to 9 lines, but still it required having to create a SIP account for each line, and the phone had to register each of these lines. It worked, but it wasn&#8217;t particularly elegant.</p>
<p>From <a href="http://trixbox.org/forums/vendor-forums-certified/aastra-endpoints/how-change-ring-tone-based-incoming-channel">a post</a> at TrixBox forums I learned of <a href="http://www.voip-info.org/wiki/view/Asterisk+and+Aastra+Phones#PriorityAlerting">a page</a> on voip-info that explains how to get distinctive rings. (They call it &#8220;Priority Alerting&#8221;.) All that needed was the addition of an <tt>Alert-Info</tt> header using the <tt>SipAddHeader</tt> command.</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="contents">exten =&gt; 3,1,Noop(Call Bob)
exten =&gt; 3,n,Dial(SIP/aastra1,20)

exten =&gt; 4,1,Noop(Call Joe)
exten =&gt; 4,n,SIPAddHeader(Alert-Info: info=&lt;Bellcore-dr3&gt;)  ; distinctive ring!
exten =&gt; 4,n,Dial(SIP/aastra1,20)</pre>
<p>In this example, if sometime dials <span class="digit">3</span> to get Bob, the phone rings as normal. If they dial <span class="digit">4</span> to get Joe, the phone now has a noticably different ring.</p>
<p>The variables seem to change the timing of the ring tone, as opposed to the tone itself, so you still don&#8217;t have <strong>total</strong> control over the ringtone. The possible values for the <tt>info</tt> variable are:</p>
<pre>  &lt;Bellcore-dr1&gt;
  &lt;Bellcore-dr2&gt;
  &lt;Bellcore-dr3&gt;
  &lt;Bellcore-dr4&gt;
  &lt;Bellcore-dr5&gt;</pre>
<p>If the Aastra people are listening, it would be <strong>amazing</strong> if the <tt>Alert-Info</tt> command was able to select different ring tones.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/finally-an-elegant-way-to-get-a-distinctive-ring-on-the-aastra-9133i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Build Your PBX: Overview</title>
		<link>http://www.pbxer.com/build-your-pbx-overview/</link>
		<comments>http://www.pbxer.com/build-your-pbx-overview/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 15:12:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[The Basics]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=130</guid>
		<description><![CDATA[Before getting into details, it helps to have a visual overview of the system we&#8217;re building. Let&#8217;s walk through this diagram. There are couple of VOIP phones that connect to a standard router. The router is connected to the internet using a broadband connection (probably ADSL or cable) that has a minimum speed of 100kbps [...]]]></description>
			<content:encoded><![CDATA[<p>Before getting into details, it helps to have a visual overview of the system we&#8217;re building.</p>
<p><img src="http://www.pbxer.com/wp-content/uploads/2008/08/pbxer-voip-overview1.png" alt="overview of the pbx architecture" title="pbxer-voip-overview1" width="402" height="560" class="alignleft size-full wp-image-132" /></p>
<p>Let&#8217;s walk through this diagram.</p>
<p>There are couple of VOIP phones that connect to a standard router. The router is connected to the internet using a broadband connection (probably ADSL or cable) that has a minimum speed of 100kbps (kilo-bits-per-second).</p>
<p>The phones connect to our PBX which will run on a VPS (virtual private server). We&#8217;ll configure our PBX to use a VOIP provider which will allow us to make calls to regular telephones, and if our VOIP provider gives us a telephone number, we&#8217;ll also be able to receive calls from regular phones as well.</p>
<div class="clear"></div>
<p>Of course, your setup might have some slight variations. For example, you might only have one VOIP phone. Or you might have two VOIP phones at separate locations (so each would require it&#8217;s own router and broadband internet connection). We&#8217;ll be explaining configuration options (not just cut and paste configuration files) so you&#8217;ll be able to make these minor adjustments as we walk through your PBX setup.</p>
<div class="goon">
<a href="/do-you-have-what-it-takes/">PBX Preflight Checklist: Do you have what it takes?</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/build-your-pbx-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run common asterisk commands without switching to the root user</title>
		<link>http://www.pbxer.com/run-common-asterisk-commands-as-a-normal-user-account/</link>
		<comments>http://www.pbxer.com/run-common-asterisk-commands-as-a-normal-user-account/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 01:23:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=108</guid>
		<description><![CDATA[The default asterisk install requires you to switch to the root user to run asterisk commands. This post describes how to create a tiny executable that allows you to run asterisk commands as a regular user. ]]></description>
			<content:encoded><![CDATA[<p>To run an asterisk command, you need to connect to the asterisk server (as root) and type your command. For example:</p>
<pre class="cmd">asterisk -r</pre>
<div class="onlyasteriskcmd">dialplan reload</div>
<p>Now, if you were already logged in as root, you could do this in one step:</p>
<pre class="cmd">asterisk -rx "dialplan reload"</pre>
<p>Or if you were a regular user:</p>
<pre class="cmd">sudo /usr/sbin/asterisk -rx "dialplan reload"</pre>
<p>But, the big problem here is that you need to be &#8216;root&#8217; to run these commands. I don&#8217;t think it&#8217;s a bad thing to simply login as the root user (with great power comes great responsibility), but if want an asterisk command to be executed by a webserver (for example, as part of a monitoring script), then sudo&#8217;ing to root is not possible.</p>
<p>What we&#8217;ll do is create a &#8220;Set UID&#8221; executable that can only run a fixed command. &#8220;Set UID&#8221; means that the executable will run with the same permissions as owner of the executable.</p>
<p>To do this, we need to write a small C program which will run our common asterisk command. Create the following file:</p>
<div class="filename">dialplan-reload.c</div>
<pre class="contents">
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[])
{
  argv[0] = "/usr/sbin/asterisk";
  argv[1] = "-rx";
  argv[2] = "dialplan reload";

  execv(*argv, argv);

}
</pre>
<p>Now, compile the file.</p>
<pre class="cmd">gcc dialplan-reload.c -o dialplan-reload</pre>
<p>You will now have an executible that will reload the dialplan. It needs to be set so that it will run as root.</p>
<pre class="cmd">sudo chown root dialplan-reload
sudo chmod u+s dialplan-reload
</pre>
<p>Now, if you give your regular login write access to your dialplan, you can edit it without having to &#8216;sudo&#8217; or login as the root user.</p>
<p>Another useful executable views the status of all the SIP peers. Compile and set the permissions the same as the dialplan-reload command.</p>
<div class="filename">sip-show-peers.c</div>
<pre class="contents">
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[])
{
  argv[0] = "/usr/sbin/asterisk";
  argv[1] = "-rx";
  argv[2] = "sip show peers";

  execv(*argv, argv);

}
</pre>
<p>This executable will be used to help create a simple PBX monitoring tool that I&#8217;ll discuss in a future post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/run-common-asterisk-commands-as-a-normal-user-account/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Build Your PBX &#8211; Step 5: Add a VOIP provider</title>
		<link>http://www.pbxer.com/build-your-pbx-step-5-add-a-voip-provider/</link>
		<comments>http://www.pbxer.com/build-your-pbx-step-5-add-a-voip-provider/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 22:42:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Problem Solving]]></category>
		<category><![CDATA[Recipe]]></category>
		<category><![CDATA[The Basics]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=79</guid>
		<description><![CDATA[A PBX is a bit boring if you can't contact the outside world. This post will walk you through connecting to a VOIP service provider so you can make calls to regular phones and receive calls from a regular phone number.]]></description>
			<content:encoded><![CDATA[<p>To be able to make calls to regular phone numbers and receive calls, you need a VOIP provider. There are so many providers coming and going that it is hard to know who to choose.  If you want to do research yourself, an excellent resource is <a href="http://www.dslreports.com/gbu">DSL Report&#8217;s The Good The Bad and The Ugly Charts</a>. In the future, I hope to describe the pros and cons of the better service providers, but for this tutorial, I&#8217;m going to assume that you&#8217;ll be using <a href="http://www.les.net/?pbxer">Les.net</a>. They offer a pay-as-you-go plan which gives you a US phone number for $1/month or a Canadian number for $3.50/month (prices in Canadian dollars). (If you use a different VOIP provider, the instructions for the most part should apply, however but you might have to do a bit of translation and interpretation as each provider is a little bit different.)</p>
<h2>Create an Account</h2>
<p>Les.net uses a pay-as-you-go model, so you need to <a href="http://www.les.net/signup.php?ref=pbxer">create an account</a> and add a few dollars to get started. Assuming you have a <strong>verified</strong> Paypal account, your payment is immediately added to your account. (If you don&#8217;t have to a verified account, you have to wait 14 days.) It&#8217;s possible to pay with a normal credit card, but this involves printing and faxing an application, so I never bothered with that. You are responsible for any payment fees, which usually is in the 3% range. Also, if you are in Canada, GST will be charged. This means that if you add $10 to your account, the actual amount added is a bit less.  The payment system at Les.net is by far the most difficult part of the whole process. Once you get some money is your account, you are given all the necessary tools to select a phone number and configure your account.</p>
<h2>Get a Phone Number</h2>
<p>If you want people to call your PBX from anywhere, you need a number. This is called a <span class="acronyn" title="direct inward dialing">DID</span>, and you can hopefully get one for the area code you need. Or you can get a Toll-free number.  <img class="alignnone size-full wp-image-83" title="Les.net Order DID" src="http://www.pbxer.com/wp-content/uploads/2008/08/les-net-order-did.gif" alt="" width="420" height="144" /> If you just want to make calls, and don&#8217;t want people to be able to call you, you can save some money and skip the DID.</p>
<h2>Create a Peer</h2>
<p>On the <strong>Peers/Trunks</strong> screen you can create a peer. The peer is a number which is essentially your username. Once you&#8217;ve created your peer, edit it. You&#8217;ll see a screen with many options. Setup the peer as follows:</p>
<pre># Les.net - Edit Peer
Peer Name:          999999     // pre-defined - this is your 'username'
Your Description    PBX        // whatever you like
Peer Technology     SIP
DTMF Mode           INFO
Error Method        Coded
Codecs              G.711

Peer Type           Registration
Peer Address                      // ignore
Password            voipsecret    // choose your own secret password!
Registered                        // ignore
Registered IP                     // ignore
Registration Expires              // ignore

Outbound CallerID                 // ignore
7-Digit Dialing                   // ignore
7-Digit Area Code Prefix          // ignore
10-Digit Dialing, Prefix 1        // ignore

Voicemail Enabled                 // unchecked
Go to voicemail after (seconds)   // ignore
Voicemail Password                // ignore
Voicemail Access Code             // ignore
Email voicemail to                // ignore</pre>
<p>Click &#8220;Save Settings&#8221; and you now have a peer.</p>
<h2>Connect DID to Peer</h2>
<p>You want incoming calls to go to this new peer. On the &#8220;Your DIDs&#8221; screen you can see all of your DID numbers. Click on your number to edit it, and set &#8220;Route to&#8221; to the new peer.</p>
<h2>Tell the PBX about the VOIP provider</h2>
<p>Now that the VOIP provider is setup, you need to tell the PBX to use the VOIP provider. First, we need the PBX to register with the VOIP provider. Second, we need to specify what happens for incoming calls from the outside world, as well as outgoing calls from your VOIP phone.</p>
<h3>Register</h3>
<p>Just as your phone registers with your PBX, your PBX registers with your VOIP provider. Under the <tt>[general]</tt> context, add the username and password in the form:</p>
<pre>register =&gt; username:password@did.voip.les.net/username</pre>
<p>Using the values from the example above,</p>
<pre>username: 999999
password: voipsecret</pre>
<p>This would look like:</p>
<div class="excerpt">/etc/asterisk/sip.conf</div>
<pre class="excerpt">[general]

register =&gt; 999999:voipsecret@did.voip.les.net/999999</pre>
<p>Now we need to define some basic parameters for this connection. Add this after the <tt>[general]</tt> context:</p>
<div class="excerpt">/etc/asterisk/sip.conf</div>
<pre class="excerpt">[lesnet_peer]
type=friend
host=did.voip.les.net
dtmfmode=auto
insecure=very
disallow=all
allow=ulaw
context=incoming ; incoming DID calls will arrive in the incoming context. see: /etc/asterisk/extensions.conf
canreinvite=no</pre>
<p>We now have defined a SIP extension called &#8220;lesnet_peer&#8221;. What does that mean? It means we can dial to the outside world. We do that in the dialplan file <tt>extensions.conf</tt></p>
<p>.</p>
<h3>Calling the Outside World</h3>
<p>We need to tell our phone what to do when we dial a phone number. So far, we&#8217;ve only told it how to dial single digits like <span class="digit">9</span> to get voicemail. If you dial a proper phone number (10-digits), we want to send that call to our VOIP provider. We need to add a rule to our dialplan.</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="excerpt">[internal-phone1] ;; calls from our VOIP phone

exten =&gt; 9,1,Answer
exten =&gt; 9,n,Wait(1)	;; wait or we lose the first syllable
exten =&gt; 9,n,VoiceMailMain(s20) ;; s=skip login, listen to msgs in box 20

exten =&gt; _XX.,1,Noop(Dialing the outside world: ${EXTEN})
exten =&gt; _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN})</pre>
<p>Asterisk supports simple pattern matching in the dialplan. (The &#8220;_&#8221; indicates it is a pattern. The &#8220;X&#8221; matches any digit, and the &#8220;.&#8221; [period] matches one or more times. So, &#8220;_XX.&#8221; matches any three digits or more.)  Reload your asterisk configuation, so these changes take effect and try calling a regular phone number.</p>
<div class="onlyasteriskcmd">reload</div>
<h3>Incoming Calls</h3>
<p>Incoming calls are also handled in <tt>extensions.conf</tt>. In <tt>sip.conf</tt> we specified that calls should come in on the &#8220;incoming&#8221; context. We need to define that context.  Incoming calls come from your DID number. If we assume our DID is &#8217;212-555-9999&#8242; we would need the following rule:</p>
<div class="excerpt">/etc/asterisk/extensions.conf</div>
<pre class="excerpt">[incoming]
exten =&gt; 2125559999,1,Noop(Incoming call from: ${CALLERID(all))
exten =&gt; 2125559999,n,Dial(SIP/phone1,20)
exten =&gt; 2125559999,n,Playback(vm-goodbye)
exten =&gt; 2125559999,n,Hangup</pre>
<p>An incoming call to your DID would simply rings your phone (for 20 seconds) and if there is no answer, the caller hears the &#8216;goodbye&#8217; recording and the call ends.</p>
<h2>Troubleshooting</h2>
<p>If things don&#8217;t work as expected, there are several places to look for error messages. First, from the asterisk console, make sure you have verbose messages on.</p>
<div class="onlyasteriskcmd">core set verbose 5</div>
<p>You should see activity on your VOIP phone as you attempt to dial a number.  Alternately, you can view the asterisk log file.</p>
<div class="cmd">tail -f /var/log/asterisk/messages</div>
<p>On the Les.net Edit Peer screen, you can see if your server is registered. The fields &#8220;Peer Address&#8221;, &#8220;Registered&#8221;, &#8220;Registered IP&#8221; and &#8220;Registration Expires&#8221; should all have relevant information. If they are empty, then asterisk has not registered with your VOIP provider.</p>
<h2>Next Steps</h2>
<p>You now have a functional PBX. It doesn&#8217;t do much at the moment, but it is a solid foundation uponw which you can start to build a phone system that works exactly how you want it to. Most of the behaviour of the phone system is controlled by the dialplan, which we will examine next.</p>
<p>Continue to: <a href="/overview-of-essential-asterisk-dialplan-commands"></a>Overview of the essential Asterisk Dialplan Commands <strong>[Sorry, still working on the dialplan article... Can I interest you in <a href="http://www.pbxer.com/recording-phone-calls/">how to record phone calls</a>?]</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/build-your-pbx-step-5-add-a-voip-provider/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Build Your PBX &#8211; Step 4: Configure your VOIP Phone</title>
		<link>http://www.pbxer.com/build-your-pbx-step-4-configure-your-voip-phone/</link>
		<comments>http://www.pbxer.com/build-your-pbx-step-4-configure-your-voip-phone/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 20:19:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[The Basics]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=64</guid>
		<description><![CDATA[You’ve got asterisk installed, configured and running. Now it’s time to get your VOIP phone configured to talk to your PBX.]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve got asterisk installed, configured and running. Now it&#8217;s time to get your phone to connect to asterisk.</p>
<p>There are several major vendors of VOIP phones. I&#8217;m going to outline the steps for a SNOM 320 and an Aastra 9133i phone. Configuring phones isn&#8217;t hard, since you basically need to enter three pieces of information:</p>
<ol>
<li>username</li>
<li>password</li>
<li>asterisk server IP address</li>
</ol>
<p>Despite only requiring these three pieces of information most VOIP phones seemed to have been designed to make this process as awkward as possible. So, take few deep breaths, and let&#8217;s get started.</p>
<h2>Snom 320</h2>
<p><img src="http://www.pbxer.com/wp-content/uploads/2008/08/snom320-350x270.jpg" alt="Snom 320 Voip Phone" title="Snom 320 Voip Phone" width="350" height="270" class="alignright size-full wp-image-66" /> SNOM phones are by far the easiest phones to setup. <a href="http://wiki.snom.com/Snom320/Documentation">Documentation is freely available</a> and you can do the setup directly from the phone.</p>
<p>Plug in the power and ethernet cables. Your router should have DHCP on and will assign the phone an IP address. After the phone boots it will enter a &#8216;wizard&#8217; mode if it has not been configured before.</p>
<p>For the <b>Account</b> enter the username in <tt>sip.conf</tt>. For example: <tt>phone1</tt></p>
<p>For the <b>Registrar</b> enter the IP address of your server running asterisk. (You can also enter a fully-qualified hostname such as pbx.mydomain.com if you have a domain name and have configured DNS for your server. If you don&#8217;t know what I&#8217;m talking about, use the IP address.)</p>
<p>The phone will contact the server and if all goes well, will ask for a <b>Password</b> which is what we defined as <tt>secret</tt> in the <tt>sip.conf</tt> config file.</p>
<p>And now you should be connected to the asterisk PBX. Dial <span class="digit">9</span> and you should be in the voicemail system. </p>
<p>If you see &#8220;NR&#8221;, that means Not Registered. More on how to debug connection problems below.</p>
<p>If you ever need to get into the administration menu, the default admin password is: 0000</p>
<h2>Aastra 9133i</h2>
<p><img src="http://www.pbxer.com/wp-content/uploads/2008/08/aastra9133i.jpg" alt="Aastra 9133i VOIP Phone" title="Aastra 9133i VOIP Phone" width="300" height="300" class="alignright size-medium wp-image-70" /><br />
A nice, sturdy phone with better sound quality sound than the SNOM, but a bit more fiddly to configure.</p>
<p>Plug in the power and ethernet cables. Your router should assign the phone an IP address. If you don&#8217;t catch the IP address when booting, you can find the IP address in the phone&#8217;s menu system.</p>
<p>Press the <b>Options</b> button (top right) and use the arrow keys to navigate the menus:</p>
<p>Network Settings • Admin Password: 22222 • IP Address</p>
<p>Now, type the IP address into a web browser. The default admin username/password is: admin/22222</p>
<p>We need to configure two screens: <b>Network Settings</b> and <b>Global SIP</b>.</p>
<h3>Network Settings</h3>
<p>Most of these settings are automatic and defined by your router when the phone boots. The only field you need to define is the <b>Time Server 1</b>. There is a bug in Aastra firmware in their DNS resolution code that crashes the phone, so I suggest you use IP addresses instead of server names.</p>
<p>You can google for <a target="_new" href="http://www.google.com/cse?cx=partner-pub-7891853231790910:xz7a0i-3k4i&#038;ie=ISO-8859-1&#038;q=public+NTP+time+server">public NTP time servers</a> or try one of the following servers below:</p>
<pre>
time.apple.com         17.151.16.20
time.euro.apple.com    17.72.255.11
time.nrc.ca            132.246.168.148
time-a.nist.gov        129.6.15.28</pre>
<p>Add an IP address for <b>Time Server 1</b> and click <b>Save Settings</b>.</p>
<h3>Global SIP</h3>
<p>There are a lot of fields on this screen. Some are not important, and many are duplicated. The following works for me. This configuration assumes the username is <tt>phone1</tt>, the password is <tt>xxxsecretxxx</tt> and the asterisk server IP address is <tt>128.1.2.3</tt>. Unless specified, leave the default values as is.</p>
<pre>

# aastra 91331 - Global SIP Settings
Screen Name:         aastra
Phone Number:        phone1
Caller ID:           phone1
Authentication Name: phone1
Password:            xxxsecretxxx
Line Mode:           Generic

Proxy Server:          128.1.2.3
Proxy Port:            5060
Outbound Proxy Server: 128.1.2.3
Outbound Proxy Port:   5060
Registrar Server:      128.1.2.3
Registrar Port:        5060
Registration Period:   600
</pre>
<p>Once you click &#8220;Save Settings&#8221;, you&#8217;ll need to click the &#8220;Reset&#8221; menu option to reboot the phone before your settings will take effect.</p>
<p>If the phone boots, the red light goes off and you don&#8217;t see a &#8220;No Service&#8221; message, then you&#8217;re connected! To test, dial <span class="digits">9</span> to enter the voicemail system or any of the extensions we&#8217;ve defined.</p>
<h2>Debugging Connection Problems</h2>
<p>If you&#8217;re phones aren&#8217;t registering with the asterisk server, then you need to isolate the problem.</p>
<p>A command I often use to get an overview of all the sip phones is: <tt>sip show peers</tt></p>
<p>On your asterisk server, as root, connect to asterisk:</p>
<div class="onlycmd">asterisk -r</div>
<p>If all is well, you should see something like the following:</p>
<div class="asteriskcmd">sip show peers</div>
<pre class="asteriskoutput">
Name/username              Host            Dyn Nat ACL Port     Status
phone1/phone1              88.10.11.12      D   N      5060     OK (115 ms)
1 sip peers [Monitored: 1 online, 0 offline Unmonitored: 0 online, 0 offline]
</pre>
<p>If the status is <b>UNKNOWN</b> or there is host address, then you need to get more information about the registration process.</p>
<p>Turn on more verbose messages.</p>
<div class="onlyasteriskcmd">core set verbose 10</div>
<p>Now reboot your phone and watch for error messages on the asterisk console. If you don&#8217;t see any &#8211; then your phone isn&#8217;t contacting the server.</p>
<p>A successful registration message is:</p>
<pre class="asteriskoutput">Registered SIP 'phone1' at 88.10.11.12 port 1025 expires 3600</pre>
<p>If you want to see all of the SIP messages between your phone and the asterisk server, type:</p>
<div class="onlyasteriskcmd">sip set debug</div>
<p>But be warned that the raw SIP messages can be overwhelming! I find that cutting and pasting them into a text editor makes them a bit easier to decode.</p>
<p>Most of the time I had problems connecting a phone it was due to typos and having the wrong username or password entered into one of the fields. Double-check that the values in <tt>sip.conf</tt> match the ones you&#8217;ve entered into your phone&#8217;s configuration.</p>
<h2>Summary</h2>
<p>Now, you&#8217;re able to use your VOIP phone to call your PBX. That&#8217;s an important step, but in order to have a real phone system we need to be able to call the outside world, and let people call our PBX. To do that we need to create an account with a VOIP provider.</p>
<div class="goon">
<a href="/build-your-pbx-step-5-add-a-voip-provider">Build your own PBX &#8211; Step 5: Add a VOIP provider</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/build-your-pbx-step-4-configure-your-voip-phone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build your PBX &#8211; Step 3: Configure your Asterisk PBX</title>
		<link>http://www.pbxer.com/build-your-pbx-step-3-configure-asterisk-pbx/</link>
		<comments>http://www.pbxer.com/build-your-pbx-step-3-configure-asterisk-pbx/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 17:15:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[The Basics]]></category>
		<category><![CDATA[aastra]]></category>
		<category><![CDATA[polycom]]></category>
		<category><![CDATA[voip phone]]></category>
		<category><![CDATA[voip phone configuration]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=54</guid>
		<description><![CDATA[There are three key configuration files that you need to setup for a basic asterisk install. We'll walk through setting up <tt>sip.conf</tt>, <tt>voicemail.conf</tt> and <tt>extensions.conf</tt>.]]></description>
			<content:encoded><![CDATA[<p>There are about a dozen configuration files in <tt>/etc/asterisk/</tt>, but for a standard PBX, you are only going to need to use a few of them:</p>
<p><b>sip.conf</b> &#8211; SIP is a protocol that allows VOIP devices to communicate. In this file you specify your VOIP provider as well as which VOIP phones will be connecting to your asterisk PBX.</p>
<p><b>voicemail.conf</b> &#8211; Asterisk comes with a voicemail system. Each voicemail box is defined in this configuration file.</p>
<p><b>extensions.conf</b> &#8211; Also known as the dialplan, it controls the behviour of your PBX. It outlines what happens when anyone calls your PBX. Interactions such as &#8220;Press 2 for Bob&#8221; are handled in this configuration file.</p>
<h2>sip.conf</h2>
<p>The default configuration files are massive and basically contains the documentation. It&#8217;s helpful to have around, but I suggest you start with a fresh new file. Initially, we are going to add one account, so you can connect to your asterisk server with a VOIP phone.</p>
<div class="filename">/etc/asterisk/sip.conf</div>
<pre class="file">
[general]
context=default                 ; Default context for incoming calls
allowguest=no                   ; Allow or reject guest calls (default is yes)
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
bindport=5060                   ; UDP Port to bind to (SIP standard port is 5060)
bindaddr=0.0.0.0                ; IP address to bind to (0.0.0.0 binds to all)
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
rfc2833compensate=yes

[authentication] ;; needed?

[phone1]
type=friend
context=internal-phone1
username=phone1
secret=xxxpassword ;; *change this!*
host=dynamic
nat=yes
qualify=yes ;; keep NAT open
canreinvite=no
allow=all
mailbox=20  ;; voicemail box
</pre>
<p>You don&#8217;t need to understand every line here. The most important points are that you have created a username and secret (password), which you will add to your VOIP phone.</p>
<h2>voicemail.conf</h2>
<p>The default <tt>voicemail.conf</tt> configuration file has dozens of options, but the default values are fine for now. The only line you need to add is one to define a voicemail box on the system. At the end of the file, there is a <tt>[default]</tt> context, where you need to define a voicemail box, password, name, and email (if you want voicemail to be sent as email).</p>
<div class="excerpt">/etc/asterisk/voicemail.conf</div>
<pre class="file">[default]
20 => 4444,Bob,bob@foo.com</pre>
<h2>extensions.conf</h2>
<p>Now that you&#8217;ve defined how your VOIP phone will connect to the asterisk PBX, you need to program what happens when you (or anyone else) calls your PBX.</p>
<p>For now, we&#8217;ll set-up a simple server where <span class="digit">9</span> will allow you to listen to your voicemail. <span class="digit">1</span> will start an echo test <span class="digit">2</span> will record a wav file. <span class="digit">3</span> will allow you to hear what callers hear when the call.</p>
<div class="filename">/etc/asterisk/extensions.conf</div>
<pre class="file">
[globals]
;; global variables can be defined here

[general]
static=yes
writeprotect=yes
autofallthrough=yes
clearglobalvars=yes
priorityjumping=no

[incoming] ;; calls from the outside world

exten => s,1,Noop('Call from the outside world')
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n,Background(hello-world)
exten => s,n,VoiceMail(20)

[internal-phone1] ;; calls from our VOIP phone

exten => 1,1,Noop(start echo test)
exten => 1,n,Answer
exten => 1,n,Wait(1)
exten => 1,n,Echo
exten => 1,n,Hangup

exten => 2,1,Noop(record a wav file - stop recording with #)
exten => 2,n,Answer
exten => 2,n,Wait(1)
exten => 2,n,Record('/tmp/outgoing-message-%d.wav') ; stop record with #
exten => 2,n,Wait(1)
exten => 2,n,Playback(${RECORDED_FILE})
exten => 2,n,Hangup

exten => 3,1,Noop('Pretend that we are an outside caller.')
exten => 3,n,Goto(pbx-incoming,s,1)

exten => 9,1,Noop('Listen to any voicemail messages')
exten => 9,n,Answer
exten => 9,n,Wait(1)	;; wait or we lose the first syllable
exten => 9,n,VoiceMailMain(s20) ;; s=skip login, listen to msgs in box 20

exten => i,1,Background(vm-goodbye)	;; invalid keypress

exten => t,1,Background(vm-goodbye)	;; timeout
</pre>
<p>Take a few minutes to study this file. The format that asterisk uses is a bit obtuse, but it&#8217;s important to understand what you see here. Two contexts have been defined: <tt>incoming</tt> which is where incoming calls from the outside world will go and <tt>internal-phone1</tt> which defines what we can dial from our internal VOIP phone.</p>
<p>Once we get our VOIP phone setup (which we will do in the next step) then we will be able to dial <span class="digit">1</span>,<span class="digit">2</span>,<span class="digit">3</span> or <span class="digit">9</span>. In <tt>sip.conf</tt> we defined the context for the phone to be <tt>internal-phone1</tt>, so when we dial from our VOIP phone, the valid extensions are defined in <tt>[internal-phone1]</tt>. In <tt>extensions.conf</tt> we define the sequence of commands that are executed for each dialed numbers. For example, if we dial <span class="digit">9</span>, first the phone is answered, then we wait one second, then we go to into the voicemail system for box 20.</p>
<p>The old-fashioned way to write these commands was to number each line. For example, the commands for extension <span class="digit">9</span> could also be written as:</p>
<pre class="file">exten => 9,1,Noop('Listen to any voicemail messages')
exten => 9,2,Answer
exten => 9,3,Wait(1)
exten => 9,4,VoiceMailMain(s20)</pre>
<p>This makes the sequence more obvious, but it is tedious and error-prone to maintain. The &#8216;n&#8217; shortcut (next) helps with this, although you still need to have an initial &#8217;1&#8242;. I typically use a Noop (no operation) command for the initial command, so all the real commands will simply have an &#8216;n&#8217; as the sequence number. The Noop command is also useful since the comments will show up in the logs and status messages which is helpful when debugging problems.</p>
<p>To start your asterisk server, run this command as root:</p>
<div class="onlycmd">asterisk</div>
<p>It should simply return quickly, but it has started asterisk. To connect to asterisk, as root, run:</p>
<div class="cmd">asterisk -r</div>
<pre class="output">Asterisk 1.4.21, Copyright (C) 1999 - 2008 Digium, Inc. and others.
Created by Mark Spencer &lt;markster@digium.com&gt;
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 1.4.21 currently running on pbxer (pid = 21010)
Verbosity is at least 10
pbxer*CLI&gt;</pre>
<p>To make sure that asterisk is using the current dialplan, type:</p>
<div class="onlyasteriskcmd">dialplan reload</div>
<p>To view the current dialplan type:</p>
<div class="asteriskcmd">dialplan show</div>
<pre class="asteriskoutput">[ Context 'internal-phone1' created by 'pbx_config' ]
  '1' =>            1. Noop(start echo test)                      [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. Echo()                                     [pbx_config]
                    5. Hangup()                                   [pbx_config]
  '2' =>            1. Noop(record a wav file - stop recording with #) [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. Record(/tmp/outgoing-message-%d.wav)       [pbx_config]
                    5. Wait(1)                                    [pbx_config]
                    6. Playback(${RECORDED_FILE})                 [pbx_config]
                    7. Hangup()                                   [pbx_config]
  '3' =>            1. Noop(Pretend that we are an outside caller.) [pbx_config]
                    2. Goto(incoming|s|1)                         [pbx_config]
  '9' =>            1. Noop(Listen to any voicemail messages)     [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. VoiceMailMain(s20)                         [pbx_config]
  'i' =>            1. Background(vm-goodbye)                     [pbx_config]
  't' =>            1. Background(vm-goodbye)                     [pbx_config]

[ Context 'pbx-incoming' created by 'pbx_config' ]
  's' =>            1. Noop(Call from the outside world)          [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. Background(hello-world)                    [pbx_config]
                    5. VoiceMail(20)                              [pbx_config]
</pre>
<p>If you have any typos in your extensions.conf file, <tt>dialplan show</tt> is the a good way to spot them, since it shows how asterisk understands the file.</p>
<p>We&#8217;ve got the PBX configured, now we need to setup a phone to connect to it.</p>
<div class="goon">
<a href="/build-your-pbx-step-4-configure-your-voip-phone">Build your PBX: Step 4: Configure your VOIP Phone</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/build-your-pbx-step-3-configure-asterisk-pbx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Build Your PBX &#8211; Step 2: Compile Asterisk</title>
		<link>http://www.pbxer.com/build-your-pbx-step-2-compile-asterisk/</link>
		<comments>http://www.pbxer.com/build-your-pbx-step-2-compile-asterisk/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 17:49:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[The Basics]]></category>

		<guid isPermaLink="false">http://www.pbxer.com/?p=41</guid>
		<description><![CDATA[Sometimes downloading the source code and compiling it is the easiest way. I'll show you how to get  the latest stable version of asterisk downloaded and compiled.]]></description>
			<content:encoded><![CDATA[<p>There is no &#8216;yum&#8217; package for asterisk, but it&#8217;s no problem to compile it from source. </p>
<p>Download asterisk from digium. They&#8217;ve made it hard to find the link from their homepage, but you can browse the files from their <a href="http://downloads.digium.com/pub/asterisk/">download area</a>.</p>
<p>At the time of writing, the latest version was 1.4.21.2, which you can be download directly onto your server.</p>
<pre class="cmd">curl -O http://downloads.digium.com/pub/asterisk/releases/asterisk-1.4.21.2.tar.gz
tar zxvf asterisk-1.4.21.2.tar.gz
cd asterisk-1.4.21.2
./configure
make
make install
</pre>
<p>If there are any errors, check that you aren&#8217;t missing any of the packages. For example, if you get errors about termcap, try searching in the package manager.</p>
<pre class="cmd">yum search termcap</pre>
<p>You&#8217;ll also want to get the library of audio files. These are required for some of the built-in applications such as voicemail, but it&#8217;s also handy to have standard audio files such as &#8220;please wait while I try that extension&#8221;.</p>
<p>The file is called <a href="http://downloads.digium.com/pub/asterisk/releases/asterisk-sounds-1.2.1.tar.gz">asterisk-sounds-1.2.1</a>. You can download this file directly to your server with:</p>
<pre class="cmd">curl -O http://downloads.digium.com/pub/asterisk/releases/asterisk-sounds-1.2.1.tar.gz
tar xzvf asterisk-sounds-1.2.1.tar.gz
cd asterisk-sounds-1.2.1
make install
</pre>
<p>Now that you&#8217;ve got the asterisk PBX installed, you&#8217;re ready to configure it.</p>
<div class="goon">
<a href="/build-your-pbx-step-3-configure-asterisk">Build your PBX: Step 3: Configure Asterisk</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.pbxer.com/build-your-pbx-step-2-compile-asterisk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
