Archive for the ‘Asterisk’ Category

MySql Trigger - Basic

Trigger คือการแทรกการกระทำ (Method/Function) ลงไว้ใน Database โดยสามารถใส่เงื่อนไขต่างๆได้เหมือนกับภาษาโปรแกรมทั่วไปครับ โดยเมื่อเกิด Query ใน Mysql แล้วตัว Database จะทำการไล่ Check ว่ามี Trigger ไหนตรงตามเงื่อนไขบ้าง และเรียกใช้งาน

การใช้ Trigger เป็นเหมือนดาบสองคม มีทั้งข้อดีแล้วข้อเสียครับ จะแจกแจงคร่าวๆเท่าที่พอนึกออกไว้ให้ครับ

+ ดูดีมีชาติตระกูล เร็ว (เร็วกว่าที่ส่งข้อมูลไปๆมาๆระหว่าง Mysql กับ Php/Server-side script อื่นๆ)

+ ทำบางอย่างที่ทำด้วยโค้ด Server-side script มาตราฐานไม่ได้ หรือไม่สะดวกนัก โดยการ Hook เข้าไปในระบบของ DB เลย

- Debug ยาก ยิ่งมีภาษาเพิ่มเข้ามาอีก ยิ่งเพิ่มความปวดหัว

- ยึดติดกับ Platform เนื่องจาก Trigger ไม่มีมาตราฐานชัดเจน ทำให้เมื่อย้ายไปใช้ตัวอื่นจะต้องศึกษาใหม่

Replacement

จริงๆ ในหลายๆกรณีก็ไม่จำเป็นต้องใช้ Trigger เช่นการ Update Table ที่เป็น Foreign key โดยสามารถใช้คำสั่ง Cascade ช่วยได้

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

Mysql Trigger พื้นฐาน

หน้าตาตัวอย่าง TriggerCREATE TRIGGER trigger_name BEFORE UPDATE ON table_name FOR EACH ROW BEGIN IF NEW.dirty=0 OR NEW.dirty=1 THEN SET NEW.dirty=1; ELSE SET NEW.dirty=0; END IF; END;

  • CREATE TRIGGER trigger_name คำสั่งสร้าง Trigger
  • BEFORE UPDATE Event หลักๆที่เราสามารถ Hook trigger ของเราเข้าไปได้ ได้แก่ INSERT, UPDATE, DELETE โดยสามารถเลือกว่าจะทำการ Hook ก่อนหรือหลัง (BEFORE / AFTER) Query เหล่านั้นได้
  • ON table_name เลือก Table ที่ต้องการให้ Trigger ทำงาน
  • หมายถึงข้อมูลเก่าก่อนที่จะเกิดการรัน Query นั้นๆ
  • นอกจากนี้ยังสามารถแทรก Query มาตราฐาน (INSERT,UPDATE,DELETE และอื่นๆ) ลงใน Trigger ได้เลยอีกด้วย ซึ่งเราสามารถนำตัวแปร ROW,OLD,NEW มาใช้งานได้เช่นกัน

สร้าง Trigger บน phpMyAdmin

ถ้าได้ลองเอาโค้ดตัวอย่างไปลอง Run ใน phpMyAdmin จะพบว่าไม่สามารถทำงานได้ ด้วย Error ที่อ่านไม่ค่อยจะเข้าใจนัก

เหตุผลphpMyAdmin ไม่สามารถ Run คำสั่งนี้ได้ เนื่องจากเกิดการสับสนเรื่อง Delimiter ของ Mysql กับ คำสั่งใน Trigger

วิธีการแก้ไข แก้ได้ด้วยการ เปลี่ยน Delimiter เป็นตัวอักษรอื่นแทน semicolon “;” ตามรูป

เปลี่ยน Delimiter ใน phpMyAdmin

ในตัวอย่างเปลี่ยนเป็น ;; แทนครับ โดยถ้าหากเราต้องการสั่งให้ phpMyAdmin ทำงานหลายๆ Query พร้อมกันก็ให้ใส่ ;; แทน ;

credit:http://blog.levelup.in.th/2009/06/29/mysql-trigger-basicmysql-trigger-basic/

  • Comments Off
InstallingBigBlueButton

How to install BigBlueButton like a real developer. :-)

These instructions will walk through how to install BigBlueButton from source onto Ubuntu. If you are using CentOS, seeInstallingBigBlueButtonCentOS. In most cases, you’ll want to install from packages, but if you want to really understand how BigBlueButton is setup, the following steps will show you how to install each component.

To start, you’ll need a computer running Ubuntu — either a physical machine or a virtual machine (VM). The easiest way to start with a VM images is to download a Ubuntu VM image from http://www.vmware.com/appliances/directory/va/147323/download and start it in VMWare Player

