Asterisk status on pfSense2.0.1 webGUI



  • Here's a basic script I wrote which adds a new status page for Asterisk server running on the same box as pfSense. Very easy to install, just copy the code below to a file named status_asterisk.php in /usr/local/www

    /* $Id$ */
    /*
    	status_asterisk.php
    	part of pfSense
    	Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>.
    	All rights reserved.
    
    	originally part of m0n0wall (http://m0n0.ch/wall)
    	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
    	All rights reserved.
    
    	Redistribution and use in source and binary forms, with or without
    	modification, are permitted provided that the following conditions are met:
    
    	1\. Redistributions of source code must retain the above copyright notice,
    	   this list of conditions and the following disclaimer.
    
    	2\. Redistributions in binary form must reproduce the above copyright
    	   notice, this list of conditions and the following disclaimer in the
    	   documentation and/or other materials provided with the distribution.
    
    	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    	POSSIBILITY OF SUCH DAMAGE.
    */
    /*	
    	pfSense_MODULE:	asterisk
    */
    
    ##|+PRIV
    ##|*IDENT=page-status-asterisk
    ##|*NAME=Status: Asterisk page
    ##|*DESCR=Allow access to the 'Status: Asterisk' page.
    ##|*MATCH=status_asterisk.php*
    ##|-PRIV
    
    require_once("guiconfig.inc");
    
    $pgtitle = array(gettext("Status"),gettext("Asterisk"));
    include("head.inc");
    
    ?>
    
    /* Data input processing */
    $cmd =  $_GET['cmd'];
    $cmd  = str_replace("+", " ", $cmd);
    
    if ($cmd == "") {
    	$cmd = "core show version";
    }
    
    $file = $_SERVER["SCRIPT_NAME"];
    $break = Explode('/', $file);
    $pfile = $break[count($break) - 1]; 
    
    /* Print command buttons */
    echo "[]($pfile?cmd=sip+show+registry)";
    echo "[]($pfile?cmd=sip+show+peers)";
    echo "[]($pfile?cmd=sip+show+channels)";
    echo "[]($pfile?cmd=core+show+codecs+audio)";
    echo "[]($pfile?cmd=core+show+uptime)";
    
    /* Run commands and print results */
    $asterisk_command=shell_exec("asterisk -rx '$cmd'");
    echo "```
    ";
    echo $asterisk_command;
    echo "
    ```";
    ?></mk@neon1.net></sullrich@gmail.com> 
    

    To make it appear in the dropdown menu, edit /usr/local/www/fbegin.inc, add a new line after line 150 (// Status section, right after $status_menu = array();), like this:

    $status_menu[] = array("Asterisk", "/status_asterisk.php");
    

    And you'll get something like the attached picture.
    It queries asterisk locally using shell, no manager interface needed on asterisk side.



  • Banned

    I like that!



  • Maybe it will be the first alpha release of asterisk package to pfsense.  :)

    If freepbx runs on pfsense without issues, it will be a nice package option fro sip server/gatway/proxy.


  • Banned

    Yes :)



  • Also in status_services.php if you add this at lines 271 (below the similar ntpd entry), you'll get service status info, and start/stop commands will also work correctly.

    $pconfig = array();
    $pconfig['name'] = "asterisk";
    $pconfig['description'] = gettext("Asterisk VoIP telephony");
    $services[] = $pconfig;
    

    For the dashboard, in widgets/widgets/services_status.widget.php add this at line 76 (similarly below the similar ntpd entry):

    $svcconfig = array();
    $svcconfig['name'] = "asterisk";
    $svcconfig['description'] = gettext("Asterisk VoIP telephony");
    $services[] = $svcconfig;
    
    






  • @marcelloc:

    Maybe it will be the first alpha release of asterisk package to pfsense.  :)

    If freepbx runs on pfsense without issues, it will be a nice package option fro sip server/gatway/proxy.

    Got no clue how to make a pfSense-compatible full-blown package. Configuring Asterisk is no easy task at all, so beside status info, manual editing of config files remains for now.

    Fivn's Asterisk Managemnet GUI brings much more than these, all we need to do is make it run on the box, it's just a single script.


  • Banned

    Therefore Tommyboy180 or Marcello is the guys to talk to. They can make a pacakage happen and if one could use an alternate free product like Freepbx instead, then it would make a lot of PFSense… :D



  • I've extended the capability of my Asterisk Status page.

    • look & feel matching pfSense's skin
    • more useful status commands + reload
    • detailed callog, with option to download original CSV file, trim, clear
    • asterisk log, with option to trim, clear the file

    Download the attached status_asterisk.zip.xls file, and rename it to status_asterisk.zip.

    Copy status_asterisk.php, status_asterisk_calls.php, status_asterisk_log.php to /usr/local/www

    Good luck!



    status_asterisk.zip.xls



  • Updates:

    • calls list in reversed order
    • log lines 50 instead of 200

    (rename .xls to .zip after download)

    status_asterisk_v01_pfSense.zip.xls



  • This rocks !
    Any way this becomes an insstallable pfSense package ?  ::)



  • It will soon.  ;)



  • Update:

    • added a config file editor, based on original edit.php



    status_asterisk_v02.zip.xls



  • First package release is out.  :)

    http://forum.pfsense.org/index.php/topic,47210.msg248054.html#msg248054

    I did some changes to improve stability and checks for nanobsd or normal install.



  • HI

    and thats what i am looking for waiting for  only great

    and now my question
    is it possible to get info from an external asterisk?
    i have read that is possible that to make an ssh connect over php
    over an ssh connection that script would work or?

    thx max



  • You need to enable asterisk managment to get stats but this package has no options for remote connections. Maybe you can edit asterisk.Inc file and point to your remote server



  • The first part of your answer i understood but the second part i did totaly not.

    thx max



  • hi

    no idea ?

    max



  • Asterisk.Inc file is the script that creates asterisk config file. You can edit it to include your config to asterisk.


Locked