1 |
<?php
|
1 |
<?php
|
2 |
/**
|
2 |
/**
|
3 |
* Basic Plugin Functions
|
3 |
* Basic Plugin Functions
|
4 |
*
|
4 |
*
|
5 |
* PHP version 5
|
5 |
* PHP version 5
|
6 |
*
|
6 |
*
|
7 |
* @category PHP
|
7 |
* @category PHP
|
8 |
* @package PSI_Plugin
|
8 |
* @package PSI_Plugin
|
9 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
9 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
10 |
* @copyright 2009 phpSysInfo
|
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
|
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.PSI_Plugin.inc.php 661 2012-08-27 11:26:39Z namiltd $
|
12 |
* @version SVN: $Id: class.PSI_Plugin.inc.php 661 2012-08-27 11:26:39Z namiltd $
|
13 |
* @link http://phpsysinfo.sourceforge.net
|
13 |
* @link http://phpsysinfo.sourceforge.net
|
14 |
*/
|
14 |
*/
|
15 |
/**
|
15 |
/**
|
16 |
* basic functions to get a plugin working in phpSysinfo
|
16 |
* basic functions to get a plugin working in phpSysinfo
|
17 |
* every plugin must implement this abstract class to be a valid plugin, main tasks
|
17 |
* every plugin must implement this abstract class to be a valid plugin, main tasks
|
18 |
* of this class are reading the configuration file and check for the required files
|
18 |
* of this class are reading the configuration file and check for the required files
|
19 |
* (*.js, lang/en.xml) to get everything working, if we have errors here we log them
|
19 |
* (*.js, lang/en.xml) to get everything working, if we have errors here we log them
|
20 |
* to our global error object
|
20 |
* to our global error object
|
21 |
*
|
21 |
*
|
22 |
* @category PHP
|
22 |
* @category PHP
|
23 |
* @package PSI_Plugin
|
23 |
* @package PSI_Plugin
|
24 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
24 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
25 |
* @copyright 2009 phpSysInfo
|
25 |
* @copyright 2009 phpSysInfo
|
26 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
26 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
27 |
* @version Release: 3.0
|
27 |
* @version Release: 3.0
|
28 |
* @link http://phpsysinfo.sourceforge.net
|
28 |
* @link http://phpsysinfo.sourceforge.net
|
29 |
*/
|
29 |
*/
|
30 |
abstract class PSI_Plugin implements PSI_Interface_Plugin
|
30 |
abstract class PSI_Plugin implements PSI_Interface_Plugin
|
31 |
{
|
31 |
{
|
32 |
/**
|
32 |
/**
|
33 |
* name of the plugin (classname)
|
33 |
* name of the plugin (classname)
|
34 |
*
|
34 |
*
|
35 |
* @var string
|
35 |
* @var string
|
36 |
*/
|
36 |
*/
|
37 |
private $_plugin_name = "";
|
37 |
private $_plugin_name = "";
|
38 |
|
38 |
|
39 |
/**
|
39 |
/**
|
40 |
* full directory path of the plugin
|
40 |
* full directory path of the plugin
|
41 |
*
|
41 |
*
|
42 |
* @var string
|
42 |
* @var string
|
43 |
*/
|
43 |
*/
|
44 |
private $_plugin_base = "";
|
44 |
private $_plugin_base = "";
|
45 |
|
45 |
|
46 |
/**
|
46 |
/**
|
47 |
* global object for error handling
|
47 |
* global object for error handling
|
48 |
*
|
48 |
*
|
49 |
* @var Error
|
49 |
* @var Error
|
50 |
*/
|
50 |
*/
|
51 |
protected $global_error = "";
|
51 |
protected $global_error = "";
|
52 |
|
52 |
|
53 |
/**
|
53 |
/**
|
54 |
* xml tamplate with header
|
54 |
* xml tamplate with header
|
55 |
*
|
55 |
*
|
56 |
* @var SimpleXMLExtended
|
56 |
* @var SimpleXMLExtended
|
57 |
*/
|
57 |
*/
|
58 |
protected $xml;
|
58 |
protected $xml;
|
59 |
|
59 |
|
60 |
/**
|
60 |
/**
|
61 |
* build the global Error object, read the configuration and check if all files are available
|
61 |
* build the global Error object, read the configuration and check if all files are available
|
62 |
* for a minimalistic function of the plugin
|
62 |
* for a minimalistic function of the plugin
|
63 |
*
|
63 |
*
|
64 |
* @param string $plugin_name name of the plugin
|
64 |
* @param string $plugin_name name of the plugin
|
65 |
* @param string $enc target encoding
|
65 |
* @param string $enc target encoding
|
66 |
* @return void
|
66 |
* @return void
|
67 |
*/
|
67 |
*/
|
68 |
public function __construct($plugin_name, $enc)
|
68 |
public function __construct($plugin_name, $enc)
|
69 |
{
|
69 |
{
|
70 |
$this->global_error = PSI_Error::Singleton();
|
70 |
$this->global_error = PSI_Error::Singleton();
|
71 |
if (trim($plugin_name) != "") {
|
71 |
if (trim($plugin_name) != "") {
|
72 |
$this->_plugin_name = $plugin_name;
|
72 |
$this->_plugin_name = $plugin_name;
|
73 |
$this->_plugin_base = PSI_APP_ROOT."/plugins/".strtolower($this->_plugin_name)."/";
|
73 |
$this->_plugin_base = PSI_APP_ROOT."/plugins/".strtolower($this->_plugin_name)."/";
|
74 |
$this->_checkfiles();
|
74 |
$this->_checkfiles();
|
75 |
$this->_getconfig();
|
75 |
$this->_getconfig();
|
76 |
} else {
|
76 |
} else {
|
77 |
$this->global_error->addError("__construct()", "Parent constructor called without Plugin-Name!");
|
77 |
$this->global_error->addError("__construct()", "Parent constructor called without Plugin-Name!");
|
78 |
}
|
78 |
}
|
79 |
$this->_createXml($enc);
|
79 |
$this->_createXml($enc);
|
80 |
}
|
80 |
}
|
81 |
|
81 |
|
82 |
/**
|
82 |
/**
|
83 |
* read the plugin configuration file, if we have one in the plugin directory
|
83 |
* read the plugin configuration file, if we have one in the plugin directory
|
84 |
*
|
84 |
*
|
85 |
* @return void
|
85 |
* @return void
|
86 |
*/
|
86 |
*/
|
87 |
private function _getconfig()
|
87 |
private function _getconfig()
|
88 |
{
|
88 |
{
|
- |
|
89 |
if ((strtoupper($this->_plugin_name) !== 'DISKLOAD') &&
|
89 |
if ((!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
|
90 |
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
|
90 |
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE')) &&
|
91 |
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE')) &&
|
91 |
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SHOW_SERIAL'))) {
|
92 |
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SHOW_SERIAL'))) {
|
92 |
$this->global_error->addError("phpsysinfo.ini", "Config for plugin ".$this->_plugin_name." not exist!");
|
93 |
$this->global_error->addError("phpsysinfo.ini", "Config for plugin ".$this->_plugin_name." not exist!");
|
93 |
}
|
94 |
}
|
94 |
}
|
95 |
}
|
95 |
|
96 |
|
96 |
/**
|
97 |
/**
|
97 |
* check if there is a default translation file availabe and also the required js file for
|
98 |
* check if there is a default translation file availabe and also the required js file for
|
98 |
* appending the content of the plugin to the main webpage
|
99 |
* appending the content of the plugin to the main webpage
|
99 |
*
|
100 |
*
|
100 |
* @return void
|
101 |
* @return void
|
101 |
*/
|
102 |
*/
|
102 |
private function _checkfiles()
|
103 |
private function _checkfiles()
|
103 |
{
|
104 |
{
|
104 |
if (!file_exists($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
|
105 |
if (!file_exists($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
|
105 |
$this->global_error->addError("file_exists(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is missing!");
|
106 |
$this->global_error->addError("file_exists(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is missing!");
|
106 |
} else {
|
107 |
} else {
|
107 |
if (!is_readable($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
|
108 |
if (!is_readable($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
|
108 |
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is not readable but present!");
|
109 |
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is not readable but present!");
|
109 |
}
|
110 |
}
|
110 |
}
|
111 |
}
|
111 |
if (!file_exists($this->_plugin_base."lang/en.xml")) {
|
112 |
if (!file_exists($this->_plugin_base."lang/en.xml")) {
|
112 |
$this->global_error->addError("file_exists(".$this->_plugin_base."lang/en.xml)", "At least an english translation must exist for the plugin!");
|
113 |
$this->global_error->addError("file_exists(".$this->_plugin_base."lang/en.xml)", "At least an english translation must exist for the plugin!");
|
113 |
} else {
|
114 |
} else {
|
114 |
if (!is_readable($this->_plugin_base."lang/en.xml")) {
|
115 |
if (!is_readable($this->_plugin_base."lang/en.xml")) {
|
115 |
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".$this->_plugin_name.".js)", "The english translation can't be read but is present!");
|
116 |
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".$this->_plugin_name.".js)", "The english translation can't be read but is present!");
|
116 |
}
|
117 |
}
|
117 |
}
|
118 |
}
|
118 |
}
|
119 |
}
|
119 |
|
120 |
|
120 |
/**
|
121 |
/**
|
121 |
* create the xml template where plugin information are added to
|
122 |
* create the xml template where plugin information are added to
|
122 |
*
|
123 |
*
|
123 |
* @param string $enc target encoding
|
124 |
* @param string $enc target encoding
|
124 |
*
|
125 |
*
|
125 |
* @return void
|
126 |
* @return void
|
126 |
*/
|
127 |
*/
|
127 |
private function _createXml($enc)
|
128 |
private function _createXml($enc)
|
128 |
{
|
129 |
{
|
129 |
$dom = new DOMDocument('1.0', 'UTF-8');
|
130 |
$dom = new DOMDocument('1.0', 'UTF-8');
|
130 |
$root = $dom->createElement("Plugin_".$this->_plugin_name);
|
131 |
$root = $dom->createElement("Plugin_".$this->_plugin_name);
|
131 |
$dom->appendChild($root);
|
132 |
$dom->appendChild($root);
|
132 |
$this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
|
133 |
$this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
|
133 |
$plugname = strtoupper($this->_plugin_name);
|
134 |
$plugname = strtoupper($this->_plugin_name);
|
134 |
if (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) &&
|
135 |
if ((PSI_OS == 'Linux') && defined('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME') &&
|
- |
|
136 |
(!defined('PSI_SSH_HOSTNAME') || (PSI_SSH_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SSH_HOSTNAME')))) {
|
- |
|
137 |
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SSH_HOSTNAME'));
|
135 |
defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME') &&
|
138 |
} elseif (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) && defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME') &&
|
136 |
(!defined('PSI_WMI_HOSTNAME') || (PSI_WMI_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME')))) {
|
139 |
(!defined('PSI_WMI_HOSTNAME') || (PSI_WMI_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME')))) {
|
137 |
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME'));
|
140 |
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME'));
|
138 |
}
|
141 |
}
|
139 |
}
|
142 |
}
|
140 |
}
|
143 |
}
|
141 |
|
144 |
|