The only prerequisite is that your Ubuntu machine has a network connection.

  • To start, check if you have a network connection
  •  > ping www.google.com
    
    If you get an error saying yout eth0 is not connected, then fix it by:
    
      Check if it is using eth1 
    
    root@ubuntu904server:/usr/local# ifconfig -a
    eth1      Link encap:Ethernet  HWaddr 00:0c:29:dd:b4:51
              inet addr:192.168.0.154  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fedd:b451/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:4080349 errors:0 dropped:0 overruns:0 frame:0
              TX packets:3932137 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:1216680270 (1.2 GB)  TX bytes:822963271 (822.9 MB)
              Interrupt:19 Base address:0×2000
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:12938 errors:0 dropped:0 overruns:0 frame:0
              TX packets:12938 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:40299608 (40.2 MB)  TX bytes:40299608 (40.2 MB)
    
    root@ubuntu904server:/usr/local# vi /etc/udev/rules.d/70-persistent-net.rules
    Swap the two entries by eidting “NAME=eth1″ to “NAME=eth0″ and vice versa.
    
    Reboot your machine. 
    Check if you manage to connect to the internet. 
    If you are running on a Virtual Machine, make sure the VM’s network adapter is using a Bridged connection instead of NAT. 
    On the VMWare player this is enabled in the Devices menu at the top.
    
    More info can be found here http://ubuntuforums.org/showthread.php?t=221768
  • Once you have interner connection, update and upgrade.
  •   > sudo apt-get update
      > sudo apt-get upgrade
  • Install Java 6
  •  > apt-get install openjdk-6-jre-headless
  • Install MySQL
  •  > apt-get install mysql-server
  • Install Tomcat
  •   > apt-cache search tomcat
    
      > apt-get install tomcat6
  • Confirm that tomcat is running
  •   http://<YOUR IP>:8080/
  • Install swftools
  •   > apt-get install swftools
  • Install ImageMagick
  •   > apt-get install imagemagick
  • Install Nginx
  •   > apt-get install nginx
  • Install ActiveMQ
  •   > cd opt
      > wget http://apache.mirror.rafal.ca/activemq/apache-activemq/5.2.0/apache-activemq-5.2.0-bin.tar.gz
      > tar zxvf apache-activemq-5.2.0-bin.tar.gz
    
      Start ActiveMQ
      > /opt/apache-activemq-5.2.0/bin/activemq
  • Modify tomcat6 account
  •  > vi /etc/passwd
    
     Modify tomcat6 entry to this
      tomcat6:x:106:113::/usr/share/tomcat6:/bin/bash
  • Install red5
  •   > cd opt
      > wget http://build.xuggle.com/job/red5_jdk6_stable/131/artifact/workingcopy/red5-0.8.RC3-build-hudson-red5_jdk6_stable-131.tar.gz
      > tar zxvf red5-0.8.RC3-build-hudson-red5_jdk6_stable-131.tar.gz
      > mv red5-0.8.RC3-build-hudson-red5_jdk6_stable-131 red5-0.8
    
      Start red5 as tomcat6 user
      > sudo su -l tomcat6
      > red5.sh
  • Install oflaDemo
  • http://192.168.0.154:5080/
    
    Click on “Click here to install demos” and then choose oflaDemo java 6.
    
    http://192.168.0.154:5080/demos/
    
    http://192.168.0.154:5080/demos/ofla_demo.html
    
    Edit rtmp://192.168.0.154/oflaDemo and click connect
    
    You would see a list of available videos. Select one to play.
  • Prepare to install Asterisk
  • Some info found here http://godson.in/how-to-install-asterisk-on-ubuntu
    
     > apt-get install build-essential
     > apt-get install linux-headers-`uname -r`
     > apt-get install libssl-dev
     > apt-get install ncurses-dev
     > apt-get install libnewt-dev
     > apt-get install zlib1g-dev
     > apt-get install bison
  • Install Dahdi

