-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.php
executable file
·99 lines (84 loc) · 3.33 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
<?php
/*
This file is part of Erben
A tool for making full e-books from pages digitized by Czech National Library
Copyright (C) 2014 Czech Pirate Party
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (isset($_SERVER['argv'])) {
die("Running this installer from command line is not allowed.\n");
}
define('APP_BASEDIR', dirname(__FILE__));
require 'lib/init.php';
function runDbScript(\Common\Database $db, $filename) {
echo "<p>Running SQL script " . htmlspecialchars($filename) . "</p>\n";
$data = file_get_contents($filename);
$db->exec($data);
}
$baseurl = dirname($_SERVER['PHP_SELF']);
if (empty($baseurl) || $baseurl == '.') {
$baseurl = '/';
} else if (substr($baseurl, -1) != '/') {
$baseurl .= '/';
}
$htaccess = <<<EOF
DirectorySlash Off
Options -MultiViews
RewriteEngine On
RewriteOptions AllowNoSlash
RewriteBase $baseurl
RewriteRule ^css/ - [L]
RewriteRule ^js/ - [L]
RewriteRule ^(.*)$ index.php [QSA,END]
EOF;
# Check that required extensions are available (except PCNTL which is CLI-only)
$req_ext = array('curl', 'date', 'dom', 'libxml', 'pcre', 'PDO', 'pdo_pgsql',
'posix', 'xml');
$missing_ext = array();
foreach ($req_ext as $ext) {
if (!extension_loaded($ext)) {
$missing_ext[] = $ext;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Erben installer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
try {
if (!empty($missing_ext)) {
throw new Exception('Missing required PHP extensions: ' . implode(', ', $missing_ext));
}
$db = new \Common\Database();
runDbScript($db, 'db/job.sql');
runDbScript($db, 'db/pages.sql');
try {
if (@file_put_contents('.htaccess', $htaccess) === false) {
throw new Exception('Could not create .htacces file');
} else {
echo "<p>Erben installation successful. You can now <a href=\"" . htmlspecialchars($baseurl) . "\">continue to Erben</a>.</p>\n";
}
} catch (Exception $e) {
echo "<p>Could not create .htaccess file in current directory. To complete the installation, you'll have to create the file manually with the following content:</p>\n<pre>" . htmlspecialchars($htaccess) . "</pre>\n<p>Then you can <a href=\"" . htmlspecialchars($baseurl) . "\">continue to Erben</a>.</p>\n";
}
echo "<p><b>Note:</b> If the above link gives you <i>Internal Server Error</i>, check Apache error log. Apache system configuration files may prevent use of some directives in .htaccess files. Disabling mod_dir and mod_negotiation for this directory is necessary to make Erben work. If they cannot be disabled in .htaccess file, you will have to edit the system configuration files.</p>";
} catch (Exception $e) {
echo '<p><b>Error:</b> ' . htmlspecialchars($e->getMessage()) . "</p>\n";
}
?>
</body>
</html>