Update devices to provide customizable line information.

This commit is contained in:
Mark Crane
2013-06-09 20:46:14 +00:00
parent 10b852cdbc
commit cd207440a3
5 changed files with 727 additions and 57 deletions

View File

@@ -52,19 +52,28 @@ require_once "includes/require.php";
//get http post variables and set them to php variables
if (count($_POST) > 0) {
$device_mac_address = check_str($_POST["device_mac_address"]);
$device_mac_address = strtolower($device_mac_address);
$device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
$device_label = check_str($_POST["device_label"]);
$device_vendor = check_str($_POST["device_vendor"]);
$device_model = check_str($_POST["device_model"]);
$device_firmware_version = check_str($_POST["device_firmware_version"]);
$device_provision_enable = check_str($_POST["device_provision_enable"]);
$device_template = check_str($_POST["device_template"]);
$device_username = check_str($_POST["device_username"]);
$device_password = check_str($_POST["device_password"]);
$device_time_zone = check_str($_POST["device_time_zone"]);
$device_description = check_str($_POST["device_description"]);
//devices
$device_mac_address = check_str($_POST["device_mac_address"]);
$device_mac_address = strtolower($device_mac_address);
$device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
$device_label = check_str($_POST["device_label"]);
$device_vendor = check_str($_POST["device_vendor"]);
$device_model = check_str($_POST["device_model"]);
$device_firmware_version = check_str($_POST["device_firmware_version"]);
$device_provision_enable = check_str($_POST["device_provision_enable"]);
$device_template = check_str($_POST["device_template"]);
$device_username = check_str($_POST["device_username"]);
$device_password = check_str($_POST["device_password"]);
$device_time_zone = check_str($_POST["device_time_zone"]);
$device_description = check_str($_POST["device_description"]);
//lines
$line_number = check_str($_POST["line_number"]);
$server_address = check_str($_POST["server_address"]);
$outbound_proxy = check_str($_POST["outbound_proxy"]);
$display_name = check_str($_POST["display_name"]);
$user_id = check_str($_POST["user_id"]);
$auth_id = check_str($_POST["auth_id"]);
$password = check_str($_POST["password"]);
}
//use the mac address to find the vendor
@@ -121,7 +130,7 @@ require_once "includes/require.php";
//if (strlen($device_password) == 0) { $msg .= "Please provide: Password<br>\n"; }
//if (strlen($device_time_zone) == 0) { $msg .= "Please provide: Time Zone<br>\n"; }
//if (strlen($device_description) == 0) { $msg .= "Please provide: Description<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
if (strlen($msg) > 0) {
require_once "includes/header.php";
require_once "includes/persistformvar.php";
echo "<div align='center'>\n";
@@ -137,8 +146,10 @@ require_once "includes/require.php";
//add or update the database
if ($_POST["persistformvar"] != "true") {
if ($action == "add" && permission_exists('device_add')) {
//sql add
//set the device_uuid
$device_uuid = uuid();
//add device
$sql = "insert into v_devices ";
$sql .= "(";
$sql .= "domain_uuid, ";
@@ -173,22 +184,10 @@ require_once "includes/require.php";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//write the provision files
require_once "app/provision/provision_write.php";
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=devices.php\">\n";
echo "<div align='center'>\n";
echo $text['message-add']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($action == "add")
if ($action == "update" && permission_exists('device_edit')) {
//sql update
//update the device
if ($action == "update" && permission_exists('device_edit')) {
$sql = "update v_devices set ";
$sql .= "device_mac_address = '$device_mac_address', ";
$sql .= "device_label = '$device_label', ";
@@ -205,19 +204,51 @@ require_once "includes/require.php";
$sql .= "and device_uuid = '$device_uuid'";
$db->exec(check_sql($sql));
unset($sql);
}
//write the provision files
require_once "app/provision/provision_write.php";
//add line to the device
if (strlen($user_id) > 0 && permission_exists('device_add')) {
$sql = "insert into v_device_lines ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "device_line_uuid, ";
$sql .= "device_uuid, ";
$sql .= "line_number, ";
$sql .= "server_address, ";
$sql .= "outbound_proxy, ";
$sql .= "display_name, ";
$sql .= "user_id, ";
$sql .= "auth_id, ";
$sql .= "password ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'".uuid()."', ";
$sql .= "'$device_uuid', ";
$sql .= "'$line_number', ";
$sql .= "'$server_address', ";
$sql .= "'$outbound_proxy', ";
$sql .= "'$display_name', ";
$sql .= "'$user_id', ";
$sql .= "'$auth_id', ";
$sql .= "'$password' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=devices.php\">\n";
echo "<div align='center'>\n";
echo $text['message-update']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
}
//write the provision files
require_once "app/provision/provision_write.php";
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=devices.php\">\n";
echo "<div align='center'>\n";
echo $text['message-add']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
@@ -293,6 +324,161 @@ require_once "includes/require.php";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-device_template'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo "<select id='device_template' name='device_template' class='formfld'>\n";
echo "<option value=''></option>\n";
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/".$_SESSION["domain_name"])) {
$temp_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/".$_SESSION["domain_name"];
} else {
$temp_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
}
if($dh = opendir($temp_dir)) {
while($dir = readdir($dh)) {
if($file != "." && $dir != ".." && $dir[0] != '.') {
if(is_dir($temp_dir . "/" . $dir)) {
echo "<optgroup label='$dir'>";
if($dh_sub = opendir($temp_dir.'/'.$dir)) {
while($dir_sub = readdir($dh_sub)) {
if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') {
if(is_dir($temp_dir . '/' . $dir .'/'. $dir_sub)) {
if ($device_template == $dir."/".$dir_sub) {
echo "<option value='".$dir."/".$dir_sub."' selected='selected'>".$dir."/".$dir_sub."</option>\n";
}
else {
echo "<option value='".$dir."/".$dir_sub."'>".$dir."/".$dir_sub."</option>\n";
}
}
}
}
closedir($dh_sub);
}
echo "</optgroup>";
}
}
}
closedir($dh);
}
echo "</select>\n";
echo "<br />\n";
echo $text['description-device_template']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>";
echo " <td class='vncell' valign='top'>".$text['label-lines'].":</td>";
echo " <td class='vtable' align='left'>";
if ($action == "update") {
echo " <table width='52%' border='0' cellpadding='0' cellspacing='0'>\n";
$sql = "SELECT * FROM v_device_lines ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "order by line_number asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
echo "<tr>\n";
echo " <td class='vtable'>".$text['label-line']."</td>\n";
echo " <td class='vtable'>".$text['label-server_address']."</td>\n";
echo " <td class='vtable'>".$text['label-outbound_proxy']."</td>\n";
echo " <td class='vtable'>".$text['label-display_name']."</td>\n";
echo " <td class='vtable'>".$text['label-user_id']."</td>\n";
echo " <td class='vtable'>".$text['label-auth_id']."</td>\n";
echo " <td class='vtable'>".$text['label-password']."</td>\n";
echo " <td></td>\n";
echo "</tr>\n";
foreach($result as $row) {
//if (strlen($row['line_number']) == 0) { $row['line_number'] = "1"; }
echo " <tr>\n";
echo " <td class='vtable'>\n";
echo " ".$row['line_number']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['server_address']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['outbound_proxy']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['display_name']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['user_id']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['auth_id']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['password']."&nbsp;\n";
echo " </td>\n";
echo " <td>\n";
if (permission_exists('device_edit')) {
echo " <a href='device_line_edit.php?device_uuid=".$row['device_uuid']."&id=".$row['device_line_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>\n";
}
if (permission_exists('device_delete')) {
echo " <a href='device_line_delete.php?device_uuid=".$row['device_uuid']."&id=".$row['device_line_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>\n";
} echo " </td>\n";
echo " </tr>\n";
}
echo " <tr>\n";
echo " <td class='vtable' valign='top' align='left' nowrap='nowrap'>\n";
echo " <select class='formfld' style='width: 45px;' name='line_number'>\n";
echo " <option value=''></option>\n";
echo " <option value='1'>1</option>\n";
echo " <option value='2'>2</option>\n";
echo " <option value='3'>3</option>\n";
echo " <option value='4'>4</option>\n";
echo " <option value='5'>5</option>\n";
echo " <option value='6'>6</option>\n";
echo " <option value='7'>7</option>\n";
echo " <option value='8'>8</option>\n";
echo " <option value='9'>9</option>\n";
echo " <option value='10'>10</option>\n";
echo " <option value='11'>11</option>\n";
echo " <option value='12'>12</option>\n";
echo " </select>\n";
echo " </td>\n";
echo " <td class='vtable' valign='top' align='left' nowrap='nowrap'>\n";
echo " <input class='formfld' style='width: 125px;' type='text' name='server_address' maxlength='255' value=\"$server_address\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 125px;' type='text' name='outbound_proxy' maxlength='255' value=\"$outbound_proxy\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 95px;' type='text' name='display_name' maxlength='255' value=\"$display_name\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 75px;' type='text' name='user_id' maxlength='255' value=\"$user_id\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 75px;' type='text' name='auth_id' maxlength='255' value=\"$auth_id\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 90px;' type='text' name='password' maxlength='255' value=\"$password\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
}
echo " <br>\n";
echo " ".$text['description-extensions']."\n";
echo " <br />\n";
echo " </td>";
echo " </tr>";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-extension'].":\n";
@@ -436,7 +622,6 @@ require_once "includes/require.php";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-device_vendor'].":\n";