Code Search for Developers
 
 
  

config.php from freePBX at Krugle


Show config.php syntax highlighted

<?php /* $Id: config.php 4993 2007-09-02 22:07:42Z gregmac $ */
//Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

/* benchmark */
function microtime_float() { list($usec,$sec) = explode(' ',microtime()); return ((float)$usec+(float)$sec); }
$benchmark_starttime = microtime_float();
/*************/

$type = isset($_REQUEST['type'])?$_REQUEST['type']:'setup';
$display = isset($_REQUEST['display'])?$_REQUEST['display']:'';
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
$skip = isset($_REQUEST['skip'])?$_REQUEST['skip']:0;
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
$quietmode = isset($_REQUEST['quietmode'])?$_REQUEST['quietmode']:'';

// determine module type to show, default to 'setup'
$type_names = array(
	'tool'=>'Tools',
	'setup'=>'Setup',
	'cdrcost'=>'Call Cost',
);

include('header.php');

// handle special requests
if (isset($_REQUEST['handler'])) {
	switch ($_REQUEST['handler']) {
		case 'reload':
			/** AJAX handler for reload event
			 */
			include_once('common/json.inc.php');
			$response = do_reload();
			$json = new Services_JSON();
			echo $json->encode($response);
		break;
		case 'file':
			/** Handler to pass-through file requests 
			 * Looks for "module" and "file" variables, strips .. and only allows normal filename characters.
			 * Accepts only files of the type listed in $allowed_exts below, and sends the corresponding mime-type, 
			 * and always interprets files through the PHP interpreter. (Most of?) the freepbx environment is available,
			 * including $db and $astman, and the user is authenticated.
			 */
			if (!isset($_REQUEST['module']) || !isset($_REQUEST['file'])) {
				die_freepbx("unknown");
			}
			//TODO: this could probably be more efficient
			$module = str_replace('..','.', preg_replace('/[^a-zA-Z0-9-\_\.]/','',$_REQUEST['module']));
			$file = str_replace('..','.', preg_replace('/[^a-zA-Z0-9-\_\.]/','',$_REQUEST['file']));
			
			$allowed_exts = array(
				'.js' => 'text/javascript',
				'.js.php' => 'text/javascript',
				'.css' => 'text/css',
				'.css.php' => 'text/css',
				'.html.php' => 'text/html',
				'.jpg.php' => 'image/jpeg',
				'.jpeg.php' => 'image/jpeg',
				'.png.php' => 'image/png',
				'.gif.php' => 'image/gif',
			);
			foreach ($allowed_exts as $ext=>$mimetype) {
				if (substr($file, -1*strlen($ext)) == $ext) {
					$fullpath = 'modules/'.$module.'/'.$file;
					if (file_exists($fullpath)) {
						// file exists, and is allowed extension

						// image, css, js types - set Expires to an hour in advance so the client does
						// not keep checking for them. Replace from header.php
						if (!$amp_conf['DEVEL']) {
							@header('Expires: '.gmdate('D, d M Y H:i:s', time()+3600).' GMT', true);
							@header('Cache-Control: ',true); 
							@header('Pragma: ', true); 
						}
						@header("Content-type: ".$mimetype);
						include($fullpath);
						exit();
					}
					break;
				}
			}
			die_freepbx("not allowed");
		break;
	}
	exit();
}


module_run_notification_checks();

$framework_asterisk_running =  checkAstMan();

// get all enabled modules
// active_modules array used below and in drawselects function and genConf function
$active_modules = module_getinfo(false, MODULE_STATUS_ENABLED);

// initialize menu with module admin
$fpbx_menu = array(
	'modules1' => array('display'=>'modules', 'type'=>'tool', 'category' => 'Admin', 'name' => 'Module Admin', 'sort' => -9),
	'modules2' => array('display'=>'modules', 'type'=>'setup', 'category' => 'Admin', 'name' => 'Module Admin', 'sort' => -9),
);

// pointer to current item in $fpbx_menu, if applicable
$cur_menuitem = null;

