file exists
public static fileexists ( string $strFileName ) : boolean | ||
$strFileName | string | name of the file which should be check |
return | boolean | command successfull or not |
/** * get temperature information * * @return void */ private function _temperature() { if (PSI_OS == 'Linux') { $hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT); if (($totalh = count($hwpaths)) > 0) { $buf = ""; for ($h = 0; $h < $totalh; $h++) { $tempsensor = glob($hwpaths[$h] . "temp*_input", GLOB_NOSORT); if (($total = count($tempsensor)) > 0) { $buf = ""; for ($i = 0; $i < $total; $i++) { if (CommonFunctions::rfts($tempsensor[$i], $buf, 1, 4096, false) && trim($buf) != "") { $dev = new SensorDevice(); $dev->setValue(trim($buf) / 1000); $label = preg_replace("/_input\$/", "_label", $tempsensor[$i]); $crit = preg_replace("/_input\$/", "_crit", $tempsensor[$i]); $max = preg_replace("/_input\$/", "_max", $tempsensor[$i]); $crit_alarm = preg_replace("/_input\$/", "_crit_alarm", $tempsensor[$i]); if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setName(trim($buf)); } else { $labelname = trim(preg_replace("/_input\$/", "", pathinfo($tempsensor[$i], PATHINFO_BASENAME))); if ($labelname !== "") { $dev->setName($labelname); } else { $dev->setName('unknown'); } } if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setMax(trim($buf) / 1000); if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && trim($buf) === "1") { $dev->setEvent("Critical Alarm"); } } elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setMax(trim($buf) / 1000); } $this->mbinfo->setMbTemp($dev); } } } } } } else { $smp = 1; CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp); for ($i = 0; $i < $smp; $i++) { $temp = 0; if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.' . $i . '.temperature', $temp)) { $temp = preg_replace('/C/', '', $temp); $dev = new SensorDevice(); $dev->setName("CPU " . ($i + 1)); $dev->setValue($temp); // $dev->setMax(70); $this->mbinfo->setMbTemp($dev); } } } }
/** * Distribution * * @return void */ private function _distro() { $this->sys->setDistribution("Linux"); $list = @parse_ini_file(APP_ROOT . "/data/distros.ini", true); if (!$list) { return; } // We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && strlen(trim($distro_info)) > 0) { $distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY); foreach ($distro_tmp as $info) { $info_tmp = preg_split('/:/', $info, 2); if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && trim($distro_tmp[0]) != "" && isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && trim($distro_tmp[1]) != "") { $distro[trim($info_tmp[0])] = trim($info_tmp[1]); } } if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && trim($distro_tmp[0]) != "") { $this->sys->setDistribution(trim($distro_tmp[0])); if (preg_match('/^(\\S+)\\s*/', $distro_tmp[0], $id_buf) && isset($list[trim($id_buf[1])]['Image'])) { $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); } } } else { if (isset($distro['Description']) && preg_match('/^NAME=\\s*(.+)\\s*$/', $distro['Description'], $name_tmp)) { $distro['Description'] = $name_tmp[1]; } if (isset($distro['Description']) && $distro['Description'] != "n/a" && !isset($distro['Distributor ID'])) { $this->sys->setDistribution($distro['Description']); } elseif (isset($distro['Description']) && $distro['Description'] != "n/a" && isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a" && $distro['Description'] != $distro['Distributor ID']) { $this->sys->setDistribution($distro['Description']); } elseif (isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a") { $this->sys->setDistribution($distro['Distributor ID']); if (isset($distro['Release']) && $distro['Release'] != "n/a") { $this->sys->setDistribution($this->sys->getDistribution() . " " . $distro['Release']); } if (isset($distro['Codename']) && $distro['Codename'] != "n/a") { $this->sys->setDistribution($this->sys->getDistribution() . " (" . $distro['Codename'] . ")"); } } if (isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a" && isset($list[$distro['Distributor ID']]['Image'])) { $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']); } } } else { /* default error handler */ if (function_exists('errorHandlerPsi')) { restore_error_handler(); } /* fatal errors only */ $old_err_rep = error_reporting(); error_reporting(E_ERROR); // Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release if (CommonFunctions::fileexists($filename = "/etc/lsb-release") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRIB_ID="?([^"\\n]+)"?/m', $buf, $id_buf)) { if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\\n]+)"?/m', $buf, $desc_buf) && trim($desc_buf[1]) != trim($id_buf[1])) { $this->sys->setDistribution(trim($desc_buf[1])); } else { if (isset($list[trim($id_buf[1])]['Name'])) { $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name'])); } else { $this->sys->setDistribution(trim($id_buf[1])); } if (preg_match('/^DISTRIB_RELEASE="?([^"\\n]+)"?/m', $buf, $vers_buf)) { $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1])); } if (preg_match('/^DISTRIB_CODENAME="?([^"\\n]+)"?/m', $buf, $vers_buf)) { $this->sys->setDistribution($this->sys->getDistribution() . " (" . trim($vers_buf[1]) . ")"); } } if (isset($list[trim($id_buf[1])]['Image'])) { $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); } } else { // otherwise find files specific for distribution foreach ($list as $section => $distribution) { if (!isset($distribution['Files'])) { continue; } else { foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) { if (CommonFunctions::fileexists($filename)) { $distro = $distribution; if (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "detection") { $buf = ""; } elseif (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "execute") { if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) { $buf = ""; } } else { if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) { $buf = ""; } elseif (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "analyse") { if (preg_match('/^(\\S+)\\s*/', preg_replace('/^Red\\s+/', 'Red', $buf), $id_buf) && isset($list[trim($id_buf[1])]['Image'])) { $distro = $list[trim($id_buf[1])]; } } } if (isset($distro['Image'])) { $this->sys->setDistributionIcon($distro['Image']); } if (isset($distribution['Name'])) { if (is_null($buf) || trim($buf) == "") { $this->sys->setDistribution($distribution['Name']); } else { $this->sys->setDistribution($distribution['Name'] . " " . trim($buf)); } } else { if (is_null($buf) || trim($buf) == "") { $this->sys->setDistribution($section); } else { $this->sys->setDistribution(trim($buf)); } } if (isset($distribution['Files2'])) { foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) { if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) { if (preg_match('/^majorversion="?([^"\\n]+)"?/m', $buf, $maj_buf) && preg_match('/^minorversion="?([^"\\n]+)"?/m', $buf, $min_buf)) { $distr2 = $maj_buf[1] . '.' . $min_buf[1]; if (preg_match('/^buildphase="?([^"\\n]+)"?/m', $buf, $pha_buf) && $pha_buf[1] !== "0") { $distr2 .= '.' . $pha_buf[1]; } if (preg_match('/^buildnumber="?([^"\\n]+)"?/m', $buf, $num_buf)) { $distr2 .= '-' . $num_buf[1]; } if (preg_match('/^builddate="?([^"\\n]+)"?/m', $buf, $dat_buf)) { $distr2 .= ' (' . $dat_buf[1] . ')'; } $this->sys->setDistribution($this->sys->getDistribution() . " " . $distr2); } else { $distr2 = trim(substr($buf, 0, strpos($buf, "\n"))); if (!is_null($distr2) && $distr2 != "") { $this->sys->setDistribution($this->sys->getDistribution() . " " . $distr2); } } break; } } } break 2; } } } } } // if the distribution is still unknown if ($this->sys->getDistribution() == "Linux") { if (CommonFunctions::fileexists($filename = "/etc/DISTRO_SPECS") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) { if (isset($list[trim($id_buf[1])]['Name'])) { $dist = trim($list[trim($id_buf[1])]['Name']); } else { $dist = trim($id_buf[1]); } if (preg_match('/^DISTRO_VERSION=(.+)/m', $buf, $vers_buf)) { $this->sys->setDistribution(trim($dist . " " . trim($vers_buf[1]))); } else { $this->sys->setDistribution($dist); } if (isset($list[trim($id_buf[1])]['Image'])) { $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); } else { if (isset($list['Puppy']['Image'])) { $this->sys->setDistributionIcon($list['Puppy']['Image']); } } } elseif (CommonFunctions::fileexists($filename = "/etc/distro-release") && CommonFunctions::rfts($filename, $buf, 1, 4096, false) && !is_null($buf) && trim($buf) != "" || CommonFunctions::fileexists($filename = "/etc/system-release") && CommonFunctions::rfts($filename, $buf, 1, 4096, false) && !is_null($buf) && trim($buf) != "") { $this->sys->setDistribution(trim($buf)); if (preg_match('/^(\\S+)\\s*/', preg_replace('/^Red\\s+/', 'Red', $buf), $id_buf) && isset($list[trim($id_buf[1])]['Image'])) { $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); } } elseif (CommonFunctions::fileexists($filename = "/etc/solydxk/info") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRIB_ID="?([^"\\n]+)"?/m', $buf, $id_buf)) { if (preg_match('/^DESCRIPTION="?([^"\\n]+)"?/m', $buf, $desc_buf) && trim($desc_buf[1]) != trim($id_buf[1])) { $this->sys->setDistribution(trim($desc_buf[1])); } else { if (isset($list[trim($id_buf[1])]['Name'])) { $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name'])); } else { $this->sys->setDistribution(trim($id_buf[1])); } if (preg_match('/^RELEASE="?([^"\\n]+)"?/m', $buf, $vers_buf)) { $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1])); } if (preg_match('/^CODENAME="?([^"\\n]+)"?/m', $buf, $vers_buf)) { $this->sys->setDistribution($this->sys->getDistribution() . " (" . trim($vers_buf[1]) . ")"); } } if (isset($list[trim($id_buf[1])]['Image'])) { $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); } else { $this->sys->setDistributionIcon($list['SolydXK']['Image']); } } elseif (CommonFunctions::fileexists($filename = "/etc/os-release") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && (preg_match('/^TAILS_VERSION_ID="?([^"\\n]+)"?/m', $buf, $tid_buf) || preg_match('/^NAME="?([^"\\n]+)"?/m', $buf, $id_buf))) { if (preg_match('/^TAILS_VERSION_ID="?([^"\\n]+)"?/m', $buf, $tid_buf)) { if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\\n]+)"?/m', $buf, $desc_buf)) { $this->sys->setDistribution(trim($desc_buf[1]) . " " . trim($tid_buf[1])); } else { if (isset($list['Tails']['Name'])) { $this->sys->setDistribution(trim($list['Tails']['Name']) . " " . trim($tid_buf[1])); } else { $this->sys->setDistribution('Tails' . " " . trim($tid_buf[1])); } } $this->sys->setDistributionIcon($list['Tails']['Image']); } else { if (preg_match('/^PRETTY_NAME="?([^"\\n]+)"?/m', $buf, $desc_buf) && !preg_match('/\\$/', $desc_buf[1])) { //if is not defined by variable $this->sys->setDistribution(trim($desc_buf[1])); } else { if (isset($list[trim($id_buf[1])]['Name'])) { $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name'])); } else { $this->sys->setDistribution(trim($id_buf[1])); } if (preg_match('/^VERSION="?([^"\\n]+)"?/m', $buf, $vers_buf)) { $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1])); } elseif (preg_match('/^VERSION_ID="?([^"\\n]+)"?/m', $buf, $vers_buf)) { $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1])); } } if (isset($list[trim($id_buf[1])]['Image'])) { $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); } } } elseif (CommonFunctions::fileexists($filename = "/etc/debian_version")) { if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) { $buf = ""; } if (isset($list['Debian']['Image'])) { $this->sys->setDistributionIcon($list['Debian']['Image']); } if (isset($list['Debian']['Name'])) { if (is_null($buf) || trim($buf) == "") { $this->sys->setDistribution($list['Debian']['Name']); } else { $this->sys->setDistribution($list['Debian']['Name'] . " " . trim($buf)); } } else { if (is_null($buf) || trim($buf) == "") { $this->sys->setDistribution('Debian'); } else { $this->sys->setDistribution(trim($buf)); } } } } /* restore error level */ error_reporting($old_err_rep); /* restore error handler */ if (function_exists('errorHandlerPsi')) { set_error_handler('errorHandlerPsi'); } } }
/** * get current information * * @return void */ private function _current($hwpath) { $sensor = glob($hwpath . "curr*_input", GLOB_NOSORT); if (($total = count($sensor)) > 0) { $buf = ""; for ($i = 0; $i < $total; $i++) { if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && trim($buf) != "") { $dev = new SensorDevice(); $dev->setValue(trim($buf) / 1000); $label = preg_replace("/_input\$/", "_label", $sensor[$i]); $alarm = preg_replace("/_input\$/", "_alarm", $sensor[$i]); $max = preg_replace("/_input\$/", "_max", $sensor[$i]); $min = preg_replace("/_input\$/", "_min", $sensor[$i]); if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setName(trim($buf)); } else { $labelname = trim(preg_replace("/_input\$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME))); if ($labelname !== "") { $dev->setName($labelname); } else { $dev->setName('unknown'); } } if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setMax(trim($buf) / 1000); } if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setMin(trim($buf) / 1000); } if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && trim($buf) === "1") { $dev->setEvent("Alarm"); } $this->mbinfo->setMbCurrent($dev); } } } }