Rev 45 | Rev 51 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
include_once( dirname(__FILE__) . '/../include/functions.php');
global $configuration;
$error = '';
$message = array();
$configStuff = loadConfig();
$configuration = $configStuff['configuration'];
$configPath = $configStuff['path'];
unset( $configStuff );
$message[] = "Reading from $configPath";
if ( ! $configuration ) {
$configuration = array(
'database' => array(
'dbserver' => '127.0.0.1',
'dbname' => 'camp2',
'dbusername' => 'camp2',
'dbpassword' => 'camp2'
),
'debug' => 0,
'locations' => array (
'base_url' => parentURL( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ),
'main_script' => 'index.php',
'config_dir' => '/var/www',
'include_dirs' => array (
'php_library_v2' => findFile( $_SERVER['DOCUMENT_ROOT'], 'DBQuery.class.php'), #'/var/www/php72/php_library_v2',
'php_users' => findFile( $_SERVER['DOCUMENT_ROOT'], 'UsersPermissions.class.php'), #'/var/www/php72/php_users',
'camp' => realpath( __DIR__ . '/../include' )
),
),
// fields for the Users class, adds where_clause, a TEXT object
// and super_admin, a boolean
'customUsersFields' => array(
'tables' => array(
'users' => array(
'fields' => array(
'super_admin' => array(
'label' => 'Super Admin',
'html type' => 'boolean',
'restrict' => true,
'instructions' => 'Check to allow permissions above even admin',
'hint' => 'User who can edit configs also',
'dbColumn' => 'superuser',
'type' => 'boolean',
'required' => false,
'default' => false
),
'where_clause' => array(
'label' => 'Limit via SQL where clause',
'html type' => 'textarea',
'restrict' => true,
'instructions' => 'This will be added to every SQL query to limit access, or 1=1 for everything',
'hint' => 'Enter an SQL where clause',
'dbColumn' => 'where_clause',
'type' => 'text',
'required' => false,
'default' => '1=1'
) // where_clause
) // fields
) // users
) // tables
) // customUsersFields
);
} // if there was no configuration file
if ( isset( $_REQUEST['writeconf'] ) ) {
//print "Ready to update configuration";
$configuration = updateConfig( $configuration );
$message[] = writeConfig( $configuration['locations']['config_dir'] );
}
function parentURL( $url, $numRemove = 2 ) {
$parts = explode( '/', $url );
while ( $numRemove-- )
array_pop( $parts ); // get rid of last one
return implode( '/', $parts );
}
function updateConfig ( $configuration ) {
foreach ( $configuration as $key => $value ) {
//print "Updating $key<br />";
if ( is_array( $value ) ) {
$configuration[$key] = updateConfig( $value );
} elseif ( is_scalar( $value ) && isset( $_REQUEST[$key] ) ) {
$configuration[$key] = $_REQUEST[$key];
}
}
return $configuration;
}
function writeConfig( $path ) {
global $configuration;
$path .= "/camp2_config.yaml";
//print "Writing to $path<br />";
if (yaml_emit_file( $path, $configuration ) ) {
return "Configuration saved to $path";
} else {
return "Error saving configuration to $path, check permissions";
}
}
function findFile( $root, $filename ) {
$it = new RecursiveDirectoryIterator( $root );
foreach ( new RecursiveIteratorIterator( $it ) as $file ) {
if ( preg_match( "^/$filename$^", $file ) ) {
return realpath( preg_replace( "^/$filename$^", '/', $file ) );;
}
}
}
?>
<html>
<head>
</head>
<body>
<div class='install'>
<div class='messages'>
<pre><?php //print_r( $_REQUEST ); ?></pre>
<?php print implode( "<br />\n", $message ); ?>
<p><a href='installer.php'>Done with Configuration</a></p>
</div>
<h1>Build/Edit Configuration</h1>
<form method='post'>
<h3>Database</h3>
<p>
<label>Database Name
<input type='text' name='dbname' value='<?php print $configuration['database']['dbname']; ?>'>
</label>
</p>
<p>
<label>Database Server
<input type='text' name='dbserver' value='<?php print $configuration['database']['dbserver']; ?>'>
</label>
</p>
<p>
<label>Database User
<input type='text' name='dbusername' value='<?php print $configuration['database']['dbusername']; ?>'>
</label>
</p>
<p>
<label>Database Password
<input type='text' name='dbpassword' value='<?php print $configuration['database']['dbpassword']; ?>'>
</label>
</p>
<h3>Locations</h3>
<p>
<label>Base URL
<input type='text' name='baseurl' value='<?php print $configuration['locations']['base_url']; ?>'>
</label>
</p>
<p>
<label>Main Script Name
<input type='text' name='main_script' value='<?php print $configuration['locations']['main_script']; ?>'>
</label>
</p>
<p>
<label>Config Directory
<input type='text' name='config_dir' value='<?php print $configuration['locations']['config_dir']; ?>'>
</label>
</p>
<p>
<label>PHP Library v2
<input type='text' name='php_library_v2' value='<?php print $configuration['locations']['include_dirs']['php_library_v2']; ?>'>
</label>
</p>
<p>
<label>PHP Users
<input type='text' name='php_users' value='<?php print $configuration['locations']['include_dirs']['php_users']; ?>'>
</label>
</p>
<h3>Other</h3>
<p>
<label>Debug Mode
<input type='checkbox' name='debug' <?php if ( $configuration['debug'] ) print 'checked'; ?>>
</label>
</p>
<input type='submit' name='writeconf' value='Save'>
</form>
</div>
<pre>
<?php //print_r( $configuration ); ?>
</pre>
</body>
</html>