You may have to find out what the newest version is. Go here

 > cd /usr/local/src
 > wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.2.0.2+2.2.0.tar.gz
 > tar zxvf dahdi-linux-complete-2.2.0.1+2.2.0.tar.gz
 > cd dahdi-linux-complete-2.2.0.1+2.2.0
 > make all
 > make install
 > make config
  • Install Asterisk
  •   > cd /usr/local/src
      > wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1.4.25.tar.gz
      > tar zxvf asterisk-1.4.25.tar.gz
      > cd asterisk-1.4.25
      > more README
      > ./configure
      > make
      > make install
      > make samples
      > make config
  • Modify Extensions
  • cd /tmp/
    wget http://bigbluebutton.googlecode.com/files/asterisk-extensions.conf
    cat asterisk-extensions.conf >> /etc/asterisk/extensions.conf 
  • Create SIP account
  • wget http://bigbluebutton.googlecode.com/files/asterisk-sip.conf
    cat asterisk-sip.conf >> /etc/asterisk/sip.conf
  • Create SIP Accounts to be used by Red5Phone
  • wget http://bigbluebutton.googlecode.com/files/asterisk-create-sip-accounts.sh
    chmod a+x asterisk-create-sip-accounts.sh
    ./asterisk-create-sip-accounts.sh
  • Test your SIP account
  •  Download Zoiper from here http://www.zoiper.com/zwin.php
    
     After installing Zoiper, start it and create a SIP account using the echotest user above.
    
     Then dial 600. You should be connected to the “Echo” application.
  • Create AMI account
  •  > vi /etc/asterisk/manager.conf
    
     Modify “enabled” to yes
    
    [general]
    
    enabled = yes
    
      Add the following at the bottom of the file
    
    ; BigBlueButton: Enable Red5 to connect
    [bbb]
    secret = secret
    permit = 0.0.0.0/0.0.0.0
    read = system,call,log,verbose,command,agent,user
    write = system,call,log,verbose,command,agent,user
  • Configure Nginx
  •  > vi /etc/nginx/sites-available/bigbluebutton
    
     Paste the following into the file and edit server_name with you IP.
    
    server {
         listen   80;
         server_name  192.168.0.136;
    
         access_log  /var/log/nginx/bigbluebutton.access.log;
    
          location ~ (/open/|/close/|/idle/|/send/) {
              proxy_pass         http://127.0.0.1:8088;
              proxy_redirect     off;
              proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    
              client_max_body_size       10m;
              client_body_buffer_size    128k;
    
              proxy_connect_timeout      90;
              proxy_send_timeout         90;
              proxy_read_timeout         90;
    
              proxy_buffering            off;
          }
    
           location /deskshare {
               proxy_pass         http://127.0.0.1:5080;
               proxy_redirect     default;
               proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
               client_max_body_size       10m;
               client_body_buffer_size    128k;
               proxy_connect_timeout      90;
               proxy_send_timeout         90;
               proxy_read_timeout         90;
               proxy_buffer_size          4k;
               proxy_buffers              4 32k;
               proxy_busy_buffers_size    64k;
               proxy_temp_file_write_size 64k;
               include    fastcgi_params;
           }
    
           location /bigbluebutton {
               proxy_pass         http://127.0.0.1:8080;
               proxy_redirect     default;
               proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    
               client_max_body_size       10m;
               client_body_buffer_size    128k;
    
               proxy_connect_timeout      90;
               proxy_send_timeout         90;
               proxy_read_timeout         90;
    
               proxy_buffer_size          4k;
               proxy_buffers              4 32k;
               proxy_busy_buffers_size    64k;
               proxy_temp_file_write_size 64k;
    
               include    fastcgi_params;
           }
    
            location / {
              root   /var/www/bigbluebutton-default;
              index  index.html index.htm;
            }
    
            location /client {
                    root    /var/www/bigbluebutton;
                    index  index.html index.htm;
            }
    
            #error_page  404  /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                    root   /var/www/nginx-default;
            }
    }
  • Enable the bigbluebutton nginx config
  • > ln -s /etc/nginx/sites-available/bigbluebutton /etc/nginx/sites-enabled/bigbluebutton
  • Download BigBlueButton
  •  > mkdir /home/user/temp
     > cd /home/user/temp
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Apps/ws/dist/bigbluebutton-apps-0.5.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Apps-Deskshare/ws/dist/webapps/deskshare.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Client/ws/client.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Web/ws/bigbluebutton-0.1.war
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Config/ws/web//*zip*/web.zip
     > wget http://www.bigbluebutton.org/hudson/job/bbb-trunk-apps-sip/ws/dist/webapps/sip.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/bbb-trunk-apps-video/ws/dist/webapps/video.tar.gz
  • Disable Security settings for TOMCAT6
  •   > vi /etc/default/tomcat6
    
      Edit and uncomment #TOMCAT6_SECURITY=yes to
    
      TOMCAT6_SECURITY=no
  • setup the database
  •  > mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 33
    Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
    
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
    
    mysql> create database bigbluebutton_dev;
    Query OK, 1 row affected (0.05 sec)
    
    mysql> grant all on bigbluebutton_dev.* to ‘bbb’@‘localhost’ identified by ’secret’;
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> commit;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  • Install BigBlueButton Web
  •  > cd /var/lib/tomcat6/webapps
     > cp /home/user/temp/bigbluebutton-0.1.war ./bigbluebutton.war
  • Determine PDF2SWF, CONVERT and GS applications
  •   Make a note of where pdf2swf is installed
      > which pdf2swf
    
      You should see something like
      /usr/bin/pdf2swf
    
      Make a note of where the convert application is installed
      > which convert
    
      You shoud see something like.
      /usr/bin/convert
    
      Note where GhostScript is installed
      > which gs
    
      You shoud see something like.
      /usr/bin/gs
  • Edit bbb-web properties
  •  > vi /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
    
    Change the following:
     - swfToolsDir to the directory where pdf2swf is located
     - imageMagickDir to the directory where convert is located
     - ghostScriptExec to point to the gs application
     - change bigbluebutton.web.serverURL=http://<YOUR IP>
    
    Your bigbluebutton.properties should resemble something like this
    
    #
    # These are the default properites for BigBlueButton Web application
    
    dataSource.url=jdbc:mysql://localhost/bigbluebutton_dev
    dataSource.username=bbb
    dataSource.password=secret
    
    swfToolsDir=/usr/bin
    imageMagickDir=/usr/bin
    presentationDir=/var/bigbluebutton
    ghostScriptExec=/usr/bin/gs
    
    beans.presentationService.swfToolsDir=${swfToolsDir}
    beans.presentationService.imageMagickDir=${imageMagickDir}
    beans.presentationService.presentationDir=${presentationDir}
    
    # Use fullpath to ghostscript executable since the exec names are different
    # for each platform.
    beans.presentationService.ghostScriptExec=${ghostScriptExec}
    
    #
    # This URL needs to reference the host running the tomcat server
    bigbluebutton.web.serverURL=http://192.168.0.154
    
    # This is a workaround for a problem converting PDF files, referenced at
    # http://groups.google.com/group/comp.lang.postscript/browse_thread/thread/c2e264ca76534ce0?pli=1
    noPdfMarkWorkaround=/etc/bigbluebutton/nopdfmark.ps
    beans.presentationService.noPdfMarkWorkaround=${noPdfMarkWorkaround}
  • Restart Tomcat6
  •  > /etc/init.d/tomcat6 restart
  • Check if database tables were created
  •  > mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 56
    Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
    
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
    
    mysql> use bigbluebutton_dev;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +—————————–+
    | Tables_in_bigbluebutton_dev |
    +—————————–+
    | account                     |
    | account_conference          |
    | account_user                |
    | conference                  |
    | permission                  |
    | role                        |
    | role_permission_rel         |
    | scheduled_session           |
    | user                        |
    | user_permission_rel         |
    | user_role_rel               |
    | voice_conference_bridge     |
    +—————————–+
    12 rows in set (0.00 sec)
    
    mysql> select * from user;
    +—-+———+———————+———–+———————+——————————————+—————-+
    | id | version | date_created        | full_name | last_updated        | password_hash                            | username       |
    +—-+———+———————+———–+———————+——————————————+—————-+
    |  1 |       0 | 2009-06-29 09:51:17 | Admin     | 2009-06-29 09:51:17 | d033e22ae348aeb5660fc2140aec35850c4da997 | admin@test.com |
    +—-+———+———————+———–+———————+——————————————+—————-+
    1 row in set (0.02 sec)
    
    mysql>
  • Create the Presentation Upload directory
  •  > mkdir /var/bigbluebutton
     > chown -R tomcat6:adm /var/bigbluebutton
     > chmod -R 777 /var/bigbluebutton
  • Install bbb-apps
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/bigbluebutton-apps-0.5.tar.gz ./
    
     > tar zxvf bigbluebutton-apps-0.5.tar.gz
     >  mv webapps/bigbluebutton ./
     > rm -rf bigbluebutton-apps-0.5.tar.gz webapps/
  • Edit BigBlueButton Apps properties
  •  > vi /opt/red5-0.8/webapps/bigbluebutton/WEB-INF/bigbluebutton.properties
    
    # Location for recordings
    recordingsDirectory=/var/bigbluebutton
    
    # These properties are for Asterisk Management Interface (AMI)
    ami.host=127.0.0.1
    ami.port=5038
    ami.username=bbb
    ami.password=secret
  • Uncommet RTMPT section of /opt/red5-0.8/conf/red5-core.xml
  • Install Xuggler
  •  Goto http://www.xuggle.com/xuggler/downloads/
    
      > cd /usr/local
      >  wget http://com.xuggle.s3.amazonaws.com/xuggler/xuggler-3.1.FINAL/xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh
    
      > chmod a+x xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh
      > ./xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh
  • Put Xuggler into PATH
  •   >  vi /etc/profile
    
     Add the following at the bottom of the file
    
    export XUGGLE_HOME=/usr/local/xuggler
    export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATH
    export PATH=$XUGGLE_HOME/bin:$PATH
  • Install Desk Share App
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/deskshare.tar.gz ./
     > tar zxvf deskshare.tar.gz
     >  rm deskshare.tar.gz
  • Install Video App
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/video.tar.gz ./
     > tar zxvf video.tar.gz
     >  rm video.tar.gz
  • Install Voice App
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/sip.tar.gz ./
     > tar zxvf sip.tar.gz
     >  rm sip.tar.gz
    
     Edit /opt/red5-0.8/webapps/sip/WEB-INF/bigbluebutton-sip.properties
    
     Point sip.server.host to the IP of your Asterisk installation
    
     sip.server.host=192.168.0.177
  • Install BigBlueButton Client
  •   > cd /var/www
      > mkdir bigbluebutton
      > cd bigbluebutton
      > cp /home/user/temp/client.tar.gz ./
      > tar zxvf client.tar.gz
      > rm client.tar.gz
  • Modify BBB client config in /var/www/bigbluebutton/client/conf/config.xml
  •  - Change the uri to your IP address
     - Change host=“conf/join-mock.xml” to host=“http://<YOUR IP:PORT>/bigbluebutton/conference-session/enter”
    
    <?xml version=“1.0″ ?>
    <config>
        <version>0.4</version>
        <porttest host=”192.168.0.136″ application=”video”/>
            <modules>
    
                    <module name=“VideoModule” url=“VideoModule.swf”
                            uri=“rtmp://192.168.0.136/video”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“ChatModule” url=“ChatModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            loadNextModule=“PresentationModule”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“ViewersModule” url=“ViewersModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            host=“conf/join-mock.xml”
                            onAppInitEvent=“LOAD” loadNextModule=“ChatModule”
                            onAppStartEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“ListenersModule” url=“ListenersModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            recordingHost=“http://192.168.0.136″
                            loadNextModule=“DeskShareModule”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“PresentationModule” url=“PresentationModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            host=“http://192.168.0.136″
                            loadNextModule=“ListenersModule”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
    
                    <module name=“DeskShareModule” url=“DeskShareModule.swf”
                            uri=“rtmp://192.168.0.136/deskShare”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                            loadNextModule=“PhoneModule”
                    />
    
                    <module name=“PhoneModule” url=“PhoneModule.swf”
                            uri=“rtmp://192.168.0.136/sip”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                            loadNextModule=“VideoModule”
                    />
            </modules>
    </config>
  • Install bbb-default pages
  •   > cd /var/www/
      > cp /home/user/temp/web.zip ./
      > apt-get install unzip
      > unzip -dc web.zip
      > mv c/web ./bigbluebutton-default
      > rm -rf c
  • Restart server apps
  •  * Start ActiveMQ
     * Start Red5 as tomcat6 user
     * Restart Tomcat
     * Restart Asterisk 
  • Try out BigBlueButton
  •  Go to http://<YOUR-IP> which should display the bbb web page.
    
     To use voice conference, using your zoiper, dial 1500 which will prompt you for the conference number.

