function deleteModule($moddir)
{
    $deldir = getRelModPath() . "/" . $moddir;
    # XXX standardize and refactor all the error handling in this module
    if (preg_match("/[^\\w\\-\\.]/", $moddir)) {
        log_error("deleteModule: Invalid Module Name");
        header("HTTP/1.1 500 Internal Server Error");
        header("Content-Type: application/json");
        echo "{ \"error\" : \"deleteModule: Invalid Module Name\", \"moddir\" : \"{$moddir}\" }\n";
        exit;
    }
    # brutally dangerous? how to improve?
    exec("rm -rf '{$deldir}' 2>&1", $output, $rval);
    if ($rval == 0) {
        # restart kiwix so it sees what modules are visible/hidden
        kiwix_restart();
        header("HTTP/1.1 200 OK");
        header("Content-Type: application/json");
        echo "{ \"moddir\" : \"{$moddir}\" }\n";
    } else {
        $output = implode(", ", $output);
        header("HTTP/1.1 500 Internal Server Error");
        header("Content-Type: application/json");
        echo "{ \"error\" : \"{$output}\", \"moddir\" : \"{$moddir}\" }\n";
    }
    exit;
}
Example #2
0
function getRelAdminPath()
{
    return preg_replace("/modules/", "admin", getRelModPath());
}