[asterisk-users] utils.c: fwrite() returned error: Broken pipe how to solve it ???

2013-10-10 Thread akhilesh chand
Dear all,

I want to make call through socket i have set code given below:

#!/usr/bin/perl -w

use IO::Socket::INET;


sub asterisk_command ()
{
#  my $command=$_[0];
my
$ami=IO::Socket::INET-new(PeerAddr='127.0.0.1',PeerPort=5038,Proto='tcp')
or die failed to connect to AMI!;
print $ami Action: Login\r\nUsername: lite\r\nSecret:
4003\r\n\r\nAction: Logoff\r\n\r\n;
}
asterisk_command(Channel: DAHDI/27/7702009896\r\nExten: s\r\nContext:
outbound\r\nCallerID: 20048645\r\nPriority: 1\r\nMaxRetries: 2\r\n);

Whenever i execute that code i'm get following error

[Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
returned error: Broken pipe
[Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
returned error: Broken pipe
[Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
returned error: Broken pipe
[Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
returned error: Broken pipe


asterisk verison :-  1.6.2.7
CentOS release 5.3
kernel version :- 2.6.18-128.el5
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] utils.c: fwrite() returned error: Broken pipe how to solve it ???

2013-10-10 Thread Tony Mountifield
In article cae6_ne+dxtsgadtg0mp-9jumngxguwo4exadm_hrwc8opuo...@mail.gmail.com,
akhilesh chand omakhileshch...@gmail.com wrote:
 
 I want to make call through socket i have set code given below:
 
 #!/usr/bin/perl -w
 
 use IO::Socket::INET;
 
 
 sub asterisk_command ()
 {
 #  my $command=$_[0];
 my
 $ami=IO::Socket::INET-new(PeerAddr='127.0.0.1',PeerPort=5038,Proto='tcp')
 or die failed to connect to AMI!;
 print $ami Action: Login\r\nUsername: lite\r\nSecret:
 4003\r\n\r\nAction: Logoff\r\n\r\n;
 }
 asterisk_command(Channel: DAHDI/27/7702009896\r\nExten: s\r\nContext:
 outbound\r\nCallerID: 20048645\r\nPriority: 1\r\nMaxRetries: 2\r\n);
 
 Whenever i execute that code i'm get following error
 
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 
 
 asterisk verison :-  1.6.2.7
 CentOS release 5.3
 kernel version :- 2.6.18-128.el5

AMI is a *two-way* protocol. You mustn't just fire in a bunch of commands
and close the socket!

The reason Asterisk reports the fwrite() error is because you have closed
the socket before it had a chance to send you the responses.

What you need to do is this:

1. Connect to the AMI port.
2. Read the one-line greeting message that Asterisk sends you. It will tell
   you the version of the protocol (which might be of interest if you wanted
   to be compatible with different versions of Asterisk).
3. Send the Login action with username, secret and terminating blank line.
4. Read the response lines from Asterisk until it gives you a blank line.
5. Send whatever command you want it to do, and go back to step 4.
6. When you have done the commands you want, send the Logoff action.
7. *** READ THE RESPONSE TO THE LOGOFF
8. Close the socket.

If it helps. Here is similar piece of code I wrote to query pri spans.
Note carefully the setting of $/ in two places, and the inclusion of
Events: off to avoid responses getting confused by asynchronous events.

==
#!/usr/bin/perl

use IO::Socket;

my $numspans = 4;
my $host = 'localhost';
my $login = Action: login\r\nUsername: \r\nSecret: \r\nEvents: 
off\r\n\r\n;

$/ = \r\n;#  reads a single line for signon banner

my $s = IO::Socket::INET-new($host:5038) or die can't connect to $host: 
$!\n;
my $banner = $s;  # read the banner

#my $line = ('-' x 78).\n;
#print $banner,$line;

$/ = \r\n\r\n;#  reads a complete response ending in a blank line

print $s $login;
my $resp = $s;

#print $resp,$line;

my @spans;

foreach $span (1..$numspans) {
print $s Action: Command\r\nCommand: pri show span $span\r\n\r\n;
$resp = $s;
#print $resp,$line;

if ($resp =~ /Status: (.*)\n/) {
$status = $1;
} else {
$status = 'Unknown';
}
$spans[$span-1] = Span $span status = $status\n;
}

print $s Action: Logoff\r\n\r\n;
$resp = $s;
#print $resp,$line;

close $s;

# go on to display the results from @spans
==

Cheers
Tony

-- 
Tony Mountifield
Work: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] utils.c: fwrite() returned error: Broken pipe how to solve it ???

2013-10-10 Thread A J Stiles
On Thursday 10 October 2013, akhilesh chand wrote:
 Dear all,
 
 I want to make call through socket i have set code given below:
 
 #!/usr/bin/perl -w
 
 use IO::Socket::INET;
 
 
 sub asterisk_command ()
 {
 #  my $command=$_[0];
 my
 $ami=IO::Socket::INET-new(PeerAddr='127.0.0.1',PeerPort=5038,Proto='tcp
 ') or die failed to connect to AMI!;
 print $ami Action: Login\r\nUsername: lite\r\nSecret:
 4003\r\n\r\nAction: Logoff\r\n\r\n;
 }
 asterisk_command(Channel: DAHDI/27/7702009896\r\nExten: s\r\nContext:
 outbound\r\nCallerID: 20048645\r\nPriority: 1\r\nMaxRetries: 2\r\n);
 
 Whenever i execute that code i'm get following error
 
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
 returned error: Broken pipe
 
 
 asterisk verison :-  1.6.2.7
 CentOS release 5.3
 kernel version :- 2.6.18-128.el5

Broken Pipe is a bit misleading because it can refer to other modes of 
connection besides pipes  (although that certainly is the most common case 
where you would see it).  It just means something tried to write to a stream 
that has already been closed.

In this case, AMI is trying to send back a response *after* you have already 
closed the socket.  To avoid the error, you need to see if there is any data 
waiting to be read from the socket, and then read it.  (Then, having gone to 
the trouble of actually reading it, you may as well at least do a simple 
regular expression match to ensure that what you were expecting to happen 
actually happened.

Also, as Asterisk runs on Unix-like systems, you don't really need the 
Microsoft-style \r\n line endings.  Just an ordinary Unix-style \n on its own 
will suffice.  It even saves a few CPU cycles on the far end  (not that you'll 
ever actually notice from within an interpreted script).

-- 
AJS

Answers come *after* questions.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] utils.c: fwrite() returned error: Broken pipe how to solve it ???

2013-10-10 Thread Tony Mountifield
In article 201310101230.56058.asterisk_l...@earthshod.co.uk,
A J Stiles asterisk_l...@earthshod.co.uk wrote:
 
 Also, as Asterisk runs on Unix-like systems, you don't really need the 
 Microsoft-style \r\n line endings.  Just an ordinary Unix-style \n on its own 
 will suffice.  It even saves a few CPU cycles on the far end  (not that 
 you'll 
 ever actually notice from within an interpreted script).

Text-based internet protocols (e.g. SMTP, FTP, etc) canonically use \r\n
as a line terminator, and AMI does likewise. It may well accept commands
with just \n as a line termiator (I haven't checked), but it certainly
sends \r\n to terminate lines that it outputs. IMHO, it's good to adhere
to the same convention in both directions.

Cheers
Tony
-- 
Tony Mountifield
Work: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Calling a demo menu after voicemail authintication

2013-10-10 Thread Asmaa Ahmed
Thanks, It helps indeed!But what if I want to change the language based on user 
preferences for example How can I include it before the voicemail dialogue?
Is there a possibility for doing that?

To: asterisk-users@lists.digium.com
From: kevin.lar...@pioneerballoon.com
Date: Wed, 9 Oct 2013 10:43:44 -0500
Subject: Re: [asterisk-users] Calling a demo menu after voicemail   
authintication





From:  
 Asmaa Ahmed asabatg...@hotmail.com

To:  
 asterisk-users@lists.digium.com
asterisk-users@lists.digium.com, 

Date:  
 10/09/2013 10:36 AM

Subject:
   [asterisk-users]
Calling a demo menu after voicemail authintication

Sent by:
   asterisk-users-boun...@lists.digium.com








Hello,



I wonder if it is configurable possible
to add a new menu demo to run within voicemail context dialogue!

I want to run am interactive menu before or within the normal voicemail
dialogue to run a script based on the subscriber selection.

My point is to get use from the authenticated password that provided by
user to go though his voicemail to access this new feature as well!

If not, is there a way to use the same authentication to access this menu
a way from voicemailmain application?



Thanks. 



If you are trying to use dialplan logic
directly, you could use the function VM_INFO to compare a users password
with what they have entered. You would basically be writing your own code
before you ever went to voicemail to have them type their password, then
save that to a variable and compare with what VM_INFO shows as the correct
password.



You could also use an AGI script as detailed
here:   
http://www.voip-info.org/wiki/view/Asterisk+authenticate+using+voicemail+passwords




__

This email has been scanned by the Symantec Email Security.cloud service.

For more information please visit http://www.symanteccloud.com

__--


_

-- Bandwidth and Colocation Provided by http://www.api-digital.com
--

New to Asterisk? Join us for a live introductory webinar every Thurs:

   http://www.asterisk.org/hello



asterisk-users mailing list

To UNSUBSCRIBE or update options visit:

   http://lists.digium.com/mailman/listinfo/asterisk-users


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users  
  -- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Using sqlite3 for CDR logging

2013-10-10 Thread Tech Support
Thanks for the feedback. I read someplace that the Berkeley DB was wicked
fast and allowed for much higher concurrency. The only problem is that I
have no idea how to implement it into Asterisk. Does anyone have any
experience with something like this?
Regards;
John

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Chris Bagnall
Sent: Thursday, October 03, 2013 1:25 PM
To: asterisk-users@lists.digium.com
Subject: Re: [asterisk-users] Using sqlite3 for CDR logging

On 3/10/13 5:52 pm, Tech Support wrote:
I was
 thinking of using sqlite3 to log CDR's, thinking that would be faster than
 using MySQL. Has anyone ever benchmarked this to quantify just how much
 faster sqlite3 is? Are there any drawbacks to using it?

Lack of multi-user concurrency is the big one.

At the risk of encouraging database contests on the list, have you tried 
using PostgreSQL instead? It's a gross generalisation, but In my 
experience, PG handles writes better than MySQL, which in turn tends to 
handle reads a little faster than PG - assuming both are in 'out of the 
box' (i.e. unoptimised) conditions.

If you wanted to stick with MySQL, you might want to have a go at 
optimising it - there are quite a few scripts knocking around the web 
which run a set of queries on your data and suggest optimisations to apply.

And others have said, running the DB on a separate host is never a bad 
thing, and ideally on SSDs or RAM storage if you can. Spinning disks are 
often the bottleneck with large data sets.

Kind regards,

Chris
-- 
This email is made from 100% recycled electrons

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


[asterisk-users] asterisk 11.6 nat problem

2013-10-10 Thread Jeremy Kister
using asterisk 11.6.0-rc1 i just converted my nat=yes to 
nat=auto_force_rport,auto_comedia



I have my asterisk box on the same subnet as a cisco 1760 (vgw1).

a few times per day, Asterisk thinks vgw1 is dead (by qualify/options). 
 A 'sip reload' always fixes the problem.


i left 'sip set debug peer vgw1' on the console.  but i dont see what's 
causing the issue..



http://kister.net/tmp/ast-sip.conf
http://kister.net/tmp/ast-console.txt

can anyone spot the issue?


--

Jeremy Kister
http://jeremy.kister.net./

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
  http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Failed to authenticate user 1000sip:1000@MY_OWN_IP_ADDRESS; tag=03f82bb9

2013-10-10 Thread Michelle Dupuis
Gareth:

Did you check if your message (or security) log recorded anything during these 
attempts?  If so, can you post the content of the logs during this attack?

M

From: asterisk-users-boun...@lists.digium.com 
[asterisk-users-boun...@lists.digium.com] On Behalf Of Asghar Mohammad 
[asghar...@gmail.com]
Sent: Tuesday, October 01, 2013 11:53 AM
To: Asterisk Users List
Subject: Re: [asterisk-users] Failed to authenticate user 
1000sip:1000@MY_OWN_IP_ADDRESS; tag=03f82bb9

Hi,
Bad boys trying to guess a valid username.
in sip.conf uncomment  alwaysauthreject=yes and Asterisk always reject 1st 
invite.


On Tue, Oct 1, 2013 at 5:26 PM, Gareth Blades 
mailinglist+aster...@dns99.co.ukmailto:mailinglist+aster...@dns99.co.uk 
wrote:
On 01/10/13 15:44, gincantalupo wrote:
On Tue, Oct 1, 2013 at 5:07 AM, gincantalupo 
gincantal...@fgasoftware.commailto:gincantal...@fgasoftware.com wrote:
Hi,

I get a lot of these messages on my Asterisk CLI:

Failed to authenticate user 1000sip:1000@MY_OWN_IP_ADDRESS;tag=03f82bb9

as if my PBX machine is trying to authenticate to itself. It seems someone is 
attacking my asterisk PBX.

Is there a way to fix this problem?

in sip.conf I have guest connections permitted and have them going to the 
default context which contains :-

[default]
; all unauthenticated connection attempts from the internet come in here.
exten = _[+*#0-9].,1,NoOp(Unauthenticated call attempt - 
${SIP_HEADER(Contact)})
exten = _[+*#0-9].,n,Congestion

Then in fail2ban I have it match the following :-

failregex = Registration from .* failed for \'HOST\' - Wrong password
Unauthenticated call attempt .*\@HOST\:


--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] utils.c: fwrite() returned error: Broken pipe how to solve it ???

2013-10-10 Thread akhilesh chand
thanks a lot Tony


On Thu, Oct 10, 2013 at 4:31 PM, Tony Mountifield t...@softins.co.ukwrote:

 In article 
 cae6_ne+dxtsgadtg0mp-9jumngxguwo4exadm_hrwc8opuo...@mail.gmail.com,
 akhilesh chand omakhileshch...@gmail.com wrote:
 
  I want to make call through socket i have set code given below:
 
  #!/usr/bin/perl -w
 
  use IO::Socket::INET;
 
 
  sub asterisk_command ()
  {
  #  my $command=$_[0];
  my
 
 $ami=IO::Socket::INET-new(PeerAddr='127.0.0.1',PeerPort=5038,Proto='tcp')
  or die failed to connect to AMI!;
  print $ami Action: Login\r\nUsername: lite\r\nSecret:
  4003\r\n\r\nAction: Logoff\r\n\r\n;
  }
  asterisk_command(Channel: DAHDI/27/7702009896\r\nExten: s\r\nContext:
  outbound\r\nCallerID: 20048645\r\nPriority: 1\r\nMaxRetries: 2\r\n);
 
  Whenever i execute that code i'm get following error
 
  [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
  returned error: Broken pipe
  [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
  returned error: Broken pipe
  [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
  returned error: Broken pipe
  [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
  returned error: Broken pipe
 
 
  asterisk verison :-  1.6.2.7
  CentOS release 5.3
  kernel version :- 2.6.18-128.el5

 AMI is a *two-way* protocol. You mustn't just fire in a bunch of commands
 and close the socket!

 The reason Asterisk reports the fwrite() error is because you have closed
 the socket before it had a chance to send you the responses.

 What you need to do is this:

 1. Connect to the AMI port.
 2. Read the one-line greeting message that Asterisk sends you. It will tell
you the version of the protocol (which might be of interest if you
 wanted
to be compatible with different versions of Asterisk).
 3. Send the Login action with username, secret and terminating blank line.
 4. Read the response lines from Asterisk until it gives you a blank line.
 5. Send whatever command you want it to do, and go back to step 4.
 6. When you have done the commands you want, send the Logoff action.
 7. *** READ THE RESPONSE TO THE LOGOFF
 8. Close the socket.

 If it helps. Here is similar piece of code I wrote to query pri spans.
 Note carefully the setting of $/ in two places, and the inclusion of
 Events: off to avoid responses getting confused by asynchronous events.

 ==
 #!/usr/bin/perl

 use IO::Socket;

 my $numspans = 4;
 my $host = 'localhost';
 my $login = Action: login\r\nUsername: \r\nSecret: \r\nEvents:
 off\r\n\r\n;

 $/ = \r\n;#  reads a single line for signon banner

 my $s = IO::Socket::INET-new($host:5038) or die can't connect to
 $host: $!\n;
 my $banner = $s;  # read the banner

 #my $line = ('-' x 78).\n;
 #print $banner,$line;

 $/ = \r\n\r\n;#  reads a complete response ending in a blank
 line

 print $s $login;
 my $resp = $s;

 #print $resp,$line;

 my @spans;

 foreach $span (1..$numspans) {
 print $s Action: Command\r\nCommand: pri show span $span\r\n\r\n;
 $resp = $s;
 #print $resp,$line;

 if ($resp =~ /Status: (.*)\n/) {
 $status = $1;
 } else {
 $status = 'Unknown';
 }
 $spans[$span-1] = Span $span status = $status\n;
 }

 print $s Action: Logoff\r\n\r\n;
 $resp = $s;
 #print $resp,$line;

 close $s;

 # go on to display the results from @spans
 ==

 Cheers
 Tony

 --
 Tony Mountifield
 Work: t...@softins.co.uk - http://www.softins.co.uk
 Play: t...@mountifield.org - http://tony.mountifield.org

 --
 _
 -- Bandwidth and Colocation Provided by http://www.api-digital.com --
 New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

 asterisk-users mailing list
 To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users