BigBlueButton-dev letting everyone know that you are a real developer and you have installed BigBlueButton from source. :-)

  • Comments Off

Asterisk Fax bash script

For sending faxes through asterisk (once successfully set up) is very easy. You can make it do some funky things. To test to see if it works though I wrote this quick script;

#!/bin/sh
#
# Work fax number = 01618771111
#

FAXDATE=`date +%s-%N`
cat <<EOF >/tmp/fax-$FAXDATE.call
Channel: SIP/fax/01618771111
MaxRetries: 1
WaitTime: 20
Set: LOCALSTATIONID=Company Name
Set: LOCALHEADERINFO=Department
Set: REMOTESTATIONID=0161100000
Application: txfax
Data: /var/spool/asterisk/fax/11158588-200709211145.tiff|caller
EOF

mv /tmp/fax-$FAXDATE.call /var/spool/asterisk/outgoing/
  • Comments Off

Asterisk cdr mysql

Asterisk can store CDR records in a MySQL database, as an alternative to CSV text files and other database formats.

How to download cdr_mysql

Due to Mysql client libraries licensing, the Mysql billing application is no longer an integrated part of the Asterisk standard distribution. It is now located in the asterisk-addons CVS directory.

Follow the instructions on http://www.asterisk.org/index.php?menu=download for Subversion download

