##Google Analz## ##Microsoft## ##Googel## Swanand: March 2014

Monday 31 March 2014

php script for LDAP/ Active directory

code:

<?php
  function getLdapInfo($user,$password,$domain) {
    // Config:
    $ldap_server = "ldaps://<YOUR_LDAP_SERVER>";
    $defaultDN = "dc=<DOMAIN_NAME>,dc=<DOMAIN_TLD>";
    $filter = '(&(objectClass=user)(sAMAccountName='.$user.'))';

    // Script
    $ad = @ldap_connect($ldap_server);              
    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
    $bd = @ldap_bind($ad,$user.'@'.$domain,$password);
    if (ldap_errno($ad)) {
      switch(ldap_errno($ad)) {
        case 81:
          # Can't connect to LDAP Server
          return(array(
            'errorno' => -1,
            'errorstr' => 'Can\'t connect to Domain Server', 
            'errortxt' => 'Error #'.ldap_errno($ad).': '.ldap_err2str(ldap_errno($ad))
          ));
        case 49:
          # Can't authenticate
          return(array(
            'errorno' => -2,
            'errorstr' => 'Invalid Login/Password',  
            'errortxt' => 'Error #'.ldap_errno($ad).': '.ldap_err2str(ldap_errno($ad))
          ));
        default:
          # Unknown Error
          return(array(
            'errorno' => -99,
            'errorstr' => 'Unknown Error, Please contact support',  
            'errortxt' => 'Error #'.ldap_errno($ad).': '.ldap_err2str(ldap_errno($ad))
          ));
       }
    }
    $result = @ldap_search($ad, $defaultDN, $filter, array('memberOf','displayName','mail','sAMAccountName'));                     
    $entries = @ldap_get_entries($ad, $result);
    if (ldap_errno($ad)) {     
      return(array(
       'errorno' => -3,
       'errorstr' => 'Configuration Error, Please contact support',
       'errortxt' => 'Error #'.ldap_errno($ad).': '.ldap_err2str(ldap_errno($ad))
      ));
    }
    $_RETURN[id] = $entries[0]["samaccountname"][0];
    $_RETURN[name] = $entries[0]["displayname"][0];
    $_RETURN[email] = $entries[0]["mail"][0];
    $_RETURN[groups] = array();
    for ($i=0; $i < $entries[0]["memberof"]["count"]; $i++) {
      array_push($_RETURN[groups],substr($entries[0]["memberof"][$i],3,strpos($entries[0]["memberof"][$i],',')-3));
    }
    return($_RETURN);
    ldap_unbind($ad);
  }

  // Test Code
  print "<pre>";
  print_r(getLdapInfo('<USERNAME>','<PASSWORD>','<DOMAIN_CONTROLLER'));
?>

script end

result of the script
Array
(
    [id] => adambotbyl
    [name] => Adam Botbyl
    [email] => adam@locateadam.com
    [groups] => Array
        (
            [0] => Web Blog
            [1] => Admin
        )
)

Click to Dial or php API to dial from asterisk

PHP script for click to dial or API to dial from asterisk via http
source :  Elastix forum

copy the below code to a file (call.php)  to the webdirectory.
executes as  :  http://ipaddress/call.php??exten=SIP/100&number=9999999999


