Thursday, November 15, 2012

regular expression to match xml attribute values

Lead Id="xxxx" and AgentId="yyyyy" are two attributes in an XML file (Lead Id must be the first)
[\s\S]*Lead Id="([^"]*)"[\S\s]*AgentId="([^"]*)"

Tuesday, October 30, 2012

using ngrep to view sip messages


ngrep -W byline -d eth0 port 5060
Just the invites:
ngrep -W byline -d eth0 INVITE
thanks to
http://www.jonathanmanning.com/2009/11/17/how-to-sip-capture-using-ngrep-debug-sip-packets/

Thursday, October 11, 2012

bash script cgi post and get process web form input

Thanks to Thanks to http://oinkzwurgl.org/bash_cgi

#!/bin/bash
echo -e "Content-type: text/html\n\n"
cat <<EOF
<html>
<body>
<form action="?foo=1234" method="POST" enctype="application/x-www-form-urlencoded">
bar: <input type="text" name="bar"><br/>
foobar: <textarea name="foobar"></textarea></br>
<input type="submit">
</form>
EOF


# (internal) routine to store POST data
function cgi_get_POST_vars()
{
    # check content type
    # FIXME: not sure if we could handle uploads with this..
    [ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ] && \
    echo "bash.cgi warning: you should probably use MIME type "\
         "application/x-www-form-urlencoded!" 1>&2
    # save POST variables (only first time this is called)
    [ -z "$QUERY_STRING_POST" \
      -a "$REQUEST_METHOD" = "POST" -a ! -z "$CONTENT_LENGTH" ] && \
        read -n $CONTENT_LENGTH QUERY_STRING_POST
    # prevent shell execution
    local t
    t=${QUERY_STRING_POST//%60//} # %60 = `
    t=${t//\`//}
    t=${t//\$(//}
    QUERY_STRING_POST=${t}
    return
}

# (internal) routine to decode urlencoded strings
function cgi_decodevar()
{
    [ $# -ne 1 ] && return
    local v t h
    # replace all + with whitespace and append %%
    t="${1//+/ }%%"
    while [ ${#t} -gt 0 -a "${t}" != "%" ]; do
    v="${v}${t%%\%*}" # digest up to the first %
    t="${t#*%}"       # remove digested part
    # decode if there is anything to decode and if not at end of string
    if [ ${#t} -gt 0 -a "${t}" != "%" ]; then
        h=${t:0:2} # save first two chars
        t="${t:2}" # remove these
        v="${v}"`echo -e \\\\x${h}` # convert hex to special char
    fi
    done
    # return decoded string
    echo "${v}"
    return
}

# routine to get variables from http requests
# usage: cgi_getvars method varname1 [.. varnameN]
# method is either GET or POST or BOTH
# the magic varible name ALL gets everything
function cgi_getvars()
{
    [ $# -lt 2 ] && return
    local q p k v s
    # prevent shell execution
    t=${QUERY_STRING//%60//} # %60 = `
    t=${t//\`//}
    t=${t//\$(//}
    QUERY_STRING=${t}
    # get query
    case $1 in
    GET)
        [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
        ;;
    POST)
        cgi_get_POST_vars
        [ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
        ;;
    BOTH)
        [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
        cgi_get_POST_vars
        [ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
        ;;
    esac
    shift
    s=" $* "
    # parse the query data
    while [ ! -z "$q" ]; do
    p="${q%%&*}"  # get first part of query string
    k="${p%%=*}"  # get the key (variable name) from it
    v="${p#*=}"   # get the value from it
    q="${q#$p&*}" # strip first part from query string
    # decode and evaluate var if requested
    [ "$1" = "ALL" -o "${s/ $k /}" != "$s" ] && \
        eval "$k=\"`cgi_decodevar \"$v\"`\""
    done
    return
}



# register all GET and POST variables
cgi_getvars BOTH ALL

echo "<pre>foo=$foo</pre>"
echo "<pre>bar=$bar</pre>"
echo "<pre>foobar=$foobar</pre>"

cat <<EOF
</body>
</html>
EOF

Monday, October 08, 2012

run command from within awk

cat ips.txt | awk '{system("ping -c 1 "$1}'

Thursday, October 04, 2012

Thursday, September 06, 2012

nagios check_snmp does not work but snmpget does

check_snmp of nagios uses version 1 of SNMP automatically, to force version 2c for the devices that do not support it add a -P 2c to the switches.

Also to check what snmpget is executed by the check_snmp simply run it with -v switch

snmpget works but nagios check_snmp does not

run your check_snmp with -v so it displays what exact snmpget it is calling

Thursday, August 16, 2012

SIPXECS 404

On SipXecs when you get a 404 not found, it does not only mean the user was not found, it means that the registrations string was not matched, so it is quite possible that the server aliases are not put under the Domain so strings do not match


XXXX@sip1.sip.company.com needs to match
add sip1.sip.company.com under Domain =>Alias

Tuesday, August 14, 2012

add functionality to snmpd to report the output of a script

Add functionality to snmpd to report the output of a script

1. Create the script

cat /usr/local/check_reg.sh

#!/bin/bash
grep uri /var/sipxdata/sipdb/registration.xml | wc -l

2. Add it to snmpd.conf

cat /etc/snmp/snmpd.conf
...
extend check_reg /usr/local/check_reg.sh
....

3. now snmpwalk it
snmpwalk -v2c -c pub localhost NET-SNMP-AGENT-MIB::nsExtensions


Monday, August 13, 2012

listen to g722 RTP streams in a PCAP file

The easiest way to listen to g722 RTP streams in a pcap file is to
1. Open the pcap file and just save the RTP packets (remove the RTCP using the filter rtp.ssrc!=0xBADBADBA)
2. Upload the file in http://pcap2wav.xplico.org/ and download the wav files

Friday, June 15, 2012

linux find executable files


find . -type f -perm -+x

Sunday, May 20, 2012

Windows VPN Connection with automatic routes added without default gateway option

type c:\windows\vpn.bat

@echo off
rasdial VPN_CONNECTION_NAME USERNAME PASSWORD
for /f "tokens=15 delims= " %%A in ('ipconfig ^| find "192.168.200"') do @set GW=%%A
route add 192.168.45.0 mask 255.255.255.0 %GW%

Wednesday, May 02, 2012

SRV records for service redudnacy

You can use SRV records just like MX records for other services redundancy for services other than mail

Friday, April 06, 2012

rescue missing vmdk disk

recreate vmdk from *-flat.vmdk file
vmkfstool -c $SIZE -a lsilogic -d thin temp.vmdk
edit the temp file and replace temp-flat with your own flat file name
thanks to http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1002511

Wednesday, March 07, 2012

windows variables

use %%A within batch files and %A outside in the shell

automatic windows VPN/PPP dial using rasdial

rasdial %CONNECTION_NAME% username password

windows awk using for /f command

example:
C:\Documents and Settings\Ali>for /f "tokens=15 delims= " %A in ('ipconfig ^| find "192.168.7"') do @set GW=%A

windows extract ip address from command line

for /f "tokens=15 delims= " %A in ('ipconfig ^| find "192.168.7"') do @set GW=%A

Wednesday, February 29, 2012

Wednesday, February 22, 2012

Windows automatic dial VPN PPTP connection

rasdial CONNECTION_NAME USERNAME PASSWORD

Thursday, January 19, 2012

veeam scp problem windows 64 bit (x64)

download courflags from
http://www.virtualvcp.com/content/view/26/1/
then do a
courflags "C:\Program Files (x86)\Veeam\Veeam Backup and FastSCP\VeeamShell.exe" /32BIT+"

big thanks to
http://www.everything-virtual.com/?p=279

Monday, January 16, 2012

vmware server 2 remote client problem on linux

goto somewhere like the below

cd ~/.mozilla/firefox/r1ejwkml.default/extensions/VMwareVMRC@vmware.com/plugins

and run
./vmware-vmrc -h "localhost:8333"





Saturday, January 14, 2012

dd progress status

while [ `pgrep ^dd` ]; do kill -USR1 `pgrep ^dd`;sleep 1;done

Tuesday, January 10, 2012

ssh disable slow dns

in /etc/ssh/sshd_config
UseDNS no