PageRenderTime 27ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/share/pnp/application/controllers/system.php

https://github.com/CoolCold/pnp4nagios
PHP | 219 lines | 186 code | 13 blank | 20 comment | 30 complexity | 52bb5bac375d73e51baf0cd8132f1e53 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2. /**
  3. * system controller.
  4. *
  5. * @package pnp4nagios
  6. * @author Joerg Linge
  7. * @license GPL
  8. */
  9. class System_Controller extends Template_Controller {
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. $this->data = new Data_Model();
  14. $this->config = new Config_Model();
  15. $this->rrdtool = new Rrdtool_Model();
  16. $this->auth = new Auth_Model();
  17. #$this->system = new System_Model();
  18. $this->config->read_config();
  19. Kohana::config_set('locale.language',$this->config->conf['lang']);
  20. // Check for mod_rewrite
  21. $this->check_mod_rewrite();
  22. $this->start = $this->input->get('start',FALSE);
  23. $this->end = $this->input->get('end',FALSE);
  24. $this->theme = $this->input->get('theme',FALSE);
  25. $this->view = "";
  26. $this->host = $this->input->get('host',NULL);
  27. $this->service = $this->input->get('srv',NULL);
  28. $this->controller = Router::$controller;
  29. if($this->host != NULL){
  30. $this->host = urldecode($this->host);
  31. }
  32. if($this->service != NULL){
  33. $this->service = urldecode($this->service);
  34. }
  35. if(isset($_GET['view']) && $_GET['view'] != "" )
  36. $this->view = pnp::clean($_GET['view']);
  37. $this->data->getTimeRange($this->start,$this->end,$this->view);
  38. if(Router::$controller != "image" && Router::$controller != "image_special"){
  39. $this->session = Session::instance();
  40. # Session withou theme info
  41. if($this->session->get("theme","new") == "new"){
  42. if($this->theme){
  43. # store $this->theme if available
  44. Kohana::config_set('core.theme',$this->theme);
  45. $this->session->set('theme', $this->theme );
  46. }else{
  47. # set $this->theme to default value
  48. $this->theme = $this->config->conf['ui-theme'];
  49. Kohana::config_set('core.theme',$this->theme);
  50. }
  51. # Sesion with theme info
  52. }else{
  53. if($this->theme && $this->theme != 'default'){
  54. # store $this->theme if available
  55. $this->session->set('theme', $this->theme );
  56. Kohana::config_set('core.theme',$this->theme);
  57. }elseif($this->theme == 'default'){
  58. # reset to default theme
  59. $this->theme = $this->config->conf['ui-theme'];
  60. $this->session->set('theme', $this->theme );
  61. Kohana::config_set('core.theme',$this->theme);
  62. }else{
  63. # set $this->theme with session infos
  64. $this->theme = $this->session->get('theme');
  65. Kohana::config_set('core.theme',$this->theme);
  66. }
  67. }
  68. if($this->start && $this->end ){
  69. if($this->session->get('timerange-reset',0) == 0){
  70. $this->session->set("start", $this->start);
  71. $this->session->set("end", $this->end);
  72. }else{
  73. $this->session->set('timerange-reset', 0);
  74. }
  75. }
  76. if($this->start && !$this->end){
  77. if($this->session->get('timerange-reset',0) == 0){
  78. $this->session->set("start", $this->start);
  79. $this->session->set("end", "");
  80. }else{
  81. $this->session->set('timerange-reset', 0);
  82. }
  83. }
  84. if($this->end && !$this->start){
  85. if($this->session->get('timerange-reset',0) == 0){
  86. $this->session->set("end", $this->end);
  87. $this->session->set("start", "");
  88. }else{
  89. $this->session->set('timerange-reset', 0);
  90. }
  91. }
  92. }
  93. }
  94. public function __call($method, $arguments)
  95. {
  96. // Disable auto-rendering
  97. $this->auto_render = FALSE;
  98. // By defining a __call method, all pages routed to this controller
  99. // that result in 404 errors will be handled by this method, instead of
  100. // being displayed as "Page Not Found" errors.
  101. echo $this->_("The requested page doesn't exist") . " ($method)";
  102. }
  103. /**
  104. * Handle paths to current theme etc
  105. *
  106. */
  107. public function add_view($view=false)
  108. {
  109. $view = trim($view);
  110. if (empty($view)) {
  111. return false;
  112. }
  113. if (!file_exists(APPPATH."/views/".$view.".php")) {
  114. return false;
  115. }
  116. #return new View($this->theme_path.$view);
  117. return new View($view);
  118. }
  119. public function check_mod_rewrite(){
  120. if(!function_exists('apache_get_modules')){
  121. // Add index.php to every URL while not running withn apache mod_php
  122. Kohana::config_set('core.index_page','index.php');
  123. return TRUE;
  124. }
  125. if(!in_array('mod_rewrite', apache_get_modules())){
  126. // Add index.php to every URL while mod_rewrite is not available
  127. Kohana::config_set('core.index_page','index.php');
  128. }
  129. if ( $this->config->conf['use_url_rewriting'] == 0 ){
  130. Kohana::config_set('core.index_page','index.php');
  131. }
  132. }
  133. public function isAuthorizedFor($auth) {
  134. $conf = $this->config->conf;
  135. if ($auth == "service_links") {
  136. $users = explode(",", $conf['allowed_for_service_links']);
  137. if (in_array('EVERYONE', $users)) {
  138. return 1;
  139. }
  140. elseif (in_array('NONE', $users)) {
  141. return 0;
  142. }
  143. elseif (in_array($_SERVER["REMOTE_USER"], $users)) {
  144. return 1;
  145. } else {
  146. return 0;
  147. }
  148. }
  149. if ($auth == "host_search") {
  150. $users = explode(",", $conf['allowed_for_host_search']);
  151. if (in_array('EVERYONE', $users)) {
  152. return 1;
  153. }
  154. elseif (in_array('NONE', $users)) {
  155. return 0;
  156. }
  157. elseif (in_array($_SERVER["REMOTE_USER"], $users)) {
  158. return 1;
  159. } else {
  160. return 0;
  161. }
  162. }
  163. if ($auth == "host_overview") {
  164. $users = explode(",", $conf['allowed_for_host_overview']);
  165. if (in_array('EVERYONE', $users)) {
  166. return 1;
  167. }
  168. elseif (in_array('NONE', $users)) {
  169. return 0;
  170. }
  171. elseif (in_array($_SERVER["REMOTE_USER"], $users)) {
  172. return 1;
  173. } else {
  174. return 0;
  175. }
  176. }
  177. if ($auth == "pages") {
  178. $users = explode(",", $conf['allowed_for_pages']);
  179. if (in_array('EVERYONE', $users)) {
  180. return 1;
  181. }
  182. elseif (in_array('NONE', $users)) {
  183. return 0;
  184. }
  185. elseif (in_array($_SERVER["REMOTE_USER"], $users)) {
  186. return 1;
  187. } else {
  188. return 0;
  189. }
  190. }
  191. }
  192. public function isMobileDevice (){
  193. if( $this->session->get('classic-ui',0) == 1){
  194. return FALSE;
  195. }
  196. if ( preg_match('/'.$this->config->conf['mobile_devices'].'/', $_SERVER['HTTP_USER_AGENT'] ) ){
  197. return TRUE;
  198. }else{
  199. return FALSE;
  200. }
  201. }
  202. }