<commit_before><?php
$name = $_POST['Name'];
$sysadmin = $_POST['Sysadmin'];
$systems = array_filter(explode("\n", `sudo /var/ossec/bin/syscheck_control -ls`));
$headers = array ("SystemId", "Name", "IP", "Active");

$hs = array();
$mdr = array();
if (isset($sysadmin) and $sysadmin != 'false') {
  $mdr = array_filter(explode("\n", `k5start -qUf /etc/service.crcweb -- remctl frankoz1 mdr query "su_support is SA-CRC; su_sysadmin0"`));
  foreach ($mdr as $s) {
    $s = explode(': ', $s);
    $hs[$s[0]] = $s[1];
  }
}
unset ($mdr);

$mysys = array();

if (isset($name) and $name != '') {
  foreach ($systems as $row) {
    $row = rtrim($row, ",");
    $row = str_getcsv($row);
      if (strpos($row[1], $name) !== false) {
          if (isset($sysadmin) and $sysadmin != 'false') {
            if ($hs[$row[1]] == $_SERVER['REMOTE_USER']) {
              $mysys[] = array_combine($headers, $row);
            }
          } else {
            $mysys[] = array_combine($headers, $row);
          }
      }
  }
}
else {
  foreach($systems as $row) {
    $row = rtrim($row, ",");
    $row = str_getcsv($row);
    if (isset($sysadmin) and $sysadmin != 'false') {
      if ($hs[$row[1]] == $_SERVER['REMOTE_USER']) {
        $mysys[] = array_combine($headers, $row);
      }
    } else {
      $mysys[] = array_combine($headers, $row);
    }
  }
}


$json['Result'] = "OK";<commit_msg>List: sort by Name, add fix for local master hostname<commit_after><?php
$name = $_POST['Name'];
$sysadmin = $_POST['Sysadmin'];
$systems = array_filter(explode("\n", `sudo /var/ossec/bin/syscheck_control -ls`));
$headers = array ("SystemId", "Name", "IP", "Active");

$hs = array();
$mdr = array();
if (isset($sysadmin) and $sysadmin != 'false') {
  $mdr = array_filter(explode("\n", `k5start -qUf /etc/service.crcweb -- remctl frankoz1 mdr query "su_support is SA-CRC; su_sysadmin0"`));
  foreach ($mdr as $s) {
    $s = explode(': ', $s);
    $hs[$s[0]] = $s[1];
  }
}
unset ($mdr);

$mysys = array();

# Search by name, check if sysadin for filter.
if (isset($name) and $name != '') {
  foreach ($systems as $row) {
    $row = rtrim($row, ",");
    $row = str_getcsv($row);
    if (strpos($row[1], $name) !== false) {
      if (isset($sysadmin) and $sysadmin != 'false') {
        $ln = explode("\s", $row[1])[0];
        if ($hs[$ln] == $_SERVER['REMOTE_USER']) {
          $mysys[] = array_combine($headers, $row);
        }
      } else {
        $mysys[] = array_combine($headers, $row);
      }
    }
  }
}
else {
  # Return all systems, still check if sysadmin for filter.
  foreach($systems as $row) {
    $row = rtrim($row, ",");
    $row = str_getcsv($row);
    if (isset($sysadmin) and $sysadmin != 'false') {
      $ln = explode("\s", $row[1])[0];
      if ($hs[$ln] == $_SERVER['REMOTE_USER']) {
        $mysys[] = array_combine($headers, $row);
      }
    } else {
      $mysys[] = array_combine($headers, $row);
    }
  }
}

# Alphabetical sort on hostname for results.
function cmp($a, $b) {
  return strcmp($a['Name'], $b['Name']);
}

usort($mysys, 'cmp');

$json['Result'] = "OK";
{'fraction_non_alphanumeric': 0.2270515731430425, 'fraction_numerical': 0.005838469023678235, 'mean_word_length': 3.1340482573726542, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7597210', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1156, 'n_words': 259}