Home » Asterisk » Asterisk manager Y.A.A.M

Posted on Jun 09, 2013  - Last updated on Aug 24, 2013
By Benoit Frigon

This is a web interface that i wrote to “manage” my Asterisk server. It is not meant at all to be an alternative to FreePbx and the like. It has very basic functionality : A call log viewer, voicemail manager, system log viewer and a few tools. You can’t add voicemail boxes, user extensions or modify the dialplan with this interface.

It has a plugin system, so you can add or remove features you don’t need.

Please note that this is still at an alpha stage, so don’t expect it to be plug-and-play. I have put the code there so that you can take it and adapt it to run on your server. Don’t expect me to provide support if it does not work for you, i just don’t have the time, sorry.

Source code

Get the source code here on Github

Screenshoots

MYSQL table structure

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| user    | varchar(40)  | NO   | MUL | NULL    |                |
| keyname | varchar(30)  | NO   |     | NULL    |                |
| value   | varchar(100) | YES  |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

table : cnam
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(11)      | NO   | PRI | NULL    | auto_increment |
| number   | varchar(32)  | YES  | UNI | NULL    |                |
| fullname | varchar(120) | YES  |     | NULL    |                |
| cidname  | varchar(15)  | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

table : cdr
+-------------+--------------+------+-----+---------------------+----------------+
| Field       | Type         | Null | Key | Default             | Extra          |
+-------------+--------------+------+-----+---------------------+----------------+
| id          | int(11)      | NO   | PRI | NULL                | auto_increment |
| calldate    | datetime     | NO   | MUL | 0000-00-00 00:00:00 |                |
| type        | varchar(40)  | NO   |     | NULL                |                |
| clid        | varchar(80)  | NO   | MUL | NULL                |                |
| src         | varchar(80)  | NO   |     | NULL                |                |
| dst         | varchar(80)  | NO   | MUL | NULL                |                |
| dcontext    | varchar(80)  | NO   |     | NULL                |                |
| channel     | varchar(80)  | NO   |     | NULL                |                |
| dstchannel  | varchar(80)  | NO   |     | NULL                |                |
| lastapp     | varchar(80)  | NO   |     | NULL                |                |
| lastdata    | varchar(80)  | NO   |     | NULL                |                |
| billsec     | int(11)      | NO   |     | 0                   |                |
| duration    | int(11)      | NO   |     | 0                   |                |
| amaflags    | int(11)      | NO   |     | 0                   |                |
| accountcode | varchar(20)  | NO   | MUL |                     |                |
| disposition | varchar(45)  | NO   |     | NULL                |                |
| route       | int(11)      | NO   |     | 0                   |                |
| cost        | float        | NO   |     | 0                   |                |
| uniqueid    | varchar(32)  | NO   |     |                     |                |
| userfield   | varchar(255) | YES  |     | NULL                |                |
+-------------+--------------+------+-----+---------------------+----------------+
20 rows in set (0.01 sec)

table : cdr_routes
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| priority   | int(11)     | NO   |     | 0       |                |
| name       | varchar(80) | NO   |     | NULL    |                |
| channel    | varchar(80) | NO   |     | NULL    |                |
| dcontext   | varchar(80) | NO   |     | NULL    |                |
| dst        | varchar(80) | NO   |     | NULL    |                |
| src        | varchar(80) | NO   |     | NULL    |                |
| dstchannel | varchar(80) | NO   |     | NULL    |                |
| type       | varchar(20) | NO   |     | NULL    |                |
| cost       | float       | NO   |     | NULL    |                |
| min        | int(11)     | NO   |     | 0       |                |
| increment  | int(11)     | NO   |     | 1       |                |
+------------+-------------+------+-----+---------+----------------+
12 rows in set (0.01 sec)

Call log

In addition to the tables above, i have setup a trigger in mysql to populate new cdr entries with additional data from cdr_routes based on origin context, destination number, etc.

tools/db_cdr_insert.sql view raw
DELIMITER $$
DROP TRIGGER IF EXISTS `asterisk`.`cdr_insert`$$ 
CREATE TRIGGER `cdr_insert` BEFORE INSERT ON cdr
FOR EACH ROW BEGIN

declare _matches INTEGER;
declare _id INTEGER;
declare _type VARCHAR(20);
declare _cost FLOAT;
declare _min INTEGER;
declare _inc INTEGER;

DECLARE EXIT HANDLER FOR NOT FOUND BEGIN 
    SET NEW.route=0;
    SET NEW.type='unknown';
    SET NEW.cost=0;
END;

SELECT id,cost,type,min,increment INTO _id, _cost, _type, _min, _inc 
    FROM cdr_routes 
    WHERE
    (channel = '' OR NEW.channel LIKE channel) AND 
    (dcontext = '' OR NEW.dcontext LIKE dcontext) AND
    (dstchannel = '' OR NEW.dstchannel LIKE dstchannel) AND
    (src = '' OR NEW.src LIKE src) AND
    (dst = '' OR NEW.dst LIKE dst) 
    ORDER BY priority
    LIMIT 1;

SET _inc = GREATEST(_inc, 1);

IF (NEW.billsec > 0) THEN 
    SET NEW.billsec = GREATEST(_min, ceil(NEW.billsec / _inc) * _inc);
END IF;

SET NEW.type = _type;
SET NEW.route = _id;
SET NEW.cost = (NEW.billsec/60) * _cost;

END;
$$

DELIMITER ;