forked from rvolz/BicBucStriim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installcheck.php
135 lines (119 loc) · 2.83 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
<?php
/**
* BicBucStriim installation check
*
* Copyight 2012 Rainer Volz
* Licensed under MIT License, see LICENSE
*
*/
# 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 {
$mod_rewrite = getenv('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();
if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info,$matches)) {
$gd_version_number = $matches[1];
} else {
$gd_version_number = 0;
}
return $gd_version_number;
}
function check_calibre($dir) {
$ret = 2;
if (file_exists($dir) && is_readable($dir)) {
$mdb = realpath($dir).'/metadata.db';
if (file_exists($mdb)) {
$ret = 1;
}
}
return $ret;
}
function check_php() {
$pv = preg_split('/\./', phpversion());
$maj = intval($pv[0]);
$min = intval($pv[1]);
if ($maj == 5 && $min >= 3)
return true;
elseif ($maj > 5)
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' => '', #$app->request()->getRootUri(),
'version' => '1.2.0-alpha'
),
'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();
?>