";
+ ";
+ $installed_drives[$gid] = $i_drive;
+ $i_drive++;
+ }
+
+ if($total_main_trays == $i) {
+ $disklocation_page[$gid] .= "
";
+ }
+
+ $i++;
}
+ $grid_columns_styles[$gid] = str_repeat(" auto", $grid_columns);
+ $grid_rows_styles[$gid] = str_repeat(" auto", $grid_rows);
- $i++;
+ unset($datajson); // delete array
}
- $grid_columns_styles[$gid] = str_repeat(" auto", $grid_columns);
- $grid_rows_styles[$gid] = str_repeat(" auto", $grid_rows);
-
- unset($datajson); // delete array
}
//print_r($devices); // for debugging
diff --git a/disklocation/pages/functions.php b/disklocation/pages/functions.php
index 11cecae..298344c 100644
--- a/disklocation/pages/functions.php
+++ b/disklocation/pages/functions.php
@@ -98,6 +98,7 @@
$disklocation_new_install = 1;
}
+ require_once("default_settings.php");
( file_exists("sqlite_tables.php") ?? require_once("sqlite_tables.php" ) );
//( (file_exists("sqlite_tables.php") && file_exists(DISKLOCATION_CONF) && file_exists(DISKLOCATION_DEVICES) && file_exists(DISKLOCATION_LOCATIONS) && file_exists(DISKLOCATION_GROUPS)) ?? unlink("sqlite_table.php") );
@@ -271,7 +272,7 @@ function config_array($file, $operation, $array = '') { // file, [r]ead/[w]rite,
}
if($operation == 'r') {
$contents = file_get_contents($file);
- $cur_array = json_decode($content, true);
+ $cur_array = json_decode($contents, true);
return $cur_array;
}
else return false;
@@ -819,44 +820,31 @@ function force_undelete_devices($db, $action) {
}
}
- function force_reset_color($db, $hash = 0) {
+ function force_reset_color($config, $devices, $groups, $hash = 0) {
global $bgcolor_parity_default, $bgcolor_unraid_default, $bgcolor_cache_default, $bgcolor_others_default, $bgcolor_empty_default;
if($hash == '*' || $hash == 'all') {
- $sql_status = "
- UPDATE disks SET
- color = ''
- ;
- ";
+ foreach($devices as $id => $data) { // id=hash not $hash
+ $devices[$id]["color"] = '';
+ }
+ foreach($groups as $id => $data) {
+ $groups[$id]["group_color"] = 'test';
+ }
+ return ((config_array(DISKLOCATION_DEVICES, 'w', $devices) && config_array(DISKLOCATION_GROUPS, 'w', $groups)) ? true : false );
}
else if($hash) {
- $sql_status .= "
- UPDATE disks SET
- color = ''
- ;
- WHERE hash = '" . $hash . "';
- ";
+ $devices[$hash]["color"] = '';
+ return config_array(DISKLOCATION_DEVICES, 'w', $devices);
}
else {
- $sql_status = "
- UPDATE settings SET
- bgcolor_parity = '" . $bgcolor_parity_default . "',
- bgcolor_unraid = '" . $bgcolor_unraid_default . "',
- bgcolor_cache = '" . $bgcolor_cache_default . "',
- bgcolor_others = '" . $bgcolor_others_default . "',
- bgcolor_empty = '" . $bgcolor_empty_default . "'
- ;
- WHERE id = '1';
- ";
- $hash = 1;
- }
-
- $ret = $db->exec($sql_status);
- if(!$ret) {
- return $db->lastErrorMsg();
- }
- else {
- return $hash;
+ foreach($config as $key => $data) {
+ $config["bgcolor_parity"] = $bgcolor_parity_default;
+ $config["bgcolor_unraid"] = $bgcolor_unraid_default;
+ $config["bgcolor_cache"] = $bgcolor_cache_default;
+ $config["bgcolor_others"] = $bgcolor_others_default;
+ $config["bgcolor_empty"] = $bgcolor_empty_default;
+ }
+ return !config_array(DISKLOCATION_CONF, 'w', $config);
}
}
diff --git a/disklocation/pages/info.php b/disklocation/pages/info.php
index b71d023..bc74c49 100644
--- a/disklocation/pages/info.php
+++ b/disklocation/pages/info.php
@@ -119,6 +119,8 @@
"groupid" => "
" . stripslashes(htmlspecialchars($formatted["group_name"])) . " | ",
"tray" => "
" . $physical_traynumber . " | ",
"device" => "
" . $formatted["device"] . " | ",
+ "pool" => "
" . $formatted["pool"] . " | ",
+ "name" => "
" . $formatted["name"] . " | ",
"node" => "
" . $formatted["node"] . " | ",
"lun" => "
" . $formatted["lun"] . " | ",
"manufacturer" => "
" . $formatted["manufacturer"] . " | ",
diff --git a/disklocation/pages/load_settings.php b/disklocation/pages/load_settings.php
index 992c2c1..9846a04 100644
--- a/disklocation/pages/load_settings.php
+++ b/disklocation/pages/load_settings.php
@@ -19,13 +19,29 @@
*
*/
+ if(isset($SUBMIT_RELOAD)) {
+ print("
+
+ ");
+ }
+
if(file_exists(DISKLOCATION_CONF)) {
- $get_config = json_decode(file_get_contents(DISKLOCATION_CONF), true);
+ $get_disklocation_config = json_decode(file_get_contents(DISKLOCATION_CONF), true);
+ }
+ if(file_exists(DISKLOCATION_LOCATIONS)) {
+ $get_locations = json_decode(file_get_contents(DISKLOCATION_LOCATIONS), true);
+ }
+ if(file_exists(DISKLOCATION_GROUPS)) {
+ $get_groups = json_decode(file_get_contents(DISKLOCATION_GROUPS), true);
}
$displayinfo = ""; // reset variable, otherwise it will be reloaded as an array and fault.
- extract($get_config);
+ extract($get_disklocation_config);
$color_array = array();
$color_array["empty"] = $bgcolor_empty;
diff --git a/disklocation/pages/sqlite_tables.php b/disklocation/pages/sqlite_tables.php
index 8600bc6..deda309 100644
--- a/disklocation/pages/sqlite_tables.php
+++ b/disklocation/pages/sqlite_tables.php
@@ -27,91 +27,6 @@
exit();
}
-// Common settings
-// Variable name Default value Description
-// --------------------------------------------------------------------------------
- $smart_exec_delay = '200'; // set milliseconds for next execution for SMART shell_exec - needed to actually grab all the information for unassigned devices. Default: 200
- $smart_updates = 'disabled'; // set how often to update the cronjob [hourly|daily|weekly|monthly|disabled]
- $bgcolor_parity = 'ca3f33'; // background color for Unraid parity disks / critical temp
- $bgcolor_unraid = 'ca7233'; // background color for Unraid data disks / warning temp // old default: ef6441
- $bgcolor_cache = 'cabd33'; // background color for Unraid cache disks / normal temp // old default: ff884c
- $bgcolor_others = '3398ca'; // background color for unassigned/other disks / unknown temp // old default: 41b5ef
- $bgcolor_empty = '7c7c7c'; // background color for empty trays // old default: aaaaaa
- $tray_reduction_factor = '10'; // set the scale divider for the mini tray layout
- $force_orb_led = '0'; // set the LED to 0: show Unraid icons (triangle warning / hot critical) - 1: show circle LEDs (color coded circles).
- $warranty_field = 'u'; // choose [u]nraid's way of entering warranty date (12/24/36... months) or enter [m]anual ISO dates.
- $dashboard_widget = '1'; // choose background for the drives, Drive Type (0) or Heat Map (1)
- $dashboard_widget_pos = '0'; // make serial number friendlier, substr() value -99 - 99.
- $reallocated_sector_w = '1'; // SMART warnings (RAW)
- $reported_uncorr_w = '1'; // -
- $command_timeout_w = '0'; // '-> disabled by default as Seagate devices reports this different from other manufacturers.
- $pending_sector_w = '1'; // -
- $offline_uncorr_w = '1'; // -
- $css_serial_number_highlight = 'font-weight: bold;'; // user styles for serial number
- $displayinfo = json_encode(array( // this will store an json_encoded array of display settings for the "Device" page.
- 'tray' => 1,
- 'leddiskop' => 1,
- 'ledsmart' => 1,
- 'ledtemp' => 1,
- 'unraidinfo' => 1,
- 'path' => 0,
- 'devicenode' => 0,
- 'luname' => 0,
- 'manufacturer' => 1,
- 'devicemodel' => 1,
- 'serialnumber' => 1,
- 'temperature' => 1,
- 'powerontime' => 1,
- 'loadcyclecount' => 1,
- 'capacity' => 1,
- 'cache' => 1,
- 'rotation' => 1,
- 'formfactor' => 1,
- 'reallocated_sector_count' => 0,
- 'reported_uncorrectable_errors' => 0,
- 'command_timeout' => 0,
- 'current_pending_sector_count' => 0,
- 'offline_uncorrectable' => 0,
- 'available_spare' => 1,
- 'percentage_used' => 1,
- 'units_read' => 1,
- 'units_written' => 1,
- 'manufactured' => 0,
- 'purchased' => 0,
- 'installed' => 0,
- 'warranty' => 0,
- 'comment' => 0,
- 'hideemptycontents' => 0,
- 'flashwarning' => 0,
- 'flashcritical' => 1
- ));
-
- $select_db_info = "group,tray,manufacturer,model,serial,capacity,cache,rotation,formfactor,read,written,manufactured,purchased,installed,warranty,comment";
- $sort_db_info = "asc:group,tray";
-
- // mandatory: group,tray,locate,color
- $select_db_trayalloc = "device,node,lun,manufacturer,model,serial,capacity,rotation,formfactor,manufactured,purchased,installed,warranty,comment";
- $sort_db_trayalloc = "asc:group,tray";
-
- $select_db_drives = "device,manufacturer,model,serial,capacity,cache,rotation,formfactor,manufactured,purchased,installed,removed,warranty,comment";
- $sort_db_drives = "asc:serial";
-
- //not used, but prepared just in case it will be added in the future:
- $select_db_devices = "";
- $sort_db_devices = "";
-
-// Group settings
-
- $grid_count = 'column'; // how to count the trays: [column]: trays ordered from top to bottom from left to right | [row]: ..from left to right from top to bottom
- $grid_columns = '4'; // number of horizontal trays
- $grid_rows = '6'; // number of verical trays
- $grid_trays = ''; // total number of trays. default this is (grid_columns * grid_rows), but we choose to add some flexibility for drives outside normal trays
- $disk_tray_direction = 'h'; // direction of the hard drive trays [h]horizontal | [v]ertical
- $tray_direction = '1'; // tray count direction
- $tray_start_num = '1'; // tray count start number, 0 or 1
- $tray_width = '400'; // the pixel width of the hard drive tray: in the horizontal direction ===
- $tray_height = '70'; // the pixel height of the hard drive tray: in the horizontal direction ===
-
// Create database
$sql_create_disks = "
diff --git a/disklocation/pages/system.php b/disklocation/pages/system.php
index 8690b26..4b060cf 100644
--- a/disklocation/pages/system.php
+++ b/disklocation/pages/system.php
@@ -72,61 +72,81 @@
}
if(isset($_POST["group_add"])) {
- $sql = "
- INSERT INTO settings_group(group_name) VALUES('');
- ";
-
- $ret = $db->exec($sql);
- if(!$ret) {
- echo $db->lastErrorMsg();
- }
-
- //$db->close();
-
+ $gid = ( empty($_POST["last_group_id"]) ? 1 : $_POST["last_group_id"]+1 );
+ $groups = config_array(DISKLOCATION_GROUPS, 'r');
+ $groups[$gid] = array(
+ "group_color" => $group_color,
+ "grid_count" => $grid_count,
+ "grid_columns" => $grid_columns,
+ "grid_rows" => $grid_rows,
+ "grid_trays" => $grid_trays,
+ "disk_tray_direction" => $disk_tray_direction,
+ "tray_direction" => $tray_direction,
+ "tray_start_num" => $tray_start_num,
+ "tray_width" => $tray_width,
+ "tray_height" => $tray_height
+ );
+ config_array(DISKLOCATION_GROUPS, 'w', $groups);
+
+ $SUBMIT_RELOAD = 1;
//header("Location: " . DISKLOCATION_URL);
//print("
");
//exit;
}
if(isset($_POST["group_del"]) && isset($_POST["last_group_id"])) {
- $sql = "
- DELETE FROM settings_group WHERE id = '" . $_POST["last_group_id"] . "';
- DELETE FROM location WHERE groupid = '" . $_POST["last_group_id"] . "';
- ";
-
- $ret = $db->exec($sql);
- if(!$ret) {
- echo $db->lastErrorMsg();
+ $gid = $_POST["last_group_id"];
+ $groups = config_array(DISKLOCATION_GROUPS, 'r');
+ unset($groups[$gid]);
+
+ $locations = config_array(DISKLOCATION_LOCATIONS, 'r');
+ foreach($locations as $hash => $array) {
+ if($locations[$hash]["groupid"] == $gid) {
+ unset($locations[$hash]);
+ }
}
- //$db->close();
+ config_array(DISKLOCATION_GROUPS, 'w', $groups);
+ config_array(DISKLOCATION_LOCATIONS, 'w', $locations);
+ $SUBMIT_RELOAD = 1;
//header("Location: " . DISKLOCATION_URL);
//print("
");
//exit;
}
if(isset($_POST["group_swap"])) {
list($group_left, $group_right) = explode(":", $_POST["group_swap"]);
- $sql = "
- UPDATE location SET
- groupid = (CASE WHEN groupid = '" . $group_left . "' THEN '" . $group_right . "' ELSE '" . $group_left . "' END) WHERE groupid IN (" . $group_left . ", " . $group_right . ")
- ;
- BEGIN;
- CREATE TEMPORARY TABLE tmp_sg AS SELECT * FROM settings_group WHERE id = '" . $group_left . "';
- DELETE FROM settings_group WHERE id = '" . $group_left . "';
- UPDATE settings_group SET id = '" . $group_left . "' WHERE id = " . $group_right . ";
- UPDATE tmp_sg SET id = " . $group_right . " WHERE id = '" . $group_left . "';
- INSERT INTO settings_group SELECT * FROM tmp_sg;
- DROP TABLE tmp_sg;
- COMMIT;
- ";
-
- $ret = $db->exec($sql);
- if(!$ret) {
- echo $db->lastErrorMsg();
+ $groups = config_array(DISKLOCATION_GROUPS, 'r');
+ $groups["swap_left"] = $groups[$group_left];
+ $groups["swap_right"] = $groups[$group_right];
+ $groups[$group_right] = $groups["swap_left"];
+ $groups[$group_left] = $groups["swap_right"];
+ unset($groups["swap_left"]);
+ unset($groups["swap_right"]);
+
+ $locations = config_array(DISKLOCATION_LOCATIONS, 'r');
+ foreach($locations as $hash => $array) {
+ if($array["groupid"] == $group_left) {
+ $locations[$hash]["swap_right"] = $group_right;
+ }
+ if($array["groupid"] == $group_right) {
+ $locations[$hash]["swap_left"] = $group_left;
+ }
+ }
+ foreach($locations as $hash => $array) {
+ if($array["groupid"] == $group_left) {
+ $locations[$hash]["groupid"] = $locations[$hash]["swap_right"];
+ unset($locations[$hash]["swap_right"]);
+ }
+ if($array["groupid"] == $group_right) {
+ $locations[$hash]["groupid"] = $locations[$hash]["swap_left"];
+ unset($locations[$hash]["swap_left"]);
+ }
}
- //$db->close();
+ config_array(DISKLOCATION_GROUPS, 'w', $groups);
+ config_array(DISKLOCATION_LOCATIONS, 'w', $locations);
+ $SUBMIT_RELOAD = 1;
//header("Location: " . DISKLOCATION_URL);
//print("
");
//exit;
@@ -143,7 +163,7 @@
}
// settings
- if(!preg_match("/[0-9]{1,5}/", $_POST["smart_exec_delay"])) { $disklocation_error[] = "SMART execution delay missing or invalid number."; }
+ //if(!preg_match("/[0-9]{1,5}/", $_POST["smart_exec_delay"])) { $disklocation_error[] = "SMART execution delay missing or invalid number."; }
//if(!preg_match("/(hourly|daily|weekly|monthly|disabled)/", $_POST["smart_updates"])) { $disklocation_error[] = "Invalid data for SMART updates."; }
if(!preg_match("/#([a-f0-9]{3}){1,2}\b/i", $_POST["bgcolor_parity"])) { $disklocation_error[] = "Background color for \"Parity\" invalid."; } else { $_POST["bgcolor_parity"] = str_replace("#", "", $_POST["bgcolor_parity"]); }
if(!preg_match("/#([a-f0-9]{3}){1,2}\b/i", $_POST["bgcolor_unraid"])) { $disklocation_error[] = "Background color for \"Data\" invalid."; } else { $_POST["bgcolor_unraid"] = str_replace("#", "", $_POST["bgcolor_unraid"]); }
@@ -196,54 +216,45 @@
config_array(DISKLOCATION_CONF, 'w', $array);
+ $SUBMIT_RELOAD = 1;
//header("Location: " . DISKLOCATION_URL);
//print("
");
//exit;
}
}
- if(isset($_POST["save_groupsettings"]) && isset($_POST["groupid"])) {
+ if(isset($_POST["save_groupsettings"])) {
debug_print($debugging_active, __LINE__, "POST", "Button: SAVE GROUP SETTINGS has been pressed.");
- $sql = "";
- // settings
- if(!preg_match("/\b(column|row)\b/", $_POST["grid_count"])) { $disklocation_error[] = "Physical tray assignment invalid."; }
- if(!preg_match("/[0-9]{1,3}/", $_POST["grid_columns"])) { $disklocation_error[] = "Grid columns missing or number invalid."; }
- if(!preg_match("/[0-9]{1,3}/", $_POST["grid_rows"])) { $disklocation_error[] = "Grid rows missing or number invalid."; }
- if($_POST["grid_trays"] && !preg_match("/[0-9]{1,3}/", $_POST["grid_trays"])) { $disklocation_error[] = "Grid trays number invalid."; }
- if(!preg_match("/(h|v)/", $_POST["disk_tray_direction"])) { $disklocation_error[] = "Physical tray direction invalid."; }
- if(!preg_match("/[0-9]{1}/", $_POST["tray_direction"])) { $disklocation_error[] = "Tray number direction invalid."; }
- if(!preg_match("/[0-9]{1,7}/", $_POST["tray_start_num"])) { $disklocation_error[] = "Tray start number invalid."; }
- if(!preg_match("/[0-9]{1,4}/", $_POST["tray_width"])) { $disklocation_error[] = "Tray's longest side outside limits or invalid number entered."; }
- if(!preg_match("/[0-9]{1,3}/", $_POST["tray_height"])) { $disklocation_error[] = "Tray's smallest side outside limits or invalid number entered."; }
- if(!preg_match("/[0-9]{1,}/", $_POST["groupid"])) { $disklocation_error[] = "Expected group ID to be an integer."; }
+ unset($_POST["save_groupsettings"]);
+ unset($_POST["last_group_id"]);
- if(empty($disklocation_error)) {
- $sql .= "
- UPDATE settings_group SET
- group_name = '" . SQLite3::escapeString($_POST["group_name"]) . "',
- grid_count = '" . $_POST["grid_count"] . "',
- grid_columns = '" . $_POST["grid_columns"] . "',
- grid_rows = '" . $_POST["grid_rows"] . "',
- grid_trays = '" . ( empty($_POST["grid_trays"]) ? null : $_POST["grid_trays"] ) . "',
- disk_tray_direction = '" . $_POST["disk_tray_direction"] . "',
- tray_direction = '" . $_POST["tray_direction"] . "',
- tray_start_num = '" . $_POST["tray_start_num"] . "',
- tray_width = '" . $_POST["tray_width"] . "',
- tray_height = '" . $_POST["tray_height"] . "'
- WHERE id = '" . $_POST["groupid"] . "'
- ;
- ";
-
- debug_print($debugging_active, __LINE__, "SQL", "GROUP SETTINGS:
" . $sql . "
");
-
- $ret = $db->exec($sql);
- if(!$ret) {
- echo $db->lastErrorMsg();
+ $new_array = array();
+ foreach($_POST as $settings => $array) {
+ foreach($array as $id => $data) {
+ $new_array[$id][$settings] = $data;
+ $new_array[$id]["group_name"] = stripslashes(htmlspecialchars($new_array[$id]["group_name"]));
}
+ }
+
+ foreach($new_array as $id => $setting) {
+ if($new_array[$id]["group_color"] && !preg_match("/#([a-f0-9]{3}){1,2}\b/i", $new_array[$id]["group_color"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Background color invalid."; } else { $new_array[$id]["group_color"] = str_replace("#", "", $new_array[$id]["group_color"]); }
+ if($new_array[$id]["grid_count"] && !preg_match("/\b(column|row)\b/", $new_array[$id]["grid_count"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Physical tray assignment invalid."; }
+ if($new_array[$id]["grid_columns"] && !preg_match("/[0-9]{1,3}/", $new_array[$id]["grid_columns"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Grid columns missing or number invalid."; }
+ if($new_array[$id]["grid_rows"] && !preg_match("/[0-9]{1,3}/", $new_array[$id]["grid_rows"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Grid rows missing or number invalid."; }
+ if($new_array[$id]["grid_trays"] && !preg_match("/[0-9]{1,3}/", $new_array[$id]["grid_trays"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Grid trays number invalid."; }
+ if($new_array[$id]["disk_tray_direction"] && !preg_match("/(h|v)/", $new_array[$id]["disk_tray_direction"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Physical tray direction invalid."; }
+ if($new_array[$id]["tray_direction"] && !preg_match("/[0-9]{1}/", $new_array[$id]["tray_direction"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Tray number direction invalid."; }
+ if($new_array[$id]["tray_start_num"] && !preg_match("/[0-9]{1,7}/", $new_array[$id]["tray_start_num"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Tray start number invalid."; }
+ if($new_array[$id]["tray_width"] && !preg_match("/[0-9]{1,4}/", $new_array[$id]["tray_width"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Tray's longest side outside limits or invalid number entered."; }
+ if($new_array[$id]["tray_height"] && !preg_match("/[0-9]{1,3}/", $new_array[$id]["tray_height"])) { $disklocation_error[] = "" . $new_array[$id]["group_name"] . ": Tray's smallest side outside limits or invalid number entered."; }
+ if($id && !preg_match("/[0-9]{1,}/", $id)) { $disklocation_error[] = "" . $id . ": Expected group ID to be an integer."; }
+ }
+
+ if(empty($disklocation_error)) {
+ config_array(DISKLOCATION_GROUPS, "w", $new_array);
- //$db->close();
-
+ $SUBMIT_RELOAD = 1;
//header("Location: " . DISKLOCATION_URL);
//print("
");
//exit;
@@ -389,7 +400,7 @@
}
if(isset($_POST["reset_all_colors"])) {
- force_reset_color($db, "*");
+ force_reset_color($get_disklocation_config, $get_devices, $get_groups, "*");
//if(force_reset_color($db, "*")) {
//$db->close();
//print("
");
@@ -397,7 +408,7 @@
//}
}
if(isset($_POST["reset_common_colors"])) {
- force_reset_color($db);
+ force_reset_color($get_disklocation_config, $get_devices, $get_groups);
//if(force_reset_color($db)) {
//$db->close();
//print("
");