/**
  * localize important stuff
  * 
  * @access public
  */
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     // Localize error handler
     $this->_LinfoError = LinfoError::Singleton();
     // Should we hide mac addresses, to prevent stuff like mac address spoofing?
     $this->_hide_mac = array_key_exists('dhcpd3_hide_mac', $settings) ? (bool) $settings['dhcpd3_hide_mac'] : false;
     // Find leases file
     $this->_leases_file = LinfoCommon::locateActualPath(array('/var/lib/dhcp/dhcpd.leases', '/var/lib/dhcp3/dhcpd.leases', '/var/lib/dhcpd/dhcpd.leases', '/var/state/dhcp/dhcpd.leases', '/var/db/dhcpd/dhcpd.leases', '/var/db/dhcpd.leases'));
 }
Exemplo n.º 2
0
 /**
  * getDevs 
  * 
  * @access private
  * @return array of devices
  */
 public function getDevs()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new LinfoTimerStart('Hardware Devices');
     }
     // Location of useful paths
     $pci_ids = LinfoCommon::locateActualPath(array('/usr/share/misc/pci.ids', '/usr/share/pci.ids', '/usr/share/hwdata/pci.ids'));
     $usb_ids = LinfoCommon::locateActualPath(array('/usr/share/misc/usb.ids', '/usr/share/usb.ids', '/usr/share/hwdata/usb.ids'));
     // Did we not get them?
     $pci_ids || $this->error->add('Linux Device Finder', 'Cannot find pci.ids; ensure pciutils is installed.');
     $usb_ids || $this->error->add('Linux Device Finder', 'Cannot find usb.ids; ensure usbutils is installed.');
     // Class that does it
     $hw = new HW_IDS($usb_ids, $pci_ids);
     $hw->work('linux');
     return $hw->result();
 }
 /**
  * @test
  */
 public function locateActualPath()
 {
     $paths = array(LINFO_TESTDIR . '/files/test1.txt', LINFO_TESTDIR . '/files/test2.txt', LINFO_TESTDIR . '/files/test3.txt');
     $real = LINFO_TESTDIR . '/files/test2.txt';
     $this->assertEquals($real, LinfoCommon::locateActualPath($paths));
 }
Exemplo n.º 4
0
 /**
  * Run a command and cache its output for later
  *
  * @throws CallExtException
  * @param string $name name of executable to call
  * @param string $switches command arguments
  */
 public function exec($name, $switches = '')
 {
     // Sometimes it is necessary to call a program with sudo
     $attempt_sudo = array_key_exists('sudo_apps', self::$settings) && in_array($name, self::$settings['sudo_apps']);
     // Have we gotten it before?
     if (array_key_exists($name . $switches, $this->cliCache)) {
         return $this->cliCache[$name . $switches];
     }
     // Try finding the exec
     foreach ($this->searchPaths as $path) {
         // Found it; run it
         if (is_file($path . $name) && is_executable($path . $name)) {
             // Complete command, path switches and all
             $command = "{$path}{$name} {$switches}";
             // Sudoing?
             $command = $attempt_sudo ? LinfoCommon::locateActualPath(LinfoCommon::arrayAppendString($this->searchPaths, 'sudo', '%2s%1s')) . ' ' . $command : $command;
             // Result of command
             $result = `{$command}`;
             // Increment call count
             self::$callCount++;
             // Cache that
             $this->cliCache[$name . $switches] = $result;
             // Give result
             return $result;
         }
     }
     // Never got it
     throw new CallExtException('Exec `' . $name . '\' not found');
 }