GerryGerry
Member
- Joined
- Dec 26, 2015
- Messages
- 57
- Reaction score
- 9
Here is my first asterisk 'project' I'm posting it here as I'd like to shre what I've done in the hope that it will help others (if this is the wrong forum let me know). I'd also appreciate it if and 'gurus' would look at what I've done and comment on how they might have achived the same objective. That way everyone learns.
First you need to create and populate a table in a mySQL database, I did this on the test database
here is the code to create the SQL table:
I then added the following custom context to /ect/asterisk/extensions_custom.conf
Finally I added a custom destination and called it limit-calls as follows:-
To use,
Just call in from the administrators phone (replace the ZZZZZZZZ in first line of the limit calls context with this telephone number) and enter 1111 when prompted for the password finally dial the number on mins to limit the call or 0 to cancel.
First you need to create and populate a table in a mySQL database, I did this on the test database
here is the code to create the SQL table:
next I added the following functions to the /ect/asterisk/func_odbc.conf fileCREATE TABLE IF NOT EXISTS `calltime` (
`id` char(1) NOT NULL,
`seconds` int(4) NOT NULL DEFAULT '0',
`selected` tinyint(4) NOT NULL DEFAULT '0',
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `calltime`
--
INSERT INTO `calltime` (`id`, `seconds`, `selected`) VALUES
('0', 7200, 0),
('1', 60, 0),
('2', 120, 0),
('3', 180, 0),
('4', 240, 0),
('5', 300, 0),
('6', 360, 1),
('7', 720, 0),
('8', 780, 0),
('9', 840, 0),;
[LIMITCALLTIME]
dsn=MySQL-test
read=SELECT `seconds` from `calltime` WHERE `selected`=1
write=UPDATE `calltime` SET `selected`=1 WHERE id='${SQL_ESC(${ARG1})}'
[RESETCALLTIME]
dsn=MySQL-test
write=UPDATE `calltime` SET `selected`=0
I then added the following custom context to /ect/asterisk/extensions_custom.conf
[limit-calls]
exten => _X.,1,GotoIf($[${CALLERID(number)}=ZZZZZZZZZZ]?change)
exten => _X.,n,noop(number is ${CALLERID(number)} name is ${CALLERID(name)})
exten => _X.,n,noop(Limiting maximum call duration)
exten => _X.,n,Set(TIMELIMIT=${ODBC_LIMITCALLTIME()})
exten => _X.,n,noop(time retived was ${TIMELIMIT})
exten => _X.,n,Dial(SIP/101,120,S(${TIMELIMIT}))
exten => _X.,n,Hangup()
exten => _X.,n(change),Wait(1)
exten => _X.,n,Authenticate(1111)
exten => _X.,n,Read(newwait,please-enter-the&number, 1)
exten => _X.,n,Set(ODBC_RESETCALLTIME()=1)
exten => _X.,n,Set(ODBC_LIMITCALLTIME(${newwait})=1)
exten => _X.,n,SayDigits(${newwait})
exten => _X.,n,Hangup()
Finally I added a custom destination and called it limit-calls as follows:-
limit-calls,${EXTEN},1
and then created an inbound route and pointed it to this custom destination.To use,
Just call in from the administrators phone (replace the ZZZZZZZZ in first line of the limit calls context with this telephone number) and enter 1111 when prompted for the password finally dial the number on mins to limit the call or 0 to cancel.