Change hardware phones to devices in the provision index.php file.

This commit is contained in:
Mark Crane 2013-04-09 22:27:02 +00:00
parent 745213cdfc
commit ee17d01fc4
1 changed files with 70 additions and 70 deletions

View File

@ -30,7 +30,7 @@ require_once "includes/require.php";
$file_count = 0; $file_count = 0;
$row_count = 0; $row_count = 0;
$tmp_array = ''; $tmp_array = '';
$phone_template = ''; $device_template = '';
//if password was defined in the system -> variables page then require the password. //if password was defined in the system -> variables page then require the password.
if (strlen($_SESSION['provision']['password']['var']) > 0) { if (strlen($_SESSION['provision']['password']['var']) > 0) {
@ -60,7 +60,7 @@ require_once "includes/require.php";
$mac = check_str($_REQUEST['mac']); $mac = check_str($_REQUEST['mac']);
$file = check_str($_REQUEST['file']); $file = check_str($_REQUEST['file']);
if (strlen(check_str($_REQUEST['template'])) > 0) { if (strlen(check_str($_REQUEST['template'])) > 0) {
$phone_template = check_str($_REQUEST['template']); $device_template = check_str($_REQUEST['template']);
} }
//check alternate MAC source //check alternate MAC source
@ -83,83 +83,83 @@ require_once "includes/require.php";
//use the mac address to find the vendor //use the mac address to find the vendor
switch (substr($mac, 0, 6)) { switch (substr($mac, 0, 6)) {
case "00085d": case "00085d":
$phone_vendor = "aastra"; $device_vendor = "aastra";
break; break;
case "000e08": case "000e08":
$phone_vendor = "linksys"; $device_vendor = "linksys";
break; break;
case "0004f2": case "0004f2":
$phone_vendor = "polycom"; $device_vendor = "polycom";
break; break;
case "00907a": case "00907a":
$phone_vendor = "polycom"; $device_vendor = "polycom";
break; break;
case "001873": case "001873":
$phone_vendor = "cisco"; $device_vendor = "cisco";
break; break;
case "00045a": case "00045a":
$phone_vendor = "linksys"; $device_vendor = "linksys";
break; break;
case "000625": case "000625":
$phone_vendor = "linksys"; $device_vendor = "linksys";
break; break;
case "001565": case "001565":
$phone_vendor = "yealink"; $device_vendor = "yealink";
break; break;
case "000413": case "000413":
$phone_vendor = "snom"; $device_vendor = "snom";
default: default:
$phone_vendor = ""; $device_vendor = "";
} }
//check to see if the mac_address exists in v_hardware_phones //check to see if the mac_address exists in v_devices
if (mac_exists_in_hardware_phones($db, $mac)) { if (mac_exists_in_devices($db, $mac)) {
//get the phone_template //get the device_template
if (strlen($phone_template) == 0) { if (strlen($device_template) == 0) {
$sql = "SELECT * FROM v_hardware_phones "; $sql = "SELECT * FROM v_devices ";
$sql .= "where domain_uuid=:domain_uuid "; $sql .= "where domain_uuid=:domain_uuid ";
$sql .= "and phone_mac_address=:mac "; $sql .= "and device_mac_address=:mac ";
$prep_statement_2 = $db->prepare(check_sql($sql)); $prep_statement_2 = $db->prepare(check_sql($sql));
if ($prep_statement_2) { if ($prep_statement_2) {
$prep_statement_2->bindParam(':domain_uuid', $domain_uuid); $prep_statement_2->bindParam(':domain_uuid', $domain_uuid);
$prep_statement_2->bindParam(':mac', $mac); $prep_statement_2->bindParam(':mac', $mac);
$prep_statement_2->execute(); $prep_statement_2->execute();
$row = $prep_statement_2->fetch(); $row = $prep_statement_2->fetch();
$phone_label = $row["phone_label"]; $device_label = $row["device_label"];
if (strlen($row["phone_vendor"]) > 0) { if (strlen($row["device_vendor"]) > 0) {
$phone_vendor = $row["phone_vendor"]; $device_vendor = $row["device_vendor"];
} }
$phone_model = $row["phone_model"]; $device_model = $row["device_model"];
$phone_firmware_version = $row["phone_firmware_version"]; $device_firmware_version = $row["device_firmware_version"];
$phone_provision_enable = $row["phone_provision_enable"]; $device_provision_enable = $row["device_provision_enable"];
$phone_template = $row["phone_template"]; $device_template = $row["device_template"];
$phone_username = $row["phone_username"]; $device_username = $row["device_username"];
$phone_password = $row["phone_password"]; $device_password = $row["device_password"];
$phone_time_zone = $row["phone_time_zone"]; $device_time_zone = $row["device_time_zone"];
$phone_description = $row["phone_description"]; $device_description = $row["device_description"];
} }
} }
//find a template that was defined on another phone and use that as the default. //find a template that was defined on another phone and use that as the default.
if (strlen($phone_template) == 0) { if (strlen($device_template) == 0) {
$sql = "SELECT * FROM v_hardware_phones "; $sql = "SELECT * FROM v_devices ";
$sql .= "where domain_uuid=:domain_uuid "; $sql .= "where domain_uuid=:domain_uuid ";
$sql .= "and phone_template like '%/%' "; $sql .= "and device_template like '%/%' ";
$prep_statement3 = $db->prepare(check_sql($sql)); $prep_statement3 = $db->prepare(check_sql($sql));
if ($prep_statement3) { if ($prep_statement3) {
$prep_statement3->bindParam(':domain_uuid', $domain_uuid); $prep_statement3->bindParam(':domain_uuid', $domain_uuid);
$prep_statement3->bindParam(':mac', $mac); $prep_statement3->bindParam(':mac', $mac);
$prep_statement3->execute(); $prep_statement3->execute();
$row = $prep_statement3->fetch(); $row = $prep_statement3->fetch();
$phone_label = $row["phone_label"]; $device_label = $row["device_label"];
$phone_vendor = $row["phone_vendor"]; $device_vendor = $row["device_vendor"];
$phone_model = $row["phone_model"]; $device_model = $row["device_model"];
$phone_firmware_version = $row["phone_firmware_version"]; $device_firmware_version = $row["device_firmware_version"];
$phone_provision_enable = $row["phone_provision_enable"]; $device_provision_enable = $row["device_provision_enable"];
$phone_template = $row["phone_template"]; $device_template = $row["device_template"];
$phone_username = $row["phone_username"]; $device_username = $row["device_username"];
$phone_password = $row["phone_password"]; $device_password = $row["device_password"];
$phone_time_zone = $row["phone_time_zone"]; $device_time_zone = $row["device_time_zone"];
$phone_description = $row["phone_description"]; $device_description = $row["device_description"];
} }
} }
} }
@ -172,36 +172,36 @@ require_once "includes/require.php";
foreach ($template_list as $key=>$val){ foreach ($template_list as $key=>$val){
if(stripos($_SERVER['HTTP_USER_AGENT'],$key)!== false) { if(stripos($_SERVER['HTTP_USER_AGENT'],$key)!== false) {
$phone_template=$val; $device_template=$val;
break; break;
} }
} }
unset($template_list); unset($template_list);
//mac address does not exist in the table so add it //mac address does not exist in the table so add it
$hardware_phone_uuid = uuid(); $device_uuid = uuid();
$sql = "insert into v_hardware_phones "; $sql = "insert into v_devices ";
$sql .= "("; $sql .= "(";
$sql .= "domain_uuid, "; $sql .= "domain_uuid, ";
$sql .= "hardware_phone_uuid, "; $sql .= "device_uuid, ";
$sql .= "phone_mac_address, "; $sql .= "device_mac_address, ";
$sql .= "phone_vendor, "; $sql .= "device_vendor, ";
$sql .= "phone_model, "; $sql .= "device_model, ";
$sql .= "phone_provision_enable, "; $sql .= "device_provision_enable, ";
$sql .= "phone_template, "; $sql .= "device_template, ";
$sql .= "phone_username, "; $sql .= "device_username, ";
$sql .= "phone_password, "; $sql .= "device_password, ";
$sql .= "phone_description "; $sql .= "device_description ";
$sql .= ")"; $sql .= ")";
$sql .= "values "; $sql .= "values ";
$sql .= "("; $sql .= "(";
$sql .= "'$domain_uuid', "; $sql .= "'$domain_uuid', ";
$sql .= "'$hardware_phone_uuid', "; $sql .= "'$device_uuid', ";
$sql .= "'$mac', "; $sql .= "'$mac', ";
$sql .= "'$phone_vendor', "; $sql .= "'$device_vendor', ";
$sql .= "'', "; $sql .= "'', ";
$sql .= "'true', "; $sql .= "'true', ";
$sql .= "'$phone_template', "; $sql .= "'$device_template', ";
$sql .= "'', "; $sql .= "'', ";
$sql .= "'', "; $sql .= "'', ";
$sql .= "'auto {$_SERVER['HTTP_USER_AGENT']}' "; $sql .= "'auto {$_SERVER['HTTP_USER_AGENT']}' ";
@ -212,13 +212,13 @@ require_once "includes/require.php";
//if $file is not provided then look for a default file that exists //if $file is not provided then look for a default file that exists
if (strlen($file) == 0) { if (strlen($file) == 0) {
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$phone_template ."/{v_mac}")) { if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$device_template ."/{v_mac}")) {
$file = "{v_mac}"; $file = "{v_mac}";
} }
elseif (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$phone_template ."/{v_mac}.xml")) { elseif (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$device_template ."/{v_mac}.xml")) {
$file = "{v_mac}.xml"; $file = "{v_mac}.xml";
} }
elseif (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$phone_template ."/{v_mac}.cfg")) { elseif (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$device_template ."/{v_mac}.cfg")) {
$file = "{v_mac}.cfg"; $file = "{v_mac}.cfg";
} }
else { else {
@ -228,7 +228,7 @@ require_once "includes/require.php";
} }
else { else {
//make sure the file exists //make sure the file exists
if (!file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$phone_template ."/".$file)) { if (!file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$device_template ."/".$file)) {
echo "file not found"; echo "file not found";
exit; exit;
} }
@ -261,7 +261,7 @@ require_once "includes/require.php";
//$proxy3_address= ""; //$proxy3_address= "";
//get the contents of the template //get the contents of the template
$file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$phone_template ."/".$file); $file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$device_template ."/".$file);
//replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
@ -332,7 +332,7 @@ require_once "includes/require.php";
unset ($prep_statement); unset ($prep_statement);
//set the mac address in the correct format //set the mac address in the correct format
switch ($phone_vendor) { switch ($device_vendor) {
case "aastra": case "aastra":
$mac = strtoupper($mac); $mac = strtoupper($mac);
break; break;
@ -346,9 +346,9 @@ require_once "includes/require.php";
//replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
$file_contents = str_replace("{v_mac}", $mac, $file_contents); $file_contents = str_replace("{v_mac}", $mac, $file_contents);
$file_contents = str_replace("{v_label}", $phone_label, $file_contents); $file_contents = str_replace("{v_label}", $device_label, $file_contents);
$file_contents = str_replace("{v_firmware_version}", $phone_firmware_version, $file_contents); $file_contents = str_replace("{v_firmware_version}", $device_firmware_version, $file_contents);
$file_contents = str_replace("{domain_time_zone}", $phone_time_zone, $file_contents); $file_contents = str_replace("{domain_time_zone}", $device_time_zone, $file_contents);
$file_contents = str_replace("{domain_name}", $_SESSION['domain_name'], $file_contents); $file_contents = str_replace("{domain_name}", $_SESSION['domain_name'], $file_contents);
$file_contents = str_replace("{v_project_path}", PROJECT_PATH, $file_contents); $file_contents = str_replace("{v_project_path}", PROJECT_PATH, $file_contents);
$file_contents = str_replace("{v_server1_address}", $server1_address, $file_contents); $file_contents = str_replace("{v_server1_address}", $server1_address, $file_contents);
@ -373,7 +373,7 @@ require_once "includes/require.php";
//deliver the customized config over HTTP/HTTPS //deliver the customized config over HTTP/HTTPS
//need to make sure content-type is correct //need to make sure content-type is correct
$cfg_ext = ".cfg"; $cfg_ext = ".cfg";
if ($phone_vendor === "aastra" && strrpos($file, $cfg_ext, 0) === strlen($file) - strlen($cfg_ext)) { if ($device_vendor === "aastra" && strrpos($file, $cfg_ext, 0) === strlen($file) - strlen($cfg_ext)) {
header ("content-type: text/plain"); header ("content-type: text/plain");
} else { } else {
header ("content-type: text/xml"); header ("content-type: text/xml");
@ -382,11 +382,11 @@ require_once "includes/require.php";
echo $file_contents; echo $file_contents;
//define the function which checks to see if the mac address exists in the table //define the function which checks to see if the mac address exists in the table
function mac_exists_in_hardware_phones($db, $mac) { function mac_exists_in_devices($db, $mac) {
global $domain_uuid; global $domain_uuid;
$sql = "SELECT count(*) as count FROM v_hardware_phones "; $sql = "SELECT count(*) as count FROM v_devices ";
$sql .= "where domain_uuid=:domain_uuid "; $sql .= "where domain_uuid=:domain_uuid ";
$sql .= "and phone_mac_address=:mac "; $sql .= "and device_mac_address=:mac ";
$prep_statement = $db->prepare(check_sql($sql)); $prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) { if ($prep_statement) {
$prep_statement->bindParam(':domain_uuid', $domain_uuid); $prep_statement->bindParam(':domain_uuid', $domain_uuid);