livestatus: Stop relying on broken short-cut
[ninja.git] / application / helpers / nagvisconfig.php
blob2ce02b9bdad3a0db1c10b1bd03e4b37232efad4a
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Nagvis config reader class
4 */
6 class nagvisconfig_Core {
7 /**
8 * Get a list of maps and automaps the current user is authorized for
9 */
10 public static function get_map_list() {
11 $maps = array();
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);
20 return $maps;
22 $cfg = Op5Config::instance();
23 $nagvis_config = $cfg->getConfig('nagvis');
25 $contactgroups = Livestatus::instance()->getContactGroups(array(
26 'columns'=>array('name'),
27 'filter'=>array(
28 'members'=>array('>='=>$auth->get_user()->username)
30 ));
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]))
42 continue;
43 foreach( $groups as $group ) {
44 if (!isset( $nagvis_config[$grouptype][$group]))
45 continue;
46 foreach( $nagvis_config[$grouptype][$group] as $map => $perms ) {
47 if (in_array('view', $perms))
48 $maps[] = $map;
52 return $maps;
55 /**
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);
62 $data = array();
63 $cat = '';
64 foreach ($lines as $line) {
65 // Comments and empty lines, don't care
66 if (preg_match("/^;/", $line) || $line == "") {
67 continue;
70 // A category tagged [name]
71 if (preg_match("/^\[(.*)\]/", $line, $category)) {
72 $cat = $category[1];
75 // A value under a category, key=value
76 if (preg_match('/^(.*)="(.*)"/', $line, $values)) {
77 $data[$cat][$values[1]] = str_replace('"', '', $values[2]);
81 return $data;