# cd /usr/src
# svn checkout http://svn.digium.com/svn/asterisk-addons/branches/1.2 asterisk-addons-1.2

You must have mysql and mysql-devel packages installed.

  • In an RPM-based Linux, you can check presence of MySQL like this:
    • rpm -qa | grep mysql
  • For debian or other dpkg-based systems, check like this:
    • dpkg -l mysql-server libmysqlclient*dev
  • In FreeBSD, you’ll find MySQL in the ports library, /usr/ports/databases/mysql4-server

Compile

# cd asterisk-addons-1.2
# make clean
# make
# make install

Check that in make stage that there are no mysql.h errors, which mean you are missing mysql-devel package

root@localhost asterisk-addons-1.2# make
./mkdep -fPIC -I../asterisk -D_GNU_SOURCE `ls *.c`
app_addon_sql_mysql.c:23:19: error: mysql.h: No such file or directory
cdr_addon_mysql.c:38:19: error: mysql.h: No such file or directory
cdr_addon_mysql.c:39:20: error: errmsg.h: No such file or directory
res_config_mysql.c:53:19: error: mysql.h: No such file or directory
res_config_mysql.c:54:27: error: mysql_version.h: No such file or directory
res_config_mysql.c:55:20: error: errmsg.h: No such file or directory

If make fails due to complaining about a missing “asterisk.h” file you can either copy this file from your asterisk directory, or create a soft link (”ln -s …”) for /usr/src/asterisk that points to your asterisk source directory.

