From aaebd5e23768b5d20f6fb774107b34298632f80c Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Sat, 8 Jul 2023 09:02:46 +0100 Subject: [PATCH] Sigle Line Update for Modprobe --- emhttp/plugins/dynamix/SysDrivers.page | 84 +++---------------- emhttp/plugins/dynamix/include/SysDrivers.php | 39 +++++---- 2 files changed, 34 insertions(+), 89 deletions(-) diff --git a/emhttp/plugins/dynamix/SysDrivers.page b/emhttp/plugins/dynamix/SysDrivers.page index 3c6a1d412..9616ff0ee 100644 --- a/emhttp/plugins/dynamix/SysDrivers.page +++ b/emhttp/plugins/dynamix/SysDrivers.page @@ -1,5 +1,5 @@ Menu="UNRAID-OS" -Title="System Modules/Drivers" +Title="System Drivers" Icon="fa-sitemap" Tag="server" --- @@ -46,76 +46,13 @@ table.t1 tr>td+td+td+td+td+td+td+td+td+td+td+td+td{text-align:left;} - if (typeof " ".formatUnicorn !== "function") - { - String.prototype.formatUnicorn = String.prototype.formatUnicorn || - function () { - "use strict"; - var str = this.toString(); - if (arguments.length) { - var t = typeof arguments[0]; - var key; - var args = ("string" === t || "number" === t) ? - Array.prototype.slice.call(arguments) - : arguments[0]; - - for (key in args) { - str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]); - } - } - - return str; - }; - } - - (function ($) { - $.fn.getHiddenDimensions = function (includeMargin) - { - var $item = this, - props = { position: 'absolute', visibility: 'hidden', display: 'block' }, - dim = { width: 0, height: 0, innerWidth: 0, innerHeight: 0, outerWidth: 0, outerHeight: 0 }, - $hiddenParents = $item.parents().andSelf().not(':visible'), - includeMargin = (includeMargin == null) ? false : includeMargin; - - var oldProps = []; - $hiddenParents.each(function () - { - var old = {}; - - for (var name in props) - { - old[name] = this.style[name]; - this.style[name] = props[name]; - } - - oldProps.push(old); - }); - - dim.width = $item.width(); - dim.outerWidth = $item.outerWidth(includeMargin); - dim.innerWidth = $item.innerWidth(); - dim.height = $item.height(); - dim.innerHeight = $item.innerHeight(); - dim.outerHeight = $item.outerHeight(includeMargin); - - $hiddenParents.each(function (i) - { - var old = oldProps[i]; - for (var name in props) - { - this.style[name] = old[name]; - } - }); - - return dim; - } - }(jQuery)); - $(function(){ - $('#t1').load('/webGui/include/SysDrivers.php',{table:'t1',option:"inuse"}); + $('#t1').load('/webGui/include/SysDrivers.php',{table:'t1',option:"inuse"}).tablesorter(); }); + + function showDrivers(options) { option = options ; timers.refresh = setTimeout(function(){$('div.spinner.fixed').show('slow');},500); @@ -141,18 +78,21 @@ function textsave(module) { $('#save'+module).attr('hidden', true); var x = document.getElementById("text" + module).value; $.post('/webGui/include/SysDrivers.php',{table:'update',module:module,conf:x},function(data){ - formHasUnsavedChanges=false; - select = document.getElementById("select").value; - showDrivers(select) ; + if(data) { + formHasUnsavedChanges=false; + $('#text'+module).val(data.modprobe) ; + $('#status'+module).html(data.state) ; + if (data.modprobe == "") $('#text'+module).attr('hidden', true); else $('#text'+module).attr('rows', 3) + } var message = "_(System Drivers)_: _(A reboot is required to apply changes)_"; addRebootNotice(message); - }); + },"json"); } $('.tabs').append("_(Select View)_:"); -

+

