This file is indexed.

/usr/share/php/Icinga/User/Preferences/Store/IniStore.php is in php-icinga 2.1.0-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */

namespace Icinga\User\Preferences\Store;

use Icinga\Application\Config;
use Icinga\Exception\NotReadableError;
use Icinga\Exception\NotWritableError;
use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore;
use Icinga\File\Ini\IniParser;

/**
 * Load and save user preferences from and to INI files
 */
class IniStore extends PreferencesStore
{
    /**
     * Preferences file of the given user
     *
     * @var string
     */
    protected $preferencesFile;

    /**
     * Stored preferences
     *
     * @var array
     */
    protected $preferences = array();

    /**
     * Initialize the store
     */
    protected function init()
    {
        $this->preferencesFile = sprintf(
            '%s/%s/config.ini',
            $this->getStoreConfig()->location,
            strtolower($this->getUser()->getUsername())
        );
    }

    /**
     * Load preferences from source
     *
     * @return  array
     *
     * @throws  NotReadableError    When the INI file of the user exists and is not readable
     */
    public function load()
    {
        if (file_exists($this->preferencesFile)) {
            if (! is_readable($this->preferencesFile)) {
                throw new NotReadableError(
                    'Preferences INI file %s for user %s is not readable',
                    $this->preferencesFile,
                    $this->getUser()->getUsername()
                );
            } else {
                $this->preferences = IniParser::parseIniFile($this->preferencesFile)->toArray();
            }
        }

        return $this->preferences;
    }

    /**
     * Save the given preferences
     *
     * @param   Preferences     $preferences    The preferences to save
     */
    public function save(Preferences $preferences)
    {
        $this->preferences = $preferences->toArray();

        // TODO: Elaborate whether we need to patch the contents
        // $preferences = $preferences->toArray();
        // $this->update(array_diff_assoc($preferences, $this->preferences));
        // $this->delete(array_keys(array_diff_key($this->preferences, $preferences)));

        $this->write();
    }

    /**
     * Write the preferences
     *
     * @throws  NotWritableError    In case the INI file cannot be written
     */
    public function write()
    {
        Config::fromArray($this->preferences)->saveIni($this->preferencesFile);
    }

    /**
     * Add or update the given preferences
     *
     * @param   array   $preferences    The preferences to set
     */
    protected function update(array $preferences)
    {
        foreach ($preferences as $key => $value) {
            $this->preferences[$key] = $value;
        }
    }

    /**
     * Delete the given preferences by name
     *
     * @param   array   $preferenceKeys     The preference names to delete
     */
    protected function delete(array $preferenceKeys)
    {
        foreach ($preferenceKeys as $key) {
            unset($this->preferences[$key]);
        }
    }
}