Exemplo n.º 1
0
 /**
  * Prepare and then send the data that Provisioner expects, then take what provisioner gives us and do what it says
  * @param array $phone_info Everything from get_phone_info
  * @param bool  $reboot Reboot the Phone after write
  * @param bool  $write  Write out Directory structure.
  */
 function prepare_configs($phone_info, $reboot = TRUE, $write = TRUE)
 {
     $this->PROVISIONER_BASE = $this->PHONE_MODULES_PATH;
     //define('PROVISIONER_BASE', $this->PROVISIONER_BASE);
     if (file_exists($this->PHONE_MODULES_PATH . 'autoload.php')) {
         if (!class_exists('ProvisionerConfig')) {
             require $this->PHONE_MODULES_PATH . 'autoload.php';
         }
         //Load Provisioner
         $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone';
         $base_class = "endpoint_" . $phone_info['directory'] . '_base';
         $master_class = "endpoint_base";
         if (!class_exists($master_class)) {
             ProvisionerConfig::endpointsAutoload($master_class);
         }
         if (!class_exists($base_class)) {
             ProvisionerConfig::endpointsAutoload($base_class);
         }
         if (!class_exists($class)) {
             ProvisionerConfig::endpointsAutoload($class);
         }
         if (class_exists($class)) {
             $provisioner_lib = new $class();
             //Determine if global settings have been overridden
             if ($phone_info['template_id'] > 0) {
                 if (isset($phone_info['template_data_info']['global_settings_override'])) {
                     $settings = unserialize($phone_info['template_data_info']['global_settings_override']);
                 } else {
                     $settings['srvip'] = $this->configmod->get('srvip');
                     $settings['ntp'] = $this->configmod->get('ntp');
                     $settings['config_location'] = $this->configmod->get('config_location');
                     $settings['tz'] = $this->configmod->get('tz');
                 }
             } else {
                 if (isset($phone_info['global_settings_override'])) {
                     $settings = unserialize($phone_info['global_settings_override']);
                 } else {
                     $settings['srvip'] = $this->configmod->get('srvip');
                     $settings['ntp'] = $this->configmod->get('ntp');
                     $settings['config_location'] = $this->configmod->get('config_location');
                     $settings['tz'] = $this->configmod->get('tz');
                 }
             }
             //Tell the system who we are and were to find the data.
             $provisioner_lib->root_dir = $this->PHONE_MODULES_PATH;
             $provisioner_lib->engine = 'asterisk';
             $provisioner_lib->engine_location = $this->configmod->get('asterisk_location', 'asterisk');
             $provisioner_lib->system = 'unix';
             //have to because of versions less than php5.3
             $provisioner_lib->brand_name = $phone_info['directory'];
             $provisioner_lib->family_line = $phone_info['cfg_dir'];
             //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models)
             //This has to match word for word. I really need to fix this....
             $provisioner_lib->model = $phone_info['model'];
             //Timezone
             try {
                 $provisioner_lib->DateTimeZone = new \DateTimeZone($settings['tz']);
             } catch (Exception $e) {
                 $this->error['parse_configs'] = 'Error Returned From Timezone Library: ' . $e->getMessage();
                 return FALSE;
             }
             $temp = "";
             $template_data = unserialize($phone_info['template_data']);
             $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']);
             if ($phone_info['template_id'] > 0) {
                 $global_custom_cfg_data = unserialize($phone_info['template_data_info']['global_custom_cfg_data']);
                 //Provide alternate Configuration file instead of the one from the hard drive
                 if (!empty($phone_info['template_data_info']['config_files_override'])) {
                     $temp = unserialize($phone_info['template_data_info']['config_files_override']);
                     foreach ($temp as $list) {
                         $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " . $list;
                         //$res = sql($sql);
                         $res = sql($sql, 'getAll', DB_FETCHMODE_ASSOC);
                         if ($res->rowCount()) {
                             $data = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
                             $provisioner_lib->config_files_override[$data['original_name']] = $data['data'];
                         }
                     }
                 }
             } else {
                 $global_custom_cfg_data = unserialize($phone_info['global_custom_cfg_data']);
                 //Provide alternate Configuration file instead of the one from the hard drive
                 if (!empty($phone_info['config_files_override'])) {
                     $temp = unserialize($phone_info['config_files_override']);
                     foreach ($temp as $list) {
                         $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = " . $list;
                         //$res = sql($sql);
                         $res = sql($sql, 'getAll', DB_FETCHMODE_ASSOC);
                         if ($res->rowCount()) {
                             $data = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
                             $provisioner_lib->config_files_override[$data['original_name']] = $data['data'];
                         }
                     }
                 }
             }
             if (!empty($global_custom_cfg_data)) {
                 if (array_key_exists('data', $global_custom_cfg_data)) {
                     $global_custom_cfg_ari = $global_custom_cfg_data['ari'];
                     $global_custom_cfg_data = $global_custom_cfg_data['data'];
                 } else {
                     $global_custom_cfg_data = array();
                     $global_custom_cfg_ari = array();
                 }
             }
             $new_template_data = array();
             $line_ops = array();
             if (is_array($global_custom_cfg_data)) {
                 foreach ($global_custom_cfg_data as $key => $data) {
                     //TODO: clean up with reg-exp
                     $full_key = $key;
                     $key = explode('|', $key);
                     $count = count($key);
                     switch ($count) {
                         case 1:
                             if ($this->global_cfg['enable_ari'] == 1 and isset($global_custom_cfg_ari[$full_key]) and isset($global_user_cfg_data[$full_key])) {
                                 $new_template_data[$full_key] = $global_user_cfg_data[$full_key];
                             } else {
                                 $new_template_data[$full_key] = $global_custom_cfg_data[$full_key];
                             }
                             break;
                         case 2:
                             $breaks = explode('_', $key[1]);
                             if ($this->global_cfg['enable_ari'] == 1 and isset($global_custom_cfg_ari[$full_key]) and isset($global_user_cfg_data[$full_key])) {
                                 $new_template_data['loops'][$breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key];
                             } else {
                                 $new_template_data['loops'][$breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key];
                             }
                             break;
                         case 3:
                             if ($this->global_cfg['enable_ari'] == 1 and isset($global_custom_cfg_ari[$full_key]) and isset($global_user_cfg_data[$full_key])) {
                                 $line_ops[$key[1]][$key[2]] = $global_user_cfg_data[$full_key];
                             } else {
                                 $line_ops[$key[1]][$key[2]] = $global_custom_cfg_data[$full_key];
                             }
                             break;
                     }
                 }
             }
             if (!$write) {
                 $new_template_data['provision']['type'] = 'dynamic';
                 $new_template_data['provision']['protocol'] = 'http';
                 $new_template_data['provision']['path'] = rtrim($settings['srvip'] . dirname($_SERVER['REQUEST_URI']) . '/', '/');
                 $new_template_data['provision']['encryption'] = FALSE;
             } else {
                 $new_template_data['provision']['type'] = 'file';
                 $new_template_data['provision']['protocol'] = 'tftp';
                 $new_template_data['provision']['path'] = $settings['srvip'];
                 $new_template_data['provision']['encryption'] = FALSE;
             }
             $new_template_data['ntp'] = $settings['ntp'];
             //Overwrite all specific settings variables now
             if (!empty($phone_info['specific_settings'])) {
                 $specific_settings = unserialize($phone_info['specific_settings']);
                 $specific_settings = is_array($specific_settings) ? $specific_settings : array();
             } else {
                 $specific_settings = array();
             }
             //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create
             //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included
             //line 'global' will set variables that aren't line dependant
             $provisioner_lib->settings = $new_template_data;
             //Loop through Lines!
             $li = 0;
             foreach ($phone_info['line'] as $line) {
                 $line_options = is_array($line_ops[$line['line']]) ? $line_ops[$line['line']] : array();
                 $line_statics = array('line' => $line['line'], 'username' => $line['ext'], 'authname' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description'], 'server_host' => $settings['srvip'], 'server_port' => '5060', 'user_extension' => $line['user_extension']);
                 $provisioner_lib->settings['line'][$li] = array_merge($line_options, $line_statics);
                 $li++;
             }
             if (array_key_exists('data', $specific_settings)) {
                 foreach ($specific_settings['data'] as $key => $data) {
                     $default_exp = preg_split("/\\|/i", $key);
                     if (isset($default_exp[2])) {
                         //lineloop
                         $var = $default_exp[2];
                         $line = $default_exp[1];
                         $loc = $this->system->arraysearchrecursive($line, $provisioner_lib->settings['line'], 'line');
                         if ($loc !== FALSE) {
                             $k = $loc[0];
                             $provisioner_lib->settings['line'][$k][$var] = $data;
                         } else {
                             //Adding a new line-ish type options
                             if (isset($specific_settings['data']['line|' . $line . '|line_enabled'])) {
                                 $lastkey = array_pop(array_keys($provisioner_lib->settings['line']));
                                 $lastkey++;
                                 $provisioner_lib->settings['line'][$lastkey]['line'] = $line;
                                 $provisioner_lib->settings['line'][$lastkey][$var] = $data;
                             }
                         }
                     } else {
                         switch ($key) {
                             case "connection_type":
                                 $provisioner_lib->settings['network'][$key] = $data;
                                 break;
                             case "ip4_address":
                                 $provisioner_lib->settings['network']['ipv4'] = $data;
                                 break;
                             case "ip6_address":
                                 $provisioner_lib->settings['network']['ipv6'] = $data;
                                 break;
                             case "subnet_mask":
                                 $provisioner_lib->settings['network']['subnet'] = $data;
                                 break;
                             case "gateway_address":
                                 $provisioner_lib->settings['network']['gateway'] = $data;
                                 break;
                             case "primary_dns":
                                 $provisioner_lib->settings['network'][$key] = $data;
                                 break;
                             default:
                                 $provisioner_lib->settings[$key] = $data;
                                 break;
                         }
                     }
                 }
             }
             $provisioner_lib->settings['mac'] = $phone_info['mac'];
             $provisioner_lib->mac = $phone_info['mac'];
             //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed
             //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
             $provisioner_lib->processor_info = "EndPoint Manager Version " . $this->global_cfg['version'];
             // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is
             //Start timer
             $time_start = microtime(true);
             $provisioner_lib->debug = TRUE;
             try {
                 $returned_data = $provisioner_lib->generate_all_files();
             } catch (Exception $e) {
                 $this->error['prepare_configs'] = 'Error Returned From Provisioner Library: ' . $e->getMessage();
                 return FALSE;
             }
             //print_r($provisioner_lib->debug_return);
             //End timer
             $time_end = microtime(true);
             $time = $time_end - $time_start;
             if ($time > 360) {
                 $this->error['generate_time'] = "It took an awfully long time to generate configs...(" . round($time, 2) . " seconds)";
             }
             if ($write) {
                 $this->write_configs($provisioner_lib, $reboot, $settings['config_location'], $phone_info, $returned_data);
             } else {
                 return $returned_data;
             }
             return TRUE;
         } else {
             $this->error['parse_configs'] = "Can't Load \"" . $class . "\" Class!";
             return FALSE;
         }
     } else {
         $this->error['parse_configs'] = "Can't Load the Autoloader!";
         return FALSE;
     }
 }
 public function epm_advanced_poce_select()
 {
     if (!isset($_REQUEST['product_select'])) {
         $retarr = array("status" => false, "message" => _("No send Product Select!"));
     } elseif (!is_numeric($_REQUEST['product_select'])) {
         $retarr = array("status" => false, "message" => _("Product Select send is not number!"));
     } elseif ($_REQUEST['product_select'] < 0) {
         $retarr = array("status" => false, "message" => _("Product Select send is number not valid!"));
     } else {
         $dget['product_select'] = $_REQUEST['product_select'];
         $sql = 'SELECT * FROM `endpointman_product_list` WHERE `hidden` = 0 AND `id` = ' . $dget['product_select'];
         $product_select_info = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
         $sql = "SELECT cfg_dir,directory,config_files FROM endpointman_product_list,endpointman_brand_list WHERE endpointman_product_list.brand = endpointman_brand_list.id AND endpointman_product_list.id ='" . $dget['product_select'] . "'";
         $row = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
         $config_files = explode(",", $row['config_files']);
         $i = 0;
         if (count($config_files)) {
             foreach ($config_files as $config_files_data) {
                 //$file_list[$i]['value'] = $i;
                 $file_list[$i]['value'] = $dget['product_select'];
                 $file_list[$i]['text'] = $config_files_data;
                 $i++;
             }
         } else {
             $file_list = NULL;
         }
         $sql = "SELECT * FROM endpointman_custom_configs WHERE product_id = '" . $dget['product_select'] . "'";
         $data = sql($sql, 'getAll', DB_FETCHMODE_ASSOC);
         $i = 0;
         if (count($data)) {
             //$data = sql($sql, 'getAll', DB_FETCHMODE_ASSOC);
             foreach ($data as $row2) {
                 $sql_file_list[$i]['value'] = $row2['id'];
                 $sql_file_list[$i]['text'] = $row2['name'];
                 $sql_file_list[$i]['ref'] = $row2['original_name'];
                 $i++;
             }
         } else {
             $sql_file_list = NULL;
         }
         require_once $this->PHONE_MODULES_PATH . 'setup.php';
         $class = "endpoint_" . $row['directory'] . "_" . $row['cfg_dir'] . '_phone';
         $base_class = "endpoint_" . $row['directory'] . '_base';
         $master_class = "endpoint_base";
         /*********************************************************************************
          *** Quick Fix for FreePBX Distro
          *** I seriously want to figure out why ONLY the FreePBX Distro can't do autoloads.
          **********************************************************************************/
         if (!class_exists($master_class)) {
             ProvisionerConfig::endpointsAutoload($master_class);
         }
         if (!class_exists($base_class)) {
             ProvisionerConfig::endpointsAutoload($base_class);
         }
         if (!class_exists($class)) {
             ProvisionerConfig::endpointsAutoload($class);
         }
         //end quick fix
         $phone_config = new $class();
         //TODO: remove
         $template_file_list[0]['value'] = "template_data_custom.xml";
         $template_file_list[0]['text'] = "template_data_custom.xml";
         $sql = "SELECT id, model FROM endpointman_model_list WHERE product_id = '" . $dget['product_select'] . "' AND enabled = 1 AND hidden = 0";
         $data = sql($sql, 'getAll', DB_FETCHMODE_ASSOC);
         $i = 1;
         foreach ($data as $list) {
             //$template_file_list[$i]['value'] = "template_data_" . $list['model'] . "_custom.xml";
             $template_file_list[$i]['value'] = $list['id'];
             $template_file_list[$i]['text'] = "template_data_" . $list['model'] . "_custom.xml";
         }
         $retarr = array("status" => true, "message" => "OK", "product_select" => $dget['product_select'], "product_select_info" => $product_select_info, "file_list" => $file_list, "template_file_list" => $template_file_list, "sql_file_list" => $sql_file_list);
         unset($dget);
     }
     return $retarr;
 }
Exemplo n.º 3
0
     }
     $phone_info = $endpoint->get_phone_info($row['id']);
     $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone';
     $base_class = "endpoint_" . $phone_info['directory'] . '_base';
     $master_class = "endpoint_base";
     /**Fix for FreePBX Distro
      * I seriously want to figure out why ONLY the FreePBX Distro can't do autoloads.
      **/
     if (!class_exists($master_class)) {
         ProvisionerConfig::endpointsAutoload($master_class);
     }
     if (!class_exists($base_class)) {
         ProvisionerConfig::endpointsAutoload($base_class);
     }
     if (!class_exists($class)) {
         ProvisionerConfig::endpointsAutoload($class);
     }
     //end quick fix
     $provisioner_lib = new $class();
     $provisioner_lib->root_dir = PHONE_MODULES_PATH;
     $provisioner_lib->engine = 'asterisk';
     $provisioner_lib->engine_location = !empty($endpoint->global_cfg['asterisk_location']) ? $endpoint->global_cfg['asterisk_location'] : 'asterisk';
     $provisioner_lib->system = 'unix';
     //have to because of versions less than php5.3
     $provisioner_lib->brand_name = $phone_info['directory'];
     $provisioner_lib->family_line = $phone_info['cfg_dir'];
     $provisioner_lib->settings['line'][0] = array('username' => $phone_info['line'][1]['ext'], 'authname' => $phone_info['line'][1]['ext']);
     $provisioner_lib->reboot();
     unset($provisioner_lib);
 }
 $endpoint->message['page:devices_manager'] = "Rebooted all " . $phone_info['name'] . " phones";