Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
14 KiB

2 years ago
2 years ago
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. //set variables if not set
  25. //if (!isset($_SESSION["template_content"])) { $_SESSION["template_content"] = null; }
  26. if (!isset($document)) { $document = null; }
  27. if (!isset($v_menu)) { $v_menu = null; }
  28. if (!isset($_SESSION["menu"])) { $_SESSION["menu"] = null; }
  29. if (!isset($_SESSION["username"])) { $_SESSION["username"] = null; }
  30. //get the output from the buffer
  31. $body = $content_from_db.ob_get_contents();
  32. ob_end_clean(); //clean the buffer
  33. //clear the template
  34. //if (isset($_SESSION['theme']['cache']['boolean']) && $_SESSION['theme']['cache']['boolean'] == "false") {
  35. // $_SESSION["template_content"] = '';
  36. //}
  37. //set a default template
  38. if (strlen($_SESSION["template_full_path"]) == 0) { //build template if session template has no length
  39. $template_base_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
  40. if (strlen($template_rss_sub_category) > 0) {
  41. //this template was assigned by the content manager
  42. //get the contents of the template and save it to the template variable
  43. $template_full_path = $template_base_path.'/'.$template_rss_sub_category.'/template.php';
  44. if (!file_exists($template_full_path)) {
  45. $_SESSION['domain']['template']['name'] = 'default';
  46. $template_full_path = $template_base_path.'/default/template.php';
  47. }
  48. $_SESSION["template_full_path"] = $template_full_path;
  49. }
  50. else {
  51. //get the contents of the template and save it to the template variable
  52. $template_full_path = $template_base_path.'/'.$_SESSION['domain']['template']['name'].'/template.php';
  53. if (!file_exists($template_full_path)) {
  54. $_SESSION['domain']['template']['name'] = 'default';
  55. $template_full_path = $template_base_path.'/default/template.php';
  56. }
  57. $_SESSION["template_full_path"] = $template_full_path;
  58. }
  59. }
  60. //initialize a template object
  61. $view = new template();
  62. $view->engine = 'smarty';
  63. $view->template_dir = $_SERVER['DOCUMENT_ROOT'].PROJECT_PATH.'/themes/'.$_SESSION['domain']['template']['name'].'/';
  64. $view->cache_dir = $_SESSION['server']['temp']['dir'] ?: sys_get_temp_dir();
  65. $view->init();
  66. //add multi-lingual support
  67. $language = new text;
  68. $text_default = $language->get();
  69. $text_application = $language->get(null,'themes/'.$_SESSION['domain']['template']['name']);
  70. $text = array_merge($text_default, $text_application);
  71. //set template variables
  72. //add translations
  73. foreach($text as $key => $value) {
  74. $array[str_replace('-', '_', $key)] = $value;
  75. }
  76. $view->assign('text', $array);
  77. //project path
  78. $view->assign('project_path', PROJECT_PATH);
  79. //domain menu
  80. $view->assign('domain_menu', escape($_SESSION['domain']['menu']['uuid']));
  81. //theme settings
  82. if (is_array($_SESSION['theme']) && @sizeof($_SESSION['theme']) != 0) {
  83. //load into array
  84. foreach ($_SESSION['theme'] as $subcategory => $setting) {
  85. switch($subcategory) {
  86. //exceptions
  87. case 'favicon':
  88. case 'custom_css':
  89. if ($setting['text'] != '') {
  90. $tmp_url = parse_url($setting['text']);
  91. $tmp_path = pathinfo($setting['text']);
  92. if (
  93. is_array($tmp_url) && @sizeof($tmp_url) != 0 &&
  94. is_array($tmp_path) && @sizeof($tmp_path) != 0 &&
  95. (
  96. ($tmp_url['scheme'] != '' && $tmp_url['scheme'].'://'.$tmp_url['host'].$tmp_url['path'] == $tmp_path['dirname'].'/'.$tmp_path['filename'].'.'.$tmp_path['extension']) //is url
  97. || $tmp_url['path'] == $tmp_path['dirname'].'/'.$tmp_path['filename'].'.'.$tmp_path['extension'] //is path
  98. )) {
  99. $settings['theme'][$subcategory] = $setting['text'];
  100. }
  101. unset($tmp_url, $tmp_path);
  102. }
  103. break;
  104. //otherwise
  105. default:
  106. if (isset($setting['text']) && $setting['text'] != '') {
  107. $settings['theme'][$subcategory] = str_replace('&lowbar;','_',escape($setting['text']));
  108. }
  109. else if (isset($setting['numeric']) && is_numeric($setting['numeric'])) {
  110. $settings['theme'][$subcategory] = $setting['numeric'];
  111. }
  112. else if (isset($setting['boolean'])) {
  113. $settings['theme'][$subcategory] = $setting['boolean'] == 'true' ? true : false;
  114. }
  115. else {
  116. $settings['theme'][$subcategory] = escape($setting);
  117. }
  118. }
  119. }
  120. //pre-process some settings
  121. $settings['theme']['favicon'] = $settings['theme']['favicon'] != '' ? $settings['theme']['favicon'] : PROJECT_PATH.'/themes/default/favicon.ico';
  122. $settings['theme']['font_loader_version'] = $settings['theme']['font_loader_version'] != '' ? urlencode($settings['theme']['font_loader_version']) : '1';
  123. $settings['theme']['message_delay'] = is_numeric($settings['theme']['message_delay']) ? 1000 * (float) $settings['theme']['message_delay'] : 3000;
  124. $settings['theme']['menu_side_width_contracted'] = is_numeric($settings['theme']['menu_side_width_contracted']) ? $settings['theme']['menu_side_width_contracted'] : '60';
  125. $settings['theme']['menu_side_width_expanded'] = is_numeric($settings['theme']['menu_side_width_expanded']) ? $settings['theme']['menu_side_width_expanded'] : '225';
  126. $settings['theme']['menu_side_toggle_hover_delay_expand'] = is_numeric($settings['theme']['menu_side_toggle_hover_delay_expand']) ? $settings['theme']['menu_side_toggle_hover_delay_expand'] : '300';
  127. $settings['theme']['menu_side_toggle_hover_delay_contract'] = is_numeric($settings['theme']['menu_side_toggle_hover_delay_contract']) ? $settings['theme']['menu_side_toggle_hover_delay_contract'] : '1000';
  128. $settings['theme']['menu_style'] = $settings['theme']['menu_style'] != '' ? $settings['theme']['menu_style'] : 'fixed';
  129. $settings['theme']['menu_position'] = $settings['theme']['menu_position'] != '' ? $settings['theme']['menu_position'] : 'top';
  130. $settings['theme']['footer'] = $settings['theme']['footer'] != '' ? $settings['theme']['footer'] :"<p>FusionPBX-LDAP made by crt @ <a href='https://512mb.org' class='footer' target='_blank'>512mb.org</a> </p> <p>512mb, Very little storage indeed!</p> ";
  131. $view->assign('settings', $settings);
  132. }
  133. //document title
  134. if (isset($_SESSION['theme']['title']['text']) && $_SESSION['theme']['title']['text'] != '') {
  135. $document_title = $_SESSION['theme']['title']['text'];
  136. }
  137. else if (isset($_SESSION['software_name'])) {
  138. $document_title = $_SESSION['software_name'];
  139. }
  140. $document_title = ($document['title'] != '' ? $document['title'].' - ' : null).$document_title;
  141. $view->assign('document_title', $document_title);
  142. //domain selector control
  143. $domain_selector_enabled = permission_exists('domain_select') && count($_SESSION['domains']) > 1 ? true : false;
  144. $view->assign('domain_selector_enabled', $domain_selector_enabled);
  145. //browser name
  146. $user_agent = http_user_agent();
  147. $browser_version = $user_agent['version'];
  148. $view->assign('browser_name', $user_agent['name']);
  149. $view->assign('browser_name_short', $user_agent['name_short']);
  150. //login state
  151. $authenticated = isset($_SESSION['username']) && $_SESSION['username'] != '' ? true : false;
  152. $view->assign('authenticated', $authenticated);
  153. //domains application path
  154. $view->assign('domains_app_path', PROJECT_PATH.(file_exists($_SERVER['DOCUMENT_ROOT'].'/app/domains/domains.php') ? '/app/domains/domains.php' : '/core/domains/domains.php'));
  155. //domain count
  156. $view->assign('domain_count', is_array($_SESSION['domains']) ? sizeof($_SESSION['domains']) : 0);
  157. //domain selector row background colors
  158. $view->assign('domain_selector_background_color_1', $_SESSION['theme']['domain_inactive_background_color'][0] != '' ? $_SESSION['theme']['domain_inactive_background_color'][0] : '#eaedf2');
  159. $view->assign('domain_selector_background_color_2', $_SESSION['theme']['domain_inactive_background_color'][1] != '' ? $_SESSION['theme']['domain_inactive_background_color'][1] : '#ffffff');
  160. $view->assign('domain_active_background_color', $_SESSION['theme']['domain_active_background_color']['text'] != '' ? $_SESSION['theme']['domain_active_background_color']['text'] : '#eeffee');
  161. //domain list
  162. $view->assign('domains', $_SESSION['domains']);
  163. //domain uuid
  164. $view->assign('domain_uuid', $_SESSION['domain_uuid']);
  165. //menu container
  166. //load menu array into the session
  167. if (!isset($_SESSION['menu']['array'])) {
  168. $menu = new menu;
  169. $menu->menu_uuid = $_SESSION['domain']['menu']['uuid'];
  170. $_SESSION['menu']['array'] = $menu->menu_array();
  171. unset($menu);
  172. }
  173. //build menu by style
  174. switch ($_SESSION['theme']['menu_style']['text']) {
  175. case 'side':
  176. $view->assign('menu_side_state', (isset($_SESSION['theme']['menu_side_state']['text']) && $_SESSION['theme']['menu_side_state']['text'] != '' ? $_SESSION['theme']['menu_side_state']['text'] : 'expanded'));
  177. if ($_SESSION['theme']['menu_side_state']['text'] != 'hidden') {
  178. $menu_side_toggle = $_SESSION['theme']['menu_side_toggle']['text'] == 'hover' ? " onmouseenter=\"clearTimeout(menu_side_contract_timer); if ($('#menu_side_container').width() < 100) { menu_side_expand_start(); }\" onmouseleave=\"clearTimeout(menu_side_expand_timer); if ($('#menu_side_container').width() > 100 && $('#menu_side_state_current').val() != 'expanded') { menu_side_contract_start(); }\"" : null;
  179. }
  180. $container_open = "<div id='menu_side_container' ".($_SESSION['theme']['menu_side_state']['text'] == 'hidden' ? "style='display: none;'" : "class='hide-xs'").$menu_side_toggle." >\n";
  181. $menu = new menu;
  182. $menu->text = $text;
  183. $menu_html = $menu->menu_vertical($_SESSION['menu']['array']);
  184. unset($menu);
  185. break;
  186. case 'inline':
  187. $container_open = "<div class='container-fluid' style='padding: 0;' align='".($_SESSION['theme']['logo_align']['text'] != '' ? $_SESSION['theme']['logo_align']['text'] : 'left')."'>\n";
  188. if ($_SERVER['PHP_SELF'] != PROJECT_PATH.'/core/install/install.php') {
  189. $logo = "<a href='".PROJECT_PATH."/'><img src='".($_SESSION['theme']['logo']['text'] ?: PROJECT_PATH.'/themes/default/images/logo.png')."' style='padding: 15px 20px; ".($_SESSION['theme']['logo_style']['text'] ?: null)."'></a>";
  190. }
  191. $menu = new menu;
  192. $menu->text = $text;
  193. $menu_html = $menu->menu_horizontal($_SESSION['menu']['array']);
  194. unset($menu);
  195. break;
  196. case 'static':
  197. $container_open = "<div class='container-fluid' style='padding: 0;' align='center'>\n";
  198. $menu = new menu;
  199. $menu->text = $text;
  200. $menu_html = $menu->menu_horizontal($_SESSION['menu']['array']);
  201. unset($menu);
  202. break;
  203. case 'fixed':
  204. default:
  205. $menu = new menu;
  206. $menu->text = $text;
  207. $menu_html = $menu->menu_horizontal($_SESSION['menu']['array']);
  208. unset($menu);
  209. $container_open = "<div class='container-fluid' style='padding: 0;' align='center'>\n";
  210. break;
  211. }
  212. $view->assign('logo', $logo);
  213. $view->assign('menu', $menu_html);
  214. $view->assign('container_open', $container_open);
  215. $view->assign('container_close', '</div>');
  216. $view->assign('document_body', $body);
  217. $view->assign('current_year', date('Y'));
  218. //login logo
  219. //determine logo source
  220. if (isset($_SESSION['theme']['logo_login']['text']) && $_SESSION['theme']['logo_login']['text'] != '') {
  221. $login_logo_source = $_SESSION['theme']['logo_login']['text'];
  222. }
  223. else if (isset($_SESSION['theme']['logo']['text']) && $_SESSION['theme']['logo']['text'] != '') {
  224. $login_logo_source = $_SESSION['theme']['logo']['text'];
  225. }
  226. else {
  227. $login_logo_source = PROJECT_PATH.'/themes/default/images/logo_login.png';
  228. }
  229. //determine logo dimensions
  230. if (isset($_SESSION['theme']['login_logo_width']['text']) && $_SESSION['theme']['login_logo_width']['text'] != '') {
  231. $login_logo_width = $_SESSION['theme']['login_logo_width']['text'];
  232. }
  233. else {
  234. $login_logo_width = 'auto; max-width: 300px';
  235. }
  236. if (isset($_SESSION['theme']['login_logo_height']['text']) && $_SESSION['theme']['login_logo_height']['text'] != '') {
  237. $login_logo_height = $_SESSION['theme']['login_logo_height']['text'];
  238. }
  239. else {
  240. $login_logo_height = 'auto; max-height: 300px';
  241. }
  242. $view->assign('login_logo_source', $login_logo_source);
  243. $view->assign('login_logo_width', $login_logo_width);
  244. $view->assign('login_logo_height', $login_logo_height);
  245. //login page
  246. $view->assign('login_page', $login_page);
  247. //messages
  248. $view->assign('messages', message::html(true, ' '));
  249. //session timer
  250. if (
  251. $authenticated &&
  252. file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH.'/app/session_timer/session_timer.php') &&
  253. $_SESSION['security']['session_timer_enabled']['boolean'] == 'true'
  254. ) {
  255. include_once PROJECT_PATH.'app/session_timer/session_timer.php';
  256. $view->assign('session_timer', $session_timer);
  257. }
  258. //render the view
  259. $output = $view->render('template.php');
  260. //unset background image
  261. unset($_SESSION['background_image']);
  262. //send the output to the browser
  263. echo $output;
  264. unset($output);
  265. //$statsauth = "a3az349x2bf3fdfa8dbt7x34fas5X";
  266. //require_once "stats/stat_sadd.php";
  267. ?>