This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
117 lines (101 loc) · 3.19 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
$rewrite = array(
'bootstrap' => array(
'default'=>'./app/bootstrap.default.php',
'custom' =>'./app/bootstrap.php',
'fields'=>array("baseurl", "environment"),
),
'htaccess' => array(
'default' => './public/default.htaccess',
'custom' => './public/.htaccess',
'fields' => array('baseurl'),
),
'database' => array(
'default' => './app/config/database.default.php',
'custom' => './app/config/database.php',
'fields' => array("hostname", "database", "username", "password"),
),
);
$store = array("store"=>array("custom"=>"./custom_settings.json"));
$proceed = true;
$suggest = array();
foreach(array_merge($rewrite, $store) as $name => $config){
if(!is_writable($config['custom'])){
print "Configuration file ". $config['custom'] ." is not writable!<br />";
$suggest[] = "touch ".$config['custom']." && chmod o+w ".$config['custom']."\n";
$proceed = false;
}
}
if(!$proceed) die("You need to fix these permissions first before we can proceed. Try: <pre>".implode('', $suggest)."</pre>");
if(isset($_POST['install']) || !empty($_SERVER['SHELL']))
{
if(!empty($_SERVER['SHELL']))
echo "Working...\n";
foreach($rewrite as $name => $config){
if(!file_exists($config['default'])) die("Default config for $config not found");
$file = file_get_contents($config['default']);
foreach($config['fields'] as $key){
$file = str_replace(":$key", value($name, $key), $file);
}
file_put_contents($config['custom'], $file);
}
if(!empty($_SERVER['SHELL']))
echo "Updating tables...\n";
// Prevent executing route
$_SERVER['installing'] = true;
include 'public/index.php';
Controller_Install::update_tables();
if(!empty($_SERVER['SHELL']))
die("Customized your installation. Happy developing!\n");
}
/*if(isset($_POST['file'])){
$f = realpath($_POST['file']);
$t = realpath(dirname(__FILE__));
if(strpos($f, $t) != 0) die('0');
echo (file_exists($_POST['file']) ? '1' : '0');
}*/
function load(){
global $config_loaded;
if($config_loaded) return $config_loaded;
else {
$f = @file_get_contents('custom_settings.json');
if(!$f) return $config_loaded = (object) array();
else return $config_loaded = json_decode($f);
}
}
function value($name, $key){
$config = load();
// Make config
if(!isset($config->$name)) $config->$name = (object) array();
// Return POST
if(isset($_POST[$name][$key])){
$config->$name->$key = $_POST[$name][$key];
file_put_contents('custom_settings.json', json_encode($config));
}
// Return saved
return isset($config->$name->$key) ? $config->$name->$key : '';
}
/// OUTPUT
if(!empty($_SERVER['SHELL'])){
echo "To install the app, please enter the following details in json format in custom_settings.json: \n";
foreach($rewrite as $name => $config){
foreach($config['fields'] as $key){
echo $name."[$key]: $key\n";
}
}
exit;
}
?>
<h1>Install</h1>
<form method="post"><table>
<?php
foreach($rewrite as $name => $config){
echo "<tr><th colspan=2><h2>$name</h2></th></tr>";
foreach($config['fields'] as $key){
echo "<tr><th>$key</th><td><input type='text' name='".$name."[$key]' value='".value($name, $key)."' /></td></tr>";
}
}
?></table>
<input type='hidden' name='install' value='1'>
<input type='submit' value='Install' />
</form>