Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings when IPDICOVER_IPD_DIR is set to default #1587

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plugins/main_sections/ms_ipdiscover/ms_custom_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@
$result_exist = ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
$fipdisc = "ipdiscover-util.pl";
$values = look_config_default_values(array('IPDISCOVER_IPD_DIR'), '', array('IPDISCOVER_IPD_DIR' => array('TVALUE' => VARLIB_DIR)));
$IPD_DIR = $values['tvalue']['IPDISCOVER_IPD_DIR'] . "/ipd";
$IPD_DIR = $values['tvalue']['IPDISCOVER_IPD_DIR'] ?? '' . "/ipd";
// Print $IPD_DIR in apache error log
error_log("IPD_DIR cus: " . $IPD_DIR);

if ($scriptPresent = @stat($fipdisc)) {
$filePresent = true;
if (!is_executable($fipdisc)) {
Expand Down
89 changes: 81 additions & 8 deletions require/search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,26 @@ public function generateSearchQuery($sessData){
$columnName[$index] = $value['fields'];
$containvalue[$index] = $value['operator'];
}

$tabSessValue=[];
$tabSessComparator=[];
$tabSessOperator=[];
$maxSessValue=0;
$isLessOrMore=0;

// Retrieve all mutli search
foreach ($searchInfos as $val) {
$tabSessValue[] = $val[self::SESS_VALUES];
$tabSessComparator[] = $val[self::SESS_COMPARATOR];
$tabSessOperator[] = $val[self::SESS_OPERATOR];
$maxSessValue =max($tabSessValue);
}

// check if < or > operators exist once
foreach ($tabSessOperator as $val) {
if ($val == "LESS" || $val == "MORE") {
$isLessOrMore++;
}
}
foreach ($searchInfos as $value) {
$nameTable = $tableName;
$open="";
Expand Down Expand Up @@ -400,13 +419,67 @@ public function generateSearchQuery($sessData){
if($value[self::SESS_OPERATOR] != "IS NULL"){
if ($nameTable != DatabaseSearch::COMPUTER_DEF_TABLE && $nameTable != self::GROUP_TABLE && $value[self::SESS_FIELDS] != 'CATEGORY_ID' && $value[self::SESS_FIELDS] != 'CATEGORY'
&& $value[self::SESS_OPERATOR] != "NOT IN" && $value[self::SESS_OPERATOR] != "ISNOTEMPTY") {
$this->columnsQueryConditions .= "$operator[$p] $open EXISTS (SELECT 1 FROM %s WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s '%s')$close ";
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $value[self::SESS_OPERATOR];
$this->queryArgs[] = $value[self::SESS_VALUES];
$lessOperator = "<";

if ($isLessOrMore >0) {
if (($value[self::SESS_COMPARATOR] == "AND" || empty($value[self::SESS_COMPARATOR])) && ($value[self::SESS_COMPARATOR] != "OR" && in_array("AND", $tabSessComparator))) {
if ($maxSessValue == $value[self::SESS_VALUES]) {
$this->columnsQueryConditions .= "$operator[$p] $open EXISTS (SELECT 1 FROM %s WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s %s) $close";
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $value[self::SESS_OPERATOR];
$this->queryArgs[] = $value[self::SESS_VALUES];
} else {

if (array_shift($tabSessValue) == $maxSessValue) {
$this->columnsQueryConditions .= "$operator[$p] $open EXISTS (SELECT 1 FROM %s WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s %s %s %s.%s %s %s $close";
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $value[self::SESS_OPERATOR];
$this->queryArgs[] = $value[self::SESS_VALUES];
$this->queryArgs[] = $value[self::SESS_COMPARATOR];
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $lessOperator;
$this->queryArgs[] = $maxSessValue;
$value[self::SESS_COMPARATOR] == "AND" ? $this->columnsQueryConditions .=")" : "";
} else {
$this->columnsQueryConditions .= "$operator[$p] $open EXISTS (SELECT 1 FROM %s WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s %s AND %s.%s %s %s) $close";
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $value[self::SESS_OPERATOR];
$this->queryArgs[] = $value[self::SESS_VALUES];
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $lessOperator;
$this->queryArgs[] = $maxSessValue;
}
}
} elseif (($value[self::SESS_COMPARATOR] == "OR" || empty($value[self::SESS_COMPARATOR])) && ($value[self::SESS_COMPARATOR] != "AND" && in_array("OR", $tabSessComparator))) {
$value[self::SESS_COMPARATOR] == "OR" ? $this->columnsQueryConditions .=") " : "";
$this->columnsQueryConditions .= "$operator[$p] EXISTS (SELECT 1 FROM % WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s %s $close";
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $value[self::SESS_OPERATOR];
$this->queryArgs[] = $value[self::SESS_VALUES];
}
} else {
$this->columnsQueryConditions .= "$operator[$p] $open EXISTS (SELECT 1 FROM %s WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s '%s')$close ";
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $nameTable;
$this->queryArgs[] = $value[self::SESS_FIELDS];
$this->queryArgs[] = $value[self::SESS_OPERATOR];
$this->queryArgs[] = $value[self::SESS_VALUES];
}
}elseif($nameTable == self::GROUP_TABLE || $value[self::SESS_FIELDS] == 'CATEGORY_ID' || $value[self::SESS_FIELDS] == 'CATEGORY'
|| $value[self::SESS_OPERATOR] == "NOT IN"){
$this->columnsQueryConditions .= "$operator[$p] $open EXISTS (SELECT 1 FROM %s WHERE hardware.ID = %s.HARDWARE_ID AND %s.%s %s (%s))$close ";
Expand Down
Loading