Exemplo n.º 1
0
    if (strlen($_POST['name']) == 0) {
        $error[] = "Invalid agent name";
    }
}
# die if errors
if (sizeof($error) > 0) {
    $Result->show("danger", $error, true);
} else {
    # create array of values for modification
    $values = array("id" => @$_POST['id'], "name" => $_POST['name'], "description" => @$_POST['description'], "code" => @$_POST['code'], "type" => @$_POST['type']);
    # null
    $values = $Admin->remove_empty_array_fields($values);
    # execute
    if (!$Admin->object_modify("scanAgents", $_POST['action'], "id", $values)) {
        $Result->show("danger", _("Agent {$_POST['action']} error"), true);
    } else {
        $Result->show("success", _("Agent {$_POST['action']} success"), false);
    }
    # delete - unset scanning in all subnets
    if ($_POST['action'] == "delete") {
        $query = "update `subnets` set `scanAgent`=0, `pingSubnet`=0, `discoverSubnet`=0 where `scanAgent` = ?;";
        try {
            $Database->runQuery($query, array($_POST['id']));
        } catch (Exception $e) {
            $this->Result->show("danger", _("Error: ") . $e->getMessage());
            return false;
        }
        // references removed
        $this->Result->show("info", _("Scan agent references removed"));
    }
}
Exemplo n.º 2
0
$_POST['csrf_cookie'] == $_SESSION['csrf_cookie'] ?: $Result->show("danger", _("Invalid CSRF cookie"), true);
# get action
$action = $_POST['action'];
//for adding remove id
if ($action == "add") {
    unset($_POST['id']);
} else {
    //check id
    if (!is_numeric($_POST['id'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
}
# set update query
$values = array("id" => @$_POST['id'], "type" => $_POST['type'], "description" => @$_POST['description']);
# add params
unset($_POST['id'], $_POST['type'], $_POST['description'], $_POST['action']);
$values["params"] = json_encode($_POST);
# add - set protected
if ($action == "add") {
    $values['protected'] = "No";
}
# update
if (!$Admin->object_modify("usersAuthMethod", $action, "id", $values)) {
    $Result->show("danger", _("Failed to edit authentication method"), false);
} else {
    $Result->show("success", _("Authentication method updated"), false);
}
# if delete also reset all users that have thos auth method
if ($action == "delete") {
    $Database->runQuery("update `users` set `authMethod`=1 where `authMethod`= ?;", array($values['id']));
}