// handler just to check hardcoded fpbx_menu items to see whats being displayed
//   For non-hardcoded modules we check this below while looping through $active_modules.
//   These are separate to avoid looping through $active_modules and then $fpbX_menu
foreach ($fpbx_menu as $itemKey => $item) {
	if ($item['display'] == $display) {
		$cur_menuitem =& $fpbx_menu[$itemKey];
	}
}

// include any module global functions
// add module sections to $fpbx_menu
$types = array();
if(is_array($active_modules)){
	foreach($active_modules as $key => $module) {
		//include module functions
		if (is_file("modules/{$key}/functions.inc.php")) {
			require_once("modules/{$key}/functions.inc.php");
		}
		
		//create an array of module sections to display
		// stored as [items][$type][$category][$name] = $displayvalue
		if (isset($module['items']) && is_array($module['items'])) {
			// loop through the types
			foreach($module['items'] as $itemKey => $item) {

				// check access, unless module.xml defines all have access
				if (!isset($item['access']) || strtolower($item['access']) != 'all') {
					if (!$_SESSION["AMP_user"]->checkSection($itemKey)) {
						// no access, skip to the next 
						continue;
					}
				}

				if (!$framework_asterisk_running && 
					  ((isset($item['needsenginedb']) && strtolower($item['needsenginedb'] == 'yes')) || 
					  (isset($item['needsenginerunning']) && strtolower($item['needsenginerunning'] == 'yes')))
				   )
				{
					$item['disabled'] = true;
				} else {
					$item['disabled'] = false;
				}

				if (!in_array($item['type'], $types)) {
					$types[] = $item['type'];
				}
				
				if (!isset($item['display'])) {
					$item['display'] = $itemKey;
				}
				
				// reference to the actual module
				$item['module'] =& $active_modules[$key];
				
				// item is an assoc array, with at least array(module=> name=>, category=>, type=>, display=>)
				$fpbx_menu[$itemKey] = $item;
				
				// allow a module to replace our main index page
				if (($item['display'] == 'index') && ($display == '')) {
					$display = 'index';
				}
				
				// check current item
				if ($display == $item['display']) {
					// found current menuitem, make a reference to it 
					$cur_menuitem =& $fpbx_menu[$itemKey];
				}
			}
		}
	}
}
sort($types);

// new gui hooks
if(is_array($active_modules)){
	foreach($active_modules as $key => $module) {
		if (isset($module['items']) && is_array($module['items'])) {
			foreach($module['items'] as $itemKey => $itemName) {
				//list of potential _configpageinit functions
				$initfuncname = $key . '_' . $itemKey . '_configpageinit';
				if ( function_exists($initfuncname) ) {
					$configpageinits[] = $initfuncname;
				}
			}
		}
		//check for module level (rather than item as above) _configpageinit function
		$initfuncname = $key . '_configpageinit';
		if ( function_exists($initfuncname) ) {
			$configpageinits[] = $initfuncname;
		}
	}
}

// extensions vs device/users ... this is a bad design, but hey, it works
if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) {
	unset($fpbx_menu["extensions"]);
} else {
	unset($fpbx_menu["devices"]);
	unset($fpbx_menu["users"]);
}

// check access
if (!is_array($cur_menuitem) && $display != "") {
	showview("noaccess");
	exit;
}

// load the component from the loaded modules
if ( $display != '' && isset($configpageinits) && is_array($configpageinits) ) {

	$currentcomponent = new component($display,$type);

	// call every modules _configpageinit function which should just
	// register the gui and process functions for each module, if relevent
	// for this $display
	foreach ($configpageinits as $func) {
		$func($display);
	}
	
	// now run each 'process' function and 'gui' function
	$currentcomponent->processconfigpage();
	$currentcomponent->buildconfigpage();
}

//  note: we buffer all the output from the 'page' being loaded..
// This may change in the future, with proper returns, but for now, it's a simple 
// way to support the old page.item.php include module format.

