}
#
# TID
#
if (!isset($formfields["tid"]) || $formfields["tid"] == "") {
    $errors["Template ID"] = "Missing Field";
} elseif (!TBvalid_eid($formfields["tid"])) {
    $errors["Template ID"] = TBFieldErrorString();
}
#
# Description:
#
if (!isset($formfields["description"]) || $formfields["description"] == "") {
    $errors["Description"] = "Missing Field";
} elseif (!TBvalid_template_description($formfields["description"])) {
    $errors["Description"] = TBFieldErrorString();
}
#
# The NS file. There is a bunch of stuff here for Netbuild.
#
$formfields["nsfile"] = "";
if (isset($formfields["guid"])) {
    if ($formfields["guid"] == "" || !preg_match("/^\\d+\$/", $formfields["guid"])) {
        $errors["NS File GUID"] = "Invalid characters";
    }
    $nsfilelocale = "nsref";
} elseif (isset($formfields["nsref"])) {
    if ($formfields["nsref"] == "" || !preg_match("/^\\d+\$/", $formfields["nsref"])) {
        $errors["NS File Reference"] = "Invalid characters";
    }
    $nsfilelocale = "nsref";
Example #2
0
    PAGEFOOTER();
    return;
}
#
# If not clicked, then put up a form.
#
if (!isset($submit)) {
    SPITFORM($target_user, "", null);
    return;
}
# Sanity checks
$error = null;
if (!isset($new_uid) || $new_uid == "") {
    $error = "UID: Must supply a new UID";
} elseif (!TBvalid_uid($new_uid)) {
    $error = "UID: " . TBFieldErrorString();
} elseif (User::Lookup($new_uid) || posix_getpwnam($new_uid)) {
    $error = "UID: Already in use. Pick another";
}
if ($error) {
    SPITFORM($target_user, $new_uid, $error);
    return;
}
#
# Standard Testbed Header.
#
PAGEHEADER("Change login UID for user");
# Okay, call out to backend to change.
STARTBUSY("Changing UID");
#
# Run the backend script.
function CheckValue($name, &$errors, $attributes, $value)
{
    $which = $attributes['#which'];
    # Allow a null value. User wants to compare against ""
    if (!isset($value) || $value == "") {
        return;
    }
    #
    # The value has to be plain text, but thats about it. We will escape
    # it before passing off to mysql in a query.
    #
    if (!TBvalid_userdata($value)) {
        $errors["Value {$which}"] = TBFieldErrorString();
    }
}
Example #4
0
        $errors["Not Swappable"] = TBFieldErrorString();
    }
} else {
    $formfields["exp_swappable"] = 1;
    $formfields["exp_noswap_reason"] = "";
}
if (!isset($formfields["exp_idleswap"]) || strcmp($formfields["exp_idleswap"], "1")) {
    $formfields["exp_idleswap"] = 0;
    if (!isset($formfields["exp_noidleswap_reason"]) || !strcmp($formfields["exp_noidleswap_reason"], "")) {
        if (!ISADMIN()) {
            $errors["Not Idle-Swappable"] = "No justification provided";
        } else {
            $formfields["exp_noidleswap_reason"] = "ADMIN";
        }
    } elseif (!TBvalid_description($formfields["exp_noidleswap_reason"])) {
        $errors["Not Idle-Swappable"] = TBFieldErrorString();
    }
} else {
    $formfields["exp_idleswap"] = 1;
    $formfields["exp_noidleswap_reason"] = "";
}
# Proper idleswap timeout must be provided.
if (!isset($formfields["exp_idleswap_timeout"]) || !preg_match("/^[\\d]+\$/", $formfields["exp_idleswap_timeout"]) || $formfields["exp_idleswap_timeout"] + 0 <= 0 || $formfields["exp_idleswap_timeout"] + 0 > $idleswaptimeout) {
    $errors["Idleswap"] = "Invalid time provided - " . "must be non-zero and less than {$idleswaptimeout}";
}
if (!isset($formfields["exp_autoswap"]) || strcmp($formfields["exp_autoswap"], "1")) {
    if (!ISADMIN()) {
        $errors["Max. Duration"] = "You must ask testbed operations to disable this";
    }
    $formfields["exp_autoswap"] = 0;
} else {
Example #5
0
function FormValidateElement($name, &$errors, $attributes, &$submitted, $parent_label)
{
    $error_label = CombineLabels($parent_label, $attributes);
    # Check for required fields not filled out
    if (isset($attributes['#prep']) && isset($submitted[$name]) && $submitted[$name] != "") {
        $submitted[$name] = $attributes['#prep']($submitted[$name]);
    }
    if (isset($attributes['#required']) && $attributes['#required'] && !(isset($submitted[$name]) && $submitted[$name] != "")) {
        $errors[$error_label] = "Missing required value";
    } elseif (isset($attributes['#checkslot']) && isset($submitted[$name]) && $submitted[$name] != "") {
        $check = $attributes['#checkslot'];
        if (function_exists($check)) {
            $check($name, $errors, $attributes, $submitted[$name]);
        } elseif (preg_match("/^([-\\w]+):([-\\w]+)\$/", $check, $matches)) {
            #
            # What if not required and not set?
            #
            if (!isset($submitted[$name]) || $submitted[$name] == "") {
                $submitted[$name] = "";
            }
            if (!TBcheck_dbslot($submitted[$name], $matches[1], $matches[2], TBDB_CHECKDBSLOT_WARN | TBDB_CHECKDBSLOT_ERROR)) {
                $errors[$error_label] = TBFieldErrorString();
            }
        } elseif (substr($check, 0, 1) == "/") {
            # Regular expression.
            if (!preg_match($check, $submitted[$name])) {
                $errors[$error_label] = "Illegal characters";
            }
        } else {
            TBERROR("Could not parse checkslot: {$check}", 1);
        }
    }
}
        if (!TBvalid_float($newtime)) {
            $errors["{$vname} time"] = TBFieldErrorString();
        } elseif ($newtime < 0) {
            $errors["{$vname} time"] = "Cannot be less then zero";
        } else {
            if (!isset($changes[$vname])) {
                $changes[$vname] = array();
            }
            $changes[$vname]["time"] = $newtime;
        }
    }
    # Modify the arguments
    if (isset($formfields[$args_name]) && $formfields[$args_name] != "{$args}") {
        $newargs = $formfields[$args_name];
        if (!TBcheck_dbslot($newargs, 'eventlist', 'arguments', TBDB_CHECKDBSLOT_WARN | TBDB_CHECKDBSLOT_ERROR)) {
            $errors["{$vname} time"] = TBFieldErrorString();
        } else {
            if (!isset($changes[$vname])) {
                $changes[$vname] = array();
            }
            $changes[$vname]["arguments"] = $newargs;
        }
    }
}
if (count($errors)) {
    SPITFORM($template, $formfields, $errors);
    PAGEFOOTER();
    exit(1);
}
#
# Do the deletes and changes.
function CLEANUP()
{
    global $tmpfname;
    if ($tmpfname != NULL) {
        unlink($tmpfname);
    }
    exit;
}
register_shutdown_function("CLEANUP");
#
# Otherwise, must validate and redisplay if errors
#
$errors = array();
if (isset($formfields["message"]) && $formfields["message"] != "") {
    if (!TBvalid_archive_message($formfields["message"])) {
        $errors["Message"] = TBFieldErrorString();
    } else {
        #
        # Easier to stick the entire message into a temporary file and
        # send that through.
        #
        $tmpfname = tempnam("/tmp", "archive_tag");
        $fp = fopen($tmpfname, "w");
        fwrite($fp, $formfields["message"]);
        fclose($fp);
        chmod($tmpfname, 0666);
        $message = "-m {$tmpfname}";
    }
} else {
    $errors["Message"] = "Please provide a minimal message!";
}