forked from rvolz/BicBucStriim
-
Notifications
You must be signed in to change notification settings - Fork 2
/
installcheck.php
155 lines (138 loc) · 3.58 KB
/
installcheck.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
<?php
/**
* BicBucStriim installation check
*
* Copyright 2012-2023 Rainer Volz
* Copyright 2023- mikespub
* Licensed under MIT License, see LICENSE
*
*/
require_once 'vendor/autoload.php';
use BicBucStriim\AppData\Settings;
use BicBucStriim\Utilities\InstallUtil;
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader, []);
# Check for Apache server
function is_apache($srv)
{
if (preg_match('/apache/i', $srv)) {
return true;
} else {
return false;
}
}
# see http://christian.roy.name/blog/detecting-modrewrite-using-php
function mod_rewrite_enabled()
{
if (function_exists('apache_get_modules')) {
$modules = apache_get_modules();
$mod_rewrite = in_array('mod_rewrite', $modules);
} else {
# Recent Apache versions (Synology DSM5) prefix envvars with the module name
$mod_rewrite = (getenv('HTTP_MOD_REWRITE') == 'On' || getenv('REDIRECT_HTTP_MOD_REWRITE') == 'On') ? true : false ;
}
return $mod_rewrite;
}
function has_sqlite()
{
$version = false;
try {
$mydb = new PDO('sqlite:data/data.db', null, null, []);
return true;
} catch (PDOException $e) {
return false;
}
}
function fw($file)
{
return (file_exists($file) && is_writeable($file));
}
function get_gd_version()
{
ob_start();
phpinfo(8);
$module_info = ob_get_contents();
ob_end_clean();
return InstallUtil::find_gd_version($module_info);
}
function check_calibre($dir)
{
clearstatcache();
$ret = ['status' => 2, 'dir_exists' => false, 'dir_is_readable' => false, 'dir_is_executable' => false, 'realpath' => '', 'library_ok' => false];
if (file_exists($dir)) {
$ret['dir_exists'] = true;
if (is_readable($dir)) {
$ret['dir_is_readable'] = true;
$ret['dir_is_executable'] = is_executable($dir);
$mdb = realpath($dir) . '/metadata.db';
$ret['realpath'] = $mdb;
if (file_exists($mdb)) {
$ret['status'] = 1;
try {
$mydb = new PDO('sqlite:' . $mdb, null, null, []);
$ret['library_ok'] = true;
} catch (PDOException $e) {
;
}
}
}
}
return $ret;
}
function check_php()
{
$pv = preg_split('/\./', phpversion());
$maj = intval($pv[0]);
$min = intval($pv[1]);
if ($maj == 8 && $min >= 0) {
return true;
} elseif ($maj > 8) {
return true;
} else {
return false;
}
}
if (isset($_POST['calibre_dir'])) {
$calibre_dir = $_POST['calibre_dir'];
$cd = check_calibre($calibre_dir);
} else {
$calibre_dir = null;
$cd = null;
}
$srv = $_SERVER['SERVER_SOFTWARE'];
$is_a = is_apache($srv) ;
if ($is_a) {
$mre = mod_rewrite_enabled();
} else {
$mre = false;
}
$gdv = get_gd_version();
if ($gdv >= 2) {
$gde = true;
} else {
$gde = false;
}
$template = $twig->load('installcheck.twig');
echo $template->render([
'page' => [
'rot' => '',
'version' => Settings::APP_VERSION,
],
'is_a' => $is_a,
'srv' => $srv,
'mre' => $mre,
'calibre_dir' => $calibre_dir,
'cd' => $cd,
'htaccess' => file_exists('./.htaccess'),
'hsql' => has_sqlite(),
'hgd2' => $gde,
'hgd2v' => $gdv,
'dwrit' => fw('./data'),
'intl' => extension_loaded('intl'),
'sodium' => extension_loaded('sodium'),
'mwrit' => fw('./data/data.db'),
'opd' => ini_get('open_basedir'),
'php' => check_php(),
'phpv' => phpversion(),
]);
#echo phpinfo();