Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2775 rexy 1
<?php
2
/**
3
 * start page for webaccess
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Web
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: class.Webpage.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * generate the dynamic webpage
17
 *
18
 * @category  PHP
19
 * @package   PSI_Web
20
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
21
 * @copyright 2009 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
23
 * @version   Release: 3.0
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
26
class Webpage extends Output implements PSI_Interface_Output
27
{
28
    /**
29
     * configured indexname
30
     *
31
     * @var String
32
     */
33
    private $_indexname;
34
 
35
    /**
36
     * configured language
37
     *
38
     * @var String
39
     */
40
    private $_language;
41
 
42
    /**
43
     * configured template
44
     *
45
     * @var String
46
     */
47
    private $_template;
48
 
49
    /**
50
     * all available templates
51
     *
52
     * @var array
53
     */
54
    private $_templates = array();
55
 
56
    /**
57
     * configured bootstrap template
58
     *
59
     * @var String
60
     */
61
    private $_bootstrap_template;
62
 
63
    /**
64
     * all available bootstrap templates
65
     *
66
     * @var array
67
     */
68
    private $_bootstrap_templates = array();
69
 
70
    /**
71
     * all available languages
72
     *
73
     * @var array
74
     */
75
    private $_languages = array();
76
 
77
    /**
78
     * configured show picklist language
79
     *
80
     * @var boolean
81
     */
82
    private $_pick_language;
83
 
84
    /**
85
     * configured show picklist template
86
     *
87
     * @var boolean
88
     */
89
    private $_pick_template;
90
 
91
    /**
92
     * check for all extensions that are needed, initialize needed vars and read phpsysinfo.ini
93
     * @param string $indexname
94
     */
95
    public function __construct($indexname="dynamic")
96
    {
97
        $this->_indexname = $indexname;
98
        parent::__construct();
99
        $this->_getTemplateList();
100
        $this->_getLanguageList();
101
    }
102
 
103
    /**
104
     * checking phpsysinfo.ini setting for template, if not supportet set phpsysinfo.css as default
105
     * checking phpsysinfo.ini setting for language, if not supported set en as default
106
     *
107
     * @return void
108
     */
109
    private function _checkTemplateLanguage()
110
    {
111
        if (!defined("PSI_DEFAULT_TEMPLATE") || (($this->_template = strtolower(trim(PSI_DEFAULT_TEMPLATE))) == "") || !file_exists(PSI_APP_ROOT.'/templates/'.$this->_template.".css")) {
112
            $this->_template = 'phpsysinfo';
113
        }
114
        if (!defined("PSI_DEFAULT_BOOTSTRAP_TEMPLATE") || (($this->_bootstrap_template = strtolower(trim(PSI_DEFAULT_BOOTSTRAP_TEMPLATE))) == "") || !file_exists(PSI_APP_ROOT.'/templates/'.$this->_bootstrap_template."_bootstrap.css")) {
115
            $this->_bootstrap_template = 'phpsysinfo';
116
        }
117
        $this->_pick_template = !defined("PSI_SHOW_PICKLIST_TEMPLATE") || (PSI_SHOW_PICKLIST_TEMPLATE !== false);
118
 
119
        if (!defined("PSI_DEFAULT_LANG") || (($this->_language = strtolower(trim(PSI_DEFAULT_LANG))) == "") || !file_exists(PSI_APP_ROOT.'/language/'.$this->_language.".xml")) {
120
            $this->_language = 'en';
121
        }
122
        $this->_pick_language = !defined("PSI_SHOW_PICKLIST_LANG") || (PSI_SHOW_PICKLIST_LANG !== false);
123
    }
124
 
125
    /**
126
     * get all available tamplates and store them in internal array
127
     *
128
     * @return void
129
     */
130
    private function _getTemplateList()
131
    {
132
        $dirlist = CommonFunctions::gdc(PSI_APP_ROOT.'/templates/');
133
        sort($dirlist);
134
        foreach ($dirlist as $file) {
135
            $tpl_ext = substr($file, strlen($file) - 4);
136
            $tpl_name = substr($file, 0, strlen($file) - 4);
137
            if ($tpl_ext === ".css") {
138
                if (preg_match("/(\S+)_bootstrap$/", $tpl_name, $ar_buf)) {
139
                    array_push($this->_bootstrap_templates, $ar_buf[1]);
140
                } else {
141
                    array_push($this->_templates, $tpl_name);
142
                }
143
            }
144
        }
145
    }
