$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// add translations
$_SERVER['REQUEST_URI'] = 'tools';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
$kernel = shell_exec("uname -r") ;
$kernel = trim($kernel,"\n") ;
$lsmod = shell_exec("lsmod") ;
$supportpage = true;
function getplugin($in) {
$plugins = "/var/log/plugins/";
$plugin_link = $plugins.$in ;
$plugin_file = @readlink($plugin_link);
$support = plugin('support',$plugin_file) ?: "";
#$support = $support ? ""._('Support Thread')."" : "";
return($support) ;
}
function getmodules($line) {
global $arrModules,$lsmod,$kernel ;
$modprobe = "" ;
$name = $line ;
#echo $line ;
$modname = trim(shell_exec("modinfo $name > /dev/null"),"\n") ;
$output=null ;
exec("modinfo $name",$output,$error) ;
$parms = array() ;
foreach($output as $outline) {
$data = explode(":",$outline) ;
$support = false ; $supporturl = null ;
switch ($data[0])
{
case "name":
$modname = trim($data[1]) ;
break ;
case "depends":
$depends = trim($data[1]) ;
break ;
case "filename":
$filename = trim($data[1]) ;
break ;
case "description":
$desc = trim($data[1]) ;
break ;
case "parm":
$parms[] = trim(str_replace("parm:","",$outline)) ;
break ;
case "file":
$file = trim(str_replace("file:","",$outline)) ;
break ;
case "alias":
case "author":
case "firmware":
case "intree":
case "vermagic":
case "retpoline":
case "import_ns":
case "license":
break ;
default:
$parms[] = trim($outline) ;
break ;
}
}
if (strpos($lsmod, $modname,0)) $state = "Inuse" ; else $state = "Available";
if (is_file("/boot/config/modprobe.d/$modname.conf")) {
$modprobe = file_get_contents("/boot/config/modprobe.d/$modname.conf") ;
$state = strpos($modprobe, "blacklist");
$supportpos = strpos($modprobe, "#Plugin:");
if ($supportpos !== false) {
$support = true ;
$supportendpos = strpos($modprobe,"\n",$supportpos) ;
$pluginfileget = substr($modprobe,$supportpos + 8,$supportendpos ) ;
$pluginfile = str_replace("\n","",$pluginfileget) ;
$supporturl = getplugin($pluginfile) ;
#$modprobe = str_replace($pluginfileget,"",$modprobe) ;
} else {
$support = false ;
$plugin = "" ;
}
$modprobe = explode(PHP_EOL,$modprobe) ;
if($state !== false) {$state = "Disabled" ;}
else $state="Custom" ;
} else if($option == "conf") return ;
if ($filename != "(builtin)") {
$type = pathinfo($filename) ;
$dir = $type['dirname'] ;
$dir = str_replace("/lib/modules/$kernel/kernel/drivers/", "" ,$dir) ;
$dir = str_replace("/lib/modules/$kernel/kernel/", "" ,$dir) ;
} else {
$dir = $file ;
$dir = str_replace("drivers/", "" ,$dir) ;
if ($state == "Inuse") $state= "(builtin) - Inuse"; else $state="(builtin)" ;
}
$arrModules[$modname] = [
'modname' => $modname,
'dependacy' => $depends,
'parms' => $parms,
'file' => $file,
'modprobe' => $modprobe,
'plugin' => $pluginfile ,
'state' => $state,
'type' => $dir,
'support' => $support,
'supporturl' => $supporturl,
'description' => substr($desc , 0 ,60) ,
] ;
}
switch ($_POST['table']) {
case 't1pre':
$option = $_POST['option'] ;
$select = $_POST['select'] ;
$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) ;
$arrModules = array() ;
foreach($builtinmodules as $bultin)
{
if ($bultin == "") continue ;
getmodules(pathinfo($bultin)["filename"]) ;
}
foreach($procmodules as $line) {
if ($line == "") continue ;
getmodules(pathinfo($line)["filename"]) ;
}
echo " ";
echo ""._("Module/Driver")." "._("Description")." "._("State")." "._("Type")." "._("Modeprobe.d config file")."
| " ; if ($module['support'] == false) { $supporthtml = "title='"._("Support Page")."' id=\"support'.$modname.'\" class='fa fa-circle' disabled " ; } else { $supporturl = $module['supporturl'] ; $supporthtml = ""._('Support Thread').""; } echo "$supporthtml $modname | " ; echo "$status | $status | " ; echo "$status | "; $text = "" ; if (is_array($module["modprobe"])) { $text = implode("\n",$module["modprobe"]) ; echo ""; } else echo " | "; } echo "" ; break; case 't1': $option = $_POST['option'] ; $select = $_POST['select'] ; $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) ; $arrModules = array() ; foreach($builtinmodules as $bultin) { if ($bultin == "") continue ; getmodules(pathinfo($bultin)["filename"]) ; } foreach($procmodules as $line) { if ($line == "") continue ; getmodules(pathinfo($line)["filename"]) ; } echo " |
| "._("Actions")." | "._("Module/Driver")." | "._("Description")." | "._("State")." | "._("Type")." | "._("Modeprobe.d config file")." |
|---|---|---|---|---|---|
| " ; if ($supportpage) { if ($module['support'] == false) { $supporthtml = "" ; } else { $supporturl = $module['supporturl'] ; $supporthtml = "" ; } } echo "$supporthtml | $modname | " ; echo "{$module['description']} | {$module['state']} | {$module['type']} | "; $text = "" ; if (is_array($module["modprobe"])) { $text = implode("\n",$module["modprobe"]) ; echo ""; } echo "" ; break; case "update": $conf = $_POST['conf'] ; $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) ; getmodules($module) ; $return = $arrModules[$module] ; $return['supportpage'] = $supportpage ; 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) ; } ?> |