/
regsetup.php
executable file
·188 lines (156 loc) · 6.77 KB
/
regsetup.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?
require_once('core/kregistry.class.php');
//--------------------------------------------------------------------------------------------------
//* utility to create kapenta registry
//--------------------------------------------------------------------------------------------------
//+ NOTE: expects 'pass' value in GET, matching recovery password, will also accept 'reload' value
//+ to reload setup.inc.php, and 'set' to set values.
//+
//+ Sending recovery password as a $_GET var is awful, TODO: fix this
//----------------------------------------------------------------------------------------------
// initialize registry and check password
//----------------------------------------------------------------------------------------------
session_start();
$registry = new KRegistry();
$auth = false;
$recoveryPass = $registry->get('kapenta.recoverypassword');
$userPass = '';
if ((true == array_key_exists('action', $_POST)) && ('logout' == $_POST['action'])) {
$_SESSION['regsetup_pass'] = '';
}
if ((true == array_key_exists('action', $_POST)) && ('login' == $_POST['action'])) {
if (true == array_key_exists('pass', $_POST)) { $userPass = $_POST['pass']; }
$_SESSION['regsetup_pass'] = $userPass;
}
if (true == array_key_exists('regsetup_pass', $_SESSION)) {
$userPass = $_SESSION['regsetup_pass'];
}
//----------------------------------------------------------------------------------------------
// show login form if not authorized
//----------------------------------------------------------------------------------------------
$header = "<html>
<head>
<link href='themes/clockface/css/default.css'
rel='stylesheet' type='text/css' />
</head>
<body>
<h1>Kapenta Registry Setup</h1>
";
$footer = "</body></html>";
echo $header;
if (sha1($userPass) == $recoveryPass) { $auth = true; }
if ('' == $recoveryPass) { $auth = true; }
if (false == $auth) {
$loginForm = "
<h2>Please log in.</h2>
<form name='pwForm' method='POST'>
<input type='hidden' name='action' value='login' />
<b>Kapenta Recovery Password:</b> <input type='password' name='pass' />
<input type='submit' />
</form><hr/><br/>
";
die($loginForm . $footer);
}
//----------------------------------------------------------------------------------------------
// load if setup.inc.php if requested and it exists - save values to the registry
//----------------------------------------------------------------------------------------------
if ((true == array_key_exists('action', $_POST)) && ('reload' == $_POST['action'])) {
if (true == file_exists('setup.inc.php')) {
require_once('setup.inc.php');
echo "Reloading setup.inc.php...<br/>\n";
$varMap = array(
'installPath' => 'kapenta.installpath',
'serverPath' => 'kapenta.serverpath',
'dbType' => 'kapenta.db.type',
'dbHost' => 'kapenta.db.host',
'dbName' => 'kapenta.db.name',
'dbUser' => 'kapenta.db.user',
'dbPass' => 'kapenta.db.password',
'defaultModule' => 'kapenta.modules.default',
'useBlockCache' => 'kapenta.blockcache.enabled',
'websiteName' => 'kapenta.sitename',
'defaultTheme' => 'kapenta.themes.default',
'logLevel' => 'kapenta.loglevel',
'cronInterval' => 'cron.interval',
'hostInterface' => 'kapenta.network.interface',
'proxyEnabled' => 'kapenta.proxy.enabled',
'proxyAddress' => 'kapenta.proxy.address',
'proxyPort' => 'kapenta.proxy.port',
'proxyUser' => 'kapenta.proxy.user',
'proxyPass' => 'kapenta.proxy.pass',
'rsaKeySize' => 'kapenta.rsa.keysize',
'rsaPublicKey' => 'kapenta.rsa.publickey',
'rsaPrivateKey' => 'kapenta.rsa.privatekey'
);
foreach ($varMap as $varName => $regkey) {
if (true == isset($$varName)) { $registry->set($regkey, $$varName); }
echo "setting $regkey ...<br/>\n";
}
} else {
echo "setup.inc.php not found.<br/>\n";
}
}
//----------------------------------------------------------------------------------------------
// set a key
//----------------------------------------------------------------------------------------------
if ((true == array_key_exists('action', $_POST)) && ('add' == $_POST['action'])) {
$key = (array_key_exists('key', $_POST)) ? $_POST['key'] : '';
$value = (array_key_exists('value', $_POST)) ? $_POST['value'] : '';
//echo "setting $key to $value ...<br/>";
if (('kapenta.recoverypassword' == $key) && ('' != $value)) { $value = sha1($value); }
if ('' != $key) {
$registry->set($key, $value);
}
}
//----------------------------------------------------------------------------------------------
// load all registry files
//----------------------------------------------------------------------------------------------
$prefixes = $registry->listFiles();
echo "<b>Jump to:</b> ";
foreach($prefixes as $prefix) { echo "<a href='#$prefix'>$prefix</a>, "; }
echo "<br/><br/>";
//----------------------------------------------------------------------------------------------
// show 'add key' form
//----------------------------------------------------------------------------------------------
$addForm = "
<form name='addForm' method='POST'>
<input type='hidden' name='action' value='add' />
<b>key:</b> <input type='text' name='key' />
<b>value:</b> <input type='text' name='value' />
<input type='submit' value='Add Key >>' />
</form><br/>
";
//----------------------------------------------------------------------------------------------
// show 'reload' form
//----------------------------------------------------------------------------------------------
$reloadForm = "
<form name='reloadForm' method='POST'>
<input type='hidden' name='action' value='reload' />
<input type='submit' value='Reload setup.inc.php >>' />
</form><hr/><br/>
";
//----------------------------------------------------------------------------------------------
// show 'log out' form
//----------------------------------------------------------------------------------------------
$logOutForm = "
<form name='logoutForm' method='POST'>
<input type='hidden' name='action' value='logout' />
<input type='submit' value='Log out >>' />
</form><hr/><br/>
";
echo $logOutForm;
//----------------------------------------------------------------------------------------------
// show keys and controls
//----------------------------------------------------------------------------------------------
foreach($prefixes as $prefix) {
echo "<h2><a name='$prefix'>" . $prefix . "</a></h2>\n";
echo $addForm;
echo $registry->toHtml($prefix);
echo $reloadForm;
}
echo $logOutForm;
//----------------------------------------------------------------------------------------------
// done
//----------------------------------------------------------------------------------------------
echo $footer;
?>