ob_start();

$module_name = "";
$module_page = "";
$module_file = "";

// show the appropriate page
switch($display) {
	default:
		//display the appropriate module page
		$module_name = $cur_menuitem['module']['rawname'];
		$module_page = $cur_menuitem['display'];
		$module_file = 'modules/'.$module_name.'/page.'.$module_page.'.php';

		//TODO Determine which item is this module displaying. Currently this is over the place, we should standarize on a "itemid" request var for now, we'll just cover all possibilities :-(
		$possibilites = array(
			'userdisplay',
			'extdisplay',
			'id',
			'itemid',
			'category',
			'selection'
		);
		$itemid = '';
		foreach($possibilites as $possibility) {
			if ( isset($_REQUEST[$possibility]) && $_REQUEST[$possibility] != '' ) 
				$itemid = $_REQUEST[$possibility];
		}

		// create a module_hook object for this module's page
		$module_hook = new moduleHook;
		
		// populate object variables
		$module_hook->install_hooks($module_page,$module_name,$itemid);

		// let hooking modules process the $_REQUEST
		$module_hook->process_hooks($itemid, $module_name, $module_page, $_REQUEST);


		// include the module page
		if (isset($cur_menuitem['disabled']) && $cur_menuitem['disabled']) {
			showview("menuitem_disabled",$cur_menuitem);
			break; // we break here to avoid the generateconfigpage() below
		} else if (file_exists($module_file)) {
			// load language info if available
			if (extension_loaded('gettext')) {
				if (is_dir("modules/{$module_name}/i18n")) {
					bindtextdomain($module_name,"modules/{$module_name}/i18n");
					bind_textdomain_codeset($module_name, 'utf8');
					textdomain($module_name);
				}
			}
			include($module_file);
		} else {
			// TODO: make this a showview()
			echo "404 Not found";
		}
		
		// global component
		if ( isset($currentcomponent) ) {
			echo $currentcomponent->generateconfigpage();
		}

	break;
	case 'modules':
		// set these to avoide undefined variable warnings later
		//
		$module_name = 'modules';
		$module_page = $cur_menuitem['display'];
		include 'page.modules.php';
	break;
	case '':
		if ($astman) {
			showview('welcome', array('AMP_CONF' => &$amp_conf));
		} else {
			// no manager, no connection to asterisk
			showview('welcome_nomanager', array('mgruser' => $amp_conf["AMPMGRUSER"]));
		}
	break;
}

if ($quietmode) {
	// send the output buffer
	@ob_end_flush();
} else {
	$admin_template = $template = array();
	$admin_template['content'] = ob_get_contents();
	@ob_end_clean();

	// build the admin interface (with menu)
	$admin_template['fpbx_types'] = $types;
	$admin_template['fpbx_type_names'] = $type_names;
	$admin_template['fpbx_menu'] = $fpbx_menu;
	$admin_template['fpbx_usecategories'] = $amp_conf['USECATEGORIES'];
	$admin_template['fpbx_type'] = $type;
	$admin_template['display'] = $display;

	// set the language so local module languages take
	set_language();

	// then load it and put it into the main freepbx interface
	$template['content'] = loadview('freepbx_admin', $admin_template);
	$template['use_nav_background'] = true;

	// setup main template
	$template['module_name'] = $module_name;
	$template['module_page'] = $module_page;
	$template['title'] = "FreePBX administration";
	$template['amp_conf'] = &$amp_conf;
	$template['reload_needed'] = check_reload_needed();
	$template['benchmark_starttime'] = $benchmark_starttime;

	showview('freepbx', $template);
}

?>




See more files for this project here

freePBX

FreePBX is the most powerful GUI (Web Based) configuration tool for Asterisk. It provides everything that a standard legacy phone system can, plus a huge amount of new features. All documentation and information is avalable from http://www.freepbx.org

