整合 SugarCRM 與 Asterisk

    簡介

    系統環境:

    • CentOS 5.8
    • SugarCRM CE 6.5
    • Asterisk 1.8.11
    • PHP 5.2

    安裝 SugarCRM CE

    官方教學:

    升級 PHP 到 5.3

    SugarCRM 6.x 必須安裝在 PHP 5.3+ 的環境,所以請先將 PHP 升級到 5.3,可參閱此篇 CentOS 5.5 升級至 PHP 5.3

    不要使用 PHP 5.2,此版本會使 SugarCRM 無法順利完成安裝

    下載軟體

    http://www.sugarforge.org/frs/?group_id=6

    wget http://www.sugarforge.org/frs/download.php/9248/SugarCE-6.5.0.zip
    unzip SugarCE-6.5.0.zip
    mv SugarCE-Full-6.5.0 /var/www/html/sugarcrm650 
    

    變更目錄權現

    cd /var/www/html/sugarcrm650/
    chown -R root:asterisk  cache/ custom/ modules/ upload/ config.php config_override.php sugarcrm.log
    chmod 0775 -R  cache/ custom/ modules/ upload/ config.php config_override.php sugarcrm.log 
    

    NOTE:

    Group asterisk 是指 apache 所執行的的 group name。

    修改 php.ini

    upload_max_filesize = 20M
    memory_limit = 256M 
    
    網頁安裝開始

    前往 http://<server.ip>/<sugarcrm directory>/install.php。

    安裝重點提示:

    Database Configuration

    Databas Name: sugarcrm

    Host Name: localhost

    Database Administrator Username: root

    Database Administrator Password: <管理員密碼>

    Sugar Database Name: Define user to create

    Sugar Database Username: sugar

    Sugar Database User Password: sugarpass

    Re-enter Sugar Database User Password: sugarpass

    Site Configuration

    Sugar Application Admin Name: admin

    Sugar Admin User Password: 登入密碼

    Re-eneter Sugar Admin User Password: 登入密碼

    安裝完成後,還需要做以下步驟

    編輯 <sugarcrm 根目錄>/.htaccess

    # BEGIN SUGARCRM RESTRICTIONS
    RedirectMatch 403 (?i)^.*\.log$
    RedirectMatch 403 (?i)/+not_imported_.*\.txt
    RedirectMatch 403 (?i)/+(soap|cache|xtemplate|data|examples|include|log4php|metadata|modules)/+.*\.(php|tpl)
    RedirectMatch 403 (?i)/+emailmandelivery\.php
    RedirectMatch 403 (?i)/+cache/+upload
    # END SUGARCRM RESTRICTIONS
    

    新增 cron jib

    crontab -e -u asterisk
    
    * * * * * cd /var/www/html/sugarcrm650 && /usr/bin/php -f cron.php 2>&1

    TIPs:

    asterisk 是指 apache 的用戶名稱

    有關 cron 的用途,請參閱 http://support.sugarcrm.com/04_Find_...bout_Cron_Jobs

    安裝 Yaai - Yet Another Asterisk Integration

    功能測試

    • Incoming Caller ID Popup 只能用在 IVR, RingGroup,對於 Queue 沒有作用。
       

    系統需求

    TIPs

    如何檢查 Asterisk Manager 版本?
    執行 telnet localhost 5038

    Trying 127.0.0.1...
    Connected to localhost.localdomain (127.0.0.1).
    Escape character is '^]'.
    Asterisk Call Manager/1.1

    Step1:使用 Module Loader 安裝 Yaai

    SugarCRM > Admin(右上角) > Administration > Module Loader > 選擇 *.zip 檔

    Step2:編輯 /etc/asterisk/manager.conf

    [dialog]
    secret = dialog
    deny = 0.0.0.0/0.0.0.0
    permit = 127.0.0.1/255.255.255.0
    read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
    write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
    

    Step3:複製 asteriskLogger.php
    將下載的 zip 檔解壓後

    cd misc/asteriskLogger_v6.1_AMIv1.1.php <sugarcrm>/custom/modules/Asterisk
    cd <sugarcrm>/custom/modules/Asterisk
    mv asteriskLogger.php asteriskLogger.php.default
    mv asteriskLogger_v6.1_AMIv1.1.php  asteriskLogger.php

    Step4:建立 asteriskLogger.php 的啟動檔

    /usr/local/bin/asterisk_Logger-start

    #!/bin/bash
    
    ###
    # quick and dirty start stop script
    # Parts of this code are (c) 2009 abcona e. K. Angelo Malaguarnera E-Mail admin@abcona.de
    #  http://www.sugarforge.org/projects/yaai/
    # gnu public licence
    #
    ###
    ###
    # modified by alang 2012/6/25
    #
    
    ###
    # Please edit this for your environment
    
    path=/var/www/html/sugarcrm650/custom/modules/Asterisk
    pid_file=/var/run/asterisk_Logger.pid
    
    ### finish to edit :-)
    
    start() {
            KIND="asteriskLogger"
            echo -n "Starting $KIND services: "
            # Checking if it's already running
            if [ -r $pid_file ]; then
               pid="$(cat $pid_file)"
               if [ "$(ps -ef | grep $pid | grep -v grep)" ]; then
                  echo " Running"
                  echo "The process ID is $pid"
                  echo
                  exit
               fi
            fi
    
            cd $path
            php asteriskLogger.php >> /var/log/asterisklogger&
            if [ $? -eq 0 ]; then
               pid="$!"
               echo " Done"
               echo "The process ID is $pid"
               echo "$pid" > $pid_file
               echo
            else
               echo " failed"
               echo
            fi
    
    }
    stop() {
            KIND="asterisklogger"
            echo -n $"Shutting down $KIND services: "
            if [ -r $pid_file ]; then
               pid=`cat $pid_file`
               kill $pid
               [ $? -eq 0 ] && echo " Done"
               rm $pid_file
               echo
               exit
            fi
            echo " failed"
            echo
    
    }
    restart() {
            stop
            start
    
    }
    case "$1" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      restart)
            restart
            ;;
     *)
            echo "Usage: $0 {start|stop|restart}"
            exit 2
    esac
    
    exit $?
    

    將開機啟動的指令寫在 /etc/rc.local

    Q & A

    Q: 開始網頁安裝時,發生錯誤: A common misconfiguration is that the 'session.save_path' directive is not pointing to a valid directory.

    Ans: 檢查 /etc/php.init 的參數 session.save_path 所設定的目錄,是否可讓 apache 寫入。

    Q: 網頁安裝過程,檢驗必要元件時,出現有關 MB Strings Module 錯誤

    Ans: 使用 yum 安裝缺少的模組

    yum install php-mbstring
    

    TIPs:

    如果 php 5.3 是由 php 5.1 升級上來的,必須要再加上 --enablerepo=<套件庫名稱>,否則會出現套件衝突的錯誤訊息。

    Q: 網頁安裝過程,檢驗目錄時,出現錯誤 Writable Upload Directory, Warning: Not Writable

    Ans: 檢查網頁檔目錄內的 upload 目錄是否有 apache 可寫入的權限。

    Q: 如果執行 amportal 出現以下錯誤

    Fetching FreePBX settings with gen_amp_conf.php..
    PHP Fatal error:  Call to undefined function posix_getpwuid() in /var/lib/asterisk/bin/gen_amp_conf.php on line 3

    Ans:這是因為升級 php 5.3 後,某個 php 模組被移除了,使用以下指令安裝

    yum --enablerepo=remi install php-posix
    或
    yum --enablerepo=remi install php-process
    
    Q: 執行asteriskLogger.php 發生錯誤

    錯誤:

    ! Error 0 connecting to Asterisk: Failed to parse address ""PHP Warning:  fsockopen(): unable to connect to :0 (Failed to parse address "") in /var/www/html/sugarcrm650/custom/modules/Asterisk/asteriskLogger.php on line 231

    Ans:檢查 SurgarCRM 的 Asterisk Configuration 是否與 manager.conf 的內容相符,如果是第一次安裝,請在 Asterisk Configuration 的表單上做一次儲存

    錯誤:

    PHP Warning:  Attempt to modify property of non-object in /var/www/html/sugarcrm650/include/nusoap/nusoap.php on line 6160

    Ans:這是 nusoap 在 PHP 5.3 的 bug,以下步驟可解

    編輯 <sugarcrm>/include/nusoap/class.wsdl.php
    搜尋 Schema imports

    ...
                    // Schema imports
                    foreach ($this->schemas as $ns => $list) {
                            // fixed for PHP5.3 by alang
                            //foreach ($list as $xs) {
                            foreach ($list as $ilist => $xs) {
    ...
    ...
                                            if (! $list2[$ii]['loaded']) {
                                                    // fixed for PHP5.3 by alang
                                                    //$this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
                                                    $this->schemas[$ns][$ilist]->imports[$ns2][$ii]['loaded'] = true;
    ... 
    

    編輯 <sugarcrm>/include/nusoap/nusoap.php
    搜尋 Schema imports

    ...
                    // Schema imports
                    foreach ($this->schemas as $ns => $list) {
                            // fixed for PHP5.3 by alang
                            //foreach ($list as $xs) {
                            foreach ($list as $ilist => $xs) {
    ...
    ...
                                            if (! $list2[$ii]['loaded']) {
                                                    // fixed for PHP5.3 by alang
                                                    //$this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
                                                    $this->schemas[$ns][$ilist]->imports[$ns2][$ii]['loaded'] = true;
    ... 
    
    Q: 檢查 sugarcrm.log 不斷出現錯誤

    [FATAL] Configuration variable date.timezone is not set, guessed timezone Asia/Chongqing. Please set date.timezone="Asia/Chongqing" in php.ini!

    Ans:修改 /etc/php.ini,重啟 apache 服務。

    date.timezone = Asia/Taipei
    
    Q: 當有電話撥入後,Web 會出現錯誤

    Call Record ID returned from server is -1, unable to save call notes for 0702500267 - 'Ringing'

    Ans:這是因為 Sugar 6.5.0 的密碼編碼改成 crypt(md5('yourpassword'),而 SOAP 僅支援 md5 編碼,所以 SOAP 認證始終失敗,解決方式是稍微修改 asteriskLogger.php。

    asteriskLogger.php:

    ...
    // Get SOAP config
    $sugarSoapEndpoint = $sugar_config['site_url'] . "/soap.php";
    $sugarSoapUser = $sugar_config['asterisk_soapuser'];
    $sugarSoapCredential = "";
    {
        $sql = "select user_hash from users where user_name='$sugarSoapUser'";
        $sqlResult = mysql_query($sql);
        if ($sqlResult)
        {
            $rowData = mysql_fetch_assoc($sqlResult);
            $sugarSoapCredential = $rowData['user_hash'];
        }
        else
        {
            echo "! FATAL: Cannot find login credentials for user $sugarSoapUser\n";
            die();
        }
    }
    
    // fixed for SugarCRM 650 by alang
    // Below is the username/password for SOAP connection
    $SOAP_USER="admin";
    $SOAP_PASS="osslab";
    
    $sugarSoapUser=$SOAP_USER;
    $sugarSoapCredential = md5($SOAP_PASS);
    
    //
    // And finally open a SOAP connection to SugarCRM
    //
    ... 
    

    NOTEs:

    SOAP_USER, SOAP_PASS 是 SugarCRM 的任一個用戶帳號/密碼。

     

    Q: 如何測試 SOAP 的認證

    Ans:建立一個 test.php

    test.php:

    <?php
    define('sugarEntry', TRUE);
    require_once('/var/www/html/sugarcrm650/include/nusoap/nusoap.php');
    
    $soap_username='admin';
    $soap_password='yourpass';
    $myWsdl = 'http://192.168.7.76/sugarcrm650/soap.php?wsdl';
    
    $myAuth = array(
            'user_name' => $soap_username,
            'password' => md5($soap_password),
    );
    $soapClient = new nusoap_client($myWsdl,true);
    
    $loginParams = array('user_auth' => $myAuth);
    $loginResult = $soapClient->call('login', $loginParams);
    $sessionId = $loginResult['id'];
    echo "[SESSIONID]= ".$sessionId ."\n";
    echo "[Encrypted PASS]= ".$myAuth['password']."\n";
    
    ?>
    

    TIPs:

    修改 soap_username, soap_password, myWsdl 路徑

    修改 require_once 路徑

    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core