******************************************************************************************************************************
<?php
#ip address that asterisk is on.
$strHost = "127.0.0.1";
$strUser = "admin";#specify the asterisk manager username you want to login with
$strSecret = "elastix456";#specify the password for the above user
#specify the channel (extension) you want to receive the call requests with
#e.g. SIP/XXX, IAX2/XXXX, ZAP/XXXX, etc
# $strChannel = "SIP/100";
$strChannel = $_REQUEST['exten'];
$strContext = "from-internal";
#specify the amount of time you want to try calling the specified channel before hangin up
$strWaitTime = "30";
#specify the priority you wish to place on making this call
$strPriority = "1";
#specify the maximum amount of retries
$strMaxRetry = "2";
$number=strtolower($_REQUEST['number']);
$pos=strpos ($number,"local");
if ($number == null) :
exit() ;
endif ;
if ($pos===false) :
$errno=0 ;
$errstr=0 ;
$strCallerId = "Web Call $number";
$oSocket = fsockopen ("localhost", 5038, &$errno, &$errstr, 20);
if (!$oSocket) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $strUser\r\n");
fputs($oSocket, "Secret: $strSecret\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: $strChannel\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
fputs($oSocket, "CallerId: $strCallerId\r\n");
fputs($oSocket, "Exten: $number\r\n");
fputs($oSocket, "Context: $strContext\r\n");
fputs($oSocket, "Priority: $strPriority\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");
sleep(2);
fclose($oSocket);
}
echo "Extension $strChannel should be calling $number." ;
else :
exit() ;
endif ;
?>
***********************************************************************
Using this script for click to dial number in mozilla firefox.

1. Install the Telify  addon to the mozilla

2. then configure it as shown in below picture
3. used protocal- Custom URL
4. Custom URL - https://192.168.1.2/call.php?exten=222&number=$0
5. apply or ok

once done , any numbers in the webpage or mail  will be highlighted fro click to dial.


How to reinstall / uninstall or upgrade sangoma wanpipe driver




  • Following steps is for Reinstalling or uninstalling or upgrading the Sangoma Wanpipe Driver
Reinstalling/Uninstalling 
(for upgrade steps check the last steps)

step 1 ---  Check the wanpipe version installed
command to check the current version
wanrouter version

step 2 --- Go to the wanpipe source code of the installed version or download from sangoma for the same version
in my case i have downloaded the wanpipe in src directory
cd /usr/src/wanpipe-"version no"

if you dont have the source file then download the same version from the below link and untar the file

Step 3 --- uninstalling the wanpipe
wanrouter stop
wanrouter modules  ;to check if any loaded
./Setup remove

Step 4 --- installing the latest wanpipe driver or installing the any version of wanpipe which downloaded
- move to the wanpipe source folder and run below command
cd /usr/src/wanpipe-currentveriondownloaded/
./Setup dahdi    ; as i am using dahdi driver if you use zaptel then run ./Setup  zaptel

****** reinstallation done here ************************************
******below steps is for upgrading the wanpipe to latest *****

Wanpipe Upgrade 


  • Download the Latest wanpipe from the below link 
  • untar the file and move to the folder
  • wanrouter stop
  • cd /usr/src/wanpipe-currentversion
  • cd /util/wan_aftup
  • ./update_aft_firm.sh
*************END of WANPIPE UPGRADE********************


How to configure Digium TE133 and TE134 Single Span T1/E1 card in asterisk , Vicidial , Goautodial, vicidialnow ,osdial , AsteriskNow , Elastix.



How to configure Digium TE133 and TE134 Single Span T1/E1 card in asterisk , Vicidial , Goautodial, vicidialnow ,osdial , AsteriskNow , Elastix.

The new digium TE133X cards wont have Jumpers to switch between E1 and T1,  it can be configured via software itself. 
   The following Blog will instruct you on how to install Digium TE133 and TE134 in you asterisk as T1 or E1

   The new Digium cards  requires  Latest DAHDI drivers , you can download the latest DAHDI and LIBPRI driver from the below link and follow below blog link for DAHDI upgrade or DAHDI reinstall

DAHDI : wget http://downloads.digium.com/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
LIBPRI : wget http://downloads.digium.com/pub/telephony/libpri/libpri-X.X.current.tar.gz
BLOG to reinstall dahdi : http://striker24x7.blogspot.com/2013/05/steps-to-reinstall-or-upgrade-dahdi.html


For E1 mode :
Step 1
Go to   :   /etc/modprobe.d/dahdi.conf  (ie:  vi /etc/modprobe.d/dahdi.conf)
And enter below line at last  ,save and exit
options wcte13xp default_linemode=e1
Step 2
Run the below command as root
# modprobe wcte13xp default_linemode=e1
#dahdi_genconf -v
#dahdi_cfg -v   (make sure the ouput should show 31 channels)