Another way to resolve the missing “asterisk.h” file is to run the ./configure with option “–with-asterisk=” like
./configure –with-asterisk=MyAsteriskSourceDir

A sample configuration file, can be found on the cdr_mysql.conf page.

Copy the sample configuration file to /etc/asterisk/cdr_mysql.conf and edit it according to your requirements. Then edit your modules.conf to load cdr_addon_mysql.so and finally restart asterisk; before the restart you should, however, check that your cdr table has been created correctly and is accessible to the username and password you specified.

Table definitions for Asterisk cdr_mysql

This is the database definition you use to install in Mysql to support billing.

Create the database

mysql –user=root –password=password [-h dbhost]

CREATE DATABASE asterisk;

GRANT INSERT
ON asterisk.*
TO asterisk@localhost
IDENTIFIED BY ’yourpassword’;

USE asterisk;

CREATE TABLE `cdr` (
`calldate` datetime NOT NULL default ’0000-00-00 00:00:00′,
`clid` varchar(80) NOT NULL default ”,
`src` varchar(80) NOT NULL default ”,
`dst` varchar(80) NOT NULL default ”,
`dcontext` varchar(80) NOT NULL default ”,
`channel` varchar(80) NOT NULL default ”,
`dstchannel` varchar(80) NOT NULL default ”,
`lastapp` varchar(80) NOT NULL default ”,
`lastdata` varchar(80) NOT NULL default ”,
`duration` int(11) NOT NULL default ’0′,
`billsec` int(11) NOT NULL default ’0′,
`disposition` varchar(45) NOT NULL default ”,
`amaflags` int(11) NOT NULL default ’0′,
`accountcode` varchar(20) NOT NULL default ”,
`userfield` varchar(255) NOT NULL default ”
);

ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL default ”;
ALTER TABLE `cdr` ADD INDEX ( `calldate` );
ALTER TABLE `cdr` ADD INDEX ( `dst` );
ALTER TABLE `cdr` ADD INDEX ( `accountcode` );

Please note that the rights granted in GRANT above is the _least_ the asterisk user will need. To allow the user to do more than just add new data to the table, see the MySQL manual on the topic

for trunk version since 29 Dec 2007 must be:
GRANT INSERT, SELECT …
because cdr_addon_mysql now do DESC ‘cdr’; for check tables fields.

Hint: Copy and paste this SQL command into a text file, save it under an appropriate name, then execute the following command:

mysql –user=username –password=password databasename < nameoftextfile

Voila! The table is created for you. (:biggrin:)

An interesting note: on versions prior to v1.2, the name of the table, ‘cdr’, is hard-coded into the mysql interface, so if the table is created under a different name, the mysql CDR backend will not work. In v1.2 the table name is configurable via the “table=” option in cdr_mysql.conf

Yet another note: It probably isn’t a good idea to use the InnoDB engine. Asterisk keeps autocommit turned on by default; therefore, each INSERT query is its own transaction. This will cause the query to take significantly longer to execute. On my personal computer, the “clock time” penalty is about 4-7 times that of MyISAM on a default Ubuntu install. Please also note that the CDR table does not require the features that the InnoDB engine provides.

Storing the Unique ID

Q: It would appear that the “uniqueid” field is not being populated in the MySQL CDR DB. Is this an obsolete field or is a bug?

A: You need to define MYSQL_LOGUNIQUEID at compile time for it to use that field.

You have two options in /usr/src/asterisk-addons:
1. Either add CFLAGS+=-DMYSQL_LOGUNIQUEID to the Makefile.
Note that recently (around Asterisk 1.4.18 or before) this has changed to ASTCFLAGS+=-DMYSQL_LOGUNIQUEID
2. Or instead add a #define MYSQL_LOGUNIQUEID to the top of cdr_addon_mysql.c.

Finally perform the usual make clean, make, make install. Be sure to check the Makefile for the presence of this flag after having done a CVS update! You will most probably also want to index the uniqueid field in your cdr table to improve performance.

You will also have to add a `uniqueid` column in your mysql database after the `accountcode` column:

ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL default ”

after `accountcode`;

What would I need all this for? For example you are running an AGI script and would like to be able to related AGI data with the CDR table. The problem is that the AGI script will lose connection to the call as soon as the caller hangs up, so you’ll need a way to find the correct cdr entry (that’ll also be created only after the call has been completed).

Attention! The uniqueid field is not guaranteed to be unique across the different CDR entries, even though the name suggests exactly that.

If you get the following error while compiling cdr_mysql:

/usr/bin/ld: cannot find -lz

Make sure you have the zlib-devel package installed.

  • Comments Off

Asterisk RealTime Extensions

extconfig.conf Setup

Add the following line, swapping your own personal values if you wish:

extensions => mysql,asterisk,extensions_table

You can change mysql to odbc if you want to use odbc.
You can change asterisk to be the name of your database.
You can change extensions_table to be the name of the extensions table we will create below.

modules.conf Setup

