PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/options/oreon/modules/listModules.php

https://gitlab.com/florianocomercial/centreon
PHP | 260 lines | 154 code | 22 blank | 84 comment | 52 complexity | f360150793e64eb1df0a2528774c4792 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005-2015 Centreon
  4. * Centreon is developped by : Julien Mathis and Romain Le Merlus under
  5. * GPL Licence 2.0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License as published by the Free Software
  9. * Foundation ; either version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. * PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, see <http://www.gnu.org/licenses>.
  17. *
  18. * Linking this program statically or dynamically with other modules is making a
  19. * combined work based on this program. Thus, the terms and conditions of the GNU
  20. * General Public License cover the whole combination.
  21. *
  22. * As a special exception, the copyright holders of this program give Centreon
  23. * permission to link this program with independent modules to produce an executable,
  24. * regardless of the license terms of these independent modules, and to copy and
  25. * distribute the resulting executable under terms of Centreon choice, provided that
  26. * Centreon also meet, for each linked independent module, the terms and conditions
  27. * of the license of that module. An independent module is a module which is not
  28. * derived from this program. If you modify this program, you may extend this
  29. * exception to your version of the program, but you are not obliged to do so. If you
  30. * do not wish to do so, delete this exception statement from your version.
  31. *
  32. * For more information : contact@centreon.com
  33. *
  34. */
  35. if (!isset($centreon)) {
  36. exit();
  37. }
  38. /**
  39. * Parsing a Zend license file
  40. *
  41. * @param string $file The file name
  42. * @return array
  43. */
  44. function parse_zend_license_file($file) {
  45. $lines = preg_split('/\n/', file_get_contents($file));
  46. $infos = array();
  47. foreach ($lines as $line) {
  48. if (preg_match('/^([^= ]+)\s*=\s*(.+)$/', $line, $match)) {
  49. $infos[$match[1]] = $match[2];
  50. }
  51. }
  52. return $infos;
  53. }
  54. /*
  55. * Test Modules Existence for deletion
  56. */
  57. if ($id && $o == "d" && testModuleExistence($id)) {
  58. $moduleinfo = getModuleInfoInDB(NULL, $id);
  59. deleteModuleInDB($id);
  60. if ($moduleinfo["is_removeable"]) {
  61. /*
  62. * SQL deletion
  63. */
  64. $sql_file = "uninstall.sql";
  65. $sql_file_path = "./modules/".$moduleinfo["name"]."/sql/";
  66. if ($moduleinfo["sql_files"] && file_exists($sql_file_path.$sql_file))
  67. execute_sql_file($sql_file, $sql_file_path);
  68. /*
  69. * PHP deletion
  70. */
  71. $php_file = "uninstall.php";
  72. $php_file_path = "./modules/".$moduleinfo["name"]."/php/";
  73. if ($moduleinfo["php_files"] && file_exists($php_file_path.$php_file))
  74. include_once($php_file_path.$php_file);
  75. /*
  76. * SESSION deletion
  77. */
  78. if (isset($oreon->modules[$moduleinfo["name"]])) {
  79. unset($oreon->modules[$moduleinfo["name"]]);
  80. }
  81. }
  82. }
  83. /*
  84. * Smarty template Init
  85. */
  86. $tpl = new Smarty();
  87. $tpl = initSmartyTpl($path, $tpl);
  88. /*
  89. * start header menu
  90. */
  91. $tpl->assign("headerMenu_name", _("Name"));
  92. $tpl->assign("headerMenu_rname", _("Real name"));
  93. $tpl->assign("headerMenu_release", _("Release"));
  94. $tpl->assign("headerMenu_infos", _("Information"));
  95. $tpl->assign("headerMenu_moduleStatus", _("Status"));
  96. $tpl->assign("headerMenu_author", _("Author"));
  97. $tpl->assign("headerMenu_licenseExpire", _("Expiration date"));
  98. $tpl->assign("headerMenu_isinstalled", _("Installed"));
  99. $tpl->assign("headerMenu_action", _("Actions"));
  100. $tpl->assign("confirm_removing", _("Do you confirm the deletion ?"));
  101. /*
  102. * Different style between each lines
  103. */
  104. $style = "one";
  105. /*
  106. * Get Modules List
  107. */
  108. $handle = opendir("./modules/");
  109. /*
  110. * Fill a tab with a mutlidimensionnal Array we put in $tpl
  111. */
  112. $elemArr = array();
  113. $i = 0;
  114. while (false !== ($filename = readdir($handle))) {
  115. if (is_dir(_CENTREON_PATH_ . "www/modules/" . $filename) && $filename != "." && $filename != "..") {
  116. $moduleinfo = getModuleInfoInDB($filename, NULL);
  117. /*
  118. * Package already installed
  119. */
  120. if (isset($moduleinfo["rname"])) {
  121. if (function_exists('zend_loader_enabled') && file_exists(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl")) {
  122. if (zend_loader_file_encoded(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl")) {
  123. $zend_info = zend_loader_file_licensed(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl");
  124. } else {
  125. $zend_info = parse_zend_license_file(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl");
  126. }
  127. $license_expires = date("d/m/Y", strtotime($zend_info['Expires']));
  128. } else {
  129. $license_expires = "N/A";
  130. }
  131. $elemArr[$i] = array( "MenuClass" => "list_".$style,
  132. "RowMenu_name" => $moduleinfo["name"],
  133. "RowMenu_rname" => $moduleinfo["rname"],
  134. "RowMenu_release" => $moduleinfo["mod_release"],
  135. "RowMenu_infos" => $moduleinfo["infos"],
  136. "RowMenu_moduleId" => $moduleinfo["id"],
  137. "RowMenu_author" => $moduleinfo["author"],
  138. "RowMenu_licenseExpire" => $license_expires,
  139. "RowMenu_upgrade" => 0,
  140. "RowMenu_isinstalled" => _("Yes"),
  141. "RowMenu_link" => "?p=".$p."&o=w&id=".$moduleinfo["id"],
  142. "RowMenu_link_install" => NULL,
  143. "RowMenu_link_delete" => "?p=".$p."&o=w&id=".$moduleinfo["id"]."&o=d",
  144. "RowMenu_link_upgrade" => "?p=".$p."&o=w&id=".$moduleinfo["id"]."&o=u");
  145. /*
  146. * Check Update
  147. */
  148. $upgradeAvailable = false;
  149. if (!file_exists(_CENTREON_PATH_ . "www/modules/" . $filename . "/license"))
  150. $upgradeAvailable = true;
  151. else {
  152. if (function_exists('zend_loader_enabled') && file_exists(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl"))
  153. $upgradeAvailable = true;
  154. }
  155. if ($upgradeAvailable) {
  156. if (is_dir("./modules/".$moduleinfo["name"]."/UPGRADE")) {
  157. $handle2 = opendir("./modules/".$moduleinfo["name"]."/UPGRADE");
  158. while (false !== ($filename2 = readdir($handle2))) {
  159. if (substr($filename2, 0, 1) != "." && strstr($filename2, $moduleinfo["name"]."-") && file_exists("./modules/".$moduleinfo["name"]."/UPGRADE/".$filename2."/conf.php")) {
  160. @include_once("./modules/".$moduleinfo["name"]."/UPGRADE/".$filename2."/conf.php");
  161. if (isset($upgrade_conf[$moduleinfo["name"]]["release_from"]) && $moduleinfo["mod_release"] == $upgrade_conf[$moduleinfo["name"]]["release_from"]) {
  162. $elemArr[$i]["RowMenu_upgrade"] = 1;
  163. }
  164. }
  165. }
  166. closedir($handle2);
  167. }
  168. }
  169. } else {
  170. /*
  171. * Valid package to install
  172. */
  173. if (is_file(_CENTREON_PATH_ . "www/modules/".$filename."/conf.php")) {
  174. include_once(_CENTREON_PATH_ . "www/modules/".$filename."/conf.php");
  175. } else if (is_file(_CENTREON_PATH_ . "www/modules/".$filename."/.api/conf.php")) {
  176. include_once(_CENTREON_PATH_ . "www/modules/".$filename."/.api/conf.php");
  177. }
  178. if (isset($module_conf[$filename]["name"])) {
  179. $picturePath = "./img/icones/16x16/component_green.gif";
  180. if (file_exists(_CENTREON_PATH_ . "www/modules/".$filename."/icone.gif")) {
  181. $picturePath = "./modules/".$filename."/icone.gif";
  182. }
  183. if (file_exists(_CENTREON_PATH_ . "www/modules/".$filename."/.api/icone.gif")) {
  184. $picturePath = "./modules/".$filename."/.api/icone.gif";
  185. }
  186. if (function_exists('zend_loader_enabled') && file_exists(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl")) {
  187. if (zend_loader_file_encoded(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl")) {
  188. $zend_info = zend_loader_file_licensed(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl");
  189. } else {
  190. $zend_info = parse_zend_license_file(_CENTREON_PATH_ . "www/modules/" . $filename . "/license/merethis_lic.zl");
  191. }
  192. $license_expires = date("d/m/Y", strtotime($zend_info['Expires']));
  193. } else {
  194. $license_expires = "N/A";
  195. }
  196. $elemArr[$i] = array( "MenuClass" => "list_".$style,
  197. "RowMenu_name" => $module_conf[$filename]["name"],
  198. "RowMenu_rname" => $module_conf[$filename]["rname"],
  199. "RowMenu_release" => $module_conf[$filename]["mod_release"],
  200. "RowMenu_author" => $module_conf[$filename]["author"],
  201. "RowMenu_licenseExpire" => $license_expires,
  202. "RowMenu_infos" => (isset($module_conf[$filename]["infos"]) ? $module_conf[$filename]["infos"] : ""),
  203. "RowMenu_picture" => $picturePath,
  204. "RowMenu_isinstalled" => _("No"),
  205. "RowMenu_link" => "?p=".$p."&o=w&name=".$module_conf[$filename]["name"],
  206. "RowMenu_link_install" => "?p=".$p."&o=w&name=".$module_conf[$filename]["name"]."&o=i",
  207. "RowMenu_link_delete" => NULL,
  208. "RowMenu_link_upgrade" => NULL);
  209. } else {
  210. /*
  211. * Non valid package
  212. */
  213. $elemArr[$i] = array( "MenuClass" => "list_".$style,
  214. "RowMenu_name" => $filename,
  215. "RowMenu_rname" => _("NA"),
  216. "RowMenu_release" => _("NA"),
  217. "RowMenu_author" => _("NA"),
  218. "RowMenu_isinstalled" => _("Impossible"),
  219. "RowMenu_link" => NULL);
  220. }
  221. }
  222. $style != "two" ? $style = "two" : $style = "one";
  223. $i++;
  224. }
  225. }
  226. closedir($handle);
  227. /*
  228. * Init Template Var
  229. */
  230. $tpl->assign("elemArr", $elemArr);
  231. $tpl->assign("action_install", _("Install Module"));
  232. $tpl->assign("action_delete", _("Uninstall Module"));
  233. $tpl->assign("action_upgrade", _("Upgrade"));
  234. /*
  235. * Apply a template definition
  236. */
  237. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  238. $tpl->display("listModules.ihtml");