提交 83bb91e2 authored 作者: Raymond Chandler's avatar Raymond Chandler

added acl.conf

updated fs_configuration to allow fetching configs with no corresponding mod
updated index.php to return valid XML even when the XMLWriter class isn't available
added new tables to mysql schema

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/scripts/contrib@9178 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 c64c6842
<?php
/**
* @package FS_CURL
* @subpackage FS_CURL_Configuration
* acl.conf.php
*/
/**
* @package FS_CURL
* @subpackage FS_CURL_Configuration
* @license
* @author Raymond Chandler (intralanman) <intralanman@gmail.com>
* @version 0.1
* Class to write the XML for acl.conf
*/
class acl_conf extends fs_configuration {
public function acl_conf() {
$this -> fs_configuration();
}
public function main() {
$acl = $this -> get_acl();
$this -> write_acl($acl);
}
/**
* Write individual node elements with their attributes
*
* @param array $node_attributes
*/
private function write_node($node_attributes) {
$this -> xmlw -> startElement('node');
$this -> xmlw -> writeAttribute('type', $node_attributes['type']);
$this -> xmlw -> writeAttribute('cidr', $node_attributes['cidr']);
$this -> xmlw -> endElement();
}
/**
* Fetch the ACL data from the database
*
* @return array $acl_data
*/
private function get_acl() {
$query = sprintf(
'SELECT * FROM acl_lists al JOIN acl_nodes an ON an.list_id=al.id;'
);
$acl_data = $this -> db -> queryAll($query, null, MDB2_FETCHMODE_ASSOC);
if (MDB2::isError($profiles)) {
$this -> comment($query);
$this -> comment($acl_data -> getMessage());
return array();
}
return $acl_data;
}
/**
* Write ACL data out
*
* @param array $acl
*/
private function write_acl($acl) {
$this -> xmlw -> startElement('network-lists');
$node_count = count($acl);
for ($i=0; $i<$node_count; $i++) {
$last = $i - 1;
$next = $i + 1;
if ($last < 0 || $acl[$last]['acl_name'] != $acl[$i]['acl_name']) {
$this -> xmlw -> startElement('list');
$this -> xmlw -> writeAttribute('name', $acl[$i]['acl_name']);
$this -> xmlw -> writeAttribute(
'default', $acl[$i]['default_policy']
);
}
$this -> write_node($acl[$i]);
if ((!array_key_exists($next, $acl))
|| $acl[$next]['acl_name'] != $acl[$i]['acl_name']) {
$this -> xmlw -> endElement();
}
}
$this -> xmlw -> endElement();
}
}
?>
\ No newline at end of file
......@@ -27,8 +27,9 @@ class fs_configuration extends fs_curl {
$this -> fs_curl();
$mod_name = sprintf('mod_%s', str_replace('.conf', '', $this -> request['key_value']));
$this -> comment("module name is $mod_name");
if (!$this -> is_mod_enabled($mod_name)) {
$this -> comment('module not enabled');
if (!($this -> is_mod_enabled($mod_name))
&& !($this -> is_modless_conf($this -> request['key_value']))) {
$this -> comment('module not enabled and not modless config file');
$this -> file_not_found();
}
$this -> xmlw -> startElement('section');
......@@ -47,9 +48,6 @@ class fs_configuration extends fs_curl {
* @return bool
*/
function is_mod_enabled($mod_name) {
if ($mod_name == 'mod_post_load_modules') {
return true;
}
$query = sprintf('%s %s'
, "SELECT * FROM post_load_modules_conf"
, "WHERE module_name='$mod_name' AND load_module=1"
......@@ -60,13 +58,35 @@ class fs_configuration extends fs_curl {
$this -> comment($res -> getMessage());
return true; //default allow policy
return false; //comment previous line to default deny
$this -> file_not_found();
} elseif ($res -> numRows() == 1) {
return true;
} else {
return false;
}
}
/**
* Allow config files that aren't tied to any module
*
* @param string $conf
* @return bool
*/
private function is_modless_conf($conf) {
$this -> comment("conf is $conf");
$query = sprintf(
"SELECT COUNT(*) cnt FROM modless_conf WHERE conf_name = '$conf';"
);
$res = $this -> db -> query($query);
if (MDB2::isError($res)) {
$this -> comment($query);
$this -> comment($res -> getMessage());
return true; //default allow policy
return false; //comment previous line to default deny
}
$row = $res -> fetchRow();
//$this -> comment($row['cnt']);
return $row['cnt'];
}
}
?>
\ No newline at end of file
......@@ -16,7 +16,7 @@
*/
function file_not_found($no=false, $str=false, $file=false, $line=false) {
if ($no == E_STRICT) {
return;
return;
}
header('Content-Type: text/xml');
$xmlw = new XMLWriter();
......@@ -43,9 +43,17 @@ function file_not_found($no=false, $str=false, $file=false, $line=false) {
error_reporting(E_ALL);
set_error_handler('file_not_found');
if (!class_exists('XMLWriter')) {
trigger_error(
"XMLWriter Class NOT Found... You Must install it before using this package"
, E_USER_ERROR
);
}
if (!(@include_once('fs_curl.php'))
|| !(@include_once('global_defines.php'))) {
trigger_error('could not include fs_curl.php or global_defines.php');
trigger_error(
'could not include fs_curl.php or global_defines.php', E_USER_ERROR
);
}
if (!is_array($_REQUEST)) {
trigger_error('$_REQUEST is not an array');
......@@ -67,8 +75,7 @@ switch ($section) {
$processor = sprintf('configuration/%s.php', $config);
$class = str_replace('.', '_', $config);
if (!(@include_once($processor))) {
file_not_found();
exit();
trigger_error("unable to include $processor");
}
$conf = new $class;
$conf -> comment("class name is $class");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论