Don’t forget to load the proper modules or Strange Things (TM) will happen.

autoload=yes

or explicitly list them out:

load => res_config_mysql.so
load => app_realtime.so
load => func_realtime.so
load => pbx_realtime.so

(props to Corydon76 for setting a few of us straight)

extensions.conf Setup

The way RealTime Extensions work is through a switch statement in the dialplan. Here is an example of my context:

[test]
;
; switch => Realtime/[context]@[family][/options]
; If context is not given, current context is default
; If family is not given, family of ‘extensions’ is default
;
switch => Realtime/mycontext@realtime_ext

This tells Asterisk that any call into the ‘test’ context are to be switched to RealTime using the context “mycontext” and the family name “realtime_ext”.

context is optional: (switch => Realtime/@realtime_ext) and if left off, RealTime will use the current context, in this case “test”.

family is also optional: (switch => Realtime/@) and if left off, RealTime will use the family name “extensions”.

Currently there are no supported options so you can leave it off.

The family name above can be anything you wish. Just be sure it matches the family name you have stored in extconfig.conf: ( realtime_ext => mysql,asterisk,extensions_table )

And YES! You can have multiple switches and multiple family names using this method.

NOTE: It seems like Asterisk 1.6.0 always matches the realtime context with the name of the static context that contains the switch statement. The above example will always seek for the “Test” context in the database and not for the “mycontext”. So you might as well use:

[test]
switch => Realtime

Database Table

Now lets create the table we need:

NOTE: You can use any table name you wish, just make sure the table name matches what you have the above family name bound to.

NOTE: You should REALLY add indices for the context, exten and priority columns, as your asterisk system might slow down considerably otherwise.

#
# Table structure for table `extensions_table`
#

CREATE TABLE `extensions_table` (
`id` int(11) NOT NULL auto_increment,
`context` varchar(20) NOT NULL default ”,
`exten` varchar(20) NOT NULL default ”,
`priority` tinyint(4) NOT NULL default ’0′,
`app` varchar(20) NOT NULL default ”,
`appdata` varchar(128) NOT NULL default ”,
PRIMARY KEY  (`context`,`exten`,`priority`),
KEY `id` (`id`)
) TYPE=MyISAM;

#
# Dumping data for table `extensions_table`
#

INSERT INTO `extensions_table` VALUES (1, ‘mycontext’, ‘_574555XXXX’, 1, ‘Wait’, ‘2′);
INSERT INTO `extensions_table` VALUES (2, ‘mycontext’, ‘_574555XXXX’, 2, ‘SayNumber’, ‘102′);
INSERT INTO `extensions_table` VALUES (3, ‘mycontext’, ‘2815551212′, 1, ‘Playback’, ‘pbx-invalid’);

Matthen Boehm writes:

Here are some “complicated” extensions that work in my RealTime extensions:

INSERT INTO `extensions` (`id`, `context`, `exten`, `priority`, `app`, `appdata`)
VALUES (5, ‘cytel’, ‘8322008630′, ‘1′, ‘Dial’, ‘SIP/3044,30′);

INSERT INTO `extensions` (`id`, `context`, `exten`, `priority`, `app`, `appdata`)
VALUES (7, ‘cytel’, ‘80′, ‘1′, ‘Voicemailmain’, ‘@cytel’);

INSERT INTO `extensions` (`id`, `context`, `exten`, `priority`, `app`, `appdata`)
VALUES (8, ‘cytel’, ‘_832.’, ‘1′, ‘Dial’, ‘SIP/${EXTEN}@66.88.74.85|30′);

INSERT INTO `extensions` (`id`, `context`, `exten`, `priority`, `app`, `appdata`)
VALUES (9, ‘cytel’, ‘_9X.’, ‘1′, ‘Dial’,
‘IAX2/devasterisk:asterisk@asterisk-alpha/${EXTEN}@cytel-internal’);

INSERT INTO `extensions` (`id`, `context`, `exten`, `priority`, `app`, `appdata`)
VALUES (10, ‘cytel’, ‘3013′, ‘1′, ‘Dial’, ‘SIP/3013|30′);

INSERT INTO `extensions` (`id`, `context`, `exten`, `priority`, `app`, `appdata`)
VALUES (11, ‘cytel’, ‘_3XXX’, ‘1′, ‘Dial’,
‘IAX2/devasterisk:asterisk@asterisk-alpha/${EXTEN}@cytel-internal’);

When calling a macro from the extensions_conf database you need to pipe delimit your appdata where asterisk doesn’t convert the commas to pipes when it parses the data. So an example of an extensions_conf insert statement for a Macro entry would look like:
Insert into extensions_conf (context,exten,priority,app,appdata) values (’internal’,'1234′,’1′,’Macro’,'ExtensionDial|1234|SIP/1234@gateway’);

In the database it would look like the following:

context exten priority app appdata
internal 1234 1 Macro ExtensionDial|1234|SIP/1234@gateway

