예제 #1
0
function add_library_hf($options)
{
    global $u;
    global $library_messages;
    global $APP;
    if (!isset($options['id_user'])) {
        echo "library add id_user not found!";
        exit;
    }
    if (!isset($options['hf_name'])) {
        echo "library add hf_name not found!";
        exit;
    }
    if (!isset($options['hf_expression'])) {
        echo "library add hf_expression not found!";
        exit;
    }
    if (!isset($options['inheritable'])) {
        echo "library add inheritable not found!";
        exit;
    }
    if (!isset($options['sys_kinds'])) {
        echo "library add sys_kinds not found!";
        exit;
    }
    if (!isset($options['resources'])) {
        echo "library add resources not found!";
        exit;
    }
    if (!isset($options['hf_parameters'])) {
        echo "library add hf_parameters not found!";
        exit;
    }
    $id_user = $options['id_user'];
    $hf_name = $options['hf_name'];
    $hf_expression = $options['hf_expression'];
    $inheritable = $options['inheritable'];
    $sys_kinds = $options['sys_kinds'];
    $resources = $options['resources'];
    $hf_parameters = $options['hf_parameters'];
    $inherit_from = "";
    if (isset($options['inherit_from'])) {
        $inherit_from = $options['inherit_from'];
    }
    $id_mime_type = "undefined";
    if (isset($options['mime'])) {
        $id_mime_type = $options['mime'];
    }
    $retval = "";
    $props = array();
    $props['id_user'] = $id_user;
    $props['id'] = sha1(microtime() . $hf_name . rand(1, 20));
    $retval = $props['id'];
    $props['name'] = $hf_name;
    $props['str_expression'] = $hf_expression;
    // CREATE HIS FUNCTION
    $props['id_condition'] = "perfectly";
    $props['str_cache_out_xml'] = "undefined";
    $props['str_cache_out_cxml'] = "undefined";
    $props['str_cache_approved'] = 'undefined';
    $props['str_cache_latest'] = 'undefined';
    $props['id_mime_type'] = $id_mime_type;
    $props['int_ws'] = "0";
    $props['int_wait'] = "0";
    $props['int_maxruntime'] = "0";
    $props['int_delay'] = "10";
    $new_hf = new hf_id_user();
    $new_hf->create($props);
    // CREATE SYSTEM KINDS
    foreach ($sys_kinds as $hf_sys_kind) {
        echo " ";
        $system_kind_current_id = "";
        // GET THIS SYS KIND FROM USER_SYSTEM_KINDS
        foreach ($u->obj_system_kinds as $user_system_kind) {
            if ($user_system_kind->name == $hf_sys_kind) {
                $system_kind_current_id = $user_system_kind->id;
            }
        }
        // end foreach (system kind name)
        if ($hf_sys_kind == "any") {
            $system_kind_current_id = "any";
        }
        if (strlen($system_kind_current_id) > 0) {
            $props = array();
            $props['id_hf'] = $new_hf->id;
            $props['id'] = sha1(microtime() . $system_kind_current_id . rand(1, 20));
            $props['id_sk'] = $system_kind_current_id;
            $new_hf_sk = new hf_system_kind();
            $new_hf_sk->create($props);
        } else {
            $library_message .= "Unable to find sys kind: {$hf_sys_kind} for function {$hf_name}.\n";
        }
    }
    // end foreach (system kind)
    foreach ($resources as $hf_resource) {
        echo " ";
        // CREATE RESOURCE
        $props = array();
        $props['id_hf'] = $new_hf->id;
        $props['id'] = sha1(microtime() . $hf_resource['content'] . rand(1, 20));
        $props['str_location'] = $hf_resource['content'];
        $props['str_filename'] = $hf_resource['filename'];
        $new_hf_resource = new hf_resource();
        $new_hf_resource->create($props);
        echo " ";
        if (isset($hf_resource['system_kinds'])) {
            foreach ($hf_resource['system_kinds'] as $hfr_system_kind) {
                echo " ";
                $system_kind_current_id = "";
                // GET THIS SYS KIND FROM USER_SYSTEM_KINDS
                foreach ($u->obj_system_kinds as $user_system_kind) {
                    if ($user_system_kind->name == $hfr_system_kind) {
                        $system_kind_current_id = $user_system_kind->id;
                    }
                }
                // end foreach (system kind name)
                if ($hfr_system_kind == "any") {
                    $system_kind_current_id = "any";
                }
                if (strlen($system_kind_current_id) > 0) {
                    $new_hfrsk = new hfr_system_kind();
                    $props = array();
                    $props['id_resource'] = $new_hf_resource->id;
                    $props['id'] = sha1(microtime() . rand(1, 20) . $system_kind_current_id);
                    $props['id_sk'] = $system_kind_current_id;
                    $new_hfrsk->create($props);
                } else {
                    echo "<pre>";
                    print_r($u);
                    echo "LIBRARY ERROR: UNABLE TO FIND SYSTEM KIND ({$hfr_system_kind})";
                    exit;
                }
            }
            // end foreach (system kind)
        }
        // end if (system kinds is set)
    }
    // end if (resource)
    if (strlen($inherit_from) > 0) {
        $props = array();
        $props['id_hf'] = $new_hf->id;
        $props['id'] = sha1(microtime() . rand(1, 20) . rand(2, 30));
        $props['id_inherit'] = $inherit_from;
        $new_hf_inherit = new hf_inherit();
        $new_hf_inherit->create($props);
    }
    // this part makes the function inherit from other functions
    if ($inheritable) {
        $props = array();
        $props['id_user'] = $id_user;
        $props['id_hf'] = $new_hf->id;
        $new_user_inherit = new user_inherit();
        $new_user_inherit->create($props);
    }
    foreach ($hf_parameters as $hf_parameter) {
        echo " ";
        $props = array();
        $props['id_hf'] = $new_hf->id;
        $props['id'] = sha1(microtime() . rand(1, 20) . $hf_parameter['keyword'] . $hf_parameter['parameter_name']);
        $props['keyword'] = $hf_parameter['keyword'];
        $props['parameter_name'] = $hf_parameter['parameter_name'];
        $props['str_default_value'] = $hf_parameter['default_value'];
        $props['int_preserve_encode'] = "0";
        if (isset($hf_parameter['int_preserve_encode'])) {
            if (strtolower($hf_parameter['int_preserve_encode']) == "true") {
                $props['int_preserve_encode'] = "1";
            }
        }
        $new_hf_parameter = new hf_parameter();
        $new_hf_parameter->create($props);
        if (isset($hf_parameter['constraints'])) {
            foreach ($hf_parameter['constraints'] as $hfp_constraint) {
                echo " ";
                $props = array();
                $props['id_hf_parameter'] = $new_hf_parameter->id;
                $props['id'] = sha1(microtime() . rand(1, 20) . $hfp_constraint['constraint_type'] . $hfp_constraint['constraint_text']);
                $props['id_constraint_type'] = $hfp_constraint['constraint_type'];
                $props['str_constraint_text'] = $hfp_constraint['constraint_text'];
                $new_hfp_vcs = new hfp_vcs();
                $new_hfp_vcs->create($props);
                //usleep(10);
            }
            // end foreach
        }
        //usleep(10);
    }
    // end foreach
    usleep(10);
    return $retval;
}
예제 #2
0
 public function build($obj_build_exclude = array())
 {
     global $APP;
     global $hf_parameters_given;
     parent::build($obj_build_exclude);
     $this->obj_hfp_vcs = array();
     $hfp_vcs = new hfp_vcs();
     $all_constraints = $hfp_vcs->get_from_hashrange($this->id);
     if (is_array($all_constraints)) {
         foreach ($all_constraints as $each_constraint) {
             $a_hfp_vcs = new hfp_vcs();
             $a_hfp_vcs->set($each_constraint);
             $a_hfp_vcs->build();
             $this->obj_hfp_vcs[] = $a_hfp_vcs;
         }
     }
     $hfp_name = $this->parameter_name;
     // hf parameter given
     $_POSTGET = array();
     foreach ($_GET as $GK => $GV) {
         $_POSTGET[$GK] = $GV;
     }
     foreach ($_POST as $PK => $PV) {
         $_POSTGET[$PK] = $PV;
     }
     if (isset($_POSTGET[$hfp_name]) && intval($this->int_immutable) == 0) {
         if (intval($this->int_preserve_encode) == 0) {
             $this->value = $_POSTGET[$hfp_name];
         } else {
             if (urlencode($_POSTGET[$hfp_name]) != $_POSTGET[$hfp_name]) {
                 $this->value = urlencode($_POSTGET[$hfp_name]);
             } else {
                 $this->value = $_POSTGET[$hfp_name];
             }
         }
         $hf_parameters_given = true;
         $mode_short = false;
     } else {
         // hf parameter value not given
         // or hf parameter is immutable (will always have default value)
         // only in edit mode, does "user id" make any sense :(
         if (false) {
             $this->value = "123";
         } else {
             $default_value = $this->obj_default_value->body;
             $this->value = $default_value;
             if (intval($this->int_preserve_encode) == 0) {
                 $this->value = urldecode($default_value);
             } else {
                 $this->value = $default_value;
             }
         }
     }
     // hf parameter given in arguments
     if (is_secret($this->keyword)) {
         $this->printable_value = "*****";
     } else {
         $this->printable_value = $this->value;
     }
     // get value constraints
     $parameter_constraints = $this->obj_hfp_vcs;
     $validated_value = "";
     if (count($parameter_constraints) > 0) {
         if (isset($this->value)) {
             $fstr = "" . $this->value . "";
             if (strlen($fstr) > 0) {
                 for ($fstri = 0; $fstri < strlen($fstr); $fstri++) {
                     $character = substr($fstr, $fstri, 1);
                     $bMatch = false;
                     $bEnforceRules = false;
                     if (is_array($parameter_constraints)) {
                         foreach ($parameter_constraints as $parameter_constraint) {
                             // 1 allow alphanumeric
                             // 2 allow spaces
                             // 3 allow numbers
                             // 4 allow alphabetic characters
                             // 5 allow the following special characters:
                             if ($parameter_constraint->id_constraint_type == "allow-alphanum") {
                                 $bEnforceRules = true;
                                 // allow alphanumeric
                                 if (ctype_alnum($character)) {
                                     $bMatch = true;
                                 } else {
                                     $bMatch = false;
                                 }
                             } else {
                                 if ($parameter_constraint->id_constraint_type == 'allow-space') {
                                     $bEnforceRules = true;
                                     // allow spaces
                                     if ($character == " ") {
                                         $bMatch = true;
                                     }
                                 } else {
                                     if ($parameter_constraint->id_constraint_type == 'allow-num') {
                                         $bEnforceRules = true;
                                         // allow numbers
                                         if (is_numeric($character)) {
                                             $bMatch = true;
                                         }
                                     } else {
                                         if ($parameter_constraint->id_constraint_type == 'allow-alpha') {
                                             $bEnforceRules = true;
                                             // allow alphabetic
                                             if (ctype_alpha($character)) {
                                                 $bMatch = true;
                                             }
                                         } else {
                                             if ($parameter_constraint->id_constraint_type == 'allow-special') {
                                                 $bEnforceRules = true;
                                                 // allow the following characters
                                                 $ctxt = $parameter_constraint->obj_constraint_text->body;
                                                 for ($i = 0; $i < strlen($ctxt); $i++) {
                                                     $ctxc = substr($ctxt, $i, 1);
                                                     if ($character == $ctxc) {
                                                         $bMatch = true;
                                                         break;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if ($bMatch) {
                                 break;
                             }
                         }
                         // end foreach (each constraint on parameter)
                     }
                     // end if (is array)
                     if ($bMatch || !$bEnforceRules) {
                         $validated_value = $validated_value . $character;
                     }
                 }
                 // foreach (each character in value)
                 $this->value = $validated_value;
             }
             // end if (string longer than 0 length)
         }
         // end if (hf parameter value isset)
     } else {
         $validated_value = $this->value;
     }
     $bMatches = true;
     if (is_array($parameter_constraints)) {
         foreach ($parameter_constraints as $parameter_constraint) {
             // 5 disallowed string
             // 6 must match regular expression
             if ($parameter_constraint->id_constraint_type == 'disallowed-str') {
                 // 5 disallowed string
                 if (strpos($validated_value, $parameter_constraint->obj_constraint_text->body) !== false) {
                     $bMatches = false;
                 }
             } else {
                 if ($parameter_constraint->id_constraint_type == 'match-regex') {
                     // 6 must match regular expression
                     if (preg_match($parameter_constraint->obj_constraint_text->body, $validated_value) == 0) {
                         $bMatches = false;
                     }
                 }
             }
             // end if (constraint type)
             if (!$bMatches) {
                 break;
             }
         }
         // foreach (parameter constraint)
     }
     // end if (count param constraints)
     if (!$bMatches) {
         // hf parameter value not given
         // only in edit mode does "user id" make any sense :(
         if (false) {
             $this->value = "123";
         } else {
             if (intval($this->int_preserve_encode) == 0) {
                 $this->value = urldecode($this->obj_default_value->body);
             } else {
                 $this->value = $this->obj_default_value->body;
             }
         }
     }
     // end if (constraint types 5 or 6 failed validation) - restore default values
 }
예제 #3
0
                $props = array();
                $props['id_hf_parameter'] = $_POST['id_hf_parameter'];
                $props['id'] = sha1(time() . $_POST['expression']);
                $props['id_constraint_type'] = $_POST['id_constraint_type'];
                $props['str_constraint_text'] = $_POST['expression'];
                $new_hfp_vcs = new hfp_vcs();
                $new_hfp_vcs->create($props);
            }
        }
    }
}
// delete hf parameter constraint
if (isset($_GET['action'])) {
    if ($_GET['action'] == "delete-hf-parameter-constraint") {
        if (isset($_POST['id_constraint'])) {
            $delete_hfp_vc = new hfp_vcs();
            $delete_hfp_vc->get_from_hashrange($_POST['id_hfp'], $_POST['id_constraint']);
            if ($delete_hfp_vc->id_hf_parameter != 'undefined') {
                $delete_hfp_vc->delete();
            }
        }
    }
}
// main page - add a hf
if (isset($_GET['action'])) {
    if ($_GET['action'] == 'delete-user-server') {
        if (isset($_POST['name'])) {
            $this_user_server = new user_server();
            $this_user_server->get_from_hashrange($u->id_user, $_POST['name']);
            if ($this_user_server->id_user != "undefined") {
                $this_user_server->delete();