Use Traits to simplify Sccp_Manager.class
Move helper functions to trait Move Ajax to trait (WIP - next step to create subclass to simplify initialisation) Rename Directories to eliminate punctuation Add new directory for traits
This commit is contained in:
parent
91986cb674
commit
f6bdd27335
|
@ -36,10 +36,10 @@ class aminterface
|
||||||
);
|
);
|
||||||
foreach ($drivers as $key => $value) {
|
foreach ($drivers as $key => $value) {
|
||||||
$class = $driverNamespace . "\\" . $key;
|
$class = $driverNamespace . "\\" . $key;
|
||||||
$driver = __DIR__ . "/aminterface/" . $value;
|
$driver = __DIR__ . "/amInterfaceClasses/" . $value;
|
||||||
if (!class_exists($class, false)) {
|
if (!class_exists($class, false)) {
|
||||||
if (file_exists($driver)) {
|
if (file_exists($driver)) {
|
||||||
include(__DIR__ . "/aminterface/" . $value);
|
include(__DIR__ . "/amInterfaceClasses/" . $value);
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception("Class required but file not found " . $driver);
|
throw new \Exception("Class required but file not found " . $driver);
|
||||||
}
|
}
|
384
SccpManTraits/ajaxHelper.php
Normal file
384
SccpManTraits/ajaxHelper.php
Normal file
|
@ -0,0 +1,384 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreePBX\modules\Sccp_manager\SccpManTraits;
|
||||||
|
|
||||||
|
trait ajaxHelper {
|
||||||
|
|
||||||
|
public function ajaxRequest($req, &$setting) {
|
||||||
|
// Called first by BMO. Must return true or request will be aborted.
|
||||||
|
// See https://wiki.freepbx.org/display/FOP/BMO+Ajax+Calls
|
||||||
|
switch ($req) {
|
||||||
|
case 'backupsettings':
|
||||||
|
case 'savesettings':
|
||||||
|
case 'save_hardware':
|
||||||
|
case 'save_sip_hardware':
|
||||||
|
case 'save_ruser':
|
||||||
|
case 'save_dialplan_template':
|
||||||
|
case 'delete_hardware':
|
||||||
|
case 'getPhoneGrid':
|
||||||
|
case 'getExtensionGrid':
|
||||||
|
case 'getDeviceModel':
|
||||||
|
case 'getUserGrid':
|
||||||
|
case 'getSoftKey':
|
||||||
|
case 'getDialTemplate':
|
||||||
|
case 'create_hw_tftp':
|
||||||
|
case 'reset_dev':
|
||||||
|
case 'reset_token':
|
||||||
|
case 'model_enabled':
|
||||||
|
case 'model_disabled':
|
||||||
|
case 'model_update':
|
||||||
|
case 'model_add':
|
||||||
|
case 'model_delete':
|
||||||
|
case 'update_button_label':
|
||||||
|
case 'updateSoftKey':
|
||||||
|
case 'deleteSoftKey':
|
||||||
|
case 'delete_dialplan':
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ajaxHandler is called after ajaxRequest returns true
|
||||||
|
public function ajaxHandler() {
|
||||||
|
$request = $_REQUEST;
|
||||||
|
$msg = array();
|
||||||
|
$cmd_id = $request['command'];
|
||||||
|
switch ($cmd_id) {
|
||||||
|
case 'savesettings':
|
||||||
|
$action = isset($request['sccp_createlangdir']) ? $request['sccp_createlangdir'] : '';
|
||||||
|
if ($action == 'yes') {
|
||||||
|
$this->initializeTFtpLanguagePath();
|
||||||
|
}
|
||||||
|
$this->handleSubmit($request);
|
||||||
|
// $this->saveSccpSettings();
|
||||||
|
//$this->createDefaultSccpConfig();
|
||||||
|
$this->createDefaultSccpXml();
|
||||||
|
|
||||||
|
$res = $this->aminterface->core_sccp_reload();
|
||||||
|
$msg [] = 'Config Saved: ' . $res['Response'];
|
||||||
|
$msg [] = 'Info :' . $res['data'];
|
||||||
|
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
|
||||||
|
return array('status' => true, 'message' => $msg, 'reload' => true);
|
||||||
|
break;
|
||||||
|
case 'save_sip_hardware':
|
||||||
|
case 'save_hardware':
|
||||||
|
$this->saveSccpDevice($request);
|
||||||
|
return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'sccpdevice');
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'save_ruser':
|
||||||
|
//$res = $request;
|
||||||
|
$res = $this->handleRoamingUsers($request);
|
||||||
|
return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'general');
|
||||||
|
break;
|
||||||
|
case 'save_dialplan_template':
|
||||||
|
/* !TODO!: -TODO-: dialplan templates should be removed (only required for very old devices (like ATA) */
|
||||||
|
// ------------------------------- Old + Sip device support - In the development---
|
||||||
|
$res = $this->saveDialPlan($request);
|
||||||
|
//public
|
||||||
|
if (empty($res)) {
|
||||||
|
return array('status' => true, 'search' => '?display=sccp_adv', 'hash' => 'sccpdialplan');
|
||||||
|
} else {
|
||||||
|
return array('status' => false, 'message' => print_r($res));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'delete_dialplan':
|
||||||
|
if (!empty($request['dialplan'])) {
|
||||||
|
$get_file = $request['dialplan'];
|
||||||
|
$res = $this->deleteDialPlan($get_file);
|
||||||
|
return array('status' => true, 'message' => 'Dial Template has been deleted ! ', 'table_reload' => true);
|
||||||
|
} else {
|
||||||
|
return array('status' => false, 'message' => print_r($res));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// ------------------------------- Old device support - In the development---
|
||||||
|
case 'delete_hardware':
|
||||||
|
if (!empty($request['idn'])) {
|
||||||
|
foreach ($request['idn'] as $idv) {
|
||||||
|
if ($this->strpos_array($idv, array('SEP', 'ATA', 'VG')) !== false) {
|
||||||
|
$this->dbinterface->write('sccpdevice', array('name' => $idv), 'delete', "name");
|
||||||
|
$this->dbinterface->write('sccpbuttons', array(), 'delete', '', $idv);
|
||||||
|
$this->deleteSccpDeviceXML($idv); // Концы в вводу !!
|
||||||
|
$this->aminterface->sccpDeviceReset($idv, 'reset');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array('status' => true, 'table_reload' => true, 'message' => 'Hardware device has been deleted! ');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'create_hw_tftp':
|
||||||
|
$ver_id = ' Test !';
|
||||||
|
if (!empty($request['idn'])) {
|
||||||
|
$models = array();
|
||||||
|
foreach ($request['idn'] as $idv) {
|
||||||
|
$this->deleteSccpDeviceXML($idv);
|
||||||
|
$models [] = array('name' => $idv);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->deleteSccpDeviceXML('all');
|
||||||
|
$models = $this->dbinterface->HWextension_db_SccpTableData("SccpDevice");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->createDefaultSccpXml(); // Default XML
|
||||||
|
$ver_id = ' on found active model !';
|
||||||
|
foreach ($models as $data) {
|
||||||
|
$ver_id = $this->createSccpDeviceXML($data['name']);
|
||||||
|
if ($ver_id == -1) {
|
||||||
|
return array('status' => false, 'message' => 'Error Create Configuration Divice :' . $data['name']);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($this->sccpvalues['siptftp']['data'] == 'on') { // Check SIP Support Enabled
|
||||||
|
$this->createSccpXmlSoftkey(); // Create Softkey Sets for SIP
|
||||||
|
}
|
||||||
|
// !TODO!: -TODO-: Do these returned message strings work with i18n ?
|
||||||
|
return array('status' => true, 'message' => 'Create new config files (version:' . $ver_id . ')');
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'reset_token':
|
||||||
|
case 'reset_dev':
|
||||||
|
$msg = '';
|
||||||
|
$msgr = array();
|
||||||
|
$msgr[] = 'Reset command send';
|
||||||
|
if (!empty($request['name'])) {
|
||||||
|
foreach ($request['name'] as $idv) {
|
||||||
|
$msg = strpos($idv, 'SEP-');
|
||||||
|
if (!(strpos($idv, 'SEP') === false)) {
|
||||||
|
if ($cmd_id == 'reset_token') {
|
||||||
|
$res = $this->aminterface->sccpDeviceReset($idv, 'tokenack');
|
||||||
|
$msgr[] = $msg . ' ' . $res['Response'] . ' ' . $res['data'];
|
||||||
|
} else {
|
||||||
|
$res = $this->aminterface->sccpDeviceReset($idv, 'reset');
|
||||||
|
$msgr[] = $msg . ' ' . $res['Response'] . ' ' . $res['data'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($idv == 'all') {
|
||||||
|
$dev_list = $this->aminterface->sccp_get_active_device();
|
||||||
|
foreach ($dev_list as $key => $data) {
|
||||||
|
if ($cmd_id == 'reset_token') {
|
||||||
|
if (($data['token'] == 'Rej') || ($data['status'] == 'Token ')) {
|
||||||
|
$res = $this->aminterface->sccpDeviceReset($idv, 'tokenack');
|
||||||
|
$msgr[] = 'Send Token reset to :' . $key;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$res = $this->aminterface->sccpDeviceReset($idv, 'reset');
|
||||||
|
$msgr[] = $res['Response'] . ' ' . $res['data'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array('status' => true, 'message' => $msgr, 'reload' => true);
|
||||||
|
break;
|
||||||
|
case 'update_button_label':
|
||||||
|
$msg = '';
|
||||||
|
$hw_list = array();
|
||||||
|
if (!empty($request['name'])) {
|
||||||
|
foreach ($request['name'] as $idv) {
|
||||||
|
if (!(strpos($idv, 'SEP') === false)) {
|
||||||
|
$hw_list[] = array('name' => $idv);
|
||||||
|
}
|
||||||
|
if ($idv == 'all') {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res = $this->updateSccpButtons($hw_list);
|
||||||
|
$msg .= $res['Response'] . ' raw: ' . $res['data'] . ' ';
|
||||||
|
return array('status' => true, 'message' => 'Update Butons Labels Complite ' . $msg, 'reload' => true);
|
||||||
|
case 'model_add':
|
||||||
|
$save_settings = array();
|
||||||
|
$key_name = array('model', 'vendor', 'dns', 'buttons', 'loadimage', 'loadinformationid', 'nametemplate');
|
||||||
|
$upd_mode = 'replace';
|
||||||
|
case 'model_update':
|
||||||
|
if ($request['command'] == 'model_update') {
|
||||||
|
$key_name = array('model','vendor','dns', 'buttons', 'loadimage', 'loadinformationid', 'nametemplate');
|
||||||
|
$upd_mode = 'update';
|
||||||
|
}
|
||||||
|
if (!empty($request['model'])) {
|
||||||
|
foreach ($key_name as $key => $value) {
|
||||||
|
if (!empty($request[$value])) {
|
||||||
|
$save_settings[$value] = $request[$value];
|
||||||
|
} else {
|
||||||
|
$save_settings[$value] = $this->val_null; // null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->dbinterface->write('sccpdevmodel', $save_settings, $upd_mode, "model");
|
||||||
|
return array('status' => true, 'table_reload' => true);
|
||||||
|
}
|
||||||
|
return $save_settings;
|
||||||
|
break;
|
||||||
|
case 'model_enabled':
|
||||||
|
$model_set = '1'; // fall through intentionally
|
||||||
|
case 'model_disabled':
|
||||||
|
if ($request['command'] == 'model_disabled') {
|
||||||
|
$model_set = '0';
|
||||||
|
}
|
||||||
|
$msg = '';
|
||||||
|
$save_settings = array();
|
||||||
|
if (!empty($request['model'])) {
|
||||||
|
foreach ($request['model'] as $idv) {
|
||||||
|
$this->dbinterface->write('sccpdevmodel', array('model' => $idv, 'enabled' => $model_set), 'update', "model");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array('status' => true, 'table_reload' => true);
|
||||||
|
break;
|
||||||
|
case 'model_delete':
|
||||||
|
if (!empty($request['model'])) {
|
||||||
|
$this->dbinterface->write('sccpdevmodel', array('model' => $request['model']), 'delete', "model");
|
||||||
|
return array('status' => true, 'table_reload' => true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'getDeviceModel':
|
||||||
|
switch ($request['type']) {
|
||||||
|
case 'all':
|
||||||
|
case 'extension':
|
||||||
|
case 'enabled':
|
||||||
|
$devices = $this->getSccpModelInformation($request['type'], $validate = true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (empty($devices)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
return $devices;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'deleteSoftKey':
|
||||||
|
if (!empty($request['softkey'])) {
|
||||||
|
$id_name = $request['softkey'];
|
||||||
|
unset($this->sccp_conf_init[$id_name]);
|
||||||
|
$this->createDefaultSccpConfig();
|
||||||
|
$msg = print_r($this->aminterface->core_sccp_reload(), 1);
|
||||||
|
return array('status' => true, 'table_reload' => true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'updateSoftKey':
|
||||||
|
if (!empty($request['id'])) {
|
||||||
|
$id_name = preg_replace('/[^A-Za-z0-9]/', '', $request['id']);
|
||||||
|
$this->sccp_conf_init[$id_name]['type'] = "softkeyset";
|
||||||
|
foreach ($this->extconfigs->getextConfig('keyset') as $keyl => $vall) {
|
||||||
|
if (!empty($request[$keyl])) {
|
||||||
|
$this->sccp_conf_init[$id_name][$keyl] = $request[$keyl];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->createDefaultSccpConfig();
|
||||||
|
|
||||||
|
// !TODO!: -TODO-: Check SIP Support Enabled
|
||||||
|
$this->createSccpXmlSoftkey();
|
||||||
|
$msg = print_r($this->aminterface->core_sccp_reload, 1);
|
||||||
|
return array('status' => true, 'table_reload' => true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'getSoftKey':
|
||||||
|
$result = array();
|
||||||
|
$i = 0;
|
||||||
|
$keyl = 'default';
|
||||||
|
foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
|
||||||
|
$result[$i]['softkeys'] = $keyl;
|
||||||
|
if ($keyl == 'default') {
|
||||||
|
foreach ($this->extconfigs->getextConfig('keyset') as $key => $value) {
|
||||||
|
$result[$i][$key] = str_replace(',', '<br>', $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($this->getMyConfig('softkeyset', $keyl) as $key => $value) {
|
||||||
|
$result[$i][$key] = str_replace(',', '<br>', $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
case 'getExtensionGrid':
|
||||||
|
$result = $this->dbinterface->HWextension_db_SccpTableData('SccpExtension');
|
||||||
|
if (empty($result)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
case 'getPhoneGrid':
|
||||||
|
$cmd_type = !empty($request['type']) ? $request['type'] : '';
|
||||||
|
|
||||||
|
$result = $this->dbinterface->HWextension_db_SccpTableData('SccpDevice', array('type' => $cmd_type));
|
||||||
|
if ($cmd_type == 'cisco-sip') {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
$staus = $this->aminterface->sccp_get_active_device();
|
||||||
|
if (empty($result)) {
|
||||||
|
$result = array();
|
||||||
|
} else {
|
||||||
|
foreach ($result as &$dev_id) {
|
||||||
|
$id_name = $dev_id['name'];
|
||||||
|
if (!empty($staus[$id_name])) {
|
||||||
|
$dev_id['description'] = $staus[$id_name]['descr'];
|
||||||
|
$dev_id['status'] = $staus[$id_name]['status'];
|
||||||
|
$dev_id['address'] = $staus[$id_name]['address'];
|
||||||
|
$dev_id['new_hw'] = 'N';
|
||||||
|
$staus[$id_name]['news'] = 'N';
|
||||||
|
} else {
|
||||||
|
$dev_id['description'] = '- -';
|
||||||
|
$dev_id['status'] = 'not connected';
|
||||||
|
$dev_id['address'] = '- -';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($staus)) {
|
||||||
|
foreach ($staus as $dev_ids) {
|
||||||
|
$id_name = $dev_ids['name'];
|
||||||
|
if (empty($dev_ids['news'])) {
|
||||||
|
$dev_data = $this->aminterface->sccp_getdevice_info($id_name);
|
||||||
|
if (!empty($dev_data['SCCP_Vendor']['model_id'])) {
|
||||||
|
$dev_addon = $dev_data['SCCP_Vendor']['model_addon'];
|
||||||
|
if (empty($dev_addon)) {
|
||||||
|
$dev_addon = null;
|
||||||
|
}
|
||||||
|
$dev_schema = $this->getSccpModelInformation('byciscoid', false, "all", array('model' => $dev_data['SCCP_Vendor']['model_id']));
|
||||||
|
if (empty($dev_schema)) {
|
||||||
|
$dev_schema[0]['model'] = "ERROR in Model Schema";
|
||||||
|
}
|
||||||
|
$result[] = array(
|
||||||
|
'name' => $id_name,
|
||||||
|
'mac' => $id_name,
|
||||||
|
'button' => '---',
|
||||||
|
'type' => $dev_schema[0]['model'],
|
||||||
|
'new_hw' => 'Y',
|
||||||
|
'description' => '*NEW* ' . $dev_ids['descr'],
|
||||||
|
'status' => '*NEW* ' . $dev_ids['status'],
|
||||||
|
'address' => $dev_ids['address'],
|
||||||
|
'addon' => $dev_addon
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
case 'getDialTemplate':
|
||||||
|
// ------------------------------- Old device support - In the development---
|
||||||
|
$result = $this->getDialPlanList();
|
||||||
|
if (empty($result)) {
|
||||||
|
$result = array();
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
case 'backupsettings':
|
||||||
|
// ------------------------------- Old device support - In the development---
|
||||||
|
$filename = $this->createSccpBackup();
|
||||||
|
$file_name = basename($filename);
|
||||||
|
|
||||||
|
header("Content-Type: application/zip");
|
||||||
|
header("Content-Disposition: attachment; filename=$file_name");
|
||||||
|
header("Content-Length: " . filesize($filename));
|
||||||
|
|
||||||
|
readfile($filename);
|
||||||
|
unlink($filename);
|
||||||
|
|
||||||
|
// return array('status' => false, 'message' => $result);
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
124
SccpManTraits/helperfunctions.php
Normal file
124
SccpManTraits/helperfunctions.php
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreePBX\modules\Sccp_manager\SccpManTraits;
|
||||||
|
|
||||||
|
trait helperfunctions {
|
||||||
|
|
||||||
|
function getIpInformation($type = '') {
|
||||||
|
$interfaces = array();
|
||||||
|
switch ($type) {
|
||||||
|
case 'ip4':
|
||||||
|
exec("/sbin/ip -4 -o addr", $result, $ret);
|
||||||
|
break;
|
||||||
|
case 'ip6':
|
||||||
|
exec("/sbin/ip -6 -o addr", $result, $ret);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
exec("/sbin/ip -o addr", $result, $ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
foreach ($result as $line) {
|
||||||
|
$vals = preg_split("/\s+/", $line);
|
||||||
|
if ($vals[3] == "mtu") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($vals[2] != "inet" && $vals[2] != "inet6") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (preg_match("/(.+?)(?:@.+)?:$/", $vals[1], $res)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$ret = preg_match("/(\d*+.\d*+.\d*+.\d*+)[\/(\d*+)]*/", $vals[3], $ip);
|
||||||
|
|
||||||
|
$interfaces[$vals[1] . ':' . $vals[2]] = array('name' => $vals[1], 'type' => $vals[2], 'ip' => ((empty($ip[1]) ? '' : $ip[1])));
|
||||||
|
}
|
||||||
|
return $interfaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function before($thing, $inthat) {
|
||||||
|
return substr($inthat, 0, strpos($inthat, $thing));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function array_key_exists_recursive($key, $arr) {
|
||||||
|
if (array_key_exists($key, $arr)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
foreach ($arr as $currentKey => $value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
return $this->array_key_exists_recursive($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function strpos_array($haystack, $needles) {
|
||||||
|
if (is_array($needles)) {
|
||||||
|
foreach ($needles as $str) {
|
||||||
|
if (is_array($str)) {
|
||||||
|
$pos = $this->strpos_array($haystack, $str);
|
||||||
|
} else {
|
||||||
|
$pos = strpos($haystack, $str);
|
||||||
|
}
|
||||||
|
if ($pos !== FALSE) {
|
||||||
|
return $pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return strpos($haystack, $needles);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function findAllFiles($dir, $file_mask = null, $mode = 'full') {
|
||||||
|
$result = null;
|
||||||
|
if (empty($dir) || (!file_exists($dir))) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
$root = scandir($dir);
|
||||||
|
foreach ($root as $value) {
|
||||||
|
if ($value === '.' || $value === '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (is_file("$dir/$value")) {
|
||||||
|
$filter = false;
|
||||||
|
if (!empty($file_mask)) {
|
||||||
|
if (is_array($file_mask)) {
|
||||||
|
foreach ($file_mask as $k) {
|
||||||
|
if (strpos(strtolower($value), strtolower($k)) !== false) {
|
||||||
|
$filter = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (strpos(strtolower($value), strtolower($file_mask)) !== false) {
|
||||||
|
$filter = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$filter = true;
|
||||||
|
}
|
||||||
|
if ($filter) {
|
||||||
|
if ($mode == 'fileonly') {
|
||||||
|
$result[] = "$value";
|
||||||
|
} else {
|
||||||
|
$result[] = "$dir/$value";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result[] = null;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$sub_fiend = $this->findAllFiles("$dir/$value", $file_mask, $mode);
|
||||||
|
if (!empty($sub_fiend)) {
|
||||||
|
foreach ($sub_fiend as $sub_value) {
|
||||||
|
if (!empty($sub_value)) {
|
||||||
|
$result[] = $sub_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -86,23 +86,13 @@ namespace FreePBX\modules;
|
||||||
|
|
||||||
class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
/* Field Values for type seq */
|
/* Field Values for type seq */
|
||||||
|
|
||||||
// const General - sccp.conf = '0';
|
|
||||||
// const General - sccp.conf[general] = '0';
|
|
||||||
// const General - sccp.conf[%keyset%] = '5'; NAME space
|
|
||||||
// const General - sccp.conf[%keyset%] = '6'; data
|
|
||||||
// const General - default.xml = '10';
|
|
||||||
// const General - template.xml = '20';
|
|
||||||
// const General - system_path = '2';
|
|
||||||
// const General - don't store = '99';
|
|
||||||
// private $SCCP_LANG_DICTIONARY = 'SCCP-dictionary.xml'; // CISCO LANG file search in /tftp-path
|
|
||||||
private $SCCP_LANG_DICTIONARY = 'be-sccp.jar'; // CISCO LANG file search in /tftp-path
|
private $SCCP_LANG_DICTIONARY = 'be-sccp.jar'; // CISCO LANG file search in /tftp-path
|
||||||
private $pagedata = null;
|
private $pagedata = null;
|
||||||
private $sccp_driver_ver = '11.4'; // Ver fore SCCP.CLASS.PHP
|
private $sccp_driver_ver = '11.4'; // Ver fore SCCP.CLASS.PHP
|
||||||
public $sccp_manager_ver = '14.0.0.2';
|
public $sccp_manager_ver = '14.0.0.2';
|
||||||
public $sccp_branch = 'm'; // Ver fore SCCP.CLASS.PHP
|
public $sccp_branch = 'm'; // Ver fore SCCP.CLASS.PHP
|
||||||
private $tftpLang = array();
|
private $tftpLang = array();
|
||||||
// private $hint_context = '@ext-local'; /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Get it from Config !!!
|
|
||||||
private $hint_context = array('default' => '@ext-local'); /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Get it from Config !!!
|
private $hint_context = array('default' => '@ext-local'); /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Get it from Config !!!
|
||||||
private $val_null = 'NONE'; /// REPLACE to null Field
|
private $val_null = 'NONE'; /// REPLACE to null Field
|
||||||
public $sccp_model_list = array();
|
public $sccp_model_list = array();
|
||||||
|
@ -115,6 +105,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
public $class_error; //error construct
|
public $class_error; //error construct
|
||||||
public $info_warning;
|
public $info_warning;
|
||||||
|
|
||||||
|
use \FreePBX\modules\Sccp_Manager\SccpManTraits\helperfunctions;
|
||||||
|
use \FreePBX\modules\Sccp_Manager\SccpManTraits\ajaxHelper;
|
||||||
|
|
||||||
public function __construct($freepbx = null) {
|
public function __construct($freepbx = null) {
|
||||||
if ($freepbx == null) {
|
if ($freepbx == null) {
|
||||||
throw new Exception("Not given a FreePBX Object");
|
throw new Exception("Not given a FreePBX Object");
|
||||||
|
@ -127,7 +120,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
// $this->v = new \Respect\Validation\Validator();
|
// $this->v = new \Respect\Validation\Validator();
|
||||||
$driverNamespace = "\\FreePBX\\Modules\\Sccp_manager";
|
$driverNamespace = "\\FreePBX\\Modules\\Sccp_manager";
|
||||||
if (class_exists($driverNamespace, false)) {
|
if (class_exists($driverNamespace, false)) {
|
||||||
foreach (glob(__DIR__ . "/Sccp_manager.inc/*.class.php") as $driver) {
|
foreach (glob(__DIR__ . "/SccpManClasses/*.class.php") as $driver) {
|
||||||
if (preg_match("/\/([a-z1-9]*)\.class\.php$/i", $driver, $matches)) {
|
if (preg_match("/\/([a-z1-9]*)\.class\.php$/i", $driver, $matches)) {
|
||||||
$name = $matches[1];
|
$name = $matches[1];
|
||||||
$class = $driverNamespace . "\\" . $name;
|
$class = $driverNamespace . "\\" . $name;
|
||||||
|
@ -638,383 +631,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxRequest($req, &$setting) {
|
|
||||||
// Called first by BMO. Must return true or request will be aborted.
|
|
||||||
// See https://wiki.freepbx.org/display/FOP/BMO+Ajax+Calls
|
|
||||||
switch ($req) {
|
|
||||||
case 'backupsettings':
|
|
||||||
case 'savesettings':
|
|
||||||
case 'save_hardware':
|
|
||||||
case 'save_sip_hardware':
|
|
||||||
case 'save_ruser':
|
|
||||||
case 'save_dialplan_template':
|
|
||||||
case 'delete_hardware':
|
|
||||||
case 'getPhoneGrid':
|
|
||||||
case 'getExtensionGrid':
|
|
||||||
case 'getDeviceModel':
|
|
||||||
case 'getUserGrid':
|
|
||||||
case 'getSoftKey':
|
|
||||||
case 'getDialTemplate':
|
|
||||||
case 'create_hw_tftp':
|
|
||||||
case 'reset_dev':
|
|
||||||
case 'reset_token':
|
|
||||||
case 'model_enabled':
|
|
||||||
case 'model_disabled':
|
|
||||||
case 'model_update':
|
|
||||||
case 'model_add':
|
|
||||||
case 'model_delete':
|
|
||||||
case 'update_button_label':
|
|
||||||
case 'updateSoftKey':
|
|
||||||
case 'deleteSoftKey':
|
|
||||||
case 'delete_dialplan':
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// !TODO!: this should go into it's only ajax.html.php file (see: dahdiconfig)
|
|
||||||
// ajaxHandler is called after ajaxRequest returns true
|
|
||||||
public function ajaxHandler() {
|
|
||||||
$request = $_REQUEST;
|
|
||||||
$msg = array();
|
|
||||||
$cmd_id = $request['command'];
|
|
||||||
switch ($cmd_id) {
|
|
||||||
case 'savesettings':
|
|
||||||
$action = isset($request['sccp_createlangdir']) ? $request['sccp_createlangdir'] : '';
|
|
||||||
if ($action == 'yes') {
|
|
||||||
$this->initializeTFtpLanguagePath();
|
|
||||||
}
|
|
||||||
$this->handleSubmit($request);
|
|
||||||
// $this->saveSccpSettings();
|
|
||||||
//$this->createDefaultSccpConfig();
|
|
||||||
$this->createDefaultSccpXml();
|
|
||||||
|
|
||||||
$res = $this->aminterface->core_sccp_reload();
|
|
||||||
$msg [] = 'Config Saved: ' . $res['Response'];
|
|
||||||
$msg [] = 'Info :' . $res['data'];
|
|
||||||
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
|
|
||||||
return array('status' => true, 'message' => $msg, 'reload' => true);
|
|
||||||
break;
|
|
||||||
case 'save_sip_hardware':
|
|
||||||
case 'save_hardware':
|
|
||||||
$this->saveSccpDevice($request);
|
|
||||||
return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'sccpdevice');
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'save_ruser':
|
|
||||||
//$res = $request;
|
|
||||||
$res = $this->handleRoamingUsers($request);
|
|
||||||
return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'general');
|
|
||||||
break;
|
|
||||||
case 'save_dialplan_template':
|
|
||||||
/* !TODO!: -TODO-: dialplan templates should be removed (only required for very old devices (like ATA) */
|
|
||||||
// ------------------------------- Old + Sip device support - In the development---
|
|
||||||
$res = $this->saveDialPlan($request);
|
|
||||||
//public
|
|
||||||
if (empty($res)) {
|
|
||||||
return array('status' => true, 'search' => '?display=sccp_adv', 'hash' => 'sccpdialplan');
|
|
||||||
} else {
|
|
||||||
return array('status' => false, 'message' => print_r($res));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'delete_dialplan':
|
|
||||||
if (!empty($request['dialplan'])) {
|
|
||||||
$get_file = $request['dialplan'];
|
|
||||||
$res = $this->deleteDialPlan($get_file);
|
|
||||||
return array('status' => true, 'message' => 'Dial Template has been deleted ! ', 'table_reload' => true);
|
|
||||||
} else {
|
|
||||||
return array('status' => false, 'message' => print_r($res));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// ------------------------------- Old device support - In the development---
|
|
||||||
case 'delete_hardware':
|
|
||||||
if (!empty($request['idn'])) {
|
|
||||||
foreach ($request['idn'] as $idv) {
|
|
||||||
if ($this->strpos_array($idv, array('SEP', 'ATA', 'VG')) !== false) {
|
|
||||||
$this->dbinterface->write('sccpdevice', array('name' => $idv), 'delete', "name");
|
|
||||||
$this->dbinterface->write('sccpbuttons', array(), 'delete', '', $idv);
|
|
||||||
$this->deleteSccpDeviceXML($idv); // Концы в вводу !!
|
|
||||||
$this->aminterface->sccpDeviceReset($idv, 'reset');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array('status' => true, 'table_reload' => true, 'message' => 'Hardware device has been deleted! ');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'create_hw_tftp':
|
|
||||||
$ver_id = ' Test !';
|
|
||||||
if (!empty($request['idn'])) {
|
|
||||||
$models = array();
|
|
||||||
foreach ($request['idn'] as $idv) {
|
|
||||||
$this->deleteSccpDeviceXML($idv);
|
|
||||||
$models [] = array('name' => $idv);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->deleteSccpDeviceXML('all');
|
|
||||||
$models = $this->dbinterface->HWextension_db_SccpTableData("SccpDevice");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->createDefaultSccpXml(); // Default XML
|
|
||||||
$ver_id = ' on found active model !';
|
|
||||||
foreach ($models as $data) {
|
|
||||||
$ver_id = $this->createSccpDeviceXML($data['name']);
|
|
||||||
if ($ver_id == -1) {
|
|
||||||
return array('status' => false, 'message' => 'Error Create Configuration Divice :' . $data['name']);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($this->sccpvalues['siptftp']['data'] == 'on') { // Check SIP Support Enabled
|
|
||||||
$this->createSccpXmlSoftkey(); // Create Softkey Sets for SIP
|
|
||||||
}
|
|
||||||
// !TODO!: -TODO-: Do these returned message strings work with i18n ?
|
|
||||||
return array('status' => true, 'message' => 'Create new config files (version:' . $ver_id . ')');
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'reset_token':
|
|
||||||
case 'reset_dev':
|
|
||||||
$msg = '';
|
|
||||||
$msgr = array();
|
|
||||||
$msgr[] = 'Reset command send';
|
|
||||||
if (!empty($request['name'])) {
|
|
||||||
foreach ($request['name'] as $idv) {
|
|
||||||
$msg = strpos($idv, 'SEP-');
|
|
||||||
if (!(strpos($idv, 'SEP') === false)) {
|
|
||||||
if ($cmd_id == 'reset_token') {
|
|
||||||
$res = $this->aminterface->sccpDeviceReset($idv, 'tokenack');
|
|
||||||
$msgr[] = $msg . ' ' . $res['Response'] . ' ' . $res['data'];
|
|
||||||
} else {
|
|
||||||
$res = $this->aminterface->sccpDeviceReset($idv, 'reset');
|
|
||||||
$msgr[] = $msg . ' ' . $res['Response'] . ' ' . $res['data'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($idv == 'all') {
|
|
||||||
$dev_list = $this->aminterface->sccp_get_active_device();
|
|
||||||
foreach ($dev_list as $key => $data) {
|
|
||||||
if ($cmd_id == 'reset_token') {
|
|
||||||
if (($data['token'] == 'Rej') || ($data['status'] == 'Token ')) {
|
|
||||||
$res = $this->aminterface->sccpDeviceReset($idv, 'tokenack');
|
|
||||||
$msgr[] = 'Send Token reset to :' . $key;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$res = $this->aminterface->sccpDeviceReset($idv, 'reset');
|
|
||||||
$msgr[] = $res['Response'] . ' ' . $res['data'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array('status' => true, 'message' => $msgr, 'reload' => true);
|
|
||||||
break;
|
|
||||||
case 'update_button_label':
|
|
||||||
$msg = '';
|
|
||||||
$hw_list = array();
|
|
||||||
if (!empty($request['name'])) {
|
|
||||||
foreach ($request['name'] as $idv) {
|
|
||||||
if (!(strpos($idv, 'SEP') === false)) {
|
|
||||||
$hw_list[] = array('name' => $idv);
|
|
||||||
}
|
|
||||||
if ($idv == 'all') {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$res = $this->updateSccpButtons($hw_list);
|
|
||||||
$msg .= $res['Response'] . ' raw: ' . $res['data'] . ' ';
|
|
||||||
return array('status' => true, 'message' => 'Update Butons Labels Complite ' . $msg, 'reload' => true);
|
|
||||||
case 'model_add':
|
|
||||||
$save_settings = array();
|
|
||||||
$key_name = array('model', 'vendor', 'dns', 'buttons', 'loadimage', 'loadinformationid', 'nametemplate');
|
|
||||||
$upd_mode = 'replace';
|
|
||||||
case 'model_update':
|
|
||||||
if ($request['command'] == 'model_update') {
|
|
||||||
$key_name = array('model','vendor','dns', 'buttons', 'loadimage', 'loadinformationid', 'nametemplate');
|
|
||||||
$upd_mode = 'update';
|
|
||||||
}
|
|
||||||
if (!empty($request['model'])) {
|
|
||||||
foreach ($key_name as $key => $value) {
|
|
||||||
if (!empty($request[$value])) {
|
|
||||||
$save_settings[$value] = $request[$value];
|
|
||||||
} else {
|
|
||||||
$save_settings[$value] = $this->val_null; // null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->dbinterface->write('sccpdevmodel', $save_settings, $upd_mode, "model");
|
|
||||||
return array('status' => true, 'table_reload' => true);
|
|
||||||
}
|
|
||||||
return $save_settings;
|
|
||||||
break;
|
|
||||||
case 'model_enabled':
|
|
||||||
$model_set = '1'; // fall through intentionally
|
|
||||||
case 'model_disabled':
|
|
||||||
if ($request['command'] == 'model_disabled') {
|
|
||||||
$model_set = '0';
|
|
||||||
}
|
|
||||||
$msg = '';
|
|
||||||
$save_settings = array();
|
|
||||||
if (!empty($request['model'])) {
|
|
||||||
foreach ($request['model'] as $idv) {
|
|
||||||
$this->dbinterface->write('sccpdevmodel', array('model' => $idv, 'enabled' => $model_set), 'update', "model");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array('status' => true, 'table_reload' => true);
|
|
||||||
break;
|
|
||||||
case 'model_delete':
|
|
||||||
if (!empty($request['model'])) {
|
|
||||||
$this->dbinterface->write('sccpdevmodel', array('model' => $request['model']), 'delete', "model");
|
|
||||||
return array('status' => true, 'table_reload' => true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'getDeviceModel':
|
|
||||||
switch ($request['type']) {
|
|
||||||
case 'all':
|
|
||||||
case 'extension':
|
|
||||||
case 'enabled':
|
|
||||||
$devices = $this->getSccpModelInformation($request['type'], $validate = true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (empty($devices)) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
return $devices;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'deleteSoftKey':
|
|
||||||
if (!empty($request['softkey'])) {
|
|
||||||
$id_name = $request['softkey'];
|
|
||||||
unset($this->sccp_conf_init[$id_name]);
|
|
||||||
$this->createDefaultSccpConfig();
|
|
||||||
$msg = print_r($this->aminterface->core_sccp_reload(), 1);
|
|
||||||
return array('status' => true, 'table_reload' => true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'updateSoftKey':
|
|
||||||
if (!empty($request['id'])) {
|
|
||||||
$id_name = preg_replace('/[^A-Za-z0-9]/', '', $request['id']);
|
|
||||||
$this->sccp_conf_init[$id_name]['type'] = "softkeyset";
|
|
||||||
foreach ($this->extconfigs->getextConfig('keyset') as $keyl => $vall) {
|
|
||||||
if (!empty($request[$keyl])) {
|
|
||||||
$this->sccp_conf_init[$id_name][$keyl] = $request[$keyl];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->createDefaultSccpConfig();
|
|
||||||
|
|
||||||
// !TODO!: -TODO-: Check SIP Support Enabled
|
|
||||||
$this->createSccpXmlSoftkey();
|
|
||||||
$msg = print_r($this->aminterface->core_sccp_reload, 1);
|
|
||||||
return array('status' => true, 'table_reload' => true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'getSoftKey':
|
|
||||||
$result = array();
|
|
||||||
$i = 0;
|
|
||||||
$keyl = 'default';
|
|
||||||
foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
|
|
||||||
$result[$i]['softkeys'] = $keyl;
|
|
||||||
if ($keyl == 'default') {
|
|
||||||
foreach ($this->extconfigs->getextConfig('keyset') as $key => $value) {
|
|
||||||
$result[$i][$key] = str_replace(',', '<br>', $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($this->getMyConfig('softkeyset', $keyl) as $key => $value) {
|
|
||||||
$result[$i][$key] = str_replace(',', '<br>', $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
break;
|
|
||||||
case 'getExtensionGrid':
|
|
||||||
$result = $this->dbinterface->HWextension_db_SccpTableData('SccpExtension');
|
|
||||||
if (empty($result)) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
break;
|
|
||||||
case 'getPhoneGrid':
|
|
||||||
$cmd_type = !empty($request['type']) ? $request['type'] : '';
|
|
||||||
|
|
||||||
$result = $this->dbinterface->HWextension_db_SccpTableData('SccpDevice', array('type' => $cmd_type));
|
|
||||||
if ($cmd_type == 'cisco-sip') {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
$staus = $this->aminterface->sccp_get_active_device();
|
|
||||||
if (empty($result)) {
|
|
||||||
$result = array();
|
|
||||||
} else {
|
|
||||||
foreach ($result as &$dev_id) {
|
|
||||||
$id_name = $dev_id['name'];
|
|
||||||
if (!empty($staus[$id_name])) {
|
|
||||||
$dev_id['description'] = $staus[$id_name]['descr'];
|
|
||||||
$dev_id['status'] = $staus[$id_name]['status'];
|
|
||||||
$dev_id['address'] = $staus[$id_name]['address'];
|
|
||||||
$dev_id['new_hw'] = 'N';
|
|
||||||
$staus[$id_name]['news'] = 'N';
|
|
||||||
} else {
|
|
||||||
$dev_id['description'] = '- -';
|
|
||||||
$dev_id['status'] = 'not connected';
|
|
||||||
$dev_id['address'] = '- -';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!empty($staus)) {
|
|
||||||
foreach ($staus as $dev_ids) {
|
|
||||||
$id_name = $dev_ids['name'];
|
|
||||||
if (empty($dev_ids['news'])) {
|
|
||||||
$dev_data = $this->aminterface->sccp_getdevice_info($id_name);
|
|
||||||
if (!empty($dev_data['SCCP_Vendor']['model_id'])) {
|
|
||||||
$dev_addon = $dev_data['SCCP_Vendor']['model_addon'];
|
|
||||||
if (empty($dev_addon)) {
|
|
||||||
$dev_addon = null;
|
|
||||||
}
|
|
||||||
$dev_schema = $this->getSccpModelInformation('byciscoid', false, "all", array('model' => $dev_data['SCCP_Vendor']['model_id']));
|
|
||||||
if (empty($dev_schema)) {
|
|
||||||
$dev_schema[0]['model'] = "ERROR in Model Schema";
|
|
||||||
}
|
|
||||||
$result[] = array(
|
|
||||||
'name' => $id_name,
|
|
||||||
'mac' => $id_name,
|
|
||||||
'button' => '---',
|
|
||||||
'type' => $dev_schema[0]['model'],
|
|
||||||
'new_hw' => 'Y',
|
|
||||||
'description' => '*NEW* ' . $dev_ids['descr'],
|
|
||||||
'status' => '*NEW* ' . $dev_ids['status'],
|
|
||||||
'address' => $dev_ids['address'],
|
|
||||||
'addon' => $dev_addon
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
break;
|
|
||||||
case 'getDialTemplate':
|
|
||||||
// ------------------------------- Old device support - In the development---
|
|
||||||
$result = $this->getDialPlanList();
|
|
||||||
if (empty($result)) {
|
|
||||||
$result = array();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
break;
|
|
||||||
case 'backupsettings':
|
|
||||||
// ------------------------------- Old device support - In the development---
|
|
||||||
$filename = $this->createSccpBackup();
|
|
||||||
$file_name = basename($filename);
|
|
||||||
|
|
||||||
header("Content-Type: application/zip");
|
|
||||||
header("Content-Disposition: attachment; filename=$file_name");
|
|
||||||
header("Content-Length: " . filesize($filename));
|
|
||||||
|
|
||||||
readfile($filename);
|
|
||||||
unlink($filename);
|
|
||||||
|
|
||||||
// return array('status' => false, 'message' => $result);
|
|
||||||
return $result;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function doGeneralPost() {
|
public function doGeneralPost() {
|
||||||
// $this->FreePBX->WriteConfig($config);
|
// $this->FreePBX->WriteConfig($config);
|
||||||
if (!isset($_REQUEST['Submit'])) {
|
if (!isset($_REQUEST['Submit'])) {
|
||||||
|
@ -1214,13 +830,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
$value = $get_settings[$hdr_prefix . 'netlang'] . ':' . $get_settings[$hdr_prefix . 'devlang'];
|
$value = $get_settings[$hdr_prefix . 'netlang'] . ':' . $get_settings[$hdr_prefix . 'devlang'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case '_json':
|
|
||||||
foreach ($get_settings[$hdr_arprefix . $key.'_sip'] as $vkey => $vval) {
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
if (!empty($get_settings[$hdr_prefix . $key])) {
|
if (!empty($get_settings[$hdr_prefix . $key])) {
|
||||||
$value = $get_settings[$hdr_prefix . $key];
|
$value = $get_settings[$hdr_prefix . $key];
|
||||||
|
@ -1386,16 +995,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
|
|
||||||
$save_buttons = array();
|
$save_buttons = array();
|
||||||
$save_settings = array();
|
$save_settings = array();
|
||||||
/*
|
|
||||||
$def_feature = array('parkinglot' => array('name' => 'P.slot', 'value' => 'default'),
|
|
||||||
'devstate' => array('name' => 'Coffee', 'value' => 'coffee'),
|
|
||||||
'monitor' => array('name' => 'Record Calls', 'value' => '')
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
$name_dev = '';
|
$name_dev = '';
|
||||||
$db_field = $this->dbinterface->HWextension_db_SccpTableData("get_columns_sccpuser");
|
$db_field = $this->dbinterface->HWextension_db_SccpTableData("get_columns_sccpuser");
|
||||||
// $hw_id = (empty($get_settings['sccp_deviceid'])) ? 'new' : $get_settings['sccp_deviceid'];
|
|
||||||
// $update_hw = ($hw_id == 'new') ? 'update' : 'clear';
|
|
||||||
$hw_prefix = 'SEP';
|
$hw_prefix = 'SEP';
|
||||||
$name_dev = $get_settings[$hdr_prefix . 'id'];
|
$name_dev = $get_settings[$hdr_prefix . 'id'];
|
||||||
$save_buttons = $this->getPhoneButtons($get_settings, $name_dev, 'sccpline');
|
$save_buttons = $this->getPhoneButtons($get_settings, $name_dev, 'sccpline');
|
||||||
|
@ -1614,26 +1215,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
$this->debugdata($engine);
|
$this->debugdata($engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
function soundlang_hookGet_config($engine) {
|
|
||||||
|
|
||||||
global $core_conf;
|
|
||||||
$this->debugdata($engine);
|
|
||||||
|
|
||||||
switch ($engine) {
|
|
||||||
case "asterisk":
|
|
||||||
if (isset($core_conf) && is_a($core_conf, "core_conf")) {
|
|
||||||
$language = FreePBX::Soundlang()->getLanguage();
|
|
||||||
if ($language != "") {
|
|
||||||
$core_conf->addSipGeneral('language', $language);
|
|
||||||
$core_conf->addIaxGeneral('language', $language);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve Active Codecs
|
* Retrieve Active Codecs
|
||||||
* return fiends Lag pack
|
* return fiends Lag pack
|
||||||
|
@ -2201,154 +1782,5 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
/* !TODO!: Update Hint info from sip DB ??? */
|
/* !TODO!: Update Hint info from sip DB ??? */
|
||||||
return $res_sort;
|
return $res_sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIpInformation($type = '') {
|
|
||||||
$interfaces = array();
|
|
||||||
switch ($type) {
|
|
||||||
case 'ip4':
|
|
||||||
exec("/sbin/ip -4 -o addr", $result, $ret);
|
|
||||||
break;
|
|
||||||
case 'ip6':
|
|
||||||
exec("/sbin/ip -6 -o addr", $result, $ret);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
exec("/sbin/ip -o addr", $result, $ret);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
foreach ($result as $line) {
|
|
||||||
$vals = preg_split("/\s+/", $line);
|
|
||||||
if ($vals[3] == "mtu") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($vals[2] != "inet" && $vals[2] != "inet6") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (preg_match("/(.+?)(?:@.+)?:$/", $vals[1], $res)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$ret = preg_match("/(\d*+.\d*+.\d*+.\d*+)[\/(\d*+)]*/", $vals[3], $ip);
|
|
||||||
|
|
||||||
$interfaces[$vals[1] . ':' . $vals[2]] = array('name' => $vals[1], 'type' => $vals[2], 'ip' => ((empty($ip[1]) ? '' : $ip[1])));
|
|
||||||
}
|
|
||||||
return $interfaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIpInformationOld() {
|
|
||||||
$interfaces['auto'] = array('0.0.0.0', 'All', '0');
|
|
||||||
|
|
||||||
exec("/sbin/ip -4 -o addr", $result, $ret);
|
|
||||||
foreach ($result as $line) {
|
|
||||||
$vals = preg_split("/\s+/", $line);
|
|
||||||
|
|
||||||
// We only care about ipv4 (inet) lines, or definition lines
|
|
||||||
if ($vals[2] != "inet" && $vals[3] != "mtu") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match("/(.+?)(?:@.+)?:$/", $vals[1], $res)) { // Matches vlans, which are eth0.100@eth0
|
|
||||||
// It's a network definition.
|
|
||||||
// This won't clobber an exsiting one, as it always comes
|
|
||||||
// before the IP addresses.
|
|
||||||
$interfaces[$res[1]] = array();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($vals[4] == "scope" && $vals[5] == "host") {
|
|
||||||
$int = 6;
|
|
||||||
} else {
|
|
||||||
$int = 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strip netmask off the end of the IP address
|
|
||||||
$ret = preg_match("/(\d*+.\d*+.\d*+.\d*+)[\/(\d*+)]*/", $vals[3], $ip);
|
|
||||||
$interfaces[$vals[$int]] = array($ip[1], $vals[$int], ((empty($ip[2]) ? '' : $ip[2])));
|
|
||||||
}
|
|
||||||
return $interfaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function before($thing, $inthat) {
|
|
||||||
return substr($inthat, 0, strpos($inthat, $thing));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function array_key_exists_recursive($key, $arr) {
|
|
||||||
if (array_key_exists($key, $arr)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
foreach ($arr as $currentKey => $value) {
|
|
||||||
if (is_array($value)) {
|
|
||||||
return $this->array_key_exists_recursive($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function strpos_array($haystack, $needles) {
|
|
||||||
if (is_array($needles)) {
|
|
||||||
foreach ($needles as $str) {
|
|
||||||
if (is_array($str)) {
|
|
||||||
$pos = $this->strpos_array($haystack, $str);
|
|
||||||
} else {
|
|
||||||
$pos = strpos($haystack, $str);
|
|
||||||
}
|
|
||||||
if ($pos !== FALSE) {
|
|
||||||
return $pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return strpos($haystack, $needles);
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function findAllFiles($dir, $file_mask = null, $mode = 'full') {
|
|
||||||
$result = null;
|
|
||||||
if (empty($dir) || (!file_exists($dir))) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$root = scandir($dir);
|
|
||||||
foreach ($root as $value) {
|
|
||||||
if ($value === '.' || $value === '..') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (is_file("$dir/$value")) {
|
|
||||||
$filter = false;
|
|
||||||
if (!empty($file_mask)) {
|
|
||||||
if (is_array($file_mask)) {
|
|
||||||
foreach ($file_mask as $k) {
|
|
||||||
if (strpos(strtolower($value), strtolower($k)) !== false) {
|
|
||||||
$filter = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (strpos(strtolower($value), strtolower($file_mask)) !== false) {
|
|
||||||
$filter = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$filter = true;
|
|
||||||
}
|
|
||||||
if ($filter) {
|
|
||||||
if ($mode == 'fileonly') {
|
|
||||||
$result[] = "$value";
|
|
||||||
} else {
|
|
||||||
$result[] = "$dir/$value";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result[] = null;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$sub_fiend = $this->findAllFiles("$dir/$value", $file_mask, $mode);
|
|
||||||
if (!empty($sub_fiend)) {
|
|
||||||
foreach ($sub_fiend as $sub_value) {
|
|
||||||
if (!empty($sub_value)) {
|
|
||||||
$result[] = $sub_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
|
|
@ -1,88 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
function removeSimpleXmlNode($node)
|
|
||||||
{
|
|
||||||
$dom = dom_import_simplexml($node);
|
|
||||||
$dom->parentNode->removeChild($dom);
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceSimpleXmlNode($xml, SimpleXMLElement $element) {
|
|
||||||
$dom = dom_import_simplexml($xml);
|
|
||||||
$import = $dom->ownerDocument->importNode(
|
|
||||||
dom_import_simplexml($element),TRUE
|
|
||||||
);
|
|
||||||
$dom->parentNode->replaceChild($import, $dom);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
function after($thing, $inthat)
|
|
||||||
{
|
|
||||||
if (!is_bool(strpos($inthat, $thing))) {
|
|
||||||
return substr($inthat, strpos($inthat, $thing) + strlen($thing));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function after_last($thing, $inthat)
|
|
||||||
{
|
|
||||||
if (!is_bool(strrevpos($inthat, $thing))) {
|
|
||||||
return substr($inthat, strrevpos($inthat, $thing) + strlen($thing));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function before($thing, $inthat)
|
|
||||||
{
|
|
||||||
return substr($inthat, 0, strpos($inthat, $thing));
|
|
||||||
}
|
|
||||||
|
|
||||||
function before_last($thing, $inthat)
|
|
||||||
{
|
|
||||||
return substr($inthat, 0, strrevpos($inthat, $thing));
|
|
||||||
}
|
|
||||||
|
|
||||||
function between($thing, $that, $inthat)
|
|
||||||
{
|
|
||||||
return before($that, after($thing, $inthat));
|
|
||||||
}
|
|
||||||
|
|
||||||
function between_last($thing, $that, $inthat)
|
|
||||||
{
|
|
||||||
return after_last($thing, before_last($that, $inthat));
|
|
||||||
}
|
|
||||||
|
|
||||||
function strrevpos($instr, $needle)
|
|
||||||
{
|
|
||||||
$rev_pos = strpos(strrev($instr), strrev($needle));
|
|
||||||
if ($rev_pos === false) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return strlen($instr) - $rev_pos - strlen($needle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function strpos_array($haystack, $needles)
|
|
||||||
{
|
|
||||||
if (is_array($needles)) {
|
|
||||||
foreach ($needles as $str) {
|
|
||||||
if (is_array($str)) {
|
|
||||||
$pos = strpos_array($haystack, $str);
|
|
||||||
} else {
|
|
||||||
$pos = strpos($haystack, $str);
|
|
||||||
}
|
|
||||||
if ($pos !== false) {
|
|
||||||
return $pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return strpos($haystack, $needles);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
Loading…
Reference in a new issue