Sigle Line Update for Modprobe

This commit is contained in:
SimonFair
2023-07-08 09:02:46 +01:00
parent d8e0d82152
commit aaebd5e237
2 changed files with 34 additions and 89 deletions
+22 -17
View File
@@ -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 "<thead><tr><td><b>"._("Module/Driver")."</td><td><b>"._("Description")."</td><td><b>"._("State")."</td><td><b>"._("Type")."</td><td><b>"._("Modeprobe.d config file")."</td></tr></thead>";
echo "<thead><tr><th><b>"._("Module/Driver")."</th><th><b>"._("Description")."</th><th><b>"._("State")."</hd><th><b>"._("Type")."</th><th><b>"._("Modeprobe.d config file")."</th></tr></thead>";
# echo "<tr><td>Total Number of drivers the system:".count($arrModules)."</td></tr>" ;
echo "<tbody>" ;
if (is_array($arrModules)) ksort($arrModules) ;
foreach($arrModules as $modname => $module)
@@ -139,7 +140,7 @@ foreach($procmodules as $line) {
}
#echo "<div class='show-disks'><table class='disk_status >" ;
echo "<tr><td><span onclick=\"textedit('".$modname."')\" ><a><i title='"._("Edit Modprobe config")."' id=\"icon'.$modname.'\" class='fa fa-edit' ></i></a></span> $modname</td><td>{$module['description']}</td><td>{$module['state']}</td><td>{$module['type']}</td>";
echo "<tr><td><span onclick=\"textedit('".$modname."')\" ><a><i title='"._("Edit Modprobe config")."' id=\"icon'.$modname.'\" class='fa fa-edit' ></i></a></span> $modname</td><td>{$module['description']}</td><td id=\"status$modname\">{$module['state']}</td><td>{$module['type']}</td>";
$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) ;
}
?>