$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/SysDriversHelpers.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
// add translations
$_SERVER['REQUEST_URI'] = 'tools';
require_once "$docroot/webGui/include/Translations.php";
$kernel = shell_exec("uname -r");
$kernel = trim($kernel,"\n");
$lsmod = shell_exec("lsmod");
$supportpage = true;
$modtoplgfile = "/tmp/modulestoplg.json";
$sysdrvfile = "/tmp/sysdrivers.json";
$sysdrvinit = "/tmp/sysdrivers.init";
if (!is_file($modtoplgfile) || !is_file($sysdrvfile)) { modtoplg(); createlist();}
$arrModtoPlg = json_decode(file_get_contents("/tmp/modulestoplg.json") ,TRUE);
switch ($_POST['table']) {
case 't1create':
if (is_file("/tmp/sysdrvbuild.running")) break;
touch("/tmp/sysdrvbuild.running");
modtoplg();
createlist();
unlink("/tmp/sysdrvbuild.running");
break;
case 't1load':
$list = file_get_contents($sysdrvfile);
$arrModules = json_decode($list,TRUE);
$init = false;
if (is_file($sysdrvinit)) $init = file_get_contents($sysdrvinit);
$html = "| "._('Driver')." | "._('Description')." | "._('State')." | "._('Type')." | "._('Modprobe.d config file')." |
";
$html .= "
";
ksort($arrModules);
foreach($arrModules as $modname => $module) {
if ($modname == "") continue;
if (is_file("/boot/config/modprobe.d/$modname.conf")) {
$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";
$module['state'] = $state;
$module['modprobe'] = $modprobe;
} else {
if (is_file("/etc/modprobe.d/$modname.conf")) {
$modprobe = file_get_contents("/etc/modprobe.d/$modname.conf");
$state = strpos($modprobe, "blacklist");
$modprobe = explode(PHP_EOL,$modprobe);
if($state !== false) {$state = "Disabled";} else $state="System";
$module['state'] = $state;
$module['modprobe'] = $modprobe;
}
}
$html .= "";
if ($supportpage) {
if ($module['support'] == false) {
$supporthtml = "";
} else {
$supporturl = $module['supporturl'];
$pluginname = $module['plugin'];
$supporthtml = "";
}
}
if (!empty($module["version"])) $version = " (".$module["version"].")"; else $version = "";
$html .= "| $modname$version$supporthtml | ";
$html .= "{$module['description']} | {$module['state']} | {$module['type']} | ";
$text = "";
if (is_array($module["modprobe"]) && count($module["modprobe"])) {
$text = implode("\n",$module["modprobe"]);
$hidden = ($module['state'] == "System") ? "hidden" : "";
$html .= "";
$html .= "";
$html .= "";
$html .= "";
$html .= " |
";
} else {
$html .= "";
$html .= "";
$html .= "";
$html .= "";
$html .= " | ";
}
}
$html .= "";
$rtn = array();
$rtn['html'] = $html;
if ($init !== false) {$init = true; unlink($sysdrvinit);}
$rtn['init'] = $init;
echo json_encode($rtn);
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);
break;
}
?>