146
 
147
    /**
148
     * get all available translations and store them in internal array
149
     *
150
     * @return void
151
     */
152
    private function _getLanguageList()
153
    {
154
        $dirlist = CommonFunctions::gdc(PSI_APP_ROOT.'/language/');
155
        sort($dirlist);
156
        foreach ($dirlist as $file) {
157
            $lang_ext = strtolower(substr($file, strlen($file) - 4));
158
            $lang_name = strtolower(substr($file, 0, strlen($file) - 4));
159
            if ($lang_ext == ".xml") {
160
                array_push($this->_languages, $lang_name);
161
            }
162
        }
163
    }
164
 
165
    /**
166
     * render the page
167
     *
168
     * @return void
169
     */
170
    public function run()
171
    {
172
        $this->_checkTemplateLanguage();
173
 
174
        $tpl = new Template("/templates/html/index_".$this->_indexname.".html");
175
 
176
        $tpl->set("template", $this->_template);
177
        $tpl->set("templates", $this->_templates);
178
        $tpl->set("bootstraptemplate", $this->_bootstrap_template);
179
        $tpl->set("bootstraptemplates", $this->_bootstrap_templates);
180
        $tpl->set("picktemplate", $this->_pick_template);
181
        $tpl->set("language", $this->_language);
182
        $tpl->set("languages", $this->_languages);
183
        $tpl->set("picklanguage", $this->_pick_language);
184
        $tpl->set("showCPUListExpanded", defined('PSI_SHOW_CPULIST_EXPANDED') ? (PSI_SHOW_CPULIST_EXPANDED ? 'true' : 'false') : 'true');
185
        $tpl->set("showCPUInfoExpanded", defined('PSI_SHOW_CPUINFO_EXPANDED') ? (PSI_SHOW_CPUINFO_EXPANDED ? 'true' : 'false') : 'false');
186
        $tpl->set("showNetworkInfosExpanded", defined('PSI_SHOW_NETWORK_INFOS_EXPANDED') ? (PSI_SHOW_NETWORK_INFOS_EXPANDED ? 'true' : 'false') : 'false');
187
        $tpl->set("showMemoryInfosExpanded", defined('PSI_SHOW_MEMORY_INFOS_EXPANDED') ? (PSI_SHOW_MEMORY_INFOS_EXPANDED ? 'true' : 'false') : 'false');
188
        $tpl->set("showNetworkActiveSpeed", defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') ? (PSI_SHOW_NETWORK_ACTIVE_SPEED ? ((strtolower(PSI_SHOW_NETWORK_ACTIVE_SPEED) === 'bps') ? 'bps' :'true') : 'false') : 'false');
189
        $tpl->set("showCPULoadCompact", defined('PSI_LOAD_BAR') ? ((strtolower(PSI_LOAD_BAR) === 'compact') ? 'true' :'false') : 'false');
190
        $tpl->set("hideBootstrapLoader", defined('PSI_HIDE_BOOTSTRAP_LOADER') ? (PSI_HIDE_BOOTSTRAP_LOADER ? 'true' : 'false') : 'false');
191
        if (defined('PSI_BLOCKS')) {
192
            if (is_string(PSI_BLOCKS)) {
193
                if (preg_match(ARRAY_EXP, PSI_BLOCKS)) {
194
                    $blocks = eval(strtolower(PSI_BLOCKS));
195
                } else {
196
                    $blocks = array(strtolower(PSI_BLOCKS));
197
                }
198
                $blocklist = '';
199
                $validblocks = array('vitals','hardware','memory','filesystem','network','voltage','current','temperature','fans','power','other','ups');
200
                foreach ($blocks as $block) {
201
                    if (in_array($block, $validblocks)) {
202
                        if (empty($blocklist)) {
203
                            $blocklist = $block;
204
                        } else {
205
                            $blocklist .= ','.$block;
206
                        }
207
                    }
208
                }
209
                if (!empty($blocklist)) {
210
                    $tpl->set("blocks", $blocklist);
211
                }
212
            } elseif (PSI_BLOCKS) {
213
                $tpl->set("blocks", 'true');
214
            }
215
        } else {
216
            $tpl->set("blocks", 'true');
217
        }
218
 
219
        echo $tpl->fetch();
220
    }
221
}