Skip to content

Instantly share code, notes, and snippets.

@multitel
Created January 19, 2016 19:37
Show Gist options
  • Save multitel/8e2b8f1c72b604ef09d0 to your computer and use it in GitHub Desktop.
Save multitel/8e2b8f1c72b604ef09d0 to your computer and use it in GitHub Desktop.
Asterisk CURL realtime sample CodeIgniter controller
Controller:
# ROUTING ENGINE ("re" controller)
## THIS IS JUST A SAMPLE
## MAKE SURE YOU PUT PROPER SECURITY MEASURES IN PLACE
## Use it along with this:
## https://wiki.asterisk.org/wiki/display/AST/cURL
##
## (c) MultiTEL - https://multitel.net
## Use at your own risk and however you want.
## Released under the "beerware" license.
class Re extends CI_Controller {
public function __construct() {
parent::__construct();
$this->ci =& get_instance();
error_reporting(1);
$http_host = $_SERVER['HTTP_HOST']; $remote = $_SERVER['REMOTE_ADDR'];
class_exists('voicemail_user_m') OR $this->ci->load->model('voicemail_user_m');
}
function sippeers($action='') {
$ci = &get_instance();
$data = $_REQUEST;
switch ($action) {
case 'single':
$account = $ci->sipfriend_m->get_by(array('name'=>$data['name']));
$output = http_build_query($account);
echo $output;
break;
case 'update':
$name = $_GET['name'];
if (!empty($_POST)) {
$account = $ci->sipfriend_m->update_by(
array(
'name' => $name
),
$_POST
);
}
break;
}
}
function voicemail($action='') {
$ci = &get_instance();
$data = $_REQUEST; $data['context'] = '';//we have no context defined in db yet
switch ($action) {
case 'multi':
$output = '';
$accounts = $ci->voicemail_user_m->get_many_by(array('context'=>$data['context']));
foreach ($accounts as $account) {
$output.= http_build_query($account)."\n";
}
echo $output;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment