index.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) Ubilling Development Team //
  4. // https://ubilling.net.ua //
  5. // //
  6. // This program is distributed in the hope that it will be useful, //
  7. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  9. // //
  10. // This product released under GNU General Public License v2 //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. /**
  13. * is Xhprof Hierarchical Profiler enabled?
  14. */
  15. $minimalBillingConfig = @parse_ini_file('config/billing.ini');
  16. if (@$minimalBillingConfig['XHPROF']) {
  17. define('XHPROF', 1);
  18. } else {
  19. define('XHPROF', 0);
  20. }
  21. if (XHPROF) {
  22. //xhprof installed?
  23. if (file_exists('modules/foreign/xhprof/xhprof_lib/utils/xhprof_lib.php')) {
  24. define("XHPROF_ROOT", __DIR__ . '/modules/foreign/xhprof');
  25. require_once (XHPROF_ROOT . '/xhprof_lib/utils/xhprof_lib.php');
  26. require_once (XHPROF_ROOT . '/xhprof_lib/utils/xhprof_runs.php');
  27. //append XHPROF_FLAGS_NO_BUILTINS if your PHP instance crashes
  28. xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
  29. }
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////
  32. // Initializations //
  33. ////////////////////////////////////////////////////////////////////////////////
  34. define('RCMS_ROOT_PATH', './');
  35. require_once(RCMS_ROOT_PATH . 'common.php');
  36. $menu_points = parse_ini_file(CONFIG_PATH . 'menus.ini', true);
  37. // Page gentime start
  38. $starttime = explode(' ', microtime());
  39. $starttime = $starttime[1] + $starttime[0];
  40. // Send main headers
  41. header('Last-Modified: ' . gmdate('r'));
  42. header('Content-Type: text/html; charset=' . $system->config['encoding']);
  43. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  44. header("Pragma: no-cache");
  45. /**
  46. * Maintance mode
  47. */
  48. if (file_exists('UPDATE')) {
  49. die('Ubilling maintance in progress');
  50. }
  51. /**
  52. * Stargazer PID control
  53. */
  54. $ubillingMainConf = parse_ini_file(CONFIG_PATH . 'billing.ini');
  55. if (isset($ubillingMainConf['NOSTGCHECKPID'])) {
  56. if ($ubillingMainConf['NOSTGCHECKPID']) {
  57. $checkStgPid = false;
  58. } else {
  59. $checkStgPid = true;
  60. }
  61. } else {
  62. $checkStgPid = true;
  63. }
  64. if ($checkStgPid) {
  65. $stgPidPath = $ubillingMainConf['STGPID'];
  66. if (!file_exists($stgPidPath)) {
  67. $stgPidAlert = __('Stargazer currently not running. We strongly advise against trying to use Ubilling in this case. If you are absolutely sure of what you are doing - you can turn off this alert with the option NOSTGCHECKPID');
  68. die($stgPidAlert);
  69. }
  70. }
  71. /**
  72. * IP ACL implementation
  73. */
  74. if (@$ubillingMainConf['IPACL_ENABLED']) {
  75. $ipAclAllowedIps = rcms_scandir(IPACLALLOWIP_PATH);
  76. $ipAclAllowedNets = rcms_scandir(IPACLALLOWNETS_PATH);
  77. //checks only if at least one ACL exists
  78. if (!empty($ipAclAllowedIps) OR ! empty($ipAclAllowedNets)) {
  79. $ipAclAllowedFlag = false;
  80. $ipAclAllowedIps = array_flip($ipAclAllowedIps);
  81. $ipAclRemoteIp = $_SERVER['REMOTE_ADDR'];
  82. //localhost is always allowed
  83. if ($ipAclRemoteIp != '127.0.0.1') {
  84. //checking is remote IP in allowed list
  85. if (isset($ipAclAllowedIps[$ipAclRemoteIp])) {
  86. $ipAclAllowedFlag = true;
  87. }
  88. } else {
  89. $ipAclAllowedFlag = true;
  90. }
  91. //if user IP isnt still allowed as-is - check on nets ACL
  92. if (!$ipAclAllowedFlag) {
  93. if (!empty($ipAclAllowedNets)) {
  94. foreach ($ipAclAllowedNets as $ipAclIndex => $ipAclNeteach) {
  95. $ipAclNetCidr = str_replace('_', '/', $ipAclNeteach);
  96. $ipAclNetParams = ipcidrToStartEndIP($ipAclNetCidr);
  97. if (multinet_checkIP($ipAclRemoteIp, $ipAclNetParams['startip'], $ipAclNetParams['endip'])) {
  98. $ipAclAllowedFlag = true;
  99. }
  100. }
  101. }
  102. }
  103. //Interrupt execution if remote user is not allowed explicitly
  104. if (!$ipAclAllowedFlag) {
  105. require_once(SKIN_PATH . 'acldenied.html');
  106. die();
  107. }
  108. }
  109. }
  110. // Loading main module
  111. $system->setCurrentPoint('__MAIN__');
  112. if (!empty($_GET['module']))
  113. $module = basename($_GET['module']);
  114. else
  115. $module = 'index';
  116. if (!empty($system->modules['main'][$module]))
  117. include_once(MODULES_PATH . $module . '/index.php');
  118. // Load menu modules
  119. include_once(CUR_SKIN_PATH . 'skin.php');
  120. if (!empty($menu_points)) {
  121. foreach ($menu_points as $point => $menus) {
  122. $system->setCurrentPoint($point);
  123. if (!empty($menus) && isset($skin['menu_point'][$point])) {
  124. foreach ($menus as $menu) {
  125. if (substr($menu, 0, 4) == 'ucm:' && is_readable(DF_PATH . substr($menu, 4) . '.ucm')) {
  126. $file = file(DF_PATH . substr($menu, 4) . '.ucm');
  127. $title = preg_replace("/[\n\r]+/", '', $file[0]);
  128. $align = preg_replace("/[\n\r]+/", '', $file[1]);
  129. unset($file[0]);
  130. unset($file[1]);
  131. show_window($title, implode('', $file), $align);
  132. } elseif (!empty($system->modules['menu'][$menu])) {
  133. $module = $menu;
  134. $module_dir = MODULES_PATH . $menu;
  135. require(MODULES_PATH . $menu . '/index.php');
  136. } else {
  137. show_window('', __('Module not found'), 'center');
  138. }
  139. }
  140. }
  141. }
  142. }
  143. if (XHPROF) {
  144. if (defined('XHPROF_ROOT')) {
  145. $xhprof_data = xhprof_disable();
  146. $xhprof_runs = new XHProfRuns_Default();
  147. $xhprof_run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_ubilling");
  148. $xhprof_content = '<iframe src="modules/foreign/xhprof/xhprof_html/index.php?run=' . $xhprof_run_id . '&source=xhprof_ubilling" width="100%" height="750"></iframe>';
  149. $xhprof_link = wf_modal(wf_img_sized('skins/xhprof.png', __('XHPROF'), 20), 'XHProf current page results', $xhprof_content, '', '1024', '768');
  150. } else {
  151. $xhprof_install_url = '?module=report_sysload&xhprofmoduleinstall=true';
  152. $xhprof_install_form = wf_AjaxLink($xhprof_install_url, wf_img('skins/icon_download.png') . ' ' . __('Download') . ' ' . __('XHProf'), 'xhprofinstall', true, 'ubButton');
  153. $xhprof_install_form .= wf_AjaxContainer('xhprofinstall');
  154. $xhprof_link = wf_modal(wf_img_sized('skins/xhprof.png', __('XHPROF'), 20), __('Download') . ' XHProf', $xhprof_install_form, '', '320', '200');
  155. }
  156. }
  157. // Start output
  158. require_once(CUR_SKIN_PATH . 'skin.general.php');
  159. //
  160. // Everything is better with unicorns
  161. //
  162. // _______\)%%%%%%%%._
  163. //`''''-'-; % % % % %'-._
  164. // :b) \ '-.
  165. // : :__)' .' .'
  166. // :.::/ '.' .'
  167. // o_i/ : ;
  168. // : .'
  169. // ''`
  170. // Glory to Ukraine!
  171. //