Skip to content

Commit

Permalink
git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97…
Browse files Browse the repository at this point in the history
…f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Jun 25, 2006
1 parent 0d0f76b commit b7f7d10
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 167 deletions.
25 changes: 13 additions & 12 deletions admin/Makefile.am
@@ -1,18 +1,19 @@
## Cherokee: cherokee/Makefile.am -*- makefile -*-

cherokeeadmindir = "$(prefix)/share/cherokee/admin/"
cherokeeadmin_DATA = \
index.php \
common.php \
config_node.php \
server.php \
page.php \
page_index.php \
page_debug.php \
widget.php \
widget_debug.php \
widget_prop_table.php \
theme.php \
cherokeeadmin_DATA = \
index.php \
common.php \
config_node.php \
server.php \
page.php \
page_index.php \
page_debug.php \
widget.php \
widget_debug.php \
widget_prop_table.php \
widget_vsrvs_table.php \
theme.php \
check.php

EXTRA_DIST = \
Expand Down
42 changes: 35 additions & 7 deletions admin/check.php
Expand Up @@ -25,7 +25,8 @@
require_once ('common.php');


function check_is_int ($i) {
function check_is_int ($i)
{
if (!is_numeric ($i))
return 'Non numeric';

Expand All @@ -39,7 +40,8 @@ function check_is_int ($i) {
return NULL;
}

function fix_bool ($b) {
function fix_bool ($b)
{
$lb = strtolower($b);

if (($lb == 'on') || ($lb == 'true'))
Expand All @@ -51,7 +53,8 @@ function fix_bool ($b) {
return (int)$b;
}

function check_is_bool ($b) {
function check_is_bool ($b)
{
$lb = strtolower($b);

if (($lb == 'on') or ($lb == 'true') or
Expand All @@ -64,7 +67,8 @@ function check_is_bool ($b) {
return "Wrong value";
}

function check_is_ipv4 ($ip) {
function check_is_ipv4 ($ip)
{
$oct = explode('.', $ip);
if (count($oct) != 4) {
return "Bad formated";
Expand All @@ -83,19 +87,22 @@ function check_is_ipv4 ($ip) {
return NULL;
}

function check_is_ipv6 ($ip) {
function check_is_ipv6 ($ip)
{
return NULL;
}

function check_is_ip ($ip) {
function check_is_ip ($ip)
{
$colon = strchr ($ip, ':');
if ($colon != FALSE)
return check_is_ipv6($ip);

return check_is_ipv4($ip);
}

function check_is_path ($path) {
function check_is_path ($path)
{
if (is_windows()) {
// TODO
return "Windows: unsupported";
Expand All @@ -107,4 +114,25 @@ function check_is_path ($path) {
return NULL;
}

function check_nil ($param)
{
return NULL;
}

function check_file_list ($l)
{
if (empty($l))
return NULL;

$parts = preg_split ('/ *\, */', $l);

foreach ($parts as $part) {
$re = preg_match ('/[a-zA-Z0-9\.\_\-]+/', $part);
if (!$re)
return "Invalid: ".$part;
}

return NULL;
}

?>
89 changes: 60 additions & 29 deletions admin/config_node.php
Expand Up @@ -31,40 +31,53 @@ function ConfigNode() {
$this->value = NULL;
}

function ParseLine ($line) {
/* Split left and right sides
*/
list($left, $right) = explode(' = ', $line);
function &_CreatePath ($path) {
$subconf =& $this;

/* Get the first element
*/
$sep = strchr ($left, '!');
for (;;) {
/* Get the first element
*/
$sep = strchr ($path, '!');

/* Intermediate node
*/
if (empty($sep)) {
$first = $left;
$rest = '';
} else {
$first = substr ($left, 0, strlen($left) - strlen($sep));
$rest = substr ($line, strlen($first) + 1, strlen($line)-(strlen($first)+1));
/* Intermediate node
*/
if (empty($sep)) {
$first = $path;
$rest = '';
} else {
$first = substr ($path, 0, strlen($path) - strlen($sep));
$rest = substr ($path, strlen($first) + 1, strlen($path)-(strlen($first)+1));
}

/* Create a new node
*/
if (! array_key_exists ($first, $subconf->child)) {
$subconf->child[$first] =& new ConfigNode;
}

$child =& $subconf->child;
$subconf =& $child[$first];

if (empty($rest))
return $subconf;

$path = $rest;
}
}

/* Create a new node
function ParseLine ($line) {
/* Split left and right sides
*/
if (! array_key_exists ($first, $this->child)) {
$this->child[$first] =& new ConfigNode;
}
list($left, $right) = explode(' = ', $line);

$child =& $this->child;
$subconf =& $child[$first];
$subconf = $this->_CreatePath ($left);
if ($subconf == NULL) return ret_error;

/* Configure it
/* Assign the value
*/
if (! empty($rest))
$subconf->ParseLine ($rest);
else
if (!empty ($right)) {
$subconf->value = $right;
}

return ret_ok;
}
Expand Down Expand Up @@ -234,13 +247,31 @@ function FindValue ($path)
return $re->value;
}

function SetValue ($path, $value, $create=0)
function AddPath ($path) {
$this->_CreatePath ($path);
}

function SetValue ($path, $value, $create=false)
{
/* Look for the entry
*/
$entry =& $this->Find ($path);

if ($entry == NULL)
return "Node not found";
if ($entry == NULL) {
/* There is no such element
*/
if (! $create)
return "Node not found: ".$path;

/* Add a new config node
*/
$entry = $this->_CreatePath ($path);

if ($entry == NULL)
return "Could not create: ".$path;
}

/* Fill it out
*/
$entry->value = $value;
return NULL;
}
Expand Down
19 changes: 15 additions & 4 deletions admin/index.php
Expand Up @@ -27,6 +27,7 @@
require_once ('config_node.php');
require_once ('page_index.php');
require_once ('page_debug.php');
require_once ('page_vserver.php');


function &read_configuration () {
Expand All @@ -46,18 +47,28 @@ function &instance_page (&$theme, &$conf) {
$params = $_REQUEST;

unset ($params['page']);
$ajax = $params['ajax'];

switch ($name) {
case 'debug':
$page =& new PageDebug(&$theme, $conf, $params);
break;
case 'restart':
$server =& new Server ($conf);
$conf->Save (cherokee_default_config_file);
$server->SendHUP();
break;

case 'debug':
$page =& new PageDebug(&$theme, $conf, $params);
break;

case 'vserver':
if (!empty($ajax))
$page =& new PageVserverAjax ($conf, $params);
else
$page =& new PageVServer(&$theme, $conf, $params);
break;

default:
if (!empty($params['ajax']))
if (!empty($ajax))
$page =& new PageIndexAjax ($conf, $params);
else
$page =& new PageIndex ($theme, $conf, $params);
Expand Down

0 comments on commit b7f7d10

Please sign in to comment.