Esempio n. 1
0
function validateInputs($Z)
{
    #function validateInputs is meant to be a general validation function that is based on rules for validation
    #The rules come in the format of triples
    #$validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db'))
    $messages = $GLOBALS['messages'];
    $error_codes = $GLOBALS['error_codes'];
    #echo '<pre>';print_r($messages);
    if (!$model) {
        $model = 'nsy';
    }
    extract($Z);
    if (ereg('edit|update', $action)) {
        $action = 'edit';
        if (empty($inputs)) {
            $inputs = $info;
        }
    } else {
        $action = 'create';
    }
    $code = $GLOBALS['s3codesInv'][$element];
    #echo '<pre>';print_r($inputs);
    switch ($code) {
        case 'U':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Login cannot be empty</message>' => !empty($inputs['account_lid']), '<error>' . $error_codes['wrong_input'] . '</error><message>Account type must be a,u,g or p</message>' => ereg('^(a|u|g|p|r)$', $inputs['account_type']), '<error>' . $error_codes['something_missing'] . '</error><message>Account status cannot be empty</message>' => !empty($inputs['account_status']), '<error>' . $error_codes['something_missing'] . '</error><message>username cannot be empty</message>' => !empty($inputs['account_uname']), '<error>' . $error_codes['something_missing'] . '</error><message>email cannot be empty</message>' => !empty($inputs['account_email']), '<error>' . $error_codes['something_missing'] . '</error><message>password cannot be empty</message>' => !empty($inputs['account_pwd']), '<error>' . $error_codes['repeating_action'] . '</error><message>User ' . $inputs['account_lid'] . ' already exists</message>' => !user_already_exist($info['user_id'], $inputs, $db), '<error>' . $error_codes['repeating_action'] . '</error><message>Email ' . $inputs['account_email'] . ' already exists</message>' => !email_already_exist($Z) || $inputs['account_email'] == '*****@*****.**' || $action == 'edit' && $info['account_email'] == $inputs['account_email'], '<error>' . $error_codes['wrong_input'] . '</error><message>Permission level ' . $inputs['permission_level'] . ' is invalid</message>' => $inputs['permission_level'] == "" || eregi('[' . $model . ']+', $inputs['permission_level']), '<error>' . $error_codes['no_permission_message'] . '</error><message>User is not allowed to update permission on user' . $info['user_id'] . '</message>' => $info['created_by'] == $user_id || $info['account_id'] == $user_id || $user_id == 1);
            break;
        case 'G':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Group name cannot be empty</message>' => !empty($inputs['account_lid']), '<error>' . $error_codes['repeating_action'] . '</error><message>Group ' . $inputs['account_lid'] . ' already exists</message>' => !user_already_exist($info['group_id'], $inputs, $db));
            break;
        case 'P':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Project Name cannot be empty</message>' => !empty($inputs['project_name']));
            break;
        case 'C':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Name Cannot Be Empty' . $messages['syntax_message'] . '</message>' => !empty($inputs['entity']), '<error>' . $error_codes['repeating_action'] . '</error><message>Collection Already Exists in Project</message>' => !is_resource_exists($inputs, $db), '<error>' . $error_codes['nothing_to_change'] . '</error><message>Nothing Was Changed</message>' => !nothing_changed($inputs, $oldvalues));
            break;
        case 'I':
            $ruleValid[$element] = array('<error>' . $error_codes['nothing_to_change'] . '</error><message>Nothing Was Changed</message>' => !nothing_changed($inputs, $oldvalues), '<error>' . $error_codes['something_missing'] . '</error><message>Class_id Cannot Be Empty</message>' => $action != 'create' || !empty($inputs['resource_class_id']));
            break;
        case 'R':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Subject Cannot Be Empty</message>' => !empty($inputs['subject']) || !empty($inputs['subject_id']), '<error>' . $error_codes['something_missing'] . '</error><message>Class_id was not found for this Subject</message>' => !empty($inputs['subject_id']), '<error>' . $error_codes['something_missing'] . '</error><message>Verb Cannot Be Empty</message>' => !empty($inputs['verb']) || !empty($inputs['verb_id']), '<error>' . $error_codes['something_missing'] . '</error><message>Object Cannot Be Empty</message>' => !empty($inputs['object']) || !empty($inputs['object_id']), '<error>' . $error_codes['repeating_action'] . '</error><message>Rule Already Exists</message>' => !rule_exists(compact('info', 'db')), '<error>' . $error_codes['nothing_to_change'] . '</error><message>Nothing Was Changed</message>' => !nothing_changed($inputs, $oldvalues), '<error>' . $error_codes['wrong_input'] . '</error><message>Subject_id Must Exist as a Class Before Creating this Rule</message>' => subject_in_project($inputs['subject_id'], $inputs['project_id'], $db) && $info['object'] != 'UID', '<error>' . $error_codes['repeating_action'] . '</error><message>Request Is Already Pending For This Rule</message>' => !($info['project_id'] != $inputs['project_id'] && request_already_pending($info, $db)));
            break;
        case 'S':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Value Cannot Be Empty</message>' => $inputs['value'] != "", '<error>' . $error_codes['something_missing'] . '</error><message>Instance_id Cannot Be Empty</message>' => !(empty($inputs['instance_id']) && empty($inputs['resource_id'])), '<error>' . $error_codes['something_missing'] . '</error><message>Rule_id Cannot Be Empty</message>' => !empty($inputs['rule_id']), '<error>' . $error_codes['wrong_input'] . '</error><message>Value Must Be a Valid Instance_id of Object of Rule</message>' => objectResourcANDvalueInstance(array('rule_id' => $inputs['rule_id'], 'value' => $inputs['value'], 'user_id' => $user_id, 'key' => $key, 'db' => $db)), '<error>' . $error_codes['not_valid'] . '</error><message>This Rule Requires the Format: ' . getRuleValidation($inputs['rule_id'], $key, $user_id, $db) . '</message>' => validate_statement_value($inputs['rule_id'], $inputs['value'], $db), '<error>' . $error_codes['nothing_to_change'] . '</error><message>Nothing Was Changed</message>' => !nothing_changed($inputs, $oldvalues));
            break;
        case 'F':
            $ruleValid[$element] = array('<error>' . $error_codes['something_missing'] . '</error><message>Filekey cannot be empty</message>' => !empty($inputs['filekey']), '<error>' . $error_codes['something_missing'] . '</error><message>Instance_id Cannot Be Empty</message>' => !(empty($inputs['instance_id']) && empty($inputs['resource_id'])), '<error>' . $error_codes['something_missing'] . '</error><message>Rule_id Cannot Be Empty</message>' => !empty($inputs['rule_id']), '<error>' . $error_codes['something_missing'] . '</error><message>File was not found</message>' => fileFound(array('filekey' => $inputs['filekey'], 'db' => $db, 'user_id' => $user_id, 'rule_id' => $inputs['rule_id'])), '<error>' . $error_codes['nothing_to_change'] . '</error><message>Nothing Was Changed</message>' => !nothing_changed($inputs, $oldvalues));
            break;
    }
    #echo '<pre>ruleValid';print_r($ruleValid);exit;
    if (!min($ruleValid[$element])) {
        ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', array_search('0', $ruleValid[$element]), $s3qlout);
        $error_code = $s3qlout[1];
        $message = $s3qlout[3];
        return array(false, 'error_code' => $error_code, 'message' => $message);
        #return $message= array(false, $error_code, $message);
    } else {
        #$id_name =$GLOBALS['s3ids'][$element];
        #$id_name.' '.$info[$id_name].' ';
        $error_code = '0';
        $message = "Validation Successfull";
        return array(true, 'error_code' => $error_code, 'message' => $message);
    }
}
Esempio n. 2
0
function rule_create($chain, $source, $target) {
  if (! rule_exists($chain, $source, $target)) {
    //    ipt_insert_rule($chain, $source, $target);
    ipt_do_command(sprintf('-I %s -s %s -j %s', $chain, $source, $target));
  }
}