1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Nagvis config reader class
6 class nagvisconfig_Core
{
8 * Get a list of maps and automaps the current user is authorized for
10 public static function get_map_list() {
12 $auth = Auth
::instance();
13 if ($auth->authorized_for('nagvis_view')) {
14 $files = scandir(Kohana
::config('nagvis.nagvis_real_path').'/etc/maps');
15 foreach ($files as $file) {
16 if (strpos($file, '.cfg') !== false)
17 $maps[] = substr($file, 0, -4);
22 $cfg = Op5Config
::instance();
23 $nagvis_config = $cfg->getConfig('nagvis');
25 $contactgroups = Livestatus
::instance()->getContactGroups(array(
26 'columns'=>array('name'),
28 'members'=>array('>='=>$auth->get_user()->username
)
31 foreach ($contactgroups as $idx) {
32 $contactgroups[$idx] = $contactgroups[$idx]['name'];
35 $groups_per_type = array(
36 'auth_groups' => $auth->get_user()->groups
,
37 'contact_groups' => $contactgroups
40 foreach($groups_per_type as $grouptype => $groups) {
41 if(!isset($nagvis_config[$grouptype]))
43 foreach( $groups as $group ) {
44 if (!isset( $nagvis_config[$grouptype][$group]))
46 foreach( $nagvis_config[$grouptype][$group] as $map => $perms ) {
47 if (in_array('view', $perms))
56 * Function to read Nagvis config file and return array with key->values
58 public static function get($ConfigFile) {
59 $raw = file_get_contents($ConfigFile);
60 $lines = explode("\n", $raw);
64 foreach ($lines as $line) {
65 // Comments and empty lines, don't care
66 if (preg_match("/^;/", $line) ||
$line == "") {
70 // A category tagged [name]
71 if (preg_match("/^\[(.*)\]/", $line, $category)) {
75 // A value under a category, key=value
76 if (preg_match('/^(.*)="(.*)"/', $line, $values)) {
77 $data[$cat][$values[1]] = str_replace('"', '', $values[2]);