1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Xcloner_Requirements { |
4
|
|
|
|
5
|
|
|
var $min_php_version = "5.6.0"; |
6
|
|
|
var $safe_mode = "Off"; |
7
|
|
|
|
8
|
|
|
private $xcloner_settings; |
9
|
|
|
private $xcloner_container; |
10
|
|
|
|
11
|
|
|
public function __construct(Xcloner $xcloner_container) { |
12
|
|
|
$this->xcloner_container = $xcloner_container; |
13
|
|
|
$this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
private function get_xcloner_container() { |
|
|
|
|
17
|
|
|
return $this->xcloner_container; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function check_backup_ready_status() { |
21
|
|
|
if (!$this->check_min_php_version(1)) { |
22
|
|
|
return false; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if (!$this->check_safe_mode(1)) { |
26
|
|
|
return false; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (!$this->check_xcloner_start_path(1)) { |
30
|
|
|
return false; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (!$this->check_xcloner_store_path(1)) { |
34
|
|
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if (!$this->check_xcloner_tmp_path(1)) { |
38
|
|
|
return false; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function get_constant($var) { |
45
|
|
|
return $this->$var; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function check_min_php_version($return_bool = 0) { |
49
|
|
|
|
50
|
|
|
if ($return_bool == 1) { |
51
|
|
|
if (version_compare(phpversion(), $this->min_php_version, '<')) { |
52
|
|
|
return false; |
53
|
|
|
} else { |
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return phpversion(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function check_safe_mode($return_bool = 0) { |
|
|
|
|
62
|
|
|
/*no longer needed for PHP 7*/ |
63
|
|
|
$safe_mode = "Off"; |
64
|
|
|
|
65
|
|
|
/*if($return_bool) |
66
|
|
|
{ |
67
|
|
|
if( ini_get('safe_mode') ) |
68
|
|
|
return false; |
69
|
|
|
else |
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if( ini_get('safe_mode') ) |
74
|
|
|
$safe_mode = "On"; |
75
|
|
|
* */ |
76
|
|
|
|
77
|
|
|
return $safe_mode; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function check_xcloner_start_path($return_bool = 0) { |
81
|
|
|
$path = $this->xcloner_settings->get_xcloner_start_path(); |
|
|
|
|
82
|
|
|
|
83
|
|
|
if ($return_bool) { |
84
|
|
|
if (!file_exists($path)) { |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return is_readable($path); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $path; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function check_xcloner_tmp_path($return_bool = 0) { |
95
|
|
|
$path = $this->xcloner_settings->get_xcloner_tmp_path(); |
96
|
|
|
|
97
|
|
|
if ($return_bool) { |
98
|
|
|
if (!file_exists($path)) { |
99
|
|
|
return false; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (!is_writeable($path)) { |
103
|
|
|
@chmod($path, 0777); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return is_writeable($path); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $path; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function check_xcloner_store_path($return_bool = 0) { |
113
|
|
|
$path = $this->xcloner_settings->get_xcloner_store_path(); |
114
|
|
|
|
115
|
|
|
if ($return_bool) { |
116
|
|
|
if (!file_exists($path)) { |
117
|
|
|
return false; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if (!is_writeable($path)) { |
121
|
|
|
@chmod($path, 0777); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return is_writeable($path); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $path; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function get_max_execution_time() { |
131
|
|
|
return ini_get('max_execution_time'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function get_memory_limit() { |
135
|
|
|
return ini_get('memory_limit'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function get_open_basedir() { |
139
|
|
|
$open_basedir = ini_get('open_basedir'); |
140
|
|
|
|
141
|
|
|
if (!$open_basedir) { |
142
|
|
|
$open_basedir = "none"; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $open_basedir; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function get_free_disk_space() { |
149
|
|
|
return $this->file_format_size(disk_free_space($this->xcloner_settings->get_xcloner_store_path())); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function file_format_size($bytes, $decimals = 2) { |
153
|
|
|
$unit_list = array('B', 'KB', 'MB', 'GB', 'PB'); |
154
|
|
|
|
155
|
|
|
if ($bytes == 0) { |
156
|
|
|
return $bytes.' '.$unit_list[0]; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$unit_count = count($unit_list); |
160
|
|
|
for ($i = $unit_count - 1; $i >= 0; $i--) { |
161
|
|
|
$power = $i * 10; |
162
|
|
|
if (($bytes >> $power) >= 1) { |
163
|
|
|
return round($bytes / (1 << $power), $decimals).' '.$unit_list[$i]; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
?> |
|
|
|
|
170
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.