Note:  dahdi_genconf  will generate default configs for digium cards,  if  your  pri  CRC4 is disabled, then do the changes in   /etc/dahdi/system.conf 
Step 3
Now open /etc/asterisk/chan_dahdi.conf and add the below line at the last line (use shift+g to go to last line in putty)
#include dahdi-channels.conf

Step 4
Dialplan to dial via PRI
vi /etc/asterisk/extension.conf

[default]   ; the default will already exists in most asterisk installation if not create a new
exten => _9X.,1,Dial(DAHDI/g0/${EXTEN:1},30)
exten => _9X.,2,Hangup()

Note:  9 is just a prefix, and it will be discarded while dialling out
Note: for vicidial /goautodial use below dialplan in dialplan entry or extensions.conf
exten => _9X.,1,AGI(agi://127.0.0.1:4577/call_log)
exten => _9X.,2,Dial(DAHDI/g0/${EXTEN:1},,Tto)
exten => _9X.,3,Hangup

For T1 Mode:
Go to   :   /etc/modprobe.d/dahdi.conf  (ie:  vi /etc/modprobe.d/dahdi.conf)
And enter below line at last  ,save and exit
options wcte13xp default_linemode=t1
Step 2
Run the below command as root
# modprobe wcte13xp default_linemode=t1
#dahdi_genconf -v
#dahdi_cfg -v   (make sure the ouput should show 31 channels)

follow the above steps for the dialplan.

Troubleshoot
* make sure pri is up  by typing below command in asterisk cli
dahdi show staus
pri show spans

* if the line is up and still not dialling then do the following changes in chan_dahdi.conf
pridialplan=unknown
prilocaldialplan=unknown

* incomming calls will land in  from-pstn context  ,
* to change the incomming context go to  /etc/asterisk/dahdi-channels.conf   and change from-pstn to what ever you want
* for vicidial put trunkinbound as inbound context.

Time synchronization Error , Vicidial ,Goautodial

Time synchronization Error in vicidial goautodial


there is a problem of time synchronization in your system .please contact administrator


The major cause for the time sync error are
  1. The vicidial based system is using  MeetMe conference , These MeetMe Conference Bridge requires a timing resources like  Dahdi or Zaptel.  if they are not loaded poperly then time sync error occurs
  2. wrong System timing . different timing in server and agent systems
  3. wrong time set for DB time , PHP time , server Time
  4. Not updated the New server ip for the vicidial /goautodial 
-------------------------------------------------------------------------------------------
Troubleshoot 1:
MeetMe Conference dahdi issue
  • make sure the dahdi/zaptel driver is installed properly
If you are not using any telephony cards then you need to use the dummy drivers
type:   modprobe dahdi_dummy
          dahdi_cfg -vvvvv
          asterisk  -vvvvvr
          module unload chan_dahdi.so
          module load chan_dahdi.so
  • Now login as agent and check whether the problem arises
  • For those using asterisk telephone cards like digium , sangoma ,allo use the below links 
  • Digium sangoma allo
-------------------------------------------------------------------------------------------
Troubleshoot 2:
wrong server time
check the server time ,
type  date  in the linux console ,  it will display the current server time.  if the server time and timezone is wrong follow the below commands to change it.

  • rm /etc/localtime
  • ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
  • rdate -s time-a.nist.gov
  • chkconfig ntpd on
  • ntpdate pool.ntp.org
  • /etc/init.d/ntpd start
-------------------------------------------------------------------------------------------
Troubleshoot 3:

Check the db time php time from the vicidail report section


          if the time is different for all the three then follow the above trouble shoot and reboot the server.
-------------------------------------------------------------------------------------------
Troubleshoot 4:
If you have changed your server ip, dont forget to run the ip update script.
type the below command to update
/usr/share/astguiclient/ADMIN_update_server_ip.pl
and follow the onscreen steps , once done reboot the server and login as agent and check .

-------------------------------------------------------------------------------------------
Troubleshoot 5

If you have very big setup of vicidial , then Dahdi_dummy will not be sufficient to provide time source , so you can use the Sangoma voice time sync USB stick


-------------------------------------------------------------------------------------------
For Support
Swanand.awatad@gmail.com
+91 963 741 5650

Sorry, there are no available sessions

(vicidial , goautodial ,vicibox , asterisk)

The major cause for this error
  1. The vicidial based system is using  MeetMe conference , These MeetMe Conference Bridge requires a timing resources like  Dahdi or Zaptel.  if they are not loaded poperly then this error appears.
  2. Not updated the New server ip for the vicidial /goautodial database
  3. Wrong ip set in DB (even after IP update script executed)
  4. MeetMe Conference Sessions are not created or deleted accidently

Troubleshoot 1
Dahdi driver.
MeetMe Conference dahdi issue
  • make sure the dahdi/zaptel driver is installed properly
  • Run  dadhi_cfg  -v   
  • the above command should give below output (if you are not using any telephony card)
DAHDI Version: 2.6
Echo Canceller(s): HWEC
Configuration
======================

Channel map:

0 channels to configure.
  • If the above command gives error like dahdi not found 1 error"
  • then reinstall the latest dadhi driver check the below link for reinstalling

once installing dahdi driver, If you are not using any telephony cards then you need to use the dummy drivers
type:   modprobe dahdi_dummy
          dahdi_cfg -vvvvv
          asterisk  -vvvvvr
          module unload chan_dahdi.so
          module load chan_dahdi.so
  • Now login as agent and check whether the problem arises
  • For those using asterisk telephone cards like digium , sangoma ,allo use the below links 
  • Digium sangoma allo

Troubleshoot 2
Update the server ip in the Database
Once you have changed the ipaddress of your server, you need to update the same ip in the vicidial database.
run the below command to update and enter the new ip while it prompts.
/usr/share/astguiclient/ADMIN_update_server_ip.pl

Troubleshoot 3
Sometime the new  IP wont get updated , if you have entered wrong old ip field , or Db ip get a localhost(127.0.0,1) 
1. check what ip is showing in serverip field of  Phones, conferences, vicidial-confereces, server in vicidial admin panel  and run the below command
option1 
/usr/share/astguiclient/ADMIN_update_server_ip.pl --old-server_ip=oldipaddress

option 2 ( mysql update)
run the below command in linux console
mysql -
password :  "enter ur mysql password "  note: vicidialnow is the goautodial default pass
mysql>use asterisk
mysql >UPDATE conferences SET server_ip='your current serverip' where server_ip=''oldip"; 
mysql>UPDATE vicidial_conferences SET server_ip='your currentserverip' where server_ip="oldip";
mysql>UPDATE servers SET server_ip='your currentserverip' where server_ip="oldip";
mysql>UPDATE phones SET server_ip='your currentserverip' where server_ip="oldip";
6. quit
7. reboot

Troubleshoot 4
Missing or Conference sessions or Deleted the Conference sessions.
  • Make sure you have Conference rooms under ADMIN-CONFERENCE  & VICIDIAL-CONFERENCE
  • if its empty download the below file from dropbox link
  • https://www.dropbox.com/s/1wwplp2scwzmfpr/first_server_install.sql
  • copy the first_server_install.sql  file to /usr/src/   using winscp  and run below command
  • #mysql -p
  • password :
  • mysql> use asterisk
  • mysql>\. /usr/src/first_server_install.sql
  • mysql>quit
  • #/usr/share/astguiclient/ADMIN_update_server_ip.pl --old-server_ip=10.10.10.15
  • #reboot

Featured post

Vicidial With WebRTC

Vicidial With WebRTC VICIDial is well known open source call center software. It has been in use by many small to large scaled con...