Skip to content

Instantly share code, notes, and snippets.

View marcelog's full-sized avatar

Marcelo Gornstein marcelog

View GitHub Profile
./configure --enable-cgi
@marcelog
marcelog / nginx.conf
Created May 8, 2016 14:43
Part of: http://marcelog.github.io/articles/configure_nginx_php_5.3_5.2_fastcgi.html NGINX configuration file to support different (multiple) PHP versions in different virtual hosts by using FastCGI
# Useful to debug rewrite rules and other stuff
error_log logs/error.log notice;
http {
# Debug rewrite rules
rewrite_log on;
}
server {
listen 80;
@marcelog
marcelog / start_fastcgi_php.sh
Created May 8, 2016 14:45
Part of: http://marcelog.github.io/articles/configure_nginx_php_5.3_5.2_fastcgi.html Used to start different FastCGI daemons with different (multiple) PHP versions
#!/bin/bash
USER=nobody
PHP_52_BIND=127.0.0.1:9000
PHP_53_BIND=127.0.0.1:9001
PHP_52_CGI=/usr/php-5.2/bin/php-cgi
PHP_53_CGI=/usr/php-5.3/bin/php-cgi
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS"
PHP_52_CGI_ARGS="${PHP_CGI_ARGS} ${PHP_52_CGI} -b ${PHP_52_BIND}"
@marcelog
marcelog / run_bami.sh
Created May 8, 2016 14:55
Part of: http://marcelog.github.io/articles/bash_asterisk_manager_interface_client_shell_script.html Using netcat to run the Bash Asterisk Manager Interface (BAMI)
#!/bin/bash
nc 127.0.0.1 5038 -e ./bami.sh
@marcelog
marcelog / sample_bami_log.txt
Created May 8, 2016 14:57
Part of: http://marcelog.github.io/articles/bash_asterisk_manager_interface_client_shell_script.html Example of AMI events received by the Bash Asterisk Manager Interface (BAMI)
09/08/11 21:46:40 - DEBUG - Event: Newstate Privilege: call,all Channel: DAHDI/x-1 ChannelState: 5 ChannelStateDesc: Ringing CallerIDNum: x CallerIDName: Uniqueid: 1315529123.320110
09/08/11 21:46:40 - INFO - === Unhandled event: Newstate ===
09/08/11 21:46:40 - DEBUG - Event: DTMF Privilege: dtmf,all Channel: DAHDI/x-1 Uniqueid: 1315529106.320100 Digit: 6 Direction: Received Begin: No End: Yes
09/08/11 21:46:40 - INFO - DTMF
09/08/11 21:46:40 - DEBUG - Event: DTMF Privilege: dtmf,all Channel: DAHDI/x-1 Uniqueid: 1315529097.320090 Digit: 0 Direction: Received Begin: Yes End: No
09/08/11 21:46:40 - INFO - DTMF
@marcelog
marcelog / bami_logging_functions.sh
Created May 8, 2016 15:04
Part of: http://marcelog.github.io/articles/bash_asterisk_manager_interface_client_shell_script.html General logging functions for BAMI the Bash Asterisk Manager Interface client
# Generic function for logging
function log() {
echo `date "+%D %T - "` "${@}" >> ${log}
}
# Will call log() with a INFO prefix
function info() {
log "INFO - ${@}"
}
# Reads a line from AMI (stdin), will strip \r
function readLine() {
local line=""
read line
line=`echo ${line} | tr -d "\r"`
echo ${line}
}
# Reads a full PDU from asterisk. Since Asterisk messages
# ends with a \r\n\r\n, and we use "read" to read line by
# Performs a Login action. Will terminate with error code 255 if
# the asterisk ami welcome message is not found.
function login() {
local welcome=`readLine`
if [ ${welcome} != "Asterisk Call Manager/1.1" ]; then
error "Invalid peer. Not AMI."
exit 255
fi
printf "Action: Login\r\nUsername: ${user}\r\nSecret: ${pass}\r\n\r\n"
local response=`readPdu`
# Main reading loop.
while [ true ]; do
pdu=`readPdu`
debug "${pdu}"
$regex="Event: *"
if [[ $pdu =~ $regex ]]; then
eventName=`echo ${pdu} | cut -d' ' -f2`
case ${eventName} in
DTMF)
info DTMF
src/mg/AsterTrace ==> Main source directory
ServerHandlers ==> Server Handlers reside here. These will listen for events triggered from the tcp server.
ServerHandler.php ==> A base class for all tcp command listeners.
ServerCommandDTO.php ==> DTO to be used when dispatching events from the TCP server. The handlers will get this as the argument of the event.
CoreShowChannels.php ==> Event handler when a tcp client issues CoreShowChannels
EventHandlers ==> Event Handlers reside here. These are our listening beans.
DialListener.php
DtmfListener.php
EventListener.php
PDOListener.php