Changeset 13276
- Timestamp:
- 01/30/12 13:55:32 (1 year ago)
- Files:
-
- modules/branches/2.10/endpointman/ari/modules/phonesettings.module (modified) (4 diffs)
- modules/branches/2.10/endpointman/functions.inc.php (modified) (1 diff)
- modules/branches/2.10/endpointman/includes/advanced.inc (modified) (4 diffs)
- modules/branches/2.10/endpointman/includes/functions.inc (modified) (119 diffs)
- modules/branches/2.10/endpointman/includes/popup.inc (modified) (1 diff)
- modules/branches/2.10/endpointman/install.php (modified) (5 diffs)
- modules/branches/2.10/endpointman/module.xml (modified) (1 diff)
- modules/branches/2.10/endpointman/provisioning/p.php (modified) (1 diff)
- modules/branches/2.10/endpointman/templates/freepbx/advanced_settings_settings.html (modified) (1 diff)
- modules/branches/2.10/endpointman/templates/freepbx/devices_manager.html (modified) (4 diffs)
- modules/branches/2.10/endpointman/templates/freepbx/specifics_pop.html (modified) (2 diffs)
- modules/branches/2.10/endpointman/templates/freepbx/template_editor.html (modified) (2 diffs)
- modules/branches/2.10/endpointman/templates/freepbx/variables.html (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.10/endpointman/ari/modules/phonesettings.module
r12954 r13276 72 72 73 73 $sql = "SELECT mac_id, line FROM endpointman_line_list WHERE ext = '".$_SESSION['ari_user']['extension']."' "; 74 $mac_row =& $endpoint-> db->getRow($sql, array(), DB_FETCHMODE_ASSOC);74 $mac_row =& $endpoint->eda->sql($sql, 'getrow', DB_FETCHMODE_ASSOC); 75 75 76 76 $mac_id = $mac_row['mac_id']; … … 109 109 110 110 $sql = "UPDATE endpointman_mac_list SET global_user_cfg_data = '".$custom_cfg_data."' WHERE id = ". $mac_id; 111 $endpoint-> db->query($sql);111 $endpoint->eda->sql($sql); 112 112 113 113 $reboot = isset($_REQUEST['epm_reboot'])?$_REQUEST['epm_reboot']:null; … … 149 149 die('No Database?'); 150 150 } 151 151 152 152 global $amp_conf; 153 153 … … 156 156 157 157 $endpoint = new endpointmanager(); 158 158 159 159 $sql = "SELECT mac_id, line FROM endpointman_line_list WHERE ext = '".$_SESSION['ari_user']['extension']."' "; 160 160 161 $res =& $endpoint-> db->query($sql);161 $res =& $endpoint->eda->sql($sql); 162 162 if($res->numRows()) { 163 163 164 $mac_row =& $endpoint-> db->getRow($sql, array(), DB_FETCHMODE_ASSOC);164 $mac_row =& $endpoint->eda->sql($sql, 'getrow', DB_FETCHMODE_ASSOC); 165 165 166 166 $mac_id = $mac_row['mac_id']; modules/branches/2.10/endpointman/functions.inc.php
r12912 r13276 150 150 } 151 151 } 152 } else {153 //Mac not set so delete154 $sql = "SELECT mac_id,luid FROM endpointman_line_list WHERE ext = ". $extdisplay;155 $macid = $endpoint->eda->sql($sql,'getRow',DB_FETCHMODE_ASSOC);156 if($macid) {157 //$endpoint->delete_line($macid['luid'], TRUE);158 }159 152 } 160 153 } modules/branches/2.10/endpointman/includes/advanced.inc
r12938 r13276 376 376 $phone_config = new $class(); 377 377 378 379 if((method_exists($phone_config,'display_options')) AND (method_exists($phone_config,'process_options'))) { 380 if(isset($_REQUEST['phone_options'])) { 381 $endpoint->tpl->assign("options", $phone_config->process_options()); 382 } else { 383 $endpoint->tpl->assign("options", $phone_config->display_options()); 384 } 385 } 386 387 388 378 //TODO: remove 389 379 $template_file_list[0]['value'] = "template_data_custom.xml"; 390 380 $template_file_list[0]['text'] = "template_data_custom.xml"; … … 448 438 $_POST['config_loc'] = $_POST['config_loc'] ."/"; 449 439 } 450 440 441 $tftp_writable = FALSE; 451 442 if((isset($_POST['config_loc'])) AND ($_POST['config_loc'] != "")) { 452 443 if((file_exists($_POST['config_loc'])) AND (is_dir($_POST['config_loc']))) { … … 454 445 $sql="UPDATE endpointman_global_vars SET value='" . $_POST['config_loc'] . "' WHERE var_name='config_location'"; 455 446 $endpoint->eda->sql($sql); 447 $tftp_writable = TRUE; 456 448 } else { 457 449 $endpoint->error['config_dir'] = "Directory Not Writable!"; 458 450 } 459 451 } else { 460 $endpoint->error['config_dir'] = "Not a Vaild Directory ";452 $endpoint->error['config_dir'] = "Not a Vaild Directory <br /> Try to run 'mkdir ".$_POST['config_loc']."' as root"; 461 453 } 462 454 } else { … … 464 456 } 465 457 458 //Check tftp server to make sure it's functioning if we are using it 459 if(($_POST['cfg_type'] == 'file') AND ($tftp_writable)) { 460 $endpoint->tftp_check(); 461 } 462 466 463 if((isset($_POST['enable_ari'])) AND ($_POST['enable_ari'] == "on")) { 467 464 $_POST['enable_ari'] = 1; modules/branches/2.10/endpointman/includes/functions.inc
r12938 r13276 1 1 <?php 2 2 3 /** 3 4 * Endpoint Manager Functions File … … 8 9 */ 9 10 class endpointmanager { 11 10 12 //Load this class upon construction of the class 11 13 … … 23 25 * @global object $db Pear DB information, we move this into a public variable 24 26 */ 27 25 28 function __construct() { 26 29 global $amp_conf; 27 require('abstraction/freepbx.inc'); 30 require_once('abstraction/freepbx.inc'); 31 require_once('json.inc'); 28 32 $this->eda = new epm_data_abstraction(); 29 33 … … 46 50 $this->global_cfg['disable_epm'] = TRUE; 47 51 } 48 49 //TODO: Possibly remove these as I don't believe anything uses them anymore 52 50 53 define("UPDATE_PATH", $this->global_cfg['update_server']); 51 define("VER", $this->global_cfg['version']); 52 //end possible removal 53 54 define("MODULES_PATH", $amp_conf['AMPWEBROOT'] . '/admin/modules/'); 55 54 define("MODULES_PATH", $amp_conf['AMPWEBROOT'] . '/admin/modules/'); 55 56 56 //Determine if local path is correct! 57 if (file_exists(MODULES_PATH."endpointman/")) {58 define("LOCAL_PATH", MODULES_PATH ."endpointman/");57 if (file_exists(MODULES_PATH . "endpointman/")) { 58 define("LOCAL_PATH", MODULES_PATH . "endpointman/"); 59 59 } else { 60 60 die("Can't Load Local Endpoint Manager Directory!"); … … 62 62 63 63 //Define the location of phone modules, keeping it outside of the module directory so that when the user updates endpointmanager they don't lose all of their phones 64 if (file_exists(MODULES_PATH."_ep_phone_modules/")) {65 define("PHONE_MODULES_PATH", MODULES_PATH ."_ep_phone_modules/");66 } else { 67 define("PHONE_MODULES_PATH", MODULES_PATH ."_ep_phone_modules/");64 if (file_exists(MODULES_PATH . "_ep_phone_modules/")) { 65 define("PHONE_MODULES_PATH", MODULES_PATH . "_ep_phone_modules/"); 66 } else { 67 define("PHONE_MODULES_PATH", MODULES_PATH . "_ep_phone_modules/"); 68 68 if (!file_exists(PHONE_MODULES_PATH)) { 69 69 mkdir(PHONE_MODULES_PATH, 0764); … … 77 77 mkdir(PHONE_MODULES_PATH . "temp/", 0764); 78 78 } 79 if (!file_exists(MODULES_PATH."_ep_phone_modules/")) {79 if (!file_exists(MODULES_PATH . "_ep_phone_modules/")) { 80 80 die('Endpoint Manager can not create the modules folder!'); 81 81 } … … 83 83 84 84 //include the local template class 85 if(file_exists(LOCAL_PATH."includes/rain.tpl.class.inc")) { 86 require(LOCAL_PATH."includes/rain.tpl.class.inc"); 87 } else { 88 die("Can't Load the Template Class"); 85 if (!class_exists('RainTPL')) { 86 if (file_exists(LOCAL_PATH . "includes/rain.tpl.class.inc")) { 87 require(LOCAL_PATH . "includes/rain.tpl.class.inc"); 88 } else { 89 die("Can't Load the Template Class"); 90 } 89 91 } 90 92 91 93 //Define error reporting 92 if (($this->global_cfg['debug']) AND (!isset($_REQUEST['quietmode']))) {94 if (($this->global_cfg['debug']) AND (!isset($_REQUEST['quietmode']))) { 93 95 error_reporting(E_ALL); 94 96 ini_set('display_errors', 1); … … 98 100 99 101 //Check if config location is writable and/or exists! 100 if (isset($this->global_cfg['config_location'])) {101 if (is_dir($this->global_cfg['config_location'])) {102 if (!is_writeable($this->global_cfg['config_location'])) {102 if (isset($this->global_cfg['config_location'])) { 103 if (is_dir($this->global_cfg['config_location'])) { 104 if (!is_writeable($this->global_cfg['config_location'])) { 103 105 $user = exec('whoami'); 104 106 $group = exec("groups"); 105 $this->error['config_location'] = "Configuration Directory is not writable!" .106 "<br />Please change the location: <a href='config.php?type=tool&display=epm_advanced'>Here</a>".107 "<br />Or run this command on SSH: 'chown -R ".$user.":".$group." ".$this->global_cfg['config_location']."' then 'chmod -R 777 ".$this->global_cfg['config_location']."'";107 $this->error['config_location'] = "Configuration Directory is not writable!" . 108 "<br />Please change the location: <a href='config.php?type=tool&display=epm_advanced'>Here</a>" . 109 "<br />Or run this command on SSH: 'chown -hR root:" . $group . " " . $this->global_cfg['config_location'] . "' then 'chmod g+w " . $this->global_cfg['config_location'] . "'"; 108 110 $this->global_cfg['diable_epm'] = TRUE; 109 111 } … … 113 115 } 114 116 } 115 117 116 118 $sql = 'SELECT value FROM `admin` WHERE `variable` LIKE CONVERT(_utf8 \'version\' USING latin1) COLLATE latin1_swedish_ci'; 117 119 118 120 preg_match('/^(\d*)\.(\d*)/', $this->eda->sql($sql, 'getone'), $versions); 119 121 … … 121 123 $this->global_cfg['amp_ver']['minor'] = $versions[2]; 122 124 123 $this->tpl = new RainTPL( LOCAL_PATH.'templates/freepbx', LOCAL_PATH.'templates/freepbx/compiled', '/admin/assets/endpointman/images' ); 124 125 126 if($this->global_cfg['disable_help']) { 125 $this->tpl = new RainTPL(LOCAL_PATH . 'templates/freepbx', LOCAL_PATH . 'templates/freepbx/compiled', '/admin/assets/endpointman/images'); 126 127 if ($this->global_cfg['disable_help']) { 127 128 $this->tpl->assign("disable_help", 1); 128 129 } 129 130 130 131 $this->tpl->assign("amp_ver", $this->global_cfg['amp_ver']['minor']); 131 132 } 133 134 /** 135 * @author http://www.php.net/manual/en/function.socket-create.php#43057 136 * @param type $host 137 * @param type $filename 138 * @return type 139 */ 140 function tftp_fetch($host, $filename) { 141 //first off let's check if this is installed or disabled 142 $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 143 144 // create the request packet 145 $packet = chr(0) . chr(1) . $filename . chr(0) . 'octet' . chr(0); 146 // UDP is connectionless, so we just send on it. 147 socket_sendto($socket, $packet, strlen($packet), 0x100, $host, 69); 148 149 $buffer = ''; 150 $port = ''; 151 $ret = ''; 152 $time = time(); 153 do { 154 $new_time = time() - $time; 155 if ($new_time > 5) { 156 break; 157 } 158 // $buffer and $port both come back with information for the ack 159 // 516 = 4 bytes for the header + 512 bytes of data 160 socket_recvfrom($socket, $buffer, 516, 0, $host, $port); 161 162 // add the block number from the data packet to the ack packet 163 $packet = chr(0) . chr(4) . substr($buffer, 2, 2); 164 // send ack 165 socket_sendto($socket, $packet, strlen($packet), 0, $host, $port); 166 167 // append the data to the return variable 168 // for large files this function should take a file handle as an arg 169 $ret .= substr($buffer, 4); 170 } while (strlen($buffer) == 516); // the first non-full packet is the last. 171 return $ret; 172 } 173 174 function tftp_check() { 175 $subject = shell_exec("netstat -luan --numeric-ports"); 176 if(preg_match('/:69\s/i', $subject)) { 177 $rand = md5(rand(10,2000)); 178 if(file_put_contents($this->global_cfg['config_location'].'TEST', $rand)) { 179 if($this->tftp_fetch('127.0.0.1','TEST') != $rand) { 180 $this->error['tftp_check'] = 'Local TFTP Server is not correctly configured'; 181 } 182 unlink($this->global_cfg['config_location'].'TEST'); 183 } else { 184 $this->error['tftp_check'] = 'Unable to write to '.$this->global_cfg['config_location']; 185 } 186 } else { 187 $dis = FALSE; 188 if (file_exists('/etc/xinetd.d/tftp')) { 189 $contents = file_get_contents('/etc/xinetd.d/tftp'); 190 if (preg_match('/disable.*=.*yes/i', $contents)) { 191 $this->error['tftp_check'] = 'Disabled is set to "yes" in /etc/xinetd.d/tftp. Please fix <br />Then restart your TFTP service'; 192 $dis = TRUE; 193 } 194 } 195 if(!$dis) { 196 $this->error['tftp_check'] = 'TFTP Server is not running. <br />'. 197 'See here for instructions on how to install one: <a href="http://wiki.provisioner.net/index.php/Tftp" target="_blank">http://wiki.provisioner.net/index.php/Tftp</a>'; 198 199 } 200 } 201 132 202 } 133 203 … … 150 220 * @param <type> $data The config file's data 151 221 */ 152 function submit_config($brand, $product,$orig_name,$data) {222 function submit_config($brand, $product, $orig_name, $data) { 153 223 $posturl = 'http://www.provisioner.net/submit_config.php'; 154 224 155 $fp = fopen(LOCAL_PATH .'data.txt', 'w');225 $fp = fopen(LOCAL_PATH . 'data.txt', 'w'); 156 226 fwrite($fp, $data); 157 227 fclose($fp); 158 $file_name_with_full_path = LOCAL_PATH ."data.txt";159 160 $postvars = array('brand' => $brand, 'product' => $product, 'origname' => htmlentities(addslashes($orig_name)), 'file_contents'=>'@'.$file_name_with_full_path);228 $file_name_with_full_path = LOCAL_PATH . "data.txt"; 229 230 $postvars = array('brand' => $brand, 'product' => $product, 'origname' => htmlentities(addslashes($orig_name)), 'file_contents' => '@' . $file_name_with_full_path); 161 231 162 232 $ch = curl_init($posturl); … … 170 240 ob_start(); 171 241 header("Content-Type: text/html"); 172 $Final_Out =ob_get_clean();242 $Final_Out = ob_get_clean(); 173 243 curl_close($ch); 174 244 unlink($file_name_with_full_path); … … 179 249 function prepare_message_box() { 180 250 $error_message = NULL; 181 foreach ($this->error as $key => $error) {251 foreach ($this->error as $key => $error) { 182 252 $error_message .= $error; 183 if ($this->global_cfg['debug']) {184 $error_message .= " Function: [" .$key."]";253 if ($this->global_cfg['debug']) { 254 $error_message .= " Function: [" . $key . "]"; 185 255 } 186 256 $error_message .= "<br />"; 187 257 } 188 258 $message = NULL; 189 foreach ($this->message as $key => $error) {190 if (is_array($error)) {191 foreach ($error as $sub_error) {259 foreach ($this->message as $key => $error) { 260 if (is_array($error)) { 261 foreach ($error as $sub_error) { 192 262 $message .= $sub_error; 193 263 if ($this->global_cfg['debug']) { … … 199 269 $message .= $error; 200 270 if ($this->global_cfg['debug']) { 201 $message .= " Function: [" . $key . "]";271 $message .= " Function: [" . $key . "]"; 202 272 } 203 273 $message .= "<br />"; … … 205 275 } 206 276 207 if (isset($message)) {208 $this->display_message_box($message, 0);209 } 210 211 if (isset($error_message)) {212 $this->display_message_box($error_message, 1);277 if (isset($message)) { 278 $this->display_message_box($message, 0); 279 } 280 281 if (isset($error_message)) { 282 $this->display_message_box($error_message, 1); 213 283 } 214 284 } … … 258 328 * @return array 259 329 */ 260 function get_brand_from_mac($mac) {330 function get_brand_from_mac($mac) { 261 331 //Check for valid mac address first 262 if (!$this->mac_check_clean($mac)) {332 if (!$this->mac_check_clean($mac)) { 263 333 return(FALSE); 264 334 } 265 335 266 336 //Get the OUI only 267 $oui = substr($this->mac_check_clean($mac), 0,6);337 $oui = substr($this->mac_check_clean($mac), 0, 6); 268 338 //Find the matching brand model to the oui 269 $oui_sql = "SELECT endpointman_brand_list.name, endpointman_brand_list.id FROM endpointman_oui_list, endpointman_brand_list WHERE oui LIKE '%" . $oui ."%' AND endpointman_brand_list.id = endpointman_oui_list.brand AND endpointman_brand_list.installed = 1 LIMIT 1";339 $oui_sql = "SELECT endpointman_brand_list.name, endpointman_brand_list.id FROM endpointman_oui_list, endpointman_brand_list WHERE oui LIKE '%" . $oui . "%' AND endpointman_brand_list.id = endpointman_oui_list.brand AND endpointman_brand_list.installed = 1 LIMIT 1"; 270 340 $brand = $this->eda->sql($oui_sql, 'getRow', DB_FETCHMODE_ASSOC); 271 341 … … 275 345 if (!$brand_count) { 276 346 //oui doesn't have a matching mysql reference, probably a PC/router/wap/printer of some sort. 277 $phone_info['id'] = 0;278 $phone_info['name'] = _("Unknown");279 } else { 280 $phone_info['id'] = $brand['id'];281 $phone_info['name'] = $brand['name'];347 $phone_info['id'] = 0; 348 $phone_info['name'] = _("Unknown"); 349 } else { 350 $phone_info['id'] = $brand['id']; 351 $phone_info['name'] = $brand['name']; 282 352 } 283 353 … … 285 355 } 286 356 287 function add_device($mac, $model,$ext,$template=NULL,$line=NULL,$displayname=NULL) {357 function add_device($mac, $model, $ext, $template=NULL, $line=NULL, $displayname=NULL) { 288 358 289 359 $mac = $this->mac_check_clean($mac); 290 if ($mac) {291 if (empty($model)) {292 $this->error['add_device'] = _("You Must Select A Model From the Drop Down") ."!";360 if ($mac) { 361 if (empty($model)) { 362 $this->error['add_device'] = _("You Must Select A Model From the Drop Down") . "!"; 293 363 return(FALSE); 294 } elseif (empty($ext)) {295 $this->error['add_device'] = _("You Must Select an Extension/Device From the Drop Down") ."!";364 } elseif (empty($ext)) { 365 $this->error['add_device'] = _("You Must Select an Extension/Device From the Drop Down") . "!"; 296 366 return(FALSE); 297 367 } else { 298 if ($this->sync_model($model)) {299 $sql = "SELECT id,template_id FROM endpointman_mac_list WHERE mac = '" .$mac."'";300 $dup = $this->eda->sql($sql, 'getRow',DB_FETCHMODE_ASSOC);301 302 if ($dup) {303 if (!isset($template)) {368 if ($this->sync_model($model)) { 369 $sql = "SELECT id,template_id FROM endpointman_mac_list WHERE mac = '" . $mac . "'"; 370 $dup = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 371 372 if ($dup) { 373 if (!isset($template)) { 304 374 $template = $dup['template_id']; 305 375 } 306 376 307 $sql = "UPDATE endpointman_mac_list SET model = " .$model.", template_id = ".$template." WHERE id = ".$dup['id'];377 $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . " WHERE id = " . $dup['id']; 308 378 $this->eda->sql($sql); 309 379 $return = $this->add_line($dup['id'], $line, $ext); 310 if ($return) {380 if ($return) { 311 381 return($return); 312 382 } else { … … 314 384 } 315 385 } else { 316 if (!isset($template)) {386 if (!isset($template)) { 317 387 $template = 0; 318 388 } 319 389 320 $sql = "SELECT mac_id FROM endpointman_line_list WHERE ext = " .$ext;321 $used = $this->eda->sql($sql, 'getOne');322 323 if (($used) AND (!$this->global_cfg['show_all_registrations'])) {390 $sql = "SELECT mac_id FROM endpointman_line_list WHERE ext = " . $ext; 391 $used = $this->eda->sql($sql, 'getOne'); 392 393 if (($used) AND (!$this->global_cfg['show_all_registrations'])) { 324 394 $this->error['add_device'] = "You can't assign the same user to multiple devices!"; 325 395 return(FALSE); 326 396 } 327 397 328 if (!isset($displayname)) {329 $sql = 'SELECT description FROM devices WHERE id = ' .$ext;330 $name = & $this->eda->sql($sql,'getOne');398 if (!isset($displayname)) { 399 $sql = 'SELECT description FROM devices WHERE id = ' . $ext; 400 $name = & $this->eda->sql($sql, 'getOne'); 331 401 } else { 332 402 $name = $displayname; 333 403 } 334 404 335 $sql = 'SELECT endpointman_product_list. * , endpointman_model_list.template_data, endpointman_brand_list.directory FROM endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_model_list.id = \'' .$model.'\' AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id';336 337 $row = & $this->eda->sql($sql,'getRow',DB_FETCHMODE_ASSOC);338 339 $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `template_id`) VALUES ('" .$mac."', '".$model."', '".$template."')";405 $sql = 'SELECT endpointman_product_list. * , endpointman_model_list.template_data, endpointman_brand_list.directory FROM endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_model_list.id = \'' . $model . '\' AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id'; 406 407 $row = & $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 408 409 $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `template_id`) VALUES ('" . $mac . "', '" . $model . "', '" . $template . "')"; 340 410 $this->eda->sql($sql); 341 411 342 412 $sql = 'SELECT last_insert_id()'; 343 $ext_id = & $this->eda->sql($sql,'getOne');344 345 if (empty($line)) {413 $ext_id = & $this->eda->sql($sql, 'getOne'); 414 415 if (empty($line)) { 346 416 $line = 1; 347 417 } 348 418 349 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" .$ext_id."', '".$ext."', '".$line."', '".addslashes($name)."')";419 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" . $ext_id . "', '" . $ext . "', '" . $line . "', '" . addslashes($name) . "')"; 350 420 $this->eda->sql($sql); 351 421 352 $this->message['add_device'][] = "Added " .$name." to line ".$line;422 $this->message['add_device'][] = "Added " . $name . " to line " . $line; 353 423 return($ext_id); 354 424 } 355 425 } else { 356 $this->error['Sync_Model'] = _("Invalid Model Selected, Can't Sync System") ."!";426 $this->error['Sync_Model'] = _("Invalid Model Selected, Can't Sync System") . "!"; 357 427 return(FALSE); 358 428 } 359 429 } 360 430 } else { 361 $this->error['add_device'] = _("Invalid MAC Address") ."!";431 $this->error['add_device'] = _("Invalid MAC Address") . "!"; 362 432 return(FALSE); 363 433 } 364 434 } 365 435 366 function add_line($mac_id, $line=NULL,$ext=NULL,$displayname=NULL) {367 if ((!isset($line)) AND (!isset($ext))) {368 if ($this->linesAvailable(NULL,$mac_id)) {369 if ($this->eda->all_unused_registrations()) {370 $sql = 'SELECT * FROM endpointman_line_list WHERE mac_id = ' . $mac_id;371 $lines_list = $this->eda->sql($sql, 'getAll',DB_FETCHMODE_ASSOC);372 373 foreach ($lines_list as $row) {374 $sql = "SELECT description FROM devices WHERE id = " .$row['ext'];375 $name =$this->eda->sql($sql,'getOne');376 377 $sql = "UPDATE endpointman_line_list SET line = '" .$row['line']."', ext = ".$row['ext'].", description = '".addslashes($name)."' WHERE luid = ". $row['luid'];436 function add_line($mac_id, $line=NULL, $ext=NULL, $displayname=NULL) { 437 if ((!isset($line)) AND (!isset($ext))) { 438 if ($this->linesAvailable(NULL, $mac_id)) { 439 if ($this->eda->all_unused_registrations()) { 440 $sql = 'SELECT * FROM endpointman_line_list WHERE mac_id = ' . $mac_id; 441 $lines_list = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 442 443 foreach ($lines_list as $row) { 444 $sql = "SELECT description FROM devices WHERE id = " . $row['ext']; 445 $name = $this->eda->sql($sql, 'getOne'); 446 447 $sql = "UPDATE endpointman_line_list SET line = '" . $row['line'] . "', ext = " . $row['ext'] . ", description = '" . addslashes($name) . "' WHERE luid = " . $row['luid']; 378 448 $this->eda->sql($sql); 379 449 } 380 450 381 451 $reg = array_values($this->display_registration_list()); 382 $lines = array_values($this->linesAvailable(NULL, $mac_id));383 384 $sql = "SELECT description FROM devices WHERE id = " .$reg[0]['value'];385 $name = $this->eda->sql($sql, 'getOne');386 387 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" .$mac_id."', '".$reg[0]['value']."', '".$lines[0]['value']."', '".addslashes($name)."')";452 $lines = array_values($this->linesAvailable(NULL, $mac_id)); 453 454 $sql = "SELECT description FROM devices WHERE id = " . $reg[0]['value']; 455 $name = $this->eda->sql($sql, 'getOne'); 456 457 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" . $mac_id . "', '" . $reg[0]['value'] . "', '" . $lines[0]['value'] . "', '" . addslashes($name) . "')"; 388 458 $this->eda->sql($sql); 389 459 390 $this->message['add_line'] = "Added '<i>" .$name."</i>' to line '<i>".$lines[0]['value']."</i>' on device '<i>".$reg[0]['value']."</i>' <br/> Configuration Files will not be Generated until you click Save!";460 $this->message['add_line'] = "Added '<i>" . $name . "</i>' to line '<i>" . $lines[0]['value'] . "</i>' on device '<i>" . $reg[0]['value'] . "</i>' <br/> Configuration Files will not be Generated until you click Save!"; 391 461 return($mac_id); 392 462 } else { 393 $this->error['add_line'] = _("No Devices/Extensions Left to Add") ."!";463 $this->error['add_line'] = _("No Devices/Extensions Left to Add") . "!"; 394 464 return(FALSE); 395 465 } 396 466 } else { 397 $this->error['add_line'] = _("No Lines Left to Add") ."!";467 $this->error['add_line'] = _("No Lines Left to Add") . "!"; 398 468 return(FALSE); 399 469 } 400 } elseif ((!isset($line)) AND (isset($ext))) {401 if ($this->linesAvailable(NULL,$mac_id)) {402 if ($this->eda->all_unused_registrations()) {403 $lines = array_values($this->linesAvailable(NULL, $mac_id));404 405 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" .$mac_id."', '".$ext."', '".$lines[0]['value']."', '".addslashes($displayname)."')";470 } elseif ((!isset($line)) AND (isset($ext))) { 471 if ($this->linesAvailable(NULL, $mac_id)) { 472 if ($this->eda->all_unused_registrations()) { 473 $lines = array_values($this->linesAvailable(NULL, $mac_id)); 474 475 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" . $mac_id . "', '" . $ext . "', '" . $lines[0]['value'] . "', '" . addslashes($displayname) . "')"; 406 476 $this->eda->sql($sql); 407 477 408 $this->message['add_line'] = "Added '<i>" .$name."</i>' to line '<i>".$lines[0]['value']."</i>' on device '<i>".$reg[0]['value']."</i>' <br/> Configuration Files will not be Generated until you click Save!";478 $this->message['add_line'] = "Added '<i>" . $name . "</i>' to line '<i>" . $lines[0]['value'] . "</i>' on device '<i>" . $reg[0]['value'] . "</i>' <br/> Configuration Files will not be Generated until you click Save!"; 409 479 return($mac_id); 410 480 } else { 411 $this->error['add_line'] = _("No Devices/Extensions Left to Add") ."!";481 $this->error['add_line'] = _("No Devices/Extensions Left to Add") . "!"; 412 482 return(FALSE); 413 483 } 414 484 } else { 415 $this->error['add_line'] = _("No Lines Left to Add") ."!";485 $this->error['add_line'] = _("No Lines Left to Add") . "!"; 416 486 return(FALSE); 417 487 } 418 } elseif ((isset($line)) AND (isset($ext))) {419 $sql = "SELECT luid FROM endpointman_line_list WHERE line = '" .$line."' AND mac_id = ".$mac_id;420 $luid = $this->eda->sql($sql, 'getOne');421 if ($luid) {488 } elseif ((isset($line)) AND (isset($ext))) { 489 $sql = "SELECT luid FROM endpointman_line_list WHERE line = '" . $line . "' AND mac_id = " . $mac_id; 490 $luid = $this->eda->sql($sql, 'getOne'); 491 if ($luid) { 422 492 $this->error['add_line'] = "This line has already been assigned!"; 423 493 return(FALSE); 424 494 } else { 425 if (!isset($displayname)) {426 $sql = 'SELECT description FROM devices WHERE id = ' .$ext;427 $name = & $this->eda->sql($sql,'getOne');495 if (!isset($displayname)) { 496 $sql = 'SELECT description FROM devices WHERE id = ' . $ext; 497 $name = & $this->eda->sql($sql, 'getOne'); 428 498 } else { 429 499 $name = $displayname; 430 500 } 431 501 432 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" .$mac_id."', '".$ext."', '".$line."', '".addslashes($name)."')";502 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('" . $mac_id . "', '" . $ext . "', '" . $line . "', '" . addslashes($name) . "')"; 433 503 $this->eda->sql($sql); 434 $this->message['add_line'] .= "Added " .$name." to line ".$line . "<br/>";504 $this->message['add_line'] .= "Added " . $name . " to line " . $line . "<br/>"; 435 505 return($mac_id); 436 506 } 437 438 } 439 } 440 441 function update_device($macid,$model,$template,$luid=NULL,$name=NULL,$line=NULL,$update_lines=TRUE) { 442 $sql = "UPDATE endpointman_mac_list SET model = ".$model.", template_id = ".$template." WHERE id = ".$macid; 507 } 508 } 509 510 function update_device($macid, $model, $template, $luid=NULL, $name=NULL, $line=NULL, $update_lines=TRUE) { 511 $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . " WHERE id = " . $macid; 443 512 $this->eda->sql($sql); 444 513 445 if ($update_lines) {446 if (isset($luid)) {447 $this->update_line($luid, NULL,$name,$line);514 if ($update_lines) { 515 if (isset($luid)) { 516 $this->update_line($luid, NULL, $name, $line); 448 517 return(TRUE); 449 518 } else { 450 $this->update_line(NULL, $macid);519 $this->update_line(NULL, $macid); 451 520 return(TRUE); 452 521 } … … 454 523 } 455 524 456 function update_line($luid=NULL, $macid=NULL,$name=NULL,$line=NULL) {457 if (isset($luid)) {458 $sql = "SELECT * FROM endpointman_line_list WHERE luid = " .$luid;525 function update_line($luid=NULL, $macid=NULL, $name=NULL, $line=NULL) { 526 if (isset($luid)) { 527 $sql = "SELECT * FROM endpointman_line_list WHERE luid = " . $luid; 459 528 $row = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 460 529 461 if (!isset($name)) {462 $sql = "SELECT description FROM devices WHERE id = " .$row['ext'];463 $name =$this->eda->sql($sql,'getOne');464 } 465 466 if (!isset($line)) {530 if (!isset($name)) { 531 $sql = "SELECT description FROM devices WHERE id = " . $row['ext']; 532 $name = $this->eda->sql($sql, 'getOne'); 533 } 534 535 if (!isset($line)) { 467 536 $line = $row['line']; 468 537 } 469 $sql = "UPDATE endpointman_line_list SET line = '" .$line."', ext = '".$row['ext']."', description = '".$name."' WHERE luid = ". $row['luid'];538 $sql = "UPDATE endpointman_line_list SET line = '" . $line . "', ext = '" . $row['ext'] . "', description = '" . $name . "' WHERE luid = " . $row['luid']; 470 539 $this->eda->sql($sql); 471 540 return(TRUE); 472 541 } else { 473 $sql = "SELECT * FROM endpointman_line_list WHERE mac_id = " .$macid;542 $sql = "SELECT * FROM endpointman_line_list WHERE mac_id = " . $macid; 474 543 $lines_info = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 475 foreach ($lines_info as $row) {476 $sql = "SELECT description FROM devices WHERE id = " .$row['ext'];477 $name =$this->eda->sql($sql,'getOne');478 479 $sql = "UPDATE endpointman_line_list SET line = '" .$row['line']."', ext = '".$row['ext']."', description = '".$name."' WHERE luid = ". $row['luid'];544 foreach ($lines_info as $row) { 545 $sql = "SELECT description FROM devices WHERE id = " . $row['ext']; 546 $name = $this->eda->sql($sql, 'getOne'); 547 548 $sql = "UPDATE endpointman_line_list SET line = '" . $row['line'] . "', ext = '" . $row['ext'] . "', description = '" . $name . "' WHERE luid = " . $row['luid']; 480 549 $this->eda->sql($sql); 481 550 } … … 489 558 * @return <type> 490 559 */ 491 function delete_line($lineid, $allow_device_remove=FALSE) {492 $sql = 'SELECT mac_id FROM endpointman_line_list WHERE luid = ' .$lineid;493 $mac_id = $this->eda->sql($sql, 'getOne');560 function delete_line($lineid, $allow_device_remove=FALSE) { 561 $sql = 'SELECT mac_id FROM endpointman_line_list WHERE luid = ' . $lineid; 562 $mac_id = $this->eda->sql($sql, 'getOne'); 494 563 $row = $this->get_phone_info($mac_id); 495 564 496 $sql = 'SELECT COUNT(*) FROM endpointman_line_list WHERE mac_id = ' .$mac_id;497 $num_lines = $this->eda->sql($sql, 'getOne');498 if ($num_lines > 1) {499 $sql = "DELETE FROM endpointman_line_list WHERE luid=" .$lineid;565 $sql = 'SELECT COUNT(*) FROM endpointman_line_list WHERE mac_id = ' . $mac_id; 566 $num_lines = $this->eda->sql($sql, 'getOne'); 567 if ($num_lines > 1) { 568 $sql = "DELETE FROM endpointman_line_list WHERE luid=" . $lineid; 500 569 $this->eda->sql($sql); 501 570 $this->message['delete_line'] = "Deleted!"; 502 571 return(TRUE); 503 572 } else { 504 if ($allow_device_remove) {505 $sql = "DELETE FROM endpointman_line_list WHERE luid=" .$lineid;573 if ($allow_device_remove) { 574 $sql = "DELETE FROM endpointman_line_list WHERE luid=" . $lineid; 506 575 $this->eda->sql($sql); 507 576 508 $sql = "DELETE FROM endpointman_mac_list WHERE id=" . $mac_id;577 $sql = "DELETE FROM endpointman_mac_list WHERE id=" . $mac_id; 509 578 $this->eda->sql($sql); 510 579 $this->message['delete_line'] = "Deleted!"; 511 580 return(TRUE); 512 581 } else { 513 $this->error['delete_line'] = _("You can't remove the only line left") ."!";582 $this->error['delete_line'] = _("You can't remove the only line left") . "!"; 514 583 return(FALSE); 515 584 } … … 518 587 519 588 function delete_device($mac_id) { 520 $sql = "DELETE FROM endpointman_mac_list WHERE id=" .$mac_id;589 $sql = "DELETE FROM endpointman_mac_list WHERE id=" . $mac_id; 521 590 $this->eda->sql($sql); 522 591 523 $sql = "DELETE FROM endpointman_line_list WHERE mac_id=" .$mac_id;592 $sql = "DELETE FROM endpointman_line_list WHERE mac_id=" . $mac_id; 524 593 $this->eda->sql($sql); 525 594 $this->message['delete_device'] = "Deleted!"; … … 528 597 529 598 function get_message($function_name) { 530 if (isset($this->message[$function_name])) {599 if (isset($this->message[$function_name])) { 531 600 return($this->message[$function_name]); 532 601 } else { … … 534 603 } 535 604 } 605 536 606 /** 537 607 * Send this function an ID from the mac devices list table and you'll get all the information we have on that particular phone … … 586 656 return(FALSE); 587 657 } 588 $sql = "SELECT id FROM endpointman_mac_list WHERE model > 0 AND id =" .$mac_id;658 $sql = "SELECT id FROM endpointman_mac_list WHERE model > 0 AND id =" . $mac_id; 589 659 590 660 $res = $this->eda->sql($sql); 591 if ($res->numRows()) {661 if ($res->numRows()) { 592 662 //Returns Brand Name, Brand Directory, Model Name, Mac Address, Extension (FreePBX), Custom Configuration Template, Custom Configuration Data, Product Name, Product ID, Product Configuration Directory, Product Configuration Version, Product XML name, 593 $sql = "SELECT endpointman_mac_list.specific_settings, endpointman_mac_list.config_files_override, endpointman_mac_list.global_user_cfg_data, endpointman_model_list.id as model_id, endpointman_brand_list.id as brand_id, endpointman_brand_list.name, endpointman_brand_list.directory, endpointman_model_list.model, endpointman_mac_list.mac, endpointman_mac_list.template_id, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.long_name, endpointman_product_list.id as product_id, endpointman_product_list.cfg_dir, endpointman_product_list.cfg_ver, endpointman_model_list.template_data, endpointman_model_list.enabled, endpointman_mac_list.global_settings_override FROM endpointman_line_list, endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_mac_list.model = endpointman_model_list.id AND endpointman_brand_list.id = endpointman_model_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.id = " . $mac_id;663 $sql = "SELECT endpointman_mac_list.specific_settings, endpointman_mac_list.config_files_override, endpointman_mac_list.global_user_cfg_data, endpointman_model_list.id as model_id, endpointman_brand_list.id as brand_id, endpointman_brand_list.name, endpointman_brand_list.directory, endpointman_model_list.model, endpointman_mac_list.mac, endpointman_mac_list.template_id, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.long_name, endpointman_product_list.id as product_id, endpointman_product_list.cfg_dir, endpointman_product_list.cfg_ver, endpointman_model_list.template_data, endpointman_model_list.enabled, endpointman_mac_list.global_settings_override FROM endpointman_line_list, endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_mac_list.model = endpointman_model_list.id AND endpointman_brand_list.id = endpointman_model_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.id = " . $mac_id; 594 664 595 665 $phone_info = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 596 666 597 if (!$phone_info) {667 if (!$phone_info) { 598 668 $this->error['get_phone_info'] = "Error with SQL Statement"; 599 669 } … … 601 671 //If there is a template associated with this phone then pull that information and put it into the array 602 672 if ($phone_info['template_id'] > 0) { 603 $sql = "SELECT name, global_custom_cfg_data, config_files_override, global_settings_override FROM endpointman_template_list WHERE id = " .$phone_info['template_id'];673 $sql = "SELECT name, global_custom_cfg_data, config_files_override, global_settings_override FROM endpointman_template_list WHERE id = " . $phone_info['template_id']; 604 674 605 675 $phone_info['template_data_info'] = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 606 607 } 608 609 $sql = "SELECT endpointman_line_list.*, sip.data as secret, devices.*, endpointman_line_list.description AS epm_description FROM endpointman_line_list, sip, devices WHERE endpointman_line_list.ext = devices.id AND endpointman_line_list.ext = sip.id AND sip.keyword = 'secret' AND mac_id = ".$mac_id." ORDER BY endpointman_line_list.line ASC"; 676 } 677 678 $sql = "SELECT endpointman_line_list.*, sip.data as secret, devices.*, endpointman_line_list.description AS epm_description FROM endpointman_line_list, sip, devices WHERE endpointman_line_list.ext = devices.id AND endpointman_line_list.ext = sip.id AND sip.keyword = 'secret' AND mac_id = " . $mac_id . " ORDER BY endpointman_line_list.line ASC"; 610 679 $lines_info = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 611 foreach ($lines_info as $line) {680 foreach ($lines_info as $line) { 612 681 $phone_info['line'][$line['line']] = $line; 613 682 $phone_info['line'][$line['line']]['description'] = $line['epm_description']; 614 } 615 616 617 } else { 618 $sql = "SELECT id, mac, ext FROM endpointman_mac_list WHERE id =".$mac_id; 683 } 684 } else { 685 $sql = "SELECT id, mac, ext FROM endpointman_mac_list WHERE id =" . $mac_id; 619 686 //Phone is unknown, we need to display this to the end user so that they can make corrections 620 687 $row = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 621 688 622 689 $brand = $this->get_brand_from_mac($row['mac']); 623 if ($brand) {690 if ($brand) { 624 691 $phone_info['brand_id'] = $brand['id']; 625 692 $phone_info['name'] = $brand['name']; … … 634 701 $phone_info['custom_cfg_template'] = 0; 635 702 $phone_info['mac'] = $row['mac']; 636 $sql = "SELECT endpointman_line_list.*, sip.data as secret, devices.* FROM endpointman_line_list, sip, devices WHERE endpointman_line_list.ext = devices.id AND endpointman_line_list.ext = sip.id AND sip.keyword = 'secret' AND mac_id = " .$mac_id;703 $sql = "SELECT endpointman_line_list.*, sip.data as secret, devices.* FROM endpointman_line_list, sip, devices WHERE endpointman_line_list.ext = devices.id AND endpointman_line_list.ext = sip.id AND sip.keyword = 'secret' AND mac_id = " . $mac_id; 637 704 $lines_info = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 638 foreach ($lines_info as $line) {705 foreach ($lines_info as $line) { 639 706 $phone_info['line'][$line['line']] = $line; 640 707 } … … 655 722 $alt_configs = NULL; 656 723 657 if ($custom == 0) {658 $sql = "SELECT model_id FROM endpointman_template_list WHERE id=" .$id;659 } else { 660 $sql = "SELECT model FROM endpointman_mac_list WHERE id=" .$id;661 } 662 663 $model_id = $this->eda->sql($sql, 'getOne');724 if ($custom == 0) { 725 $sql = "SELECT model_id FROM endpointman_template_list WHERE id=" . $id; 726 } else { 727 $sql = "SELECT model FROM endpointman_mac_list WHERE id=" . $id; 728 } 729 730 $model_id = $this->eda->sql($sql, 'getOne'); 664 731 665 732 //Make sure the model data from the local confg files are stored in the database and vice-versa. Serious errors will occur if the database is not in sync with the local file 666 if (!$this->sync_model($model_id)) {667 die("unable to sync local template files - TYPE:" . $custom);733 if (!$this->sync_model($model_id)) { 734 die("unable to sync local template files - TYPE:" . $custom); 668 735 } 669 736 670 737 671 738 //Determine if we are dealing with a general template or a specific [for that phone only] template (custom =0 means general) 672 if ($custom == 0) {673 $sql = "SELECT endpointman_model_list.max_lines, endpointman_model_list.model as model_name, endpointman_template_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_product_list.short_name, endpointman_product_list.id as product_id, endpointman_model_list.template_data, endpointman_model_list.id as model_id, endpointman_template_list.* FROM endpointman_product_list, endpointman_model_list, endpointman_template_list WHERE endpointman_product_list.id = endpointman_template_list.product_id AND endpointman_template_list.model_id = endpointman_model_list.id AND endpointman_template_list.id = " .$id;674 } else { 675 $sql = "SELECT endpointman_model_list.max_lines, endpointman_model_list.model as model_name, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_line_list.*, endpointman_model_list.id as model_id, endpointman_model_list.template_data, endpointman_product_list.id as product_id, endpointman_product_list.short_name, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_brand_list, endpointman_mac_list, endpointman_model_list, endpointman_product_list, endpointman_line_list WHERE endpointman_mac_list.id=" .$id." AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id";739 if ($custom == 0) { 740 $sql = "SELECT endpointman_model_list.max_lines, endpointman_model_list.model as model_name, endpointman_template_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_product_list.short_name, endpointman_product_list.id as product_id, endpointman_model_list.template_data, endpointman_model_list.id as model_id, endpointman_template_list.* FROM endpointman_product_list, endpointman_model_list, endpointman_template_list WHERE endpointman_product_list.id = endpointman_template_list.product_id AND endpointman_template_list.model_id = endpointman_model_list.id AND endpointman_template_list.id = " . $id; 741 } else { 742 $sql = "SELECT endpointman_model_list.max_lines, endpointman_model_list.model as model_name, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_line_list.*, endpointman_model_list.id as model_id, endpointman_model_list.template_data, endpointman_product_list.id as product_id, endpointman_product_list.short_name, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_brand_list, endpointman_mac_list, endpointman_model_list, endpointman_product_list, endpointman_line_list WHERE endpointman_mac_list.id=" . $id . " AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id"; 676 743 } 677 744 … … 679 746 680 747 $this->tpl->assign("template_editor_display", 1); 681 echo $this->tpl->draw( 'global_header');748 echo $this->tpl->draw('global_header'); 682 749 //Let the template system know if we are working with a general template or a specific [for that phone only] template 683 750 $this->tpl->assign("custom", $custom); 684 if ($custom) {751 if ($custom) { 685 752 $this->tpl->assign("ext", $row['ext']); 686 753 } else { … … 690 757 $this->tpl->assign("model", $row['model_name']); 691 758 692 if ($ma = $this->models_available($row['model_id'], NULL, $row['product_id'])) {759 if ($ma = $this->models_available($row['model_id'], NULL, $row['product_id'])) { 693 760 $this->tpl->assign("models_ava", $ma); 694 761 } 695 762 696 if (isset($_REQUEST['maxlines'])) {697 $areas = $this->areaAvailable($row['model_id'], $_REQUEST['maxlines']);763 if (isset($_REQUEST['maxlines'])) { 764 $areas = $this->areaAvailable($row['model_id'], $_REQUEST['maxlines']); 698 765 } else { 699 766 $areas = $this->areaAvailable($row['model_id'], 3); … … 702 769 $this->tpl->assign("area_ava", $areas); 703 770 //Start the display of the html file in the product folder 704 if ($row['config_files_override'] == "") {771 if ($row['config_files_override'] == "") { 705 772 $config_files_saved = ""; 706 773 } else { 707 774 $config_files_saved = unserialize($row['config_files_override']); 708 775 } 709 $config_files_list = explode(",", $row['config_files']);776 $config_files_list = explode(",", $row['config_files']); 710 777 $i = 0; 711 778 $alt = 0; 712 779 713 $i =0;714 $b =0;780 $i = 0; 781 $b = 0; 715 782 $only_configs = array(); 716 foreach ($config_files_list as $files) {717 $sql = "SELECT * FROM endpointman_custom_configs WHERE product_id = '" .$row['product_id']."' AND original_name = '".$files."'";783 foreach ($config_files_list as $files) { 784 $sql = "SELECT * FROM endpointman_custom_configs WHERE product_id = '" . $row['product_id'] . "' AND original_name = '" . $files . "'"; 718 785 $alt_configs_list_count = $this->eda->sql($sql); 719 if ($alt_configs_list_count->numRows() > 0) {786 if ($alt_configs_list_count->numRows() > 0) { 720 787 $alt_configs_list = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 721 788 $alt_configs[$i]['name'] = $files; 722 $files = str_replace(".", "_",$files);723 $h =0;724 foreach ($alt_configs_list as $ccf) {789 $files = str_replace(".", "_", $files); 790 $h = 0; 791 foreach ($alt_configs_list as $ccf) { 725 792 $alt_configs[$i]['list'][$h]['id'] = $ccf['id']; 726 793 $cf_key = $files; 727 if ((isset($config_files_saved[$cf_key])) AND (is_array($config_files_saved)) AND ($config_files_saved[$cf_key] == $ccf['id'])) {794 if ((isset($config_files_saved[$cf_key])) AND (is_array($config_files_saved)) AND ($config_files_saved[$cf_key] == $ccf['id'])) { 728 795 $alt_configs[$i]['list'][$h]['selected'] = 'selected'; 729 796 } … … 742 809 $this->tpl->assign("alt_configs", $alt_configs); 743 810 $this->tpl->assign("alt", $alt); 744 if (!isset($_REQUEST['maxlines'])) {811 if (!isset($_REQUEST['maxlines'])) { 745 812 $maxlines = 3; 746 813 } else { 747 814 $maxlines = $_REQUEST['maxlines']; 748 815 } 749 if ($row['template_data'] != "") {750 $out = $this->generate_gui_html($row['template_data'], $row['global_custom_cfg_data'],TRUE, NULL, $maxlines);816 if ($row['template_data'] != "") { 817 $out = $this->generate_gui_html($row['template_data'], $row['global_custom_cfg_data'], TRUE, NULL, $maxlines); 751 818 } else { 752 819 echo "No Template Data has been defined for this Product<br />"; … … 756 823 $this->tpl->assign("hidden_id", $row['id']); 757 824 $this->tpl->assign("hidden_custom", $custom); 758 echo $this->tpl->draw( 'template_editor');825 echo $this->tpl->draw('template_editor'); 759 826 760 827 $this->tpl->assign("debug", ""); 761 762 828 } 763 829 … … 770 836 * @return <type> 771 837 */ 772 function generate_gui_html($cfg_data, $custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL,$max_lines=3,$ext=NULL) {838 function generate_gui_html($cfg_data, $custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL, $max_lines=3, $ext=NULL) { 773 839 //take the data out of the database and turn it back into an array for use 774 840 $cfg_data = unserialize($cfg_data); 775 776 $count = count($cfg_data); 777 841 $template_type = 'GENERAL'; 778 842 //Check to see if there is a custom template for this phone already listed in the endpointman_mac_list database 779 843 if (!empty($custom_cfg_data)) { 780 844 $custom_cfg_data = unserialize($custom_cfg_data); 781 if(array_key_exists('data', $custom_cfg_data)) { 782 $custom_cfg_data_ari = $custom_cfg_data['ari']; 845 if (array_key_exists('data', $custom_cfg_data)) { 846 if(array_key_exists('ari', $custom_cfg_data)) { 847 $extra_data = $custom_cfg_data['ari']; 848 } else { 849 $template_type = 'GLOBAL'; 850 $extra_data = $custom_cfg_data['freepbx']; 851 } 783 852 $custom_cfg_data = $custom_cfg_data['data']; 784 853 } else { 785 $ custom_cfg_data_ari= array();854 $extra_data = array(); 786 855 } 787 856 } else { 788 857 $custom_cfg_data = array(); 789 $ custom_cfg_data_ari= array();790 } 791 if (isset($user_cfg_data)) {858 $extra_data = array(); 859 } 860 if (isset($user_cfg_data)) { 792 861 $user_cfg_data = unserialize($user_cfg_data); 793 862 } … … 797 866 $variables_count = 0; 798 867 799 foreach($cfg_data as $data) { 800 $data = $this->fix_single_array_keys($data['category']); 801 foreach($data as $cats) { 802 //We force the start of a new 'section' by increasing group_count and resetting variables_count to zero 803 if($cats['name'] != 'lines') { 804 $key = $this->arraysearchrecursive($cats['name'], $template_variables_array, 'title'); 805 if(is_array($key)) { 806 $group_count == $key[0]; 807 $num = count($this->fix_single_array_keys($template_variables_array[$group_count]['data'])); 808 $variables_count == $num; 868 foreach ($cfg_data['data'] as $cats_name => $cats) { 869 if ($admin) { 870 $group_count++; 871 $template_variables_array[$group_count]['title'] = $cats_name; 872 } else { 873 //Group all ARI stuff into one tab 874 $template_variables_array[$group_count]['title'] = "Your Phone Settings"; 875 } 876 foreach ($cats as $subcat_name => $subcats) { 877 foreach ($subcats as $item_var => $config_options) { 878 if (preg_match('/(.*)\|(.*)/i', $item_var, $matches)) { 879 $type = $matches[1]; 880 $variable = $matches[2]; 809 881 } else { 810 if($admin) { 811 $group_count++; 812 $variables_count = 0; 882 die('no matches!'); 883 } 884 if ($admin) { 885 //Administration View Only 886 switch ($type) { 887 case "lineloop": 888 //line|1|display_name 889 foreach ($config_options as $var_name => $var_items) { 890 $lcount = isset($var_items['line_count']) ? $var_items['line_count'] : $lcount; 891 $key = "line|" . $lcount . "|" . $var_name; 892 $items[$variables_count] = $items; 893 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count, $var_items, $key, $custom_cfg_data, $admin, $user_cfg_data, $extra_data,$template_type); 894 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 895 $variables_count++; 896 } 897 898 if ($lcount <= $max_lines) { 899 $template_variables_array[$group_count]['title'] = "Line Options for Line " . $lcount; 900 $group_count++; 901 } else { 902 unset($template_variables_array[$group_count]); 903 } 904 905 continue 2; 906 case "loop": 907 foreach ($config_options as $var_name => $var_items) { 908 //loop|remotephonebook_url_0 909 $tv = explode('_', $variable); 910 $key = "loop|" . $tv[0] . "_" . $var_name . "_" . $var_items['loop_count']; 911 $items[$variables_count] = $var_items; 912 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count, $var_items, $key, $custom_cfg_data, $admin, $user_cfg_data, $extra_data,$template_type); 913 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 914 $variables_count++; 915 } 916 continue 2; 813 917 } 814 } 815 $template_variables_array[$group_count]['title'] = $cats['name']; 816 } 817 $cats = $this->fix_single_array_keys($cats['subcategory']); 818 foreach($cats as $subcats) { 819 $items = $this->fix_single_array_keys($subcats['item']); 820 foreach($items as $config_options) { 821 if($admin) { 822 //Administration View Only 823 switch ($config_options['type']) { 824 case "loop_line_options": 825 for($a=1;$a <= $max_lines; $a++) { 826 $group_count++; 827 $variables_count = 0; 828 $template_variables_array[$group_count]['title'] = "Line Options for Line ".$a; 829 foreach($config_options['data']['item'] as $items) { 830 if(isset($items['description'])) { 831 $items['description'] = str_replace('{$count}',$a,$items['description']); 832 $key = "line|".$a."|".str_replace('$','',$items['variable']); 833 if(array_key_exists($key,$custom_cfg_data)) { 834 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 835 } else { 836 $custom_cfg_data[$key] = str_replace('{$count}', $a, $this->fix_single_array_keys($items['default_value'])); 837 } 838 } 839 $items[$variables_count] = $items; 840 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 841 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 842 $variables_count++; 843 } 844 } 845 continue 2; 846 case "loop": 847 //We force the start of a new 'section' by increasing group_count and resetting variables_count to zero 848 $loop_start = $config_options['loop_start']; 849 $loop_end = $config_options['loop_end']; 850 for($a=$loop_start;$a<=$loop_end;$a++) { 851 foreach($config_options['data']['item'] as $items) { 852 if(isset($items['description'])) { 853 $items['description'] = str_replace('{$count}',$a,$items['description']); 854 $key = "loop|".str_replace('$','',$items['variable'])."_".$a; 855 if(array_key_exists($key,$custom_cfg_data)) { 856 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 857 } else { 858 $custom_cfg_data[$key] = str_replace('{$count}', $a, $this->fix_single_array_keys($items['default_value'])); 859 } 860 } 861 $items[$variables_count] = $items; 862 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 863 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 864 $variables_count++; 865 } 866 } 867 continue 2; 868 } 869 } else { 870 //ARI View Only 871 $template_variables_array[$group_count]['title'] = "Your Phone Settings"; 872 switch ($config_options['type']) { 873 case "loop_line_options": 874 //$a is the line number 875 $sql = "SELECT line FROM endpointman_line_list WHERE ext = ".$ext; 876 $a = $this->eda->sql($sql,'getOne'); 877 $template_variables_array[$group_count]['title'] = "Line Options for Line ".$a; 878 foreach($config_options['data']['item'] as $items) { 879 if(isset($items['description'])) { 880 $items['description'] = str_replace('{$count}',$a,$items['description']); 881 $key = "line|".$a."|".str_replace('$','',$items['variable']); 882 if(array_key_exists($key,$custom_cfg_data)) { 883 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 884 } else { 885 $custom_cfg_data[$key] = str_replace('{$count}', $a, $this->fix_single_array_keys($items['default_value'])); 886 } 887 } 888 if(isset($custom_cfg_data_ari[$key])) { 889 $items[$variables_count] = $items; 890 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 891 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 892 $variables_count++; 893 } 894 } 895 $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; 896 $variables_count++; 897 continue 2; 898 case "loop": 899 $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; 900 $variables_count++; 901 $loop_start = $config_options['loop_start']; 902 $loop_end = $config_options['loop_end']; 903 for($a=$loop_start;$a<=$loop_end;$a++) { 904 foreach($config_options['data']['item'] as $items) { 905 if(isset($items['description'])) { 906 $items['description'] = str_replace('{$count}',$a,$items['description']); 907 $key = "loop|".str_replace('$','',$items['variable'])."_".$a; 908 if(array_key_exists($key,$custom_cfg_data)) { 909 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 910 } else { 911 $custom_cfg_data[$key] = ''; 912 } 913 } 914 if(isset($custom_cfg_data_ari[$key])) { 915 $items[$variables_count] = $items; 916 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 917 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 918 $variables_count++; 919 } 920 } 921 } 922 continue 2; 923 } 924 } 925 //Both Views 926 switch ($config_options['type']) { 927 case "break": 928 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$config_options,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 918 } else { 919 //ARI View Only 920 switch ($type) { 921 case "loop_line_options": 922 //$a is the line number 923 $sql = "SELECT line FROM endpointman_line_list WHERE ext = " . $ext; 924 $a = $this->eda->sql($sql, 'getOne'); 925 //TODO: fix this area 926 $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; 929 927 $variables_count++; 930 break; 931 default: 932 if(array_key_exists('variable',$config_options)) { 933 $key = str_replace('$','',$config_options['variable']); 934 //TODO: Move this into the sync function 935 //Checks to see if values are defined in the database, if not then we assume this is a new option and we need a default value here! 936 if(!isset($custom_cfg_data[$key])) { 937 //xml2array will take values that have no data and turn them into arrays, we want to avoid the word 'array' as a default value, so we blank it out here if we are an array 938 if((array_key_exists('default_value',$config_options)) AND (is_array($config_options['default_value']))) { 939 $custom_cfg_data[$key] = ""; 940 } elseif((array_key_exists('default_value',$config_options)) AND (!is_array($config_options['default_value']))) { 941 $custom_cfg_data[$key] = $config_options['default_value']; 942 } 943 } 944 if((!$admin) AND (isset($custom_cfg_data_ari[$key]))) { 945 $custom_cfg_data[$key] = $user_cfg_data[$key]; 946 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$config_options,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 947 $variables_count++; 948 } elseif($admin) { 949 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$config_options,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 928 continue 2; 929 case "loop": 930 foreach ($config_options as $var_name => $var_items) { 931 $tv = explode('_', $variable); 932 $key = "loop|" . $tv[0] . "_" . $var_name . "_" . $var_items['loop_count']; 933 if (isset($extra_data[$key])) { 934 $items[$variables_count] = $var_items; 935 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count, $var_items, $key, $custom_cfg_data, $admin, $user_cfg_data, $extra_data,$template_type); 936 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 950 937 $variables_count++; 951 938 } 952 939 } 953 break;940 continue 2; 954 941 } 955 continue; 956 } 957 } 958 } 959 } 942 } 943 //Both Views 944 switch ($config_options['type']) { 945 case "break": 946 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count, $config_options, $key, $custom_cfg_data, $admin, $user_cfg_data, $extra_data,$template_type); 947 $variables_count++; 948 break; 949 default: 950 if (array_key_exists('variable', $config_options)) { 951 $key = str_replace('$', '', $config_options['variable']); 952 //TODO: Move this into the sync function 953 //Checks to see if values are defined in the database, if not then we assume this is a new option and we need a default value here! 954 if (!isset($custom_cfg_data[$key])) { 955 //xml2array will take values that have no data and turn them into arrays, we want to avoid the word 'array' as a default value, so we blank it out here if we are an array 956 if ((array_key_exists('default_value', $config_options)) AND (is_array($config_options['default_value']))) { 957 $custom_cfg_data[$key] = ""; 958 } elseif ((array_key_exists('default_value', $config_options)) AND (!is_array($config_options['default_value']))) { 959 $custom_cfg_data[$key] = $config_options['default_value']; 960 } 961 } 962 if ((!$admin) AND (isset($extra_data[$key]))) { 963 $custom_cfg_data[$key] = $user_cfg_data[$key]; 964 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count, $config_options, $key, $custom_cfg_data, $admin, $user_cfg_data, $extra_data,$template_type); 965 $variables_count++; 966 } elseif ($admin) { 967 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count, $config_options, $key, $custom_cfg_data, $admin, $user_cfg_data, $extra_data,$template_type); 968 $variables_count++; 969 } 970 } 971 break; 972 } 973 continue; 974 } 975 } 976 } 977 960 978 return($template_variables_array); 961 979 } … … 969 987 * @return array 970 988 */ 971 function generate_form_data ($i,$cfg_data,$key=NULL,$custom_cfg_data=NULL,$admin=FALSE,$user_cfg_data=NULL,$custom_cfg_data_ari=NULL) {989 function generate_form_data($i, $cfg_data, $key=NULL, $custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL, $extra_data=NULL,$template_type='GENERAL') { 972 990 switch ($cfg_data['type']) { 973 991 case "input": 974 if ((!$admin) && (isset($user_cfg_data[$key]))) {992 if ((!$admin) && (isset($user_cfg_data[$key]))) { 975 993 $custom_cfg_data[$key] = $user_cfg_data[$key]; 976 994 } 977 995 $template_variables_array['type'] = "input"; 978 if (isset($cfg_data['max_chars'])) {996 if (isset($cfg_data['max_chars'])) { 979 997 $template_variables_array['max_chars'] = $cfg_data['max_chars']; 980 998 } 981 999 $template_variables_array['key'] = $key; 982 $template_variables_array['value'] = $custom_cfg_data[$key];1000 $template_variables_array['value'] = isset($custom_cfg_data[$key]) ? $custom_cfg_data[$key] : $cfg_data['default_value']; 983 1001 $template_variables_array['description'] = $cfg_data['description']; 984 1002 break; 985 1003 case "radio": 986 if ((!$admin) && (isset($user_cfg_data[$key]))) {1004 if ((!$admin) && (isset($user_cfg_data[$key]))) { 987 1005 $custom_cfg_data[$key] = $user_cfg_data[$key]; 988 1006 } 989 $num = $custom_cfg_data[$key];1007 $num = isset($custom_cfg_data[$key]) ? $custom_cfg_data[$key] : $cfg_data['default_value']; 990 1008 $template_variables_array['type'] = "radio"; 991 1009 $template_variables_array['key'] = $key; 992 1010 $template_variables_array['description'] = $cfg_data['description']; 993 1011 $z = 0; 994 while ($z < count($cfg_data['data'])) {1012 while ($z < count($cfg_data['data'])) { 995 1013 $template_variables_array['data'][$z]['key'] = $key; 996 1014 $template_variables_array['data'][$z]['value'] = $cfg_data['data'][$z]['value']; … … 1003 1021 break; 1004 1022 case "list": 1005 if ((!$admin) && (isset($user_cfg_data[$key]))) {1023 if ((!$admin) && (isset($user_cfg_data[$key]))) { 1006 1024 $custom_cfg_data[$key] = $user_cfg_data[$key]; 1007 1025 } 1008 $num = $custom_cfg_data[$key];1026 $num = isset($custom_cfg_data[$key]) ? $custom_cfg_data[$key] : $cfg_data['default_value']; 1009 1027 $template_variables_array['type'] = "list"; 1010 1028 $template_variables_array['key'] = $key; 1011 1029 $template_variables_array['description'] = $cfg_data['description']; 1012 1030 $z = 0; 1013 while ($z < count($cfg_data['data'])) {1031 while ($z < count($cfg_data['data'])) { 1014 1032 $template_variables_array['data'][$z]['value'] = $cfg_data['data'][$z]['value']; 1015 1033 $template_variables_array['data'][$z]['description'] = $cfg_data['data'][$z]['text']; … … 1029 1047 break; 1030 1048 case "checkbox": 1031 if ((!$admin) && (isset($user_cfg_data[$key]))) {1049 if ((!$admin) && (isset($user_cfg_data[$key]))) { 1032 1050 $custom_cfg_data[$key] = $user_cfg_data[$key]; 1033 1051 } 1034 $num = $custom_cfg_data[$key];1052 $num = isset($custom_cfg_data[$key]) ? $custom_cfg_data[$key] : $cfg_data['default_value']; 1035 1053 $template_variables_array['type'] = "checkbox"; 1036 1054 $template_variables_array['key'] = $key; 1037 1055 $template_variables_array['description'] = $cfg_data['description']; 1038 $z = 0; 1039 while($z < count($cfg_data['data'])) { 1040 $template_variables_array['data'][$z]['key'] = $key; 1041 $template_variables_array['data'][$z]['value'] = $cfg_data['data'][$z]['value']; 1042 $template_variables_array['data'][$z]['description'] = $cfg_data['data'][$z]['text']; 1043 if ($cfg_data['data'][$z]['value'] == $num) { 1044 $template_variables_array['data'][$z]['checked'] = 'checked'; 1045 } 1046 $z++; 1047 } 1056 $template_variables_array['checked'] = $custom_cfg_data[$key] ? TRUE : NULL; 1057 $template_variables_array['value'] = $key; 1048 1058 break; 1049 1059 case "file"; 1050 if ((!$admin) && (isset($user_cfg_data[$key]))) {1060 if ((!$admin) && (isset($user_cfg_data[$key]))) { 1051 1061 $custom_cfg_data[$key] = $user_cfg_data[$key]; 1052 1062 } 1053 1063 $template_variables_array['type'] = "file"; 1054 if (isset($cfg_data['max_chars'])) {1064 if (isset($cfg_data['max_chars'])) { 1055 1065 $template_variables_array['max_chars'] = $cfg_data['max_chars']; 1056 1066 } … … 1060 1070 break; 1061 1071 case "textarea": 1062 if ((!$admin) && (isset($user_cfg_data[$key]))) {1072 if ((!$admin) && (isset($user_cfg_data[$key]))) { 1063 1073 $custom_cfg_data[$key] = $user_cfg_data[$key]; 1064 1074 } 1065 1075 $template_variables_array['type'] = "textarea"; 1066 if (isset($cfg_data['max_chars'])) {1076 if (isset($cfg_data['max_chars'])) { 1067 1077 $template_variables_array['max_chars'] = $cfg_data['max_chars']; 1068 1078 } 1069 1079 $template_variables_array['key'] = $key; 1070 $template_variables_array['value'] = $custom_cfg_data[$key];1080 $template_variables_array['value'] = isset($custom_cfg_data[$key]) ? $custom_cfg_data[$key] : $cfg_data['default_value']; 1071 1081 $template_variables_array['description'] = $cfg_data['description']; 1072 1082 break; 1073 1083 case "break": 1074 if($admin) {1084 if ($admin) { 1075 1085 $template_variables_array['type'] = "break"; 1076 } else {1086 } else { 1077 1087 $template_variables_array['type'] = "NA"; 1078 }1079 break;1088 } 1089 break; 1080 1090 default: 1081 1091 $template_variables_array['type'] = "NA"; … … 1083 1093 } 1084 1094 1085 if(isset($cfg_data['description_attr']['tooltip'])) {1086 $template_variables_array['tooltip'] = $cfg_data['description_attr']['tooltip'];1087 }1088 1089 if (($this->global_cfg['enable_ari']) AND ($admin) AND ($cfg_data['type'] != "break") AND ($cfg_data['type'] != "group")) {1090 1095 if (isset($cfg_data['description_attr']['tooltip'])) { 1096 $template_variables_array['tooltip'] = $cfg_data['description_attr']['tooltip']; 1097 } 1098 1099 if (($this->global_cfg['enable_ari']) AND ($admin) AND ($cfg_data['type'] != "break") AND ($cfg_data['type'] != "group") AND ($template_type == 'GENERAL')) { 1100 1091 1101 $template_variables_array['aried'] = 1; 1092 1102 $template_variables_array['ari']['key'] = $key; 1093 if(isset($custom_cfg_data_ari[$key])) { 1103 1104 if (isset($extra_data[$key])) { 1094 1105 $template_variables_array['ari']['checked'] = "checked"; 1106 } 1107 } 1108 1109 if($template_type == 'GLOBAL') { 1110 $template_variables_array['freepbxed'] = 1; 1111 $template_variables_array['freepbx']['key'] = $key; 1112 if(empty($extra_data)) { 1113 $template_variables_array['freepbx']['checked'] = TRUE; 1114 } elseif (isset($extra_data[$key])) { 1115 $template_variables_array['freepbx']['checked'] = TRUE; 1095 1116 } 1096 1117 } … … 1108 1129 //Custom Means specific to that MAC 1109 1130 //This function is reversed. Not sure why 1110 if ($custom != "0") {1111 $sql = "SELECT endpointman_model_list.max_lines, endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_product_list.id as product_id, endpointman_product_list.long_name, endpointman_model_list.template_data, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_brand_list, endpointman_mac_list, endpointman_model_list, endpointman_product_list WHERE endpointman_mac_list.id=" .$id." AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id";1112 } else { 1113 $sql = "SELECT endpointman_model_list.max_lines, endpointman_brand_list.directory, endpointman_product_list.cfg_dir, endpointman_product_list.config_files, endpointman_product_list.long_name, endpointman_model_list.template_data, endpointman_model_list.id as model_id, endpointman_template_list.* FROM endpointman_brand_list, endpointman_product_list, endpointman_model_list, endpointman_template_list WHERE endpointman_product_list.id = endpointman_template_list.product_id AND endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_template_list.model_id = endpointman_model_list.id AND endpointman_template_list.id = " .$id;1131 if ($custom != "0") { 1132 $sql = "SELECT endpointman_model_list.max_lines, endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_product_list.id as product_id, endpointman_product_list.long_name, endpointman_model_list.template_data, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_brand_list, endpointman_mac_list, endpointman_model_list, endpointman_product_list WHERE endpointman_mac_list.id=" . $id . " AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id"; 1133 } else { 1134 $sql = "SELECT endpointman_model_list.max_lines, endpointman_brand_list.directory, endpointman_product_list.cfg_dir, endpointman_product_list.config_files, endpointman_product_list.long_name, endpointman_model_list.template_data, endpointman_model_list.id as model_id, endpointman_template_list.* FROM endpointman_brand_list, endpointman_product_list, endpointman_model_list, endpointman_template_list WHERE endpointman_product_list.id = endpointman_template_list.product_id AND endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_template_list.model_id = endpointman_model_list.id AND endpointman_template_list.id = " . $id; 1114 1135 } 1115 1136 … … 1122 1143 $custom_cfg_data_ari = array(); 1123 1144 1124 foreach($cfg_data as $data) { 1125 $data = $this->fix_single_array_keys($data['category']); 1126 foreach($data as $cats) { 1127 $cats = $this->fix_single_array_keys($cats['subcategory']); 1128 foreach($cats as $subcats) { 1129 $items = $this->fix_single_array_keys($subcats['item']); 1130 foreach($items as $config_options) { 1131 if(array_key_exists('variable',$config_options)) { 1132 $temping = str_replace('$','',$config_options['variable']); 1133 $temping_ari = "ari_" . $temping; 1134 if(array_key_exists($temping, $_REQUEST)) { 1135 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 1136 if(array_key_exists($temping_ari, $_REQUEST)) { 1137 if($_REQUEST[$temping_ari] == "on") { 1138 $custom_cfg_data_ari[$temping] = 1; 1139 } 1140 } 1141 } 1142 } elseif ($config_options['type'] == 'loop') { 1143 $loop_start = $config_options['loop_start']; 1144 $loop_end = $config_options['loop_end']; 1145 $variables_count = 0; 1146 for($a=$loop_start;$a<=$loop_end;$a++) { 1147 foreach($config_options['data']['item'] as $items) { 1148 if(isset($items['description'])) { 1149 $items['description'] = str_replace('{$count}',$a,$items['description']); 1150 $temping = "loop|".str_replace('$','',$items['variable'])."_".$a; 1151 $temping_ari = "ari_" . $temping; 1152 if(array_key_exists($temping, $_REQUEST)) { 1153 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 1154 if(array_key_exists($temping_ari, $_REQUEST)) { 1155 if($_REQUEST[$temping_ari] == "on") { 1156 $custom_cfg_data_ari[$temping] = 1; 1157 } 1158 } 1145 foreach ($cfg_data['data'] as $cats) { 1146 foreach ($cats as $items) { 1147 foreach ($items as $key_name => $config_options) { 1148 if (preg_match('/(.*)\|(.*)/i', $key_name, $matches)) { 1149 $type = $matches[1]; 1150 $key = $matches[2]; 1151 } else { 1152 die('invalid'); 1153 } 1154 switch ($type) { 1155 case "loop": 1156 $stuffing = explode("_", $key); 1157 $key2 = $stuffing[0]; 1158 foreach ($config_options as $item_key => $item_data) { 1159 $lc = isset($item_data['loop_count']) ? $item_data['loop_count'] : ''; 1160 $key = 'loop|' . $key2 . '_' . $item_key . '_' . $lc; 1161 if ((isset($item_data['loop_count'])) AND (isset($_REQUEST[$key]))) { 1162 $custom_cfg_data[$key] = $_REQUEST[$key]; 1163 $ari_key = "ari_" . $key; 1164 if (isset($_REQUEST[$ari_key])) { 1165 if ($_REQUEST[$ari_key] == "on") { 1166 $custom_cfg_data_ari[$key] = 1; 1159 1167 } 1160 1168 } 1161 1169 } 1162 1170 } 1163 } elseif ($config_options['type'] == 'loop_line_options') { 1164 for($a=1;$a<=$row['max_lines'];$a++) { 1165 foreach($config_options['data']['item'] as $items) { 1166 if(isset($items['description'])) { 1167 $items['description'] = str_replace('{$count}',$a,$items['description']); 1168 $temping = "line|".$a."|".str_replace('$','',$items['variable']); 1169 $temping_ari = "ari_" . $temping; 1170 if(array_key_exists($temping, $_REQUEST)) { 1171 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 1172 if(array_key_exists($temping_ari, $_REQUEST)) { 1173 if($_REQUEST[$temping_ari] == "on") { 1174 $custom_cfg_data_ari[$temping] = 1; 1175 } 1176 } 1171 break; 1172 case "lineloop": 1173 foreach ($config_options as $item_key => $item_data) { 1174 $lc = isset($item_data['line_count']) ? $item_data['line_count'] : ''; 1175 $key = 'line|' . $lc . '|' . $item_key; 1176 if ((isset($item_data['line_count'])) AND (isset($_REQUEST[$key]))) { 1177 $custom_cfg_data[$key] = $_REQUEST[$key]; 1178 $ari_key = "ari_" . $key; 1179 if (isset($_REQUEST[$ari_key])) { 1180 if ($_REQUEST[$ari_key] == "on") { 1181 $custom_cfg_data_ari[$key] = 1; 1177 1182 } 1178 1183 } 1179 1184 } 1180 1185 } 1181 } 1182 } 1183 } 1184 } 1185 } 1186 1187 $config_files = explode(",",$row['config_files']); 1186 break; 1187 case "option": 1188 if (isset($_REQUEST[$key])) { 1189 $custom_cfg_data[$key] = $_REQUEST[$key]; 1190 $ari_key = "ari_" . $key; 1191 if (isset($_REQUEST[$ari_key])) { 1192 if ($_REQUEST[$ari_key] == "on") { 1193 $custom_cfg_data_ari[$key] = 1; 1194 } 1195 } 1196 } 1197 break; 1198 default: 1199 break; 1200 } 1201 } 1202 } 1203 } 1204 1205 $config_files = explode(",", $row['config_files']); 1188 1206 1189 1207 $i = 0; 1190 while ($i < count($config_files)) {1191 $config_files[$i] = str_replace(".", "_",$config_files[$i]);1192 if (isset($_REQUEST[$config_files[$i]])) {1193 $_REQUEST[$config_files[$i]] = explode("_", $_REQUEST[$config_files[$i]], 2);1208 while ($i < count($config_files)) { 1209 $config_files[$i] = str_replace(".", "_", $config_files[$i]); 1210 if (isset($_REQUEST[$config_files[$i]])) { 1211 $_REQUEST[$config_files[$i]] = explode("_", $_REQUEST[$config_files[$i]], 2); 1194 1212 $_REQUEST[$config_files[$i]] = $_REQUEST[$config_files[$i]][0]; 1195 if ($_REQUEST[$config_files[$i]] > 0) {1213 if ($_REQUEST[$config_files[$i]] > 0) { 1196 1214 $config_files_selected[$config_files[$i]] = $_REQUEST[$config_files[$i]]; 1197 1215 } … … 1200 1218 } 1201 1219 1202 if (!isset($config_files_selected)) {1220 if (!isset($config_files_selected)) { 1203 1221 $config_files_selected = ""; 1204 1222 } else { … … 1207 1225 $custom_cfg_data_temp['data'] = $custom_cfg_data; 1208 1226 $custom_cfg_data_temp['ari'] = $custom_cfg_data_ari; 1227 1209 1228 $save = serialize($custom_cfg_data_temp); 1210 1229 1211 if ($custom == "0") {1212 $sql = 'UPDATE endpointman_template_list SET config_files_override = \'' .addslashes($config_files_selected).'\', global_custom_cfg_data = \''.addslashes($save).'\' WHERE id ='.$id;1230 if ($custom == "0") { 1231 $sql = 'UPDATE endpointman_template_list SET config_files_override = \'' . addslashes($config_files_selected) . '\', global_custom_cfg_data = \'' . addslashes($save) . '\' WHERE id =' . $id; 1213 1232 $location = "template_manager"; 1214 1233 } else { 1215 $sql = 'UPDATE endpointman_mac_list SET config_files_override = \'' .addslashes($config_files_selected).'\', template_id = 0, global_custom_cfg_data = \''.addslashes($save).'\' WHERE id ='.$id;1234 $sql = 'UPDATE endpointman_mac_list SET config_files_override = \'' . addslashes($config_files_selected) . '\', template_id = 0, global_custom_cfg_data = \'' . addslashes($save) . '\' WHERE id =' . $id; 1216 1235 $location = "devices_manager"; 1217 1236 } 1218 1237 1219 1238 $this->eda->sql($sql); 1220 1239 1221 1240 $phone_info = array(); 1222 1241 1223 if ($custom != 0) {1242 if ($custom != 0) { 1224 1243 $phone_info = $this->get_phone_info($id); 1225 if (isset($_REQUEST['epm_reboot'])) {1244 if (isset($_REQUEST['epm_reboot'])) { 1226 1245 $this->prepare_configs($phone_info); 1227 1246 } else { 1228 $this->prepare_configs($phone_info, FALSE);1229 } 1230 } else { 1231 $sql = 'SELECT id FROM endpointman_mac_list WHERE template_id = ' .$id;1247 $this->prepare_configs($phone_info, FALSE); 1248 } 1249 } else { 1250 $sql = 'SELECT id FROM endpointman_mac_list WHERE template_id = ' . $id; 1232 1251 $phones = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 1233 foreach ($phones as $data) {1252 foreach ($phones as $data) { 1234 1253 $phone_info = $this->get_phone_info($data['id']); 1235 if (isset($_REQUEST['epm_reboot'])) {1254 if (isset($_REQUEST['epm_reboot'])) { 1236 1255 $this->prepare_configs($phone_info); 1237 1256 } else { 1238 $this->prepare_configs($phone_info, FALSE);1239 } 1240 } 1241 } 1242 1243 if (isset($_REQUEST['silent_mode'])) {1257 $this->prepare_configs($phone_info, FALSE); 1258 } 1259 } 1260 } 1261 1262 if (isset($_REQUEST['silent_mode'])) { 1244 1263 echo '<script language="javascript" type="text/javascript">window.close();</script>'; 1245 1264 } else { 1246 1265 return($location); 1247 1266 } 1248 1267 } 1268 1269 function write_configs($provisioner_lib, $reboot, $write_path, $phone_info, $returned_data) { 1270 //Create Directory Structure (If needed) 1271 if (isset($provisioner_lib->directory_structure)) { 1272 foreach ($provisioner_lib->directory_structure as $data) { 1273 $dir = $write_path . $data; 1274 if (!file_exists($dir)) { 1275 if (!@mkdir($dir, 0755)) { 1276 $this->error['parse_configs'] = "Could Not Create Directory: " . $data; 1277 return(FALSE); 1278 } 1279 } 1280 } 1281 } 1282 1283 //Copy Files/Directories (If needed) 1284 if (isset($provisioner_lib->copy_files)) { 1285 foreach ($provisioner_lib->copy_files as $data) { 1286 if (((file_exists($write_path . $data)) AND (!in_array($data, $provisioner_lib->protected_files))) OR (!file_exists($write_path . $data))) { 1287 if (is_dir(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data)) { 1288 if (!file_exists($write_path . $data)) { 1289 if (!@mkdir($write_path . $data, 0666)) { 1290 $this->error['parse_configs'] = "Could Not Create Directory: " . $data; 1291 return(FALSE); 1292 } 1293 } 1294 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data . "/"); 1295 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); 1296 // could use CHILD_FIRST if you so wish 1297 foreach ($iterator as $file) { 1298 if (is_dir($file)) { 1299 $dir = str_replace(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data . "/", "", $file); 1300 if (!file_exists($write_path . $data . "/" . $dir)) { 1301 if (!@mkdir($write_path . $data . "/" . $dir, 0666)) { 1302 $this->error['parse_configs'] = "Could Not Create Directory: " . $data . "/" . $dir; 1303 return(FALSE); 1304 } 1305 } 1306 } else { 1307 $dir = str_replace(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data . "/", "", $file); 1308 if (!@copy($file, $write_path . $data . "/" . $dir)) { 1309 $this->error['parse_configs'] = "Could Not Copy File: " . $data . "/" . $dir; 1310 return(FALSE); 1311 } else { 1312 chmod($write_path . $data . "/" . $dir, 0666); 1313 } 1314 } 1315 } 1316 } else { 1317 copy(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data, $write_path . $data); 1318 chmod($write_path . $data, 0666); 1319 } 1320 } 1321 } 1322 } 1323 1324 foreach ($returned_data as $file => $data) { 1325 if (((file_exists($write_path . $file)) AND (is_writable($write_path . $file)) AND (!in_array($file, $provisioner_lib->protected_files))) OR (!file_exists($write_path . $file))) { 1326 file_put_contents($write_path . $file, $data); 1327 chmod($write_path . $file, 0666); 1328 if (!file_exists($write_path . $file)) { 1329 $this->error['parse_configs'] = "File not written to hard drive!"; 1330 return(FALSE); 1331 } 1332 } elseif (!in_array($file, $provisioner_lib->protected_files)) { 1333 $this->error['parse_configs'] = "File not written to hard drive!"; 1334 return(FALSE); 1335 } 1336 } 1337 1338 if ($reboot) { 1339 $provisioner_lib->reboot(); 1340 } 1341 } 1342 1343 function display_configs() { 1344 1249 1345 } 1250 1346 … … 1255 1351 * @param bool $write Write out Directory structure. 1256 1352 */ 1257 function prepare_configs($phone_info, $reboot=TRUE,$write=TRUE) {1258 1259 if (file_exists(PHONE_MODULES_PATH.'setup.php')) {1260 if (!class_exists('ProvisionerConfig')) {1261 require(PHONE_MODULES_PATH .'setup.php');1353 function prepare_configs($phone_info, $reboot=TRUE, $write=TRUE) { 1354 1355 if (file_exists(PHONE_MODULES_PATH . 'setup.php')) { 1356 if (!class_exists('ProvisionerConfig')) { 1357 require(PHONE_MODULES_PATH . 'setup.php'); 1262 1358 } 1263 1359 1264 1360 //Load Provisioner 1265 1361 $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; 1266 $base_class = "endpoint_" . $phone_info['directory'] . '_base';1362 $base_class = "endpoint_" . $phone_info['directory'] . '_base'; 1267 1363 $master_class = "endpoint_base"; 1268 /**Quick Fix for FreePBX Distro 1269 * I seriously want to figure out why ONLY the FreePBX Distro can't do autoloads. 1270 **/ 1271 if(!class_exists($master_class)) { 1364 if (!class_exists($master_class)) { 1272 1365 ProvisionerConfig::endpointsAutoload($master_class); 1273 1366 } 1274 if (!class_exists($base_class)) {1367 if (!class_exists($base_class)) { 1275 1368 ProvisionerConfig::endpointsAutoload($base_class); 1276 1369 } 1277 if (!class_exists($class)) {1370 if (!class_exists($class)) { 1278 1371 ProvisionerConfig::endpointsAutoload($class); 1279 1372 } 1280 //end quick fix 1281 1282 if(class_exists($class)) { 1373 1374 if (class_exists($class)) { 1283 1375 $provisioner_lib = new $class(); 1284 1376 1285 1377 //Determine if global settings have been overridden 1286 if ($phone_info['template_id'] > 0) {1287 if (isset($phone_info['template_data_info']['global_settings_override'])) {1378 if ($phone_info['template_id'] > 0) { 1379 if (isset($phone_info['template_data_info']['global_settings_override'])) { 1288 1380 $settings = unserialize($phone_info['template_data_info']['global_settings_override']); 1289 1381 } else { … … 1294 1386 } 1295 1387 } else { 1296 if (isset($phone_info['global_settings_override'])) {1388 if (isset($phone_info['global_settings_override'])) { 1297 1389 $settings = unserialize($phone_info['global_settings_override']); 1298 1390 } else { … … 1316 1408 $provisioner_lib->family_line = $phone_info['cfg_dir']; 1317 1409 1318 //Mac Address 1319 $provisioner_lib->mac = $phone_info['mac']; 1410 1320 1411 1321 1412 //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models) … … 1327 1418 try { 1328 1419 $provisioner_lib->DateTimeZone = new DateTimeZone($settings['tz']); 1329 } catch (Exception $e) {1330 $this->error['parse_configs'] = ' Caught exception: '. $e->getMessage();1420 } catch (Exception $e) { 1421 $this->error['parse_configs'] = 'Error Returned From Timezone Library: ' . $e->getMessage(); 1331 1422 return(FALSE); 1332 1423 } 1333 1334 //Network Time Server1335 $provisioner_lib->ntp = $settings['ntp'];1336 1337 //Server IP1338 $provisioner_lib->server[1]['ip'] = $settings['srvip'];1339 $provisioner_lib->server[1]['port'] = 5060;1340 1424 1341 1425 $temp = ""; 1342 1426 $template_data = unserialize($phone_info['template_data']); 1343 1427 $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']); 1344 if ($phone_info['template_id'] > 0) {1428 if ($phone_info['template_id'] > 0) { 1345 1429 $global_custom_cfg_data = unserialize($phone_info['template_data_info']['global_custom_cfg_data']); 1346 1430 //Provide alternate Configuration file instead of the one from the hard drive 1347 if (!empty($phone_info['template_data_info']['config_files_override'])) {1431 if (!empty($phone_info['template_data_info']['config_files_override'])) { 1348 1432 $temp = unserialize($phone_info['template_data_info']['config_files_override']); 1349 foreach ($temp as $list) {1350 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " .$list;1433 foreach ($temp as $list) { 1434 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " . $list; 1351 1435 $res = $this->eda->sql($sql); 1352 if ($res->numRows()) {1353 $data = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC);1436 if ($res->numRows()) { 1437 $data = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 1354 1438 $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; 1355 1439 } … … 1359 1443 $global_custom_cfg_data = unserialize($phone_info['global_custom_cfg_data']); 1360 1444 //Provide alternate Configuration file instead of the one from the hard drive 1361 if (!empty($phone_info['config_files_override'])) {1445 if (!empty($phone_info['config_files_override'])) { 1362 1446 $temp = unserialize($phone_info['config_files_override']); 1363 foreach ($temp as $list) {1364 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " .$list;1447 foreach ($temp as $list) { 1448 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " . $list; 1365 1449 $res = $this->eda->sql($sql); 1366 if ($res->numRows()) {1367 $data = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC);1450 if ($res->numRows()) { 1451 $data = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 1368 1452 $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; 1369 1453 } … … 1373 1457 1374 1458 if (!empty($global_custom_cfg_data)) { 1375 if (array_key_exists('data', $global_custom_cfg_data)) {1459 if (array_key_exists('data', $global_custom_cfg_data)) { 1376 1460 $global_custom_cfg_ari = $global_custom_cfg_data['ari']; 1377 1461 $global_custom_cfg_data = $global_custom_cfg_data['data']; … … 1384 1468 $new_template_data = array(); 1385 1469 $line_ops = array(); 1386 if(is_array($global_custom_cfg_data)) { 1387 foreach($global_custom_cfg_data as $key => $data) { 1470 if (is_array($global_custom_cfg_data)) { 1471 foreach ($global_custom_cfg_data as $key => $data) { 1472 //TODO: clean up with reg-exp 1388 1473 $full_key = $key; 1389 $key = explode('|', $key);1474 $key = explode('|', $key); 1390 1475 $count = count($key); 1391 switch ($count) {1476 switch ($count) { 1392 1477 case 1: 1393 if (($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) {1478 if (($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 1394 1479 $new_template_data[$full_key] = $global_user_cfg_data[$full_key]; 1395 1480 } else { … … 1398 1483 break; 1399 1484 case 2: 1400 $breaks = explode('_', $key[1]);1401 if (($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) {1402 $new_template_data[ $breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key];1485 $breaks = explode('_', $key[1]); 1486 if (($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 1487 $new_template_data['loops'][$breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key]; 1403 1488 } else { 1404 $new_template_data[ $breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key];1489 $new_template_data['loops'][$breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key]; 1405 1490 } 1406 1491 break; 1407 1492 case 3: 1408 if (($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) {1493 if (($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 1409 1494 $line_ops[$key[1]][$key[2]] = $global_user_cfg_data[$full_key]; 1410 1495 } else { … … 1416 1501 } 1417 1502 1418 //Loop through Lines!1419 foreach($phone_info['line'] as $line) {1420 $provisioner_lib->lines[$line['line']] = array('ext' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description']);1421 }1422 1423 //testing this out1424 foreach ($line_ops as $key => $data) {1425 if (isset($line_ops[$key])) {1426 $provisioner_lib->lines[$key]['options'] = $line_ops[$key];1427 }1428 }1429 1430 1503 if (!$write) { 1431 $provisioner_lib->server_type = 'dynamic'; 1432 $provisioner_lib->provisioning_type = 'http'; 1433 $new_template_data['provisioning_path'] = $_SERVER["SERVER_ADDR"]."/provisioning/"; 1434 } 1504 $new_template_data['provision']['type'] = 'dynamic'; 1505 $new_template_data['provision']['protocol'] = 'http'; 1506 $new_template_data['provision']['path'] = $_SERVER["SERVER_ADDR"] . dirname($_SERVER['REQUEST_URI']) . '/'; 1507 $new_template_data['provision']['encryption'] = FALSE; 1508 } else { 1509 $new_template_data['provision']['type'] = 'file'; 1510 $new_template_data['provision']['protocol'] = 'tftp'; 1511 $new_template_data['provision']['path'] = $_SERVER["SERVER_ADDR"]; 1512 $new_template_data['provision']['encryption'] = FALSE; 1513 } 1514 1515 $new_template_data['ntp'] = $settings['ntp']; 1516 1517 $new_template_data['network']['dhcp'] = TRUE; 1518 $new_template_data['network']['ipv4'] = ''; 1519 $new_template_data['network']['ipv6'] = ''; 1520 $new_template_data['network']['subnet'] = '255.255.255.0'; 1521 $new_template_data['network']['gateway'] = ''; 1522 $new_template_data['network']['vlan']['id'] = ''; 1523 $new_template_data['network']['vlan']['qos'] = ''; 1524 1525 //Overwrite all specific settings variables now 1526 if (!empty($phone_info['specific_settings'])) { 1527 $specific_settings = unserialize($phone_info['specific_settings']); 1528 $specific_settings = is_array($specific_settings) ? $specific_settings : array(); 1529 } else { 1530 $specific_settings = array(); 1531 } 1532 1435 1533 1436 1534 //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create 1437 1535 //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included 1438 1536 //line 'global' will set variables that aren't line dependant 1439 $provisioner_lib->options = $new_template_data; 1537 1538 1539 $provisioner_lib->settings = $new_template_data; 1540 1541 //Loop through Lines! 1542 $li = 0; 1543 foreach ($phone_info['line'] as $line) { 1544 $line_options = is_array($line_ops[$line['line']]) ? $line_ops[$line['line']] : array(); 1545 $line_statics = array('line' => $line['line'], 'username' => $line['ext'], 'authname' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description'], 'server_host' => $this->global_cfg['srvip'], 'server_port' => '5060'); 1546 1547 $provisioner_lib->settings['line'][$li] = array_merge($line_options, $line_statics); 1548 $li++; 1549 } 1550 1551 foreach($specific_settings['data'] as $key => $data) { 1552 $default_exp = preg_split("/\|/i", $key); 1553 if(isset($default_exp[2])) { 1554 //lineloop 1555 $var = $default_exp[2]; 1556 $line = $default_exp[1]; 1557 $loc = $this->arraysearchrecursive($line, $provisioner_lib->settings['line'], 'line'); 1558 if($loc !== FALSE) { 1559 $k = $loc[0]; 1560 $provisioner_lib->settings['line'][$k][$var] = $data; 1561 } else { 1562 //Adding a new line-ish type options 1563 if(isset($specific_settings['data']['line|'.$line.'|line_enabled'])) { 1564 $lastkey = array_pop(array_keys($provisioner_lib->settings['line'])); 1565 $lastkey++; 1566 $provisioner_lib->settings['line'][$lastkey]['line'] = $line; 1567 $provisioner_lib->settings['line'][$lastkey][$var] = $data; 1568 } 1569 } 1570 } else { 1571 $provisioner_lib->settings[$var] = $data; 1572 } 1573 } 1574 1575 $provisioner_lib->settings['mac'] = $phone_info['mac']; 1576 $provisioner_lib->mac = $phone_info['mac']; 1440 1577 1441 1578 //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed 1442 1579 //and if they have defaults assigned in a future template_data.xml or in the config file using pipes (|) those will be used, pipes take precedence 1443 $provisioner_lib->processor_info = "EndPoint Manager Version " .$this->global_cfg['version'];1580 $provisioner_lib->processor_info = "EndPoint Manager Version " . $this->global_cfg['version']; 1444 1581 1445 1582 // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is 1446 1583 //Start timer 1447 1584 $time_start = microtime(true); 1448 $returned_data = $provisioner_lib->generate_config(); 1585 1586 $provisioner_lib->debug = TRUE; 1587 1588 try { 1589 $returned_data = $provisioner_lib->generate_all_files(); 1590 } catch (Exception $e) { 1591 $this->error['prepare_configs'] = 'Error Returned From Provisioner Library: '. $e->getMessage(); 1592 return(FALSE); 1593 } 1594 1595 1596 //print_r($provisioner_lib->debug_return); 1449 1597 //End timer 1450 1598 $time_end = microtime(true); 1451 1599 $time = $time_end - $time_start; 1452 if($time > 360) { 1453 $this->error['generate_time'] = "It took an awfully long time to generate configs...(".round($time,2)." seconds)"; 1454 } 1455 if($write) { 1456 //Create Directory Structure (If needed) 1457 if(isset($provisioner_lib->directory_structure)) { 1458 foreach($provisioner_lib->directory_structure as $data) { 1459 $dir = $settings['config_location'] . $data; 1460 if(!file_exists($dir)) { 1461 mkdir($dir, 0755); 1462 } 1463 } 1464 } 1465 1466 //Copy Files/Directories (If needed) 1467 if(isset($provisioner_lib->copy_files)) { 1468 foreach($provisioner_lib->copy_files as $data) { 1469 if(((file_exists($settings['config_location'].$data)) AND (!in_array($data,$provisioner_lib->protected_files))) OR (!file_exists($settings['config_location'].$data))) { 1470 if(is_dir(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data)) { 1471 if(!file_exists($settings['config_location'].$data)) { 1472 if (!@mkdir($settings['config_location'].$data, 0666)) { 1473 $this->error['parse_configs'] = "Could Not Create Directory: ".$data; 1474 return(FALSE); 1475 } 1476 } 1477 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/"); 1478 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); 1479 // could use CHILD_FIRST if you so wish 1480 foreach ($iterator as $file) { 1481 if(is_dir($file)) { 1482 $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); 1483 if(!file_exists($settings['config_location'].$data."/".$dir)) { 1484 if (!@mkdir($settings['config_location'].$data."/".$dir, 0666)) { 1485 $this->error['parse_configs'] = "Could Not Create Directory: ".$data."/".$dir; 1486 return(FALSE); 1487 } 1488 } 1489 } else { 1490 $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); 1491 if(!@copy($file, $settings['config_location'].$data."/".$dir)) { 1492 $this->error['parse_configs'] = "Could Not Copy File: ".$data."/".$dir; 1493 return(FALSE); 1494 } else { 1495 chmod($settings['config_location'].$data."/".$dir, 0666); 1496 } 1497 } 1498 } 1499 } else { 1500 copy(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data,$settings['config_location'].$data); 1501 chmod($settings['config_location'].$data, 0666); 1502 } 1503 } 1504 } 1505 } 1506 1507 //Generate Files 1508 foreach($returned_data as $key => $data) { 1509 if(((file_exists($settings['config_location'].$key)) AND (is_writable($settings['config_location'].$key)) AND (!in_array($key,$provisioner_lib->protected_files))) OR (!file_exists($settings['config_location'].$key))) { 1510 $fp = fopen($settings['config_location'].$key, 'w'); 1511 fwrite($fp, $data); 1512 fclose($fp); 1513 chmod($settings['config_location'].$key, 0666); 1514 if(!file_exists($settings['config_location'].$key)) { 1515 $this->error['parse_configs'] = "File not written to hard drive!"; 1516 return(FALSE); 1517 } 1518 } elseif(!in_array($key,$provisioner_lib->protected_files)) { 1519 $this->error['parse_configs'] = "File not written to hard drive!"; 1520 return(FALSE); 1521 } 1522 } 1523 if($reboot) { 1524 $provisioner_lib->reboot(); 1525 } 1600 if ($time > 360) { 1601 $this->error['generate_time'] = "It took an awfully long time to generate configs...(" . round($time, 2) . " seconds)"; 1602 } 1603 if ($write) { 1604 $this->write_configs($provisioner_lib, $reboot, $settings['config_location'], $phone_info, $returned_data); 1526 1605 } else { 1527 if($reboot) { 1528 $provisioner_lib->reboot(); 1529 } 1530 return($returned_data); 1606 return ($returned_data); 1531 1607 } 1532 1608 return(TRUE); 1533 1609 } else { 1534 $this->error['parse_configs'] = "Can't Load \"" .$class."\" Class!";1610 $this->error['parse_configs'] = "Can't Load \"" . $class . "\" Class!"; 1535 1611 return(FALSE); 1536 1612 } … … 1547 1623 */ 1548 1624 function firmware_update_check($id=NULL) { 1549 $sql = "SELECT * FROM endpointman_product_list WHERE id ='" . $id."'";1550 $row = $this->eda->sql($sql, 'getRow',DB_FETCHMODE_ASSOC);1551 1552 $sql = "SELECT directory FROM endpointman_brand_list WHERE id =" . $row['brand'];1553 $brand_directory = $this->eda->sql($sql, 'getOne');1625 $sql = "SELECT * FROM endpointman_product_list WHERE id ='" . $id . "'"; 1626 $row = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 1627 1628 $sql = "SELECT directory FROM endpointman_brand_list WHERE id =" . $row['brand']; 1629 $brand_directory = $this->eda->sql($sql, 'getOne'); 1554 1630 1555 1631 //config drive unknown! … … 1557 1633 return FALSE; 1558 1634 } else { 1559 $temp = $this-> xml2array(PHONE_MODULES_PATH."endpoint/".$brand_directory."/".$row['cfg_dir']."/family_data.xml");1560 if ((array_key_exists('data',$temp)) AND (!is_array($temp['data']['firmware_ver']))) {1561 if ($row['firmware_vers'] < $temp['data']['firmware_ver']) {1635 $temp = $this->file2json(PHONE_MODULES_PATH . "endpoint/" . $brand_directory . "/" . $row['cfg_dir'] . "/family_data.json"); 1636 if ((array_key_exists('data', $temp)) AND (!is_array($temp['data']['firmware_ver']))) { 1637 if ($row['firmware_vers'] < $temp['data']['firmware_ver']) { 1562 1638 return $temp; 1563 1639 } else { … … 1568 1644 } 1569 1645 } 1570 1571 1646 } 1572 1647 … … 1577 1652 */ 1578 1653 function firmware_local_check($id=NULL) { 1579 $sql = "SELECT * FROM endpointman_product_list WHERE hidden = 0 AND id ='" . $id ."'";1654 $sql = "SELECT * FROM endpointman_product_list WHERE hidden = 0 AND id ='" . $id . "'"; 1580 1655 $res = $this->eda->sql($sql); 1581 1656 1582 if ($res->numRows()) {1583 $row = $this->eda->sql($sql, 'getRow',DB_FETCHMODE_ASSOC);1584 1585 $sql = "SELECT directory FROM endpointman_brand_list WHERE hidden = 0 AND id =" . $row['brand'];1586 $brand_directory = $this->eda->sql($sql, 'getOne');1657 if ($res->numRows()) { 1658 $row = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 1659 1660 $sql = "SELECT directory FROM endpointman_brand_list WHERE hidden = 0 AND id =" . $row['brand']; 1661 $brand_directory = $this->eda->sql($sql, 'getOne'); 1587 1662 1588 1663 //config drive unknown! … … 1590 1665 return("nothing"); 1591 1666 } else { 1592 $temp = $this-> xml2array(PHONE_MODULES_PATH."endpoint/".$brand_directory."/".$row['cfg_dir']."/family_data.xml");1593 1594 if ((isset ($temp['data']['firmware_ver'])) AND (!is_array($temp['data']['firmware_ver']))) {1595 if ($row['firmware_vers'] == "") {1667 $temp = $this->file2json(PHONE_MODULES_PATH . "endpoint/" . $brand_directory . "/" . $row['cfg_dir'] . "/family_data.json"); 1668 1669 if ($temp['data']['firmware_ver'] != NULL) { 1670 if ($row['firmware_vers'] == "") { 1596 1671 return("install"); 1597 1672 } else { … … 1612 1687 */ 1613 1688 function remove_firmware($id) { 1614 $sql = "SELECT firmware_files FROM endpointman_product_list WHERE id =" . $id;1615 $files = $this->eda->sql($sql, 'getOne');1616 1617 $file_list = explode(",", $files);1689 $sql = "SELECT firmware_files FROM endpointman_product_list WHERE id =" . $id; 1690 $files = $this->eda->sql($sql, 'getOne'); 1691 1692 $file_list = explode(",", $files); 1618 1693 $i = 0; 1619 foreach ($file_list as $file) {1620 if (file_exists($this->global_cfg['config_location'].$file)) {1621 unlink($this->global_cfg['config_location'] .$file);1622 } 1623 } 1624 $sql = 'UPDATE endpointman_product_list SET firmware_files = "", firmware_vers = "" WHERE id = ' .$id;1694 foreach ($file_list as $file) { 1695 if (file_exists($this->global_cfg['config_location'] . $file)) { 1696 unlink($this->global_cfg['config_location'] . $file); 1697 } 1698 } 1699 $sql = 'UPDATE endpointman_product_list SET firmware_files = "", firmware_vers = "" WHERE id = ' . $id; 1625 1700 $this->eda->sql($sql); 1626 1701 } … … 1631 1706 */ 1632 1707 function install_firmware($product_id) { 1633 $sql = 'SELECT endpointman_product_list.*, endpointman_brand_list.directory FROM endpointman_product_list, endpointman_brand_list WHERE endpointman_product_list.brand = endpointman_brand_list.id AND endpointman_product_list.id = ' .$product_id;1708 $sql = 'SELECT endpointman_product_list.*, endpointman_brand_list.directory FROM endpointman_product_list, endpointman_brand_list WHERE endpointman_product_list.brand = endpointman_brand_list.id AND endpointman_product_list.id = ' . $product_id; 1634 1709 $row = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); 1635 $temp = $this-> xml2array(PHONE_MODULES_PATH."endpoint/".$row['directory']."/".$row['cfg_dir']."/family_data.xml");1636 if ($temp['data']['firmware_ver'] > $row['firmware_vers']) {1710 $temp = $this->file2json(PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir'] . "/family_data.json"); 1711 if ($temp['data']['firmware_ver'] > $row['firmware_vers']) { 1637 1712 echo "<div style='float: left'>Downloading firmware...</div><div style='float: left' id=\"DivExample\">.</div>"; 1638 $this->download_file_with_progress_bar(UPDATE_PATH .$row['directory']."/". $temp['data']['firmware_pkg'], PHONE_MODULES_PATH."temp/".$temp['data']['firmware_pkg']);1713 $this->download_file_with_progress_bar(UPDATE_PATH . $row['directory'] . "/" . $temp['data']['firmware_pkg'], PHONE_MODULES_PATH . "temp/" . $temp['data']['firmware_pkg']); 1639 1714 echo "<script type='text/javascript'>document.getElementById('DivExample').innerHTML='Done!';</script><br />"; 1640 1715 $md5_xml = $temp['data']['firmware_md5sum']; 1641 $md5_pkg = md5_file(PHONE_MODULES_PATH .'temp/'. $temp['data']['firmware_pkg']);1716 $md5_pkg = md5_file(PHONE_MODULES_PATH . 'temp/' . $temp['data']['firmware_pkg']); 1642 1717 echo "Checking MD5sum of Package..."; 1643 1718 if ($md5_xml == $md5_pkg) { 1644 1719 echo "Matches!<br />"; 1645 if (!file_exists(PHONE_MODULES_PATH."endpoint/".$row['directory']."/".$row['cfg_dir']."/firmware")) {1646 mkdir(PHONE_MODULES_PATH ."endpoint/".$row['directory']."/".$row['cfg_dir']."/firmware");1720 if (!file_exists(PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir'] . "/firmware")) { 1721 mkdir(PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir'] . "/firmware"); 1647 1722 } 1648 1723 echo "Installing Firmware..."; 1649 exec("rm -Rf " .PHONE_MODULES_PATH."endpoint/".$row['directory']."/".$row['cfg_dir']."/firmware");1650 mkdir(PHONE_MODULES_PATH ."endpoint/".$row['directory']."/".$row['cfg_dir']."/firmware");1651 exec("tar -xvf " .PHONE_MODULES_PATH.'temp/'. $temp['data']['firmware_pkg'] ." -C ".PHONE_MODULES_PATH."endpoint/".$row['directory']."/".$row['cfg_dir']);1724 exec("rm -Rf " . PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir'] . "/firmware"); 1725 mkdir(PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir'] . "/firmware"); 1726 exec("tar -xvf " . PHONE_MODULES_PATH . 'temp/' . $temp['data']['firmware_pkg'] . " -C " . PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir']); 1652 1727 $i = 0; 1653 foreach (glob(PHONE_MODULES_PATH ."endpoint/".$row['directory']."/".$row['cfg_dir']."/firmware/*.*") as $filename) {1728 foreach (glob(PHONE_MODULES_PATH . "endpoint/" . $row['directory'] . "/" . $row['cfg_dir'] . "/firmware/*.*") as $filename) { 1654 1729 $file = basename($filename); 1655 1730 $list[$i] = $file; 1656 if (!@copy($filename, $this->global_cfg['config_location'] .$file)) {1731 if (!@copy($filename, $this->global_cfg['config_location'] . $file)) { 1657 1732 echo "<br />--Failed To Copy $file..."; 1658 1733 $copy_error = TRUE; 1659 } elseif ($this->global_cfg['debug']) {1660 echo"<br />--Copied " .$file." to ". $this->global_cfg['config_location'];1734 } elseif ($this->global_cfg['debug']) { 1735 echo"<br />--Copied " . $file . " to " . $this->global_cfg['config_location']; 1661 1736 } 1662 1737 $i++; 1663 1738 } 1664 1739 $list = implode(",", $list); 1665 $sql = "UPDATE endpointman_product_list SET firmware_vers = '" .$temp['data']['firmware_ver']."', firmware_files = '".$list."' WHERE id = ". $row['id'];1740 $sql = "UPDATE endpointman_product_list SET firmware_vers = '" . $temp['data']['firmware_ver'] . "', firmware_files = '" . $list . "' WHERE id = " . $row['id']; 1666 1741 $this->eda->sql($sql); 1667 if (isset($copy_error)) {1742 if (isset($copy_error)) { 1668 1743 echo "<BR />Copy Error Detected! Aborting Install!"; 1669 1744 $this->remove_firmware($product_id); … … 1677 1752 } else { 1678 1753 echo "<BR />Your Firmware is already up to date"; 1679 1680 } 1681 } 1682 1683 /** 1684 * Fix arrays so that they don't return an empty array if the array is empty 1685 * Instead we will return an empty string 1686 * Also we fix the problem of wanting to get single arrays with keys but not getting them 1687 * @param array $array 1688 * @return array 1689 */ 1690 function fix_single_array_keys($array) { 1691 if((empty($array[0])) AND (!empty($array))) { 1692 $array_n[0] = $array; 1693 return($array_n); 1694 } elseif(!empty($array)) { 1695 return($array); 1696 //This is so stupid?! PHP gets confused. 1697 } elseif($array == '0') { 1698 return($array); 1699 } else { 1700 return(""); 1701 } 1702 } 1703 1704 /** 1705 * Download the requested XML configuration files from the web 1706 * @param string $location full URL of the XML file 1707 * @param string $directory Directory to place the XML file in relation to provisioner.net 1708 * @return bool True if downloaded, false if failed. 1709 */ 1710 function download_xml($location,$directory=NULL) { 1711 //If directory is not set then assume we are working with the master.xml file 1712 if(!isset($directory)) { 1713 $destination_file = PHONE_MODULES_PATH.'master.xml'; 1754 } 1755 } 1756 1757 function download_json($location, $directory=NULL) { 1758 if (!isset($directory)) { 1759 $destination_file = PHONE_MODULES_PATH . 'master.json'; 1714 1760 $directory = "master"; 1715 1761 } else { 1716 if (!file_exists(PHONE_MODULES_PATH.'/'.$directory)) {1717 mkdir(PHONE_MODULES_PATH .'/'.$directory,0764,TRUE);1718 } 1719 $destination_file = PHONE_MODULES_PATH .'/'.$directory.'/brand_data.xml';1720 } 1721 $temp_file = PHONE_MODULES_PATH .'temp/'.$directory.'.xml';1762 if (!file_exists(PHONE_MODULES_PATH . '/' . $directory)) { 1763 mkdir(PHONE_MODULES_PATH . '/' . $directory, 0764, TRUE); 1764 } 1765 $destination_file = PHONE_MODULES_PATH . '/' . $directory . '/brand_data.json'; 1766 } 1767 $temp_file = PHONE_MODULES_PATH . 'temp/' . $directory . '.json'; 1722 1768 file_exists(dirname($temp_file)) ? '' : mkdir(dirname($temp_file)); 1723 1724 if ($this->download_xml_file($location, $temp_file)) {1769 1770 if ($this->download_file($location, $temp_file)) { 1725 1771 $handle = fopen($temp_file, "rb"); 1726 1772 $contents = fread($handle, filesize($temp_file)); 1727 1773 fclose($handle); 1728 1729 @$a = simplexml_load_string($contents);1730 if ($a===FALSE) {1774 1775 $a = $this->validate_json($contents); 1776 if ($a === FALSE) { 1731 1777 //Error with the internet....ABORRRTTTT THEEEEE DOWNLOAAAAADDDDDDDD! SCOTTYYYY!; 1732 1778 unlink($temp_file); … … 1734 1780 } else { 1735 1781 rename($temp_file, $destination_file); 1736 chmod($destination_file, 0764);1782 chmod($destination_file, 0764); 1737 1783 return(TRUE); 1738 1784 } … … 1748 1794 */ 1749 1795 function update_check() { 1750 $master_result = $this->download_xml(UPDATE_PATH . "master.xml"); 1796 $master_result = $this->download_file(UPDATE_PATH . "master.json", PHONE_MODULES_PATH . "master.json"); 1797 1751 1798 1752 1799 1753 if (!$master_result) {1800 if (!$master_result) { 1754 1801 $this->error['brand_update_check_master'] = "Not able to connect to repository. Using local master file instead."; 1755 1802 } 1756 1757 $temp = $this-> xml2array(PHONE_MODULES_PATH.'master.xml');1803 1804 $temp = $this->file2json(PHONE_MODULES_PATH . 'master.json'); 1758 1805 $endpoint_package = $temp['data']['package']; 1759 1806 $endpoint_last_mod = $temp['data']['last_modified']; 1760 1807 1761 1808 $sql = "SELECT value FROM endpointman_global_vars WHERE var_name LIKE 'endpoint_vers'"; 1762 $data = $this->eda->sql($sql, 'getOne');1763 1764 $contents = file_get_contents(UPDATE_PATH ."/update_status");1765 1766 1767 if ($contents != '1') {1768 if (($data == "") OR ($data <= $endpoint_last_mod)) {1769 if ((!$master_result) OR (!$this->download_file_no_progress_bar(UPDATE_PATH.'/'.$endpoint_package, PHONE_MODULES_PATH."temp/".$endpoint_package))) {1770 $this->error['brand_update_check_ xml'] = "<br/>Not able to connect to repository. Using local Provisioner.net Package";1809 $data = $this->eda->sql($sql, 'getOne'); 1810 1811 $contents = file_get_contents(UPDATE_PATH . "/update_status"); 1812 1813 1814 if ($contents != '1') { 1815 if (($data == "") OR ($data <= $endpoint_last_mod)) { 1816 if ((!$master_result) OR (!$this->download_file(UPDATE_PATH . '/' . $endpoint_package, PHONE_MODULES_PATH . "temp/" . $endpoint_package))) { 1817 $this->error['brand_update_check_json'] = "<br/>Not able to connect to repository. Using local Provisioner.net Package"; 1771 1818 } else { 1772 exec("tar -xvf ".PHONE_MODULES_PATH.'temp/'. $endpoint_package ." -C ".PHONE_MODULES_PATH."temp/"); 1773 1774 if(!file_exists(PHONE_MODULES_PATH."endpoint")) { 1775 mkdir(PHONE_MODULES_PATH."endpoint"); 1776 } 1777 1778 unlink(PHONE_MODULES_PATH."temp/setup.php"); 1779 rename(PHONE_MODULES_PATH."temp/endpoint/base.php", PHONE_MODULES_PATH."endpoint/base.php"); 1780 1781 $sql = "UPDATE endpointman_global_vars SET value = '".$endpoint_last_mod."' WHERE var_name = 'endpoint_vers'"; 1819 exec("tar -xvf " . PHONE_MODULES_PATH . 'temp/' . $endpoint_package . " -C " . PHONE_MODULES_PATH . "temp/"); 1820 1821 if (!file_exists(PHONE_MODULES_PATH . "endpoint")) { 1822 mkdir(PHONE_MODULES_PATH . "endpoint"); 1823 } 1824 1825 //TODO: Automate this somehow... 1826 unlink(PHONE_MODULES_PATH . "temp/setup.php"); 1827 rename(PHONE_MODULES_PATH . "temp/endpoint/base.php", PHONE_MODULES_PATH . "endpoint/base.php"); 1828 rename(PHONE_MODULES_PATH . "temp/endpoint/global_template_data.json", PHONE_MODULES_PATH . "endpoint/global_template_data.json"); 1829 1830 $sql = "UPDATE endpointman_global_vars SET value = '" . $endpoint_last_mod . "' WHERE var_name = 'endpoint_vers'"; 1782 1831 $this->eda->sql($sql); 1783 1832 } … … 1788 1837 1789 1838 //Assume that if we can't connect and find the master.xml file then why should we try to find every other file. 1790 if ($master_result) {1839 if ($master_result) { 1791 1840 $row = $this->eda->sql('SELECT * FROM endpointman_brand_list WHERE id > 0', 'getAll', DB_FETCHMODE_ASSOC); 1792 1841 1793 foreach ($out as $data) {1794 1795 $local = $this->eda->sql("SELECT local FROM endpointman_brand_list WHERE directory = '" .$data['directory']."'",'getOne');1796 1797 if (!$local) {1798 $result = $this->download_ xml(UPDATE_PATH .$data['directory']."/".$data['directory'].".xml","endpoint/".$data['directory']);1799 if (!$result) {1800 $this->error['brand_update_check'] = "<br/>Not able to connect to repository. Using local brand [" .$data['name']."] file instead.";1842 foreach ($out as $data) { 1843 1844 $local = $this->eda->sql("SELECT local FROM endpointman_brand_list WHERE directory = '" . $data['directory'] . "'", 'getOne'); 1845 1846 if (!$local) { 1847 $result = $this->download_file(UPDATE_PATH . $data['directory'] . "/" . $data['directory'] . ".json", PHONE_MODULES_PATH . "endpoint/" . $data['directory'] . "/brand_data.json"); 1848 if (!$result) { 1849 $this->error['brand_update_check'] = "<br/>Not able to connect to repository. Using local brand [" . $data['name'] . "] file instead."; 1801 1850 } 1802 1851 } 1803 1852 1804 if (file_exists(PHONE_MODULES_PATH."endpoint/".$data['directory']."/brand_data.xml")) {1805 $temp = $this-> xml2array(PHONE_MODULES_PATH."endpoint/".$data['directory']."/brand_data.xml");1853 if (file_exists(PHONE_MODULES_PATH . "endpoint/" . $data['directory'] . "/brand_data.json")) { 1854 $temp = $this->file2json(PHONE_MODULES_PATH . "endpoint/" . $data['directory'] . "/brand_data.json"); 1806 1855 1807 1856 $temp = $temp['data']['brands']; 1808 1857 1809 $temp['oui_list']['oui'] = $this->fix_single_array_keys($temp['oui_list']['oui']); 1810 1811 foreach($temp['oui_list']['oui'] as $oui) { 1812 $sql = "REPLACE INTO endpointman_oui_list (`oui`, `brand`, `custom`) VALUES ('".$oui."', '".$temp['brand_id']."', '0')"; 1858 foreach ($temp['oui_list'] as $oui) { 1859 $sql = "REPLACE INTO endpointman_oui_list (`oui`, `brand`, `custom`) VALUES ('" . $oui . "', '" . $temp['brand_id'] . "', '0')"; 1813 1860 $this->eda->sql($sql); 1814 1815 1861 } 1816 1862 … … 1820 1866 $last_mod = ""; 1821 1867 1822 $temp['family_list']['family'] = $this->fix_single_array_keys($temp['family_list']['family']); 1823 1824 foreach($temp['family_list']['family'] as $list) { 1868 foreach ($temp['family_list'] as $list) { 1825 1869 $last_mod = max($last_mod, $list['last_modified']); 1826 1870 } … … 1829 1873 $version[$brand_name] = $last_mod; 1830 1874 1831 if (!($this->arraysearchrecursive($brand_name, $row, 'directory'))) {1875 if (!($this->arraysearchrecursive($brand_name, $row, 'directory'))) { 1832 1876 //insert row 1833 $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver) VALUES ('" .$temp['brand_id']."', '".$temp['name']."', '".$temp['directory']."', '".$version[$brand_name]."')";1877 $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver) VALUES ('" . $temp['brand_id'] . "', '" . $temp['name'] . "', '" . $temp['directory'] . "', '" . $version[$brand_name] . "')"; 1834 1878 $this->eda->sql($sql); 1835 1879 } else { … … 1837 1881 } 1838 1882 } else { 1839 $this->error['brand_update_check_local_file'] = "<br/>Error: No Local File for " .$data['name']."!<br /><br />Learn how to manually upload packages here (it's easy!): <a href='http://projects.colsolgrp.net/documents/28' target='_blank'>Click Here!</a>";1840 } 1841 } 1842 1843 foreach ($row as $ava_brands) {1883 $this->error['brand_update_check_local_file'] = "<br/>Error: No Local File for " . $data['name'] . "!<br /><br />Learn how to manually upload packages here (it's easy!): <a href='http://wiki.provisioner.net/index.php/Endpoint_manager_manual_upload' target='_blank'>Click Here!</a>"; 1884 } 1885 } 1886 1887 foreach ($row as $ava_brands) { 1844 1888 $key = $this->arraysearchrecursive($ava_brands['directory'], $out, 'directory'); 1845 if ($key === FALSE) {1889 if ($key === FALSE) { 1846 1890 $this->remove_brand($ava_brands['id']); 1847 1891 } else { … … 1850 1894 $brand_name = $ava_brands['directory']; 1851 1895 1852 if($ava_brands['cfg_ver'] < $version[$brand_name]) { 1896 //TODO: This seems old 1897 if ($ava_brands['cfg_ver'] < $version[$brand_name]) { 1853 1898 $out[$key]['update'] = 1; 1854 1899 $out[$key]['update_vers'] = $version[$brand_name]; … … 1859 1904 } 1860 1905 } else { 1861 $this->error['brand_update_check_master_file'] = "<br/>Aborting Brand Downloads. Can't Get Master File, Assuming Timeout Issues!<br /><br />Learn how to manually upload packages here (it's easy!): <a href='http:// projects.colsolgrp.net/documents/28' target='_blank'>Click Here!</a>";1906 $this->error['brand_update_check_master_file'] = "<br/>Aborting Brand Downloads. Can't Get Master File, Assuming Timeout Issues!<br /><br />Learn how to manually upload packages here (it's easy!): <a href='http://wiki.provisioner.net/index.php/Endpoint_manager_manual_upload' target='_blank'>Click Here!</a>"; 1862 1907 } 1863 1908 … … 1873 1918 */ 1874 1919 function download_brand($id) { 1875 $row = $this->eda->sql('SELECT * FROM endpointman_brand_list WHERE id =' .$id, 'getAll', DB_FETCHMODE_ASSOC);1876 echo "Downloading Brand XML.....";1877 $result = $this->download_ xml(UPDATE_PATH .$row[0]['directory']. "/".$row[0]['directory'].".xml","endpoint/".$row[0]['directory']);1878 1879 if ($result) {1920 $row = $this->eda->sql('SELECT * FROM endpointman_brand_list WHERE id =' . $id, 'getAll', DB_FETCHMODE_ASSOC); 1921 echo "Downloading Brand JSON....."; 1922 $result = $this->download_file(UPDATE_PATH . $row[0]['directory'] . "/" . $row[0]['directory'] . ".json", PHONE_MODULES_PATH . "endpoint/" . $row[0]['directory'] . "/brand_data.json"); 1923 1924 if ($result) { 1880 1925 echo "Done!<br/>"; 1881 1926 1882 $temp = $this-> xml2array(PHONE_MODULES_PATH.'endpoint/'. $row[0]['directory'].'/brand_data.xml');1927 $temp = $this->file2json(PHONE_MODULES_PATH . 'endpoint/' . $row[0]['directory'] . '/brand_data.json'); 1883 1928 $package = $temp['data']['brands']['package']; 1884 1929 1885 1930 echo "<div style='float: left'>Downloading Brand Package...</div><div style='float: left' id=\"DivExample\">.</div>"; 1886 $this->download_file_with_progress_bar(UPDATE_PATH .$row[0]['directory'].'/'.$package, PHONE_MODULES_PATH."temp/".$package);1931 $this->download_file_with_progress_bar(UPDATE_PATH . $row[0]['directory'] . '/' . $package, PHONE_MODULES_PATH . "temp/" . $package); 1887 1932 echo "<script type='text/javascript'>document.getElementById('DivExample').innerHTML='Done!';</script><br />"; 1888 1933 1889 if (file_exists(PHONE_MODULES_PATH.'temp/'. $package)) {1934 if (file_exists(PHONE_MODULES_PATH . 'temp/' . $package)) { 1890 1935 $md5_xml = $temp['data']['brands']['md5sum']; 1891 $md5_pkg = md5_file(PHONE_MODULES_PATH .'temp/'. $package);1936 $md5_pkg = md5_file(PHONE_MODULES_PATH . 'temp/' . $package); 1892 1937 1893 1938 echo "Checking MD5sum of Package...."; 1894 if ($md5_xml == $md5_pkg) {1939 if ($md5_xml == $md5_pkg) { 1895 1940 echo "Done!<br/>"; 1896 1941 echo "Extracting Tarball........"; 1897 exec("tar -xvf " .PHONE_MODULES_PATH.'temp/'. $package ." -C ".PHONE_MODULES_PATH."temp/");1942 exec("tar -xvf " . PHONE_MODULES_PATH . 'temp/' . $package . " -C " . PHONE_MODULES_PATH . "temp/"); 1898 1943 echo "Done!<br />"; 1899 1944 1900 //Update File in directory 1901 copy(PHONE_MODULES_PATH.'endpoint/'. $row[0]['directory'].'/brand_data.xml', PHONE_MODULES_PATH.'temp/'. $row[0]['directory'].'/brand_data.xml'); 1902 1903 $package = basename($package, ".tgz"); 1904 $package = explode("-",$package); 1905 $this->update_brand($package[0]); 1945 //Update File in the temp directory 1946 copy(PHONE_MODULES_PATH . 'endpoint/' . $row[0]['directory'] . '/brand_data.json', PHONE_MODULES_PATH . 'temp/' . $row[0]['directory'] . '/brand_data.json'); 1947 1948 $this->update_brand($row[0]['directory'], TRUE); 1906 1949 } else { 1907 1950 echo "MD5 Did not match!"; … … 1919 1962 * Still needs way to determine when models move...perhaps another function? 1920 1963 */ 1921 function update_brand($package, $remote=TRUE) {1922 if (file_exists(PHONE_MODULES_PATH.'temp/'. $package.'/brand_data.xml')) {1923 $temp = $this-> xml2array(PHONE_MODULES_PATH.'temp/'. $package.'/brand_data.xml');1924 if (key_exists('directory', $temp['data']['brands'])) {1925 echo "Appears to be a valid Provisioner.net XMLfile.....Continuing<br />";1964 function update_brand($package, $remote=TRUE) { 1965 if (file_exists(PHONE_MODULES_PATH . 'temp/' . $package . '/brand_data.json')) { 1966 $temp = $this->file2json(PHONE_MODULES_PATH . 'temp/' . $package . '/brand_data.json'); 1967 if (key_exists('directory', $temp['data']['brands'])) { 1968 echo "Appears to be a valid Provisioner.net JSON file.....Continuing<br />"; 1926 1969 1927 1970 //Pull in all variables … … 1929 1972 $brand_name = $temp['data']['brands']['name']; 1930 1973 $brand_id = $temp['data']['brands']['brand_id']; 1931 $brand_version = $temp['data']['brands']['version']; 1932 $brand_last_mod = $temp['data']['brands']['last_modified']; 1974 $brand_version = $temp['data']['brands']['last_modified']; 1933 1975 1934 1976 //create directory structure and move files 1935 1977 echo "Creating Directory Structure/Moving Files.."; 1936 1978 1937 @mkdir(PHONE_MODULES_PATH."endpoint/".$directory); 1938 1939 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."temp/".$directory."/"); 1979 if (!file_exists(PHONE_MODULES_PATH . "endpoint/" . $directory)) { 1980 mkdir(PHONE_MODULES_PATH . "endpoint/" . $directory); 1981 } 1982 1983 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH . "temp/" . $directory . "/"); 1940 1984 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); 1941 1985 foreach ($iterator as $file) { 1942 if (is_dir($file)) {1943 $dir = str_replace(PHONE_MODULES_PATH ."temp/".$directory."/", "", $file);1944 if (!file_exists(PHONE_MODULES_PATH."endpoint/".$directory."/".$dir)) {1945 mkdir(PHONE_MODULES_PATH ."endpoint/".$directory."/".$dir,0764, TRUE);1986 if (is_dir($file)) { 1987 $dir = str_replace(PHONE_MODULES_PATH . "temp/" . $directory . "/", "", $file); 1988 if (!file_exists(PHONE_MODULES_PATH . "endpoint/" . $directory . "/" . $dir)) { 1989 mkdir(PHONE_MODULES_PATH . "endpoint/" . $directory . "/" . $dir, 0764, TRUE); 1946 1990 echo "."; 1947 1991 } 1948 1992 } else { 1949 if ((basename($file) != "brand_data.xml") OR (!$remote)) {1950 $dir = str_replace(PHONE_MODULES_PATH ."temp/".$directory."/", "", $file);1951 $stats = rename($file, PHONE_MODULES_PATH ."endpoint/".$directory."/".$dir);1952 if ($stats === FALSE) {1953 echo "Error Moving " . basename($file);1993 if ((basename($file) != "brand_data.json") OR (!$remote)) { 1994 $dir = str_replace(PHONE_MODULES_PATH . "temp/" . $directory . "/", "", $file); 1995 $stats = rename($file, PHONE_MODULES_PATH . "endpoint/" . $directory . "/" . $dir); 1996 if ($stats === FALSE) { 1997 echo "Error Moving " . basename($file); 1954 1998 } 1955 chmod(PHONE_MODULES_PATH ."endpoint/".$directory."/".$dir,0764);1999 chmod(PHONE_MODULES_PATH . "endpoint/" . $directory . "/" . $dir, 0764); 1956 2000 echo "."; 1957 2001 } … … 1960 2004 echo "Done!<br />"; 1961 2005 1962 if ($remote) {2006 if ($remote) { 1963 2007 $local = 0; 1964 2008 } else { 1965 2009 $local = 1; 1966 2010 } 1967 $brand_version = max($last_mod, $brand_last_mod); 1968 1969 $b_data = $this->eda->sql("SELECT id FROM endpointman_brand_list WHERE id = '".$brand_id."'", 'getOne'); 1970 if($b_data) { 2011 2012 $b_data = $this->eda->sql("SELECT id FROM endpointman_brand_list WHERE id = '" . $brand_id . "'", 'getOne'); 2013 if ($b_data) { 1971 2014 echo "Updating data.........."; 1972 $sql = "UPDATE endpointman_brand_list SET local = '" .$local."', name = '".$brand_name."', cfg_ver = '".$brand_version."', installed = 1, hidden = 0 WHERE id = ".$brand_id;2015 $sql = "UPDATE endpointman_brand_list SET local = '" . $local . "', name = '" . $brand_name . "', cfg_ver = '" . $brand_version . "', installed = 1, hidden = 0 WHERE id = " . $brand_id; 1973 2016 $this->eda->sql($sql); 1974 2017 } else { 1975 $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver, local, installed) VALUES ('" .$brand_id."', '".$brand_name."', '".$directory."', '".$brand_version."', '1', '1')";2018 $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver, local, installed) VALUES ('" . $brand_id . "', '" . $brand_name . "', '" . $directory . "', '" . $brand_version . "', '1', '1')"; 1976 2019 $this->eda->sql($sql); 1977 2020 } 1978 2021 1979 2022 $last_mod = ""; 1980 $temp['data']['brands']['family_list']['family'] = $this->fix_single_array_keys($temp['data']['brands']['family_list']['family']); 1981 foreach($temp['data']['brands']['family_list']['family'] as $family_list) { 2023 foreach ($temp['data']['brands']['family_list'] as $family_list) { 1982 2024 echo "Updating Family Lines.................<br/>"; 1983 2025 … … 1985 2027 $last_mod = max($last_mod, $family_list['last_modified']); 1986 2028 1987 $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$directory.'/'.$family_list['directory'].'/family_data.xml'); 1988 2029 $family_line_xml = $this->file2json(PHONE_MODULES_PATH . '/endpoint/' . $directory . '/' . $family_list['directory'] . '/family_data.json'); 2030 2031 $family_line_xml['data']['last_modified'] = isset($family_line_xml['data']['last_modified']) ? $family_line_xml['data']['last_modified'] : ''; 2032 1989 2033 $require_firmware = NULL; 1990 if ((key_exists('require_firmware', $family_line_xml['data'])) && ($remote) && ($family_line_xml['data']['require_firmware'] == "TRUE")) {2034 if ((key_exists('require_firmware', $family_line_xml['data'])) && ($remote) && ($family_line_xml['data']['require_firmware'] == "TRUE")) { 1991 2035 echo "Firmware Requirment Detected!..........<br/>"; 1992 2036 $this->install_firmware($family_line_xml['data']['id']); 1993 2037 } 1994 2038 1995 $data = $this->eda->sql("SELECT id FROM endpointman_product_list WHERE id='" .$brand_id.$family_line_xml['data']['id']."'", 'getOne');2039 $data = $this->eda->sql("SELECT id FROM endpointman_product_list WHERE id='" . $brand_id . $family_line_xml['data']['id'] . "'", 'getOne'); 1996 2040 $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); 1997 if ($data) {1998 $sql = "UPDATE endpointman_product_list SET short_name = '" .$short_name."', long_name = '".$family_line_xml['data']['name']."', cfg_ver = '".$family_line_xml['data']['version']."', config_files='".$family_line_xml['data']['configuration_files']."' WHERE id = '".$brand_id.$family_line_xml['data']['id']."'";2041 if ($data) { 2042 $sql = "UPDATE endpointman_product_list SET short_name = '" . $short_name . "', long_name = '" . $family_line_xml['data']['name'] . "', cfg_ver = '" . $family_line_xml['data']['version'] . "', config_files='" . $family_line_xml['data']['configuration_files'] . "' WHERE id = '" . $brand_id . $family_line_xml['data']['id'] . "'"; 1999 2043 } else { 2000 $sql = "INSERT INTO endpointman_product_list (`id`, `brand`, `short_name`, `long_name`, `cfg_dir`, `cfg_ver`, `config_files`, `hidden`) VALUES ('" .$brand_id.$family_line_xml['data']['id']."', '".$brand_id."', '".$short_name."', '".$family_line_xml['data']['name']."', '".$family_line_xml['data']['directory']."', '".$family_line_xml['data']['version']."','".$family_line_xml['data']['configuration_files']."', '0')";2044 $sql = "INSERT INTO endpointman_product_list (`id`, `brand`, `short_name`, `long_name`, `cfg_dir`, `cfg_ver`, `config_files`, `hidden`) VALUES ('" . $brand_id . $family_line_xml['data']['id'] . "', '" . $brand_id . "', '" . $short_name . "', '" . $family_line_xml['data']['name'] . "', '" . $family_line_xml['data']['directory'] . "', '" . $family_line_xml['data']['last_modified'] . "','" . $family_line_xml['data']['configuration_files'] . "', '0')"; 2001 2045 } 2002 2046 2003 2047 $this->eda->sql($sql); 2004 $family_line_xml['data']['model_list'] = $this->fix_single_array_keys($family_line_xml['data']['model_list']);2005 2048 echo "--Updating Model Lines................<br/>"; 2006 foreach($family_line_xml['data']['model_list'] as $model_list) { 2007 if(is_array($model_list['template_data']['files'])) { 2008 $template_list = implode(",",$model_list['template_data']['files']); 2009 } else { 2010 $template_list = $model_list['template_data']['files']; 2011 } 2012 2013 $model_final_id = $brand_id.$family_line_xml['data']['id'].$model_list['id']; 2014 $sql = 'SELECT id, global_custom_cfg_data, global_user_cfg_data FROM endpointman_mac_list WHERE model = '.$model_final_id; 2049 foreach ($family_line_xml['data']['model_list'] as $model_list) { 2050 $template_list = implode(",", $model_list['template_data']); 2051 2052 $model_final_id = $brand_id . $family_line_xml['data']['id'] . $model_list['id']; 2053 $sql = 'SELECT id, global_custom_cfg_data, global_user_cfg_data FROM endpointman_mac_list WHERE model = ' . $model_final_id; 2015 2054 $old_data = NULL; 2016 2055 $old_data = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 2017 foreach ($old_data as $data) {2056 foreach ($old_data as $data) { 2018 2057 $global_custom_cfg_data = unserialize($data['global_custom_cfg_data']); 2019 if ((is_array($global_custom_cfg_data)) AND (!array_key_exists('data', $global_custom_cfg_data))) {2058 if ((is_array($global_custom_cfg_data)) AND (!array_key_exists('data', $global_custom_cfg_data))) { 2020 2059 echo "----Old Data Detected! Migrating......"; 2021 2060 $new_data = array(); 2022 2061 $new_ari = array(); 2023 foreach ($global_custom_cfg_data as $key => $old_keys) {2024 if (array_key_exists('value', $old_keys)) {2062 foreach ($global_custom_cfg_data as $key => $old_keys) { 2063 if (array_key_exists('value', $old_keys)) { 2025 2064 $new_data[$key] = $old_keys['value']; 2026 2065 } else { 2027 2066 $breaks = explode("_", $key); 2028 $new_data["loop|" .$key] = $old_keys[$breaks[2]];2067 $new_data["loop|" . $key] = $old_keys[$breaks[2]]; 2029 2068 } 2030 if (array_key_exists('ari', $old_keys)) {2069 if (array_key_exists('ari', $old_keys)) { 2031 2070 $new_ari[$key] = 1; 2032 2071 } … … 2036 2075 $final_data['ari'] = $new_ari; 2037 2076 $final_data = serialize($final_data); 2038 $sql = "UPDATE endpointman_mac_list SET global_custom_cfg_data = '" .$final_data."' WHERE id =".$data['id'];2077 $sql = "UPDATE endpointman_mac_list SET global_custom_cfg_data = '" . $final_data . "' WHERE id =" . $data['id']; 2039 2078 $this->eda->sql($sql); 2040 2079 echo "Done!<br/>"; … … 2043 2082 $global_user_cfg_data = unserialize($data['global_user_cfg_data']); 2044 2083 $old_check = FALSE; 2045 if (is_array($global_user_cfg_data)) {2046 foreach ($global_user_cfg_data as $stuff) {2047 if (is_array($stuff)) {2048 if (array_key_exists('value', $stuff)) {2084 if (is_array($global_user_cfg_data)) { 2085 foreach ($global_user_cfg_data as $stuff) { 2086 if (is_array($stuff)) { 2087 if (array_key_exists('value', $stuff)) { 2049 2088 $old_check = TRUE; 2050 2089 break; … … 2057 2096 } 2058 2097 } 2059 if ((is_array($global_user_cfg_data)) AND ($old_check)) {2098 if ((is_array($global_user_cfg_data)) AND ($old_check)) { 2060 2099 echo "Old Data Detected! Migrating......"; 2061 2100 $new_data = array(); 2062 foreach ($global_user_cfg_data as $key => $old_keys) {2063 if (array_key_exists('value', $old_keys)) {2064 $exploded = explode("_", $key);2101 foreach ($global_user_cfg_data as $key => $old_keys) { 2102 if (array_key_exists('value', $old_keys)) { 2103 $exploded = explode("_", $key); 2065 2104 $counted = count($exploded); 2066 2105 $counted = $counted - 1; 2067 if (is_numeric($exploded[$counted])) {2068 $key = "loop|" .$key;2106 if (is_numeric($exploded[$counted])) { 2107 $key = "loop|" . $key; 2069 2108 } 2070 2109 $new_data[$key] = $old_keys['value']; … … 2072 2111 } 2073 2112 $final_data = serialize($new_data); 2074 $sql = "UPDATE endpointman_mac_list SET global_user_cfg_data = '" .$final_data."' WHERE id =".$data['id'];2113 $sql = "UPDATE endpointman_mac_list SET global_user_cfg_data = '" . $final_data . "' WHERE id =" . $data['id']; 2075 2114 $this->eda->sql($sql); 2076 2115 echo "Done!<br/>"; … … 2078 2117 } 2079 2118 $old_data = NULL; 2080 $sql = 'SELECT id, global_custom_cfg_data FROM endpointman_template_list WHERE model_id = ' .$model_final_id;2119 $sql = 'SELECT id, global_custom_cfg_data FROM endpointman_template_list WHERE model_id = ' . $model_final_id; 2081 2120 $old_data = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 2082 foreach ($old_data as $data) {2121 foreach ($old_data as $data) { 2083 2122 $global_custom_cfg_data = unserialize($data['global_custom_cfg_data']); 2084 if ((is_array($global_custom_cfg_data)) AND (!array_key_exists('data', $global_custom_cfg_data))) {2123 if ((is_array($global_custom_cfg_data)) AND (!array_key_exists('data', $global_custom_cfg_data))) { 2085 2124 echo "Old Data Detected! Migrating......"; 2086 2125 $new_data = array(); 2087 2126 $new_ari = array(); 2088 foreach ($global_custom_cfg_data as $key => $old_keys) {2089 if (array_key_exists('value', $old_keys)) {2127 foreach ($global_custom_cfg_data as $key => $old_keys) { 2128 if (array_key_exists('value', $old_keys)) { 2090 2129 $new_data[$key] = $old_keys['value']; 2091 2130 } else { 2092 2131 $breaks = explode("_", $key); 2093 $new_data["loop|" .$key] = $old_keys[$breaks[2]];2132 $new_data["loop|" . $key] = $old_keys[$breaks[2]]; 2094 2133 } 2095 if (array_key_exists('ari', $old_keys)) {2134 if (array_key_exists('ari', $old_keys)) { 2096 2135 $new_ari[$key] = 1; 2097 2136 } … … 2101 2140 $final_data['ari'] = $new_ari; 2102 2141 $final_data = serialize($final_data); 2103 $sql = "UPDATE endpointman_template_list SET global_custom_cfg_data = '" .$final_data."' WHERE id =".$data['id'];2104 $this-> db->query($sql);2142 $sql = "UPDATE endpointman_template_list SET global_custom_cfg_data = '" . $final_data . "' WHERE id =" . $data['id']; 2143 $this->eda->sql($sql); 2105 2144 echo "Done!<br/>"; 2106 2145 } 2107 2146 } 2108 2147 2109 $m_data = $this->eda->sql("SELECT id FROM endpointman_model_list WHERE id='" .$brand_id.$family_line_xml['data']['id'].$model_list['id']."'", 'getone');2110 if ($m_data) {2111 $sql = "UPDATE endpointman_model_list SET max_lines = '" .$model_list['lines']."', model = '".$model_list['model']."', template_list = '".$template_list."' WHERE id = '".$brand_id.$family_line_xml['data']['id'].$model_list['id']."'";2148 $m_data = $this->eda->sql("SELECT id FROM endpointman_model_list WHERE id='" . $brand_id . $family_line_xml['data']['id'] . $model_list['id'] . "'", 'getone'); 2149 if ($m_data) { 2150 $sql = "UPDATE endpointman_model_list SET max_lines = '" . $model_list['lines'] . "', model = '" . $model_list['model'] . "', template_list = '" . $template_list . "' WHERE id = '" . $brand_id . $family_line_xml['data']['id'] . $model_list['id'] . "'"; 2112 2151 } else { 2113 $sql = "INSERT INTO endpointman_model_list (`id`, `brand`, `model`, `max_lines`, `product_id`, `template_list`, `enabled`, `hidden`) VALUES ('" .$brand_id.$family_line_xml['data']['id'].$model_list['id']."', '".$brand_id."', '".$model_list['model']."', '".$model_list['lines']."', '".$brand_id.$family_line_xml['data']['id']."', '".$template_list."', '0', '0')";2152 $sql = "INSERT INTO endpointman_model_list (`id`, `brand`, `model`, `max_lines`, `product_id`, `template_list`, `enabled`, `hidden`) VALUES ('" . $brand_id . $family_line_xml['data']['id'] . $model_list['id'] . "', '" . $brand_id . "', '" . $model_list['model'] . "', '" . $model_list['lines'] . "', '" . $brand_id . $family_line_xml['data']['id'] . "', '" . $template_list . "', '0', '0')"; 2114 2153 } 2115 2154 $this->eda->sql($sql); 2116 2155 2117 2118 if (!$this->sync_model($brand_id.$family_line_xml['data']['id'].$model_list['id'])) {2156 2157 if (!$this->sync_model($brand_id . $family_line_xml['data']['id'] . $model_list['id'])) { 2119 2158 echo "System Error in Sync Model Function, Load Failure!<br />"; 2120 2159 } … … 2123 2162 } 2124 2163 2125 foreach ($temp['data']['brands']['oui_list']['oui'] as $oui) {2126 $sql = "REPLACE INTO endpointman_oui_list (`oui`, `brand`, `custom`) VALUES ('" .$oui."', '".$brand_id."', '0')";2164 foreach ($temp['data']['brands']['oui_list'] as $oui) { 2165 $sql = "REPLACE INTO endpointman_oui_list (`oui`, `brand`, `custom`) VALUES ('" . $oui . "', '" . $brand_id . "', '0')"; 2127 2166 $this->eda->sql($sql); 2128 2167 } … … 2137 2176 2138 2177 echo "Removing Temporary Files.............."; 2139 $this->rmrf(PHONE_MODULES_PATH ."temp/" .$package);2178 $this->rmrf(PHONE_MODULES_PATH . "temp/" . $package); 2140 2179 echo "Done!<br />"; 2141 2142 } 2143 2180 } 2144 2181 2145 2182 /** … … 2147 2184 * @param int $id Brand ID 2148 2185 */ 2149 function remove_brand($id=NULL, $remove_configs=FALSE) {2150 $sql = 'SELECT id, firmware_vers FROM endpointman_product_list WHERE brand = ' .$id;2186 function remove_brand($id=NULL, $remove_configs=FALSE) { 2187 $sql = 'SELECT id, firmware_vers FROM endpointman_product_list WHERE brand = ' . $id; 2151 2188 $products = $this->eda->sql($sql, 'getall', DB_FETCHMODE_ASSOC); 2152 foreach ($products as $data) {2153 if ($data['firmware_vers'] != "") {2189 foreach ($products as $data) { 2190 if ($data['firmware_vers'] != "") { 2154 2191 $this->remove_firmware($data['id']); 2155 2192 } 2156 2193 } 2157 2194 2158 $brand_dir = $this->eda->sql("SELECT directory FROM endpointman_brand_list WHERE id=" .$id,'getone');2159 $this->rmrf(PHONE_MODULES_PATH ."endpoint/".$brand_dir);2160 2161 $sql = "DELETE FROM endpointman_model_list WHERE brand = '" . $id."'";2195 $brand_dir = $this->eda->sql("SELECT directory FROM endpointman_brand_list WHERE id=" . $id, 'getone'); 2196 $this->rmrf(PHONE_MODULES_PATH . "endpoint/" . $brand_dir); 2197 2198 $sql = "DELETE FROM endpointman_model_list WHERE brand = '" . $id . "'"; 2162 2199 $this->eda->sql($sql); 2163 2200 2164 $sql = "DELETE FROM endpointman_product_list WHERE brand = '" . $id . "'";2201 $sql = "DELETE FROM endpointman_product_list WHERE brand = '" . $id . "'"; 2165 2202 $this->eda->sql($sql); 2166 2203 2167 $sql = "DELETE FROM endpointman_oui_list WHERE brand = '" . $id . "'";2204 $sql = "DELETE FROM endpointman_oui_list WHERE brand = '" . $id . "'"; 2168 2205 $this->eda->sql($sql); 2169 2206 2170 $this->rmrf(PHONE_MODULES_PATH . $brand_dir);2171 $sql = "DELETE FROM endpointman_brand_list WHERE id = " . $id;2207 $this->rmrf(PHONE_MODULES_PATH . $brand_dir); 2208 $sql = "DELETE FROM endpointman_brand_list WHERE id = " . $id; 2172 2209 2173 2210 $this->eda->sql($sql); 2211 } 2212 2213 function merge_data($path, $template_list, $maxlines = 3) { 2214 //TODO: fix 2215 foreach ($template_list as $files_data) { 2216 $full_path = $path . $files_data; 2217 if (file_exists($full_path)) { 2218 $temp_files_data = $this->file2json($full_path); 2219 foreach ($temp_files_data['template_data']['category'] as $category) { 2220 $category_name = $category['name']; 2221 foreach ($category['subcategory'] as $subcategory) { 2222 $subcategory_name = $subcategory['name']; 2223 $items_fin = array(); 2224 $items_loop = array(); 2225 $break_count = 0; 2226 foreach ($subcategory['item'] as $item) { 2227 switch ($item['type']) { 2228 case 'loop_line_options': 2229 for ($i = 1; $i <= $maxlines; $i++) { 2230 $var_nam = "lineloop|line_" . $i; 2231 foreach ($item['data']['item'] as $item_loop) { 2232 if ($item_loop['type'] != 'break') { 2233 $z = str_replace("\$", "", $item_loop['variable']); 2234 $items_loop[$var_nam][$z] = $item_loop; 2235 $items_loop[$var_nam][$z]['description'] = str_replace('{$count}', $i, $items_loop[$var_nam][$z]['description']); 2236 $items_loop[$var_nam][$z]['default_value'] = $items_loop[$var_nam][$z]['default_value']; 2237 $items_loop[$var_nam][$z]['default_value'] = str_replace('{$count}', $i, $items_loop[$var_nam][$z]['default_value']); 2238 $items_loop[$var_nam][$z]['line_loop'] = TRUE; 2239 $items_loop[$var_nam][$z]['line_count'] = $i; 2240 } elseif ($item_loop['type'] == 'break') { 2241 $items_loop[$var_nam]['break_' . $break_count]['type'] = 'break'; 2242 $break_count++; 2243 } 2244 } 2245 } 2246 $items_fin = array_merge($items_fin, $items_loop); 2247 break; 2248 case 'loop': 2249 for ($i = $item['loop_start']; $i <= $item['loop_end']; $i++) { 2250 $name = explode("_", $item['data']['item'][0]['variable']); 2251 $var_nam = "loop|" . str_replace("\$", "", $name[0]) . "_" . $i; 2252 foreach ($item['data']['item'] as $item_loop) { 2253 if ($item_loop['type'] != 'break') { 2254 $z_tmp = explode("_", $item_loop['variable']); 2255 $z = $z_tmp[1]; 2256 $items_loop[$var_nam][$z] = $item_loop; 2257 $items_loop[$var_nam][$z]['description'] = str_replace('{$count}', $i, $items_loop[$var_nam][$z]['description']); 2258 $items_loop[$var_nam][$z]['variable'] = str_replace('_', '_' . $i . '_', $items_loop[$var_nam][$z]['variable']); 2259 $items_loop[$var_nam][$z]['default_value'] = isset($items_loop[$var_nam][$z]['default_value']) ? $items_loop[$var_nam][$z]['default_value'] : ''; 2260 $items_loop[$var_nam][$z]['loop'] = TRUE; 2261 $items_loop[$var_nam][$z]['loop_count'] = $i; 2262 } elseif ($item_loop['type'] == 'break') { 2263 $items_loop[$var_nam]['break_' . $break_count]['type'] = 'break'; 2264 $break_count++; 2265 } 2266 } 2267 } 2268 $items_fin = array_merge($items_fin, $items_loop); 2269 break; 2270 case 'break': 2271 $items_fin['break|' . $break_count]['type'] = 'break'; 2272 $break_count++; 2273 break; 2274 default: 2275 $var_nam = "option|" . str_replace("\$", "", $item['variable']); 2276 $items_fin[$var_nam] = $item; 2277 break; 2278 } 2279 } 2280 if (isset($data['data'][$category_name][$subcategory_name])) { 2281 $old_sc = $data['data'][$category_name][$subcategory_name]; 2282 $sub_cat_data[$category_name][$subcategory_name] = array(); 2283 $sub_cat_data[$category_name][$subcategory_name] = array_merge($old_sc, $items_fin); 2284 } else { 2285 $sub_cat_data[$category_name][$subcategory_name] = $items_fin; 2286 } 2287 } 2288 if (isset($data['data'][$category_name])) { 2289 $old_c = $data['data'][$category_name]; 2290 $new_c = $sub_cat_data[$category_name]; 2291 $sub_cat_data[$category_name] = array(); 2292 $data['data'][$category_name] = array_merge($old_c, $new_c); 2293 } else { 2294 $data['data'][$category_name] = $sub_cat_data[$category_name]; 2295 } 2296 } 2297 } 2298 } 2299 return($data); 2174 2300 } 2175 2301 … … 2203 2329 } 2204 2330 2205 if (!file_exists(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/family_data. xml')) {2206 $this->error['sync_model'] = "File 'family_data. xmlDoesn't exist in directory: " . PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'];2331 if (!file_exists(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/family_data.json')) { 2332 $this->error['sync_model'] = "File 'family_data.json Doesn't exist in directory: " . PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir']; 2207 2333 return(FALSE); 2208 2334 } 2209 2335 2210 $family_line_xml = $this->xml2array(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/family_data.xml'); 2211 2212 if ($product_row['cfg_ver'] <= $family_line_xml['data']['version']) { 2213 if (array_key_exists('template_data', $family_line_xml['data']['model_list'])) { 2214 if (is_array($family_line_xml['data']['model_list']['template_data']['files'])) { 2215 $template_list = implode(",", $family_line_xml['data']['model_list']['template_data']['files']); 2216 $template_list_array = $family_line_xml['data']['model_list']['template_data']['files']; 2217 } else { 2218 $template_list = $family_line_xml['data']['model_list']['template_data']['files']; 2219 $template_list_array[0] = $family_line_xml['data']['model_list']['template_data']['files']; 2220 } 2221 $maxlines = $family_line_xml['data']['model_list']['lines']; 2222 } else { 2223 $key = $this->arraysearchrecursive($model_row['model'], $family_line_xml['data']['model_list'], 'model'); 2224 if ($key === FALSE) { 2225 $this->error['sync_model'] = "Can't locate model in family XML file"; 2226 return(FALSE); 2227 } else { 2228 if (is_array($family_line_xml['data']['model_list'][$key[0]]['template_data']['files'])) { 2229 $template_list = implode(",", $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']); 2230 $template_list_array = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; 2231 } else { 2232 $template_list = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; 2233 $template_list_array[0] = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; 2234 } 2235 } 2236 $maxlines = $family_line_xml['data']['model_list'][$key[0]]['lines']; 2237 } 2238 2239 $sql = "UPDATE endpointman_model_list SET max_lines = '" . $maxlines . "', template_list = '" . $template_list . "' WHERE id = '" . $model . "'"; 2240 $this->eda->sql($sql); 2241 2242 $version = $family_line_xml['data']['version']; 2243 $long_name = $family_line_xml['data']['name']; 2244 $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); 2245 $configuration_files = $family_line_xml['data']['configuration_files']; 2246 2247 $sql = "UPDATE endpointman_product_list SET long_name = '" . $long_name . "', short_name = '" . $short_name . "' , cfg_ver = '" . $version . "' WHERE id = '" . $product_row['id'] . "'"; 2248 $this->eda->sql($sql); 2249 2250 $template_data_array = array(); 2251 foreach ($template_list_array as $data) { 2252 if (file_exists(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/' . $data)) { 2253 $template_data_xml = $this->xml2array(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/' . $data); 2254 $template_data_xml = $this->fix_single_array_keys($template_data_xml['template_data']); 2255 $template_data_array = array_merge($template_data_array, $template_data_xml); 2256 } 2257 } 2258 2259 if (file_exists(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/template_data_custom.xml')) { 2260 $template_data_multi = $this->xml2array(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/template_data_custom.xml'); 2261 if ($template_data_multi) { 2262 $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); 2263 $template_data_array = array_merge($template_data_array, $template_data_multi); 2264 } 2265 } 2266 2267 if (file_exists(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/template_data_' . $model_row['model'] . '_custom.xml')) { 2268 $template_data_multi = $this->xml2array(self::$modules_path . $this->brand_name . "/" . $this->family_line . "/template_data_" . $this->model . "_custom.xml"); 2269 if ($template_data_multi) { 2270 $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); 2271 $template_data_array = array_merge($template_data_array, $template_data_multi); 2272 } 2273 } 2274 2275 if (empty($template_data_array)) { 2276 $this->error['sync_model'] = "No Template Data Found"; 2277 return(FALSE); 2278 } 2279 2280 $sql = "UPDATE endpointman_model_list SET template_data = '" . serialize($template_data_array) . "' WHERE id = '" . $model . "'"; 2281 $this->eda->sql($sql); 2282 } 2283 2336 $family_line_json = $this->file2json(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/family_data.json'); 2337 2338 //TODO: Add local file checks to avoid slow reloading on PHP < 5.3 2339 $key = $this->arraysearchrecursive($model_row['model'], $family_line_json['data']['model_list'], 'model'); 2340 if ($key === FALSE) { 2341 $this->error['sync_model'] = "Can't locate model in family JSON file"; 2342 return(FALSE); 2343 } else { 2344 $template_list = implode(",", $family_line_json['data']['model_list'][$key[0]]['template_data']); 2345 $template_list_array = $family_line_json['data']['model_list'][$key[0]]['template_data']; 2346 } 2347 $maxlines = $family_line_json['data']['model_list'][$key[0]]['lines']; 2348 2349 $sql = "UPDATE endpointman_model_list SET max_lines = '" . $maxlines . "', template_list = '" . $template_list . "' WHERE id = '" . $model . "'"; 2350 $this->eda->sql($sql); 2351 2352 $version = isset($family_line_json['data']['last_modified']) ? $family_line_json['data']['last_modified'] : ''; 2353 $long_name = $family_line_json['data']['name']; 2354 $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_json['data']['name']); 2355 $configuration_files = $family_line_json['data']['configuration_files']; 2356 2357 $sql = "UPDATE endpointman_product_list SET long_name = '" . $long_name . "', short_name = '" . $short_name . "' , cfg_ver = '" . $version . "' WHERE id = '" . $product_row['id'] . "'"; 2358 $this->eda->sql($sql); 2359 2360 $template_data_array = array(); 2361 2362 $template_data_array = $this->merge_data(PHONE_MODULES_PATH . '/endpoint/' . $brand_row['directory'] . '/' . $product_row['cfg_dir'] . '/', $template_list_array); 2363 2364 if (empty($template_data_array)) { 2365 $this->error['sync_model'] = "No Template Data Found"; 2366 return(FALSE); 2367 } 2368 2369 $sql = "UPDATE endpointman_model_list SET template_data = '" . serialize($template_data_array) . "' WHERE id = '" . $model . "'"; 2370 $this->eda->sql($sql); 2284 2371 return(TRUE); 2285 2372 } else { … … 2300 2387 * @return array 2301 2388 */ 2302 function arraysearchrecursive($Needle, $Haystack,$NeedleKey="",$Strict=false,$Path=array()) {2303 if (!is_array($Haystack))2389 function arraysearchrecursive($Needle, $Haystack, $NeedleKey="", $Strict=false, $Path=array()) { 2390 if (!is_array($Haystack)) 2304 2391 return false; 2305 foreach ($Haystack as $Key => $Val) {2306 if (is_array($Val)&&2307 $SubPath =$this->arraysearchrecursive($Needle,$Val,$NeedleKey,$Strict,$Path)) {2308 $Path =array_merge($Path,Array($Key),$SubPath);2392 foreach ($Haystack as $Key => $Val) { 2393 if (is_array($Val) && 2394 $SubPath = $this->arraysearchrecursive($Needle, $Val, $NeedleKey, $Strict, $Path)) { 2395 $Path = array_merge($Path, Array($Key), $SubPath); 2309 2396 return $Path; 2310 } 2311 elseif((!$Strict&&$Val==$Needle&& 2312 $Key==(strlen($NeedleKey)>0?$NeedleKey:$Key))|| 2313 ($Strict&&$Val===$Needle&& 2314 $Key==(strlen($NeedleKey)>0?$NeedleKey:$Key))) { 2315 $Path[]=$Key; 2397 } elseif ((!$Strict && $Val == $Needle && 2398 $Key == (strlen($NeedleKey) > 0 ? $NeedleKey : $Key)) || 2399 ($Strict && $Val === $Needle && 2400 $Key == (strlen($NeedleKey) > 0 ? $NeedleKey : $Key))) { 2401 $Path[] = $Key; 2316 2402 return $Path; 2317 2403 } … … 2319 2405 return false; 2320 2406 } 2321 2407 2322 2408 function run_in_background($Command, $Priority = 0) { 2323 2409 if ($Priority) … … 2335 2421 function download_file_with_progress_bar($url_file, $destination_file) { 2336 2422 set_time_limit(0); 2337 $headers = get_headers($url_file, 1); 2338 $size = $headers['Content-Length']; 2339 2340 if (preg_match('/200/', $headers[0])) {2341 $pid = $this->run_in_background("wget " . $url_file . " -O " . $destination_file);2342 2343 while ($this->is_process_running($pid)) {2344 2345 $out = 100 * round(filesize($destination_file) / $size, 2);2346 echo '<script type="text/javascript">document.getElementById(\'DivExample\').innerHTML="%' .$out.'";</script>';2423 $headers = get_headers($url_file, 1); 2424 $size = $headers['Content-Length']; 2425 2426 if (preg_match('/200/', $headers[0])) { 2427 $pid = $this->run_in_background("wget " . $url_file . " -O " . $destination_file); 2428 2429 while ($this->is_process_running($pid)) { 2430 2431 $out = 100 * round(filesize($destination_file) / $size, 2); 2432 echo '<script type="text/javascript">document.getElementById(\'DivExample\').innerHTML="%' . $out . '";</script>'; 2347 2433 2348 2434 usleep('500'); … … 2357 2443 } 2358 2444 2359 function download_file _no_progress_bar($url_file, $destination_file) {2445 function download_file($url_file, $destination_file) { 2360 2446 $contents = file_get_contents($url_file); 2361 if(preg_match('/200/', $http_response_header[0])) { 2362 file_put_contents($destination_file,$contents); 2447 2448 if (preg_match('/200/', $http_response_header[0])) { 2449 $dirname = dirname($destination_file); 2450 if (!file_exists($dirname)) { 2451 mkdir($dirname); 2452 } 2453 file_put_contents($destination_file, $contents); 2363 2454 //check file placement 2364 if(!file_exists($destination_file)) { 2365 return false; 2366 } 2367 return true; 2368 } else { 2369 return false; 2370 } 2371 } 2372 2373 function download_xml_file($url_file, $destination_file) { 2374 $contents = file_get_contents($url_file); 2375 if(preg_match('/200/', $http_response_header[0])) { 2376 file_put_contents($destination_file,$contents); 2377 //check file placement 2378 if(!file_exists($destination_file)) { 2455 if (!file_exists($destination_file)) { 2379 2456 return false; 2380 2457 } … … 2387 2464 //This function looks in common linux directories for system executable files. Like ARP & NMAP 2388 2465 function find_exec($exec) { 2389 $usr_bin = glob("/usr/bin/" .$exec);2390 $usr_sbin = glob("/usr/sbin/" .$exec);2391 $sbin = glob("/sbin/" .$exec);2392 $bin = glob("/bin/" .$exec);2393 $etc = glob("/etc/" .$exec);2394 if (isset($usr_bin[0])) {2395 return("/usr/bin/" .$exec);2396 } elseif (isset($usr_sbin[0])) {2397 return("/usr/sbin/" .$exec);2398 } elseif (isset($sbin[0])) {2399 return("/sbin/" .$exec);2400 } elseif (isset($bin[0])) {2401 return("/bin/" .$exec);2402 } elseif (isset($etc[0])) {2403 return("/etc/" .$exec);2466 $usr_bin = glob("/usr/bin/" . $exec); 2467 $usr_sbin = glob("/usr/sbin/" . $exec); 2468 $sbin = glob("/sbin/" . $exec); 2469 $bin = glob("/bin/" . $exec); 2470 $etc = glob("/etc/" . $exec); 2471 if (isset($usr_bin[0])) { 2472 return("/usr/bin/" . $exec); 2473 } elseif (isset($usr_sbin[0])) { 2474 return("/usr/sbin/" . $exec); 2475 } elseif (isset($sbin[0])) { 2476 return("/sbin/" . $exec); 2477 } elseif (isset($bin[0])) { 2478 return("/bin/" . $exec); 2479 } elseif (isset($etc[0])) { 2480 return("/etc/" . $exec); 2404 2481 } else { 2405 2482 return($exec); … … 2414 2491 */ 2415 2492 function rmrf($dir) { 2416 if (file_exists($dir)) {2493 if (file_exists($dir)) { 2417 2494 $iterator = new RecursiveDirectoryIterator($dir); 2418 2495 foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { … … 2434 2511 */ 2435 2512 function table_exists($table) { 2436 global $amp_conf;2437 $sql = "SHOW TABLES FROM " .$amp_conf['AMPDBNAME'];2438 $result = $this->eda->sql($sql, 'getAll');2439 2440 foreach ($result as $row) {2513 global $amp_conf; 2514 $sql = "SHOW TABLES FROM " . $amp_conf['AMPDBNAME']; 2515 $result = $this->eda->sql($sql, 'getAll'); 2516 2517 foreach ($result as $row) { 2441 2518 if ($row[0] == $table) { 2442 2519 return TRUE; … … 2446 2523 } 2447 2524 2448 /** 2449 * xml2array() will convert the given XML text to an array in the XML structure. 2450 * @author http://www.bin-co.com/php/scripts/xml2array/ 2451 * @param <type> $url The XML file 2452 * @param <type> $get_attributes 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value. 2453 * @param <type> $priority Can be 'tag' or 'attribute'. This will change the way the resulting array structure. For 'tag', the tags are given more importance. 2454 * @param <type> $array_tags - any tag names listed here will allways be returned as an array, even if there is only one of them. 2455 * @return <type> The parsed XML in an array form. Use print_r() to see the resulting array structure. 2456 */ 2457 function xml2array($url, $get_attributes = 1, $priority = 'tag', $array_tags=array()) { 2458 $contents = ""; 2459 if (!function_exists('xml_parser_create')) { 2460 return array(); 2461 } 2462 $parser = xml_parser_create(''); 2463 if (!($fp = @ fopen($url, 'rb'))) { 2464 return array(); 2465 } 2466 while (!feof($fp)) { 2467 $contents .= fread($fp, 8192); 2468 } 2469 fclose($fp); 2470 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); 2471 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); 2472 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); 2473 xml_parse_into_struct($parser, trim($contents), $xml_values); 2474 xml_parser_free($parser); 2475 if (!$xml_values) { 2476 return; //Hmm... 2477 } 2478 $xml_array = array(); 2479 $parents = array(); 2480 $opened_tags = array(); 2481 $arr = array(); 2482 $current = & $xml_array; 2483 $repeated_tag_index = array(); 2484 foreach ($xml_values as $data) { 2485 unset($attributes, $value); 2486 extract($data); 2487 $result = array(); 2488 $attributes_data = array(); 2489 if (isset($value)) { 2490 if ($priority == 'tag') { 2491 $result = $value; 2492 } else { 2493 $result['value'] = $value; 2494 } 2495 } 2496 if (isset($attributes) and $get_attributes) { 2497 foreach ($attributes as $attr => $val) { 2498 if ($priority == 'tag') { 2499 $attributes_data[$attr] = $val; 2500 } else { 2501 $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' 2502 } 2503 } 2504 } 2505 if ($type == "open") { 2506 $parent[$level - 1] = & $current; 2507 if (!is_array($current) or (!in_array($tag, array_keys($current)))) { 2508 if (in_array($tag,$array_tags)) { 2509 $current[$tag][0] = $result; 2510 $repeated_tag_index[$tag . '_' . $level]=1; 2511 $current = & $current[$tag][0]; 2512 } else { 2513 $current[$tag] = $result; 2514 if ($attributes_data) { 2515 $current[$tag . '_attr'] = $attributes_data; 2516 } 2517 $repeated_tag_index[$tag . '_' . $level] = 1; 2518 $current = & $current[$tag]; 2519 } 2520 } else { 2521 if (isset($current[$tag][0])) { 2522 $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; 2523 $repeated_tag_index[$tag . '_' . $level]++; 2524 } else { 2525 $current[$tag] = array($current[$tag], $result); 2526 $repeated_tag_index[$tag . '_' . $level] = 2; 2527 if (isset($current[$tag . '_attr'])) { 2528 $current[$tag]['0_attr'] = $current[$tag . '_attr']; 2529 unset($current[$tag . '_attr']); 2530 } 2531 } 2532 $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; 2533 $current = & $current[$tag][$last_item_index]; 2534 } 2535 } else if ($type == "complete") { 2536 if (!isset($current[$tag])) { 2537 $current[$tag] = $result; 2538 $repeated_tag_index[$tag . '_' . $level] = 1; 2539 if ($priority == 'tag' and $attributes_data) { 2540 $current[$tag . '_attr'] = $attributes_data; 2541 } 2542 } else { 2543 if (isset($current[$tag][0]) and is_array($current[$tag])) { 2544 $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; 2545 if ($priority == 'tag' and $get_attributes and $attributes_data) { 2546 $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; 2547 } 2548 $repeated_tag_index[$tag . '_' . $level]++; 2549 } else { 2550 $current[$tag] = array($current[$tag], $result); 2551 $repeated_tag_index[$tag . '_' . $level] = 1; 2552 if ($priority == 'tag' and $get_attributes) { 2553 if (isset($current[$tag . '_attr'])) { 2554 $current[$tag]['0_attr'] = $current[$tag . '_attr']; 2555 unset($current[$tag . '_attr']); 2556 } 2557 if ($attributes_data) { 2558 $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; 2559 } 2560 } 2561 $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken 2562 } 2563 } 2564 } else if ($type == 'close') { 2565 $current = & $parent[$level - 1]; 2566 } 2567 } 2568 return ($xml_array); 2525 function file2json($file) { 2526 if (file_exists($file)) { 2527 $json = file_get_contents($file); 2528 $data = json_decode($json, TRUE); 2529 return($data); 2530 } else { 2531 return(array()); 2532 } 2569 2533 } 2570 2534 … … 2577 2541 if ((strlen($mac) == "17") OR (strlen($mac) == "12")) { 2578 2542 //It might be better to use switch here instead of these IF statements... 2579 2580 2543 //Is the mac separated by colons(:) or dashes(-)? 2581 if (preg_match("/[0-9a-f][0-9a-f][:-]" .2582 "[0-9a-f][0-9a-f][:-]".2583 "[0-9a-f][0-9a-f][:-]".2584 "[0-9a-f][0-9a-f][:-]".2585 "[0-9a-f][0-9a-f][:-]".2586 "[0-9a-f][0-9a-f]/i", $mac)) {2544 if (preg_match("/[0-9a-f][0-9a-f][:-]" . 2545 "[0-9a-f][0-9a-f][:-]" . 2546 "[0-9a-f][0-9a-f][:-]" . 2547 "[0-9a-f][0-9a-f][:-]" . 2548 "[0-9a-f][0-9a-f][:-]" . 2549 "[0-9a-f][0-9a-f]/i", $mac)) { 2587 2550 return(strtoupper(str_replace(":", "", str_replace("-", "", $mac)))); 2588 2551 //Is the string exactly 12 characters? 2589 } elseif (strlen($mac) == "12") {2552 } elseif (strlen($mac) == "12") { 2590 2553 //Now is the string a valid HEX mac address? 2591 if (preg_match("/[0-9a-f][0-9a-f]" .2592 "[0-9a-f][0-9a-f]".2593 "[0-9a-f][0-9a-f]".2594 "[0-9a-f][0-9a-f]".2595 "[0-9a-f][0-9a-f]".2596 "[0-9a-f][0-9a-f]/i", $mac)) {2554 if (preg_match("/[0-9a-f][0-9a-f]" . 2555 "[0-9a-f][0-9a-f]" . 2556 "[0-9a-f][0-9a-f]" . 2557 "[0-9a-f][0-9a-f]" . 2558 "[0-9a-f][0-9a-f]" . 2559 "[0-9a-f][0-9a-f]/i", $mac)) { 2597 2560 return(strtoupper($mac)); 2598 2561 } else { … … 2600 2563 } 2601 2564 //Is the mac separated by whitespaces? 2602 } elseif (preg_match("/[0-9a-f][0-9a-f][\s]".2603 "[0-9a-f][0-9a-f][\s]".2604 "[0-9a-f][0-9a-f][\s]".2605 "[0-9a-f][0-9a-f][\s]".2606 "[0-9a-f][0-9a-f][\s]".2607 "[0-9a-f][0-9a-f]/i", $mac)) {2565 } elseif (preg_match("/[0-9a-f][0-9a-f][\s]" . 2566 "[0-9a-f][0-9a-f][\s]" . 2567 "[0-9a-f][0-9a-f][\s]" . 2568 "[0-9a-f][0-9a-f][\s]" . 2569 "[0-9a-f][0-9a-f][\s]" . 2570 "[0-9a-f][0-9a-f]/i", $mac)) { 2608 2571 return(strtoupper(str_replace(" ", "", $mac))); 2609 2572 } else { … … 2642 2605 2643 2606 if (($use_nmap) AND (file_exists($this->global_cfg['nmap_location'])) AND ($this->validate_netmask($netmask))) { 2644 shell_exec($this->global_cfg['nmap_location'] .' -v -sP '. $netmask);2645 } elseif (!$this->validate_netmask($netmask)) {2607 shell_exec($this->global_cfg['nmap_location'] . ' -v -sP ' . $netmask); 2608 } elseif (!$this->validate_netmask($netmask)) { 2646 2609 $this->error['discover_new'] = "Invalid Netmask"; 2647 2610 return(FALSE); 2648 } elseif (!file_exists($this->global_cfg['nmap_location'])) {2611 } elseif (!file_exists($this->global_cfg['nmap_location'])) { 2649 2612 $this->error['discover_new'] = "Could Not Find NMAP, Using ARP Only"; 2650 2613 //return(FALSE); … … 2658 2621 2659 2622 //Find all references to active computers by searching out mac addresses. 2660 $temp = array_values(array_unique(preg_grep("/[0-9a-f][0-9a-f][:-]" .2661 "[0-9a-f][0-9a-f][:-]".2662 "[0-9a-f][0-9a-f][:-]".2663 "[0-9a-f][0-9a-f][:-]".2664 "[0-9a-f][0-9a-f][:-]".2665 "[0-9a-f][0-9a-f]/i", $arp_array)));2623 $temp = array_values(array_unique(preg_grep("/[0-9a-f][0-9a-f][:-]" . 2624 "[0-9a-f][0-9a-f][:-]" . 2625 "[0-9a-f][0-9a-f][:-]" . 2626 "[0-9a-f][0-9a-f][:-]" . 2627 "[0-9a-f][0-9a-f][:-]" . 2628 "[0-9a-f][0-9a-f]/i", $arp_array))); 2666 2629 2667 2630 //Go through each row of valid arp entries and pull out the information and add it into a nice array! … … 2670 2633 2671 2634 //Pull out the IP address from row. It's always the first entry in the row and it can only be a max of 15 characters with the delimiters 2672 preg_match_all("/\((.*?)\)/", $value,$matches);2635 preg_match_all("/\((.*?)\)/", $value, $matches); 2673 2636 $ip = $matches[1]; 2674 2637 $ip = $ip[0]; 2675 2638 2676 2639 //Pull out the mac address by looking for the delimiter 2677 $mac = substr($value, (strpos($value, ":") - 2), 17);2640 $mac = substr($value, (strpos($value, ":") - 2), 17); 2678 2641 2679 2642 //Get rid of the delimiter … … 2681 2644 2682 2645 //arp -n will return a MAC address of 000000000000 if no hardware was found, so we need to ignore it 2683 if ($mac_strip != "000000000000") {2646 if ($mac_strip != "000000000000") { 2684 2647 //only use the first 6 characters for the oui: http://en.wikipedia.org/wiki/Organizationally_Unique_Identifier 2685 $oui = substr($mac_strip, 0,6);2648 $oui = substr($mac_strip, 0, 6); 2686 2649 2687 2650 //Find the matching brand model to the oui 2688 $oui_sql = "SELECT endpointman_brand_list.name, endpointman_brand_list.id FROM endpointman_oui_list, endpointman_brand_list WHERE oui LIKE '%" . $oui ."%' AND endpointman_brand_list.id = endpointman_oui_list.brand AND endpointman_brand_list.installed = 1 LIMIT 1";2651 $oui_sql = "SELECT endpointman_brand_list.name, endpointman_brand_list.id FROM endpointman_oui_list, endpointman_brand_list WHERE oui LIKE '%" . $oui . "%' AND endpointman_brand_list.id = endpointman_oui_list.brand AND endpointman_brand_list.installed = 1 LIMIT 1"; 2689 2652 2690 2653 $brand = $this->eda->sql($oui_sql, 'getRow', DB_FETCHMODE_ASSOC); 2691 2654 2692 2655 $res = $this->eda->sql($oui_sql); 2693 2656 $brand_count = $res->numRows(); 2694 2657 2695 2658 if (!$brand_count) { 2696 2659 //oui doesn't have a matching mysql reference, probably a PC/router/wap/printer of some sort. … … 2700 2663 2701 2664 //Find out if endpoint has already been configured for this mac address 2702 $epm_sql = "SELECT * FROM endpointman_mac_list WHERE mac LIKE '%" . $mac_strip ."%'";2665 $epm_sql = "SELECT * FROM endpointman_mac_list WHERE mac LIKE '%" . $mac_strip . "%'"; 2703 2666 $epm_row = $this->eda->sql($epm_sql, 'getRow', DB_FETCHMODE_ASSOC); 2704 2667 … … 2720 2683 //$final = array_values($final); 2721 2684 2722 if (!is_array($final)) {2685 if (!is_array($final)) { 2723 2686 return(FALSE); 2724 2687 } else { … … 2727 2690 } 2728 2691 2729 function areaAvailable($model, $area=NULL) {2730 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = '" . $model."'";2731 $count = $this->eda->sql($sql, 'getOne');2732 2733 for ($z=0;$z<$count;$z++) {2692 function areaAvailable($model, $area=NULL) { 2693 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = '" . $model . "'"; 2694 $count = $this->eda->sql($sql, 'getOne'); 2695 2696 for ($z = 0; $z < $count; $z++) { 2734 2697 $result[$z]['id'] = $z + 1; 2735 2698 $result[$z]['model'] = $z + 1; … … 2737 2700 2738 2701 $i = 1; 2739 foreach ($result as $row) {2702 foreach ($result as $row) { 2740 2703 if ($row['id'] == $area) { 2741 2704 $temp[$i]['value'] = $row['id']; 2742 2705 $temp[$i]['text'] = $row['model']; 2743 2706 $temp[$i]['selected'] = 'selected'; 2744 } else {2707 } else { 2745 2708 $temp[$i]['value'] = $row['id']; 2746 2709 $temp[$i]['text'] = $row['model']; … … 2761 2724 */ 2762 2725 function models_available($model=NULL, $brand=NULL, $product=NULL) { 2763 2726 2764 2727 if ((!isset($oui)) && (!isset($brand)) && (!isset($model))) { 2765 2728 $result1 = $this->eda->all_models(); 2766 } elseif((isset($brand)) && ($brand !=0)) {2729 } elseif ((isset($brand)) && ($brand != 0)) { 2767 2730 $result1 = $this->eda->all_models_by_brand($brand); 2768 } elseif((isset($product)) && ($product !=0)) {2731 } elseif ((isset($product)) && ($product != 0)) { 2769 2732 $result1 = $this->eda->all_models_by_product($product); 2770 2733 } else { … … 2773 2736 2774 2737 $i = 1; 2775 foreach ($result1 as $row) {2738 foreach ($result1 as $row) { 2776 2739 if ($row['id'] == $model) { 2777 2740 $temp[$i]['value'] = $row['id']; 2778 2741 $temp[$i]['text'] = $row['model']; 2779 2742 $temp[$i]['selected'] = 'selected'; 2780 } else {2743 } else { 2781 2744 $temp[$i]['value'] = $row['id']; 2782 2745 $temp[$i]['text'] = $row['model']; … … 2786 2749 } 2787 2750 2788 if (!isset($temp)) {2789 if (!isset($this->global_cfg['new'])) {2751 if (!isset($temp)) { 2752 if (!isset($this->global_cfg['new'])) { 2790 2753 $this->error['modelsAvailable'] = "You need to enable at least ONE model"; 2791 2754 } … … 2800 2763 $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($haystack)); 2801 2764 2802 foreach ($it AS $element) {2803 if ($element == $needle) {2765 foreach ($it AS $element) { 2766 if ($element == $needle) { 2804 2767 return TRUE; 2805 2768 } 2806 } 2769 } 2807 2770 return FALSE; 2808 2771 } 2809 2772 2810 function linesAvailable($lineid=NULL, $macid=NULL) {2811 if (isset($lineid)) {2812 $sql ="SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT endpointman_mac_list.model FROM endpointman_mac_list, endpointman_line_list WHERE endpointman_line_list.luid = ".$lineid." AND endpointman_line_list.mac_id = endpointman_mac_list.id)";2813 2814 $sql_l = "SELECT line, mac_id FROM `endpointman_line_list` WHERE luid = " .$lineid;2773 function linesAvailable($lineid=NULL, $macid=NULL) { 2774 if (isset($lineid)) { 2775 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT endpointman_mac_list.model FROM endpointman_mac_list, endpointman_line_list WHERE endpointman_line_list.luid = " . $lineid . " AND endpointman_line_list.mac_id = endpointman_mac_list.id)"; 2776 2777 $sql_l = "SELECT line, mac_id FROM `endpointman_line_list` WHERE luid = " . $lineid; 2815 2778 $line = $this->eda->sql($sql_l, 'getRow', DB_FETCHMODE_ASSOC); 2816 2779 2817 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = " .$line['mac_id'];2818 } elseif (isset($macid)) {2819 $sql ="SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT model FROM endpointman_mac_list WHERE id =".$macid.")";2820 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = " .$macid;2821 2780 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = " . $line['mac_id']; 2781 } elseif (isset($macid)) { 2782 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT model FROM endpointman_mac_list WHERE id =" . $macid . ")"; 2783 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = " . $macid; 2784 2822 2785 $line['line'] = 0; 2823 2786 } 2824 2787 2825 $max_lines = $this->eda->sql($sql, 'getOne');2826 $lines_used = $this->eda->sql($sql_lu, 'getAll');2827 2828 for ($i = 1; $i <= $max_lines; $i++) {2829 if ($i == $line['line']) {2788 $max_lines = $this->eda->sql($sql, 'getOne'); 2789 $lines_used = $this->eda->sql($sql_lu, 'getAll'); 2790 2791 for ($i = 1; $i <= $max_lines; $i++) { 2792 if ($i == $line['line']) { 2830 2793 $temp[$i]['value'] = $i; 2831 2794 $temp[$i]['text'] = $i; 2832 2795 $temp[$i]['selected'] = "selected"; 2833 2796 } else { 2834 if (!$this->in_array_recursive($i,$lines_used)) {2797 if (!$this->in_array_recursive($i, $lines_used)) { 2835 2798 $temp[$i]['value'] = $i; 2836 2799 $temp[$i]['text'] = $i; … … 2838 2801 } 2839 2802 } 2840 if (isset($temp)) {2803 if (isset($temp)) { 2841 2804 return($temp); 2842 2805 } else { … … 2851 2814 function display_registration_list($line_id=NULL) { 2852 2815 2853 if (isset($line_id)) {2816 if (isset($line_id)) { 2854 2817 $result = $this->eda->all_unused_registrations(); 2855 2818 $line_data = $this->eda->get_line_information($line_id); … … 2861 2824 $i = 1; 2862 2825 $temp = array(); 2863 foreach ($result as $row) {2826 foreach ($result as $row) { 2864 2827 $temp[$i]['value'] = $row['id']; 2865 2828 $temp[$i]['text'] = $row['id'] . " --- " . $row['description']; … … 2867 2830 } 2868 2831 2869 if (isset($line_data)) {2832 if (isset($line_data)) { 2870 2833 $temp[$i]['value'] = $line_data['ext']; 2871 2834 $temp[$i]['text'] = $line_data['ext'] . " --- " . $line_data['description']; … … 2874 2837 2875 2838 return($temp); 2876 2877 } 2839 } 2840 2878 2841 /** 2879 2842 * Returns list of Brands that are installed and not hidden and that have at least one model enabled under them … … 2881 2844 * @return array Number array used to generate a select box 2882 2845 */ 2883 function brands_available ($selected = NULL,$show_blank=TRUE) {2846 function brands_available($selected = NULL, $show_blank=TRUE) { 2884 2847 $data = $this->eda->all_active_brands(); 2885 if ($show_blank) {2848 if ($show_blank) { 2886 2849 $temp[0]['value'] = ""; 2887 2850 $temp[0]['text'] = ""; … … 2890 2853 $i = 0; 2891 2854 } 2892 foreach ($data as $row) {2855 foreach ($data as $row) { 2893 2856 $temp[$i]['value'] = $row['id']; 2894 2857 $temp[$i]['text'] = $row['name']; … … 2903 2866 } 2904 2867 2905 function display_templates($product_id, $temp_select = NULL) {2868 function display_templates($product_id, $temp_select = NULL) { 2906 2869 $i = 0; 2907 $sql ="SELECT id FROM endpointman_product_list WHERE endpointman_product_list.id ='".$product_id."'";2908 2909 $id = $this->eda->sql($sql, 'getOne');2910 2911 $sql ="SELECT * FROM endpointman_template_list WHERE product_id = '".$id."'";2912 2913 $data = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC);2914 foreach ($data as $row) {2870 $sql = "SELECT id FROM endpointman_product_list WHERE endpointman_product_list.id ='" . $product_id . "'"; 2871 2872 $id = $this->eda->sql($sql, 'getOne'); 2873 2874 $sql = "SELECT * FROM endpointman_template_list WHERE product_id = '" . $id . "'"; 2875 2876 $data = $this->eda->sql($sql, 'getAll', DB_FETCHMODE_ASSOC); 2877 foreach ($data as $row) { 2915 2878 $temp[$i]['value'] = $row['id']; 2916 2879 $temp[$i]['text'] = $row['name']; … … 2931 2894 } 2932 2895 2933 function listTZ($selected) { 2934 require('timezone.inc'); 2896 function listTZ($selected) { 2897 require('timezone.inc'); 2935 2898 $data = DateTimeZone::listIdentifiers(); 2936 2899 $i = 0; 2937 foreach ($data as $key => $row) {2900 foreach ($data as $key => $row) { 2938 2901 $temp[$i]['value'] = $row; 2939 2902 $temp[$i]['text'] = $row; 2940 2903 if ($temp[$i]['value'] == $selected) { 2941 2904 $temp[$i]['selected'] = 1; 2942 } else {2905 } else { 2943 2906 $temp[$i]['selected'] = 0; 2944 2907 } … … 2948 2911 return($temp); 2949 2912 } 2913 2914 function validate_json($json) { 2915 return(TRUE); 2916 } 2917 2950 2918 } 2951 2919 2952 function endpointman_flush_buffers() {2920 function endpointman_flush_buffers() { 2953 2921 ob_end_flush(); 2954 2922 //ob_flush(); … … 2958 2926 2959 2927 function endpointman_update_progress_bar($out) { 2960 echo '<script type="text/javascript">document.getElementById(\'DivExample\').innerHTML="%' .$out.'";</script>';2928 echo '<script type="text/javascript">document.getElementById(\'DivExample\').innerHTML="%' . $out . '";</script>'; 2961 2929 } 2962 2930 … … 2966 2934 $regs = ""; 2967 2935 preg_match("/(Content-Length:) (.*)/i", $string, $regs); 2968 if ((isset($regs[2])) AND ($regs[2] <> "")) {2936 if ((isset($regs[2])) AND ($regs[2] <> "")) { 2969 2937 $file_size = intval($regs[2]); 2970 2938 } … … 2980 2948 $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); 2981 2949 $downloadProgress = 100 - $downloadProgress; 2982 if ($lastseen <> $downloadProgress and $downloadProgress < 101) {2983 if ($progress_bar) {2950 if ($lastseen <> $downloadProgress and $downloadProgress < 101) { 2951 if ($progress_bar) { 2984 2952 endpointman_update_progress_bar($downloadProgress); 2985 2953 } 2986 2954 $lastseen = $downloadProgress; 2987 2955 } 2988 if ($fout)2956 if ($fout) 2989 2957 fwrite($fout, $string); 2990 2958 //ob_flush(); modules/branches/2.10/endpointman/includes/popup.inc
r12937 r13276 9 9 10 10 if($_REQUEST['pop_type'] == 'edit_specifics') { 11 $info = $endpoint->get_phone_info($_REQUEST['edit_id']); 12 if(isset($_REQUEST['button_save'])) { 13 $endpoint->message['advanced_settings'] = "Updated!"; 14 foreach($info['line'] as $data) { 15 $line = $data['line']; 16 $final['displayname_'.$line] = $_REQUEST['displayname_'.$line]; 17 } 18 $sql = "UPDATE endpointman_mac_list SET specific_settings = '".serialize($final)."' WHERE id =". $_REQUEST['edit_id']; 19 $endpoint->eda->sql($sql); 20 } 21 22 $info = $endpoint->get_phone_info($_REQUEST['edit_id']); 23 $specific_settings = !empty($info['specific_settings']) ? unserialize($info['specific_settings']) : array(); 24 25 $z = 0; 26 foreach($info['line'] as $data) { 27 $line = $data['line']; 28 $displayname[$z]['displayname'] = isset($specific_settings['displayname_'.$line]) ? $specific_settings['displayname_'.$line] : '{$displayname.line.'.$line.'}'; 29 $displayname[$z]['line'] = $line; 30 $z++; 11 12 if(file_exists(PHONE_MODULES_PATH . 'endpoint/global_template_data.json')) { 13 $template_list[0] = 'global_template_data.json'; 14 15 $phone_info = $endpoint->get_phone_info($_REQUEST['edit_id']); 16 17 $sql = 'SELECT max_lines FROM endpointman_model_list WHERE id = '. $phone_info['model_id']; 18 19 $lines = $endpoint->eda->sql($sql, 'getOne'); 20 $merged = $endpoint->merge_data(PHONE_MODULES_PATH . 'endpoint/', $template_list,$lines); 21 22 //remove stuff that is meaningless in this context 23 unset($merged['data']['globals']['globals']['option|mac']); 24 unset($merged['data']['globals']['globals']['break|0']); 25 unset($merged['data']['globals']['globals']['option|provision_protocol']); 26 27 $html_array = $endpoint->generate_gui_html(serialize($merged), NULL, TRUE, NULL, $lines); 28 29 $specific_data = array(); 30 if (isset($_REQUEST['button_save'])) { 31 foreach ($_REQUEST as $key => $data) { 32 $key = str_replace('freepbx_', '', $key); 33 if (isset($_REQUEST['freepbx_' . $key])) { 34 $specific_data['freepbx'][$key] = TRUE; 35 } 36 if ($endpoint->arraysearchrecursive($key, $html_array, 'key')) { 37 if(!isset($specific_data['freepbx'][$key])) { 38 $specific_data['data'][$key] = $data; 39 } 40 } 41 } 42 $specific_data['data']['use_dhcp'] = isset($specific_data['data']['use_dhcp']) ? TRUE : FALSE; 43 44 $sql = "UPDATE endpointman_mac_list SET specific_settings = '" . serialize($specific_data) . "' WHERE id =" . $_REQUEST['edit_id']; 45 $endpoint->eda->sql($sql); 46 } else { 47 $sql = 'SELECT specific_settings FROM endpointman_mac_list WHERE id ='. $_REQUEST['edit_id']; 48 $specific_data = unserialize($endpoint->eda->sql($sql, 'getOne')); 49 } 50 51 foreach($phone_info['line'] as $data) { 52 $lid = $data['line']; 53 $specific_data['data']['line|'.$lid.'|displayname'] = !isset($specific_data['data']['line|'.$lid.'|displayname']) ? $data['description'] : $specific_data['data']['line|'.$lid.'|displayname']; 54 $specific_data['data']['line|'.$lid.'|username'] = !isset($specific_data['data']['line|'.$lid.'|username']) ? $data['ext'] : $specific_data['data']['line|'.$lid.'|username']; 55 $specific_data['data']['line|'.$lid.'|authname'] = !isset($specific_data['data']['line|'.$lid.'|authname']) ? $data['ext'] : $specific_data['data']['line|'.$lid.'|authname']; 56 $specific_data['data']['line|'.$lid.'|secret'] = !isset($specific_data['data']['line|'.$lid.'|secret']) ? $data['secret'] : $specific_data['data']['line|'.$lid.'|secret']; 57 $specific_data['data']['line|'.$lid.'|server_host'] = !isset($specific_data['data']['line|'.$lid.'|server_host']) ? $endpoint->global_cfg['srvip'] : $specific_data['data']['line|'.$lid.'|server_host']; 58 $specific_data['data']['line|'.$lid.'|server_port'] = !isset($specific_data['data']['line|'.$lid.'|server_port']) ? 5060 : $specific_data['data']['line|'.$lid.'|server_port']; 59 $specific_data['data']['line|'.$lid.'|line_enabled'] = !isset($specific_data['data']['line|'.$lid.'|line_enabled']) ? TRUE : $specific_data['data']['line|'.$lid.'|line_enabled']; 60 } 61 62 $specific_data['data']['ntp'] = isset($specific_data['data']['ntp']) ? $specific_data['data']['ntp'] : $endpoint->global_cfg['ntp']; 63 $specific_data['data']['use_dhcp'] = isset($specific_data['data']['use_dhcp']) ? TRUE : FALSE; 64 65 $html_array = $endpoint->generate_gui_html(serialize($merged), serialize($specific_data), TRUE, NULL, $lines); 31 66 } 32 67 33 68 $endpoint->prepare_message_box(); 34 $endpoint->tpl->assign(" display_name", $displayname);69 $endpoint->tpl->assign("html_array", $html_array); 35 70 echo $endpoint->tpl->draw( 'specifics_pop' ); 36 71 } modules/branches/2.10/endpointman/install.php
r12911 r13276 135 135 136 136 out('Version Identified as '. $full_vers); 137 out('Internal Reference Number: '.$ver); 137 138 } else { 138 139 $new_install = TRUE; … … 879 880 $db->query($sql); 880 881 881 $sql = "CREATE TABLE IF NOT EXISTS `endpointman_time_zones_desc` (882 `id` int(11) NOT NULL auto_increment,883 `tid` int(11) NOT NULL,884 `name` varchar(255) NOT NULL,885 `description` varchar(255) NOT NULL,886 PRIMARY KEY (`id`)887 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=32";888 $db->query($sql);889 890 $sql = "INSERT INTO `endpointman_time_zones_desc` (`id`, `tid`, `name`, `description`) VALUES891 (1, 1, 'UTC', 'Universal Coordinated Time (and Greenwich Mean Time)'),892 (2, 2, 'ECT', 'European Central Time'),893 (3, 3, 'EET', 'Eastern European Time'),894 (4, 3, 'ART', '(Arabic) Egypt Standard Time'),895 (5, 4, 'EAT', 'Eastern African Time'),896 (6, 5, 'MET', 'Middle East Time'),897 (7, 6, 'NET', 'Near East Time'),898 (8, 7, 'PLT', 'Pakistan Lahore Time'),899 (9, 8, 'IST', 'India Standard Time'),900 (10, 9, 'BST', 'Bangladesh Standard Time'),901 (11, 10, 'VST', 'Vietnam Standard Time'),902 (12, 11, 'CTT', 'China Taiwan Time'),903 (13, 12, 'JST', 'Japan Standard Time'),904 (14, 13, 'ACT', 'Australia Central Time'),905 (15, 14, 'AET', 'Australia Eastern Time'),906 (16, 15, 'SST', 'Solomon Standard Time'),907 (17, 16, 'NST', 'New Zealand Standard Time'),908 (18, 17, 'MIT', 'Midway Islands Time'),909 (19, 18, 'HST', 'Hawaii Standard Time'),910 (20, 19, 'AST', 'Alaska Standard Time'),911 (21, 20, 'PST', 'Pacific Standard Time'),912 (22, 21, 'PNT', 'Phoenix Standard Time'),913 (23, 21, 'MST', 'Mountain Standard Time'),914 (24, 22, 'CST', 'Central Standard Time'),915 (25, 23, 'EST', 'Eastern Standard Time'),916 (26, 23, 'IET', 'Indiana Eastern Standard Time'),917 (27, 24, 'PRT', 'Puerto Rico and US Virgin Islands Time'),918 (28, 25, 'CNT', 'Canada Newfoundland Time'),919 (29, 26, 'AGT', 'Argentina Standard Time'),920 (30, 26, 'BET', 'Brazil Eastern Time'),921 (31, 27, 'CAT', 'Central African Time')";922 $db->query($sql);923 924 $sql = "CREATE TABLE IF NOT EXISTS `endpointman_time_zones_new` (925 `id` int(11) NOT NULL auto_increment,926 `gmt` varchar(255) NOT NULL,927 `offset` int(11) NOT NULL,928 PRIMARY KEY (`id`)929 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28";930 $db->query($sql);931 932 $sql = "INSERT INTO `endpointman_time_zones_new` (`id`, `gmt`, `offset`) VALUES933 (1, 'GMT', 0),934 (2, 'GMT+1:00', 3600),935 (3, 'GMT+2:00', 7200),936 (4, 'GMT+3:00', 10800),937 (5, 'GMT+3:30', 12600),938 (6, 'GMT+4:00', 14400),939 (7, 'GMT+5:00', 18000),940 (8, 'GMT+5:30', 19800),941 (9, 'GMT+6:00', 21600),942 (10, 'GMT+7:00', 25200),943 (11, 'GMT+8:00', 28800),944 (12, 'GMT+9:00', 32400),945 (13, 'GMT+9:30', 34200),946 (14, 'GMT+10:00', 36000),947 (15, 'GMT+11:00', 39600),948 (16, 'GMT+12:00', 43200),949 (17, 'GMT-11:00', -39600),950 (18, 'GMT-10:00', -36000),951 (19, 'GMT-9:00', -32400),952 (20, 'GMT-8:00', -28800),953 (21, 'GMT-7:00', -25200),954 (22, 'GMT-6:00', -21600),955 (23, 'GMT-5:00', -18000),956 (24, 'GMT-4:00', -14400),957 (25, 'GMT-3:30', -12600),958 (26, 'GMT-3:00', -10800),959 (27, 'GMT-1:00', -3600)";960 $db->query($sql);961 962 882 out('Creating symlink to web provisioner'); 963 883 if (!symlink(LOCAL_PATH . "provisioning", $amp_conf['AMPWEBROOT'] . "/provisioning")) { … … 981 901 } 982 902 983 if ($ver <= "21002") {903 if($ver <= "21021") { 984 904 out('Updating Mirror Location...again'); 985 $sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v2.5/' WHERE var_name ='update_server'"; 905 $sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v3/' WHERE var_name ='update_server'"; 906 $db->query($sql); 907 908 out("Uninstalling All Installed Brands (You'll just simply have to update again, no loss of data)"); 909 $db->query("UPDATE endpointman_brand_list SET installed = '0'"); 910 $db->query("TRUNCATE TABLE endpointman_brand_list"); 911 912 $sql = "UPDATE endpointman_model_list SET enabled = '0', template_data = '".serialize(array())."'"; 913 $db->query($sql); 914 915 out("Moving old brand data for backups, its now in ". $amp_conf['AMPWEBROOT']."/admin/modules/_ep_phone_modules_old"); 916 exec("mv ". $amp_conf['AMPWEBROOT']."/admin/modules/_ep_phone_modules" . " ". $amp_conf['AMPWEBROOT']."/admin/modules/_ep_phone_modules_old"); 917 918 if(!file_exists(PHONE_MODULES_PATH)) { 919 mkdir(PHONE_MODULES_PATH, 0764); 920 out("Creating Phone Modules Directory"); 921 } 922 923 if(!file_exists(PHONE_MODULES_PATH."setup.php")) { 924 copy(LOCAL_PATH."install/setup.php",PHONE_MODULES_PATH."setup.php"); 925 out("Moving Auto Provisioner Class"); 926 } 927 928 if(!file_exists(PHONE_MODULES_PATH."temp/")) { 929 mkdir(PHONE_MODULES_PATH."temp/", 0764); 930 out("Creating temp folder"); 931 } 932 } 933 934 if($ver <= "21024") { 935 out('Updating Mirror Location...again'); 936 $sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v3/' WHERE var_name ='update_server'"; 986 937 $db->query($sql); 987 938 } … … 1040 991 (4, 'gmthr', ''), 1041 992 (5, 'config_location', '/tftpboot/'), 1042 (6, 'update_server', 'http://mirror.freepbx.org/provisioner/v 2.5/'),993 (6, 'update_server', 'http://mirror.freepbx.org/provisioner/v3/'), 1043 994 (7, 'version', '".$xml_full_version."'), 1044 995 (8, 'enable_ari', '0'), … … 1151 1102 $db->query($sql); 1152 1103 1153 $sql = "UPDATE endpointman_global_vars SET value = 'http:// mirror.freepbx.org/provisioner/v2.5/' WHERE var_name = 'update_server'";1104 $sql = "UPDATE endpointman_global_vars SET value = 'http://www.provisioner.net/release/v3/' WHERE var_name = 'update_server'"; 1154 1105 $db->query($sql); 1155 1106 modules/branches/2.10/endpointman/module.xml
r12940 r13276 3 3 <repo>standard</repo> 4 4 <name>PBX End Point Manager</name> 5 <version>2.10. 1.3</version>5 <version>2.10.2.4</version> 6 6 <type>setup</type> 7 7 <category>Connectivity</category> modules/branches/2.10/endpointman/provisioning/p.php
r12938 r13276 52 52 if(preg_match('/[0-9A-Fa-f]{12}/i', $strip, $matches) && !(preg_match('/[0]{10}[0-9]{2}/i',$strip))) { 53 53 $mac_address = $matches[0]; 54 54 55 55 $sql = 'SELECT id FROM `endpointman_mac_list` WHERE `mac` LIKE CONVERT(_utf8 \'%' . $mac_address . '%\' USING latin1) COLLATE latin1_swedish_ci'; 56 56 57 $mac_id = $endpoint-> db->getOne($sql);57 $mac_id = $endpoint->eda->sql($sql, 'getOne'); 58 58 $phone_info = $endpoint->get_phone_info($mac_id); 59 59 60 if (file_exists(PROVISIONER_BASE . 'setup.php')) { 61 if (!class_exists('ProvisionerConfig')) { 62 require(PROVISIONER_BASE . 'setup.php'); 63 } 64 65 66 //Load Provisioner 67 $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; 68 $base_class = "endpoint_" . $phone_info['directory'] . '_base'; 69 $master_class = "endpoint_base"; 70 71 if (!class_exists($master_class)) { 72 ProvisionerConfig::endpointsAutoload($master_class); 73 } 74 if (!class_exists($base_class)) { 75 ProvisionerConfig::endpointsAutoload($base_class); 76 } 77 if (!class_exists($class)) { 78 ProvisionerConfig::endpointsAutoload($class); 79 } 80 //end quick fix 81 82 if (class_exists($class)) { 83 $provisioner_libary = new $class(); 84 //Determine if global settings have been overridden 85 $settings = ''; 86 if ($phone_info['template_id'] > 0) { 87 if (isset($phone_info['template_data_info']['global_settings_override'])) { 88 $settings = unserialize($phone_info['template_data_info']['global_settings_override']); 89 } else { 90 $settings['srvip'] = $endpoint->global_cfg['srvip']; 91 $settings['ntp'] = $endpoint->global_cfg['ntp']; 92 $settings['config_location'] = $endpoint->global_cfg['config_location']; 93 $settings['tz'] = $endpoint->global_cfg['tz']; 94 } 95 } else { 96 if (isset($phone_info['global_settings_override'])) { 97 $settings = unserialize($phone_info['global_settings_override']); 98 } else { 99 $settings['srvip'] = $endpoint->global_cfg['srvip']; 100 $settings['ntp'] = $endpoint->global_cfg['ntp']; 101 $settings['config_location'] = $endpoint->global_cfg['config_location']; 102 $settings['tz'] = $endpoint->global_cfg['tz']; 103 } 104 } 105 106 //Tell the system who we are and were to find the data. 107 $provisioner_libary->root_dir = PROVISIONER_BASE; 108 $provisioner_libary->engine = 'asterisk'; 109 $provisioner_libary->engine_location = $endpoint->global_cfg['asterisk_location']; 110 $provisioner_libary->system = 'unix'; 111 112 //have to because of versions less than php5.3 113 $provisioner_libary->brand_name = $phone_info['directory']; 114 $provisioner_libary->family_line = $phone_info['cfg_dir']; 115 116 //Mac Address 117 $provisioner_libary->mac = $phone_info['mac']; 118 119 //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models) 120 //This has to match word for word. I really need to fix this.... 121 $provisioner_libary->model = $phone_info['model']; 122 123 //Timezone 124 $http_provisioner->DateTimeZone = new DateTimeZone($settings['tz']); 125 126 127 //Network Time Server 128 $provisioner_libary->ntp = $settings['ntp']; 129 130 //Server IP 131 $provisioner_libary->server[1]['ip'] = $settings['srvip']; 132 $provisioner_libary->server[1]['port'] = 5060; 133 134 $temp = ""; 135 $template_data = unserialize($phone_info['template_data']); 136 $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']); 137 if ($phone_info['template_id'] > 0) { 138 $global_custom_cfg_data = unserialize($phone_info['template_data_info']['global_custom_cfg_data']); 139 //Provide alternate Configuration file instead of the one from the hard drive 140 if (!empty($phone_info['template_data_info']['config_files_override'])) { 141 $temp = unserialize($phone_info['template_data_info']['config_files_override']); 142 foreach ($temp as $list) { 143 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " . $list; 144 $res = $endpoint->db->query($sql); 145 if ($res->numRows()) { 146 $data = $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 147 $provisioner_libary->config_files_override[$data['original_name']] = $data['data']; 148 } 149 } 150 } 151 } else { 152 $global_custom_cfg_data = unserialize($phone_info['global_custom_cfg_data']); 153 //Provide alternate Configuration file instead of the one from the hard drive 154 if (!empty($phone_info['config_files_override'])) { 155 $temp = unserialize($phone_info['config_files_override']); 156 foreach ($temp as $list) { 157 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " . $list; 158 $res = $endpoint->db->query($sql); 159 if ($res->numRows()) { 160 $data = $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 161 $provisioner_libary->config_files_override[$data['original_name']] = $data['data']; 162 } 163 } 164 } 165 } 166 167 if (!empty($global_custom_cfg_data)) { 168 if (array_key_exists('data', $global_custom_cfg_data)) { 169 $global_custom_cfg_ari = $global_custom_cfg_data['ari']; 170 $global_custom_cfg_data = $global_custom_cfg_data['data']; 171 } else { 172 $global_custom_cfg_data = array(); 173 $global_custom_cfg_ari = array(); 174 } 175 } 176 177 $new_template_data = array(); 178 $line_ops = array(); 179 if (is_array($global_custom_cfg_data)) { 180 foreach ($global_custom_cfg_data as $key => $data) { 181 $full_key = $key; 182 $key = explode('|', $key); 183 $count = count($key); 184 switch ($count) { 185 case 1: 186 if (($endpoint->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 187 $new_template_data[$full_key] = $global_user_cfg_data[$full_key]; 188 } else { 189 $new_template_data[$full_key] = $global_custom_cfg_data[$full_key]; 190 } 191 break; 192 case 2: 193 $breaks = explode('_', $key[1]); 194 if (($endpoint->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 195 $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key]; 196 } else { 197 $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key]; 198 } 199 break; 200 case 3: 201 if (($endpoint->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 202 $line_ops[$key[1]][$key[2]] = $global_user_cfg_data[$full_key]; 203 } else { 204 $line_ops[$key[1]][$key[2]] = $global_custom_cfg_data[$full_key]; 205 } 206 break; 207 } 208 } 209 } 210 211 //Loop through Lines! 212 foreach ($phone_info['line'] as $line) { 213 $provisioner_libary->lines[$line['line']] = array('ext' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description']); 214 } 215 216 //testing this out 217 foreach ($line_ops as $key => $data) { 218 if (isset($line_ops[$key])) { 219 $provisioner_libary->lines[$key]['options'] = $line_ops[$key]; 220 } 221 } 222 223 $provisioner_libary->server_type = 'dynamic'; 224 $provisioner_libary->provisioning_type = 'http'; 225 $provisioner_libary->provisioning_path = $provis_ip.dirname($_SERVER['REQUEST_URI']); 226 227 //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create 228 //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included 229 //line 'global' will set variables that aren't line dependant 230 $provisioner_libary->options = $new_template_data; 231 232 //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed 233 //and if they have defaults assigned in a future template_data.xml or in the config file using pipes (|) those will be used, pipes take precedence 234 $provisioner_libary->processor_info = "EndPoint Manager Version " . $endpoint->global_cfg['version']; 235 236 $files = $provisioner_libary->generate_config(); 237 238 if(array_key_exists($filename, $files)) { 239 echo $files[$filename]; 240 } else { 241 header("HTTP/1.0 404 Not Found"); 242 die(); 243 } 244 } else { 245 header("HTTP/1.0 500 Internal Server Error"); 246 die(); 247 } 248 } else { 60 $files = $endpoint->prepare_configs($phone_info,FALSE,FALSE); 61 62 if(!files) { 249 63 header("HTTP/1.0 500 Internal Server Error"); 250 64 die(); 251 65 } 66 67 if (array_key_exists($filename, $files)) { 68 echo $files[$filename]; 69 } else { 70 header("HTTP/1.0 404 Not Found"); 71 die(); 72 } 73 252 74 } else { 253 75 require_once (PROVISIONER_BASE.'endpoint/base.php'); modules/branches/2.10/endpointman/templates/freepbx/advanced_settings_settings.html
r12768 r13276 79 79 </tr> 80 80 <tr> 81 <td align='right'><?php echo _("Enable FreePBX ARI Module")?> (<a href="http:// projects.colsolgrp.net/documents/29" target="_blank">What?</a>)</td>81 <td align='right'><?php echo _("Enable FreePBX ARI Module")?> (<a href="http://wiki.provisioner.net/index.php/Endpoint_manager_manual_ari" target="_blank">What?</a>)</td> 82 82 <td align='left'><label> 83 83 <input type=checkbox name="enable_ari" {$ari_selected}> modules/branches/2.10/endpointman/templates/freepbx/devices_manager.html
r12938 r13276 181 181 function popitup(url, name, id) { 182 182 if(id != '0') { 183 newwindow=window.open(url + '&model_list=' + document.getElementById('model_new').value + '&template_list=' + document.getElementById('template_list').value + '&rand=' + new Date().getTime(),'name2','height=1000,width=950 ');183 newwindow=window.open(url + '&model_list=' + document.getElementById('model_new').value + '&template_list=' + document.getElementById('template_list').value + '&rand=' + new Date().getTime(),'name2','height=1000,width=950,scrollbars=yes,location=no'); 184 184 if (window.focus) {newwindow.focus()} 185 185 return false; … … 188 188 189 189 function submit_stype(type,id) { 190 newwindow=window.open('config.php?display=epm_config&quietmode=1&handler=file&file=popup.html.php&module=endpointman&pop_type=edit_specifics&edit_id=' + id + '&rand=' + new Date().getTime(),'name2','height=700,width=750 ');190 newwindow=window.open('config.php?display=epm_config&quietmode=1&handler=file&file=popup.html.php&module=endpointman&pop_type=edit_specifics&edit_id=' + id + '&rand=' + new Date().getTime(),'name2','height=700,width=750,scrollbars=yes,location=no'); 191 191 if (window.focus) {newwindow.focus()} 192 192 return false; … … 441 441 <td align='center'><h3>Extension Number</h3></td> 442 442 <td align='center'><h3>Template</h3></td> 443 < !--<td align='center'><h3>Specific</h3></td>-->443 <td align='center'><h3>Specific</h3></td> 444 444 <td align='center'><h3>Edit</h3></td> 445 445 <td align='center'><h3>Delete</h3></td> … … 454 454 <td width="19%" align='center'><div id="demo"><a><img src="assets/endpointman/images/expand.png" id="img3rowGroup{$value.master_id}" onclick="toggleDisplay(document.getElementById('devList'),'rowGroup{$value.master_id}')" title="Click to Expand Line Information"></a></div></td> 455 455 <td align='center' width='15%'>{$value.template_name}</td> 456 < !--<td align='center'><div id="demo"><a href="#" onclick="submit_stype('edit',{$value.id});"><img src='assets/endpointman/images/edit.png' ALT='<?php echo _('Edit')?>' title='Edit Device' border='0'></a></div></td>-->456 <td align='center'><div id="demo"><a href="#" onclick="submit_stype('edit',{$value.id});"><img src='assets/endpointman/images/edit.png' ALT='<?php echo _('Edit')?>' title='Edit Device' border='0'></a></div></td> 457 457 <td align='center' width='9%'><div id="demo"><a href="#" onclick="submit_wtype('edit',{$value.id});"><img src='assets/endpointman/images/edit.png' ALT='<?php echo _('Edit')?>' title='Edit Device' border='0'></a></div></td> 458 458 <td align='center' width='7%'><div id="demo"><a href="#" onclick="delete_device({$value.id});"><img src='assets/endpointman/images/delete.png' ALT='<?php echo _('Delete')?>' title='Delete Device' border='0'></a></div></td> modules/branches/2.10/endpointman/templates/freepbx/specifics_pop.html
r12831 r13276 11 11 $('#myform').append('<input type="hidden" name="button_save" value="Save"/>'); 12 12 document.myform.submit(); 13 setTimeout("opener.Reload()",100);14 13 } 15 14 </script> 16 15 </head> 17 16 <body face="Arial"> 18 <div id="spinner">19 </div>20 17 <br> 21 18 <h1><face="Arial"><center><?php echo _('End Point Configuration Manager')?></center></h1> … … 24 21 {include="message_box"} 25 22 {/if} 23 {include="variables"} 26 24 <form name="myform" id="myform" method="post" action=""><input type="hidden" id="value" name="value" value="{$value}" /> 27 25 <table width="90%" border="0" cellspacing="0" cellpadding="0"> 28 <tr><td colspan="2"><u>General Settings</u></td></tr> 29 {loop name="display_name"} 30 <tr><td>Display Name Line {$value.line}:</td><td><input type="text" name="displayname_{$value.line}" value="{$value.displayname}" /></td></tr> 31 {/loop} 32 <tr><td colspan="2"> </td></tr> 33 <tr><td colspan="2"><u>IP Settings</u></td></tr> 34 <tr><td>IP Type</td><td> 35 <select> 36 <option value="dhcp">DHCP</option> 37 <option value="static">Static</option> 38 </select> 39 </td></tr> 40 <tr><td width="30%">IPv4 Address:</td><td><input type="text" name="ipv4" value="" /></td></tr> 41 <tr><td>IPv6 Address:</td><td><input type="text" name="ipv46" value="" /></td></tr> 42 <tr><td>Subnet Mask Address:</td><td><input type="text" name="subnet" value="" /></td></tr> 43 <tr><td>Gateway Address:</td><td><input type="text" name="gateway" value="" /></td></tr> 44 <tr> 45 <td colspan="2"> 46 <br><div style="font-size: 15px"> 47 <label> 48 <input type="submit" name="button_save" value="<?php echo _('Save')?>" onClick="javascript:submitform();"><input type=button value="Close Window" onClick="javascript:Close();"> 49 </label> 50 </td> 51 </tr> 26 {loop name="html_array"} 27 <tr><td colspan="2"> </td></tr> 28 <tr><td colspan="2"><u><strong>{$value.title}</strong></u></td></tr> 29 {loop name="value.data"} 30 {if condition="$value.type != 'break'"} 31 <tr> 32 <td width="50%" nowrap> 33 {if condition="$value.type == 'input'"} 34 <label>{if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <input type='text' name='{$value.key}' id='{$value.key}' value='{$value.value}' size="{if condition="isset($value.max_chars)"}{$value.max_chars}{else}40{/if}"></label> 35 {elseif condition="$value.type == 'textarea'"} 36 {if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <textarea rows="2" cols="20" name='{$value.key}' id='{$value.key}'>{$value.value}</textarea> 37 {elseif condition="$value.type == 'file'"} 38 <label>{if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <input type='file' name='{$value.key}' id='{$value.key}' value='{$value.value}'></label> 39 {elseif condition="$value.type == 'radio'"} 40 {if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if} 41 {loop name="value.data"} 42 <label>{if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <input type='radio' name='{$value.key}' id='{$value.key}' value='{$value.value}' {if condition="array_key_exists('checked',$value)"}{$value.checked}{/if}></label> 43 {/loop} 44 {elseif condition="$value.type == 'list'"} 45 {if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <select name='{$value.key}' id='{$value.key}'> 46 {loop name="value.data"} 47 <option value='{$value.value}' {if condition="array_key_exists('selected',$value)"}{$value.selected}{/if}>{$value.description}</option> 48 {/loop} 49 </select> 50 {elseif condition="$value.type == 'checkbox'"} 51 <label>{if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <input type='checkbox' name='{$value.key}' id='{$value.key}' value='{$value.value}' {if condition="$value.checked === TRUE"}checked{/if}></label> 52 {/if} 53 </td> 54 <td><label><input type='checkbox' name='freepbx_{$value.key}' id='freepbx_{$value.key}' value='freepbx_{$value.value}' {if condition="$value.freepbx.checked === TRUE"}checked{/if}> FreePBX Controlled</label></td> 55 </tr> 56 {/if} 57 {if condition="$value.type == 'break'"} 58 <tr> 59 <td> </td> 60 <td> </td> 61 </tr> 62 {/if} 63 {/loop} 64 {/loop} 52 65 </table> 53 </form> 66 <input type="submit" value="Submit" onClick="javascript:submitform();" /><input type=button value="Close Window" onClick="javascript:Close();"> 67 </form> 54 68 </body> 55 69 </html> modules/branches/2.10/endpointman/templates/freepbx/template_editor.html
r12939 r13276 107 107 {/loop} 108 108 <br /> 109 <?php echo _('You can also use certain variables in your configs')?>:<br />{noparse} 110 -"{$server.ip.1}" = <?php echo _('Server 1 IP')?><br /> 111 -"{$server.port.1}" = <?php echo _('Server 1 Port')?><br /> 112 -"{$mac}" = <?php echo _('Device\'s Mac Address')?><br /> 113 -"{$model}" = <?php echo _('Device\'s Model')?><br /> 114 -"{$ext.line.1}" = <?php echo _('Device\'s Default Extension (Line 1 or Master)')?><br /> 115 -"{$displayname.line.1}" = <?php echo _('Device\'s Description in FreePBX (Usually the Full Name)')?><br />{/noparse} 109 {include="variables"} 116 110 <br /> 117 111 {/if} … … 144 138 {/loop} 145 139 </select> 140 {elseif condition="$value.type == 'checkbox'"} 141 <label>{if condition="isset($value.tooltip)"}<a href="#" class="info">{$value.description}<span>{$value.tooltip}</span></a>{else}{$value.description}{/if}: <input type='checkbox' name='{$value.key}' id='{$value.key}' value='{$value.value}'></label> 146 142 {/if} 147 143 </td><td width="90%">
