forked from rvolz/BicBucStriim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installcheck.php
145 lines (129 loc) · 3.27 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
<?php
/**
* BicBucStriim installation check
*
* Copyight 2012-2016 Rainer Volz
* Licensed under MIT License, see LICENSE
*
*/
require 'lib/BicBucStriim/inst_utils.php';
# Use this instead of the Composer autoload for PHP 5.2 compatibility
# At least the PHP version check should run with PHP 5.2
require_once 'vendor/twig/twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array());
# 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, array());
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 find_gd_version($module_info);
}
function check_calibre($dir) {
clearstatcache();
$ret = array('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, array());
$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 == 7 && $min >= 2)
return true;
elseif ($maj > 7)
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->loadTemplate('installcheck.html');
echo $template->render(array(
'page' => array(
'rot' => '',
'version' => '1.5.0'
),
'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'),
'mcrypt' => extension_loaded('mcrypt'),
'mwrit' => fw('./data/data.db'),
'opd' => ini_get('open_basedir'),
'php' => check_php(),
'phpv' => phpversion(),
));
#echo phpinfo();
?>