function Aastra_manage_userinfo_Asterisk($user, $action, $array = NULL) { # Translate user if needed $user = Aastra_get_userdevice_Asterisk($user); # Connect to AGI $as = new AGI_AsteriskManager(); $res = $as->connect(); # Process action switch ($action) { # Read database case 'get': # No answer $return = array(); # Cell Phone $get = $as->database_get('AMPUSER', $user . '/info/cell'); if ($get) { $return['cell'] = $get; } # Home phone $get = $as->database_get('AMPUSER', $user . '/info/home'); if ($get) { $return['home'] = $get; } # Other phone $get = $as->database_get('AMPUSER', $user . '/info/other'); if ($get) { $return['other'] = $get; } break; # Set values # Set values case 'set': # Cell phone if ($array['cell']) { $res = $as->database_put('AMPUSER', $user . '/info/cell', $array['cell']); } else { $res = $as->database_del('AMPUSER', $user . '/info/cell'); } # Home phone if ($array['home']) { $res = $as->database_put('AMPUSER', $user . '/info/home', $array['home']); } else { $res = $as->database_del('AMPUSER', $user . '/info/home'); } # Cell phone if ($array['other']) { $res = $as->database_put('AMPUSER', $user . '/info/other', $array['other']); } else { $res = $as->database_del('AMPUSER', $user . '/info/other'); } # Return $return = $array; break; } # Disconnect properly $as->disconnect(); # Return return $return; }
$userresults = $db->getAll($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($userresults)) { $userresults = null; } $sql = "SELECT * FROM devices"; $devresults = $db->getAll($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($devresults)) { $devresults = null; } //add details to astdb $astman = new AGI_AsteriskManager(); if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"], $amp_conf["AMPMGRPASS"])) { $astman->database_deltree("AMPUSER"); foreach ($userresults as $usr) { extract($usr); $astman->database_put("AMPUSER", $extension . "/password", $password); $astman->database_put("AMPUSER", $extension . "/ringtimer", $ringtimer); $astman->database_put("AMPUSER", $extension . "/noanswer", $noasnwer); $astman->database_put("AMPUSER", $extension . "/recording", $recording); $astman->database_put("AMPUSER", $extension . "/outboundcid", "\"" . $outboundcid . "\""); $astman->database_put("AMPUSER", $extension . "/cidname", "\"" . $name . "\""); } $astman->database_deltree("DEVICE"); foreach ($devresults as $dev) { extract($dev); $astman->database_put("DEVICE", $id . "/dial", $dial); $astman->database_put("DEVICE", $id . "/type", $devicetype); $astman->database_put("DEVICE", $id . "/user", $user); $astman->database_put("AMPUSER", $user . "/device", $id); //voicemail symlink exec("rm -f /var/spool/asterisk/voicemail/device/" . $id);
} } $sql = "UPDATE zap SET data = '" . $extension . "@device' WHERE id = '" . $extension . "' AND keyword = 'mailbox' LIMIT 1"; $resu = $db->query($sql); } } } $name = substr($name, 0, strcspn($name, '<')); $name = rtrim($name, "\" "); $name = ltrim($name, "\" "); $recording = "out=" . $record_out . "|in=" . $record_in; $sql = "INSERT INTO users (extension,password,name,voicemail,ringtimer,noanswer,recording,outboundcid) values (\"{$extension}\",\"\",\"{$name}\",\"\",\"15\",\"\",\"{$recording}\",\"{$outboundcid}\")"; $insertresults = $db->query($sql); if (DB::IsError($insertresult)) { die($insertresults->getMessage()); } out("Creating a device for existing extension " . $extension); $sql = "INSERT INTO devices (id,tech,dial,devicetype,user,description) values (\"{$extension}\",\"{$tech}\",\"{$dial}\",\"fixed\",\"{$extension}\",\"{$name}\")"; $insertresults = $db->query($sql); if (DB::IsError($insertresult)) { die($insertresults->getMessage()); } out("Mapping user " . $extension . " to device " . $extension); $astman->database_put("AMPUSER", $extension . "/device", "\"" . $extension . "\""); $astman->database_put("DEVICE", $extension . "/user", "\"" . $extension . "\""); } } } else { fatal("Cannot connect to Asterisk Manager with " . $amp_conf["AMPMGRUSER"] . "/" . $amp_conf["AMPMGRPASS"]); } out("..OK");
function setrobstatus($account, $incomingvalue, $mode) { require_once 'common/php-asmanager.php'; $amp_conf = parse_amportal_conf("/etc/amportal.conf"); $hosts = split(',', $amp_conf['MANAGERHOSTS']); foreach ($hosts as $host) { $astman = new AGI_AsteriskManager(); if ($res = $astman->connect($host, $amp_conf["AMPMGRUSER"], $amp_conf["AMPMGRPASS"])) { if ($mode == "write") { if ($incomingvalue == "Never") { $astman->database_del("ROBCHECK", $account); } if ($incomingvalue == "Always") { $astman->database_put("ROBCHECK", $account, "ENABLED"); } $robstatus = null; } if ($mode == "read") { $existrobstatus = $astman->database_get("ROBCHECK", $account); if ($existrobstatus) { $robstatus = "Always"; } else { $robstatus = "Never"; } } $astman->disconnect(); } else { echo "<h3>Cannot connect to Asterisk Manager {$host} with " . $amp_conf["AMPMGRUSER"] . "/" . $amp_conf["AMPMGRPASS"] . "</h3>This module requires access to the Asterisk Manager. Please ensure Asterisk is running and access to the manager is available.</div>"; exit; } } return $robstatus; }