diff --git a/disklocation/pages/config.php b/disklocation/pages/config.php index f56239a..4f53499 100644 --- a/disklocation/pages/config.php +++ b/disklocation/pages/config.php @@ -41,113 +41,103 @@ $group_ids = ( is_array($get_groups) ? array_keys($get_groups) : null ); - foreach($array_groups as $id => $value) { - extract($value); + foreach($array_groups as $id => $array) { + //extract($array); + $gid = $id; $css_grid_group = " grid-template-columns: " . $grid_columns_styles[$gid] . "; grid-template-rows: " . $grid_rows_styles[$gid] . "; - grid-auto-flow: " . $grid_count . "; + grid-auto-flow: " . $array_groups[$gid]["grid_count"] . "; "; - $tray_direction = ( empty($tray_direction) ? 1 : $tray_direction); + $tray_direction = ( empty($array_groups[$gid]["tray_direction"]) ? 1 : $array_groups[$gid]["tray_direction"]); if($count_groups > 0) { $disk_layouts_config .= " -
- -
+ "; } $disk_layouts_config .= " -
-

- Name:
- -

-
- Enter a name for the group, optional. -
-

- Default group color:
- \" /> -

-
- Choose a color for the group, select the first color to disable it. -
-

- Set sizes for trays:
- px longest side
- px shortest side -

-
- This is the HTML/CSS pixel size for a single harddisk tray, default sizes are: 400px longest side, and 70px shortest side. -
-

- Set grid size:
- columns
- rows
- total trays, override -

-
- Set columns and rows to simulate the looks of your trays, ex. 4 columns * 6 rows = 24 total trays. However, you can override the total amount for additional drives you might have which you don\"t want to include in the main setup. The total trays will always scale unless you enter a larger value yourself. This value can be left blank for saving. -
-

- Set physical tray direction:
- horizontal - vertical -

-
- This is the direction of the tray itself. Is it laying flat/horizontal, or is it vertical? -
-

- Tray assigment count properties:
- count rows - count colums -

-
- Select how to count the tray:
- · column: \"top to bottom\" or \"bottom to top\"
- · row: \"left to right\" or \"right to left\" -
-

- Tray assigment count direction:
- left/top - left/bottom -
- right/top - right/bottom -

-
- Select the direction you want to count the trays. -
-

- Tray count start:
- -

-
-

Start counting tray from the entered number.

-
-

- - -

-
-

Save the Disk Tray Layout. This does not save the Common Configuration and the Visible Frontpage Information.

-
-
-
- " . $disklocation_layout[$id] . " -
-
- This shows you an overview of your configured tray layout -
-
+

+ Name:
+ +

+
+ Enter a name for the group, optional. +
+

+ Default group color:
+ \" /> +

+
+ Choose a color for the group, select the first color to disable it. +
+

+ Set sizes for trays:
+ px longest side
+ px shortest side +

+
+ This is the HTML/CSS pixel size for a single harddisk tray, default sizes are: 400px longest side, and 70px shortest side. +
+

+ Set grid size:
+ columns
+ rows
+ total trays, override +

+
+ Set columns and rows to simulate the looks of your trays, ex. 4 columns * 6 rows = 24 total trays. However, you can override the total amount for additional drives you might have which you don\"t want to include in the main setup. The total trays will always scale unless you enter a larger value yourself. This value can be left blank for saving. +
+

+ Set physical tray direction:
+ horizontal + vertical +

+
+ This is the direction of the tray itself. Is it laying flat/horizontal, or is it vertical? +
+

+ Tray assigment count properties:
+ count rows + count colums +

+
+ Select how to count the tray:
+ · column: \"top to bottom\" or \"bottom to top\"
+ · row: \"left to right\" or \"right to left\" +
+

+ Tray assigment count direction:
+ left/top + left/bottom +
+ right/top + right/bottom +

+
+ Select the direction you want to count the trays. +
+

+ Tray count start:
+ +

+
+

Start counting tray from the entered number.

+
+
+
+ " . $disklocation_layout[$id] . " +
+
+ This shows you an overview of your configured tray layout +
"; $last_group_id = $gid; @@ -280,7 +270,6 @@
Show how to display the LEDs on the overview and dashboard. Unraid icons will show triangluar warning signs, crossed critival signs etc. Circular LEDs will all be color coded circular lights.
- - - - " /> - - - manufactured, purchased, installed, warranty, comment -
  • Sort: The "tray" sorting does sort by "TrayID" and not the physical tray. If the tray count is backwards or or have different starting points, it might affect this and show a weird behaviour. It's not a bug nor a feature, it just is what it is.
  • +
  • Possible selectors: group, tray, device, node, pool, name, lun, manufacturer, model, serial, capacity, cache, rotation, formfactor, manufactured, purchased, installed, warranty, comment
  • @@ -466,7 +447,7 @@
    @@ -487,7 +468,7 @@
    @@ -550,28 +531,29 @@

    Disk Tray Layout

    - - - - + +
    - - - - -
    -
    - - - + +
    -
    + + + + + - -
    + + + + +
    +
    + + + - -
    +

    1) { print(""); } ?> - -
    -
    +
    +
    + "); } ?> diff --git a/disklocation/pages/default_settings.php b/disklocation/pages/default_settings.php new file mode 100644 index 0000000..02fc8e8 --- /dev/null +++ b/disklocation/pages/default_settings.php @@ -0,0 +1,71 @@ +. + * + */ + +// 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 + $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). + $device_bg_color = '1'; // choose background for the drives, Drive Type (0) or Heat Map (1) + $serial_trim = '0'; // make serial number friendlier, substr() value -99 - 99. + $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, + 'temperature' => 1, + '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 = "[huge]*pool*[/huge] name node capacity rotation formfactor [color:11ff00]*[serial]*[/color]\r\nmanufacturer model\r\ncomment"; + +// Group settings + + $group_color = $bgcolor_empty; // set default group background color to "empty/disabled" + $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 === +?> diff --git a/disklocation/pages/devices.php b/disklocation/pages/devices.php index ec605c9..e9dc2ea 100644 --- a/disklocation/pages/devices.php +++ b/disklocation/pages/devices.php @@ -41,475 +41,476 @@ foreach($array_groups as $id => $value) { extract($value); - - $gid = $id; - $groupid = $gid; + if(!empty($value["group_name"])) { + $gid = $id; + $groupid = $gid; - $disklocation_page[$gid] = ""; - $disklocation_layout[$gid] = ""; - $disklocation_alloc[$gid] = ""; - $disklocation_dash[$gid] = ""; - - $i_arr=0; - if(!$total_groups) { - foreach($array_devices as $hash => $array) { - if(!$array_devices[$hash]["status"]) { - $datajson[$i_arr] = $array_devices[$hash]; - $datajson[$i_arr]["hash"] = $hash; - $i_arr++; + $disklocation_page[$gid] = ""; + $disklocation_layout[$gid] = ""; + $disklocation_alloc[$gid] = ""; + $disklocation_dash[$gid] = ""; + + $i_arr=0; + if(!$total_groups) { + foreach($array_devices as $hash => $array) { + if(!$array_devices[$hash]["status"]) { + $datajson[$i_arr] = $array_devices[$hash]; + $datajson[$i_arr]["hash"] = $hash; + $i_arr++; + } } } - } - else { - foreach($array_devices as $hash => $array) { - if(!$array_devices[$hash]["status"] && $array_locations[$hash]["groupid"] == $gid) { - $datajson[$i_arr] = $array_devices[$hash]; - $datajson[$i_arr]["hash"] = $hash; - $datajson[$i_arr] += $array_locations[$hash]; - $i_arr++; + else { + foreach($array_devices as $hash => $array) { + if(!$array_devices[$hash]["status"] && $array_locations[$hash]["groupid"] == $gid) { + $datajson[$i_arr] = $array_devices[$hash]; + $datajson[$i_arr]["hash"] = $hash; + $datajson[$i_arr] += $array_locations[$hash]; + $i_arr++; + } } + $datajson = sort_array($datajson, 'groupid', SORT_ASC, SORT_NUMERIC, 'tray', SORT_ASC, SORT_NUMERIC); } - $datajson = sort_array($datajson, 'groupid', SORT_ASC, SORT_NUMERIC, 'tray', SORT_ASC, SORT_NUMERIC); - } - - $total_trays = ( empty($grid_trays) ? $grid_columns * $grid_rows : $grid_trays ); - $total_trays_group += $total_trays; - - if($biggest_tray_group < $total_trays) { - $biggest_tray_group = $total_trays; - } - - if(!$tray_direction) { $tray_direction = 1; } - $tray_number_override = tray_number_assign($grid_columns, $grid_rows, $tray_direction, $grid_count); - - if(!isset($tray_start_num)) { $tray_start_num = 1; } - $tray_number_override_start = $tray_start_num; - - $total_main_trays = 0; - if($total_trays > ($grid_columns * $grid_rows)) { - $total_main_trays = $grid_columns * $grid_rows; - $total_rows_override_trays = ($total_trays - $total_main_trays) / $grid_columns; - $grid_columns_override_styles = str_repeat(" auto", $total_rows_override_trays); - } - - if($disk_tray_direction == "h") { - $insert_break = "
    "; - } - else { - $insert_break = ""; - $tray_swap_height = $tray_height; - $tray_swap_width = $tray_width; + $total_trays = ( empty($grid_trays) ? $grid_columns * $grid_rows : $grid_trays ); + $total_trays_group += $total_trays; - $tray_height = $tray_swap_width; - $tray_width = $tray_swap_height; - } - - debug_print($debugging_active, __LINE__, "var", "Total trays: " . $total_trays . ""); - - $i_empty=1; - $i_drive=1; - $i=1; - $empty_tray = 0; + if($biggest_tray_group < $total_trays) { + $biggest_tray_group = $total_trays; + } + + if(!$tray_direction) { $tray_direction = 1; } + $tray_number_override = tray_number_assign($grid_columns, $grid_rows, $tray_direction, $grid_count); + + if(!isset($tray_start_num)) { $tray_start_num = 1; } + $tray_number_override_start = $tray_start_num; + + $total_main_trays = 0; + if($total_trays > ($grid_columns * $grid_rows)) { + $total_main_trays = $grid_columns * $grid_rows; + $total_rows_override_trays = ($total_trays - $total_main_trays) / $grid_columns; + $grid_columns_override_styles = str_repeat(" auto", $total_rows_override_trays); + } - while($i <= $total_trays) { - $data = isset($datajson[$i_drive-1]) ? $datajson[$i_drive-1] : 0; - $smart = array(); - $tray_assign = $i; - $empty_leddiskop = ""; - $empty_ledsmart = ""; - $empty_ledtemp = ""; - $empty_tray_assign = ""; - $empty_traytext = ""; + if($disk_tray_direction == "h") { + $insert_break = "
    "; + } + else { + $insert_break = ""; + + $tray_swap_height = $tray_height; + $tray_swap_width = $tray_width; + + $tray_height = $tray_swap_width; + $tray_width = $tray_swap_height; + } + + debug_print($debugging_active, __LINE__, "var", "Total trays: " . $total_trays . ""); + + $i_empty=1; + $i_drive=1; + $i=1; + $empty_tray = 0; - if(( isset($data["tray"]) ? $data["tray"] : 0 ) != $i) { - debug_print($debugging_active, __LINE__, "loop", "Empty tray: " . $tray_assign . ""); + while($i <= $total_trays) { + $data = isset($datajson[$i_drive-1]) ? $datajson[$i_drive-1] : 0; + $smart = array(); + $tray_assign = $i; + $empty_leddiskop = ""; + $empty_ledsmart = ""; + $empty_ledtemp = ""; + $empty_tray_assign = ""; + $empty_traytext = ""; - if($displayinfo["tray"] && empty($displayinfo["hideemptycontents"])) { - if($tray_number_override[$tray_assign]) { - $empty_tray = ( !isset($tray_number_override_start) ? --$tray_number_override[$tray_assign] : ($tray_number_override_start + $tray_number_override[$tray_assign] - 1)); - $empty_tray_assign = $tray_number_override[$tray_assign]; + if(( isset($data["tray"]) ? $data["tray"] : 0 ) != $i) { + debug_print($debugging_active, __LINE__, "loop", "Empty tray: " . $tray_assign . ""); + + if($displayinfo["tray"] && empty($displayinfo["hideemptycontents"])) { + if($tray_number_override[$tray_assign]) { + $empty_tray = ( !isset($tray_number_override_start) ? --$tray_number_override[$tray_assign] : ($tray_number_override_start + $tray_number_override[$tray_assign] - 1)); + $empty_tray_assign = $tray_number_override[$tray_assign]; + } + else { + $empty_tray = ( !isset($tray_number_override_start) ? --$tray_assign : $tray_number_override_start + $tray_assign -1); + $empty_tray_assign = $tray_assign; + } } else { - $empty_tray = ( !isset($tray_number_override_start) ? --$tray_assign : $tray_number_override_start + $tray_assign -1); - $empty_tray_assign = $tray_assign; + $empty_tray = ""; } - } - else { - $empty_tray = ""; - } - - if(isset($displayinfo["leddiskop"]) && $displayinfo["leddiskop"] == 1 && empty($displayinfo["hideemptycontents"])) { - $empty_leddiskop = get_unraid_disk_status("grey-off", '', '', $force_orb_led); - } - if(isset($displayinfo["ledsmart"]) && $displayinfo["ledsmart"] == 1 && empty($displayinfo["hideemptycontents"])) { - $empty_ledsmart = get_unraid_disk_status("grey-off", '', '', $force_orb_led); - } - if(isset($displayinfo["ledtemp"]) && $displayinfo["ledtemp"] == 1 && empty($displayinfo["hideemptycontents"])) { - $empty_ledtemp = get_unraid_disk_status("grey-off", '', '', $force_orb_led); - } - if(empty($displayinfo["hideemptycontents"])) { - $empty_traytext = "Available disk slot"; - } - $disklocation_page[$gid] .= " -
    -
    -
    -
    - $empty_tray$insert_break - $empty_leddiskop $insert_break - $empty_ledsmart $insert_break - $empty_ledtemp -
    -
    - $empty_traytext -
    -
    -   + + if(isset($displayinfo["leddiskop"]) && $displayinfo["leddiskop"] == 1 && empty($displayinfo["hideemptycontents"])) { + $empty_leddiskop = get_unraid_disk_status("grey-off", '', '', $force_orb_led); + } + if(isset($displayinfo["ledsmart"]) && $displayinfo["ledsmart"] == 1 && empty($displayinfo["hideemptycontents"])) { + $empty_ledsmart = get_unraid_disk_status("grey-off", '', '', $force_orb_led); + } + if(isset($displayinfo["ledtemp"]) && $displayinfo["ledtemp"] == 1 && empty($displayinfo["hideemptycontents"])) { + $empty_ledtemp = get_unraid_disk_status("grey-off", '', '', $force_orb_led); + } + if(empty($displayinfo["hideemptycontents"])) { + $empty_traytext = "Available disk slot"; + } + $disklocation_page[$gid] .= " +
    +
    +
    +
    + $empty_tray$insert_break + $empty_leddiskop $insert_break + $empty_ledsmart $insert_break + $empty_ledtemp +
    +
    + $empty_traytext +
    +
    +   +
    -
    - "; - - $add_empty_physical_tray_order = ""; - if($tray_assign != $empty_tray) { - $add_empty_physical_tray_order = $tray_assign; - } - - $disklocation_layout[$gid] .= " -
    -
    -
    -
    - $empty_tray -
    -
    -
    -
    - + "; + + $add_empty_physical_tray_order = ""; + if($tray_assign != $empty_tray) { + $add_empty_physical_tray_order = $tray_assign; + } + + $disklocation_layout[$gid] .= " +
    +
    +
    +
    + $empty_tray +
    +
    +
    +
    + +
    -
    - "; - - $add_empty_physical_tray_order = ""; - if($tray_assign != $empty_tray) { - $add_empty_physical_tray_order = $empty_tray; - } - - $disklocation_alloc[$gid] .= " -
    -
    -
    -
    - $tray_assign -
    -
    -
    -
    - " . $add_empty_physical_tray_order . " + "; + + $add_empty_physical_tray_order = ""; + if($tray_assign != $empty_tray) { + $add_empty_physical_tray_order = $empty_tray; + } + + $disklocation_alloc[$gid] .= " +
    +
    +
    +
    + $tray_assign +
    +
    +
    +
    + " . $add_empty_physical_tray_order . " +
    -
    - "; - - $disklocation_dash[$gid] .= " -
    -
    -
    -
    - " . get_unraid_disk_status("grey-off", '', '', $force_orb_led) . " -
    -
    -
    -
    - " . $empty_tray . " + "; + + $disklocation_dash[$gid] .= " +
    +
    +
    +
    + " . get_unraid_disk_status("grey-off", '', '', $force_orb_led) . " +
    +
    +
    +
    + " . $empty_tray . " +
    -
    - "; - - $i_empty++; - } - else { - debug_print($debugging_active, __LINE__, "loop", "Populated tray: " . $tray_assign . ""); - - $device = $data["device"]; - $devicenode = $data["devicenode"]; - $hash = $data["hash"]; - $pool = ""; - $color_override = $data["color"]; - $temp_status = 0; - $temp_status_icon = ""; - $color_status = ""; - $unraid_array_icon = ""; - $physical_traynumber = null; - - if(!$unraid_array[$devicenode]["temp"] || !is_numeric($unraid_array[$devicenode]["temp"])) { // && (!$unraid_array[$devicenode]["temp"] && $unraid_array[$devicenode]["hotTemp"] == 0 && $unraid_array[$devicenode]["maxTemp"] == 0)) { - $unraid_array[$devicenode]["temp"] = 0; + "; - $temp_status_icon = "Temperature unavailable"; - $temp_status_info = array('orb' => 'fa fa-circle orb-disklocation grey-orb-disklocation', 'color' => 'grey', 'text' => 'N/A'); - $temp_status = 0; + $i_empty++; } else { - if($unraid_array[$devicenode]["temp"] < $unraid_array[$devicenode]["hotTemp"]) { - $temp_status_icon = "" . $devices[$hash]["formatted"]["temp"] . ""; - $temp_status_info = array('orb' => 'fa fa-circle orb-disklocation green-orb-disklocation', 'color' => 'green', 'text' => $devices[$hash]["formatted"]["temp"]); - $temp_status = 1; - } - if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["hotTemp"]) { - $temp_status_icon = "" . $smart_temperature . " (Warning: >" . $devices[$hash]["formatted"]["hotTemp"] . ")"; - $temp_status_info = array('orb' => "fa fa-" . ( !$force_orb_led ? 'fire' : 'circle' ) . " orb-disklocation yellow-orb-disklocation", 'color' => 'yellow', 'text' => $devices[$hash]["formatted"]["temp"]); - $temp_status = 2; - } - if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["maxTemp"]) { - $temp_status_icon = "" . $devices[$hash]["formatted"]["temp"] . " (Critical: >" . $devices[$hash]["formatted"]["maxTemp"] . ")"; - $temp_status_info = array('orb' => "fa fa-" . ( !$force_orb_led ? 'fire' : 'circle' ) . " orb-disklocation red-blink-disklocation", 'color' => 'red', 'text' => $devices[$hash]["formatted"]["temp"]); - $temp_status = 3; - } - } - if(!isset($displayinfo["ledtemp"])) { + debug_print($debugging_active, __LINE__, "loop", "Populated tray: " . $tray_assign . ""); + + $device = $data["device"]; + $devicenode = $data["devicenode"]; + $hash = $data["hash"]; + $pool = ""; + $color_override = $data["color"]; + $temp_status = 0; $temp_status_icon = ""; - } - - // Set $smart_status = 2 if $smart_errors was found AND $smart_status has NOT failed AND disk has NOT been acknowledged, else set initial value: - $smart_status = ((!empty($smart_errors) && !empty($smart_status) && !get_disk_ack($unraid_array[$data["devicenode"]]["name"])) ? 2 : $smart_status); - switch($smart_status) { - case 0: - $smart_status_icon = "S.M.A.R.T: Failed! " . $devices[$hash]["formatted"]["smart_errors"] . ""; - $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation red-orb-disklocation', 'color' => 'red', 'text' => 'Failed'); - break; - case 1: - $smart_status_icon = "S.M.A.R.T: Passed"; - $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation green-orb-disklocation', 'color' => 'green', 'text' => 'Passed'); - break; - case 2: - $smart_status_icon = "S.M.A.R.T: Warning! " . $devices[$hash]["formatted"]["smart_errors"] . ""; - $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation yellow-orb-disklocation', 'color' => 'yellow', 'text' => 'Warning'); - break; - default: - $smart_status_icon = "S.M.A.R.T: N/A"; - $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation grey-orb-disklocation', 'color' => 'grey', 'text' => 'N/A'); - } - - if(isset($displayinfo["leddiskop"])) { - $zfs_disk_status = ""; - if($zfs_check) { - $zfs_disk_status = zfs_disk("" . $data["smart_serialnumber"] . "", $zfs_parser, $lsblk_array); - } + $color_status = ""; + $unraid_array_icon = ""; + $physical_traynumber = null; - if(!$zfs_disk_status && isset($unraid_array[$devicenode]["color"]) && isset($unraid_array[$devicenode]["status"])) { - $unraid_array_icon = get_unraid_disk_status($unraid_array[$devicenode]["color"], $unraid_array[$devicenode]["type"], '', $force_orb_led); - $unraid_array_info = get_unraid_disk_status($unraid_array[$devicenode]["color"], $unraid_array[$devicenode]["type"],'array'); - $color_status = get_unraid_disk_status($unraid_array[$devicenode]["color"], $unraid_array[$devicenode]["type"],'color'); + if(!$unraid_array[$devicenode]["temp"] || !is_numeric($unraid_array[$devicenode]["temp"])) { // && (!$unraid_array[$devicenode]["temp"] && $unraid_array[$devicenode]["hotTemp"] == 0 && $unraid_array[$devicenode]["maxTemp"] == 0)) { + $unraid_array[$devicenode]["temp"] = 0; + + $temp_status_icon = "Temperature unavailable"; + $temp_status_info = array('orb' => 'fa fa-circle orb-disklocation grey-orb-disklocation', 'color' => 'grey', 'text' => 'N/A'); + $temp_status = 0; } else { - $smart_powermode = config("/tmp/disklocation/powermode.ini", 'r', $device); - switch($smart_powermode) { - case "ACTIVE": - $unraid_disk_status_color = "green-on"; - break; - case "IDLE": - $unraid_disk_status_color = "green-on"; - break; - case "STANDBY": - $unraid_disk_status_color = "green-blink"; - break; - case "UNKNOWN": - $unraid_disk_status_color = "grey-off"; - break; - default: - $unraid_disk_status_color = "grey-off"; + if($unraid_array[$devicenode]["temp"] < $unraid_array[$devicenode]["hotTemp"]) { + $temp_status_icon = "" . $devices[$hash]["formatted"]["temp"] . ""; + $temp_status_info = array('orb' => 'fa fa-circle orb-disklocation green-orb-disklocation', 'color' => 'green', 'text' => $devices[$hash]["formatted"]["temp"]); + $temp_status = 1; } - if($zfs_disk_status) { - $unraid_array_icon = get_unraid_disk_status($zfs_disk_status[1], '', '', $force_orb_led); - $unraid_array_info = get_unraid_disk_status($zfs_disk_status[1],'','array'); - $color_status = get_unraid_disk_status($zfs_disk_status[1],'','color'); + if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["hotTemp"]) { + $temp_status_icon = "" . $smart_temperature . " (Warning: >" . $devices[$hash]["formatted"]["hotTemp"] . ")"; + $temp_status_info = array('orb' => "fa fa-" . ( !$force_orb_led ? 'fire' : 'circle' ) . " orb-disklocation yellow-orb-disklocation", 'color' => 'yellow', 'text' => $devices[$hash]["formatted"]["temp"]); + $temp_status = 2; } - else { - $unraid_array_icon = get_unraid_disk_status($unraid_disk_status_color, '', '', $force_orb_led); - $unraid_array_info = get_unraid_disk_status($unraid_disk_status_color,'','array'); - $color_status = get_unraid_disk_status($unraid_disk_status_color,'','color'); + if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["maxTemp"]) { + $temp_status_icon = "" . $devices[$hash]["formatted"]["temp"] . " (Critical: >" . $devices[$hash]["formatted"]["maxTemp"] . ")"; + $temp_status_info = array('orb' => "fa fa-" . ( !$force_orb_led ? 'fire' : 'circle' ) . " orb-disklocation red-blink-disklocation", 'color' => 'red', 'text' => $devices[$hash]["formatted"]["temp"]); + $temp_status = 3; } } - } - - $drive_tray_order[$hash] = get_tray_location($get_locations, $hash, $gid); - $drive_tray_order[$hash] = ( !isset($drive_tray_order[$hash]) ? $tray_assign : $drive_tray_order[$hash] ); - if(isset($displayinfo["tray"])) { - if($tray_number_override[$drive_tray_order[$hash]]) { - $drive_tray_order_assign = $tray_number_override[$drive_tray_order[$hash]]; - $physical_traynumber = ( !isset($tray_number_override_start) ? --$tray_number_override[$drive_tray_order[$hash]] : ($tray_number_override_start + $tray_number_override[$drive_tray_order[$hash]] - 1)); - } - else { - $drive_tray_order_assign = $drive_tray_order[$hash]; - $physical_traynumber = ( !isset($tray_number_override_start) ? --$drive_tray_order[$hash] : $drive_tray_order[$hash]); + if(!isset($displayinfo["ledtemp"])) { + $temp_status_icon = ""; } - } - - $color_array[$hash] = ""; - - if(!$dashboard_widget) { // $dashboard_widget is really for Disk Type / Heatmap setting. - switch(strtolower($unraid_array[$devicenode]["type"] ?? '')) { - case "parity": - $color_array[$hash] = $bgcolor_parity; + + // Set $smart_status = 2 if $smart_errors was found AND $smart_status has NOT failed AND disk has NOT been acknowledged, else set initial value: + $smart_status = ((!empty($smart_errors) && !empty($smart_status) && !get_disk_ack($unraid_array[$data["devicenode"]]["name"])) ? 2 : $smart_status); + switch($smart_status) { + case 0: + $smart_status_icon = "S.M.A.R.T: Failed! " . $devices[$hash]["formatted"]["smart_errors"] . ""; + $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation red-orb-disklocation', 'color' => 'red', 'text' => 'Failed'); break; - case "data": - $color_array[$hash] = $bgcolor_unraid; + case 1: + $smart_status_icon = "S.M.A.R.T: Passed"; + $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation green-orb-disklocation', 'color' => 'green', 'text' => 'Passed'); + break; + case 2: + $smart_status_icon = "S.M.A.R.T: Warning! " . $devices[$hash]["formatted"]["smart_errors"] . ""; + $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation yellow-orb-disklocation', 'color' => 'yellow', 'text' => 'Warning'); break; - case "cache": - $color_array[$hash] = $bgcolor_cache; - break; default: - $color_array[$hash] = $bgcolor_others; + $smart_status_icon = "S.M.A.R.T: N/A"; + $smart_status_info = array('orb' => 'fa fa-circle orb-disklocation grey-orb-disklocation', 'color' => 'grey', 'text' => 'N/A'); + } + + if(isset($displayinfo["leddiskop"])) { + $zfs_disk_status = ""; + if($zfs_check) { + $zfs_disk_status = zfs_disk("" . $data["smart_serialnumber"] . "", $zfs_parser, $lsblk_array); + } + + if(!$zfs_disk_status && isset($unraid_array[$devicenode]["color"]) && isset($unraid_array[$devicenode]["status"])) { + $unraid_array_icon = get_unraid_disk_status($unraid_array[$devicenode]["color"], $unraid_array[$devicenode]["type"], '', $force_orb_led); + $unraid_array_info = get_unraid_disk_status($unraid_array[$devicenode]["color"], $unraid_array[$devicenode]["type"],'array'); + $color_status = get_unraid_disk_status($unraid_array[$devicenode]["color"], $unraid_array[$devicenode]["type"],'color'); + } + else { + $smart_powermode = config("/tmp/disklocation/powermode.ini", 'r', $device); + switch($smart_powermode) { + case "ACTIVE": + $unraid_disk_status_color = "green-on"; + break; + case "IDLE": + $unraid_disk_status_color = "green-on"; + break; + case "STANDBY": + $unraid_disk_status_color = "green-blink"; + break; + case "UNKNOWN": + $unraid_disk_status_color = "grey-off"; + break; + default: + $unraid_disk_status_color = "grey-off"; + } + if($zfs_disk_status) { + $unraid_array_icon = get_unraid_disk_status($zfs_disk_status[1], '', '', $force_orb_led); + $unraid_array_info = get_unraid_disk_status($zfs_disk_status[1],'','array'); + $color_status = get_unraid_disk_status($zfs_disk_status[1],'','color'); + } + else { + $unraid_array_icon = get_unraid_disk_status($unraid_disk_status_color, '', '', $force_orb_led); + $unraid_array_info = get_unraid_disk_status($unraid_disk_status_color,'','array'); + $color_status = get_unraid_disk_status($unraid_disk_status_color,'','color'); + } + } } - if($color_override) { - $color_array[$hash] = $color_override; + + $drive_tray_order[$hash] = get_tray_location($get_locations, $hash, $gid); + $drive_tray_order[$hash] = ( !isset($drive_tray_order[$hash]) ? $tray_assign : $drive_tray_order[$hash] ); + if(isset($displayinfo["tray"])) { + if($tray_number_override[$drive_tray_order[$hash]]) { + $drive_tray_order_assign = $tray_number_override[$drive_tray_order[$hash]]; + $physical_traynumber = ( !isset($tray_number_override_start) ? --$tray_number_override[$drive_tray_order[$hash]] : ($tray_number_override_start + $tray_number_override[$drive_tray_order[$hash]] - 1)); + } + else { + $drive_tray_order_assign = $drive_tray_order[$hash]; + $physical_traynumber = ( !isset($tray_number_override_start) ? --$drive_tray_order[$hash] : $drive_tray_order[$hash]); + } } - } - else { - if($unraid_array[$devicenode]["temp"] < $unraid_array[$devicenode]["hotTemp"]) { - $color_array[$hash] = $bgcolor_cache; + + $color_array[$hash] = ""; + + if(!$dashboard_widget) { // $dashboard_widget is really for Disk Type / Heatmap setting. + switch(strtolower($unraid_array[$devicenode]["type"] ?? '')) { + case "parity": + $color_array[$hash] = $bgcolor_parity; + break; + case "data": + $color_array[$hash] = $bgcolor_unraid; + break; + case "cache": + $color_array[$hash] = $bgcolor_cache; + break; + default: + $color_array[$hash] = $bgcolor_others; + } + if($color_override) { + $color_array[$hash] = $color_override; + } } - if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["hotTemp"]) { - $color_array[$hash] = $bgcolor_unraid; + else { + if($unraid_array[$devicenode]["temp"] < $unraid_array[$devicenode]["hotTemp"]) { + $color_array[$hash] = $bgcolor_cache; + } + if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["hotTemp"]) { + $color_array[$hash] = $bgcolor_unraid; + } + if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["maxTemp"]) { + $color_array[$hash] = $bgcolor_parity; + } + if(!$unraid_array[$devicenode]["temp"] && (!$unraid_array[$devicenode]["temp"] && $unraid_array[$devicenode]["hotTemp"] == 0 && $unraid_array[$devicenode]["maxTemp"] == 0)) { + $color_array[$hash] = $bgcolor_others; + } } - if($unraid_array[$devicenode]["temp"] >= $unraid_array[$devicenode]["maxTemp"]) { - $color_array[$hash] = $bgcolor_parity; + + $add_anim_bg_class = ""; + $color_array_blinker = ""; + if(isset($displayinfo["flashwarning"]) && ($temp_status == 2 || $smart_status == 2 || $color_status == "yellow")) { // warning + $color_array_blinker = "blinker-disklocation-yellow-bg"; + $add_anim_bg_class = "class=\"yellow-blink-disklocation-bg\""; } - if(!$unraid_array[$devicenode]["temp"] && (!$unraid_array[$devicenode]["temp"] && $unraid_array[$devicenode]["hotTemp"] == 0 && $unraid_array[$devicenode]["maxTemp"] == 0)) { - $color_array[$hash] = $bgcolor_others; + if(isset($displayinfo["flashcritical"]) && ($temp_status == 3 || !$smart_status || $color_status == "red")) { // critical + $color_array_blinker = "blinker-disklocation-red-bg"; + $add_anim_bg_class = "class=\"red-blink-disklocation-bg\""; } - } - - $add_anim_bg_class = ""; - $color_array_blinker = ""; - if(isset($displayinfo["flashwarning"]) && ($temp_status == 2 || $smart_status == 2 || $color_status == "yellow")) { // warning - $color_array_blinker = "blinker-disklocation-yellow-bg"; - $add_anim_bg_class = "class=\"yellow-blink-disklocation-bg\""; - } - if(isset($displayinfo["flashcritical"]) && ($temp_status == 3 || !$smart_status || $color_status == "red")) { // critical - $color_array_blinker = "blinker-disklocation-red-bg"; - $add_anim_bg_class = "class=\"red-blink-disklocation-bg\""; - } - - $disklocation_page[$gid] .= " -
    -
    -
    -
    - $physical_traynumber$insert_break - $unraid_array_icon $insert_break - $smart_status_icon $insert_break - $temp_status_icon -
    -
    - " . keys_to_content(bscode2html(nl2br(stripslashes(htmlspecialchars($select_db_devices)))), $devices[$hash]["formatted"]) . " + + $disklocation_page[$gid] .= " +
    +
    +
    +
    + $physical_traynumber$insert_break + $unraid_array_icon $insert_break + $smart_status_icon $insert_break + $temp_status_icon +
    +
    + " . keys_to_content(bscode2html(nl2br(stripslashes(htmlspecialchars($select_db_devices)))), $devices[$hash]["formatted"]) . " +
    -
    - "; - - $add_physical_tray_order = ""; - if($drive_tray_order[$hash] != $physical_traynumber) { - $add_physical_tray_order = $drive_tray_order[$hash]; - } - - $disklocation_layout[$gid] .= " -
    -
    -
    -
    - $physical_traynumber -
    -
    -
    -
    - + "; + + $add_physical_tray_order = ""; + if($drive_tray_order[$hash] != $physical_traynumber) { + $add_physical_tray_order = $drive_tray_order[$hash]; + } + + $disklocation_layout[$gid] .= " +
    +
    +
    +
    + $physical_traynumber +
    +
    +
    +
    + +
    -
    - "; - - $add_physical_tray_order = ""; - if($drive_tray_order[$hash] != $physical_traynumber) { - $add_physical_tray_order = $physical_traynumber; - } - - $disklocation_alloc[$gid] .= " -
    -
    -
    -
    - " . $drive_tray_order[$hash] . " -
    -
    -
    -
    - " . $add_physical_tray_order . " + "; + + $add_physical_tray_order = ""; + if($drive_tray_order[$hash] != $physical_traynumber) { + $add_physical_tray_order = $physical_traynumber; + } + + $disklocation_alloc[$gid] .= " +
    +
    +
    +
    + " . $drive_tray_order[$hash] . " +
    +
    +
    +
    + " . $add_physical_tray_order . " +
    -
    - "; - - // SMART=PASS: show array LED - if($smart_status == 1) { - $dashboard_orb = $unraid_array_info["orb"]; + "; - } - // TEMP STATUS=warning|critical: show temp warning - if(isset($temp_status) && $temp_status > 1) { - $dashboard_orb = $temp_status_info["orb"]; - - } - // SMART=FAIL/WARN: show SMART LED - if(isset($smart_status) && ($smart_status == 0 || $smart_status == 2)) { - $dashboard_orb = $smart_status_info["orb"]; + // SMART=PASS: show array LED + if($smart_status == 1) { + $dashboard_orb = $unraid_array_info["orb"]; + + } + // TEMP STATUS=warning|critical: show temp warning + if(isset($temp_status) && $temp_status > 1) { + $dashboard_orb = $temp_status_info["orb"]; + + } + // SMART=FAIL/WARN: show SMART LED + if(isset($smart_status) && ($smart_status == 0 || $smart_status == 2)) { + $dashboard_orb = $smart_status_info["orb"]; + + } + $dashboard_text = "" . $temp_status_info["text"] . " | SMART: " . $smart_status_info["text"] . ", " . $unraid_array_info["text"] . ""; - } - $dashboard_text = "" . $temp_status_info["text"] . " | SMART: " . $smart_status_info["text"] . ", " . $unraid_array_info["text"] . ""; - - $disklocation_dash[$gid] .= " -
    -
    -
    - -
    -
    -
    - $physical_traynumber + $disklocation_dash[$gid] .= " +
    +
    +
    + +
    +
    +
    + $physical_traynumber +
    -
    - "; - $installed_drives[$gid] = $i_drive; - $i_drive++; - } - - if($total_main_trays == $i) { - $disklocation_page[$gid] .= "
    "; - $disklocation_layout[$gid] .= "
    "; - $disklocation_alloc[$gid] .= "
    "; - $disklocation_dash[$gid] .= "
    "; + "; + $installed_drives[$gid] = $i_drive; + $i_drive++; + } + + if($total_main_trays == $i) { + $disklocation_page[$gid] .= "
    "; + $disklocation_layout[$gid] .= "
    "; + $disklocation_alloc[$gid] .= "
    "; + $disklocation_dash[$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("");