Repository navigation
Expand file tree
/
Copy pathinstall.php
More file actions
312 lines (244 loc) · 8.28 KB
/
Copy pathinstall.php
File metadata and controls
312 lines (244 loc) · 8.28 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
/******************************************************************************
*
* Copyright © 2010
*
* FreeCode Norway AS
* Nydalsveien 30A, NO-0484 Oslo, Norway
* Norway
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
******************************************************************************/
class MyInstallApp
extends InstallApplication
{
}
$app = new MyInstallApp();
$app->main();
if( false )
{
/**
Protection against bad includes.
*/
if (!defined("FREECMDB")) {
return;
}
define('CONFIG_FILE_PATH', 'config.php');
class checks{
function configFileExists(){
return file_exists(CONFIG_FILE_PATH);
}
}
class FreeCMDBInstall
{
function head()
{
header('Content-Type: text/html; charset=utf-8');
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="static/FreeCMDB.css" type="text/css" media="screen,projection" />
<script type="text/javascript" src="common/static/jquery.js"></script>
<script type="text/javascript" src="common/static/FreeCMDB.js"></script>
<title>Install FreeCMDB</title>
</head>
<body>
<div class="content_install">
<div class="content_inner">
<?php
}
function check_dependencies()
{
$res = null;
if(! (@include_once 'Image/GraphViz.php') || !class_exists("Image_GraphViz")) {
$res[] = "<span class='error'>The Image_Graphviz library is missing. You can install it by writing <code>pear install Image_Graphviz</code> at the command line.</span>";
}
if(!class_exists("PDO")) {
$res[] = "<span class='error'>The PDO library is missing. You can install it by writing <code>pecl install PDO</code> at the command line.</span>";
}
return $res;
}
function view()
{
$this->head();
$dep_str="";
$dep = $this->check_dependencies();
if (count($dep)) {
$dep_str = "<p>The following problems have been detected with your server setup.: </p><p>" . implode("</p><p>", $dep) ." </p>";
}
?>
<h2>Install FreeCMDB</h2>
<?= $dep_str; ?>
<p>
FreeCMDB has not been installed. Please fill out the following form to install FreeCMDB. All fields are required.
</p>
<form action="" name="dbDetailForm" method="post" onSubmit='return installCheckFields();'>
<input type='hidden' name='action' value='install'/>
<table class='striped'>
<thead>
<tr>
<th colspan="2">Database Details</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right"><label for="dsn">DSN</label></td>
<td align="left"><input type="text" id="dsn" name="dsn"
size="80" class="required"
value="<?= param('dsn',"pgsql:dbname=DATABASE;host=localhost;user=USERNAME;password=PASSWORD"); ?>"> <span
class="error" id="dsn_error"></span></td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="2">Administrator Information</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right"><label for="admin_username">Administrator username</label></td>
<td align="left"><input type="text" id="admin_username"
name="admin_username" size="60" class="required"
value="<?= param('admin_username','');?>">
<span class="error" id="admin_username_error"></span></td>
</tr>
<tr>
<td align="right"><label for="admin_password">Administrator password</label></td>
<td align="left"><input type="password" id="admin_password"
name="admin_password" size="60" class="required"
value="<?= param('admin_password');?>">
<span class="error" id="admin_password_error"></span></td>
</tr>
<tr>
<td align="right"><label for="admin_password2">Administrator password (Again)</label></td>
<td align="left"><input type="password" id="admin_password2"
name="admin_password2" size="60" class="required"
value="<?= param('admin_password2',''); ?>">
<span class="error" id="admin_password2_error"></span></td>
</tr>
</tbody>
</table>
<div class='button_list'>
<p>
<button type='button' onclick='installDbCheck();'>Test database...</button>
<span id='db_notification'><?= param('db_notification','');?></span>
</p>
<p>
<button>Install!</button>
</p>
</div>
</form>
<script>
stripe();
</script>
<?php
$this->tail();
}
function tail()
{
?>
</div>
</div>
</body>
</html>
<?php
}
function db_check()
{
if (!db::init(param('dsn',''))) {
echo "<span class='error'>" . db::getError()."</span>";
} else {
echo "Database details ok!";
}
}
function install()
{
$ok = true;
$dep = $this->check_dependencies();
if (count($dep)) {
$ok = false;
}
else {
if (!db::init(param('dsn',''))) {
$_REQUEST['db_notification'] = "<span class='error'>" . db::getError()."</span>";
$ok = false;
}
$admin_password2 = param('admin_password2');
$admin_password = param('admin_password');
$admin_username = param('admin_username');
if ($admin_password2 == '' ||
$admin_password2 == '' ||
$admin_password2 == '' ) {
$ok = false;
}
}
if (!$ok) {
$this->view();
return;
}
$this->head();
foreach( explode(';', file_get_contents('./static/schema.sql')) as $sql) {
db::query($sql);
}
db::query("insert into ci_user (username, fullname, password) values (:name, 'Admin', :passwd)",
array(":name"=>$admin_username,":passwd"=>$admin_password));
$config = "<?php
define('DB_DSN', '".addSlashes(param('dsn',''))."');
?>";
$write_ok = @file_put_contents("./config.php", $config);
if (!$write_ok) {
$uid = posix_getuid();
$passwd = posix_getpwuid($uid);
$username = $passwd['name'];
$script_dir = dirname($_SERVER['SCRIPT_FILENAME']);
?>
Could not write configuration file. This probably means that the web server
does not have write privileges in the FreeCMDB directory. You can either add the
correct privileges using a command like <pre>chown -R <?=$username;?> <?= $script_dir ?></pre> and press the «Reload» button, or manually create the file <?= $_SERVER['DOCUMENT_ROOT']; ?>/config.php on the web server with the following contents:
<?php
echo "<pre>";
echo htmlEncode($config);
echo "</pre>";
$this->tail();
$ok = false;
}
if ($ok) {
echo "<h2>Success!</h2>The installation is complete. Click <a href=''>here</a> to start using FreeCMDB.";
}
}
function main()
{
if (!checks::configFileExists()) {
$action = param('action','view');
switch ($action) {
case 'db_check':
$this->db_check();
break;
case 'install':
$this->install();
break;
default:
$this->view();
break;
}
exit(0);
}
}
}
$cmdb = new FreeCMDBInstall();
$cmdb->main();
}
?>