function AssessAntagonism($checkstr, &$AntagonisticWordsArray)
{
    DebugToLog('DEBUG: Begin func AssessAntagonism');
    $checkstr = str_replace('-', ' ', $checkstr);
    // People use hyphens between words all the time for no good reason. Replace hyphens with spaces.
    $EachWord = str_word_count($checkstr, 1);
    // put all in array, note the '1' parm
    if (!is_array($EachWord)) {
        DebugToLog('DEBUG:  (A1) $EachWord is NOT an array');
        return NULL;
    } else {
        DebugToLog('DEBUG:  (A1) $EachWord IS an array');
    }
    DebugToLog('DUMP: $EachWord' . print_r($EachWord, true));
    DebugToLog('DEBUG: (a9) $EachWord imploded=' . implode(' ', $EachWord));
    DebugToLog('DUMP: $AntagonisticWordsArray' . print_r($AntagonisticWordsArray, true));
    $EachWord = arrayUnique($EachWord);
    // if the antagonistc word  'black' occurrs 6x in text about a  black history, you need to count it only once so as to be conservative in assessing antagonism.
    $EachWord = reIndex(0, $EachWord);
    // this needed? Yes
    $EachWord_cnt = count($EachWord);
    DebugToLog('DEBUG: $EachWord_cnt=' . $EachWord_cnt);
    if (!is_array($EachWord)) {
        DebugToLog('DEBUG: $EachWord is NOT an array');
        return;
        NULL;
    }
    for ($x = 0; $x < $EachWord_cnt; $x++) {
        $y = strlen($EachWord[$x]);
        if ($EachWord[$x][$y - 1] == 's' and $y > 2 and $EachWord[$x][$y - 2] == '\'') {
            $EachWord[$x] = substr($EachWord[$x], 0, $y - 2);
        }
    }
    for ($x = 0; $x < $EachWord_cnt; $x++) {
        $EachWord[$x] = strtolower($EachWord[$x]);
        // so now we have an array of all words in the input string ($checkstr) with possesive 's' removed, all lowercase and recuded to a single instance of each word
    }
    $Antag_cnt = count($AntagonisticWordsArray);
    $TotalAntagonisticWords = 0;
    for ($y = 0; $y < $Antag_cnt; $y++) {
        for ($x = 0; $x < $EachWord_cnt; $x++) {
            // DebugToLog('SUPERDUMP: $EachWord=' . $EachWord[$x]. '  ANTAG singular=' . $AntagonisticWordsArray[$y]['theword'] . '  plural=' . $AntagonisticWordsArray[$y]['plural'] );
            if ($EachWord[$x] != "" and (strtolower($EachWord[$x]) == $AntagonisticWordsArray[$y]['theword'] or strtolower($EachWord[$x]) == $AntagonisticWordsArray[$y]['plural'])) {
                DebugToLog('DUMP: $EachWord' . implode(' ', $EachWord));
                DebugToLog('SUBRULE MATCH: Antagonism match - input string word =' . $EachWord[$x] . '  antagarray =' . $AntagonisticWordsArray[$y]['theword'] . '  plural =' . $AntagonisticWordsArray[$y]['plural']);
                $TotalAntagonisticWords++;
                break;
                // break becuase we only need to match one instance of an antagonistic word
            }
        }
    }
    DebugToLog('DEBUG: $TotalAntagonisticWords= ' . $TotalAntagonisticWords);
    return $TotalAntagonisticWords;
}
Example #2
0
			<th>' . _('Work Centre') . '</th>
			<th>' . _('Quantity') . '</th>
			<th>' . _('Effective After') . '</th>
			<th>' . _('Effective To') . '</th>
			<th>' . _('Auto Issue') . '</th>
			<th>' . _('Qty On Hand') . '</th>
		</tr>';
    if (count($BOMTree) == 0) {
        echo '<tr class="OddTableRows">
				<td colspan="8">' . _('No materials found.') . '</td>
			</tr>';
    } else {
        $UltimateParent = $SelectedParent;
        $k = 0;
        $RowCounter = 1;
        $BOMTree = arrayUnique($BOMTree);
        foreach ($BOMTree as $BOMItem) {
            $Level = $BOMItem['Level'];
            $Parent = $BOMItem['Parent'];
            $Component = $BOMItem['Component'];
            if ($k == 1) {
                echo '<tr class="EvenTableRows">';
                $k = 0;
            } else {
                echo '<tr class="OddTableRows">';
                $k++;
            }
            DisplayBOMItems($UltimateParent, $Parent, $Component, $Level, $db);
        }
    }
    echo '</table>