diff --git a/emhttp/plugins/dynamix/include/SysDrivers.php b/emhttp/plugins/dynamix/include/SysDrivers.php index 135e43a61..ee72ebf70 100644 --- a/emhttp/plugins/dynamix/include/SysDrivers.php +++ b/emhttp/plugins/dynamix/include/SysDrivers.php @@ -17,8 +17,12 @@ $_SERVER['REQUEST_URI'] = 'tools'; require_once "$docroot/webGui/include/Translations.php"; require_once "$docroot/webGui/include/Helpers.php"; -function getmodules($kernel,$line) { - global $arrModules,$lsmod ; +$kernel = shell_exec("uname -r") ; +$kernel = trim($kernel,"\n") ; +$lsmod = shell_exec("lsmod") ; + +function getmodules($line) { + global $arrModules,$lsmod,$kernel ; $modprobe = "" ; $name = $line ; #echo $line ; @@ -64,9 +68,10 @@ function getmodules($kernel,$line) { } if (strpos($lsmod, $modname,0)) $state = "Inuse" ; else $state = "Available"; if (is_file("/boot/config/modprobe.d/$modname.conf")) { - $modprobe = explode(PHP_EOL,file_get_contents("/boot/config/modprobe.d/$modname.conf")) ; - $state = array_search("blacklist",$modprobe); - if($state) {$state = "Disabled" ;} + $modprobe = file_get_contents("/boot/config/modprobe.d/$modname.conf") ; + $state = strpos($modprobe, "blacklist"); + $modprobe = explode(PHP_EOL,$modprobe) ; + if($state !== false) {$state = "Disabled" ;} else $state="Custom" ; } else if($option == "conf") return ; @@ -96,30 +101,26 @@ switch ($_POST['table']) { case 't1': $option = $_POST['option'] ; $select = $_POST['select'] ; - #$procmodules = file_get_contents("/proc/modules") ; - $lsmod = shell_exec("lsmod") ; - $kernel = shell_exec("uname -r") ; - $kernel = trim($kernel,"\n") ; - #$procmodules = shell_exec('find /lib/modules/$(uname -r) -type f -not -path "/lib/modules/$(uname -r)/source/*" -not -path "/lib/modules/$(uname -r)/build/*" -name "*ko*" ') ; - $procmodules = shell_exec('find /lib/modules/$(uname -r)/kernel/drivers/ -type f -not -path "/lib/modules/$(uname -r)/source/*" -not -path "/lib/modules/$(uname -r)/build/*" -name "*ko*" ') ; - $procmodules = explode(PHP_EOL,$procmodules) ; $builtinmodules = file_get_contents("/lib/modules/$kernel/modules.builtin") ; $builtinmodules = explode(PHP_EOL,$builtinmodules) ; + $procmodules =file_get_contents("/lib/modules/$kernel/modules.order") ; + $procmodules = explode(PHP_EOL,$procmodules) ; $option = $_POST['option'] ; $arrModules = array() ; foreach($builtinmodules as $bultin) { if ($bultin == "") continue ; - getmodules($kernel,pathinfo($bultin)["filename"]) ; + getmodules(pathinfo($bultin)["filename"]) ; } foreach($procmodules as $line) { if ($line == "") continue ; - getmodules($kernel,$line) ; + getmodules(pathinfo($line)["filename"]) ; } - echo ""._("Module/Driver").""._("Description").""._("State").""._("Type").""._("Modeprobe.d config file").""; + echo ""._("Module/Driver").""._("Description").""._("State").""._("Type").""._("Modeprobe.d config file").""; + # echo "Total Number of drivers the system:".count($arrModules)."" ; echo "" ; if (is_array($arrModules)) ksort($arrModules) ; foreach($arrModules as $modname => $module) @@ -139,7 +140,7 @@ foreach($procmodules as $line) { } #echo "
$modname"; + echo ""; $text = "" ; if (is_array($module["modprobe"])) { $text = implode("\n",$module["modprobe"]) ; @@ -155,6 +156,10 @@ case "update": $module = $_POST['module'] ; if ($conf == "") $error = unlink("/boot/config/modprobe.d/$module.conf") ; else $error = file_put_contents("/boot/config/modprobe.d/$module.conf",$conf) ; - echo $error ; + getmodules($module) ; + $return = $arrModules[$module] ; + if (is_array($return["modprobe"]))$return["modprobe"] = implode("\n",$return["modprobe"]) ; + if ($error !== false) $return["error"] = false ; else $return["error"] = true ; + echo json_encode($return) ; } ?>
{$module['description']}{$module['state']}{$module['type']}
$modname{$module['description']}{$module['state']}{$module['type']}