public function readTable()
 {
     $reservations = iterator_to_array($this->innerAdapter);
     $macMap = array();
     foreach ($reservations as $rid => $r) {
         $macMap[$r['MacAddress']] = $rid;
     }
     $leases = json_decode($this->platform->exec('/usr/libexec/nethserver/read-dhcp-leases')->getOutput(), TRUE);
     if (!is_array($leases)) {
         $leases = array();
     }
     $now = time();
     foreach ($leases as $l) {
         $leaseStatus = $now > $l['expire'] ? 0x0 : 0x1;
         // Expired : Valid
         $l['name'] = isset($l['name']) ? $l['name'] : 'host-' . substr(md5($l['mac'] . $l['ip']), 0, 8);
         // use hostname from reservation, if associated to MAC from lease cache:
         $lid = isset($macMap[$l['mac']]) ? $macMap[$l['mac']] : $l['name'];
         if (isset($reservations[$lid])) {
             $reservations[$lid]['LeaseStatus'] = $leaseStatus | 0x2;
             // Reserved
         } elseif (count(array_filter($reservations, function ($e) use($l) {
             // Search a reservation for the given MAC address
             return $e['MacAddress'] === $l['mac'];
         })) == 0) {
             $reservations[$lid] = array('MacAddress' => $l['mac'], 'IpAddress' => $l['ip'], 'Description' => '', 'LeaseStatus' => $leaseStatus);
         }
     }
     //        die(var_dump($reservations, 1));
     return new \ArrayObject($reservations);
 }
 public function setPlatform(\Nethgui\System\PlatformInterface $platform)
 {
     $this->platform = $platform;
     if ($platform instanceof \Nethgui\Log\LogConsumerInterface) {
         $this->setLog($platform->getLog());
     }
     return $this;
 }
 public function __construct(\Nethgui\System\PlatformInterface $platform)
 {
     $this->platform = $platform;
     # Search for installed provider
     if (file_exists('/usr/libexec/nethserver/ldap-list-users')) {
         $this->listUsersCommand = '/usr/libexec/nethserver/ldap-list-users';
     } else {
         if (file_exists('/usr/libexec/nethserver/ad-list-users')) {
             $this->listUsersCommand = '/usr/libexec/nethserver/ad-list-users';
         }
     }
     $this->ad = $platform->getDatabase('configuration')->getProp('sssd', 'Provider') === 'ad';
 }
 public function readTable()
 {
     $networks = iterator_to_array($this->innerAdapter);
     $elements = json_decode($this->platform->exec('/usr/libexec/nethserver/trusted-networks')->getOutput(), TRUE);
     if (!is_array($elements)) {
         return new \ArrayObject($networks);
     }
     foreach ($elements as $e) {
         list($net, $mask) = explode('/', $e['mask']);
         if (!isset($networks[$net])) {
             $networks[$net] = array('Mask' => $mask, 'Description' => $e['provider'], 'editable' => 0);
         }
     }
     return new \ArrayObject($networks);
 }
 public function getSharedMailboxList()
 {
     $mailboxes = array();
     $proc = $this->platform->exec('/usr/bin/sudo /usr/bin/doveadm ${@}', explode(' ', 'mailbox list -u vmail Public/*'));
     if ($proc->getExitCode() !== 0 || $proc->getOutput() === NULL) {
         return new \ArrayObject();
     }
     foreach ($proc->getOutputArray() as $mb) {
         $key = substr($mb, 7);
         // trim Public/ prefix
         $mailboxes[$key] = array('name' => $key);
     }
     ksort($mailboxes);
     return new \ArrayObject($mailboxes);
 }
 public function readMailQueue()
 {
     $messages = array();
     $process = $this->platform->exec('/usr/bin/sudo /usr/sbin/postqueue -p | head -n 4000 | /usr/libexec/nethserver/mailq2json');
     if ($process->getExitCode() == 0) {
         $messages = json_decode($process->getOutput(), TRUE);
     } else {
         $this->getLog()->error(sprintf("%s: postqueue -f command failed - %s", __CLASS__, $process->getOutput()));
     }
     $data = new \ArrayObject();
     foreach ($messages as $message) {
         $recipients = $this->getAllRecipients($message);
         $row = array('Id' => $message['id'], 'Sender' => $message['sender'], 'Status' => $message['status'], 'Size' => $this->formatSize($message['size']), 'Timestamp' => $message['time'], 'Recipients' => $recipients, 'RecipientsCount' => (string) count($recipients), 'Problems' => array_keys($message['reasons']));
         $data[$message['id']] = $row;
     }
     return $data;
 }
 /**
  * Lazy loader for `membership` relation
  */
 private function getInnerAdapters()
 {
     if (!isset($this->innerAdapters)) {
         $this->innerAdapters = array();
         $this->groups = $this->platform->getDatabase('accounts')->getAll('group');
         // Get an identity adapter for each group that points to the Members prop.
         foreach ($this->groups as $keyName => $props) {
             $this->innerAdapters[$keyName] = $this->platform->getIdentityAdapter('accounts', $keyName, 'Members', ',');
         }
     }
     return $this->innerAdapters;
 }
 private function addSearchRoles(\Nethgui\System\PlatformInterface $platform, $text)
 {
     $tmp = array();
     foreach ($platform->getDatabase('networks')->getAll() as $key => $props) {
         if (isset($props['role'])) {
             $tmp[$props['role']] = '';
         }
     }
     $ovpn = $platform->getDatabase('configuration')->getProp('openvpn', 'status');
     $ivpn = $platform->getDatabase('configuration')->getProp('ipsec', 'status');
     if ($ovpn || $ivpn) {
         $tmp['vpn'] = '';
     }
     $roles = array_filter(array_diff(array_keys($tmp), array('bridged', 'alias', 'slave')));
     foreach ($roles as $role) {
         if (!$text || strstr($role, strtolower($text)) !== FALSE) {
             $this->results->append(new \NethServer\Tool\FirewallObject($role, 'role', array(), $this->translator));
         }
     }
 }