Project homepage: http://sourceforge.net/projects/amportal
Programming language(s): PHP,Shell Script,SQL
License: other

  cdr/
    css/
      images/
        corner-bl.png
        corner-br.png
        corner-tl.png
        corner-tr.png
      content.css
      docbook.css
      layout.css
    images/
      asterisk.gif
      btn_top_12x12.gif
      button-search.gif
      call-compare.png
      call-logs.png
      excel.png
      fleche-d.gif
      fleche-g.gif
      header-download.png
      header-faq.png
      header-projects.png
      header-search.png
      icon_down_12x12.GIF
      icon_up_12x12.GIF
      jukebox_ti60.gif
      pdf.png
      print.css
      printable.png
      sidenav-selected.gif
      spacer.gif
      th_call-compare.png
      th_call-logs.png
    jpgraph_lib/
      imgdata_balls.inc
      imgdata_bevels.inc
      imgdata_diamonds.inc
      imgdata_pushpins.inc
      imgdata_squares.inc
      imgdata_stars.inc
      jpg-config.inc
      jpgraph.php
      jpgraph_antispam-digits.php
      jpgraph_antispam.php
      jpgraph_bar.php
      jpgraph_canvas.php
      jpgraph_canvtools.php
      jpgraph_error.php
      jpgraph_flags.php
      jpgraph_gantt.php
      jpgraph_gb2312.php
      jpgraph_gradient.php
      jpgraph_iconplot.php
      jpgraph_imgtrans.php
      jpgraph_line.php
      jpgraph_log.php
      jpgraph_pie.php
      jpgraph_pie3d.php
      jpgraph_plotband.php
      jpgraph_plotmark.inc
      jpgraph_polar.php
      jpgraph_radar.php
      jpgraph_regstat.php
      jpgraph_scatter.php
      jpgraph_stock.php
    lib/
      DB-modules/
      font/
      Class.Table.php
      defines.php
      fpdf.php
      iam_csvdump.php
    CHANGELOG.txt
    about.php
    call-comp.php
    call-daily-load.php
    call-last-month.php
    call-log.php
    cdr.php
    counter.txt
    encrypt.js
    export_csv.php
    export_pdf.php
    graph_hourdetail.php
    graph_pie.php
    graph_stat.php
    graph_statbar.php
    info.txt
  common/
    db_connect.php
    ie.css
    interface.dim.js
    jquery-1.1.3.1.js
    jquery.dimensions.js
    jquery.tabs-2.7.4.js
    json.inc.php
    libfreepbx.javascripts.js
    mainstyle-alternative.css
    mainstyle.css
    php-asmanager.php
    script.js.php
    script.legacy.js
    tabber-minimized.js
  i18n/
    de_DE/
    es_ES/
    fr_FR/
    he_IL/
    it_IT/
    pt_PT/
    ru_RU/
    readme.txt
  images/
    accept.png
    amp.png
    arrow_rotate_clockwise.png
    blank.gif
    cancel.png
    category1.png
    database_gear.png
    delete.gif
    freepbx.png
    freepbx_large.png
    freepbx_small.png
    header-back.png
    loading.gif
    logo.png
    modules-current1.png
    modules-hover1.png
    modules1.png
    scrolldown.gif
    scrollup.gif
    shadow-corner.png
    shadow-side-background.png
    shadow-side.png
    shadow-top.png
    tab-first-current.png
    tab-first.png
    tab-hover.png
    tab-select.png
    tab.png
    trash.png
    watermark.png
  modules/
    _cache/
    .htaccess
    import.sh
    modlist.sh
    remove.sh
    status.sh
    update.sh
  views/
    freepbx.php
    freepbx_admin.php
    freepbx_reload.php
    freepbx_reloadbar.php
    loggedout.php
    menuitem_disabled.php
    noaccess.php
    panel.php
    reports.php
    unauthorized.php
    welcome.php
    welcome_nomanager.php
  components.class.php
  config.php
  extensions.class.php
  favicon.ico
  featurecodes.class.php
  functions.inc.php
  header.php
  header_auth.php
  index.php
  page.modules.php
  panel.php
  reports.php