| 45 |
rodolico |
1 |
<?php
|
| 46 |
rodolico |
2 |
include_once( dirname(__FILE__) . '/../include/functions.php');
|
|
|
3 |
global $configuration;
|
|
|
4 |
$error = '';
|
|
|
5 |
$message = array();
|
|
|
6 |
|
|
|
7 |
$configStuff = loadConfig();
|
|
|
8 |
$configuration = $configStuff['configuration'];
|
|
|
9 |
$configPath = $configStuff['path'];
|
|
|
10 |
unset( $configStuff );
|
|
|
11 |
$message[] = "Reading from $configPath";
|
| 51 |
rodolico |
12 |
include_once( 'users_table.php' );
|
| 46 |
rodolico |
13 |
|
|
|
14 |
if ( ! $configuration ) {
|
|
|
15 |
$configuration = array(
|
|
|
16 |
'database' => array(
|
|
|
17 |
'dbserver' => '127.0.0.1',
|
|
|
18 |
'dbname' => 'camp2',
|
|
|
19 |
'dbusername' => 'camp2',
|
|
|
20 |
'dbpassword' => 'camp2'
|
|
|
21 |
),
|
|
|
22 |
'debug' => 0,
|
| 61 |
rodolico |
23 |
'session' => array(
|
|
|
24 |
'save_path'=> '/var/www/sessions',
|
|
|
25 |
'gc_maxlifetime'=> 57600,
|
|
|
26 |
'cookie_lifetime'=> 57600,
|
|
|
27 |
'cache_expire'=> 960,
|
|
|
28 |
'name'=> 'camp2'
|
|
|
29 |
),
|
| 46 |
rodolico |
30 |
'locations' => array (
|
|
|
31 |
'base_url' => parentURL( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ),
|
|
|
32 |
'main_script' => 'index.php',
|
|
|
33 |
'config_dir' => '/var/www',
|
|
|
34 |
'include_dirs' => array (
|
|
|
35 |
'php_library_v2' => findFile( $_SERVER['DOCUMENT_ROOT'], 'DBQuery.class.php'), #'/var/www/php72/php_library_v2',
|
|
|
36 |
'php_users' => findFile( $_SERVER['DOCUMENT_ROOT'], 'UsersPermissions.class.php'), #'/var/www/php72/php_users',
|
|
|
37 |
'camp' => realpath( __DIR__ . '/../include' )
|
|
|
38 |
),
|
| 45 |
rodolico |
39 |
),
|
| 46 |
rodolico |
40 |
// fields for the Users class, adds where_clause, a TEXT object
|
|
|
41 |
// and super_admin, a boolean
|
| 45 |
rodolico |
42 |
);
|
| 51 |
rodolico |
43 |
$configuration['customUsersFields'] = $customFields;
|
| 46 |
rodolico |
44 |
} // if there was no configuration file
|
|
|
45 |
|
|
|
46 |
if ( isset( $_REQUEST['writeconf'] ) ) {
|
|
|
47 |
//print "Ready to update configuration";
|
|
|
48 |
$configuration = updateConfig( $configuration );
|
|
|
49 |
$message[] = writeConfig( $configuration['locations']['config_dir'] );
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
function parentURL( $url, $numRemove = 2 ) {
|
|
|
53 |
$parts = explode( '/', $url );
|
|
|
54 |
while ( $numRemove-- )
|
|
|
55 |
array_pop( $parts ); // get rid of last one
|
|
|
56 |
return implode( '/', $parts );
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
function updateConfig ( $configuration ) {
|
|
|
60 |
foreach ( $configuration as $key => $value ) {
|
|
|
61 |
//print "Updating $key<br />";
|
|
|
62 |
if ( is_array( $value ) ) {
|
|
|
63 |
$configuration[$key] = updateConfig( $value );
|
|
|
64 |
} elseif ( is_scalar( $value ) && isset( $_REQUEST[$key] ) ) {
|
|
|
65 |
$configuration[$key] = $_REQUEST[$key];
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
return $configuration;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
function writeConfig( $path ) {
|
|
|
73 |
global $configuration;
|
|
|
74 |
|
|
|
75 |
$path .= "/camp2_config.yaml";
|
|
|
76 |
//print "Writing to $path<br />";
|
|
|
77 |
if (yaml_emit_file( $path, $configuration ) ) {
|
|
|
78 |
return "Configuration saved to $path";
|
|
|
79 |
} else {
|
|
|
80 |
return "Error saving configuration to $path, check permissions";
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
function findFile( $root, $filename ) {
|
|
|
85 |
$it = new RecursiveDirectoryIterator( $root );
|
|
|
86 |
foreach ( new RecursiveIteratorIterator( $it ) as $file ) {
|
|
|
87 |
if ( preg_match( "^/$filename$^", $file ) ) {
|
|
|
88 |
return realpath( preg_replace( "^/$filename$^", '/', $file ) );;
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
| 45 |
rodolico |
93 |
?>
|
|
|
94 |
<html>
|
|
|
95 |
<head>
|
|
|
96 |
</head>
|
|
|
97 |
<body>
|
|
|
98 |
<div class='install'>
|
| 46 |
rodolico |
99 |
<div class='messages'>
|
|
|
100 |
<pre><?php //print_r( $_REQUEST ); ?></pre>
|
|
|
101 |
<?php print implode( "<br />\n", $message ); ?>
|
|
|
102 |
<p><a href='installer.php'>Done with Configuration</a></p>
|
|
|
103 |
</div>
|
| 45 |
rodolico |
104 |
<h1>Build/Edit Configuration</h1>
|
| 46 |
rodolico |
105 |
<form method='post'>
|
| 45 |
rodolico |
106 |
<h3>Database</h3>
|
|
|
107 |
<p>
|
|
|
108 |
<label>Database Name
|
| 46 |
rodolico |
109 |
<input type='text' name='dbname' value='<?php print $configuration['database']['dbname']; ?>'>
|
| 45 |
rodolico |
110 |
</label>
|
|
|
111 |
</p>
|
|
|
112 |
<p>
|
|
|
113 |
<label>Database Server
|
| 46 |
rodolico |
114 |
<input type='text' name='dbserver' value='<?php print $configuration['database']['dbserver']; ?>'>
|
| 45 |
rodolico |
115 |
</label>
|
|
|
116 |
</p>
|
|
|
117 |
<p>
|
|
|
118 |
<label>Database User
|
| 46 |
rodolico |
119 |
<input type='text' name='dbusername' value='<?php print $configuration['database']['dbusername']; ?>'>
|
| 45 |
rodolico |
120 |
</label>
|
|
|
121 |
</p>
|
|
|
122 |
<p>
|
|
|
123 |
<label>Database Password
|
| 46 |
rodolico |
124 |
<input type='text' name='dbpassword' value='<?php print $configuration['database']['dbpassword']; ?>'>
|
| 45 |
rodolico |
125 |
</label>
|
|
|
126 |
</p>
|
| 61 |
rodolico |
127 |
<h3>Session Control</h3>
|
|
|
128 |
<p>
|
|
|
129 |
<label>Session Path
|
|
|
130 |
<input type='text' name='save_path' value='<?php print $configuration['sessions']['save_path']; ?>'>
|
|
|
131 |
</label>
|
|
|
132 |
</p>
|
|
|
133 |
<p>
|
|
|
134 |
<label>gc_maxlifetime
|
|
|
135 |
<input type='text' name='gc_maxlifetime' value='<?php print $configuration['sessions']['gc_maxlifetime']; ?>'>
|
|
|
136 |
</label>
|
|
|
137 |
</p>
|
|
|
138 |
<p>
|
|
|
139 |
<label>Cookie Lifetime (seconds)
|
|
|
140 |
<input type='text' name='cookie_lifetime' value='<?php print $configuration['sessions']['cookie_lifetime']; ?>'>
|
|
|
141 |
</label>
|
|
|
142 |
</p>
|
|
|
143 |
<p>
|
|
|
144 |
<label>Cache Expire (minutes)
|
|
|
145 |
<input type='text' name='cache_expire' value='<?php print $configuration['sessions']['cache_expire']; ?>'>
|
|
|
146 |
</label>
|
|
|
147 |
</p>
|
|
|
148 |
<p>
|
|
|
149 |
<label>Session Name
|
|
|
150 |
<input type='text' name='name' value='<?php print $configuration['sessions']['name']; ?>'>
|
|
|
151 |
</label>
|
|
|
152 |
</p>
|
| 45 |
rodolico |
153 |
<h3>Locations</h3>
|
|
|
154 |
<p>
|
|
|
155 |
<label>Base URL
|
| 46 |
rodolico |
156 |
<input type='text' name='baseurl' value='<?php print $configuration['locations']['base_url']; ?>'>
|
| 45 |
rodolico |
157 |
</label>
|
|
|
158 |
</p>
|
|
|
159 |
<p>
|
|
|
160 |
<label>Main Script Name
|
| 46 |
rodolico |
161 |
<input type='text' name='main_script' value='<?php print $configuration['locations']['main_script']; ?>'>
|
| 45 |
rodolico |
162 |
</label>
|
|
|
163 |
</p>
|
|
|
164 |
<p>
|
|
|
165 |
<label>Config Directory
|
| 46 |
rodolico |
166 |
<input type='text' name='config_dir' value='<?php print $configuration['locations']['config_dir']; ?>'>
|
| 45 |
rodolico |
167 |
</label>
|
|
|
168 |
</p>
|
|
|
169 |
<p>
|
|
|
170 |
<label>PHP Library v2
|
| 46 |
rodolico |
171 |
<input type='text' name='php_library_v2' value='<?php print $configuration['locations']['include_dirs']['php_library_v2']; ?>'>
|
| 45 |
rodolico |
172 |
</label>
|
|
|
173 |
</p>
|
|
|
174 |
<p>
|
|
|
175 |
<label>PHP Users
|
| 46 |
rodolico |
176 |
<input type='text' name='php_users' value='<?php print $configuration['locations']['include_dirs']['php_users']; ?>'>
|
| 45 |
rodolico |
177 |
</label>
|
|
|
178 |
</p>
|
|
|
179 |
<h3>Other</h3>
|
|
|
180 |
<p>
|
|
|
181 |
<label>Debug Mode
|
| 46 |
rodolico |
182 |
<input type='checkbox' name='debug' <?php if ( $configuration['debug'] ) print 'checked'; ?>>
|
| 45 |
rodolico |
183 |
</label>
|
|
|
184 |
</p>
|
|
|
185 |
|
| 46 |
rodolico |
186 |
<input type='submit' name='writeconf' value='Save'>
|
| 45 |
rodolico |
187 |
</form>
|
|
|
188 |
</div>
|
| 46 |
rodolico |
189 |
<pre>
|
|
|
190 |
<?php //print_r( $configuration ); ?>
|
|
|
191 |
</pre>
|
| 45 |
rodolico |
192 |
</body>
|
|
|
193 |
</html>
|