Example #3
0
    printf("%s\n", $f[0] . "/" . $f[1]);
}
echo "\n===============\n";
echo "Accessed tainted globals:\n";
usort($global_functions, "compareFunctions");
foreach ($global_functions as $f) {
    printf("%s\n", $f[0] . "/" . $f[1]);
}
//now calculate the set of functions where I must enable taint tracking
$tainted_functions = arrayUnique(array_merge($sink_functions, $source_functions, $global_functions));
foreach ($sink_functions as $f) {
    if (!in_array($f, $parameter_functions)) {
        continue;
    }
    //the function is not receiving tainted params
    $ftraces = arrayUnique($traces_functions[getStringRepresentation($f)]);
    foreach ($ftraces as $t) {
        $first = true;
        foreach ($t[1] as $e) {
            if ($first && strpos($f[0], ".php") !== FALSE) {
                $first = false;
                continue;
            }
            if (isset($e["function"])) {
                $fc = array($e["function"], isset($e["class"]) ? $e["class"] : NULL);
                if ($fc == $f) {
                    continue;
                }
                if (!in_array($fc, $tainted_functions)) {
                    echo "Recursively added [" . getStringRepresentation($fc) . "]\n";
                    $tainted_functions[] = $fc;
Example #4
0
    if (preg_match('/^\\-\\-[a-f0-9]+\\-[^ABCEFHIKZ]\\-\\-$/i', trim($BODY[$line]))) {
        while ($line < $BodySize) {
            if (preg_match('/^\\-\\-[a-f0-9]+\\-[ABCEFHIKZ]\\-\\-$/i', trim($BODY[$line]))) {
                break;
            } else {
                $line++;
            }
        }
    }
}
// Set a mark in RelevantOnly events trapped by sensor but not trapped by a rule
if (!isset($PhaseH_MSG)) {
    $PhaseH['Message_Severity'] = 99;
    $PhaseH['Message_Tag'] = "TRANSACTION";
} else {
    $PhaseH_MSG = array_values(arrayUnique($PhaseH_MSG));
    foreach ($PhaseH_MSG as $msg_severity) {
        if (!isset($PhaseH['Message_Severity'])) {
            if (isset($msg_severity['Message_Severity'])) {
                $PhaseH['Message_Severity'] = $msg_severity['Message_Severity'];
            }
        } elseif (isset($msg_severity['Message_Severity']) and $PhaseH['Message_Severity'] > $msg_severity['Message_Severity']) {
            $PhaseH['Message_Severity'] = $msg_severity['Message_Severity'];
        }
    }
}
// Set event as Pass (99) when no Interception_phase is defined, Pass can be a Action "pass, allowed" or can be "Detection Only"
if (!isset($PhaseH['Interception_phase'])) {
    $PhaseH['Interception_phase'] = 99;
}
// Hack to avoid handle IPv6 by now
function step1($req)
{
    ini_set('memory_limit', '500M');
    set_time_limit(0);
    //this avoids timeouts
    global $CONFIG;
    require_once $CONFIG->path . "mod/profile_manager/views/default/profile_manager/members/classes.php";
    include $CONFIG->path . "mod/profile_manager/views/default/profile_manager/members/config.php";
    $lr = unserialize(file_get_contents($IOdir . "lr"));
    $ent = $_SESSION["ent"];
    $clusters_metadata = unserialize(file_get_contents($IOdir . 'clusters_metadata'));
    $clusters_uses = unserialize(file_get_contents($IOdir . 'clusters_uses'));
    $clusters_tags = unserialize(file_get_contents($IOdir . 'clusters_tags'));
    $clusters_replinks = unserialize(file_get_contents($IOdir . 'clusters_replinks'));
    if ($dd_crosscheck == 1) {
        $metadata_dd = unserialize(file_get_contents($IOdir . 'metadata_dd'));
        $uses_dd = unserialize(file_get_contents($IOdir . 'uses_dd'));
        $tags_dd = unserialize(file_get_contents($IOdir . 'tags_dd'));
        $replinks_dd = unserialize(file_get_contents($IOdir . 'replinks_dd'));
    }
    $selected_ent = get_selected_entities($ent);
    //it takes the checkbox selected documents
    //I look for the clusters (metadata, uses, tags, replinks) which contain the document
    $clusters_matching_metadata = array();
    $clusters_matching_uses = array();
    $clusters_matching_tags = array();
    $clusters_matching_replinks = array();
    foreach ($selected_ent as $key => $type) {
        foreach ($clusters_metadata as $cluster_obj) {
            if ($cluster_obj->belongs($key) && count($cluster_obj->array_docs) > 1) {
                $clusters_matching_metadata[] = array("cluster" => $cluster_obj, "relevance" => 0);
                //all the clusters containing the selected documents; we will use relevance later
            }
        }
        foreach ($clusters_uses as $cluster_obj) {
            if ($cluster_obj->belongs($key) && count($cluster_obj->array_docs) > 1) {
                $clusters_matching_uses[] = array("cluster" => $cluster_obj, "relevance" => 0);
                //all the clusters containing the selected documents; we will use relevance later
            }
        }
        foreach ($clusters_tags as $cluster_obj) {
            if ($cluster_obj->belongs($key) && count($cluster_obj->array_docs) > 1) {
                $clusters_matching_tags[] = array("cluster" => $cluster_obj, "relevance" => 0);
                //all the clusters containing the selected documents; we will use relevance later
            }
        }
        foreach ($clusters_replinks as $cluster_obj) {
            if ($cluster_obj->belongs($key) && count($cluster_obj->array_docs) > 1) {
                $clusters_matching_replinks[] = array("cluster" => $cluster_obj, "relevance" => 0);
                //all the clusters containing the selected documents; we will use relevance later
            }
        }
    }
    $clusters_matching_metadata = arrayUnique($clusters_matching_metadata);
    $clusters_matching_uses = arrayUnique($clusters_matching_uses);
    $clusters_matching_tags = arrayUnique($clusters_matching_tags);
    $clusters_matching_replinks = arrayUnique($clusters_matching_replinks);
    /* calculate relevance for each cluster returned in the previous step: it's the relevance of the cluster to the search done
     *  relevance of the cluster is given by the number of $selected_ent contained
     */
    foreach ($selected_ent as $key => $type) {
        foreach ($clusters_matching_metadata as $num => $cluster) {
            if ($cluster["cluster"]->belongs($key)) {
                $clusters_matching_metadata[$num]["relevance"]++;
            }
        }
        foreach ($clusters_matching_uses as $num => $cluster) {
            if ($cluster["cluster"]->belongs($key)) {
                $clusters_matching_uses[$num]["relevance"]++;
            }
        }
        foreach ($clusters_matching_tags as $num => $cluster) {
            if ($cluster["cluster"]->belongs($key)) {
                $clusters_matching_tags[$num]["relevance"]++;
            }
        }
        foreach ($clusters_matching_replinks as $num => $cluster) {
            if ($cluster["cluster"]->belongs($key)) {
                $clusters_matching_replinks[$num]["relevance"]++;
            }
        }
    }
    //sort the clusters by their relevance in descending order
    usort($clusters_matching_metadata, "compare_relevance");
    usort($clusters_matching_uses, "compare_relevance");
    usort($clusters_matching_tags, "compare_relevance");
    usort($clusters_matching_replinks, "compare_relevance");
    //it creates, for each type (metadata, uses, tags, replinks), a list of the documents contained in the clusters. Each document has a relevance, in order to visualize them by relevance descending order
    //the relevance is calculated this way: relevance of the cluster multiplied by a score of the document.
    //this score, if we do a crosscheck with the doc-doc matrix, is given by that matrix, otherwise is the inherence (for the clusters given by the YACA algorithm) or 1 (for the other clusters)
    $list_documents_metadata = array();
    foreach ($clusters_matching_metadata as $num => $cluster) {
        foreach ($cluster["cluster"]->array_docs as $doc_block) {
            if (is_array($doc_block)) {
                $guid = $doc_block["guid"];
            } else {
                $guid = $doc_block;
            }
            if (array_key_exists($guid, $selected_ent)) {
                continue;
            }
            if (get_type($guid) != "resource") {
                continue;
            }
            //don't consider eventual documents that are not part of the resources, for example documents that were present and so part of the classification, but that after have been deleted
            if (!array_key_exists($guid, $list_documents_metadata)) {
                if ($dd_crosscheck == 1) {
                    $max = 0;
                    foreach ($selected_ent as $key => $type) {
                        if ($metadata_dd[$guid][$key] > $max) {
                            $max = $metadata_dd[$guid][$key];
                        }
                    }
                    $list_documents_metadata[$guid]["relevance"] = ($max + 0.05) * $cluster["relevance"];
                    //we add 0.05 to avoid having a 0 value
                } elseif (is_array($doc_block)) {
                    $list_documents_metadata[$guid]["relevance"] = $doc_block["inherence"] * $cluster["relevance"];
                } else {
                    $list_documents_metadata[$guid]["relevance"] = $cluster["relevance"];
                }
            }
        }
    }
    $list_documents_uses = array();
    foreach ($clusters_matching_uses as $num => $cluster) {
        foreach ($cluster["cluster"]->array_docs as $doc_block) {
            if (is_array($doc_block)) {
                $guid = $doc_block["guid"];
            } else {
                $guid = $doc_block;
            }
            if (array_key_exists($guid, $selected_ent)) {
                continue;
            }
            if (get_type($guid) != "resource") {
                continue;
            }
            //don't consider eventual documents that are not part of the resources, for example documents that were present and so part of the classification, but that after have been deleted
            if (!array_key_exists($guid, $list_documents_uses)) {
                if ($dd_crosscheck == 1) {
                    $max = 0;
                    foreach ($selected_ent as $key => $type) {
                        if ($uses_dd[$guid][$key] > $max) {
                            $max = $uses_dd[$guid][$key];
                        }
                    }
                    $list_documents_uses[$guid]["relevance"] = ($max + 0.05) * $cluster["relevance"];
                    //we add 0.05 to avoid having a 0 value
                } elseif (is_array($doc_block)) {
                    $list_documents_uses[$guid]["relevance"] = $doc_block["inherence"] * $cluster["relevance"];
                } else {
                    $list_documents_uses[$guid]["relevance"] = $cluster["relevance"];
                }
            }
        }
    }
    $list_documents_tags = array();
    foreach ($clusters_matching_tags as $num => $cluster) {
        foreach ($cluster["cluster"]->array_docs as $doc_block) {
            if (is_array($doc_block)) {
                $guid = $doc_block["guid"];
            } else {
                $guid = $doc_block;
            }
            if (array_key_exists($guid, $selected_ent)) {
                continue;
            }
            if (get_type($guid) != "resource") {
                continue;
            }
            //don't consider eventual documents that are not part of the resources, for example documents that were present and so part of the classification, but that after have been deleted
            if (!array_key_exists($guid, $list_documents_tags)) {
                if ($dd_crosscheck == 1) {
                    $max = 0;
                    foreach ($selected_ent as $key => $type) {
                        if ($tags_dd[$guid][$key] > $max) {
                            $max = $tags_dd[$guid][$key];
                        }
                    }
                    $list_documents_tags[$guid]["relevance"] = ($max + 0.05) * $cluster["relevance"];
                    //we add 0.05 to avoid having a 0 value
                } elseif (is_array($doc_block)) {
                    $list_documents_tags[$guid]["relevance"] = $doc_block["inherence"] * $cluster["relevance"];
                } else {
                    $list_documents_tags[$guid]["relevance"] = $cluster["relevance"];
                }
            }
        }
    }
    $list_documents_replinks = array();
    foreach ($clusters_matching_replinks as $num => $cluster) {
        foreach ($cluster["cluster"]->array_docs as $doc_block) {
            if (is_array($doc_block)) {
                $guid = $doc_block["guid"];
            } else {
                $guid = $doc_block;
            }
            if (array_key_exists($guid, $selected_ent)) {
                continue;
            }
            if (get_type($guid) != "resource") {
                continue;
            }
            //don't consider eventual documents that are not part of the resources, for example documents that were present and so part of the classification, but that after have been deleted
            if (!array_key_exists($guid, $list_documents_replinks)) {
                if ($dd_crosscheck == 1) {
                    $max = 0;
                    foreach ($selected_ent as $key => $type) {
                        if ($replinks_dd[$guid][$key] > $max) {
                            $max = $replinks_dd[$guid][$key];
                        }
                    }
                    $list_documents_replinks[$guid]["relevance"] = ($max + 0.05) * $cluster["relevance"];
                    //we add 0.05 to avoid having a 0 value
                } elseif (is_array($doc_block)) {
                    $list_documents_replinks[$guid]["relevance"] = $doc_block["inherence"] * $cluster["relevance"];
                } else {
                    $list_documents_replinks[$guid]["relevance"] = $cluster["relevance"];
                }
            }
        }
    }
    //sort the clusters by relevance and then by name
    uasort($list_documents_metadata, "compare_relevance_name");
    uasort($list_documents_uses, "compare_relevance_name");
    uasort($list_documents_tags, "compare_relevance_name");
    uasort($list_documents_replinks, "compare_relevance_name");
    $response = array();
    $response['metadata'] = create_data($list_documents_metadata, $lr, $selected_ent);
    //return the documents contained in the clusters
    $response['uses'] = create_data($list_documents_uses, $lr, $selected_ent);
    //return the documents contained in the clusters
    $response['tags'] = create_data($list_documents_tags, $lr, $selected_ent);
    //return the documents contained in the clusters
    $response['replinks'] = create_data($list_documents_replinks, $lr, $selected_ent);
    //return the documents contained in the clusters
    //Now I get positive features from the clusters
    $response['feat_metadata'] = array();
    foreach ($clusters_matching_metadata as $c) {
        if (!empty($c["cluster"]->commonFeatures)) {
            $response['feat_metadata'] = array_merge($response['feat_metadata'], $c["cluster"]->commonFeatures);
        }
    }
    $response['feat_metadata'] = array_unique($response['feat_metadata']);
    $response['feat_tags'] = array();
    foreach ($clusters_matching_tags as $c) {
        if (!empty($c["cluster"]->commonFeatures)) {
            $response['feat_tags'] = array_merge($response['feat_tags'], $c["cluster"]->commonFeatures);
        }
    }
    $response['feat_tags'] = array_unique($response['feat_tags']);
    $response['feat_uses'] = array();
    foreach ($clusters_matching_uses as $c) {
        if (!empty($c["cluster"]->commonFeatures)) {
            $response['feat_uses'] = array_merge($response['feat_uses'], $c["cluster"]->commonFeatures);
        }
    }
    $response['feat_uses'] = array_unique($response['feat_uses']);
    if ($req['save_cluster']) {
        $response['cluster'] = array();
        $response['cluster']['metadata'] = $clusters_matching_metadata;
        $response['cluster']['uses'] = $clusters_matching_uses;
        $response['cluster']['tags'] = $clusters_matching_tags;
        $response['cluster']['replinks'] = $clusters_matching_replinks;
    }
    return $response;
}