| 60 | | global $amp_conf,$global_cfg, $endpoint_db; $type; |
|---|
| 61 | | //attached to the end of every link so we can flow through FreePBX |
|---|
| 62 | | //This is really hacky but I have to do it when people have different directories instead of admin |
|---|
| 63 | | if((!array_key_exists('PHONE_MODULES_PATH',$amp_conf)) AND (dirname($_SERVER['SCRIPT_NAME']) != "/recordings")) { |
|---|
| 64 | | //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 |
|---|
| 65 | | define("PHONE_MODULES_PATH", dirname($_SERVER["SCRIPT_FILENAME"])."/modules/_ep_phone_modules/"); |
|---|
| 66 | | |
|---|
| 67 | | //Get local path information |
|---|
| 68 | | define("WEB_PATH", dirname($_SERVER['SCRIPT_NAME'])."/modules/endpointman/"); |
|---|
| 69 | | define("LOCAL_PATH", dirname($_SERVER["SCRIPT_FILENAME"])."/modules/endpointman/"); |
|---|
| 70 | | |
|---|
| 71 | | //have to hack around freepbx.... |
|---|
| 72 | | $amp_conf['PHONE_MODULES_PATH'] = PHONE_MODULES_PATH; |
|---|
| 73 | | $amp_conf['LOCAL_ENDPOINT_PATH'] = LOCAL_PATH; |
|---|
| 74 | | } elseif(dirname($_SERVER['SCRIPT_NAME']) == "/recordings") { |
|---|
| 75 | | //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 |
|---|
| 76 | | define("PHONE_MODULES_PATH", $amp_conf['AMPWEBROOT']."/admin/modules/_ep_phone_modules/"); |
|---|
| 77 | | |
|---|
| 78 | | //Get local path information |
|---|
| 79 | | define("WEB_PATH", "/admin/modules/endpointman/"); |
|---|
| 80 | | define("LOCAL_PATH", $amp_conf['AMPWEBROOT']."/admin/modules/endpointman/"); |
|---|
| 81 | | |
|---|
| 82 | | //have to hack around freepbx.... |
|---|
| 83 | | $amp_conf['PHONE_MODULES_PATH'] = PHONE_MODULES_PATH; |
|---|
| 84 | | $amp_conf['LOCAL_ENDPOINT_PATH'] = LOCAL_PATH; |
|---|
| 85 | | } else { |
|---|
| 86 | | define("PHONE_MODULES_PATH", $amp_conf['PHONE_MODULES_PATH']); |
|---|
| 87 | | define("LOCAL_PATH", $amp_conf['LOCAL_ENDPOINT_PATH']); |
|---|
| 88 | | } |
|---|
| 89 | | |
|---|
| 90 | | //Start Database Connections and keep them running this whoooooooole time |
|---|
| 91 | | $this->dblogin(); |
|---|
| 92 | | |
|---|
| 93 | | //Set Global Variables |
|---|
| 94 | | if($this->table_exists("endpointman_global_vars")) { |
|---|
| 95 | | $result = mysql_query("SELECT var_name, value FROM endpointman_global_vars"); |
|---|
| 96 | | while ($row=mysql_fetch_array($result)) { |
|---|
| 97 | | $global_cfg[$row['var_name']] = $row['value']; |
|---|
| 98 | | } |
|---|
| 99 | | |
|---|
| 100 | | define("UPDATE_PATH", $global_cfg['update_server']); |
|---|
| 101 | | define("VER", $global_cfg['version']); |
|---|
| 102 | | } |
|---|
| 103 | | |
|---|
| 104 | | //Define error reporting |
|---|
| 105 | | if($global_cfg['debug']) { |
|---|
| 106 | | error_reporting(E_ALL); |
|---|
| 107 | | ini_set('display_errors', 1); |
|---|
| 108 | | } else { |
|---|
| 109 | | ini_set('display_errors', 0); |
|---|
| 110 | | } |
|---|
| 111 | | //include the local template class |
|---|
| 112 | | include LOCAL_PATH."includes/rain.tpl.class.php"; |
|---|
| 113 | | } |
|---|
| 114 | | |
|---|
| 115 | | function add_freepbx_notification($id, $type, $display_text, $text, $link) { |
|---|
| 116 | | $sql = "INSERT INTO notifications (module, id, level, display_text, link, candelete, timestamp, extended_text) VALUES ('endpointman', '".$id."', '500', '".$display_text."', '".$link."', '1', '".time()."', '".$text."')"; |
|---|
| 117 | | mysql_query($sql); |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | //Send this function an ID from the mac devices list table and you'll get all the information we have on that particular phone |
|---|
| 121 | | function get_phone_info($mac_id=NULL) { |
|---|
| 122 | | //You could screw up a phone if the mac_id is blank |
|---|
| 123 | | if (!isset($mac_id)) { |
|---|
| 124 | | die('Can\'t get phone info!'); |
|---|
| 125 | | } |
|---|
| 126 | | $sql = "SELECT id,mac,model FROM endpointman_mac_list WHERE model > 0 AND id =".$mac_id; |
|---|
| 127 | | $result=mysql_query($sql); |
|---|
| 128 | | if(mysql_num_rows($result)) { |
|---|
| 129 | | //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, |
|---|
| 130 | | $result=mysql_query("SELECT endpointman_mac_list.config_files_override, endpointman_mac_list.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.ext, endpointman_mac_list.custom_cfg_template, endpointman_mac_list.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_product_list.xml_data, endpointman_product_list.cfg_data, endpointman_product_list.installed, endpointman_model_list.enabled, users.name as description, sip.data as secret FROM endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_product_list, sip, users WHERE endpointman_mac_list.id = ".$mac_id." AND 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.ext = sip.id AND sip.keyword = 'secret' AND endpointman_mac_list.ext = users.extension"); |
|---|
| 131 | | $phone_info=mysql_fetch_array($result); |
|---|
| 132 | | |
|---|
| 133 | | //If there is a template associated with this phone then pull that information and put it into the array |
|---|
| 134 | | if ($phone_info['custom_cfg_template'] > 0) { |
|---|
| 135 | | $result=mysql_query("SELECT name, custom_cfg_data, config_files_override FROM endpointman_template_list WHERE id = ".$phone_info['custom_cfg_template']); |
|---|
| 136 | | $phone_info['template_data'] = mysql_fetch_array($result); |
|---|
| 137 | | |
|---|
| 138 | | } |
|---|
| 139 | | } else { |
|---|
| 140 | | //Phone is unknown, we need to display this to the end user so that they can make corrections |
|---|
| 141 | | $row=mysql_fetch_array($result); |
|---|
| 142 | | $phone_info['id'] = $mac_id; |
|---|
| 143 | | $phone_info['model_id'] = 0; |
|---|
| 144 | | $phone_info['brand_id'] = 0; |
|---|
| 145 | | $phone_info['ext'] = $row['ext']; |
|---|
| 146 | | $phone_info['mac'] = $row['mac']; |
|---|
| 147 | | $phone_info['name'] = 'Unknown'; |
|---|
| 148 | | } |
|---|
| 149 | | return $phone_info; |
|---|
| 150 | | } |
|---|
| 151 | | |
|---|
| 152 | | //Open configuration files and return the data from the file |
|---|
| 153 | | function open_config_file($infile,$phone_info,$config_files_override){ |
|---|
| 154 | | //Sometimes periods turn to underscores when periods are submitted through a form as a variable, we need to account for this |
|---|
| 155 | | $key=str_replace('.', "_",$infile); |
|---|
| 156 | | //from phone info open the required file for reading |
|---|
| 157 | | $infile=PHONE_MODULES_PATH.$phone_info['directory']."/".$phone_info['cfg_dir']."/".$infile; |
|---|
| 158 | | //if there is no configuration file over ridding the default then load up $contents with the file's information, where $key is the name of the default configuration file |
|---|
| 159 | | if(!isset($config_files_override[$key])) { |
|---|
| 160 | | //always use 'rb' says php.net |
|---|
| 161 | | $handle = fopen($infile, "rb"); |
|---|
| 162 | | $contents = fread($handle, filesize($infile)); |
|---|
| 163 | | fclose($handle); |
|---|
| 164 | | } else { |
|---|
| 165 | | //$config_files_override has data in it so that means we have a configuration file over ride, lets pull the text out of the database |
|---|
| 166 | | $sql = 'SELECT data FROM endpointman_custom_configs WHERE id = ' . $config_files_override[$key]; |
|---|
| 167 | | $result = mysql_query($sql); |
|---|
| 168 | | //$config_files_override said we had a file in the database but mySQL couldn't find anything so we default back to the local file |
|---|
| 169 | | //This usually happens when the user deletes a custome configuration file but doesn't update their templates |
|---|
| 170 | | if(mysql_num_rows($result) == 0) { |
|---|
| 171 | | $handle = fopen($infile, "rb"); |
|---|
| 172 | | $contents = fread($handle, filesize($infile)); |
|---|
| 173 | | fclose($handle); |
|---|
| 174 | | } else { |
|---|
| 175 | | $data = mysql_fetch_assoc($result); |
|---|
| 176 | | $contents = $data['data']; |
|---|
| 177 | | } |
|---|
| 178 | | } |
|---|
| 179 | | return($contents); |
|---|
| 180 | | } |
|---|
| 181 | | |
|---|
| 182 | | //Write configuration files |
|---|
| 183 | | function write_config_file($outfile,$phone_info,$contents,$custom_cfg_data){ |
|---|
| 184 | | global $global_cfg; |
|---|
| 185 | | //Get End User (through ARI) set variables |
|---|
| 186 | | $user_cfg_data = unserialize($phone_info['user_cfg_data']); |
|---|
| 187 | | |
|---|
| 188 | | //Determine if ARI is enabled, if not ignore any values present in $user_cfg_data, keep unknown variables, this is what 'TRUE' means |
|---|
| 189 | | if(($global_cfg['enable_ari']) AND is_array($user_cfg_data)){ |
|---|
| 190 | | $contents = $this->parse_config_values($user_cfg_data,$contents,TRUE,$phone_info); |
|---|
| 191 | | } |
|---|
| 192 | | |
|---|
| 193 | | //Parse normal config values and set all unknown variables in the file to nothing (Blanking them out), this is what 'FALSE' means |
|---|
| 194 | | $contents = $this->parse_config_values($custom_cfg_data,$contents,FALSE,$phone_info); |
|---|
| 195 | | |
|---|
| 196 | | $outfile=$global_cfg['config_location'].$outfile; |
|---|
| 197 | | $wfh=fopen($outfile,'w'); |
|---|
| 198 | | fwrite($wfh,$contents); |
|---|
| 199 | | fclose($wfh); |
|---|
| 200 | | } |
|---|
| 201 | | |
|---|
| 202 | | /* |
|---|
| 203 | | -Send this function the contents of a text file to $file_contents and then send an array to $custom_cfg_data |
|---|
| 204 | | The key of the array is the name of the variable in the text file between "{$" and "}" |
|---|
| 205 | | Then return the contents of the file with the values merged into it |
|---|
| 206 | | -The $keep_unknown variable tells this function to ignore(TRUE) or blank out(FALSE) variables that it finds in $file_contents but can not find in $variables_array |
|---|
| 207 | | */ |
|---|
| 208 | | function parse_config_values($variables_array,$file_contents,$keep_unknown=FALSE, $phone_info=NULL) { |
|---|
| 209 | | global $global_cfg; |
|---|
| 210 | | //Find all matched variables in the text file between "{$" and "}" |
|---|
| 211 | | preg_match_all('/[{\$](.*?)[}]/i',$file_contents,$match); |
|---|
| 212 | | //Result without brackets (but with the $ variable identifier) |
|---|
| 213 | | $no_brackets = array_values(array_unique($match[1])); |
|---|
| 214 | | //Result with brackets |
|---|
| 215 | | $brackets = array_values(array_unique($match[0])); |
|---|
| 216 | | //Count how many variables were found in the file |
|---|
| 217 | | $count = count($brackets); |
|---|
| 218 | | $cfg_data = unserialize($phone_info['cfg_data']); |
|---|
| 219 | | |
|---|
| 220 | | //loop though each variable found in the text file |
|---|
| 221 | | for($i=0;$i<$count;$i++) { |
|---|
| 222 | | $key = str_replace('$','',$no_brackets[$i]); |
|---|
| 223 | | //If the variable we found in the text file exists in the variables array then replace the variable in the text file with the value under our key |
|---|
| 224 | | if (isset($variables_array[$key])) { |
|---|
| 225 | | $variables_array[$key]['value'] = htmlspecialchars($variables_array[$key]['value']); |
|---|
| 226 | | //Variables the user defined in their custom configs |
|---|
| 227 | | if(isset($phone_info)) { |
|---|
| 228 | | $variables_array[$key]['value']=str_replace('{$srvip}', $global_cfg['srvip'], $variables_array[$key]['value']); |
|---|
| 229 | | $variables_array[$key]['value']=str_replace('{$mac}', $phone_info['mac'], $variables_array[$key]['value']); |
|---|
| 230 | | $variables_array[$key]['value']=str_replace('{$ext}', $phone_info['ext'], $variables_array[$key]['value']); |
|---|
| 231 | | $variables_array[$key]['value']=str_replace('{$displayname}', $phone_info['description'], $variables_array[$key]['value']); |
|---|
| 232 | | } |
|---|
| 233 | | $file_contents=str_replace($brackets[$i], $variables_array[$key]['value'],$file_contents); |
|---|
| 234 | | } else { |
|---|
| 235 | | if(!$keep_unknown) { |
|---|
| 236 | | //read default template values here, blank unknowns or arrays (which are blanks anyways) |
|---|
| 237 | | $key1 = $this->arraysearchrecursive($no_brackets[$i], $cfg_data, 'variable'); |
|---|
| 238 | | if(isset($phone_info)) { |
|---|
| 239 | | $file_contents=str_replace('{$srvip}', $global_cfg['srvip'], $file_contents); |
|---|
| 240 | | $file_contents=str_replace('{$mac}', $phone_info['mac'], $file_contents); |
|---|
| 241 | | $file_contents=str_replace('{$ext}', $phone_info['ext'], $file_contents); |
|---|
| 242 | | $file_contents=str_replace('{$displayname}', $phone_info['description'], $file_contents); |
|---|
| 243 | | } |
|---|
| 244 | | if((isset($cfg_data[$key1[0]]['default_value'])) AND (!is_array($cfg_data[$key1[0]]['default_value']))) { |
|---|
| 245 | | $file_contents=str_replace($brackets[$i], $cfg_data[$key1[0]]['default_value'],$file_contents); |
|---|
| 246 | | } else { |
|---|
| 247 | | $file_contents=str_replace($brackets[$i], "",$file_contents); |
|---|
| 248 | | } |
|---|
| 249 | | } |
|---|
| 250 | | } |
|---|
| 251 | | } |
|---|
| 252 | | |
|---|
| 253 | | if($global_cfg['debug']) { |
|---|
| 254 | | global $debug; |
|---|
| 255 | | $list = print_r($brackets, TRUE); |
|---|
| 256 | | $debug .= "\nVariables found in file:\n".$list; |
|---|
| 257 | | } |
|---|
| 258 | | |
|---|
| 259 | | return $file_contents; |
|---|
| 260 | | } |
|---|
| 261 | | |
|---|
| 262 | | //Custom Means specific to that MAC |
|---|
| 263 | | //id is either the mac ID (not address) or the template ID |
|---|
| 264 | | function edit_template_display($id, $custom) { |
|---|
| 265 | | global $global_cfg,$debug; |
|---|
| 266 | | $alt_configs = NULL; |
|---|
| 267 | | //Determine if we are dealing with a general template or a specific [for that phone only] template (custom =0 means general) |
|---|
| 268 | | if($custom == 0) { |
|---|
| 269 | | $sql = "SELECT endpointman_product_list.config_files, endpointman_template_list.*, endpointman_product_list.id as product_id, endpointman_product_list.long_name, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_template_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_template_list.id = ".$id." AND endpointman_template_list.product_id = endpointman_product_list.id AND endpointman_product_list.brand = endpointman_brand_list.id"; |
|---|
| 270 | | } else { |
|---|
| 271 | | $sql = "SELECT endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_product_list.id as product_id, endpointman_product_list.long_name, 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"; |
|---|
| 272 | | } |
|---|
| 273 | | $result=mysql_query($sql); |
|---|
| 274 | | $row=mysql_fetch_array($result); |
|---|
| 275 | | |
|---|
| 276 | | //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 |
|---|
| 277 | | if(!$this->sync_product($row['product_id'])) { |
|---|
| 278 | | die("unable to sync local template files". $custom); |
|---|
| 279 | | } |
|---|
| 280 | | |
|---|
| 281 | | //Get default template config data from the database for this product |
|---|
| 282 | | $sql = "SELECT cfg_data FROM endpointman_product_list WHERE id=". $row['product_id']; |
|---|
| 283 | | $result=mysql_query($sql); |
|---|
| 284 | | $product_row=mysql_fetch_array($result); |
|---|
| 285 | | |
|---|
| 286 | | //inset it into our usable row |
|---|
| 287 | | $row['cfg_data'] = $product_row['cfg_data']; |
|---|
| 288 | | |
|---|
| 289 | | $brand_name = $row['directory']; |
|---|
| 290 | | $model_name = $row['cfg_dir']; |
|---|
| 291 | | $tpl = new RainTPL( LOCAL_PATH.'templates' ); |
|---|
| 292 | | $tpl->assign("template_editor_display", 1); |
|---|
| 293 | | |
|---|
| 294 | | echo $tpl->draw( 'global_header' ); |
|---|
| 295 | | //Let the template system know if we are working with a general template or a specific [for that phone only] template |
|---|
| 296 | | $tpl->assign("custom", $custom); |
|---|
| 297 | | if($custom) |
|---|
| 298 | | { |
|---|
| 299 | | $tpl->assign("ext", $row['ext']); |
|---|
| 300 | | } else { |
|---|
| 301 | | $tpl->assign("template_name", $row['name']); |
|---|
| 302 | | } |
|---|
| 303 | | $tpl->assign("model", $row['long_name']); |
|---|
| 304 | | |
|---|
| 305 | | //Start the display of the html file in the product folder |
|---|
| 306 | | if($row['config_files_override'] == "") { |
|---|
| 307 | | $config_files_saved = ""; |
|---|
| 308 | | } else { |
|---|
| 309 | | $config_files_saved = unserialize($row['config_files_override']); |
|---|
| 310 | | } |
|---|
| 311 | | $config_files = explode(",",$row['config_files']); |
|---|
| 312 | | $i = 0; |
|---|
| 313 | | $alt = 0; |
|---|
| 314 | | while($i < count($config_files)) { |
|---|
| 315 | | $sql = "SELECT * FROM endpointman_custom_configs WHERE product_id = ".$row['product_id']." AND original_name = '".$config_files[$i]."'"; |
|---|
| 316 | | $result = mysql_query($sql); |
|---|
| 317 | | if(mysql_num_rows($result) > 0) { |
|---|
| 318 | | $alt_configs .= $config_files[$i]; |
|---|
| 319 | | $alt_configs .= '<select name="'.$config_files[$i].'">'; |
|---|
| 320 | | $alt_configs .= '<option value="0">'.$config_files[$i].' (Original)</option>'; |
|---|
| 321 | | $config_files[$i] = str_replace(".","_",$config_files[$i]); |
|---|
| 322 | | while ($ccf=mysql_fetch_array($result)) { |
|---|
| 323 | | $alt_configs .= '<option value="'.$ccf['id'].'" '; |
|---|
| 324 | | $cf_key = $config_files[$i]; |
|---|
| 325 | | if((is_array($config_files_saved)) AND ($config_files_saved[$cf_key] == $ccf['id'])) { |
|---|
| 326 | | $alt_configs .= 'selected'; |
|---|
| 327 | | } |
|---|
| 328 | | $alt_configs .= '>'.$ccf['name'].'</option>'; |
|---|
| 329 | | } |
|---|
| 330 | | $alt_configs .= "</select>"; |
|---|
| 331 | | $alt = 1; |
|---|
| 332 | | } |
|---|
| 333 | | $i++; |
|---|
| 334 | | } |
|---|
| 335 | | $tpl->assign("alt_configs", $alt_configs); |
|---|
| 336 | | $tpl->assign("alt", $alt); |
|---|
| 337 | | |
|---|
| 338 | | if($row['cfg_data'] != "") { |
|---|
| 339 | | $out = $this->generate_gui_html($row['cfg_data'],$row['custom_cfg_data'],TRUE); |
|---|
| 340 | | } else { |
|---|
| 341 | | echo "No Template Data has been defined for this Product<br />"; |
|---|
| 342 | | } |
|---|
| 343 | | |
|---|
| 344 | | $tpl->assign("template_editor", $out); |
|---|
| 345 | | $tpl->assign("hidden_id", $row['id']); |
|---|
| 346 | | $tpl->assign("hidden_custom", $custom); |
|---|
| 347 | | echo $tpl->draw( 'template_editor' ); |
|---|
| 348 | | |
|---|
| 349 | | $tpl->assign("debug", $debug); |
|---|
| 350 | | |
|---|
| 351 | | } |
|---|
| 352 | | |
|---|
| 353 | | function generate_gui_html($cfg_data,$custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL) { |
|---|
| 354 | | global $global_cfg; |
|---|
| 355 | | //take the data out of the database and turn it back into an array for use |
|---|
| 356 | | $cfg_data = unserialize($cfg_data); |
|---|
| 357 | | $count = count($cfg_data); |
|---|
| 358 | | |
|---|
| 359 | | //Check to see if there is a custom template for this phone already listed in the endpointman_mac_list database |
|---|
| 360 | | if (isset($custom_cfg_data)) { |
|---|
| 361 | | $custom_cfg_data = unserialize($custom_cfg_data); |
|---|
| 362 | | } else { |
|---|
| 363 | | //No custom template so let's pull the default values for this model into the custom_cfg_data array and populate it from there so that we won't have to make two completely different functions below |
|---|
| 364 | | for($i=0;$i<$count;$i++) { |
|---|
| 365 | | $key_default = str_replace('$','',$cfg_data[$i]['variable']); |
|---|
| 366 | | if(!is_array($cfg_data[$i]['default_value'])) { |
|---|
| 367 | | $custom_cfg_data[$key_default]['value'] = $cfg_data[$i]['default_value']; |
|---|
| 368 | | |
|---|
| 369 | | } |
|---|
| 370 | | } |
|---|
| 371 | | } |
|---|
| 372 | | if(isset($user_cfg_data)) { |
|---|
| 373 | | $user_cfg_data = unserialize($user_cfg_data); |
|---|
| 374 | | } |
|---|
| 375 | | |
|---|
| 376 | | $template_variables_array = array(); |
|---|
| 377 | | |
|---|
| 378 | | $group_count = 0; |
|---|
| 379 | | //Fill the html form data with values from either the database or the default values to display to the end user |
|---|
| 380 | | for($i=0;$i<$count;$i++) { |
|---|
| 381 | | if(array_key_exists('variable',$cfg_data[$i])) { |
|---|
| 382 | | $key = str_replace('$','',$cfg_data[$i]['variable']); |
|---|
| 383 | | } else { |
|---|
| 384 | | $key = ""; |
|---|
| 385 | | } |
|---|
| 386 | | if(($admin) OR (isset($custom_cfg_data[$key]['ari']))) { |
|---|
| 387 | | //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! |
|---|
| 388 | | if(!isset($custom_cfg_data[$key]['value'])) { |
|---|
| 389 | | //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 |
|---|
| 390 | | if((array_key_exists('default_value',$cfg_data[$i])) AND (is_array($cfg_data[$i]['default_value']))) { |
|---|
| 391 | | $custom_cfg_data[$key]['value'] = ""; |
|---|
| 392 | | } elseif((array_key_exists('default_value',$cfg_data[$i])) AND (!is_array($cfg_data[$i]['default_value']))) { |
|---|
| 393 | | $custom_cfg_data[$key]['value'] = $cfg_data[$i]['default_value']; |
|---|
| 394 | | } |
|---|
| 395 | | } |
|---|
| 396 | | if ($cfg_data[$i]['type'] == "group") { |
|---|
| 397 | | $group_count++; |
|---|
| 398 | | $template_variables_array[$group_count]['title'] = $cfg_data[$i]['description']; |
|---|
| 399 | | $variables_count = 0; |
|---|
| 400 | | } elseif ($cfg_data[$i]['type'] == "input") { |
|---|
| 401 | | if((!$admin) && (isset($user_cfg_data[$key]['value']))) { |
|---|
| 402 | | $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; |
|---|
| 403 | | } |
|---|
| 404 | | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "input"; |
|---|
| 405 | | $template_variables_array[$group_count]['data'][$variables_count]['key'] = $key; |
|---|
| 406 | | $template_variables_array[$group_count]['data'][$variables_count]['value'] = $custom_cfg_data[$key]['value']; |
|---|
| 407 | | $template_variables_array[$group_count]['data'][$variables_count]['description'] = $cfg_data[$i]['description']; |
|---|
| 408 | | } elseif ($cfg_data[$i]['type'] == "radio") { |
|---|
| 409 | | if((!$admin) && (isset($user_cfg_data[$key]['value']))) { |
|---|
| 410 | | $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; |
|---|
| 411 | | } |
|---|
| 412 | | $num = $custom_cfg_data[$key]['value']; |
|---|
| 413 | | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "radio"; |
|---|
| 414 | | $template_variables_array[$group_count]['data'][$variables_count]['key'] = $key; |
|---|
| 415 | | $template_variables_array[$group_count]['data'][$variables_count]['description'] = $cfg_data[$i]['description']; |
|---|
| 416 | | $z = 0; |
|---|
| 417 | | while($z < count($cfg_data[$i]['data'])) { |
|---|
| 418 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['key'] = $key; |
|---|
| 419 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['value'] = $cfg_data[$i]['data'][$z]['value']; |
|---|
| 420 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['description'] = $cfg_data[$i]['data'][$z]['text']; |
|---|
| 421 | | if ($cfg_data[$i]['data'][$z]['value'] == $num) { |
|---|
| 422 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['checked'] = 'checked'; |
|---|
| 423 | | } |
|---|
| 424 | | $z++; |
|---|
| 425 | | } |
|---|
| 426 | | } elseif ($cfg_data[$i]['type'] == "list") { |
|---|
| 427 | | if((!$admin) && (isset($user_cfg_data[$key]['value']))) { |
|---|
| 428 | | $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; |
|---|
| 429 | | } |
|---|
| 430 | | $num = $custom_cfg_data[$key]['value']; |
|---|
| 431 | | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "list"; |
|---|
| 432 | | $template_variables_array[$group_count]['data'][$variables_count]['key'] = $key; |
|---|
| 433 | | $template_variables_array[$group_count]['data'][$variables_count]['description'] = $cfg_data[$i]['description']; |
|---|
| 434 | | $z = 0; |
|---|
| 435 | | while($z < count($cfg_data[$i]['data'])) { |
|---|
| 436 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['value'] = $cfg_data[$i]['data'][$z]['value']; |
|---|
| 437 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['description'] = $cfg_data[$i]['data'][$z]['text']; |
|---|
| 438 | | if ($cfg_data[$i]['data'][$z]['value'] == $num) { |
|---|
| 439 | | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['selected'] = 'selected'; |
|---|
| 440 | | } |
|---|
| 441 | | $z++; |
|---|
| 442 | | } |
|---|
| 443 | | } elseif ($cfg_data[$i]['type'] == "break") { |
|---|
| 444 | | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; |
|---|
| 445 | | } |
|---|
| 446 | | if(($global_cfg['enable_ari']) AND ($admin) AND ($cfg_data[$i]['type'] != "break") AND ($cfg_data[$i]['type'] != "group")) { |
|---|
| 447 | | $template_variables_array[$group_count]['data'][$variables_count]['aried'] = 1; |
|---|
| 448 | | $template_variables_array[$group_count]['data'][$variables_count]['ari']['key'] = $key; |
|---|
| 449 | | if(isset($custom_cfg_data[$key]['ari'])) { |
|---|
| 450 | | $template_variables_array[$group_count]['data'][$variables_count]['ari']['checked'] = "checked"; |
|---|
| 451 | | } |
|---|
| 452 | | } |
|---|
| 453 | | $variables_count++; |
|---|
| 454 | | } |
|---|
| 455 | | } |
|---|
| 456 | | return($template_variables_array); |
|---|
| 457 | | } |
|---|
| 458 | | |
|---|
| 459 | | function save_template($id, $custom, $variables) { |
|---|
| 460 | | //Custom Means specific to that MAC |
|---|
| 461 | | if($custom == "0") { |
|---|
| 462 | | $sql = "SELECT endpointman_product_list.config_files, endpointman_template_list.*, endpointman_product_list.long_name, endpointman_product_list.cfg_data, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_template_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_template_list.id = ".$id." AND endpointman_template_list.product_id = endpointman_product_list.id AND endpointman_product_list.brand = endpointman_brand_list.id"; |
|---|
| 463 | | } else { |
|---|
| 464 | | $sql = "SELECT endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_product_list.id as product_id, endpointman_product_list.long_name, endpointman_product_list.cfg_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"; |
|---|
| 465 | | } |
|---|
| 466 | | //Load template data |
|---|
| 467 | | $result=mysql_query($sql); |
|---|
| 468 | | $row=mysql_fetch_array($result); |
|---|
| 469 | | $cfg_data = unserialize($row['cfg_data']); |
|---|
| 470 | | $count = count($cfg_data); |
|---|
| 471 | | for($i=0;$i<$count;$i++) { |
|---|
| 472 | | if(array_key_exists('variable',$cfg_data[$i])) { |
|---|
| 473 | | $temping = str_replace('$','',$cfg_data[$i]['variable']); |
|---|
| 474 | | $temping_ari = "ari_" . $temping; |
|---|
| 475 | | if(array_key_exists($temping, $_REQUEST)) { |
|---|
| 476 | | $custom_cfg_data[$temping]['value'] = $_REQUEST[$temping]; |
|---|
| 477 | | if(array_key_exists($temping_ari, $_REQUEST)) { |
|---|
| 478 | | if($_REQUEST[$temping_ari] == "on") { |
|---|
| 479 | | $custom_cfg_data[$temping]['ari'] = 1; |
|---|
| 480 | | } |
|---|
| 481 | | } |
|---|
| 482 | | } |
|---|
| 483 | | } |
|---|
| 484 | | } |
|---|
| 485 | | |
|---|
| 486 | | $config_files = explode(",",$row['config_files']); |
|---|
| 487 | | $i = 0; |
|---|
| 488 | | while($i < count($config_files)) { |
|---|
| 489 | | $config_files[$i] = str_replace(".","_",$config_files[$i]); |
|---|
| 490 | | if(isset($_REQUEST[$config_files[$i]])) { |
|---|
| 491 | | if($_REQUEST[$config_files[$i]] > 0) { |
|---|
| 492 | | $config_files_selected[$config_files[$i]] = $_REQUEST[$config_files[$i]]; |
|---|
| 493 | | } |
|---|
| 494 | | } |
|---|
| 495 | | $i++; |
|---|
| 496 | | } |
|---|
| 497 | | if(!isset($config_files_selected)) { |
|---|
| 498 | | $config_files_selected = ""; |
|---|
| 499 | | } else { |
|---|
| 500 | | $config_files_selected = serialize($config_files_selected); |
|---|
| 501 | | } |
|---|
| 502 | | $save = serialize($custom_cfg_data); |
|---|
| 503 | | |
|---|
| 504 | | if($custom == "0") { |
|---|
| 505 | | $sql = 'UPDATE endpointman_template_list SET config_files_override = \''.addslashes($config_files_selected).'\', custom_cfg_data = \''.addslashes($save).'\' WHERE id ='.$id; |
|---|
| 506 | | $location = "template_manager"; |
|---|
| 507 | | } else { |
|---|
| 508 | | $sql = 'UPDATE endpointman_mac_list SET config_files_override = \''.addslashes($config_files_selected).'\', custom_cfg_template = 0, custom_cfg_data = \''.addslashes($save).'\' WHERE id ='.$id; |
|---|
| 509 | | $location = "devices_manager"; |
|---|
| 510 | | } |
|---|
| 511 | | $result=mysql_query($sql); |
|---|
| 512 | | |
|---|
| 513 | | |
|---|
| 514 | | require(PHONE_MODULES_PATH .$row['directory'].'/'.$row['cfg_dir'].'/functions.inc'); |
|---|
| 515 | | |
|---|
| 516 | | $phone_config = new $row['cfg_dir'](); |
|---|
| 517 | | if($custom != 0) { |
|---|
| 518 | | $phone_config->generate_config($id); |
|---|
| 519 | | } else { |
|---|
| 520 | | $sql = 'SELECT id FROM endpointman_mac_list WHERE custom_cfg_template = '.$id; |
|---|
| 521 | | $result=mysql_query($sql); |
|---|
| 522 | | while($row=mysql_fetch_array($result)) { |
|---|
| 523 | | $phone_config->generate_config($row['id']); |
|---|
| 524 | | } |
|---|
| 525 | | } |
|---|
| 526 | | return($location); |
|---|
| 527 | | |
|---|
| 528 | | } |
|---|
| 529 | | |
|---|
| 530 | | function firmware_update_check($id=NULL) { |
|---|
| 531 | | $sql = "SELECT * FROM endpointman_product_list WHERE id =". $id; |
|---|
| 532 | | $result = mysql_query($sql); |
|---|
| 533 | | $row = mysql_fetch_array($result); |
|---|
| 534 | | |
|---|
| 535 | | $sql = "SELECT directory FROM endpointman_brand_list WHERE id =". $row['brand']; |
|---|
| 536 | | $result = mysql_query($sql); |
|---|
| 537 | | if(mysql_num_rows($result)) { |
|---|
| 538 | | $brand_row = mysql_fetch_array($result); |
|---|
| 539 | | |
|---|
| 540 | | //config drive unknown! |
|---|
| 541 | | if ($row['cfg_dir'] == "") { |
|---|
| 542 | | return FALSE; |
|---|
| 543 | | } else { |
|---|
| 544 | | $temp = $this->xml2array(PHONE_MODULES_PATH.$brand_row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| 545 | | if((array_key_exists('data',$temp)) AND (!is_array($temp['data']['firmware_ver']))) { |
|---|
| 546 | | if($row['firmware_vers'] < $temp['data']['firmware_ver']) { |
|---|
| 547 | | return $temp; |
|---|
| 548 | | } else { |
|---|
| 549 | | return FALSE; |
|---|
| 550 | | } |
|---|
| 551 | | } else { |
|---|
| 552 | | return FALSE; |
|---|
| 553 | | } |
|---|
| 554 | | } |
|---|
| 555 | | } else { |
|---|
| 556 | | return FALSE; |
|---|
| 557 | | } |
|---|
| 558 | | } |
|---|
| 559 | | |
|---|
| 560 | | function firmware_local_check($id=NULL) { |
|---|
| 561 | | $sql = "SELECT * FROM endpointman_product_list WHERE installed = 1 AND id =". $id; |
|---|
| 562 | | $result = mysql_query($sql); |
|---|
| 563 | | if(mysql_num_rows($result)) { |
|---|
| 564 | | $row = mysql_fetch_array($result); |
|---|
| 565 | | |
|---|
| 566 | | $sql = "SELECT directory FROM endpointman_brand_list WHERE installed = 1 AND id =". $row['brand']; |
|---|
| 567 | | $result = mysql_query($sql); |
|---|
| 568 | | $brand_row = mysql_fetch_array($result); |
|---|
| 569 | | |
|---|
| 570 | | //config drive unknown! |
|---|
| 571 | | if ($row['cfg_dir'] == "") { |
|---|
| 572 | | return("nothing"); |
|---|
| 573 | | } else { |
|---|
| 574 | | $temp = $this->xml2array(PHONE_MODULES_PATH.$brand_row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| 575 | | if(!is_array($temp['data']['firmware_ver'])) { |
|---|
| 576 | | if($row['firmware_vers'] == "") { |
|---|
| 577 | | return("install"); |
|---|
| 578 | | } else { |
|---|
| 579 | | return("remove"); |
|---|
| 580 | | } |
|---|
| 581 | | } else { |
|---|
| 582 | | return("nothing"); |
|---|
| 583 | | } |
|---|
| 584 | | } |
|---|
| 585 | | } else { |
|---|
| 586 | | return("nothing"); |
|---|
| 587 | | } |
|---|
| 588 | | } |
|---|
| 589 | | |
|---|
| 590 | | function remove_firmware($id=NULL) { |
|---|
| 591 | | global $global_cfg; |
|---|
| 592 | | $sql = "SELECT * FROM endpointman_product_list WHERE id =". $id; |
|---|
| 593 | | $result = mysql_query($sql); |
|---|
| 594 | | $row = mysql_fetch_array($result); |
|---|
| 595 | | |
|---|
| 596 | | $file_list = explode(",",$row['firmware_files']); |
|---|
| 597 | | $i = 0; |
|---|
| 598 | | while($i < count($file_list)){ |
|---|
| 599 | | unlink($global_cfg['config_location'].$file_list[$i]); |
|---|
| 600 | | $i++; |
|---|
| 601 | | } |
|---|
| 602 | | $sql = 'UPDATE endpointman_product_list SET firmware_files = "", firmware_vers = "" WHERE id = '.$id; |
|---|
| 603 | | mysql_query($sql); |
|---|
| 604 | | } |
|---|
| 605 | | |
|---|
| 606 | | function install_firmware($product_id) { |
|---|
| 607 | | global $global_cfg, $debug; |
|---|
| 608 | | $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; |
|---|
| 609 | | $result = mysql_query($sql); |
|---|
| 610 | | $row = mysql_fetch_array($result); |
|---|
| 611 | | $temp = $this->xml2array(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| 612 | | if($temp['data']['firmware_ver'] > $row['firmware_vers']) { |
|---|
| 613 | | echo "<script>$('div.demo-container').text('Installing firmware');</script>"; |
|---|
| 614 | | $this->download_file_with_progress_bar(UPDATE_PATH . $temp['data']['firmware_pkg'], PHONE_MODULES_PATH."temp/".$temp['data']['firmware_pkg']); |
|---|
| 615 | | global $global_cfg, $endpoint; |
|---|
| 616 | | if(!file_exists(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware")) {mkdir(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware");} |
|---|
| 617 | | exec("unzip ".PHONE_MODULES_PATH."temp/" . $temp['data']['firmware_pkg'] ." -d ".PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware/", $debug_a = array()); |
|---|
| 618 | | if ($handle = opendir(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware/")) { |
|---|
| 619 | | while (false !== ($file = readdir($handle))) { |
|---|
| 620 | | if ($file != "." && $file != "..") { |
|---|
| 621 | | $list .= $file.","; |
|---|
| 622 | | } |
|---|
| 623 | | } |
|---|
| 624 | | closedir($handle); |
|---|
| 625 | | } |
|---|
| 626 | | $list = substr_replace($list ,"",-1); |
|---|
| 627 | | exec("cp -r " . PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware/*.* ". $global_cfg['config_location'], $debug_a2 = array()); |
|---|
| 628 | | $sql = "UPDATE endpointman_product_list SET firmware_vers = '".$temp['data']['firmware_ver']."', firmware_files = '".$list."' WHERE id = ". $row['id']; |
|---|
| 629 | | mysql_query($sql); |
|---|
| 630 | | echo "<script>$('div.demo-container').text('Done!');</script>"; |
|---|
| 631 | | } else { |
|---|
| 632 | | echo "<script>$('div.demo-container').text('Your Firmware is already up to date');</script>"; |
|---|
| 633 | | |
|---|
| 634 | | } |
|---|
| 635 | | if($global_cfg['debug']) { |
|---|
| 636 | | $debug = array_merge($debug_a, $debug_a2); |
|---|
| 637 | | $outfile=LOCAL_PATH."debug_installer.log"; |
|---|
| 638 | | $wfh=fopen($outfile,'a'); |
|---|
| 639 | | fwrite($wfh,print_r($debug, TRUE)); |
|---|
| 640 | | fclose($wfh); |
|---|
| 641 | | } |
|---|
| 642 | | } |
|---|
| 643 | | |
|---|
| 644 | | |
|---|
| 645 | | //Check for new packges for brands. These packages will include phone models and such which the user can remove if they want |
|---|
| 646 | | function brand_update_check() { |
|---|
| 647 | | $location = UPDATE_PATH . "brands.xml"; |
|---|
| 648 | | $temp = $this->xml2array($location); |
|---|
| 649 | | |
|---|
| 650 | | if(!isset($temp['data']['brands'][0])) { |
|---|
| 651 | | $temp2['data']['brands'][0] = $temp['data']['brands']; |
|---|
| 652 | | $temp = $temp2; |
|---|
| 653 | | } |
|---|
| 654 | | |
|---|
| 655 | | $out = $temp['data']['brands']; |
|---|
| 656 | | $count = count($out); |
|---|
| 657 | | |
|---|
| 658 | | $sql = "SELECT * FROM endpointman_brand_list WHERE id > 0"; |
|---|
| 659 | | $result = mysql_query($sql); |
|---|
| 660 | | while($row = mysql_fetch_assoc($result)){ |
|---|
| 661 | | $key = $this->arraysearchrecursive($row['directory'], $out, 'directory'); |
|---|
| 662 | | if($key === FALSE) { |
|---|
| 663 | | $this->remove_brand($row['id']); |
|---|
| 664 | | } |
|---|
| 665 | | |
|---|
| 666 | | $key = $key[0]; |
|---|
| 667 | | |
|---|
| 668 | | if($row['cfg_ver'] < $out[$key]['version']) { |
|---|
| 669 | | $out[$key]['update'] = 1; |
|---|
| 670 | | $out[$key]['update_vers'] = $out[$key]['version']; |
|---|
| 671 | | } else { |
|---|
| 672 | | $out[$key]['update'] = NULL; |
|---|
| 673 | | } |
|---|
| 674 | | |
|---|
| 675 | | } |
|---|
| 676 | | |
|---|
| 677 | | for($i=0;$i<$count;$i++){ |
|---|
| 678 | | if(!isset($out[$i]['update'])) { |
|---|
| 679 | | //insert row |
|---|
| 680 | | $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver) VALUES ('".$out[$i]['brand_id']."', '".$out[$i]['brand_name']."', '".$out[$i]['directory']."', '".$out[$i]['version']."')"; |
|---|
| 681 | | mysql_query($sql); |
|---|
| 682 | | } |
|---|
| 683 | | } |
|---|
| 684 | | |
|---|
| 685 | | return $out; |
|---|
| 686 | | } |
|---|
| 687 | | |
|---|
| 688 | | //This will update AND install brands! |
|---|
| 689 | | //id is brand id |
|---|
| 690 | | function update_brand($id = NULL) { |
|---|
| 691 | | //Get the brands run down from the update server |
|---|
| 692 | | $temp = $this->xml2array(UPDATE_PATH . "brands.xml"); |
|---|
| 693 | | |
|---|
| 694 | | $key = $this->arraysearchrecursive($id, $temp['data']['brands'],'brand_id'); |
|---|
| 695 | | |
|---|
| 696 | | |
|---|
| 697 | | $key = $key[0]; |
|---|
| 698 | | |
|---|
| 699 | | if(!isset($temp['data']['brands'][$key]['product_list'][0])) { |
|---|
| 700 | | $temp2 = $temp['data']['brands'][$key]['product_list']; |
|---|
| 701 | | unset($temp['data']['brands'][$key]['product_list']); |
|---|
| 702 | | $temp['data']['brands'][$key]['product_list'][0] = $temp2; |
|---|
| 703 | | } |
|---|
| 704 | | |
|---|
| 705 | | //Count how many products are avalible for this brand |
|---|
| 706 | | $count2 = count($temp['data']['brands'][$key]['product_list']); |
|---|
| 707 | | |
|---|
| 708 | | //Get the name of the brand (Grandstream, Polycom, etc) |
|---|
| 709 | | $brand_name = $temp['data']['brands'][$key]['brand_name']; |
|---|
| 710 | | |
|---|
| 711 | | //Though we already have the brand ID lets just pull it again to be sure |
|---|
| 712 | | $brand_id = $temp['data']['brands'][$key]['brand_id']; |
|---|
| 713 | | |
|---|
| 714 | | //Brand directory listing. We'll use this to put the generic files into place |
|---|
| 715 | | $brand_directory = $temp['data']['brands'][$key]['directory']; |
|---|
| 716 | | |
|---|
| 717 | | //Get the brand's config version |
|---|
| 718 | | $cfg_ver = $temp['data']['brands'][$key]['version']; |
|---|
| 719 | | |
|---|
| 720 | | //Update config version to the newest number |
|---|
| 721 | | $sql = "UPDATE endpointman_brand_list SET name = '".$brand_name."', cfg_ver = '".$cfg_ver."', installed = 1 WHERE id = ". $brand_id; |
|---|
| 722 | | mysql_query($sql); |
|---|
| 723 | | |
|---|
| 724 | | //Run through the list of products supported under this brand by us. Then spit these values back out into an array where the array's key is equal to the phone's ID number |
|---|
| 725 | | $sql = "SELECT * FROM endpointman_product_list WHERE brand = ". $brand_id; |
|---|
| 726 | | $result = mysql_query($sql); |
|---|
| 727 | | while($row = mysql_fetch_assoc($result)) { |
|---|
| 728 | | $rid = $row['id']; |
|---|
| 729 | | $row_out[$rid] = $row; |
|---|
| 730 | | } |
|---|
| 731 | | |
|---|
| 732 | | for($i=0;$i<$count2;$i++) { |
|---|
| 733 | | $id = $temp['data']['brands'][$key]['product_list'][$i]['product_id']; |
|---|
| 734 | | $long_name = $temp['data']['brands'][$key]['product_list'][$i]['product_name']; |
|---|
| 735 | | $cfg_dir = $temp['data']['brands'][$key]['product_list'][$i]['directory']; |
|---|
| 736 | | $xml_data = $temp['data']['brands'][$key]['product_list'][$i]['xml_name']; |
|---|
| 737 | | |
|---|
| 738 | | if(!isset($row_out[$id])) { |
|---|
| 739 | | $sql = "INSERT INTO endpointman_product_list (id, brand, long_name, cfg_dir, xml_data) VALUES ('".$id."','".$brand_id."','".$long_name."','".$cfg_dir."','".$xml_data."')"; |
|---|
| 740 | | mysql_query($sql); |
|---|
| 741 | | } else { |
|---|
| 742 | | $sql = "UPDATE endpointman_product_list SET long_name = '".$long_name."', cfg_dir= '".$cfg_dir."', xml_data='".$xml_data."' WHERE id =". $id; |
|---|
| 743 | | mysql_query($sql); |
|---|
| 744 | | } |
|---|
| 745 | | } |
|---|
| 746 | | //Now run through the OUI list and add it in! |
|---|
| 747 | | $result = mysql_query("SELECT * FROM endpointman_oui_list"); |
|---|
| 748 | | $i = 0; |
|---|
| 749 | | $oui_out = array(); |
|---|
| 750 | | while($row = mysql_fetch_assoc($result)) { |
|---|
| 751 | | $oui_out[$i] = $row; |
|---|
| 752 | | $i++; |
|---|
| 753 | | } |
|---|
| 754 | | |
|---|
| 755 | | if(!is_array($temp['data']['brands'][$key]['oui_list']['oui'])) { |
|---|
| 756 | | $temp2 = $temp['data']['brands'][$key]['oui_list']['oui']; |
|---|
| 757 | | unset($temp['data']['brands'][$key]['oui_list']); |
|---|
| 758 | | $temp['data']['brands'][$key]['oui_list']['oui'][0] = $temp2; |
|---|
| 759 | | } |
|---|
| 760 | | |
|---|
| 761 | | $count = count($temp['data']['brands'][$key]['oui_list']['oui']); |
|---|
| 762 | | for($i=0;$i < $count;$i++) { |
|---|
| 763 | | if(!$this->arraysearchrecursive($temp['data']['brands'][$key]['oui_list']['oui'][$i],$oui_out)) { |
|---|
| 764 | | $sql = "INSERT INTO endpointman_oui_list (oui, brand) VALUES ('".$temp['data']['brands'][$key]['oui_list']['oui'][$i]."', '".$brand_id."')"; |
|---|
| 765 | | mysql_query($sql); |
|---|
| 766 | | } |
|---|
| 767 | | } |
|---|
| 768 | | //Download the corresponding package and install it in the directory listed above |
|---|
| 769 | | echo "<script>$('div.demo-container').text('Installing Module....');</script>"; |
|---|
| 770 | | if(!file_exists(PHONE_MODULES_PATH."temp")) {mkdir(PHONE_MODULES_PATH."temp");} |
|---|
| 771 | | if(!file_exists(PHONE_MODULES_PATH.$brand_directory)) {mkdir(PHONE_MODULES_PATH.$brand_directory);} |
|---|
| 772 | | echo "<script>$('div.demo-container').text('Downloading Module...');</script>"; |
|---|
| 773 | | $this->download_file_with_progress_bar(UPDATE_PATH . $temp['data']['brands'][$key]['package'], PHONE_MODULES_PATH."temp/".$temp['data']['brands'][$key]['package']); |
|---|
| 774 | | echo "<script>$('div.demo-container').text('Installing Module...');</script>"; |
|---|
| 775 | | exec("unzip ".PHONE_MODULES_PATH.'temp/'. $temp['data']['brands'][$key]['package'] ." -d ".PHONE_MODULES_PATH."temp/"); |
|---|
| 776 | | exec("rm -R ".PHONE_MODULES_PATH."temp/__MACOSX"); |
|---|
| 777 | | unlink(PHONE_MODULES_PATH.'temp/'. $temp['data']['brands'][$key]['package']); |
|---|
| 778 | | exec("cp -R ".PHONE_MODULES_PATH."temp/" .$brand_directory . " " . PHONE_MODULES_PATH); |
|---|
| 779 | | chmod(PHONE_MODULES_PATH.$brand_directory, 0777); |
|---|
| 780 | | $this->deltree(PHONE_MODULES_PATH."temp/" .$brand_directory); |
|---|
| 781 | | exec("chmod 777 -R ". PHONE_MODULES_PATH.$brand_directory); |
|---|
| 782 | | |
|---|
| 783 | | //TODO: once iframe access is fixed to not go into the module, this should be $_SERVER['PHP_SELF']."?type=tool...", and type=tool should be passed in (in case it is not tool) |
|---|
| 784 | | // |
|---|
| 785 | | echo "<script>$('div.demo-container').html('<a href=\"#\" onclick=\"parent.location.href = \'/admin/config.php?type=tool&display=epm_config\';\">"._("Install Done, Click to Return")."</a>');</script>"; |
|---|
| 786 | | } |
|---|
| 787 | | |
|---|
| 788 | | function remove_brand($id=NULL) { |
|---|
| 789 | | mysql_query("DELETE FROM endpointman_brand_list WHERE id = ". $id); |
|---|
| 790 | | } |
|---|
| 791 | | |
|---|
| 792 | | function product_update_check($id=NULL) { |
|---|
| 793 | | $sql = "SELECT * FROM endpointman_product_list WHERE id =".$id; |
|---|
| 794 | | $result = mysql_query($sql); |
|---|
| 795 | | $row = mysql_fetch_array($result); |
|---|
| 796 | | //config drive unknown! |
|---|
| 797 | | if ($row['cfg_dir'] == "") { |
|---|
| 798 | | return FALSE; |
|---|
| 799 | | } else { |
|---|
| 800 | | $temp = $this->xml2array(UPDATE_PATH . $row['xml_data']); |
|---|
| 801 | | if($row['cfg_ver'] < $temp['data']['version']) { |
|---|
| 802 | | return $temp; |
|---|
| 803 | | } else { |
|---|
| 804 | | return FALSE; |
|---|
| 805 | | } |
|---|
| 806 | | } |
|---|
| 807 | | } |
|---|
| 808 | | |
|---|
| 809 | | function sync_product($product=NULL) { |
|---|
| 810 | | global $global_cfg, $debug; |
|---|
| 811 | | $sql = "SELECT * FROM endpointman_product_list WHERE id =". $product; |
|---|
| 812 | | $result = mysql_query($sql); |
|---|
| 813 | | $row = mysql_fetch_array($result); |
|---|
| 814 | | |
|---|
| 815 | | $sql = "SELECT directory FROM endpointman_brand_list WHERE id =". $row['brand']; |
|---|
| 816 | | $result = mysql_query($sql); |
|---|
| 817 | | $brand_row = mysql_fetch_array($result); |
|---|
| 818 | | //config drive unknown! |
|---|
| 819 | | if ($row['cfg_dir'] == "") { |
|---|
| 820 | | if($global_cfg['debug']) { |
|---|
| 821 | | $debug .= "\nFunction sync_product XML Data:\n".$xml; |
|---|
| 822 | | } |
|---|
| 823 | | return FALSE; |
|---|
| 824 | | } else { |
|---|
| 825 | | //check for updates in template folder |
|---|
| 826 | | $temp = $this->xml2array(PHONE_MODULES_PATH.$brand_row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| 827 | | if (($temp['data']['version'] >= $row['cfg_ver']) OR ($row['cfg_data'] == "")) { |
|---|
| 828 | | if(isset($temp['data']['item'])) { |
|---|
| 829 | | $cfg_data = serialize($temp['data']['item']); |
|---|
| 830 | | } else { |
|---|
| 831 | | $cfg_data = NULL; |
|---|
| 832 | | } |
|---|
| 833 | | $sql = "UPDATE endpointman_product_list SET config_files=\"".addslashes($temp['data']['configuration_files'])."\",cfg_data = \"".addslashes($cfg_data)."\", cfg_ver ='".$temp['data']['version']."' WHERE id = ". $product; |
|---|
| 834 | | mysql_query($sql); |
|---|
| 835 | | if($global_cfg['debug']) { |
|---|
| 836 | | $xml = print_r($temp, TRUE); |
|---|
| 837 | | $debug .= "\nFunction sync_product XML Data:\n".$xml; |
|---|
| 838 | | } |
|---|
| 839 | | return TRUE; |
|---|
| 840 | | } else { |
|---|
| 841 | | if($global_cfg['debug']) { |
|---|
| 842 | | $debug .= "\nFunction sync_product XML Data:Didn't run xml2array, local version less than sql version\n"; |
|---|
| 843 | | } |
|---|
| 844 | | return TRUE; |
|---|
| 845 | | } |
|---|
| 846 | | } |
|---|
| 847 | | } |
|---|
| 848 | | |
|---|
| 849 | | //id is model id |
|---|
| 850 | | function install_product($id = NULL) { |
|---|
| 851 | | //Update SQL below to include the brand and then use the brand_xml with the data returned to get new models are remove old ones....etc. |
|---|
| 852 | | $sql = "SELECT endpointman_product_list.*, endpointman_brand_list.directory FROM endpointman_product_list, endpointman_brand_list WHERE endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_product_list.id =". $id; |
|---|
| 853 | | $result = mysql_query($sql); |
|---|
| 854 | | $row = mysql_fetch_assoc($result); |
|---|
| 855 | | $cfg_dir = $row['cfg_dir']; |
|---|
| 856 | | $xml_data = $row['xml_data']; |
|---|
| 857 | | |
|---|
| 858 | | echo "<script>$('div.demo-container').text('Getting XML data...');</script>"; |
|---|
| 859 | | |
|---|
| 860 | | $product_xml = $this->xml2array(UPDATE_PATH . $xml_data); |
|---|
| 861 | | $brand_xml = $this->xml2array(UPDATE_PATH . "brands.xml"); |
|---|
| 862 | | |
|---|
| 863 | | $brand_id = $this->arraysearchrecursive($row['directory'], $brand_xml['data']['brands'], 'directory'); |
|---|
| 864 | | $brand_id = $brand_id[0]; |
|---|
| 865 | | |
|---|
| 866 | | |
|---|
| 867 | | if(!isset($brand_xml['data']['brands'][$brand_id]['product_list'][0])) { |
|---|
| 868 | | $temp2 = $brand_xml['data']['brands'][$brand_id]['product_list']; |
|---|
| 869 | | unset($brand_xml['data']['brands'][$brand_id]['product_list']); |
|---|
| 870 | | $brand_xml['data']['brands'][$brand_id]['product_list'][0] = $temp2; |
|---|
| 871 | | } |
|---|
| 872 | | |
|---|
| 873 | | $product_id = $this->arraysearchrecursive($row['cfg_dir'], $brand_xml['data']['brands'][$brand_id]['product_list'],'directory'); |
|---|
| 874 | | $product_id = $product_id[0]; |
|---|
| 875 | | $cfg_ver = $product_xml['data']['version']; |
|---|
| 876 | | $product_dir = $brand_xml['data']['brands'][$brand_id]['product_list'][$product_id]['directory']; |
|---|
| 877 | | |
|---|
| 878 | | if ($cfg_ver > $row['cfg_ver']) { |
|---|
| 879 | | $cfg_pkg = $temp['data']['package']; |
|---|
| 880 | | if(!file_exists(PHONE_MODULES_PATH."temp")) {mkdir(PHONE_MODULES_PATH."temp");} |
|---|
| 881 | | $this->download_file_with_progress_bar(UPDATE_PATH . $xml_data, PHONE_MODULES_PATH.'temp/'. $xml_data); |
|---|
| 882 | | echo "<script>$('div.demo-container').text('Downloading Module...');</script>"; |
|---|
| 883 | | $this->download_file_with_progress_bar(UPDATE_PATH . $product_xml['data']['package'], PHONE_MODULES_PATH.'temp/'. $product_xml['data']['package']); |
|---|
| 884 | | echo "<script>$('div.demo-container').text('Installing Module...');</script>"; |
|---|
| 885 | | exec("rm -R ".PHONE_MODULES_PATH.$row['directory']."/" .$product_dir, $debug_a = array()); |
|---|
| 886 | | exec("unzip ".PHONE_MODULES_PATH.'temp/'. $product_xml['data']['package']." -d ".PHONE_MODULES_PATH."temp/", $debug_a2 = array()); |
|---|
| 887 | | exec("rm -R ".PHONE_MODULES_PATH."temp/__MACOSX" , $debug_a3 = array()); |
|---|
| 888 | | unlink(PHONE_MODULES_PATH.'temp/'. $product_xml['data']['package']); |
|---|
| 889 | | exec("cp -R ".PHONE_MODULES_PATH."temp/" .$product_dir . " " . PHONE_MODULES_PATH.$row['directory'], $debug_a4 = array()); |
|---|
| 890 | | chmod(PHONE_MODULES_PATH.$row['directory']."/".$product_dir, 0777); |
|---|
| 891 | | rename(PHONE_MODULES_PATH."temp/" .$xml_data, PHONE_MODULES_PATH.$row['directory']."/".$product_dir."/template_data.xml"); |
|---|
| 892 | | exec("rm -R ".PHONE_MODULES_PATH."temp/" .$product_dir, $debug_a5 = array()); |
|---|
| 893 | | unlink(PHONE_MODULES_PATH."temp/" .$xml_data); |
|---|
| 894 | | exec("chmod 777 -R ". PHONE_MODULES_PATH.$row['directory']."/". $cfg_dir, $debug_a6 = array()); |
|---|
| 895 | | } |
|---|
| 896 | | |
|---|
| 897 | | echo "<script>$('div.demo-container').text('Updating System...');</script>"; |
|---|
| 898 | | |
|---|
| 899 | | |
|---|
| 900 | | $sql = 'SELECT * FROM endpointman_model_list WHERE product_id = '. $id; |
|---|
| 901 | | $result = mysql_query($sql); |
|---|
| 902 | | $i = 0; |
|---|
| 903 | | while($row = mysql_fetch_assoc($result)) { |
|---|
| 904 | | $row_o[$i] = $row; |
|---|
| 905 | | $i++; |
|---|
| 906 | | } |
|---|
| 907 | | |
|---|
| 908 | | $count = count($brand_xml['data']['brands'][$brand_id]['product_list'][$product_id]['model_list']); |
|---|
| 909 | | |
|---|
| 910 | | echo "<script>$('div.demo-container').text('Updating Models...');</script>"; |
|---|
| 911 | | |
|---|
| 912 | | //Look Through remote values and compare them to local values, adding phones if needed and updating other phones if these exist already in our database |
|---|
| 913 | | for($i=0;$i<$count;$i++) { |
|---|
| 914 | | $model_name = $brand_xml['data']['brands'][$brand_id]['product_list'][$product_id]['model_list'][$i]['model']; |
|---|
| 915 | | $model_id = $brand_xml['data']['brands'][$brand_id]['product_list'][$product_id]['model_list'][$i]['id']; |
|---|
| 916 | | $brand_id2 = $brand_xml['data']['brands'][$brand_id]['brand_id']; |
|---|
| 917 | | $temping = $this->arraysearchrecursive($model_name, $row_o); |
|---|
| 918 | | if($temping === FALSE) { |
|---|
| 919 | | $sql = "INSERT INTO endpointman_model_list (id, brand, model, product_id) VALUES ('".$model_id."','".$brand_id2."','".$model_name."','".$id."')"; |
|---|
| 920 | | } else { |
|---|
| 921 | | $sql = "UPDATE endpointman_model_list SET brand = '".$brand_id2."', model= '".$model_name."', product_id='".$id."' WHERE id =". $model_id; |
|---|
| 922 | | } |
|---|
| 923 | | mysql_query($sql); |
|---|
| 924 | | } |
|---|
| 925 | | |
|---|
| 926 | | //Look through the database and compare local values with remote values, removing those phones that are no longer supported. |
|---|
| 927 | | $count = count($row_o); |
|---|
| 928 | | for($i=0;$i<$count;$i++) { |
|---|
| 929 | | $temping = $this->arraysearchrecursive($row_o['id'], $brand_xml); |
|---|
| 930 | | if($temping === FALSE) { |
|---|
| 931 | | $sql = "DELETE FROM endpointman_model_list WHERE id = " . $row_o['id']; |
|---|
| 932 | | mysql_query("UPDATE endpointman_model_list SET model = 0 WHERE model = " . $row_o['id']); |
|---|
| 933 | | } |
|---|
| 934 | | mysql_query($sql); |
|---|
| 935 | | } |
|---|
| 936 | | $sql = "UPDATE endpointman_product_list SET installed = '1', cfg_ver= '".$cfg_ver."' WHERE id = " . $id; |
|---|
| 937 | | mysql_query($sql); |
|---|
| 938 | | |
|---|
| 939 | | echo "<script>$('div.demo-container').text('Syncing System...');</script>"; |
|---|
| 940 | | |
|---|
| 941 | | $this->sync_product($id); |
|---|
| 942 | | |
|---|
| 943 | | //TODO: once iframe access is fixed to not go into the module, this should be $_SERVER['PHP_SELF']."?type=tool...", and type=tool should be passed in (in case it is not tool) |
|---|
| 944 | | // |
|---|
| 945 | | echo "<script>$('div.demo-container').html('<a href=\"#\" onclick=\"parent.location.href = \'/admin/config.php?type=tool&display=epm_config\';\">"._("Install Done, Click to Return")."</a>');</script>"; |
|---|
| 946 | | |
|---|
| 947 | | if($global_cfg['debug']) { |
|---|
| 948 | | unlink(LOCAL_PATH."debug_installer.log"); |
|---|
| 949 | | $debug = array_merge($debug_a, $debug_a2, $debug_a3, $debug_a4, $debug_a5, $debug_a6); |
|---|
| 950 | | $outfile=LOCAL_PATH."debug_installer.log"; |
|---|
| 951 | | $wfh=fopen($outfile,'a'); |
|---|
| 952 | | fwrite($wfh,print_r($debug, TRUE)); |
|---|
| 953 | | fclose($wfh); |
|---|
| 954 | | } |
|---|
| 955 | | } |
|---|
| 956 | | |
|---|
| 957 | | function remove_product($id=NULL) { |
|---|
| 958 | | $sql = 'SELECT endpointman_model_list.*, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_model_list, endpointman_product_list, endpointman_brand_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_product_list.id = '.$id; |
|---|
| 959 | | |
|---|
| 960 | | $result = mysql_query($sql); |
|---|
| 961 | | while($row = mysql_fetch_assoc($result)) { |
|---|
| 962 | | $sql = "UPDATE endpointman_mac_list SET model = 0 WHERE model = ".$row['id']; |
|---|
| 963 | | mysql_query($sql); |
|---|
| 964 | | $row_out = $row; |
|---|
| 965 | | } |
|---|
| 966 | | |
|---|
| 967 | | $this->deltree(PHONE_MODULES_PATH.$row_out['directory']."/". $row_out['cfg_dir']); |
|---|
| 968 | | $sql = "UPDATE endpointman_product_list SET installed = 0, cfg_ver = '' WHERE id = ".$id; |
|---|
| 969 | | mysql_query($sql); |
|---|
| 970 | | $sql = "DELETE FROM endpointman_model_list WHERE product_id = ".$id; |
|---|
| 971 | | mysql_query($sql); |
|---|
| 972 | | } |
|---|
| 973 | | |
|---|
| 974 | | function arraysearchrecursive($Needle,$Haystack,$NeedleKey="",$Strict=false,$Path=array()) { |
|---|
| 975 | | if(!is_array($Haystack)) |
|---|
| 976 | | return false; |
|---|
| 977 | | foreach($Haystack as $Key => $Val) { |
|---|
| 978 | | if(is_array($Val)&& |
|---|
| 979 | | $SubPath=$this->arraysearchrecursive($Needle,$Val,$NeedleKey,$Strict,$Path)) { |
|---|
| 980 | | $Path=array_merge($Path,Array($Key),$SubPath); |
|---|
| 981 | | return $Path; |
|---|
| 982 | | } |
|---|
| 983 | | elseif((!$Strict&&$Val==$Needle&& |
|---|
| 984 | | $Key==(strlen($NeedleKey)>0?$NeedleKey:$Key))|| |
|---|
| 985 | | ($Strict&&$Val===$Needle&& |
|---|
| 986 | | $Key==(strlen($NeedleKey)>0?$NeedleKey:$Key))) { |
|---|
| 987 | | $Path[]=$Key; |
|---|
| 988 | | return $Path; |
|---|
| 989 | | } |
|---|
| 990 | | } |
|---|
| 991 | | return false; |
|---|
| 992 | | } |
|---|
| 993 | | //Below is pfSense code |
|---|
| 994 | | function download_file_with_progress_bar($url_file, $destination_file) { |
|---|
| 995 | | global $ch, $fout, $file_size, $downloaded, $pkg_interface; |
|---|
| 996 | | set_time_limit(0); |
|---|
| 997 | | $file_size = 1; |
|---|
| 998 | | $downloaded = 1; |
|---|
| 999 | | /* open destination file */ |
|---|
| 1000 | | $fout = fopen($destination_file, "wb"); |
|---|
| 1001 | | |
|---|
| 1002 | | /* |
|---|
| | 66 | global $amp_conf,$global_cfg, $endpoint_db, $db, $type; |
|---|
| | 67 | |
|---|
| | 68 | $this->db = $db; |
|---|
| | 69 | $this->amp_conf = $amp_conf; |
|---|
| | 70 | $this->error = array(); |
|---|
| | 71 | |
|---|
| | 72 | |
|---|
| | 73 | //attached to the end of every link so we can flow through FreePBX |
|---|
| | 74 | //This is really hacky but I have to do it when people have different directories instead of admin |
|---|
| | 75 | //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 |
|---|
| | 76 | define("PHONE_MODULES_PATH", dirname($_SERVER["SCRIPT_FILENAME"])."/modules/_ep_phone_modules/"); |
|---|
| | 77 | |
|---|
| | 78 | //Get local path information |
|---|
| | 79 | define("WEB_PATH", dirname($_SERVER['SCRIPT_NAME'])."/modules/endpointman/"); |
|---|
| | 80 | define("LOCAL_PATH", dirname($_SERVER["SCRIPT_FILENAME"])."/modules/endpointman/"); |
|---|
| | 81 | |
|---|
| | 82 | |
|---|
| | 83 | |
|---|
| | 84 | mysql_close(); |
|---|
| | 85 | |
|---|
| | 86 | |
|---|
| | 87 | $this->global_cfg =& $db->getAssoc("SELECT var_name, value FROM endpointman_global_vars"); |
|---|
| | 88 | |
|---|
| | 89 | define("UPDATE_PATH", $this->global_cfg['update_server']); |
|---|
| | 90 | define("VER", $this->global_cfg['version']); |
|---|
| | 91 | |
|---|
| | 92 | //Define error reporting |
|---|
| | 93 | if($this->global_cfg['debug']) { |
|---|
| | 94 | error_reporting(E_ALL); |
|---|
| | 95 | ini_set('display_errors', 1); |
|---|
| | 96 | } else { |
|---|
| | 97 | ini_set('display_errors', 0); |
|---|
| | 98 | } |
|---|
| | 99 | //include the local template class |
|---|
| | 100 | include LOCAL_PATH."includes/rain.tpl.class.php"; |
|---|
| | 101 | } |
|---|
| | 102 | |
|---|
| | 103 | function add_freepbx_notification($id, $type, $display_text, $text, $link) { |
|---|
| | 104 | $sql = "INSERT INTO notifications (module, id, level, display_text, link, candelete, timestamp, extended_text) VALUES ('endpointman', '".$id."', '500', '".$display_text."', '".$link."', '1', '".time()."', '".$text."')"; |
|---|
| | 105 | mysql_query($sql); |
|---|
| | 106 | } |
|---|
| | 107 | |
|---|
| | 108 | /** |
|---|
| | 109 | * Send this function an ID from the mac devices list table and you'll get all the information we have on that particular phone |
|---|
| | 110 | * @param integer $mac_id ID number reference from the MySQL database referencing the table endpointman_mac_list |
|---|
| | 111 | * @return <type> |
|---|
| | 112 | */ |
|---|
| | 113 | function get_phone_info($mac_id=NULL) { |
|---|
| | 114 | //You could screw up a phone if the mac_id is blank |
|---|
| | 115 | if (!isset($mac_id)) { |
|---|
| | 116 | die("Can't get phone info!"); |
|---|
| | 117 | } |
|---|
| | 118 | $sql = "SELECT id,mac,model FROM endpointman_mac_list WHERE model > 0 AND id =".$mac_id; |
|---|
| | 119 | $res =& $this->db->query($sql); |
|---|
| | 120 | if($res->numRows()) { |
|---|
| | 121 | //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, |
|---|
| | 122 | $sql = "SELECT endpointman_mac_list.config_files_override, endpointman_mac_list.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.ext, endpointman_mac_list.custom_cfg_template, endpointman_mac_list.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, users.name as description, sip.data as secret FROM endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_product_list, sip, users WHERE endpointman_mac_list.id = ".$mac_id." AND 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.ext = sip.id AND sip.keyword = 'secret' AND endpointman_mac_list.ext = users.extension"; |
|---|
| | 123 | |
|---|
| | 124 | $phone_info =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); |
|---|
| | 125 | |
|---|
| | 126 | if(!$phone_info) { |
|---|
| | 127 | $this->error['get_phone_info'] = "Error with SQL Statement"; |
|---|
| | 128 | } |
|---|
| | 129 | |
|---|
| | 130 | //If there is a template associated with this phone then pull that information and put it into the array |
|---|
| | 131 | if ($phone_info['custom_cfg_template'] > 0) { |
|---|
| | 132 | $sql = "SELECT name, custom_cfg_data, config_files_override FROM endpointman_template_list WHERE id = ".$phone_info['custom_cfg_template']; |
|---|
| | 133 | |
|---|
| | 134 | $phone_info['template_data'] =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); |
|---|
| | 135 | |
|---|
| | 136 | } |
|---|
| | 137 | } else { |
|---|
| | 138 | //Phone is unknown, we need to display this to the end user so that they can make corrections |
|---|
| | 139 | $row=mysql_fetch_array($result); |
|---|
| | 140 | $phone_info['id'] = $mac_id; |
|---|
| | 141 | $phone_info['model_id'] = 0; |
|---|
| | 142 | $phone_info['brand_id'] = 0; |
|---|
| | 143 | $phone_info['ext'] = $row['ext']; |
|---|
| | 144 | $phone_info['mac'] = $row['mac']; |
|---|
| | 145 | $phone_info['name'] = 'Unknown'; |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | return $phone_info; |
|---|
| | 149 | } |
|---|
| | 150 | |
|---|
| | 151 | /** |
|---|
| | 152 | * Custom Means specific to that MAC |
|---|
| | 153 | * id is either the mac ID (not address) or the template ID |
|---|
| | 154 | * @param integer $id |
|---|
| | 155 | * @param integer $custom |
|---|
| | 156 | */ |
|---|
| | 157 | function edit_template_display($id, $custom) { |
|---|
| | 158 | $alt_configs = NULL; |
|---|
| | 159 | |
|---|
| | 160 | if($custom == 0) { |
|---|
| | 161 | $sql = "SELECT model_id FROM endpointman_template_list WHERE id=".$id; |
|---|
| | 162 | } else { |
|---|
| | 163 | $sql = "SELECT model FROM endpointman_mac_list WHERE id=".$id; |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | $model_id = $this->db->getOne($sql); |
|---|
| | 167 | |
|---|
| | 168 | //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 |
|---|
| | 169 | if(!$this->sync_model($model_id)) { |
|---|
| | 170 | die("unable to sync local template files - TYPE:". $custom); |
|---|
| | 171 | } |
|---|
| | 172 | |
|---|
| | 173 | |
|---|
| | 174 | //Determine if we are dealing with a general template or a specific [for that phone only] template (custom =0 means general) |
|---|
| | 175 | if($custom == 0) { |
|---|
| | 176 | $sql = "SELECT 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_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; |
|---|
| | 177 | } else { |
|---|
| | 178 | $sql = "SELECT endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_model_list.id as model_id, endpointman_model_list.template_data, endpointman_product_list.id as product_id, endpointman_product_list.long_name, 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"; |
|---|
| | 179 | } |
|---|
| | 180 | |
|---|
| | 181 | $row =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); |
|---|
| | 182 | |
|---|
| | 183 | $tpl = new RainTPL( LOCAL_PATH.'templates' ); |
|---|
| | 184 | $tpl->assign("template_editor_display", 1); |
|---|
| | 185 | |
|---|
| | 186 | echo $tpl->draw( 'global_header' ); |
|---|
| | 187 | //Let the template system know if we are working with a general template or a specific [for that phone only] template |
|---|
| | 188 | $tpl->assign("custom", $custom); |
|---|
| | 189 | if($custom) { |
|---|
| | 190 | $tpl->assign("ext", $row['ext']); |
|---|
| | 191 | } else { |
|---|
| | 192 | $tpl->assign("template_name", $row['name']); |
|---|
| | 193 | } |
|---|
| | 194 | $tpl->assign("model", $row['long_name']); |
|---|
| | 195 | |
|---|
| | 196 | //Start the display of the html file in the product folder |
|---|
| | 197 | if($row['config_files_override'] == "") { |
|---|
| | 198 | $config_files_saved = ""; |
|---|
| | 199 | } else { |
|---|
| | 200 | $config_files_saved = unserialize($row['config_files_override']); |
|---|
| | 201 | } |
|---|
| | 202 | $config_files_list = explode(",",$row['config_files']); |
|---|
| | 203 | $i = 0; |
|---|
| | 204 | $alt = 0; |
|---|
| | 205 | //TODO: Perhaps fix this alternative files list |
|---|
| | 206 | foreach($config_files_list as $files) { |
|---|
| | 207 | $sql = "SELECT * FROM endpointman_custom_configs WHERE product_id = ".$row['id']." AND original_name = '".$files."'"; |
|---|
| | 208 | $alt_configs_list_count =& $this->db->query($sql); |
|---|
| | 209 | if($alt_configs_list_count->numRows() > 0) { |
|---|
| | 210 | $alt_configs_list =& $this->db->getAll($sql, array(), DB_FETCHMODE_ASSOC); |
|---|
| | 211 | $alt_configs .= $files; |
|---|
| | 212 | $alt_configs .= '<select name="'.$files.'">'; |
|---|
| | 213 | $alt_configs .= '<option value="0">'.$files.' (Original)</option>'; |
|---|
| | 214 | $files = str_replace(".","_",$files); |
|---|
| | 215 | foreach($alt_configs_list as $ccf) { |
|---|
| | 216 | $alt_configs .= '<option value="'.$ccf['id'].'" '; |
|---|
| | 217 | $cf_key = $files; |
|---|
| | 218 | if((is_array($config_files_saved)) AND ($config_files_saved[$cf_key] == $ccf['id'])) { |
|---|
| | 219 | $alt_configs .= 'selected'; |
|---|
| | 220 | } |
|---|
| | 221 | $alt_configs .= '>'.$ccf['name'].'</option>'; |
|---|
| | 222 | } |
|---|
| | 223 | $alt_configs .= "</select>"; |
|---|
| | 224 | $alt = 1; |
|---|
| | 225 | } |
|---|
| | 226 | $i++; |
|---|
| | 227 | } |
|---|
| | 228 | $tpl->assign("alt_configs", $alt_configs); |
|---|
| | 229 | $tpl->assign("alt", $alt); |
|---|
| | 230 | |
|---|
| | 231 | if($row['template_data'] != "") { |
|---|
| | 232 | $out = $this->generate_gui_html($row['template_data'],$row['custom_cfg_data'],TRUE); |
|---|
| | 233 | } else { |
|---|
| | 234 | echo "No Template Data has been defined for this Product<br />"; |
|---|
| | 235 | } |
|---|
| | 236 | |
|---|
| | 237 | $tpl->assign("template_editor", $out); |
|---|
| | 238 | $tpl->assign("hidden_id", $row['id']); |
|---|
| | 239 | $tpl->assign("hidden_custom", $custom); |
|---|
| | 240 | echo $tpl->draw( 'template_editor' ); |
|---|
| | 241 | |
|---|
| | 242 | $tpl->assign("debug", ""); |
|---|
| | 243 | |
|---|
| | 244 | } |
|---|
| | 245 | |
|---|
| | 246 | /** |
|---|
| | 247 | * Generates the Visual Display for the end user |
|---|
| | 248 | * @param <type> $cfg_data |
|---|
| | 249 | * @param <type> $custom_cfg_data |
|---|
| | 250 | * @param <type> $admin |
|---|
| | 251 | * @param <type> $user_cfg_data |
|---|
| | 252 | * @return <type> |
|---|
| | 253 | */ |
|---|
| | 254 | function generate_gui_html($cfg_data,$custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL) { |
|---|
| | 255 | //take the data out of the database and turn it back into an array for use |
|---|
| | 256 | $cfg_data = unserialize($cfg_data); |
|---|
| | 257 | $count = count($cfg_data); |
|---|
| | 258 | |
|---|
| | 259 | //Check to see if there is a custom template for this phone already listed in the endpointman_mac_list database |
|---|
| | 260 | if (isset($custom_cfg_data)) { |
|---|
| | 261 | $custom_cfg_data = unserialize($custom_cfg_data); |
|---|
| | 262 | } else { |
|---|
| | 263 | //No custom template so let's pull the default values for this model into the custom_cfg_data array and populate it from there so that we won't have to make two completely different functions below |
|---|
| | 264 | for($i=0;$i<$count;$i++) { |
|---|
| | 265 | $key_default = str_replace('$','',$cfg_data[$i]['variable']); |
|---|
| | 266 | if(!is_array($cfg_data[$i]['default_value'])) { |
|---|
| | 267 | $custom_cfg_data[$key_default]['value'] = $cfg_data[$i]['default_value']; |
|---|
| | 268 | |
|---|
| | 269 | } |
|---|
| | 270 | } |
|---|
| | 271 | } |
|---|
| | 272 | if(isset($user_cfg_data)) { |
|---|
| | 273 | $user_cfg_data = unserialize($user_cfg_data); |
|---|
| | 274 | } |
|---|
| | 275 | |
|---|
| | 276 | $template_variables_array = array(); |
|---|
| | 277 | |
|---|
| | 278 | $group_count = 0; |
|---|
| | 279 | //Fill the html form data with values from either the database or the default values to display to the end user |
|---|
| | 280 | for($i=0;$i<$count;$i++) { |
|---|
| | 281 | if(array_key_exists('variable',$cfg_data[$i])) { |
|---|
| | 282 | $key = str_replace('$','',$cfg_data[$i]['variable']); |
|---|
| | 283 | } else { |
|---|
| | 284 | $key = ""; |
|---|
| | 285 | } |
|---|
| | 286 | if(($admin) OR (isset($custom_cfg_data[$key]['ari']))) { |
|---|
| | 287 | //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! |
|---|
| | 288 | if(!isset($custom_cfg_data[$key]['value'])) { |
|---|
| | 289 | //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 |
|---|
| | 290 | if((array_key_exists('default_value',$cfg_data[$i])) AND (is_array($cfg_data[$i]['default_value']))) { |
|---|
| | 291 | $custom_cfg_data[$key]['value'] = ""; |
|---|
| | 292 | } elseif((array_key_exists('default_value',$cfg_data[$i])) AND (!is_array($cfg_data[$i]['default_value']))) { |
|---|
| | 293 | $custom_cfg_data[$key]['value'] = $cfg_data[$i]['default_value']; |
|---|
| | 294 | } |
|---|
| | 295 | } |
|---|
| | 296 | if ($cfg_data[$i]['type'] == "group") { |
|---|
| | 297 | $group_count++; |
|---|
| | 298 | $template_variables_array[$group_count]['title'] = $cfg_data[$i]['description']; |
|---|
| | 299 | $variables_count = 0; |
|---|
| | 300 | } elseif ($cfg_data[$i]['type'] == "input") { |
|---|
| | 301 | if((!$admin) && (isset($user_cfg_data[$key]['value']))) { |
|---|
| | 302 | $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; |
|---|
| | 303 | } |
|---|
| | 304 | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "input"; |
|---|
| | 305 | $template_variables_array[$group_count]['data'][$variables_count]['key'] = $key; |
|---|
| | 306 | $template_variables_array[$group_count]['data'][$variables_count]['value'] = $custom_cfg_data[$key]['value']; |
|---|
| | 307 | $template_variables_array[$group_count]['data'][$variables_count]['description'] = $cfg_data[$i]['description']; |
|---|
| | 308 | } elseif ($cfg_data[$i]['type'] == "radio") { |
|---|
| | 309 | if((!$admin) && (isset($user_cfg_data[$key]['value']))) { |
|---|
| | 310 | $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; |
|---|
| | 311 | } |
|---|
| | 312 | $num = $custom_cfg_data[$key]['value']; |
|---|
| | 313 | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "radio"; |
|---|
| | 314 | $template_variables_array[$group_count]['data'][$variables_count]['key'] = $key; |
|---|
| | 315 | $template_variables_array[$group_count]['data'][$variables_count]['description'] = $cfg_data[$i]['description']; |
|---|
| | 316 | $z = 0; |
|---|
| | 317 | while($z < count($cfg_data[$i]['data'])) { |
|---|
| | 318 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['key'] = $key; |
|---|
| | 319 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['value'] = $cfg_data[$i]['data'][$z]['value']; |
|---|
| | 320 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['description'] = $cfg_data[$i]['data'][$z]['text']; |
|---|
| | 321 | if ($cfg_data[$i]['data'][$z]['value'] == $num) { |
|---|
| | 322 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['checked'] = 'checked'; |
|---|
| | 323 | } |
|---|
| | 324 | $z++; |
|---|
| | 325 | } |
|---|
| | 326 | } elseif ($cfg_data[$i]['type'] == "list") { |
|---|
| | 327 | if((!$admin) && (isset($user_cfg_data[$key]['value']))) { |
|---|
| | 328 | $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; |
|---|
| | 329 | } |
|---|
| | 330 | $num = $custom_cfg_data[$key]['value']; |
|---|
| | 331 | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "list"; |
|---|
| | 332 | $template_variables_array[$group_count]['data'][$variables_count]['key'] = $key; |
|---|
| | 333 | $template_variables_array[$group_count]['data'][$variables_count]['description'] = $cfg_data[$i]['description']; |
|---|
| | 334 | $z = 0; |
|---|
| | 335 | while($z < count($cfg_data[$i]['data'])) { |
|---|
| | 336 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['value'] = $cfg_data[$i]['data'][$z]['value']; |
|---|
| | 337 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['description'] = $cfg_data[$i]['data'][$z]['text']; |
|---|
| | 338 | if ($cfg_data[$i]['data'][$z]['value'] == $num) { |
|---|
| | 339 | $template_variables_array[$group_count]['data'][$variables_count]['data'][$z]['selected'] = 'selected'; |
|---|
| | 340 | } |
|---|
| | 341 | $z++; |
|---|
| | 342 | } |
|---|
| | 343 | } elseif ($cfg_data[$i]['type'] == "break") { |
|---|
| | 344 | $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; |
|---|
| | 345 | } |
|---|
| | 346 | if(($this->global_cfg['enable_ari']) AND ($admin) AND ($cfg_data[$i]['type'] != "break") AND ($cfg_data[$i]['type'] != "group")) { |
|---|
| | 347 | $template_variables_array[$group_count]['data'][$variables_count]['aried'] = 1; |
|---|
| | 348 | $template_variables_array[$group_count]['data'][$variables_count]['ari']['key'] = $key; |
|---|
| | 349 | if(isset($custom_cfg_data[$key]['ari'])) { |
|---|
| | 350 | $template_variables_array[$group_count]['data'][$variables_count]['ari']['checked'] = "checked"; |
|---|
| | 351 | } |
|---|
| | 352 | } |
|---|
| | 353 | $variables_count++; |
|---|
| | 354 | } |
|---|
| | 355 | } |
|---|
| | 356 | return($template_variables_array); |
|---|
| | 357 | } |
|---|
| | 358 | |
|---|
| | 359 | function save_template($id, $custom, $variables) { |
|---|
| | 360 | //Custom Means specific to that MAC |
|---|
| | 361 | if($custom == "0") { |
|---|
| | 362 | $sql = "SELECT 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; |
|---|
| | 363 | } else { |
|---|
| | 364 | $sql = "SELECT 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"; |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | //Load template data |
|---|
| | 368 | $row =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); |
|---|
| | 369 | |
|---|
| | 370 | $cfg_data = unserialize($row['template_data']); |
|---|
| | 371 | $count = count($cfg_data); |
|---|
| | 372 | for($i=0;$i<$count;$i++) { |
|---|
| | 373 | if(array_key_exists('variable',$cfg_data[$i])) { |
|---|
| | 374 | $temping = str_replace('$','',$cfg_data[$i]['variable']); |
|---|
| | 375 | $temping_ari = "ari_" . $temping; |
|---|
| | 376 | if(array_key_exists($temping, $_REQUEST)) { |
|---|
| | 377 | $custom_cfg_data[$temping]['value'] = $_REQUEST[$temping]; |
|---|
| | 378 | if(array_key_exists($temping_ari, $_REQUEST)) { |
|---|
| | 379 | if($_REQUEST[$temping_ari] == "on") { |
|---|
| | 380 | $custom_cfg_data[$temping]['ari'] = 1; |
|---|
| | 381 | } |
|---|
| | 382 | } |
|---|
| | 383 | } |
|---|
| | 384 | } |
|---|
| | 385 | } |
|---|
| | 386 | |
|---|
| | 387 | $config_files = explode(",",$row['config_files']); |
|---|
| | 388 | $i = 0; |
|---|
| | 389 | while($i < count($config_files)) { |
|---|
| | 390 | $config_files[$i] = str_replace(".","_",$config_files[$i]); |
|---|
| | 391 | if(isset($_REQUEST[$config_files[$i]])) { |
|---|
| | 392 | if($_REQUEST[$config_files[$i]] > 0) { |
|---|
| | 393 | $config_files_selected[$config_files[$i]] = $_REQUEST[$config_files[$i]]; |
|---|
| | 394 | } |
|---|
| | 395 | } |
|---|
| | 396 | $i++; |
|---|
| | 397 | } |
|---|
| | 398 | if(!isset($config_files_selected)) { |
|---|
| | 399 | $config_files_selected = ""; |
|---|
| | 400 | } else { |
|---|
| | 401 | $config_files_selected = serialize($config_files_selected); |
|---|
| | 402 | } |
|---|
| | 403 | $save = serialize($custom_cfg_data); |
|---|
| | 404 | |
|---|
| | 405 | if($custom == "0") { |
|---|
| | 406 | $sql = 'UPDATE endpointman_template_list SET config_files_override = \''.addslashes($config_files_selected).'\', custom_cfg_data = \''.addslashes($save).'\' WHERE id ='.$id; |
|---|
| | 407 | $location = "template_manager"; |
|---|
| | 408 | } else { |
|---|
| | 409 | $sql = 'UPDATE endpointman_mac_list SET config_files_override = \''.addslashes($config_files_selected).'\', custom_cfg_template = 0, custom_cfg_data = \''.addslashes($save).'\' WHERE id ='.$id; |
|---|
| | 410 | $location = "devices_manager"; |
|---|
| | 411 | } |
|---|
| | 412 | $this->db->query($sql); |
|---|
| | 413 | |
|---|
| | 414 | $phone_info = ""; |
|---|
| | 415 | |
|---|
| | 416 | if($custom != 0) { |
|---|
| | 417 | $phone_info = $this->get_phone_info($id); |
|---|
| | 418 | $this->prepare_configs($phone_info); |
|---|
| | 419 | |
|---|
| | 420 | } else { |
|---|
| | 421 | $sql = 'SELECT id FROM endpointman_mac_list WHERE custom_cfg_template = '.$id; |
|---|
| | 422 | foreach($phones as $data) { |
|---|
| | 423 | $phone_info = $this->get_phone_info($data['id']); |
|---|
| | 424 | $this->prepare_configs($phone_info); |
|---|
| | 425 | } |
|---|
| | 426 | } |
|---|
| | 427 | |
|---|
| | 428 | return($location); |
|---|
| | 429 | |
|---|
| | 430 | } |
|---|
| | 431 | |
|---|
| | 432 | function prepare_configs($phone_info) { |
|---|
| | 433 | require(PHONE_MODULES_PATH.'setup.php'); |
|---|
| | 434 | |
|---|
| | 435 | $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; |
|---|
| | 436 | |
|---|
| | 437 | $provisioner_lib = new $class(); |
|---|
| | 438 | |
|---|
| | 439 | $provisioner_lib->root_dir = PHONE_MODULES_PATH; |
|---|
| | 440 | |
|---|
| | 441 | //have to because of versions less than php5.3 |
|---|
| | 442 | $provisioner_lib->brand_name = $phone_info['directory']; |
|---|
| | 443 | $provisioner_lib->family_line = $phone_info['cfg_dir']; |
|---|
| | 444 | |
|---|
| | 445 | //Mac Address |
|---|
| | 446 | $provisioner_lib->mac = $phone_info['mac']; |
|---|
| | 447 | |
|---|
| | 448 | //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models) |
|---|
| | 449 | $provisioner_lib->model = $phone_info['model']; |
|---|
| | 450 | |
|---|
| | 451 | //Timezone |
|---|
| | 452 | $provisioner_lib->timezone = $this->global_cfg['gmthr']; |
|---|
| | 453 | |
|---|
| | 454 | //Server IP |
|---|
| | 455 | $provisioner_lib->server[1]['ip'] = $this->global_cfg['srvip']; |
|---|
| | 456 | $provisioner_lib->server[1]['port'] = 5060; |
|---|
| | 457 | |
|---|
| | 458 | //Provide alternate Configuration file instead of the one from the hard drive |
|---|
| | 459 | //$endpoint->config_files_override['$mac.cfg'] = "{\$srvip}\n{\$admin_pass|0}\n{\$test.line.1}"; |
|---|
| | 460 | |
|---|
| | 461 | //Pretend we have three lines, we could just have one line or 20...whatever the phone supports |
|---|
| | 462 | $provisioner_lib->lines[1] = array('ext' => $phone_info['ext'], 'secret' => $phone_info['secret'], 'displayname' => $phone_info['description']); |
|---|
| | 463 | //$endpoint->lines[2] = array('ext' => '104', 'secret' => 'blah4', 'displayname' => 'Display Name'); |
|---|
| | 464 | //$endpoint->lines[3] = array('ext' => '105', 'secret' => 'blah5', 'displayname' => 'Other Account'); |
|---|
| | 465 | |
|---|
| | 466 | if(is_array($phone_info['template_data'])) { |
|---|
| | 467 | $template_data = unserialize($phone_info['template_data']['custom_cfg_data']); |
|---|
| | 468 | } else { |
|---|
| | 469 | $template_data = unserialize($phone_info['custom_cfg_data']); |
|---|
| | 470 | } |
|---|
| | 471 | |
|---|
| | 472 | $new_template_data = array(); |
|---|
| | 473 | foreach($template_data as $key => $data) { |
|---|
| | 474 | $new_template_data = array_merge($new_template_data, array($key => $data['value'])); |
|---|
| | 475 | } |
|---|
| | 476 | |
|---|
| | 477 | //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create |
|---|
| | 478 | //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included |
|---|
| | 479 | //line 'global' will set variables that aren't line dependant |
|---|
| | 480 | $provisioner_lib->options = $new_template_data; |
|---|
| | 481 | //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed |
|---|
| | 482 | //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 |
|---|
| | 483 | |
|---|
| | 484 | // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is |
|---|
| | 485 | $returned_data = $provisioner_lib->generate_config(); |
|---|
| | 486 | |
|---|
| | 487 | foreach($returned_data as $key => $data) { |
|---|
| | 488 | $fp = fopen("/tftpboot/".$key, 'w'); |
|---|
| | 489 | fwrite($fp, $data); |
|---|
| | 490 | fclose($fp); |
|---|
| | 491 | } |
|---|
| | 492 | |
|---|
| | 493 | unset($provisioner_lib); |
|---|
| | 494 | } |
|---|
| | 495 | |
|---|
| | 496 | function firmware_update_check($id=NULL) { |
|---|
| | 497 | $sql = "SELECT * FROM endpointman_product_list WHERE id =". $id; |
|---|
| | 498 | $result = mysql_query($sql); |
|---|
| | 499 | $row = mysql_fetch_array($result); |
|---|
| | 500 | |
|---|
| | 501 | $sql = "SELECT directory FROM endpointman_brand_list WHERE id =". $row['brand']; |
|---|
| | 502 | $result = mysql_query($sql); |
|---|
| | 503 | if(mysql_num_rows($result)) { |
|---|
| | 504 | $brand_row = mysql_fetch_array($result); |
|---|
| | 505 | |
|---|
| | 506 | //config drive unknown! |
|---|
| | 507 | if ($row['cfg_dir'] == "") { |
|---|
| | 508 | return FALSE; |
|---|
| | 509 | } else { |
|---|
| | 510 | $temp = $this->xml2array(PHONE_MODULES_PATH.$brand_row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| | 511 | if((array_key_exists('data',$temp)) AND (!is_array($temp['data']['firmware_ver']))) { |
|---|
| | 512 | if($row['firmware_vers'] < $temp['data']['firmware_ver']) { |
|---|
| | 513 | return $temp; |
|---|
| | 514 | } else { |
|---|
| | 515 | return FALSE; |
|---|
| | 516 | } |
|---|
| | 517 | } else { |
|---|
| | 518 | return FALSE; |
|---|
| | 519 | } |
|---|
| | 520 | } |
|---|
| | 521 | } else { |
|---|
| | 522 | return FALSE; |
|---|
| | 523 | } |
|---|
| | 524 | } |
|---|
| | 525 | |
|---|
| | 526 | function firmware_local_check($id=NULL) { |
|---|
| | 527 | $sql = "SELECT * FROM endpointman_product_list WHERE hidden = 0 AND id =". $id; |
|---|
| | 528 | $result = mysql_query($sql); |
|---|
| | 529 | if(mysql_num_rows($result)) { |
|---|
| | 530 | $row = mysql_fetch_array($result); |
|---|
| | 531 | |
|---|
| | 532 | $sql = "SELECT directory FROM endpointman_brand_list WHERE hidden = 0 AND id =". $row['brand']; |
|---|
| | 533 | $result = mysql_query($sql); |
|---|
| | 534 | $brand_row = mysql_fetch_array($result); |
|---|
| | 535 | |
|---|
| | 536 | //config drive unknown! |
|---|
| | 537 | if ($row['cfg_dir'] == "") { |
|---|
| | 538 | return("nothing"); |
|---|
| | 539 | } else { |
|---|
| | 540 | $temp = $this->xml2array(PHONE_MODULES_PATH.$brand_row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| | 541 | if((isset ($temp['data']['firmware_ver'])) AND (!is_array($temp['data']['firmware_ver']))) { |
|---|
| | 542 | if($row['firmware_vers'] == "") { |
|---|
| | 543 | return("install"); |
|---|
| | 544 | } else { |
|---|
| | 545 | return("remove"); |
|---|
| | 546 | } |
|---|
| | 547 | } else { |
|---|
| | 548 | return("nothing"); |
|---|
| | 549 | } |
|---|
| | 550 | } |
|---|
| | 551 | } else { |
|---|
| | 552 | return("nothing"); |
|---|
| | 553 | } |
|---|
| | 554 | } |
|---|
| | 555 | |
|---|
| | 556 | function remove_firmware($id=NULL) { |
|---|
| | 557 | global $global_cfg; |
|---|
| | 558 | $sql = "SELECT * FROM endpointman_product_list WHERE id =". $id; |
|---|
| | 559 | $result = mysql_query($sql); |
|---|
| | 560 | $row = mysql_fetch_array($result); |
|---|
| | 561 | |
|---|
| | 562 | $file_list = explode(",",$row['firmware_files']); |
|---|
| | 563 | $i = 0; |
|---|
| | 564 | while($i < count($file_list)) { |
|---|
| | 565 | unlink($global_cfg['config_location'].$file_list[$i]); |
|---|
| | 566 | $i++; |
|---|
| | 567 | } |
|---|
| | 568 | $sql = 'UPDATE endpointman_product_list SET firmware_files = "", firmware_vers = "" WHERE id = '.$id; |
|---|
| | 569 | mysql_query($sql); |
|---|
| | 570 | } |
|---|
| | 571 | |
|---|
| | 572 | function install_firmware($product_id) { |
|---|
| | 573 | global $global_cfg, $debug; |
|---|
| | 574 | $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; |
|---|
| | 575 | $result = mysql_query($sql); |
|---|
| | 576 | $row = mysql_fetch_array($result); |
|---|
| | 577 | $temp = $this->xml2array(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/template_data.xml"); |
|---|
| | 578 | if($temp['data']['firmware_ver'] > $row['firmware_vers']) { |
|---|
| | 579 | echo "<script>$('div.demo-container').text('Installing firmware');</script>"; |
|---|
| | 580 | $this->download_file_with_progress_bar(UPDATE_PATH . $temp['data']['firmware_pkg'], PHONE_MODULES_PATH."temp/".$temp['data']['firmware_pkg']); |
|---|
| | 581 | global $global_cfg, $endpoint; |
|---|
| | 582 | if(!file_exists(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware")) { |
|---|
| | 583 | mkdir(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware"); |
|---|
| | 584 | } |
|---|
| | 585 | exec("unzip ".PHONE_MODULES_PATH."temp/" . $temp['data']['firmware_pkg'] ." -d ".PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware/", $debug_a = array()); |
|---|
| | 586 | if ($handle = opendir(PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware/")) { |
|---|
| | 587 | while (false !== ($file = readdir($handle))) { |
|---|
| | 588 | if ($file != "." && $file != "..") { |
|---|
| | 589 | $list .= $file.","; |
|---|
| | 590 | } |
|---|
| | 591 | } |
|---|
| | 592 | closedir($handle); |
|---|
| | 593 | } |
|---|
| | 594 | $list = substr_replace($list ,"",-1); |
|---|
| | 595 | exec("cp -r " . PHONE_MODULES_PATH.$row['directory']."/".$row['cfg_dir']."/firmware/*.* ". $global_cfg['config_location'], $debug_a2 = array()); |
|---|
| | 596 | $sql = "UPDATE endpointman_product_list SET firmware_vers = '".$temp['data']['firmware_ver']."', firmware_files = '".$list."' WHERE id = ". $row['id']; |
|---|
| | 597 | mysql_query($sql); |
|---|
| | 598 | echo "<script>$('div.demo-container').text('Done!');</script>"; |
|---|
| | 599 | } else { |
|---|
| | 600 | echo "<script>$('div.demo-container').text('Your Firmware is already up to date');</script>"; |
|---|
| | 601 | |
|---|
| | 602 | } |
|---|
| | 603 | if($global_cfg['debug']) { |
|---|
| | 604 | $debug = array_merge($debug_a, $debug_a2); |
|---|
| | 605 | $outfile=LOCAL_PATH."debug_installer.log"; |
|---|
| | 606 | $wfh=fopen($outfile,'a'); |
|---|
| | 607 | fwrite($wfh,print_r($debug, TRUE)); |
|---|
| | 608 | fclose($wfh); |
|---|
| | 609 | } |
|---|
| | 610 | } |
|---|
| | 611 | |
|---|
| | 612 | function fix_single_array_keys($array) { |
|---|
| | 613 | if((empty($array[0])) AND (!empty($array))) { |
|---|
| | 614 | $array_n[0] = $array; |
|---|
| | 615 | return($array_n); |
|---|
| | 616 | } elseif(!empty($array)) { |
|---|
| | 617 | return($array); |
|---|
| | 618 | } else { |
|---|
| | 619 | return(""); |
|---|
| | 620 | } |
|---|
| | 621 | } |
|---|
| | 622 | |
|---|
| | 623 | function download_xml($location,$directory=NULL) { |
|---|
| | 624 | $handle = fopen($location, "rb"); |
|---|
| | 625 | if($handle === FALSE) { |
|---|
| | 626 | //Error with the internet....ABORRRTTTT THEEEEE DOWNLOAAAAADDDDDDDD! SCOTTYYYY!; |
|---|
| | 627 | return(FALSE); |
|---|
| | 628 | } else { |
|---|
| | 629 | $contents = ''; |
|---|
| | 630 | while (!feof($handle)) { |
|---|
| | 631 | $contents .= fread($handle, 8192); |
|---|
| | 632 | } |
|---|
| | 633 | @$a = simplexml_load_string($contents); |
|---|
| | 634 | if($a===FALSE) { |
|---|
| | 635 | //Error with the internet....ABORRRTTTT THEEEEE DOWNLOAAAAADDDDDDDD! SCOTTYYYY!; |
|---|
| | 636 | return(FALSE); |
|---|
| | 637 | } else { |
|---|
| | 638 | if(!isset($directory)) { |
|---|
| | 639 | $fp = fopen(PHONE_MODULES_PATH.'master.xml', 'w'); |
|---|
| | 640 | } else { |
|---|
| | 641 | if(!file_exists(PHONE_MODULES_PATH.'/'.$directory)) { |
|---|
| | 642 | mkdir(PHONE_MODULES_PATH.'/'.$directory); |
|---|
| | 643 | } |
|---|
| | 644 | $fp = fopen(PHONE_MODULES_PATH.'/'.$directory.'/brand_data.xml', 'w'); |
|---|
| | 645 | } |
|---|
| | 646 | fwrite($fp, $contents); |
|---|
| | 647 | fclose($fp); |
|---|
| | 648 | return(TRUE); |
|---|
| | 649 | } |
|---|
| | 650 | } |
|---|
| | 651 | fclose($handle); |
|---|
| | 652 | |
|---|
| | 653 | } |
|---|
| | 654 | |
|---|
| | 655 | //Check for new packges for brands. These packages will include phone models and such which the user can remove if they want |
|---|
| | 656 | function brand_update_check() { |
|---|
| | 657 | $result = $this->download_xml(UPDATE_PATH . "master.xml"); |
|---|
| | 658 | |
|---|
| | 659 | $message = NULL; |
|---|
| | 660 | |
|---|
| | 661 | if(!$result) { |
|---|
| | 662 | $message .= "Not able to connect to repository. Using local master file instead."; |
|---|
| | 663 | } |
|---|
| | 664 | |
|---|
| | 665 | $temp = $this->xml2array(PHONE_MODULES_PATH.'master.xml'); |
|---|
| | 666 | |
|---|
| | 667 | $endpoint_package = $temp['data']['package']; |
|---|
| | 668 | $endpoint_last_mod = $temp['data']['last_modified']; |
|---|
| | 669 | |
|---|
| | 670 | $sql = "SELECT value FROM endpointman_global_vars WHERE var_name LIKE 'endpoint_vers'"; |
|---|
| | 671 | $data =& $this->db->getOne($sql); |
|---|
| | 672 | |
|---|
| | 673 | if(($data == "") OR ($data <= $endpoint_last_mod)) { |
|---|
| | 674 | $this->download_file_with_progress_bar(UPDATE_PATH.'/'.$endpoint_package, PHONE_MODULES_PATH."temp/".$endpoint_package); |
|---|
| | 675 | exec("tar -xvf ".PHONE_MODULES_PATH.'temp/'. $endpoint_package ." -C ".PHONE_MODULES_PATH."temp/"); |
|---|
| | 676 | |
|---|
| | 677 | if(!file_exists(PHONE_MODULES_PATH."endpoint")) { |
|---|
| | 678 | mkdir(PHONE_MODULES_PATH."endpoint"); |
|---|
| | 679 | } |
|---|
| | 680 | |
|---|
| | 681 | //rename(PHONE_MODULES_PATH."temp/setup.php", PHONE_MODULES_PATH."setup.php"); |
|---|
| | 682 | |
|---|
| | 683 | |
|---|
| | 684 | rename(PHONE_MODULES_PATH."temp/endpoint/base.php", PHONE_MODULES_PATH."endpoint/base.php"); |
|---|
| | 685 | |
|---|
| | 686 | $sql = "UPDATE endpointman_global_vars SET value = '".$endpoint_last_mod."' WHERE var_name = 'endpoint_vers'"; |
|---|
| | 687 | $this->db->query($sql); |
|---|
| | 688 | } |
|---|
| | 689 | |
|---|
| | 690 | |
|---|
| | 691 | $out = $temp['data']['brands']; |
|---|
| | 692 | |
|---|
| | 693 | $row =& $this->db->getAll('SELECT * FROM endpointman_brand_list WHERE id > 0', array(), DB_FETCHMODE_ASSOC); |
|---|
| | 694 | |
|---|
| | 695 | foreach($out as $data) { |
|---|
| | 696 | //TODO: Make this pull from the local directory |
|---|
| | 697 | $result = $this->download_xml(UPDATE_PATH .$data['directory']."/".$data['directory'].".xml","endpoint/".$data['directory']); |
|---|
| | 698 | if(!$result) { |
|---|
| | 699 | $message .= "<br/>Not able to connect to repository. Using local brand [".$data['name']."] file instead."; |
|---|
| | 700 | } |
|---|
| | 701 | |
|---|
| | 702 | if(file_exists(PHONE_MODULES_PATH."endpoint/".$data['directory']."/brand_data.xml")) { |
|---|
| | 703 | $temp = $this->xml2array(PHONE_MODULES_PATH."endpoint/".$data['directory']."/brand_data.xml"); |
|---|
| | 704 | |
|---|
| | 705 | $temp = $temp['data']['brands']; |
|---|
| | 706 | |
|---|
| | 707 | $temp['oui_list']['oui'] = $this->fix_single_array_keys($temp['oui_list']['oui']); |
|---|
| | 708 | |
|---|
| | 709 | foreach($temp['oui_list']['oui'] as $oui) { |
|---|
| | 710 | $sql = "INSERT INTO endpointman_oui_list (`oui`, `brand`, `custom`) VALUES ('".$oui."', '".$temp['brand_id']."', '0')"; |
|---|
| | 711 | $this->db->query($sql); |
|---|
| | 712 | |
|---|
| | 713 | } |
|---|
| | 714 | |
|---|
| | 715 | $brand_name = $data['directory']; |
|---|
| | 716 | $version[$brand_name] = $temp['version']; |
|---|
| | 717 | |
|---|
| | 718 | if(!($this->arraysearchrecursive($brand_name, $row, 'directory'))) { |
|---|
| | 719 | //insert row |
|---|
| | 720 | $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver) VALUES ('".$temp['brand_id']."', '".$temp['name']."', '".$temp['directory']."', '".$temp['version']."')"; |
|---|
| | 721 | $this->db->query($sql); |
|---|
| | 722 | } else { |
|---|
| | 723 | //in database already! |
|---|
| | 724 | } |
|---|
| | 725 | } else { |
|---|
| | 726 | $message .= "<br/>Error: No Local File for ".$data['name']."!"; |
|---|
| | 727 | } |
|---|
| | 728 | } |
|---|
| | 729 | |
|---|
| | 730 | foreach($row as $ava_brands) { |
|---|
| | 731 | $key = $this->arraysearchrecursive($ava_brands['directory'], $out, 'directory'); |
|---|
| | 732 | if($key === FALSE) { |
|---|
| | 733 | $this->remove_brand($ava_brands['id']); |
|---|
| | 734 | } else { |
|---|
| | 735 | $key = $key[0]; |
|---|
| | 736 | |
|---|
| | 737 | $brand_name = $ava_brands['directory']; |
|---|
| | 738 | |
|---|
| | 739 | if($ava_brands['cfg_ver'] < $version[$brand_name]) { |
|---|
| | 740 | $out[$key]['update'] = 1; |
|---|
| | 741 | $out[$key]['update_vers'] = $version[$brand_name]; |
|---|
| | 742 | } else { |
|---|
| | 743 | $out[$key]['update'] = NULL; |
|---|
| | 744 | } |
|---|
| | 745 | } |
|---|
| | 746 | } |
|---|
| | 747 | |
|---|
| | 748 | $this->error['brand_update_check'] = $message; |
|---|
| | 749 | |
|---|
| | 750 | return $out; |
|---|
| | 751 | } |
|---|
| | 752 | |
|---|
| | 753 | //Version 2.5 good |
|---|
| | 754 | //Still needs way to determine when models move...perhaps another function? |
|---|
| | 755 | function update_brand($id = NULL) { |
|---|
| | 756 | $row =& $this->db->getAll('SELECT * FROM endpointman_brand_list WHERE id ='.$id, array(), DB_FETCHMODE_ASSOC); |
|---|
| | 757 | |
|---|
| | 758 | echo "Downloading Brand XML....."; |
|---|
| | 759 | $result = $this->download_xml(UPDATE_PATH .$row[0]['directory']. "/".$row[0]['directory'].".xml","endpoint/".$row[0]['directory']); |
|---|
| | 760 | if($result) { |
|---|
| | 761 | echo "Done!<br/>"; |
|---|
| | 762 | |
|---|
| | 763 | $temp = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$row[0]['directory'].'/brand_data.xml'); |
|---|
| | 764 | |
|---|
| | 765 | $brand_name = $temp['data']['brands']['name']; |
|---|
| | 766 | $brand_id = $temp['data']['brands']['brand_id']; |
|---|
| | 767 | $brand_version = $temp['data']['brands']['version']; |
|---|
| | 768 | $package = $temp['data']['brands']['package']; |
|---|
| | 769 | |
|---|
| | 770 | echo "Updating data.........."; |
|---|
| | 771 | $sql = "UPDATE endpointman_brand_list SET name = '".$brand_name."', cfg_ver = '".$brand_version."', installed = 1, hidden = 0 WHERE id = ".$id; |
|---|
| | 772 | $this->db->query($sql); |
|---|
| | 773 | echo "Done!<br/>"; |
|---|
| | 774 | |
|---|
| | 775 | echo "Downloading Tarball......."; |
|---|
| | 776 | $this->download_file_with_progress_bar(UPDATE_PATH.$row[0]['directory'].'/'.$package, PHONE_MODULES_PATH."temp/".$package); |
|---|
| | 777 | echo "Done!<br />"; |
|---|
| | 778 | |
|---|
| | 779 | echo "Extracting Tarball........"; |
|---|
| | 780 | exec("tar -xvf ".PHONE_MODULES_PATH.'temp/'. $package ." -C ".PHONE_MODULES_PATH."temp/"); |
|---|
| | 781 | echo "Done!<br />"; |
|---|
| | 782 | |
|---|
| | 783 | echo "Creating Directory Structure/Moving Files..............."; |
|---|
| | 784 | $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/"); |
|---|
| | 785 | $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); |
|---|
| | 786 | // could use CHILD_FIRST if you so wish |
|---|
| | 787 | |
|---|
| | 788 | foreach ($iterator as $file) { |
|---|
| | 789 | if(is_dir($file)) { |
|---|
| | 790 | $dir = str_replace(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/", "", $file); |
|---|
| | 791 | if(!file_exists(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir)) { |
|---|
| | 792 | mkdir(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir); |
|---|
| | 793 | } |
|---|
| | 794 | } else { |
|---|
| | 795 | if(basename($file) != "brand_data.xml") { |
|---|
| | 796 | $dir = str_replace(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/", "", $file); |
|---|
| | 797 | rename($file, PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir); |
|---|
| | 798 | } |
|---|
| | 799 | } |
|---|
| | 800 | } |
|---|
| | 801 | echo "Done!<br />"; |
|---|
| | 802 | |
|---|
| | 803 | echo "Removing Temporary Files.............."; |
|---|
| | 804 | $this->deltree(PHONE_MODULES_PATH."temp/" .$row[0]['directory']); |
|---|
| | 805 | unlink(PHONE_MODULES_PATH.'temp/'. $package); |
|---|
| | 806 | echo "Done!<br />"; |
|---|
| | 807 | |
|---|
| | 808 | |
|---|
| | 809 | $temp['data']['brands']['family_list']['family'] = $this->fix_single_array_keys($temp['data']['brands']['family_list']['family']); |
|---|
| | 810 | foreach($temp['data']['brands']['family_list']['family'] as $family_list) { |
|---|
| | 811 | echo "Updating Family Lines.................<br/>"; |
|---|
| | 812 | $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$row[0]['directory'].'/'.$family_list['directory'].'/family_data.xml'); |
|---|
| | 813 | $data =& $this->db->getOne("SELECT id FROM endpointman_product_list WHERE id='".$brand_id."-".$family_line_xml['data']['id']."'", array(), DB_FETCHMODE_ASSOC); |
|---|
| | 814 | $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); |
|---|
| | 815 | if($data) { |
|---|
| | 816 | $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']."', hidden = '0' WHERE id = '".$brand_id."-".$family_line_xml['data']['id']."'"; |
|---|
| | 817 | } else { |
|---|
| | 818 | $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')"; |
|---|
| | 819 | } |
|---|
| | 820 | |
|---|
| | 821 | $this->db->query($sql); |
|---|
| | 822 | $family_line_xml['data']['model_list'] = $this->fix_single_array_keys($family_line_xml['data']['model_list']); |
|---|
| | 823 | echo "--Updating Model Lines................<br/>"; |
|---|
| | 824 | foreach($family_line_xml['data']['model_list'] as $model_list) { |
|---|
| | 825 | if(is_array($model_list['template_data']['files'])) { |
|---|
| | 826 | $template_list = implode(",",$model_list['template_data']['files']); |
|---|
| | 827 | } else { |
|---|
| | 828 | $template_list = $model_list['template_data']['files']; |
|---|
| | 829 | } |
|---|
| | 830 | $m_data =& $this->db->getOne("SELECT id FROM endpointman_model_list WHERE id='".$brand_id."-".$family_line_xml['data']['id']."-".$model_list['id']."'", array(), DB_FETCHMODE_ASSOC); |
|---|
| | 831 | if($m_data) { |
|---|
| | 832 | $sql = "UPDATE endpointman_model_list SET model = '".$model_list['model']."', template_list = '".$template_list."', enabled = '0', hidden = '0' WHERE id = '".$brand_id."-".$family_line_xml['data']['id']."'"; |
|---|
| | 833 | } else { |
|---|
| | 834 | $sql = "INSERT INTO endpointman_model_list (`id`, `brand`, `model`, `product_id`, `template_list`, `enabled`, `hidden`) VALUES ('".$brand_id."-".$family_line_xml['data']['id']."-".$model_list['id']."', '".$brand_id."', '".$model_list['model']."', '".$brand_id."-".$family_line_xml['data']['id']."', '".$template_list."', '0', '0')"; |
|---|
| | 835 | } |
|---|
| | 836 | $this->db->query($sql); |
|---|
| | 837 | } |
|---|
| | 838 | } |
|---|
| | 839 | } else { |
|---|
| | 840 | echo "<br/>Error Connecting to the Package Repository. Module not installed. Please Try again later."; |
|---|
| | 841 | } |
|---|
| | 842 | } |
|---|
| | 843 | |
|---|
| | 844 | //Version 2.5 good |
|---|
| | 845 | function remove_brand($id=NULL) { |
|---|
| | 846 | $brand_dir =& $this->db->getOne("SELECT directory FROM endpointman_brand_list WHERE id=".$id); |
|---|
| | 847 | |
|---|
| | 848 | $sql = "DELETE FROM endpointman_model_list WHERE brand = '". $id."'"; |
|---|
| | 849 | $this->db->query($sql); |
|---|
| | 850 | |
|---|
| | 851 | $sql = "DELETE FROM endpointman_product_list WHERE brand = '". $id . "'"; |
|---|
| | 852 | $this->db->query($sql); |
|---|
| | 853 | |
|---|
| | 854 | $sql = "DELETE FROM endpointman_oui_list WHERE brand = '". $id . "'"; |
|---|
| | 855 | $this->db->query($sql); |
|---|
| | 856 | |
|---|
| | 857 | $this->deltree(PHONE_MODULES_PATH .$brand_dir); |
|---|
| | 858 | $sql = "DELETE FROM endpointman_brand_list WHERE id = ". $id; |
|---|
| | 859 | |
|---|
| | 860 | $this->db->query($sql); |
|---|
| | 861 | } |
|---|
| | 862 | |
|---|
| | 863 | function sync_model($model=NULL) { |
|---|
| | 864 | |
|---|
| | 865 | //TODO: combine these queries |
|---|
| | 866 | |
|---|
| | 867 | $sql = "SELECT * FROM endpointman_model_list WHERE id='".$model."'"; |
|---|
| | 868 | |
|---|
| | 869 | $model_id = explode("-",$model); |
|---|
| | 870 | |
|---|
| | 871 | $model_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 872 | |
|---|
| | 873 | $sql = "SELECT * FROM endpointman_product_list WHERE id='".$model_row['product_id']."'"; |
|---|
| | 874 | |
|---|
| | 875 | $product_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 876 | |
|---|
| | 877 | $sql = "SELECT * FROM endpointman_brand_list WHERE id=".$model_row['brand']; |
|---|
| | 878 | |
|---|
| | 879 | |
|---|
| | 880 | $brand_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 881 | |
|---|
| | 882 | |
|---|
| | 883 | $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/family_data.xml'); |
|---|
| | 884 | |
|---|
| | 885 | if($product_row['cfg_ver'] <= $family_line_xml['data']['version']) { |
|---|
| | 886 | $key = $this->arraysearchrecursive($model_id[2], $family_line_xml['data']['model_list'], 'id'); |
|---|
| | 887 | |
|---|
| | 888 | if($key === FALSE) { |
|---|
| | 889 | return(FALSE); |
|---|
| | 890 | } else { |
|---|
| | 891 | $key[0]; |
|---|
| | 892 | if(is_array($family_line_xml['data']['model_list'][$key[0]]['template_data']['files'])) { |
|---|
| | 893 | $template_list = implode(",",$family_line_xml['data']['model_list'][$key[0]]['template_data']['files']); |
|---|
| | 894 | $template_list_array = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 895 | } else { |
|---|
| | 896 | $template_list = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 897 | $template_list_array[0] = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 898 | } |
|---|
| | 899 | } |
|---|
| | 900 | |
|---|
| | 901 | $sql = "UPDATE endpointman_model_list SET template_list = '".$template_list."' WHERE id = '".$model."'"; |
|---|
| | 902 | $this->db->query($sql); |
|---|
| | 903 | |
|---|
| | 904 | $version = $family_line_xml['data']['version']; |
|---|
| | 905 | $long_name = $family_line_xml['data']['name']; |
|---|
| | 906 | $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); |
|---|
| | 907 | $configuration_files = $family_line_xml['data']['configuration_files']; |
|---|
| | 908 | |
|---|
| | 909 | $sql = "UPDATE endpointman_product_list SET long_name = '".$template_list."', short_name = '".$short_name."' , cfg_ver = '".$version."', WHERE id = '".$product_row['id']."'"; |
|---|
| | 910 | $this->db->query($sql); |
|---|
| | 911 | |
|---|
| | 912 | $template_data_array = array(); |
|---|
| | 913 | foreach($template_list_array as $data) { |
|---|
| | 914 | if(file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data)) { |
|---|
| | 915 | $template_data_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data); |
|---|
| | 916 | $template_data_xml = $this->fix_single_array_keys($template_data_xml['template_data']['item']); |
|---|
| | 917 | $template_data_array = array_merge($template_data_array, $template_data_xml); |
|---|
| | 918 | } |
|---|
| | 919 | } |
|---|
| | 920 | |
|---|
| | 921 | if (file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_custom.xml')) { |
|---|
| | 922 | $template_data_multi = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_custom.xml'); |
|---|
| | 923 | $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); |
|---|
| | 924 | $template_data_array = array_merge($template_data_array, $template_data_multi); |
|---|
| | 925 | } |
|---|
| | 926 | |
|---|
| | 927 | if (file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_' . $model_row['model'] . '_custom.xml')) { |
|---|
| | 928 | $template_data_multi = $this->xml2array(self::$modules_path . $this->brand_name . "/" . $this->family_line . "/template_data_" . $this->model . "_custom.xml"); |
|---|
| | 929 | $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); |
|---|
| | 930 | $template_data_array = array_merge($template_data_array, $template_data_multi); |
|---|
| | 931 | } |
|---|
| | 932 | |
|---|
| | 933 | if(empty($template_data_array)) { |
|---|
| | 934 | return(FALSE); |
|---|
| | 935 | } |
|---|
| | 936 | |
|---|
| | 937 | $sql = "UPDATE endpointman_model_list SET template_data = '".serialize($template_data_array)."' WHERE id = '".$model."'"; |
|---|
| | 938 | $this->db->query($sql); |
|---|
| | 939 | } |
|---|
| | 940 | |
|---|
| | 941 | return(TRUE); |
|---|
| | 942 | } |
|---|
| | 943 | |
|---|
| | 944 | function arraysearchrecursive($Needle,$Haystack,$NeedleKey="",$Strict=false,$Path=array()) { |
|---|
| | 945 | if(!is_array($Haystack)) |
|---|
| | 946 | return false; |
|---|
| | 947 | foreach($Haystack as $Key => $Val) { |
|---|
| | 948 | if(is_array($Val)&& |
|---|
| | 949 | $SubPath=$this->arraysearchrecursive($Needle,$Val,$NeedleKey,$Strict,$Path)) { |
|---|
| | 950 | $Path=array_merge($Path,Array($Key),$SubPath); |
|---|
| | 951 | return $Path; |
|---|
| | 952 | } |
|---|
| | 953 | elseif((!$Strict&&$Val==$Needle&& |
|---|
| | 954 | $Key==(strlen($NeedleKey)>0?$NeedleKey:$Key))|| |
|---|
| | 955 | ($Strict&&$Val===$Needle&& |
|---|
| | 956 | $Key==(strlen($NeedleKey)>0?$NeedleKey:$Key))) { |
|---|
| | 957 | $Path[]=$Key; |
|---|
| | 958 | return $Path; |
|---|
| | 959 | } |
|---|
| | 960 | } |
|---|
| | 961 | return false; |
|---|
| | 962 | } |
|---|
| | 963 | //Below is pfSense code |
|---|
| | 964 | function download_file_with_progress_bar($url_file, $destination_file) { |
|---|
| | 965 | global $ch, $fout, $file_size, $downloaded, $pkg_interface; |
|---|
| | 966 | set_time_limit(0); |
|---|
| | 967 | $file_size = 1; |
|---|
| | 968 | $downloaded = 1; |
|---|
| | 969 | /* open destination file */ |
|---|
| | 970 | $fout = fopen($destination_file, "wb"); |
|---|
| | 971 | |
|---|
| | 972 | /* |
|---|
| 1005 | | */ |
|---|
| 1006 | | |
|---|
| 1007 | | $ch = curl_init(); |
|---|
| 1008 | | curl_setopt($ch, CURLOPT_URL, $url_file); |
|---|
| 1009 | | curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'endpointmanager_read_header'); |
|---|
| 1010 | | curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'endpointmanager_read_body'); |
|---|
| 1011 | | curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); |
|---|
| 1012 | | curl_setopt($ch, CURLOPT_TIMEOUT, 0); |
|---|
| 1013 | | |
|---|
| 1014 | | curl_exec($ch); |
|---|
| 1015 | | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|---|
| 1016 | | if($fout) |
|---|
| 1017 | | fclose($fout); |
|---|
| 1018 | | curl_close($ch); |
|---|
| 1019 | | return ($http_code == 200) ? true : $http_code; |
|---|
| 1020 | | } |
|---|
| 1021 | | //end pfSense code |
|---|
| 1022 | | |
|---|
| 1023 | | //This function looks in common linux directories for system executable files. Like ARP & NMAP |
|---|
| 1024 | | function find_exec($exec) { |
|---|
| 1025 | | $usr_bin = glob("/usr/bin/".$exec); |
|---|
| 1026 | | $usr_sbin = glob("/usr/sbin/".$exec); |
|---|
| 1027 | | $sbin = glob("/sbin/".$exec); |
|---|
| 1028 | | $bin = glob("/bin/".$exec); |
|---|
| 1029 | | $etc = glob("/etc/".$exec); |
|---|
| 1030 | | if(isset($usr_bin[0])) { |
|---|
| 1031 | | return("/usr/bin/".$exec); |
|---|
| 1032 | | } elseif(isset($usr_sbin[0])) { |
|---|
| 1033 | | return("/usr/sbin/".$exec); |
|---|
| 1034 | | } elseif(isset($sbin[0])) { |
|---|
| 1035 | | return("/sbin/".$exec); |
|---|
| 1036 | | } elseif(isset($bin[0])) { |
|---|
| 1037 | | return("/bin/".$exec); |
|---|
| 1038 | | } elseif(isset($etc[0])) { |
|---|
| 1039 | | return("/etc/".$exec); |
|---|
| 1040 | | } else { |
|---|
| 1041 | | return($exec); |
|---|
| 1042 | | } |
|---|
| 1043 | | } |
|---|
| 1044 | | |
|---|
| 1045 | | //Delete Directory Tree, Doesn't work. though |
|---|
| 1046 | | function deltree($dir) { |
|---|
| 1047 | | $this->rmrf($dir); |
|---|
| 1048 | | } |
|---|
| 1049 | | |
|---|
| 1050 | | function rmrf($dir) { |
|---|
| 1051 | | foreach (glob($dir) as $file) { |
|---|
| 1052 | | if (is_dir($file)) { |
|---|
| 1053 | | $this->rmrf("$file/*"); |
|---|
| 1054 | | rmdir($file); |
|---|
| 1055 | | } else { |
|---|
| 1056 | | unlink($file); |
|---|
| 1057 | | } |
|---|
| 1058 | | } |
|---|
| 1059 | | } |
|---|
| 1060 | | |
|---|
| 1061 | | |
|---|
| 1062 | | function table_exists ($table) { |
|---|
| 1063 | | $sql = "SHOW TABLES FROM asterisk"; |
|---|
| 1064 | | $result = mysql_query($sql); |
|---|
| 1065 | | |
|---|
| 1066 | | while ($row = mysql_fetch_row($result)) { |
|---|
| 1067 | | if ($row[0] == $table) { |
|---|
| 1068 | | return TRUE; |
|---|
| 1069 | | } |
|---|
| 1070 | | } |
|---|
| 1071 | | return FALSE; |
|---|
| 1072 | | } |
|---|
| 1073 | | |
|---|
| 1074 | | /** |
|---|
| 1075 | | Parse XML file into an array |
|---|
| 1076 | | Taken from Sister Project SuperFecta |
|---|
| 1077 | | */ |
|---|
| 1078 | | function xml2array($url, $get_attributes = 1, $priority = 'tag') |
|---|
| 1079 | | { |
|---|
| 1080 | | $contents = ""; |
|---|
| 1081 | | if (!function_exists('xml_parser_create')) |
|---|
| 1082 | | { |
|---|
| 1083 | | return array (); |
|---|
| 1084 | | } |
|---|
| 1085 | | $parser = xml_parser_create(''); |
|---|
| 1086 | | if(!($fp = @ fopen($url, 'rb'))) |
|---|
| 1087 | | { |
|---|
| 1088 | | return array (); |
|---|
| 1089 | | } |
|---|
| 1090 | | while(!feof($fp)) |
|---|
| 1091 | | { |
|---|
| 1092 | | $contents .= fread($fp, 8192); |
|---|
| 1093 | | } |
|---|
| 1094 | | fclose($fp); |
|---|
| 1095 | | xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); |
|---|
| 1096 | | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
|---|
| 1097 | | xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
|---|
| 1098 | | xml_parse_into_struct($parser, trim($contents), $xml_values); |
|---|
| 1099 | | xml_parser_free($parser); |
|---|
| 1100 | | if(!$xml_values) |
|---|
| 1101 | | { |
|---|
| 1102 | | return; //Hmm... |
|---|
| 1103 | | } |
|---|
| 1104 | | $xml_array = array (); |
|---|
| 1105 | | $parents = array (); |
|---|
| 1106 | | $opened_tags = array (); |
|---|
| 1107 | | $arr = array (); |
|---|
| 1108 | | $current = & $xml_array; |
|---|
| 1109 | | $repeated_tag_index = array (); |
|---|
| 1110 | | foreach ($xml_values as $data) |
|---|
| 1111 | | { |
|---|
| 1112 | | unset ($attributes, $value); |
|---|
| 1113 | | extract($data); |
|---|
| 1114 | | $result = array (); |
|---|
| 1115 | | $attributes_data = array (); |
|---|
| 1116 | | if (isset ($value)) |
|---|
| 1117 | | { |
|---|
| 1118 | | if($priority == 'tag') |
|---|
| 1119 | | { |
|---|
| 1120 | | $result = $value; |
|---|
| 1121 | | } |
|---|
| 1122 | | else |
|---|
| 1123 | | { |
|---|
| 1124 | | $result['value'] = $value; |
|---|
| 1125 | | } |
|---|
| 1126 | | } |
|---|
| 1127 | | if(isset($attributes) and $get_attributes) |
|---|
| 1128 | | { |
|---|
| 1129 | | foreach($attributes as $attr => $val) |
|---|
| 1130 | | { |
|---|
| 1131 | | if($priority == 'tag') |
|---|
| 1132 | | { |
|---|
| 1133 | | $attributes_data[$attr] = $val; |
|---|
| 1134 | | } |
|---|
| 1135 | | else |
|---|
| 1136 | | { |
|---|
| 1137 | | $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' |
|---|
| 1138 | | } |
|---|
| 1139 | | } |
|---|
| 1140 | | } |
|---|
| 1141 | | if ($type == "open") |
|---|
| 1142 | | { |
|---|
| 1143 | | $parent[$level -1] = & $current; |
|---|
| 1144 | | if(!is_array($current) or (!in_array($tag, array_keys($current)))) |
|---|
| 1145 | | { |
|---|
| 1146 | | $current[$tag] = $result; |
|---|
| 1147 | | if($attributes_data) |
|---|
| 1148 | | { |
|---|
| 1149 | | $current[$tag . '_attr'] = $attributes_data; |
|---|
| 1150 | | } |
|---|
| 1151 | | $repeated_tag_index[$tag . '_' . $level] = 1; |
|---|
| 1152 | | $current = & $current[$tag]; |
|---|
| 1153 | | } |
|---|
| 1154 | | else |
|---|
| 1155 | | { |
|---|
| 1156 | | if (isset ($current[$tag][0])) |
|---|
| 1157 | | { |
|---|
| 1158 | | $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|---|
| 1159 | | $repeated_tag_index[$tag . '_' . $level]++; |
|---|
| 1160 | | } |
|---|
| 1161 | | else |
|---|
| 1162 | | { |
|---|
| 1163 | | $current[$tag] = array($current[$tag],$result); |
|---|
| 1164 | | $repeated_tag_index[$tag . '_' . $level] = 2; |
|---|
| 1165 | | if(isset($current[$tag . '_attr'])) |
|---|
| 1166 | | { |
|---|
| 1167 | | $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|---|
| 1168 | | unset ($current[$tag . '_attr']); |
|---|
| 1169 | | } |
|---|
| 1170 | | } |
|---|
| 1171 | | $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; |
|---|
| 1172 | | $current = & $current[$tag][$last_item_index]; |
|---|
| 1173 | | } |
|---|
| 1174 | | } |
|---|
| 1175 | | else if($type == "complete") |
|---|
| 1176 | | { |
|---|
| 1177 | | if(!isset ($current[$tag])) |
|---|
| 1178 | | { |
|---|
| 1179 | | $current[$tag] = $result; |
|---|
| 1180 | | $repeated_tag_index[$tag . '_' . $level] = 1; |
|---|
| 1181 | | if($priority == 'tag' and $attributes_data) |
|---|
| 1182 | | { |
|---|
| 1183 | | $current[$tag . '_attr'] = $attributes_data; |
|---|
| 1184 | | } |
|---|
| 1185 | | } |
|---|
| 1186 | | else |
|---|
| 1187 | | { |
|---|
| 1188 | | if (isset ($current[$tag][0]) and is_array($current[$tag])) |
|---|
| 1189 | | { |
|---|
| 1190 | | $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|---|
| 1191 | | if ($priority == 'tag' and $get_attributes and $attributes_data) |
|---|
| 1192 | | { |
|---|
| 1193 | | $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|---|
| 1194 | | } |
|---|
| 1195 | | $repeated_tag_index[$tag . '_' . $level]++; |
|---|
| 1196 | | } |
|---|
| 1197 | | else |
|---|
| 1198 | | { |
|---|
| 1199 | | $current[$tag] = array($current[$tag],$result); |
|---|
| 1200 | | $repeated_tag_index[$tag . '_' . $level] = 1; |
|---|
| 1201 | | if ($priority == 'tag' and $get_attributes) |
|---|
| 1202 | | { |
|---|
| 1203 | | if (isset ($current[$tag . '_attr'])) |
|---|
| 1204 | | { |
|---|
| 1205 | | $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|---|
| 1206 | | unset ($current[$tag . '_attr']); |
|---|
| 1207 | | } |
|---|
| 1208 | | if ($attributes_data) |
|---|
| 1209 | | { |
|---|
| 1210 | | $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|---|
| 1211 | | } |
|---|
| 1212 | | } |
|---|
| 1213 | | $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken |
|---|
| 1214 | | } |
|---|
| 1215 | | } |
|---|
| 1216 | | } |
|---|
| 1217 | | else if($type == 'close') |
|---|
| 1218 | | { |
|---|
| 1219 | | $current = & $parent[$level -1]; |
|---|
| 1220 | | } |
|---|
| 1221 | | } |
|---|
| 1222 | | return ($xml_array); |
|---|
| 1223 | | } |
|---|
| 1224 | | |
|---|
| 1225 | | //This function takes a string and tries to determine if it's a valid mac addess, return FALSE if invalid |
|---|
| 1226 | | function mac_check_clean($mac) { |
|---|
| 1227 | | if ((strlen($mac) == "17") OR (strlen($mac) == "12")) { |
|---|
| 1228 | | //It might be better to use switch here instead of these IF statements... |
|---|
| 1229 | | |
|---|
| 1230 | | //Is the mac separated by colons(:)? |
|---|
| 1231 | | if (preg_match("/[0-9a-f][0-9a-f][:-]". |
|---|
| 1232 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1233 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1234 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1235 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1236 | | "[0-9a-f][0-9a-f]/i", $mac)) { |
|---|
| 1237 | | return(strtoupper(str_replace(":", "", $mac))); |
|---|
| 1238 | | //Is the string exactly 12 characters? |
|---|
| 1239 | | } elseif(strlen($mac) == "12") { |
|---|
| 1240 | | //Now is the string a valid HEX mac address? |
|---|
| 1241 | | if (preg_match("/[0-9a-f][0-9a-f]". |
|---|
| 1242 | | "[0-9a-f][0-9a-f]". |
|---|
| 1243 | | "[0-9a-f][0-9a-f]". |
|---|
| 1244 | | "[0-9a-f][0-9a-f]". |
|---|
| 1245 | | "[0-9a-f][0-9a-f]". |
|---|
| 1246 | | "[0-9a-f][0-9a-f]/i", $mac)) { |
|---|
| 1247 | | return(strtoupper($mac)); |
|---|
| 1248 | | } else { |
|---|
| 1249 | | return(FALSE); |
|---|
| 1250 | | } |
|---|
| 1251 | | //Is the mac separated by whitespaces? |
|---|
| 1252 | | } elseif(preg_match("/[0-9a-f][0-9a-f][\s]". |
|---|
| 1253 | | "[0-9a-f][0-9a-f][\s]". |
|---|
| 1254 | | "[0-9a-f][0-9a-f][\s]". |
|---|
| 1255 | | "[0-9a-f][0-9a-f][\s]". |
|---|
| 1256 | | "[0-9a-f][0-9a-f][\s]". |
|---|
| 1257 | | "[0-9a-f][0-9a-f]/i", $mac)) { |
|---|
| 1258 | | return(strtoupper(str_replace(" ", "", $mac))); |
|---|
| 1259 | | } else { |
|---|
| 1260 | | return(FALSE); |
|---|
| 1261 | | } |
|---|
| 1262 | | } else { |
|---|
| 1263 | | return(FALSE); |
|---|
| 1264 | | } |
|---|
| 1265 | | } |
|---|
| 1266 | | |
|---|
| 1267 | | function validate_netmask($mask) { |
|---|
| 1268 | | if (preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/", $mask)) { |
|---|
| 1269 | | return(TRUE); |
|---|
| 1270 | | } else { |
|---|
| 1271 | | return(FALSE); |
|---|
| 1272 | | } |
|---|
| 1273 | | } |
|---|
| 1274 | | |
|---|
| 1275 | | //Discover New Device/Hardware |
|---|
| 1276 | | function discover_new($netmask, $use_nmap=TRUE) { |
|---|
| 1277 | | global $global_cfg, $debug, $error; |
|---|
| 1278 | | //Written by tm1000 |
|---|
| 1279 | | //Version 1.0 |
|---|
| 1280 | | |
|---|
| 1281 | | //nmap will actually discover 'unseen' devices that the VoIP server hasn't heard from |
|---|
| 1282 | | //If the user just wishes to use the local arp cache they can tell the function to not use nmap |
|---|
| 1283 | | //This results in a speed increase from 60 seconds to less than one second. |
|---|
| 1284 | | if (($use_nmap) AND ($this->validate_netmask($netmask))) { |
|---|
| 1285 | | shell_exec($global_cfg['nmap_location'].' -v -sP '. $netmask); |
|---|
| 1286 | | } elseif(!$this->validate_netmask($netmask)) { |
|---|
| 1287 | | return(FALSE); |
|---|
| 1288 | | } |
|---|
| 1289 | | //Get arp list |
|---|
| 1290 | | $arp_list = shell_exec($global_cfg['arp_location'] . " -an"); |
|---|
| 1291 | | //$arp_list = shell_exec("arp -an"); |
|---|
| 1292 | | if($global_cfg['debug']) { |
|---|
| 1293 | | $debug .= "ARP LIST:\n".$arp_list; |
|---|
| 1294 | | } |
|---|
| 1295 | | //Throw arp list into an array, break by new lines |
|---|
| 1296 | | $arp_array = explode("\n", $arp_list); |
|---|
| 1297 | | |
|---|
| 1298 | | //Find all references to active computers by searching out mac addresses. |
|---|
| 1299 | | $temp = array_values(array_unique(preg_grep("/[0-9a-f][0-9a-f][:-]". |
|---|
| 1300 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1301 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1302 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1303 | | "[0-9a-f][0-9a-f][:-]". |
|---|
| 1304 | | "[0-9a-f][0-9a-f]/i", $arp_array))); |
|---|
| 1305 | | |
|---|
| 1306 | | if($global_cfg['debug']) { |
|---|
| 1307 | | $arp_arry = print_r($temp, true); |
|---|
| 1308 | | $debug .= "ARP Array:\n".$arp_arry; |
|---|
| 1309 | | } |
|---|
| 1310 | | //Go through each row of valid arp entries and pull out the information and add it into a nice array! |
|---|
| 1311 | | foreach ($temp as $key => &$value) { |
|---|
| 1312 | | |
|---|
| 1313 | | //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 |
|---|
| 1314 | | $ip = trim(substr($value, 0, 15)); |
|---|
| 1315 | | |
|---|
| 1316 | | //Pull out the mac address by looking for the delimiter |
|---|
| 1317 | | $mac = substr($value, (strpos($value, ":") -2), 17); |
|---|
| 1318 | | |
|---|
| 1319 | | //Get rid of the delimiter |
|---|
| 1320 | | $mac_strip = strtoupper(str_replace(":", "", $mac)); |
|---|
| 1321 | | |
|---|
| 1322 | | //arp -n will return a MAC address of 000000000000 if no hardware was found, so we need to ignore it |
|---|
| 1323 | | if($mac_strip != "000000000000") { |
|---|
| 1324 | | //only use the first 6 characters for the oui: http://en.wikipedia.org/wiki/Organizationally_Unique_Identifier |
|---|
| 1325 | | $oui = substr($mac_strip,0,6); |
|---|
| 1326 | | |
|---|
| 1327 | | //Find the matching brand model to the oui |
|---|
| 1328 | | $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"; |
|---|
| 1329 | | |
|---|
| 1330 | | |
|---|
| 1331 | | $brand_result = mysql_query($oui_sql); |
|---|
| 1332 | | $brand = mysql_fetch_row($brand_result); |
|---|
| 1333 | | if ($brand == FALSE) { |
|---|
| 1334 | | //oui doesn't have a matching mysql reference, probably a PC/router/wap/printer of some sort. |
|---|
| 1335 | | $brand[0] = FALSE; |
|---|
| 1336 | | $brand[1] = NULL; |
|---|
| 1337 | | } |
|---|
| 1338 | | |
|---|
| 1339 | | //Find out if endpoint has already been configured for this mac address |
|---|
| 1340 | | $epm_sql = "SELECT * FROM endpointman_mac_list WHERE mac LIKE '%". $mac_strip ."%'"; |
|---|
| 1341 | | $epm_result = mysql_query($epm_sql); |
|---|
| 1342 | | $epm_row = mysql_fetch_row($epm_result); |
|---|
| 1343 | | if ($epm_row == TRUE) { |
|---|
| 1344 | | $epm = TRUE; |
|---|
| 1345 | | } else { |
|---|
| 1346 | | $epm = FALSE; |
|---|
| 1347 | | } |
|---|
| 1348 | | |
|---|
| 1349 | | //Add into a final array |
|---|
| 1350 | | $final[$key] = array("ip" => $ip, "mac" => $mac, "mac_strip" => $mac_strip, "oui" => $oui, "brand" => $brand[0], "brand_id" => $brand[1], "endpoint_managed" => $epm); |
|---|
| 1351 | | } |
|---|
| 1352 | | } |
|---|
| 1353 | | $final = array_values($final); |
|---|
| 1354 | | if($global_cfg['debug']) { |
|---|
| 1355 | | $arp_arry = print_r($final, true); |
|---|
| 1356 | | $debug .= "Final output from 'discover_new' function:\n".$arp_arry; |
|---|
| 1357 | | } |
|---|
| 1358 | | if(!is_array($final)) { |
|---|
| 1359 | | return(FALSE); |
|---|
| 1360 | | } else { |
|---|
| 1361 | | return ($final); |
|---|
| 1362 | | } |
|---|
| 1363 | | } |
|---|
| 1364 | | |
|---|
| 1365 | | //Function Works |
|---|
| 1366 | | function dblogin() { //Database login |
|---|
| 1367 | | global $amp_conf, $db, $endpoint_db, $ep_link; |
|---|
| 1368 | | |
|---|
| 1369 | | /* FUTURE |
|---|
| 1370 | | if (is_object($db)) { |
|---|
| 1371 | | //I 'think' we are freepbxv2 |
|---|
| 1372 | | include('databases/freepbxv2.inc'); |
|---|
| 1373 | | } else { |
|---|
| 1374 | | //Standalone |
|---|
| 1375 | | include('databases/mysql.inc'); |
|---|
| 1376 | | } |
|---|
| 1377 | | */ |
|---|
| 1378 | | |
|---|
| 1379 | | //Re-written to get rid of duplicate references to one database |
|---|
| 1380 | | |
|---|
| 1381 | | //connect to the mysql system |
|---|
| 1382 | | $ep_link=mysql_connect('localhost', $amp_conf['AMPDBUSER'], $amp_conf['AMPDBPASS']); |
|---|
| 1383 | | if ($ep_link == FALSE) { |
|---|
| 1384 | | die("Sorry, We can't connect to your database :-(\nTry checking /etc/amportal.conf for the correct settings"); |
|---|
| 1385 | | } |
|---|
| 1386 | | //connect to the only useable asterisk database, need to look this up in the amportal.conf really because someone could change it |
|---|
| 1387 | | $success = mysql_select_db($amp_conf['AMPDBNAME'],$ep_link); |
|---|
| 1388 | | if ($success== FALSE) { |
|---|
| 1389 | | die("Sorry, We can't FIND your database, but we COULD connect to MySQL :-/\nDoes Asterisk & FreePBX exist on this server?"); |
|---|
| 1390 | | } |
|---|
| 1391 | | } |
|---|
| 1392 | | |
|---|
| 1393 | | function modelsAvailable($model=NULL, $macAdd=NULL, $brand=NULL) { |
|---|
| 1394 | | if (isset($macAdd)) { |
|---|
| 1395 | | $oui=substr($macAdd,0,6); |
|---|
| 1396 | | } |
|---|
| 1397 | | if ((!isset($oui)) && (!isset($brand)) && (!isset($model))) { |
|---|
| 1398 | | $sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.installed = 1"; |
|---|
| 1399 | | }elseif(isset($brand)){ |
|---|
| 1400 | | $sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.installed = 1 AND endpointman_model_list.brand = " . $brand; |
|---|
| 1401 | | } |
|---|
| 1402 | | $result1=mysql_query($sql); |
|---|
| 1403 | | if(mysql_num_rows($result1)) { |
|---|
| 1404 | | $i = 1; |
|---|
| 1405 | | while ($row=mysql_fetch_array($result1)) { |
|---|
| 1406 | | if ($row['id'] == $model) { |
|---|
| 1407 | | $temp[$i]['value'] = $row['id']; |
|---|
| 1408 | | $temp[$i]['text'] = $row['model']; |
|---|
| 1409 | | $temp[$i]['selected'] = 'selected'; |
|---|
| 1410 | | }else{ |
|---|
| 1411 | | $temp[$i]['value'] = $row['id']; |
|---|
| 1412 | | $temp[$i]['text'] = $row['model']; |
|---|
| 1413 | | $temp[$i]['selected'] = 0; |
|---|
| 1414 | | } |
|---|
| 1415 | | $i++; |
|---|
| 1416 | | } |
|---|
| 1417 | | } |
|---|
| 1418 | | if(!isset($temp)) { |
|---|
| 1419 | | global $error, $global_cfg, $debug, $ep_link; |
|---|
| 1420 | | if($global_cfg['debug']) { |
|---|
| 1421 | | $debug .= "Error in function 'modelsAvailable'\nSQL:". $sql; |
|---|
| 1422 | | $debug .= mysql_error($ep_link); |
|---|
| 1423 | | } |
|---|
| 1424 | | return(FALSE); |
|---|
| 1425 | | } else { |
|---|
| 1426 | | return($temp); |
|---|
| 1427 | | } |
|---|
| 1428 | | } |
|---|
| 1429 | | |
|---|
| 1430 | | function displayExtension($ext = NULL) { |
|---|
| 1431 | | if(!isset($ext)) { |
|---|
| 1432 | | $not_added="SELECT devices.id, devices.description FROM devices WHERE devices.id not in (SELECT devices.id FROM devices, endpointman_mac_list WHERE tech='sip' AND devices.id = endpointman_mac_list.ext )"; |
|---|
| 1433 | | } else { |
|---|
| 1434 | | $not_added="SELECT devices.id, devices.description FROM devices WHERE devices.id not in (SELECT devices.id FROM devices, endpointman_mac_list WHERE tech='sip' AND devices.id = endpointman_mac_list.ext AND endpointman_mac_list.ext !=".$ext." )"; |
|---|
| 1435 | | } |
|---|
| 1436 | | |
|---|
| 1437 | | $result=mysql_query($not_added); |
|---|
| 1438 | | |
|---|
| 1439 | | //$temp[0]['value'] = ""; |
|---|
| 1440 | | //$temp[0]['text'] = " --- "; |
|---|
| 1441 | | //$temp[0]['selected'] = 1; |
|---|
| 1442 | | $i = 1; |
|---|
| 1443 | | while ($row=mysql_fetch_array($result)) { |
|---|
| 1444 | | $temp[$i]['value'] = $row['id']; |
|---|
| 1445 | | $temp[$i]['text'] = $row['id'] . " --- " . $row['description']; |
|---|
| 1446 | | if ($row['id'] == $ext) { |
|---|
| 1447 | | $temp[$i]['selected'] = "selected"; |
|---|
| 1448 | | } |
|---|
| 1449 | | $i++; |
|---|
| 1450 | | } |
|---|
| 1451 | | return($temp); |
|---|
| 1452 | | |
|---|
| 1453 | | } |
|---|
| 1454 | | |
|---|
| 1455 | | function brandAvailable ($selected = NULL) { |
|---|
| 1456 | | $i = 1; |
|---|
| 1457 | | $sql="SELECT name, id FROM endpointman_brand_list WHERE installed = 1"; |
|---|
| 1458 | | $result=mysql_query($sql); |
|---|
| 1459 | | $temp[0]['value'] = ""; |
|---|
| 1460 | | $temp[0]['text'] = ""; |
|---|
| 1461 | | while ($row=mysql_fetch_array($result)) { |
|---|
| 1462 | | $temp[$i]['value'] = $row['id']; |
|---|
| 1463 | | $temp[$i]['text'] = $row['name']; |
|---|
| 1464 | | if ($row['id'] == $selected) { |
|---|
| 1465 | | $temp[$i]['selected'] = TRUE; |
|---|
| 1466 | | } else { |
|---|
| 1467 | | $temp[$i]['selected'] = NULL; |
|---|
| 1468 | | } |
|---|
| 1469 | | $i++; |
|---|
| 1470 | | } |
|---|
| 1471 | | return($temp); |
|---|
| 1472 | | } |
|---|
| 1473 | | |
|---|
| 1474 | | function display_templates($product_id,$temp_select = NULL) { |
|---|
| 1475 | | $i = 0; |
|---|
| 1476 | | $sql="SELECT * FROM endpointman_product_list WHERE endpointman_product_list.id =".$product_id; |
|---|
| 1477 | | $result=mysql_query($sql); |
|---|
| 1478 | | $row=mysql_fetch_array($result); |
|---|
| 1479 | | $sql="SELECT * FROM endpointman_template_list WHERE product_id = '".$row['id']."'"; |
|---|
| 1480 | | $result=mysql_query($sql); |
|---|
| 1481 | | while ($row=mysql_fetch_array($result)) { |
|---|
| 1482 | | $temp[$i]['value'] = $row['id']; |
|---|
| 1483 | | $temp[$i]['text'] = $row['name']; |
|---|
| 1484 | | if ($row['id'] == $temp_select) { |
|---|
| 1485 | | $temp[$i]['selected'] = "selected"; |
|---|
| 1486 | | } |
|---|
| 1487 | | $i++; |
|---|
| 1488 | | } |
|---|
| 1489 | | $temp[$i]['value'] = 0; |
|---|
| 1490 | | if ($temp_select == 0) { |
|---|
| 1491 | | $temp[$i]['text'] = "Custom..."; |
|---|
| 1492 | | $temp[$i]['selected'] = "selected"; |
|---|
| 1493 | | } else { |
|---|
| 1494 | | $temp[$i]['text'] = "Custom..."; |
|---|
| 1495 | | } |
|---|
| 1496 | | return($temp); |
|---|
| 1497 | | } |
|---|
| 1498 | | |
|---|
| 1499 | | function listTZ($selected) { |
|---|
| 1500 | | $sql="SELECT tz from endpointman_time_zones"; |
|---|
| 1501 | | $result=mysql_query($sql); |
|---|
| 1502 | | $i = 0; |
|---|
| 1503 | | while ($row=mysql_fetch_array($result)) { |
|---|
| 1504 | | if ($row['tz'] == $selected) { |
|---|
| 1505 | | $temp[$i]['value'] = $row['tz']; |
|---|
| 1506 | | $temp[$i]['text'] = $row['tz']; |
|---|
| 1507 | | $temp[$i]['selected'] = 1; |
|---|
| 1508 | | }else{ |
|---|
| 1509 | | $temp[$i]['value'] = $row['tz']; |
|---|
| 1510 | | $temp[$i]['text'] = $row['tz']; |
|---|
| 1511 | | $temp[$i]['selected'] = 0; |
|---|
| 1512 | | } |
|---|
| 1513 | | $i++; |
|---|
| 1514 | | } |
|---|
| 1515 | | return($temp); |
|---|
| 1516 | | } |
|---|
| 1517 | | |
|---|
| 1518 | | function rebootPhone($ext,$datav) { |
|---|
| 1519 | | if (is_numeric($ext)) { |
|---|
| 1520 | | } elseif ($ext == 'all') { |
|---|
| 1521 | | $sql = "SELECT endpointman_mac_list.id , endpointman_brand_list.directory , endpointman_product_list.cfg_dir FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list, endpointman_product_list WHERE endpointman_mac_list.model = endpointman_model_list.id AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_model_list.brand =endpointman_brand_list.id"; |
|---|
| 1522 | | $result = mysql_query($sql); |
|---|
| 1523 | | while($row = mysql_fetch_assoc($result)) { |
|---|
| 1524 | | if(($cfg_dir == $row['cfg_dir']) AND ($directory == $row['directory'])) { |
|---|
| 1525 | | $phone_config->reboot($row['id']); |
|---|
| 1526 | | } else { |
|---|
| 1527 | | if(isset($phone_config)) { |
|---|
| 1528 | | unset($phone_config); |
|---|
| 1529 | | } |
|---|
| 1530 | | $directory = $row['directory']; |
|---|
| 1531 | | $cfg_dir = $row['cfg_dir']; |
|---|
| 1532 | | require(PHONE_MODULES_PATH.$row['directory'].'/'.$row['cfg_dir'].'/functions.inc'); |
|---|
| 1533 | | $phone_config = new $row['cfg_dir'](); |
|---|
| 1534 | | $phone_config->reboot($row['id']); |
|---|
| 1535 | | } |
|---|
| 1536 | | } |
|---|
| 1537 | | } else { |
|---|
| 1538 | | $sql = "SELECT endpointman_brand_list.directory, endpointman_product_list.cfg_dir, endpointman_mac_list.id FROM endpointman_brand_list, endpointman_model_list, endpointman_mac_list, endpointman_product_list WHERE endpointman_brand_list.id = ".$datav['rb_brand']." AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_model_list.product_id = endpointman_product_list.id"; |
|---|
| 1539 | | $result = mysql_query($sql); |
|---|
| 1540 | | while($row = mysql_fetch_assoc($result)) { |
|---|
| 1541 | | if(($cfg_dir == $row['cfg_dir']) AND ($directory == $row['directory'])) { |
|---|
| 1542 | | $phone_config->reboot($row['id']); |
|---|
| 1543 | | } else { |
|---|
| 1544 | | if(isset($phone_config)) { |
|---|
| 1545 | | unset($phone_config); |
|---|
| 1546 | | } |
|---|
| 1547 | | $directory = $row['directory']; |
|---|
| 1548 | | $cfg_dir = $row['cfg_dir']; |
|---|
| 1549 | | require(PHONE_MODULES_PATH.$row['directory'].'/'.$row['cfg_dir'].'/functions.inc'); |
|---|
| 1550 | | $phone_config = new $row['cfg_dir'](); |
|---|
| 1551 | | $phone_config->reboot($row['id']); |
|---|
| 1552 | | } |
|---|
| 1553 | | } |
|---|
| 1554 | | } |
|---|
| 1555 | | } |
|---|
| | 975 | */ |
|---|
| | 976 | |
|---|
| | 977 | $ch = curl_init(); |
|---|
| | 978 | curl_setopt($ch, CURLOPT_URL, $url_file); |
|---|
| | 979 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'endpointmanager_read_header'); |
|---|
| | 980 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'endpointmanager_read_body'); |
|---|
| | 981 | curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); |
|---|
| | 982 | curl_setopt($ch, CURLOPT_TIMEOUT, 0); |
|---|
| | 983 | |
|---|
| | 984 | curl_exec($ch); |
|---|
| | 985 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|---|
| | 986 | if($fout) |
|---|
| | 987 | fclose($fout); |
|---|
| | 988 | curl_close($ch); |
|---|
| | 989 | return ($http_code == 200) ? true : $http_code; |
|---|
| | 990 | } |
|---|
| | 991 | //end pfSense code |
|---|
| | 992 | |
|---|
| | 993 | //This function looks in common linux directories for system executable files. Like ARP & NMAP |
|---|
| | 994 | function find_exec($exec) { |
|---|
| | 995 | $usr_bin = glob("/usr/bin/".$exec); |
|---|
| | 996 | $usr_sbin = glob("/usr/sbin/".$exec); |
|---|
| | 997 | $sbin = glob("/sbin/".$exec); |
|---|
| | 998 | $bin = glob("/bin/".$exec); |
|---|
| | 999 | $etc = glob("/etc/".$exec); |
|---|
| | 1000 | if(isset($usr_bin[0])) { |
|---|
| | 1001 | return("/usr/bin/".$exec); |
|---|
| | 1002 | } elseif(isset($usr_sbin[0])) { |
|---|
| | 1003 | return("/usr/sbin/".$exec); |
|---|
| | 1004 | } elseif(isset($sbin[0])) { |
|---|
| | 1005 | return("/sbin/".$exec); |
|---|
| | 1006 | } elseif(isset($bin[0])) { |
|---|
| | 1007 | return("/bin/".$exec); |
|---|
| | 1008 | } elseif(isset($etc[0])) { |
|---|
| | 1009 | return("/etc/".$exec); |
|---|
| | 1010 | } else { |
|---|
| | 1011 | return($exec); |
|---|
| | 1012 | } |
|---|
| | 1013 | } |
|---|
| | 1014 | |
|---|
| | 1015 | //Delete Directory Tree, Doesn't work. though |
|---|
| | 1016 | function deltree($dir) { |
|---|
| | 1017 | $this->rmrf($dir); |
|---|
| | 1018 | } |
|---|
| | 1019 | |
|---|
| | 1020 | function rmrf($dir) { |
|---|
| | 1021 | foreach (glob($dir) as $file) { |
|---|
| | 1022 | if (is_dir($file)) { |
|---|
| | 1023 | $this->rmrf("$file/*"); |
|---|
| | 1024 | rmdir($file); |
|---|
| | 1025 | } else { |
|---|
| | 1026 | unlink($file); |
|---|
| | 1027 | } |
|---|
| | 1028 | } |
|---|
| | 1029 | } |
|---|
| | 1030 | |
|---|
| | 1031 | |
|---|
| | 1032 | function table_exists ($table) { |
|---|
| | 1033 | $sql = "SHOW TABLES FROM asterisk"; |
|---|
| | 1034 | $result = mysql_query($sql); |
|---|
| | 1035 | |
|---|
| | 1036 | while ($row = mysql_fetch_row($result)) { |
|---|
| | 1037 | if ($row[0] == $table) { |
|---|
| | 1038 | return TRUE; |
|---|
| | 1039 | } |
|---|
| | 1040 | } |
|---|
| | 1041 | return FALSE; |
|---|
| | 1042 | } |
|---|
| | 1043 | |
|---|
| | 1044 | /** |
|---|
| | 1045 | Parse XML file into an array |
|---|
| | 1046 | Taken from Sister Project SuperFecta |
|---|
| | 1047 | */ |
|---|
| | 1048 | function xml2array($url, $get_attributes = 1, $priority = 'tag') { |
|---|
| | 1049 | $contents = ""; |
|---|
| | 1050 | if (!function_exists('xml_parser_create')) { |
|---|
| | 1051 | return array (); |
|---|
| | 1052 | } |
|---|
| | 1053 | $parser = xml_parser_create(''); |
|---|
| | 1054 | if(!($fp = @ fopen($url, 'rb'))) { |
|---|
| | 1055 | return array (); |
|---|
| | 1056 | } |
|---|
| | 1057 | while(!feof($fp)) { |
|---|
| | 1058 | $contents .= fread($fp, 8192); |
|---|
| | 1059 | } |
|---|
| | 1060 | fclose($fp); |
|---|
| | 1061 | xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); |
|---|
| | 1062 | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
|---|
| | 1063 | xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
|---|
| | 1064 | xml_parse_into_struct($parser, trim($contents), $xml_values); |
|---|
| | 1065 | xml_parser_free($parser); |
|---|
| | 1066 | if(!$xml_values) { |
|---|
| | 1067 | return; //Hmm... |
|---|
| | 1068 | } |
|---|
| | 1069 | $xml_array = array (); |
|---|
| | 1070 | $parents = array (); |
|---|
| | 1071 | $opened_tags = array (); |
|---|
| | 1072 | $arr = array (); |
|---|
| | 1073 | $current = & $xml_array; |
|---|
| | 1074 | $repeated_tag_index = array (); |
|---|
| | 1075 | foreach ($xml_values as $data) { |
|---|
| | 1076 | unset ($attributes, $value); |
|---|
| | 1077 | extract($data); |
|---|
| | 1078 | $result = array (); |
|---|
| | 1079 | $attributes_data = array (); |
|---|
| | 1080 | if (isset ($value)) { |
|---|
| | 1081 | if($priority == 'tag') { |
|---|
| | 1082 | $result = $value; |
|---|
| | 1083 | } |
|---|
| | 1084 | else { |
|---|
| | 1085 | $result['value'] = $value; |
|---|
| | 1086 | } |
|---|
| | 1087 | } |
|---|
| | 1088 | if(isset($attributes) and $get_attributes) { |
|---|
| | 1089 | foreach($attributes as $attr => $val) { |
|---|
| | 1090 | if($priority == 'tag') { |
|---|
| | 1091 | $attributes_data[$attr] = $val; |
|---|
| | 1092 | } |
|---|
| | 1093 | else { |
|---|
| | 1094 | $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' |
|---|
| | 1095 | } |
|---|
| | 1096 | } |
|---|
| | 1097 | } |
|---|
| | 1098 | if ($type == "open") { |
|---|
| | 1099 | $parent[$level -1] = & $current; |
|---|
| | 1100 | if(!is_array($current) or (!in_array($tag, array_keys($current)))) { |
|---|
| | 1101 | $current[$tag] = $result; |
|---|
| | 1102 | if($attributes_data) { |
|---|
| | 1103 | $current[$tag . '_attr'] = $attributes_data; |
|---|
| | 1104 | } |
|---|
| | 1105 | $repeated_tag_index[$tag . '_' . $level] = 1; |
|---|
| | 1106 | $current = & $current[$tag]; |
|---|
| | 1107 | } |
|---|
| | 1108 | else { |
|---|
| | 1109 | if (isset ($current[$tag][0])) { |
|---|
| | 1110 | $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|---|
| | 1111 | $repeated_tag_index[$tag . '_' . $level]++; |
|---|
| | 1112 | } |
|---|
| | 1113 | else { |
|---|
| | 1114 | $current[$tag] = array($current[$tag],$result); |
|---|
| | 1115 | $repeated_tag_index[$tag . '_' . $level] = 2; |
|---|
| | 1116 | if(isset($current[$tag . '_attr'])) { |
|---|
| | 1117 | $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|---|
| | 1118 | unset ($current[$tag . '_attr']); |
|---|
| | 1119 | } |
|---|
| | 1120 | } |
|---|
| | 1121 | $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; |
|---|
| | 1122 | $current = & $current[$tag][$last_item_index]; |
|---|
| | 1123 | } |
|---|
| | 1124 | } |
|---|
| | 1125 | else if($type == "complete") { |
|---|
| | 1126 | if(!isset ($current[$tag])) { |
|---|
| | 1127 | $current[$tag] = $result; |
|---|
| | 1128 | $repeated_tag_index[$tag . '_' . $level] = 1; |
|---|
| | 1129 | if($priority == 'tag' and $attributes_data) { |
|---|
| | 1130 | $current[$tag . '_attr'] = $attributes_data; |
|---|
| | 1131 | } |
|---|
| | 1132 | } |
|---|
| | 1133 | else { |
|---|
| | 1134 | if (isset ($current[$tag][0]) and is_array($current[$tag])) { |
|---|
| | 1135 | $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|---|
| | 1136 | if ($priority == 'tag' and $get_attributes and $attributes_data) { |
|---|
| | 1137 | $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|---|
| | 1138 | } |
|---|
| | 1139 | $repeated_tag_index[$tag . '_' . $level]++; |
|---|
| | 1140 | } |
|---|
| | 1141 | else { |
|---|
| | 1142 | $current[$tag] = array($current[$tag],$result); |
|---|
| | 1143 | $repeated_tag_index[$tag . '_' . $level] = 1; |
|---|
| | 1144 | if ($priority == 'tag' and $get_attributes) { |
|---|
| | 1145 | if (isset ($current[$tag . '_attr'])) { |
|---|
| | 1146 | $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|---|
| | 1147 | unset ($current[$tag . '_attr']); |
|---|
| | 1148 | } |
|---|
| | 1149 | if ($attributes_data) { |
|---|
| | 1150 | $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|---|
| | 1151 | } |
|---|
| | 1152 | } |
|---|
| | 1153 | $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken |
|---|
| | 1154 | } |
|---|
| | 1155 | } |
|---|
| | 1156 | } |
|---|
| | 1157 | else if($type == 'close') { |
|---|
| | 1158 | $current = & $parent[$level -1]; |
|---|
| | 1159 | } |
|---|
| | 1160 | } |
|---|
| | 1161 | return ($xml_array); |
|---|
| | 1162 | } |
|---|
| | 1163 | |
|---|
| | 1164 | //This function takes a string and tries to determine if it's a valid mac addess, return FALSE if invalid |
|---|
| | 1165 | function mac_check_clean($mac) { |
|---|
| | 1166 | if ((strlen($mac) == "17") OR (strlen($mac) == "12")) { |
|---|
| | 1167 | //It might be better to use switch here instead of these IF statements... |
|---|
| | 1168 | |
|---|
| | 1169 | //Is the mac separated by colons(:)? |
|---|
| | 1170 | if (preg_match("/[0-9a-f][0-9a-f][:-]". |
|---|
| | 1171 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1172 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1173 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1174 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1175 | "[0-9a-f][0-9a-f]/i", $mac)) { |
|---|
| | 1176 | return(strtoupper(str_replace(":", "", $mac))); |
|---|
| | 1177 | //Is the string exactly 12 characters? |
|---|
| | 1178 | } elseif(strlen($mac) == "12") { |
|---|
| | 1179 | //Now is the string a valid HEX mac address? |
|---|
| | 1180 | if (preg_match("/[0-9a-f][0-9a-f]". |
|---|
| | 1181 | "[0-9a-f][0-9a-f]". |
|---|
| | 1182 | "[0-9a-f][0-9a-f]". |
|---|
| | 1183 | "[0-9a-f][0-9a-f]". |
|---|
| | 1184 | "[0-9a-f][0-9a-f]". |
|---|
| | 1185 | "[0-9a-f][0-9a-f]/i", $mac)) { |
|---|
| | 1186 | return(strtoupper($mac)); |
|---|
| | 1187 | } else { |
|---|
| | 1188 | return(FALSE); |
|---|
| | 1189 | } |
|---|
| | 1190 | //Is the mac separated by whitespaces? |
|---|
| | 1191 | } elseif(preg_match("/[0-9a-f][0-9a-f][\s]". |
|---|
| | 1192 | "[0-9a-f][0-9a-f][\s]". |
|---|
| | 1193 | "[0-9a-f][0-9a-f][\s]". |
|---|
| | 1194 | "[0-9a-f][0-9a-f][\s]". |
|---|
| | 1195 | "[0-9a-f][0-9a-f][\s]". |
|---|
| | 1196 | "[0-9a-f][0-9a-f]/i", $mac)) { |
|---|
| | 1197 | return(strtoupper(str_replace(" ", "", $mac))); |
|---|
| | 1198 | } else { |
|---|
| | 1199 | return(FALSE); |
|---|
| | 1200 | } |
|---|
| | 1201 | } else { |
|---|
| | 1202 | return(FALSE); |
|---|
| | 1203 | } |
|---|
| | 1204 | } |
|---|
| | 1205 | |
|---|
| | 1206 | function validate_netmask($mask) { |
|---|
| | 1207 | if (preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/", $mask)) { |
|---|
| | 1208 | return(TRUE); |
|---|
| | 1209 | } else { |
|---|
| | 1210 | return(FALSE); |
|---|
| | 1211 | } |
|---|
| | 1212 | } |
|---|
| | 1213 | |
|---|
| | 1214 | //Discover New Device/Hardware |
|---|
| | 1215 | function discover_new($netmask, $use_nmap=TRUE) { |
|---|
| | 1216 | global $global_cfg, $debug, $error; |
|---|
| | 1217 | //Written by tm1000 |
|---|
| | 1218 | //Version 1.0 |
|---|
| | 1219 | |
|---|
| | 1220 | //nmap will actually discover 'unseen' devices that the VoIP server hasn't heard from |
|---|
| | 1221 | //If the user just wishes to use the local arp cache they can tell the function to not use nmap |
|---|
| | 1222 | //This results in a speed increase from 60 seconds to less than one second. |
|---|
| | 1223 | if (($use_nmap) AND ($this->validate_netmask($netmask))) { |
|---|
| | 1224 | shell_exec($global_cfg['nmap_location'].' -v -sP '. $netmask); |
|---|
| | 1225 | } elseif(!$this->validate_netmask($netmask)) { |
|---|
| | 1226 | return(FALSE); |
|---|
| | 1227 | } |
|---|
| | 1228 | //Get arp list |
|---|
| | 1229 | $arp_list = shell_exec($global_cfg['arp_location'] . " -an"); |
|---|
| | 1230 | //$arp_list = shell_exec("arp -an"); |
|---|
| | 1231 | if($global_cfg['debug']) { |
|---|
| | 1232 | $debug .= "ARP LIST:\n".$arp_list; |
|---|
| | 1233 | } |
|---|
| | 1234 | //Throw arp list into an array, break by new lines |
|---|
| | 1235 | $arp_array = explode("\n", $arp_list); |
|---|
| | 1236 | |
|---|
| | 1237 | //Find all references to active computers by searching out mac addresses. |
|---|
| | 1238 | $temp = array_values(array_unique(preg_grep("/[0-9a-f][0-9a-f][:-]". |
|---|
| | 1239 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1240 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1241 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1242 | "[0-9a-f][0-9a-f][:-]". |
|---|
| | 1243 | "[0-9a-f][0-9a-f]/i", $arp_array))); |
|---|
| | 1244 | |
|---|
| | 1245 | if($global_cfg['debug']) { |
|---|
| | 1246 | $arp_arry = print_r($temp, true); |
|---|
| | 1247 | $debug .= "ARP Array:\n".$arp_arry; |
|---|
| | 1248 | } |
|---|
| | 1249 | //Go through each row of valid arp entries and pull out the information and add it into a nice array! |
|---|
| | 1250 | foreach ($temp as $key => &$value) { |
|---|
| | 1251 | |
|---|
| | 1252 | //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 |
|---|
| | 1253 | $ip = trim(substr($value, 0, 15)); |
|---|
| | 1254 | |
|---|
| | 1255 | //Pull out the mac address by looking for the delimiter |
|---|
| | 1256 | $mac = substr($value, (strpos($value, ":") -2), 17); |
|---|
| | 1257 | |
|---|
| | 1258 | //Get rid of the delimiter |
|---|
| | 1259 | $mac_strip = strtoupper(str_replace(":", "", $mac)); |
|---|
| | 1260 | |
|---|
| | 1261 | //arp -n will return a MAC address of 000000000000 if no hardware was found, so we need to ignore it |
|---|
| | 1262 | if($mac_strip != "000000000000") { |
|---|
| | 1263 | //only use the first 6 characters for the oui: http://en.wikipedia.org/wiki/Organizationally_Unique_Identifier |
|---|
| | 1264 | $oui = substr($mac_strip,0,6); |
|---|
| | 1265 | |
|---|
| | 1266 | //Find the matching brand model to the oui |
|---|
| | 1267 | $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"; |
|---|
| | 1268 | |
|---|
| | 1269 | |
|---|
| | 1270 | $brand_result = mysql_query($oui_sql); |
|---|
| | 1271 | $brand = mysql_fetch_row($brand_result); |
|---|
| | 1272 | if ($brand == FALSE) { |
|---|
| | 1273 | //oui doesn't have a matching mysql reference, probably a PC/router/wap/printer of some sort. |
|---|
| | 1274 | $brand[0] = FALSE; |
|---|
| | 1275 | $brand[1] = NULL; |
|---|
| | 1276 | } |
|---|
| | 1277 | |
|---|
| | 1278 | //Find out if endpoint has already been configured for this mac address |
|---|
| | 1279 | $epm_sql = "SELECT * FROM endpointman_mac_list WHERE mac LIKE '%". $mac_strip ."%'"; |
|---|
| | 1280 | $epm_result = mysql_query($epm_sql); |
|---|
| | 1281 | $epm_row = mysql_fetch_row($epm_result); |
|---|
| | 1282 | if ($epm_row == TRUE) { |
|---|
| | 1283 | $epm = TRUE; |
|---|
| | 1284 | } else { |
|---|
| | 1285 | $epm = FALSE; |
|---|
| | 1286 | } |
|---|
| | 1287 | |
|---|
| | 1288 | //Add into a final array |
|---|
| | 1289 | $final[$key] = array("ip" => $ip, "mac" => $mac, "mac_strip" => $mac_strip, "oui" => $oui, "brand" => $brand[0], "brand_id" => $brand[1], "endpoint_managed" => $epm); |
|---|
| | 1290 | } |
|---|
| | 1291 | } |
|---|
| | 1292 | $final = array_values($final); |
|---|
| | 1293 | if($global_cfg['debug']) { |
|---|
| | 1294 | $arp_arry = print_r($final, true); |
|---|
| | 1295 | $debug .= "Final output from 'discover_new' function:\n".$arp_arry; |
|---|
| | 1296 | } |
|---|
| | 1297 | if(!is_array($final)) { |
|---|
| | 1298 | return(FALSE); |
|---|
| | 1299 | } else { |
|---|
| | 1300 | return ($final); |
|---|
| | 1301 | } |
|---|
| | 1302 | } |
|---|
| | 1303 | |
|---|
| | 1304 | function modelsAvailable($model=NULL, $macAdd=NULL, $brand=NULL) { |
|---|
| | 1305 | if (isset($macAdd)) { |
|---|
| | 1306 | $oui=substr($macAdd,0,6); |
|---|
| | 1307 | } |
|---|
| | 1308 | if ((!isset($oui)) && (!isset($brand)) && (!isset($model))) { |
|---|
| | 1309 | $sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.hidden = 0"; |
|---|
| | 1310 | }elseif((isset($brand)) && ($brand !=0)) { |
|---|
| | 1311 | $sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.hidden = 0 AND endpointman_model_list.brand = " . $brand; |
|---|
| | 1312 | } else { |
|---|
| | 1313 | $sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.hidden = 0"; |
|---|
| | 1314 | } |
|---|
| | 1315 | |
|---|
| | 1316 | |
|---|
| | 1317 | $result1 =& $this->db->getAll($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 1318 | |
|---|
| | 1319 | $i = 1; |
|---|
| | 1320 | foreach($result1 as $row) { |
|---|
| | 1321 | if ($row['id'] == $model) { |
|---|
| | 1322 | $temp[$i]['value'] = $row['id']; |
|---|
| | 1323 | $temp[$i]['text'] = $row['model']; |
|---|
| | 1324 | $temp[$i]['selected'] = 'selected'; |
|---|
| | 1325 | }else { |
|---|
| | 1326 | $temp[$i]['value'] = $row['id']; |
|---|
| | 1327 | $temp[$i]['text'] = $row['model']; |
|---|
| | 1328 | $temp[$i]['selected'] = 0; |
|---|
| | 1329 | } |
|---|
| | 1330 | $i++; |
|---|
| | 1331 | } |
|---|
| | 1332 | |
|---|
| | 1333 | if(!isset($temp)) { |
|---|
| | 1334 | $this->error['modelsAvailable'] = "SQL Statement came out empty!"; |
|---|
| | 1335 | return(FALSE); |
|---|
| | 1336 | } else { |
|---|
| | 1337 | return($temp); |
|---|
| | 1338 | } |
|---|
| | 1339 | } |
|---|
| | 1340 | |
|---|
| | 1341 | function displayExtension($ext = NULL) { |
|---|
| | 1342 | if(!isset($ext)) { |
|---|
| | 1343 | $not_added="SELECT devices.id, devices.description FROM devices WHERE devices.id not in (SELECT devices.id FROM devices, endpointman_mac_list WHERE tech='sip' AND devices.id = endpointman_mac_list.ext )"; |
|---|
| | 1344 | } else { |
|---|
| | 1345 | $not_added="SELECT devices.id, devices.description FROM devices WHERE devices.id not in (SELECT devices.id FROM devices, endpointman_mac_list WHERE tech='sip' AND devices.id = endpointman_mac_list.ext AND endpointman_mac_list.ext !=".$ext." )"; |
|---|
| | 1346 | } |
|---|
| | 1347 | $result=mysql_query($not_added); |
|---|
| | 1348 | |
|---|
| | 1349 | $result =& $this->db->getAll($not_added,array(), DB_FETCHMODE_ASSOC); |
|---|
| | 1350 | |
|---|
| | 1351 | |
|---|
| | 1352 | $i = 1; |
|---|
| | 1353 | $temp = array(); |
|---|
| | 1354 | foreach($result as $row) { |
|---|
| | 1355 | $temp[$i]['value'] = $row['id']; |
|---|
| | 1356 | $temp[$i]['text'] = $row['id'] . " --- " . $row['description']; |
|---|
| | 1357 | if ($row['id'] == $ext) { |
|---|
| | 1358 | $temp[$i]['selected'] = "selected"; |
|---|
| | 1359 | } |
|---|
| | 1360 | $i++; |
|---|
| | 1361 | } |
|---|
| | 1362 | |
|---|
| | 1363 | return($temp); |
|---|
| | 1364 | |
|---|
| | 1365 | } |
|---|
| | 1366 | /** |
|---|
| | 1367 | * Returns list of Brands that are installed and not hidden and that have at least one model enabled under them |
|---|
| | 1368 | * @param integer $selected ID Number of the brand that is supposed to be selected in a drop-down list box |
|---|
| | 1369 | * @return array Number array used to generate a select box |
|---|
| | 1370 | */ |
|---|
| | 1371 | function brandAvailable ($selected = NULL) { |
|---|
| | 1372 | $sql="SELECT endpointman_brand_list.name, endpointman_brand_list.id FROM endpointman_brand_list,endpointman_model_list WHERE endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.enabled = 1 AND endpointman_model_list.hidden = 0 AND endpointman_brand_list.installed = 1 AND endpointman_brand_list.hidden = 0"; |
|---|
| | 1373 | $data =& $this->db->getAll($sql,array(), DB_FETCHMODE_ASSOC); |
|---|
| | 1374 | $temp[0]['value'] = ""; |
|---|
| | 1375 | $temp[0]['text'] = ""; |
|---|
| | 1376 | $i = 1; |
|---|
| | 1377 | foreach($data as $row) { |
|---|
| | 1378 | $temp[$i]['value'] = $row['id']; |
|---|
| | 1379 | $temp[$i]['text'] = $row['name']; |
|---|
| | 1380 | if ($row['id'] == $selected) { |
|---|
| | 1381 | $temp[$i]['selected'] = TRUE; |
|---|
| | 1382 | } else { |
|---|
| | 1383 | $temp[$i]['selected'] = NULL; |
|---|
| | 1384 | } |
|---|
| | 1385 | $i++; |
|---|
| | 1386 | } |
|---|
| | 1387 | return($temp); |
|---|
| | 1388 | } |
|---|
| | 1389 | |
|---|
| | 1390 | function display_templates($product_id,$temp_select = NULL) { |
|---|
| | 1391 | $i = 0; |
|---|
| | 1392 | $sql="SELECT id FROM endpointman_product_list WHERE endpointman_product_list.id ='".$product_id."'"; |
|---|
| | 1393 | |
|---|
| | 1394 | $id =& $this->db->getOne($sql); |
|---|
| | 1395 | |
|---|
| | 1396 | $sql="SELECT * FROM endpointman_template_list WHERE product_id = '".$id."'"; |
|---|
| | 1397 | |
|---|
| | 1398 | $data =& $this->db->getAll($sql,array(), DB_FETCHMODE_ASSOC); |
|---|
| | 1399 | foreach($data as $row) { |
|---|
| | 1400 | $temp[$i]['value'] = $row['id']; |
|---|
| | 1401 | $temp[$i]['text'] = $row['name']; |
|---|
| | 1402 | if ($row['id'] == $temp_select) { |
|---|
| | 1403 | $temp[$i]['selected'] = "selected"; |
|---|
| | 1404 | } |
|---|
| | 1405 | $i++; |
|---|
| | 1406 | } |
|---|
| | 1407 | $temp[$i]['value'] = 0; |
|---|
| | 1408 | if ($temp_select == 0) { |
|---|
| | 1409 | $temp[$i]['text'] = "Custom..."; |
|---|
| | 1410 | $temp[$i]['selected'] = "selected"; |
|---|
| | 1411 | } else { |
|---|
| | 1412 | $temp[$i]['text'] = "Custom..."; |
|---|
| | 1413 | } |
|---|
| | 1414 | |
|---|
| | 1415 | return($temp); |
|---|
| | 1416 | } |
|---|
| | 1417 | |
|---|
| | 1418 | function listTZ($selected) { |
|---|
| | 1419 | $sql="SELECT tz FROM endpointman_time_zones"; |
|---|
| | 1420 | $data =& $this->db->getAll($sql,array(), DB_FETCHMODE_ASSOC); |
|---|
| | 1421 | $i = 0; |
|---|
| | 1422 | foreach($data as $row) { |
|---|
| | 1423 | if ($row['tz'] == $selected) { |
|---|
| | 1424 | $temp[$i]['value'] = $row['tz']; |
|---|
| | 1425 | $temp[$i]['text'] = $row['tz']; |
|---|
| | 1426 | $temp[$i]['selected'] = 1; |
|---|
| | 1427 | }else { |
|---|
| | 1428 | $temp[$i]['value'] = $row['tz']; |
|---|
| | 1429 | $temp[$i]['text'] = $row['tz']; |
|---|
| | 1430 | $temp[$i]['selected'] = 0; |
|---|
| | 1431 | } |
|---|
| | 1432 | $i++; |
|---|
| | 1433 | } |
|---|
| | 1434 | return($temp); |
|---|
| | 1435 | } |
|---|
| | 1436 | |
|---|
| | 1437 | function rebootPhone($ext,$datav) { |
|---|
| | 1438 | if (is_numeric($ext)) { |
|---|
| | 1439 | } elseif ($ext == 'all') { |
|---|
| | 1440 | $sql = "SELECT endpointman_mac_list.id , endpointman_brand_list.directory , endpointman_product_list.cfg_dir FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list, endpointman_product_list WHERE endpointman_mac_list.model = endpointman_model_list.id AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_model_list.brand =endpointman_brand_list.id"; |
|---|
| | 1441 | $result = mysql_query($sql); |
|---|
| | 1442 | while($row = mysql_fetch_assoc($result)) { |
|---|
| | 1443 | if(($cfg_dir == $row['cfg_dir']) AND ($directory == $row['directory'])) { |
|---|
| | 1444 | $phone_config->reboot($row['id']); |
|---|
| | 1445 | } else { |
|---|
| | 1446 | if(isset($phone_config)) { |
|---|
| | 1447 | unset($phone_config); |
|---|
| | 1448 | } |
|---|
| | 1449 | $directory = $row['directory']; |
|---|
| | 1450 | $cfg_dir = $row['cfg_dir']; |
|---|
| | 1451 | require(PHONE_MODULES_PATH.$row['directory'].'/'.$row['cfg_dir'].'/functions.inc'); |
|---|
| | 1452 | $phone_config = new $row['cfg_dir'](); |
|---|
| | 1453 | $phone_config->reboot($row['id']); |
|---|
| | 1454 | } |
|---|
| | 1455 | } |
|---|
| | 1456 | } else { |
|---|
| | 1457 | $sql = "SELECT endpointman_brand_list.directory, endpointman_product_list.cfg_dir, endpointman_mac_list.id FROM endpointman_brand_list, endpointman_model_list, endpointman_mac_list, endpointman_product_list WHERE endpointman_brand_list.id = ".$datav['rb_brand']." AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_model_list.product_id = endpointman_product_list.id"; |
|---|
| | 1458 | $result = mysql_query($sql); |
|---|
| | 1459 | while($row = mysql_fetch_assoc($result)) { |
|---|
| | 1460 | if(($cfg_dir == $row['cfg_dir']) AND ($directory == $row['directory'])) { |
|---|
| | 1461 | $phone_config->reboot($row['id']); |
|---|
| | 1462 | } else { |
|---|
| | 1463 | if(isset($phone_config)) { |
|---|
| | 1464 | unset($phone_config); |
|---|
| | 1465 | } |
|---|
| | 1466 | $directory = $row['directory']; |
|---|
| | 1467 | $cfg_dir = $row['cfg_dir']; |
|---|
| | 1468 | require(PHONE_MODULES_PATH.$row['directory'].'/'.$row['cfg_dir'].'/functions.inc'); |
|---|
| | 1469 | $phone_config = new $row['cfg_dir'](); |
|---|
| | 1470 | $phone_config->reboot($row['id']); |
|---|
| | 1471 | } |
|---|
| | 1472 | } |
|---|
| | 1473 | } |
|---|
| | 1474 | } |
|---|