Caveats

Although Asterisk can handle pattern extension names in a realtime DB, there is something you ought to know. They can severely slow down Asterisk.

Why?

Because Asterisk will first attempt to do a direct match db lookup first for any lookup by extension. If it succeeds, all is well. But if it does not succeed, then it will sequentially load every extension in the context, and sequentially test to see which best matches the input number. If you have a small number of extensions, this is usually not a big deal. But if you have hundreds or thousands of extensions, finding the best match could take several seconds!

So, as a rule of thumb, do not put extension patterns in your realtime database. In 1.6, there is code added to the core pbx to use a trie-based search that makes the pattern search time almost constant, no matter how many patterns. But this is not possible in a realtime database situation. It must continue to use the old technique which involves testing all patterns in a context to find the ‘best’ match, which grows exponentially slower with the number of patterns. If you absolutely must use patterns, keep them in the in-memory dialplan (extensions.ael, extensions.conf). Let the DB do the exact matches in large datasets that it is built for.

There is a patch which adds an option to the Realtime switch which disables the search for extension pattern in the database: http://bugs.digium.com/view.php?id=13698

One more thing: It is usually wise to separate program from data. Keep the logical control dialplan stuff in extensions.ael and extensions.conf, and reserve realtime lookups for true database lookups. Keep extensions.conf and extensions.ael in some sort of source-control system, like cvs, subversion, or git, so you can track your changes and have some backup. Just because you CAN store your dialplan in a database, doesn’t mean it would be practical, expedient, or right to do so.

Testing

Now place a call into the [test] context. Asterisk should query the associated database/table for the number you dialed.

So if you dial 5745558896, you should Wait(2), then hear Allison saying the numbers “one zero two”.

If you dial 2815551212 you would hear Allison saying “I’m sorry. That’s not a valid extension”

The ‘i’ and ’s’ extensions are currently not supported. The ‘t’ extension is supported.
Edit: Latest CVS will accept ‘i’ and ’s’ / rowitech

Note on using Goto and GotoIf in the extensions table (and DIAL!)

When using a Goto or GotoIf or Dial command you may only use ‘|’ in the app_data field of the command and not ‘,’. For example, the app_data field must take the form of context|s|1 and not context,s,1. Or if using dial, it should be SIP/user|60|Tt, not SIP/user,60,Tt.

Cheers,
Matthew… and now Phil too.


UPDATE
inserting extensions using id values in the examples doesn’t make any real sense on an autoincrement primary key field
INSERT INTO `extensions_table` VALUES (1, ‘mycontext’, ‘_574555XXXX’, 1, ‘Wait’, ‘2′);
would be better inserted as:
INSERT INTO `extensions_table` VALUES (NULL, ‘mycontext’, ‘_574555XXXX’, 1, ‘Wait’, ‘2′); etc
Cheers
  • Comments Off

ขั้นตอนการติดตั้ง Asterisk-GUI

  1. apt-get install subversion
  2. cd /usr/src/
  3. svn checkout http://svn.digium.com/svn/asterisk-gui/branches/2.0 asterisk-gui
  4. cd asterisk-gui
  5. ./configure
  6. make
  7. make install
  8. แก้ไขไฟล์ /etc/asterisk/manager.conf

    enabled = yes
    webenabled = yes
    [administrator]
    secret = mysecret
    read = system,call,log,verbose,command,agent,user,config
    write = system,call,log,verbose,command,agent,user,config
    –>แก้ไขไฟล์ /etc/asterisk/http.conf
    enabled=yes
    enablestatic=yes
    bindaddr=0.0.0.0
    ถ้ายังไม่สามารถแสดงหน้าเว็บได้ให้เพิ่ม
    prefix=asterisk ในบรรทัดสุดท้ายด้วย

  9. make checkconfig
  10. ทำการ reload asterisk และ restart apache
  11. ลบโฟล์เดอร์ static-http/ ใน /usr/share/asterisk/ ออก
  12. ทำ symbolic link ด้วยคำสั่ง ln -s /var/lib/asterisk/static-http/ /usr/share/asterisk/

การเรียกใช้งาน

  1. เรียกใช้ asterisk-gui ได้ที่ http://ip server asterisk-gui:8088/asterisk/static/config/index.html
  2. ในกรณีที่มีปัญหาเรื่อง Folder Permission ให้แก้ปัญหาโดยใช้คำสั่ง
    chmod -R 777 /var/lib/asterisk/static-http/
  • Comments Off

Time

Mp3

Msn status

  • manon2029@hotmail.com is

Chat with Meeh

Donate

    If you find an article useful, then please make a donation.

หมวดหมู่

UserOnline

Counter

  • Visitors today: 23
  • Visitors yesterday: 48
  • Visitors per day: 528
  • Max. visitors per day: 255
  • Total page views: 155,918
  • Page views of this page: 528
  • Currently online: 1
  • Max. online: 23
  • Total visitors: 33,987
  • counterStatistics