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