Fix bugs in provisioning. When an extension is disabled don't provide provision it. Normalize the MAC address when stored in the db as lower case and no formatting. When using the MAC address in the template change it to upper case the MAC address for SNOM with no dashes.
This commit is contained in:
parent
1fef798c2a
commit
b9711091f4
|
|
@ -916,18 +916,14 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
|
|||
echo "<option value=''></option>\n";
|
||||
|
||||
foreach($result as $row) {
|
||||
$phone_mac_address = $row['phone_mac_address'];
|
||||
$phone_mac_address = substr($phone_mac_address, 0,2).'-'.substr($phone_mac_address, 2,2).'-'.substr($phone_mac_address, 4,2).'-'.substr($phone_mac_address, 6,2).'-'.substr($phone_mac_address, 8,2).'-'.substr($phone_mac_address, 10,2);
|
||||
if ($row['phone_mac_address'] == $select_mac_address) {
|
||||
echo "<option value='".$row['phone_mac_address']."' selected>".$row['phone_mac_address']." ".$row['phone_model']." ".$row['phone_description']."</option>\n";
|
||||
echo "<option value='".$row['phone_mac_address']."' selected>".$phone_mac_address." ".$row['phone_model']." ".$row['phone_description']."</option>\n";
|
||||
}
|
||||
else {
|
||||
echo "<option value='".$row['phone_mac_address']."'>".$row['phone_mac_address']." ".$row['phone_model']." ".$row['phone_description']."</option>\n";
|
||||
echo "<option value='".$row['phone_mac_address']."'>".$phone_mac_address." ".$row['phone_model']." ".$row['phone_description']."</option>\n";
|
||||
}
|
||||
//$row[phone_mac_address]
|
||||
//$row[phone_vendor]
|
||||
//$row[phone_model]
|
||||
//$row[phone_provision_enable]
|
||||
//$row[phone_description]
|
||||
//$row[hardware_phone_uuid]
|
||||
} //end foreach
|
||||
unset($sql, $result, $row_count);
|
||||
echo "</select>\n";
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ require_once "includes/require.php";
|
|||
if (count($_POST)>0) {
|
||||
$phone_mac_address = check_str($_POST["phone_mac_address"]);
|
||||
$phone_mac_address = strtolower($phone_mac_address);
|
||||
$phone_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $phone_mac_address);
|
||||
$phone_label = check_str($_POST["phone_label"]);
|
||||
$phone_vendor = check_str($_POST["phone_vendor"]);
|
||||
$phone_model = check_str($_POST["phone_model"]);
|
||||
|
|
@ -60,6 +61,40 @@ require_once "includes/require.php";
|
|||
$phone_description = check_str($_POST["phone_description"]);
|
||||
}
|
||||
|
||||
//use the mac address to find the vendor
|
||||
if (strlen($phone_vendor) == 0) {
|
||||
switch (substr($phone_mac_address, 0, 6)) {
|
||||
case "00085d":
|
||||
$phone_vendor = "aastra";
|
||||
break;
|
||||
case "000e08":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "0004f2":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "00907a":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "001873":
|
||||
$phone_vendor = "cisco";
|
||||
break;
|
||||
case "00045a":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "000625":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "001565":
|
||||
$phone_vendor = "yealink";
|
||||
break;
|
||||
case "000413":
|
||||
$phone_vendor = "snom";
|
||||
default:
|
||||
$phone_vendor = "";
|
||||
}
|
||||
}
|
||||
|
||||
//add or update the database
|
||||
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
|
||||
|
||||
|
|
@ -183,8 +218,7 @@ require_once "includes/require.php";
|
|||
//pre-populate the form
|
||||
if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
|
||||
$hardware_phone_uuid = $_GET["id"];
|
||||
$sql = "";
|
||||
$sql .= "select * from v_hardware_phones ";
|
||||
$sql = "select * from v_hardware_phones ";
|
||||
$sql .= "where domain_uuid = '$domain_uuid' ";
|
||||
$sql .= "and hardware_phone_uuid = '$hardware_phone_uuid' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
|
|
@ -192,7 +226,7 @@ require_once "includes/require.php";
|
|||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach ($result as &$row) {
|
||||
$phone_mac_address = $row["phone_mac_address"];
|
||||
$phone_mac_address = strtolower($phone_mac_address);
|
||||
$phone_mac_address = substr($phone_mac_address, 0,2).'-'.substr($phone_mac_address, 2,2).'-'.substr($phone_mac_address, 4,2).'-'.substr($phone_mac_address, 6,2).'-'.substr($phone_mac_address, 8,2).'-'.substr($phone_mac_address, 10,2);
|
||||
$phone_label = $row["phone_label"];
|
||||
$phone_vendor = $row["phone_vendor"];
|
||||
$phone_model = $row["phone_model"];
|
||||
|
|
@ -203,7 +237,6 @@ require_once "includes/require.php";
|
|||
$phone_password = $row["phone_password"];
|
||||
$phone_time_zone = $row["phone_time_zone"];
|
||||
$phone_description = $row["phone_description"];
|
||||
break; //limit to 1 row
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
|
|
@ -213,14 +246,11 @@ require_once "includes/require.php";
|
|||
|
||||
echo "<div align='center'>";
|
||||
echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
|
||||
|
||||
echo "<tr class='border'>\n";
|
||||
echo " <td align=\"left\">\n";
|
||||
echo " <br>";
|
||||
|
||||
|
||||
echo "<form method='post' name='frm' action=''>\n";
|
||||
|
||||
echo "<div align='center'>\n";
|
||||
echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
//normalize the mac address
|
||||
$sql = "select hardware_phone_uuid, phone_mac_address ";
|
||||
$sql .= "from v_hardware_phones ";
|
||||
$sql .= "where domain_uuid = '$domain_uuid' ";
|
||||
$sql .= "and (phone_mac_address like '%-%' or phone_mac_address like '%:%') ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach($result as $row) {
|
||||
$hardware_phone_uuid = $row["hardware_phone_uuid"];
|
||||
$phone_mac_address = $row["phone_mac_address"];
|
||||
$phone_mac_address = strtolower($phone_mac_address);
|
||||
$phone_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $phone_mac_address);
|
||||
|
||||
$sql = "update v_hardware_phones set ";
|
||||
$sql .= "phone_mac_address = '".$phone_mac_address."' ";
|
||||
$sql .= "where hardware_phone_uuid = '".$hardware_phone_uuid."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
}
|
||||
unset($prep_statement, $result);
|
||||
|
||||
?>
|
||||
|
|
@ -33,7 +33,7 @@ require_once "includes/require.php";
|
|||
$phone_template = '';
|
||||
|
||||
//get any system -> variables defined in the 'provision;
|
||||
$sql .= "select * from v_vars ";
|
||||
$sql = "select * from v_vars ";
|
||||
$sql .= "where var_enabled = 'true' ";
|
||||
$sql .= "and var_cat = 'Provision' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
|
|
@ -53,7 +53,7 @@ require_once "includes/require.php";
|
|||
if (strlen($password) > 0) {
|
||||
//deny access if the password doesn't match
|
||||
if ($password != $_REQUEST['password']) {
|
||||
//Log the failed auth attempt to the system, to be available for fail2ban.
|
||||
//log the failed auth attempt to the system, to be available for fail2ban.
|
||||
openlog('FusionPBX', LOG_NDELAY, LOG_AUTH);
|
||||
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt bad password for ".$_REQUEST['mac']);
|
||||
closelog();
|
||||
|
|
@ -73,24 +73,55 @@ require_once "includes/require.php";
|
|||
}
|
||||
}
|
||||
|
||||
//define variables from HTTP GET
|
||||
//define PHP variables from the HTTP values
|
||||
$mac = $_REQUEST['mac'];
|
||||
$file = $_REQUEST['file'];
|
||||
if (strlen($_REQUEST['template']) > 0) {
|
||||
$phone_template = $_REQUEST['template'];
|
||||
}
|
||||
|
||||
if(empty($mac)){//check alternate MAC source
|
||||
//check alternate MAC source
|
||||
if (empty($mac)){
|
||||
if($_SERVER['HTTP_USER_AGENT'][strlen($_SERVER['HTTP_USER_AGENT'])-17-1] == " ") {
|
||||
$mac = substr($_SERVER['HTTP_USER_AGENT'],-17);
|
||||
} //Yealink: 17 digit mac appended to the user agent, so check for a space exactly 17 digits before the end.
|
||||
}//check alternates
|
||||
|
||||
//prepare the mac address
|
||||
$mac = strtolower($mac);
|
||||
$mac = str_replace(":", "-", $mac);
|
||||
if (strlen($mac) == 12) {
|
||||
$mac = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2);
|
||||
$mac = preg_replace('#[^a-fA-F0-9./]#', '', $mac);
|
||||
|
||||
//use the mac address to find the vendor
|
||||
switch (substr($mac, 0, 6)) {
|
||||
case "00085d":
|
||||
$phone_vendor = "aastra";
|
||||
break;
|
||||
case "000e08":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "0004f2":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "00907a":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "001873":
|
||||
$phone_vendor = "cisco";
|
||||
break;
|
||||
case "00045a":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "000625":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "001565":
|
||||
$phone_vendor = "yealink";
|
||||
break;
|
||||
case "000413":
|
||||
$phone_vendor = "snom";
|
||||
default:
|
||||
$phone_vendor = "";
|
||||
}
|
||||
$file = $_REQUEST['file'];
|
||||
|
||||
//check to see if the mac_address exists in v_hardware_phones
|
||||
if (mac_exists_in_v_hardware_phones($db, $mac)) {
|
||||
|
|
@ -106,7 +137,9 @@ require_once "includes/require.php";
|
|||
$prep_statement_2->execute();
|
||||
$row = $prep_statement_2->fetch();
|
||||
$phone_label = $row["phone_label"];
|
||||
if (strlen($row["phone_vendor"]) > 0) {
|
||||
$phone_vendor = $row["phone_vendor"];
|
||||
}
|
||||
$phone_model = $row["phone_model"];
|
||||
$phone_firmware_version = $row["phone_firmware_version"];
|
||||
$phone_provision_enable = $row["phone_provision_enable"];
|
||||
|
|
@ -142,37 +175,6 @@ require_once "includes/require.php";
|
|||
}
|
||||
}
|
||||
else {
|
||||
//mac does not exist in v_hardware_phones add it to the table
|
||||
//use the mac address to find the vendor
|
||||
switch (substr($mac, 0, 8)) {
|
||||
case "00-08-5d":
|
||||
$phone_vendor = "aastra";
|
||||
break;
|
||||
case "00-0e-08":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "00-04-f2":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "00-90-7a":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "00-18-73":
|
||||
$phone_vendor = "cisco";
|
||||
break;
|
||||
case "00-04-5a":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "00-06-25":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "00-15-65":
|
||||
$phone_vendor = "yealink";
|
||||
break;
|
||||
default:
|
||||
$phone_vendor = "";
|
||||
}
|
||||
|
||||
//use the user_agent to pre-assign a template for 1-hit provisioning. Enter the a unique string to match in the user agent, and the template it should match.
|
||||
$template_list=array(
|
||||
"Linksys/SPA-2102"=>"linksys/spa2102",
|
||||
|
|
@ -187,7 +189,7 @@ require_once "includes/require.php";
|
|||
}
|
||||
unset($template_list);
|
||||
|
||||
//the 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();
|
||||
$sql = "insert into v_hardware_phones ";
|
||||
$sql .= "(";
|
||||
|
|
@ -297,6 +299,7 @@ require_once "includes/require.php";
|
|||
$sql = "select * from v_extensions ";
|
||||
$sql .= "where provisioning_list like '%|".$mac.":%' ";
|
||||
$sql .= "and domain_uuid = '$domain_uuid' ";
|
||||
$sql .= "and enabled = 'true' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
|
|
@ -334,6 +337,19 @@ require_once "includes/require.php";
|
|||
}
|
||||
unset ($prep_statement);
|
||||
|
||||
//set the mac address in the correct format
|
||||
switch ($phone_vendor) {
|
||||
case "aastra":
|
||||
$mac = strtoupper($mac);
|
||||
break;
|
||||
case "snom":
|
||||
$mac = strtoupper($mac);
|
||||
$mac = str_replace("-", "", $mac);
|
||||
default:
|
||||
$mac = strtolower($mac);
|
||||
$mac = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2);
|
||||
}
|
||||
|
||||
//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_label}", $phone_label, $file_contents);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ else {
|
|||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach ($result as &$row) {
|
||||
$phone_mac_address = $row["phone_mac_address"];
|
||||
$phone_mac_address = strtolower($phone_mac_address);
|
||||
$phone_label = $row["phone_label"];
|
||||
$phone_vendor = $row["phone_vendor"];
|
||||
$phone_model = $row["phone_model"];
|
||||
|
|
@ -74,6 +73,53 @@ else {
|
|||
$phone_time_zone = $row["phone_time_zone"];
|
||||
$phone_description = $row["phone_description"];
|
||||
|
||||
//use the mac address to find the vendor
|
||||
if (strlen($phone_vendor) == 0) {
|
||||
switch (substr($phone_mac_address, 0, 6)) {
|
||||
case "00085d":
|
||||
$phone_vendor = "aastra";
|
||||
break;
|
||||
case "000e08":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "0004f2":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "00907a":
|
||||
$phone_vendor = "polycom";
|
||||
break;
|
||||
case "001873":
|
||||
$phone_vendor = "cisco";
|
||||
break;
|
||||
case "00045a":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "000625":
|
||||
$phone_vendor = "linksys";
|
||||
break;
|
||||
case "001565":
|
||||
$phone_vendor = "yealink";
|
||||
break;
|
||||
case "000413":
|
||||
$phone_vendor = "snom";
|
||||
default:
|
||||
$phone_vendor = "";
|
||||
}
|
||||
}
|
||||
|
||||
//set the mac address in the correct format
|
||||
switch ($phone_vendor) {
|
||||
case "aastra":
|
||||
$mac = strtoupper($mac);
|
||||
break;
|
||||
case "snom":
|
||||
$mac = strtoupper($mac);
|
||||
$mac = str_replace("-", "", $mac);
|
||||
default:
|
||||
$mac = strtolower($mac);
|
||||
$mac = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2);
|
||||
}
|
||||
|
||||
//loop through the provision template directory
|
||||
$provision_template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/includes/templates/provision/".$phone_template;
|
||||
|
||||
|
|
@ -151,6 +197,7 @@ else {
|
|||
$sql2 = "select * from v_extensions ";
|
||||
$sql2 .= "where provisioning_list like '%$phone_mac_address%' ";
|
||||
$sql2 .= "and domain_uuid = '$domain_uuid' ";
|
||||
$sql2 .= "and enabled = 'true' ";
|
||||
$prep_statement_2 = $db->prepare(check_sql($sql2));
|
||||
$prep_statement_2->execute();
|
||||
$result2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED);
|
||||
|
|
|
|||
Loading…
Reference in New Issue