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
    if (EXTRA_LOGGING) {
        error_Log("all done.");
    }
    # check for the next task
    $next = $db->querySingle("\n        SELECT task_id, moddir, command\n          FROM tasks\n         WHERE pid IS NULL\n           AND dismissed IS NULL\n         ORDER BY task_id LIMIT 1\n    ", true);
    $db_started = $db->escapeString(time());
    if ($next) {
        if (EXTRA_LOGGING) {
            error_Log("New task found, rsyncing {$next['moddir']}...");
        }
        $db_task_id = $next['task_id'];
        $cmd = $next['command'];
        $moddir = $next['moddir'];
        $db->exec("\n            UPDATE tasks\n               SET started = '{$db_started}',\n                   files_done = '0',\n                   data_done = '0',\n                   data_rate = ''\n             WHERE task_id = '{$db_task_id}'\n        ");
    } else {
        if (EXTRA_LOGGING) {
            error_Log("No more tasks, exiting...");
        }
        # no more tasks -- yay
        break;
    }
}
# restart kiwix so it sees what modules are visible/hidden
# -- we could do this after each module but it seems a bit
# much... let's try doing it after installs/updates are complete
# and see if anyone complains
kiwix_restart();
if (EXTRA_LOGGING) {
    error_Log("Goodbye.");
}
exit(0);
Example #3
0
function updatemods()
{
    # if we don't turn off visible errors, even caught db
    # exceptions will print to the browser (as a "200 OK"),
    # breaking our ability to signal failure
    ini_set('display_errors', '0');
    $position = 1;
    try {
        $db = getdb();
        if (!$db) {
            throw new Exception($db->lastErrorMsg);
        }
        # figure out which modules to hide
        $hidden = array();
        if (isset($_GET['hidden'])) {
            foreach (explode(",", $_GET['hidden']) as $moddir) {
                $hidden[$moddir] = 1;
            }
        }
        $db->exec("BEGIN");
        # go to the DB and set the new order and new hidden state
        foreach (explode(",", $_GET['moddirs']) as $moddir) {
            $moddir = $db->escapeString($moddir);
            if (isset($hidden[$moddir])) {
                $is_hidden = 1;
            } else {
                $is_hidden = 0;
            }
            $rv = $db->exec("UPDATE modules SET position = '{$position}', hidden = '{$is_hidden}'" . " WHERE moddir = '{$moddir}'");
            if (!$rv) {
                throw new Exception($db->lastErrorMsg());
            }
            ++$position;
        }
    } catch (Exception $ex) {
        $db->exec("ROLLBACK");
        error_log($ex);
        header("HTTP/1.1 500 Internal Server Error");
        exit;
    }
    $db->exec("COMMIT");
    # restart kiwix so it sees what modules are visible/hidden
    kiwix_restart();
    header("HTTP/1.1 200 OK");
}