commit | author | age
|
9200ad
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
996bad
|
10 |
* Redistributions of source code must retain the above copyright notice, |
M |
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
9200ad
|
18 |
|
T |
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
c87c0a
|
30 |
error_reporting(E_ALL|E_STRICT); |
P |
31 |
|
|
32 |
|
|
33 |
$FILE = realpath('../install.php'); |
|
34 |
|
cc3fb3
|
35 |
//** Get distribution identifier |
220bb9
|
36 |
//** IMPORTANT! |
dead5c
|
37 |
// This is the same code as in server/lib/classes/monitor_tools.inc.php |
beb172
|
38 |
// So if you change it here, you also have to change it in there! |
3b8b9e
|
39 |
// |
TB |
40 |
// This function returns a string that describes the installed |
|
41 |
// Linux distribution. e.g. debian40 for Debian GNU/Linux 4.0 |
|
42 |
|
9200ad
|
43 |
function get_distname() { |
996bad
|
44 |
|
f629e2
|
45 |
$distname = ''; |
1b40a8
|
46 |
$distver = ''; |
T |
47 |
$distid = ''; |
|
48 |
$distbaseid = ''; |
996bad
|
49 |
|
3b8b9e
|
50 |
//** Debian or Ubuntu |
TB |
51 |
if(file_exists('/etc/debian_version')) { |
|
52 |
|
|
53 |
// Check if this is Ubuntu and not Debian |
|
54 |
if (strstr(trim(file_get_contents('/etc/issue')), 'Ubuntu') || (is_file('/etc/os-release') && stristr(file_get_contents('/etc/os-release'), 'Ubuntu'))) { |
|
55 |
|
|
56 |
$issue = file_get_contents('/etc/issue'); |
|
57 |
|
|
58 |
// Use content of /etc/issue file |
|
59 |
if(strstr($issue,'Ubuntu')) { |
|
60 |
if (strstr(trim($issue), 'LTS')) { |
|
61 |
$lts=" LTS"; |
|
62 |
} else { |
|
63 |
$lts=""; |
|
64 |
} |
f5daec
|
65 |
|
3b8b9e
|
66 |
$distname = 'Ubuntu'; |
TB |
67 |
$distid = 'debian40'; |
|
68 |
$distbaseid = 'debian'; |
|
69 |
$ver = explode(' ', $issue); |
|
70 |
$ver = array_filter($ver); |
|
71 |
$ver = next($ver); |
|
72 |
$mainver = explode('.', $ver); |
|
73 |
$mainver = array_filter($mainver); |
|
74 |
$mainver = current($mainver).'.'.next($mainver); |
|
75 |
// Use content of /etc/os-release file |
f35123
|
76 |
} else { |
3b8b9e
|
77 |
$os_release = file_get_contents('/etc/os-release'); |
TB |
78 |
if (strstr(trim($os_release), 'LTS')) { |
|
79 |
$lts = " LTS"; |
|
80 |
} else { |
|
81 |
$lts = ""; |
|
82 |
} |
|
83 |
|
|
84 |
$distname = 'Ubuntu'; |
|
85 |
$distid = 'debian40'; |
|
86 |
$distbaseid = 'debian'; |
f35123
|
87 |
|
3b8b9e
|
88 |
preg_match("/.*VERSION=\"(.*)\".*/ui", $os_release, $ver); |
TB |
89 |
$ver = str_replace("LTS", "", $ver[1]); |
|
90 |
$ver = explode(" ", $ver, 2); |
|
91 |
$ver = reset($ver); |
|
92 |
$mainver = $ver; |
|
93 |
} |
f35123
|
94 |
switch ($mainver){ |
480fef
|
95 |
case "16.04": |
TB |
96 |
$relname = "(Xenial Xerus)"; |
3b8b9e
|
97 |
$distconfid = 'ubuntu1604'; |
480fef
|
98 |
break; |
0a0647
|
99 |
case "15.10": |
TB |
100 |
$relname = "(Wily Werewolf)"; |
|
101 |
break; |
68af0b
|
102 |
case "15.04": |
TB |
103 |
$relname = "(Vivid Vervet)"; |
|
104 |
break; |
bc04c3
|
105 |
case "14.10": |
TB |
106 |
$relname = "(Utopic Unicorn)"; |
|
107 |
break; |
be2cbb
|
108 |
case "14.04": |
TB |
109 |
$relname = "(Trusty Tahr)"; |
|
110 |
break; |
|
111 |
case "13.10": |
|
112 |
$relname = "(Saucy Salamander)"; |
|
113 |
break; |
|
114 |
case "13.04": |
|
115 |
$relname = "(Raring Ringtail)"; |
|
116 |
break; |
7fe908
|
117 |
case "12.10": |
MC |
118 |
$relname = "(Quantal Quetzal)"; |
f35123
|
119 |
break; |
7fe908
|
120 |
case "12.04": |
MC |
121 |
$relname = "(Precise Pangolin)"; |
f35123
|
122 |
break; |
7fe908
|
123 |
case "11.10": |
MC |
124 |
$relname = "(Oneiric Ocelot)"; |
f35123
|
125 |
break; |
7fe908
|
126 |
case "11.14": |
MC |
127 |
$relname = "(Natty Narwhal)"; |
f35123
|
128 |
break; |
7fe908
|
129 |
case "10.10": |
MC |
130 |
$relname = "(Maverick Meerkat)"; |
f35123
|
131 |
break; |
7fe908
|
132 |
case "10.04": |
MC |
133 |
$relname = "(Lucid Lynx)"; |
f35123
|
134 |
break; |
7fe908
|
135 |
case "9.10": |
MC |
136 |
$relname = "(Karmic Koala)"; |
f35123
|
137 |
break; |
7fe908
|
138 |
case "9.04": |
MC |
139 |
$relname = "(Jaunty Jackpole)"; |
f35123
|
140 |
break; |
7fe908
|
141 |
case "8.10": |
f35123
|
142 |
$relname = "(Intrepid Ibex)"; |
T |
143 |
break; |
7fe908
|
144 |
case "8.04": |
MC |
145 |
$relname = "(Hardy Heron)"; |
f35123
|
146 |
break; |
7fe908
|
147 |
case "7.10": |
MC |
148 |
$relname = "(Gutsy Gibbon)"; |
f35123
|
149 |
break; |
7fe908
|
150 |
case "7.04": |
MC |
151 |
$relname = "(Feisty Fawn)"; |
f35123
|
152 |
break; |
7fe908
|
153 |
case "6.10": |
MC |
154 |
$relname = "(Edgy Eft)"; |
f35123
|
155 |
break; |
7fe908
|
156 |
case "6.06": |
MC |
157 |
$relname = "(Dapper Drake)"; |
f35123
|
158 |
break; |
7fe908
|
159 |
case "5.10": |
MC |
160 |
$relname = "(Breezy Badger)"; |
f35123
|
161 |
break; |
7fe908
|
162 |
case "5.04": |
MC |
163 |
$relname = "(Hoary Hedgehog)"; |
f35123
|
164 |
break; |
7fe908
|
165 |
case "4.10": |
MC |
166 |
$relname = "(Warty Warthog)"; |
f35123
|
167 |
break; |
7fe908
|
168 |
default: |
MC |
169 |
$relname = "UNKNOWN"; |
f35123
|
170 |
} |
T |
171 |
$distver = $ver.$lts." ".$relname; |
3b8b9e
|
172 |
swriteln("Operating System: ".$distname.' '.$distver."\n"); |
f35123
|
173 |
} elseif(trim(file_get_contents('/etc/debian_version')) == '4.0') { |
344393
|
174 |
$distname = 'Debian'; |
T |
175 |
$distver = '4.0'; |
|
176 |
$distid = 'debian40'; |
90511b
|
177 |
$distbaseid = 'debian'; |
03ade5
|
178 |
swriteln("Operating System: Debian 4.0 or compatible\n"); |
7fe908
|
179 |
} elseif(strstr(trim(file_get_contents('/etc/debian_version')), '5.0')) { |
344393
|
180 |
$distname = 'Debian'; |
1cb2e1
|
181 |
$distver = 'Lenny'; |
344393
|
182 |
$distid = 'debian40'; |
90511b
|
183 |
$distbaseid = 'debian'; |
1cb2e1
|
184 |
swriteln("Operating System: Debian Lenny or compatible\n"); |
7fe908
|
185 |
} elseif(strstr(trim(file_get_contents('/etc/debian_version')), '6.0') || trim(file_get_contents('/etc/debian_version')) == 'squeeze/sid') { |
1cb2e1
|
186 |
$distname = 'Debian'; |
F |
187 |
$distver = 'Squeeze/Sid'; |
94927b
|
188 |
$distid = 'debian60'; |
1cb2e1
|
189 |
$distbaseid = 'debian'; |
94927b
|
190 |
swriteln("Operating System: Debian 6.0 (Squeeze/Sid) or compatible\n"); |
82ff62
|
191 |
} elseif(strstr(trim(file_get_contents('/etc/debian_version')), '7.0') || substr(trim(file_get_contents('/etc/debian_version')),0,2) == '7.' || trim(file_get_contents('/etc/debian_version')) == 'wheezy/sid') { |
996bad
|
192 |
$distname = 'Debian'; |
M |
193 |
$distver = 'Wheezy/Sid'; |
d6aef1
|
194 |
$distid = 'debian60'; |
996bad
|
195 |
$distbaseid = 'debian'; |
d6aef1
|
196 |
swriteln("Operating System: Debian 7.0 (Wheezy/Sid) or compatible\n"); |
6a61a1
|
197 |
} elseif(strstr(trim(file_get_contents('/etc/debian_version')), '8') || substr(trim(file_get_contents('/etc/debian_version')),0,1) == '8') { |
TB |
198 |
$distname = 'Debian'; |
|
199 |
$distver = 'Jessie'; |
|
200 |
$distid = 'debian60'; |
|
201 |
$distbaseid = 'debian'; |
|
202 |
swriteln("Operating System: Debian 8.0 (Jessie) or compatible\n"); |
eab0cf
|
203 |
} elseif(strstr(trim(file_get_contents('/etc/debian_version')), '/sid')) { |
TB |
204 |
$distname = 'Debian'; |
|
205 |
$distver = 'Testing'; |
|
206 |
$distid = 'debian60'; |
|
207 |
$distconfid = 'debiantesting'; |
|
208 |
$distbaseid = 'debian'; |
|
209 |
swriteln("Operating System: Debian Testing\n"); |
996bad
|
210 |
} else { |
1b40a8
|
211 |
$distname = 'Debian'; |
T |
212 |
$distver = 'Unknown'; |
|
213 |
$distid = 'debian40'; |
|
214 |
$distbaseid = 'debian'; |
|
215 |
swriteln("Operating System: Debian or compatible, unknown version.\n"); |
cc3fb3
|
216 |
} |
O |
217 |
} |
996bad
|
218 |
|
7d89f5
|
219 |
//** OpenSuSE |
e38d14
|
220 |
elseif(file_exists('/etc/SuSE-release')) { |
7fe908
|
221 |
if(stristr(file_get_contents('/etc/SuSE-release'), '11.0')) { |
344393
|
222 |
$distname = 'openSUSE'; |
T |
223 |
$distver = '11.0'; |
|
224 |
$distid = 'opensuse110'; |
90511b
|
225 |
$distbaseid = 'opensuse'; |
7d89f5
|
226 |
swriteln("Operating System: openSUSE 11.0 or compatible\n"); |
7fe908
|
227 |
} elseif(stristr(file_get_contents('/etc/SuSE-release'), '11.1')) { |
a21c72
|
228 |
$distname = 'openSUSE'; |
T |
229 |
$distver = '11.1'; |
|
230 |
$distid = 'opensuse110'; |
|
231 |
$distbaseid = 'opensuse'; |
|
232 |
swriteln("Operating System: openSUSE 11.1 or compatible\n"); |
7fe908
|
233 |
} elseif(stristr(file_get_contents('/etc/SuSE-release'), '11.2')) { |
1b40a8
|
234 |
$distname = 'openSUSE'; |
df7e6d
|
235 |
$distver = '11.2'; |
T |
236 |
$distid = 'opensuse112'; |
1b40a8
|
237 |
$distbaseid = 'opensuse'; |
T |
238 |
swriteln("Operating System: openSUSE 11.2 or compatible\n"); |
|
239 |
} else { |
|
240 |
$distname = 'openSUSE'; |
|
241 |
$distver = 'Unknown'; |
df7e6d
|
242 |
$distid = 'opensuse112'; |
1b40a8
|
243 |
$distbaseid = 'opensuse'; |
T |
244 |
swriteln("Operating System: openSUSE or compatible, unknown version.\n"); |
a21c72
|
245 |
} |
7d89f5
|
246 |
} |
996bad
|
247 |
|
M |
248 |
|
cc3fb3
|
249 |
//** Redhat |
e38d14
|
250 |
elseif(file_exists('/etc/redhat-release')) { |
996bad
|
251 |
|
0711af
|
252 |
$content = file_get_contents('/etc/redhat-release'); |
996bad
|
253 |
|
7fe908
|
254 |
if(stristr($content, 'Fedora release 9 (Sulphur)')) { |
344393
|
255 |
$distname = 'Fedora'; |
T |
256 |
$distver = '9'; |
|
257 |
$distid = 'fedora9'; |
90511b
|
258 |
$distbaseid = 'fedora'; |
0711af
|
259 |
swriteln("Operating System: Fedora 9 or compatible\n"); |
7fe908
|
260 |
} elseif(stristr($content, 'Fedora release 10 (Cambridge)')) { |
5939ea
|
261 |
$distname = 'Fedora'; |
F |
262 |
$distver = '10'; |
|
263 |
$distid = 'fedora9'; |
|
264 |
$distbaseid = 'fedora'; |
|
265 |
swriteln("Operating System: Fedora 10 or compatible\n"); |
7fe908
|
266 |
} elseif(stristr($content, 'Fedora release 10')) { |
e08bdc
|
267 |
$distname = 'Fedora'; |
T |
268 |
$distver = '11'; |
|
269 |
$distid = 'fedora9'; |
|
270 |
$distbaseid = 'fedora'; |
|
271 |
swriteln("Operating System: Fedora 11 or compatible\n"); |
7fe908
|
272 |
} elseif(stristr($content, 'CentOS release 5.2 (Final)')) { |
663619
|
273 |
$distname = 'CentOS'; |
T |
274 |
$distver = '5.2'; |
|
275 |
$distid = 'centos52'; |
|
276 |
$distbaseid = 'fedora'; |
|
277 |
swriteln("Operating System: CentOS 5.2 or compatible\n"); |
7fe908
|
278 |
} elseif(stristr($content, 'CentOS release 5.3 (Final)')) { |
1b40a8
|
279 |
$distname = 'CentOS'; |
T |
280 |
$distver = '5.3'; |
edebc4
|
281 |
$distid = 'centos53'; |
1b40a8
|
282 |
$distbaseid = 'fedora'; |
T |
283 |
swriteln("Operating System: CentOS 5.3 or compatible\n"); |
7fe908
|
284 |
} elseif(stristr($content, 'CentOS release 5')) { |
fb3a98
|
285 |
$distname = 'CentOS'; |
T |
286 |
$distver = 'Unknown'; |
|
287 |
$distid = 'centos53'; |
|
288 |
$distbaseid = 'fedora'; |
|
289 |
swriteln("Operating System: CentOS 5 or compatible\n"); |
be2cbb
|
290 |
} elseif(stristr($content, 'CentOS Linux release 6')) { |
TB |
291 |
$distname = 'CentOS'; |
|
292 |
$distver = 'Unknown'; |
|
293 |
$distid = 'centos53'; |
|
294 |
$distbaseid = 'fedora'; |
|
295 |
swriteln("Operating System: CentOS 6 or compatible\n"); |
2b8e51
|
296 |
} elseif(stristr($content, 'CentOS Linux release 7.2')) { |
FS |
297 |
$distname = 'CentOS'; |
|
298 |
$distver = 'Unknown'; |
2b3dfa
|
299 |
$distid = 'centos72'; |
3b8b9e
|
300 |
$distconfid = 'centos72'; |
2b8e51
|
301 |
$distbaseid = 'fedora'; |
FS |
302 |
swriteln("Operating System: CentOS 7.2\n"); |
be2cbb
|
303 |
} elseif(stristr($content, 'CentOS Linux release 7')) { |
TB |
304 |
$distname = 'CentOS'; |
|
305 |
$distver = 'Unknown'; |
ccebb9
|
306 |
$distid = 'centos70'; |
be2cbb
|
307 |
$distbaseid = 'fedora'; |
TB |
308 |
swriteln("Operating System: CentOS 7 or compatible\n"); |
1b40a8
|
309 |
} else { |
T |
310 |
$distname = 'Redhat'; |
|
311 |
$distver = 'Unknown'; |
|
312 |
$distid = 'fedora9'; |
|
313 |
$distbaseid = 'fedora'; |
|
314 |
swriteln("Operating System: Redhat or compatible, unknown version.\n"); |
663619
|
315 |
} |
cb8c86
|
316 |
} |
996bad
|
317 |
|
cb8c86
|
318 |
//** Gentoo |
996bad
|
319 |
elseif(file_exists('/etc/gentoo-release')) { |
M |
320 |
|
|
321 |
$content = file_get_contents('/etc/gentoo-release'); |
|
322 |
|
7fe908
|
323 |
preg_match_all('/([0-9]{1,2})/', $content, $version); |
996bad
|
324 |
$distname = 'Gentoo'; |
M |
325 |
$distver = $version[0][0].$version[0][1]; |
|
326 |
$distid = 'gentoo'; |
|
327 |
$distbaseid = 'gentoo'; |
|
328 |
swriteln("Operating System: Gentoo $distver or compatible\n"); |
|
329 |
|
7d89f5
|
330 |
} else { |
e38d14
|
331 |
die('Unrecognized GNU/Linux distribution'); |
cc3fb3
|
332 |
} |
3b8b9e
|
333 |
|
TB |
334 |
// Set $distconfid to distid, if no different id for the config is defined |
|
335 |
if(!isset($distconfid)) $distconfid = $distid; |
996bad
|
336 |
|
3b8b9e
|
337 |
return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'confid' => $distconfid, 'baseid' => $distbaseid); |
9200ad
|
338 |
} |
T |
339 |
|
|
340 |
function sread() { |
7fe908
|
341 |
$input = fgets(STDIN); |
MC |
342 |
return rtrim($input); |
9200ad
|
343 |
} |
T |
344 |
|
239ce8
|
345 |
function swrite($text = '') { |
9200ad
|
346 |
echo $text; |
T |
347 |
} |
|
348 |
|
239ce8
|
349 |
function swriteln($text = '') { |
9200ad
|
350 |
echo $text."\n"; |
T |
351 |
} |
|
352 |
|
|
353 |
function ilog($msg){ |
7fe908
|
354 |
exec("echo `date` \"- [ISPConfig] - \"".$msg.' >> '.ISPC_LOG_FILE); |
9200ad
|
355 |
} |
T |
356 |
|
|
357 |
function error($msg){ |
c87c0a
|
358 |
ilog($msg); |
P |
359 |
die($msg."\n"); |
9200ad
|
360 |
} |
T |
361 |
|
|
362 |
function caselog($command, $file = '', $line = '', $success = '', $failure = ''){ |
7fe908
|
363 |
exec($command, $arr, $ret_val); |
c87c0a
|
364 |
$arr = NULL; |
P |
365 |
if(!empty($file) && !empty($line)){ |
|
366 |
$pre = $file.', Line '.$line.': '; |
|
367 |
} else { |
|
368 |
$pre = ''; |
|
369 |
} |
|
370 |
if($ret_val != 0){ |
|
371 |
if($failure == '') $failure = 'could not '.$command; |
|
372 |
ilog($pre.'WARNING: '.$failure); |
|
373 |
} else { |
|
374 |
if($success == '') $success = $command; |
|
375 |
ilog($pre.$success); |
|
376 |
} |
9200ad
|
377 |
} |
T |
378 |
|
|
379 |
function phpcaselog($ret_val, $msg, $file = '', $line = ''){ |
c87c0a
|
380 |
if(!empty($file) && !empty($line)){ |
P |
381 |
$pre = $file.', Line '.$line.': '; |
|
382 |
} else { |
|
383 |
$pre = ''; |
|
384 |
} |
|
385 |
if($ret_val == true){ |
|
386 |
ilog($pre.$msg); |
|
387 |
} else { |
|
388 |
ilog($pre.'WARNING: could not '.$msg); |
|
389 |
} |
|
390 |
return $ret_val; |
9200ad
|
391 |
} |
T |
392 |
|
|
393 |
function mkdirs($strPath, $mode = '0755'){ |
2ffaf4
|
394 |
if(isset($strPath) && $strPath != ''){ |
c87c0a
|
395 |
//* Verzeichnisse rekursiv erzeugen |
P |
396 |
if(is_dir($strPath)){ |
|
397 |
return true; |
|
398 |
} |
|
399 |
$pStrPath = dirname($strPath); |
|
400 |
if(!mkdirs($pStrPath, $mode)){ |
|
401 |
return false; |
|
402 |
} |
|
403 |
$old_umask = umask(0); |
|
404 |
$ret_val = mkdir($strPath, octdec($mode)); |
|
405 |
umask($old_umask); |
|
406 |
return $ret_val; |
|
407 |
} |
|
408 |
return false; |
9200ad
|
409 |
} |
T |
410 |
|
615a0a
|
411 |
function rfsel($file, $file2) { |
7fe908
|
412 |
clearstatcache(); |
MC |
413 |
if(is_file($file)) return rf($file); |
|
414 |
else return rf($file2); |
615a0a
|
415 |
} |
T |
416 |
|
9200ad
|
417 |
function rf($file){ |
c87c0a
|
418 |
clearstatcache(); |
b77113
|
419 |
if(is_file($file)) { |
7fe908
|
420 |
if(!$fp = fopen($file, 'rb')){ |
b77113
|
421 |
ilog('WARNING: could not open file '.$file); |
T |
422 |
} |
|
423 |
return filesize($file) > 0 ? fread($fp, filesize($file)) : ''; |
|
424 |
} else { |
|
425 |
return ''; |
c87c0a
|
426 |
} |
9200ad
|
427 |
} |
T |
428 |
|
|
429 |
function wf($file, $content){ |
c87c0a
|
430 |
mkdirs(dirname($file)); |
7fe908
|
431 |
if(!$fp = fopen($file, 'wb')){ |
c87c0a
|
432 |
ilog('WARNING: could not open file '.$file); |
P |
433 |
} |
|
434 |
fwrite($fp, $content); |
|
435 |
fclose($fp); |
9200ad
|
436 |
} |
T |
437 |
|
|
438 |
function af($file, $content){ |
c87c0a
|
439 |
mkdirs(dirname($file)); |
7fe908
|
440 |
if(!$fp = fopen($file, 'ab')){ |
c87c0a
|
441 |
ilog('WARNING: could not open file '.$file); |
P |
442 |
} |
7fe908
|
443 |
fwrite($fp, $content); |
c87c0a
|
444 |
fclose($fp); |
9200ad
|
445 |
} |
T |
446 |
|
|
447 |
function aftsl($file, $content){ |
7fe908
|
448 |
if(!$fp = fopen($file, 'ab')){ |
c87c0a
|
449 |
ilog('WARNING: could not open file '.$file); |
P |
450 |
} |
7fe908
|
451 |
fwrite($fp, $content); |
c87c0a
|
452 |
fclose($fp); |
9200ad
|
453 |
} |
T |
454 |
|
|
455 |
function unix_nl($input){ |
c87c0a
|
456 |
$output = str_replace("\r\n", "\n", $input); |
P |
457 |
$output = str_replace("\r", "\n", $output); |
|
458 |
return $output; |
9200ad
|
459 |
} |
T |
460 |
|
|
461 |
function remove_blank_lines($input, $file = 1){ |
c87c0a
|
462 |
//TODO ? Leerzeilen l�schen |
P |
463 |
if($file){ |
|
464 |
$content = unix_nl(rf($input)); // WTF -pedro ! |
|
465 |
}else{ |
|
466 |
$content = $input; |
|
467 |
} |
|
468 |
$lines = explode("\n", $content); |
|
469 |
if(!empty($lines)){ |
|
470 |
foreach($lines as $line){ |
|
471 |
if(trim($line) != '') $new_lines[] = $line; |
|
472 |
} |
|
473 |
} |
|
474 |
if(is_array($new_lines)){ |
|
475 |
$content = implode("\n", $new_lines); |
|
476 |
} else { |
|
477 |
$content = ''; |
|
478 |
} |
|
479 |
if($file){ |
|
480 |
wf($input, $content); |
|
481 |
}else{ |
|
482 |
return $content; |
|
483 |
} |
9200ad
|
484 |
} |
T |
485 |
|
|
486 |
function no_comments($file, $comment = '#'){ |
c87c0a
|
487 |
$content = unix_nl(rf($file)); |
P |
488 |
$lines = explode("\n", $content); |
|
489 |
if(!empty($lines)){ |
|
490 |
foreach($lines as $line){ |
|
491 |
if(strstr($line, $comment)){ |
|
492 |
$pos = strpos($line, $comment); |
|
493 |
if($pos != 0){ |
7fe908
|
494 |
$new_lines[] = substr($line, 0, $pos); |
c87c0a
|
495 |
}else{ |
P |
496 |
$new_lines[] = ''; |
|
497 |
} |
|
498 |
}else{ |
|
499 |
$new_lines[] = $line; |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
503 |
if(is_array($new_lines)){ |
|
504 |
$content_without_comments = implode("\n", $new_lines); |
|
505 |
$new_lines = NULL; |
|
506 |
return $content_without_comments; |
|
507 |
} else { |
|
508 |
return ''; |
|
509 |
} |
9200ad
|
510 |
} |
T |
511 |
|
|
512 |
function comment_out($file, $string){ |
c87c0a
|
513 |
$inhalt = no_comments($file); |
P |
514 |
$gesamt_inhalt = rf($file); |
|
515 |
$modules = explode(',', $string); |
|
516 |
foreach($modules as $val){ |
|
517 |
$val = trim($val); |
|
518 |
if(strstr($inhalt, $val)){ |
|
519 |
$gesamt_inhalt = str_replace($val, '##ISPConfig INSTALL## '.$val, $gesamt_inhalt); |
|
520 |
} |
|
521 |
} |
|
522 |
wf($file, $gesamt_inhalt); |
9200ad
|
523 |
} |
T |
524 |
|
|
525 |
function is_word($string, $text, $params = ''){ |
996bad
|
526 |
//* params: i ?? |
M |
527 |
return preg_match("/\b$string\b/$params", $text); |
|
528 |
/* |
|
529 |
if(preg_match("/\b$string\b/$params", $text)) { |
|
530 |
return true; |
|
531 |
} else { |
|
532 |
return false; |
|
533 |
} |
|
534 |
*/ |
9200ad
|
535 |
} |
T |
536 |
|
|
537 |
function grep($content, $string, $params = ''){ |
996bad
|
538 |
// params: i, v, w |
M |
539 |
$content = unix_nl($content); |
|
540 |
$lines = explode("\n", $content); |
|
541 |
foreach($lines as $line){ |
|
542 |
if(!strstr($params, 'w')){ |
|
543 |
if(strstr($params, 'i')){ |
|
544 |
if(strstr($params, 'v')){ |
|
545 |
if(!stristr($line, $string)) $find[] = $line; |
|
546 |
} else { |
|
547 |
if(stristr($line, $string)) $find[] = $line; |
|
548 |
} |
|
549 |
} else { |
|
550 |
if(strstr($params, 'v')){ |
|
551 |
if(!strstr($line, $string)) $find[] = $line; |
|
552 |
} else { |
|
553 |
if(strstr($line, $string)) $find[] = $line; |
|
554 |
} |
|
555 |
} |
|
556 |
} else { |
|
557 |
if(strstr($params, 'i')){ |
|
558 |
if(strstr($params, 'v')){ |
|
559 |
if(!is_word($string, $line, 'i')) $find[] = $line; |
|
560 |
} else { |
|
561 |
if(is_word($string, $line, 'i')) $find[] = $line; |
|
562 |
} |
|
563 |
} else { |
|
564 |
if(strstr($params, 'v')){ |
|
565 |
if(!is_word($string, $line)) $find[] = $line; |
|
566 |
} else { |
|
567 |
if(is_word($string, $line)) $find[] = $line; |
|
568 |
} |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
if(is_array($find)){ |
|
573 |
$ret_val = implode("\n", $find); |
7fe908
|
574 |
if(substr($ret_val, -1) != "\n") $ret_val .= "\n"; |
996bad
|
575 |
$find = NULL; |
M |
576 |
return $ret_val; |
|
577 |
} else { |
|
578 |
return false; |
|
579 |
} |
9200ad
|
580 |
} |
T |
581 |
|
|
582 |
function edit_xinetd_conf($service){ |
c87c0a
|
583 |
$xinetd_conf = '/etc/xinetd.conf'; |
P |
584 |
$contents = unix_nl(rf($xinetd_conf)); |
|
585 |
$lines = explode("\n", $contents); |
|
586 |
$j = sizeof($lines); |
|
587 |
for($i=0;$i<sizeof($lines);$i++){ |
|
588 |
if(grep($lines[$i], $service, 'w')){ |
|
589 |
$fundstelle_anfang = $i; |
|
590 |
$j = $i; |
|
591 |
$parts = explode($lines[$i], $contents); |
|
592 |
} |
|
593 |
if($j < sizeof($lines)){ |
|
594 |
if(strstr($lines[$i], '}')){ |
|
595 |
$fundstelle_ende = $i; |
|
596 |
$j = sizeof($lines); |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
if(isset($fundstelle_anfang) && isset($fundstelle_ende)){ |
|
601 |
for($i=$fundstelle_anfang;$i<=$fundstelle_ende;$i++){ |
|
602 |
if(strstr($lines[$i], 'disable')){ |
|
603 |
$disable = explode('=', $lines[$i]); |
|
604 |
$disable[1] = ' yes'; |
|
605 |
$lines[$i] = implode('=', $disable); |
|
606 |
} |
|
607 |
} |
|
608 |
} |
|
609 |
$fundstelle_anfang = NULL; |
|
610 |
$fundstelle_ende = NULL; |
|
611 |
$contents = implode("\n", $lines); |
|
612 |
wf($xinetd_conf, $contents); |
9200ad
|
613 |
} |
T |
614 |
|
4f7028
|
615 |
//* Converts a ini string to array |
T |
616 |
function ini_to_array($ini) { |
|
617 |
$config = ''; |
|
618 |
$ini = str_replace("\r\n", "\n", $ini); |
|
619 |
$lines = explode("\n", $ini); |
|
620 |
foreach($lines as $line) { |
7fe908
|
621 |
$line = trim($line); |
4f7028
|
622 |
if($line != '') { |
T |
623 |
if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) { |
|
624 |
$section = strtolower($matches[1]); |
|
625 |
} elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) { |
|
626 |
$item = trim($matches[1]); |
|
627 |
$config[$section][$item] = trim($matches[2]); |
|
628 |
} |
|
629 |
} |
|
630 |
} |
|
631 |
return $config; |
|
632 |
} |
996bad
|
633 |
|
M |
634 |
|
4f7028
|
635 |
//* Converts a config array to a string |
a171d6
|
636 |
function array_to_ini($config_array = '') { |
4f7028
|
637 |
if($config_array == '') $config_array = $this->config; |
T |
638 |
$content = ''; |
|
639 |
foreach($config_array as $section => $data) { |
|
640 |
$content .= "[$section]\n"; |
|
641 |
foreach($data as $item => $value) { |
|
642 |
if($item != ''){ |
7fe908
|
643 |
$content .= "$item=$value\n"; |
MC |
644 |
} |
4f7028
|
645 |
} |
T |
646 |
$content .= "\n"; |
|
647 |
} |
|
648 |
return $content; |
|
649 |
} |
|
650 |
|
b73329
|
651 |
function is_user($user){ |
996bad
|
652 |
global $mod; |
M |
653 |
$user_datei = '/etc/passwd'; |
|
654 |
$users = no_comments($user_datei); |
|
655 |
$lines = explode("\n", $users); |
|
656 |
if(is_array($lines)){ |
|
657 |
foreach($lines as $line){ |
|
658 |
if(trim($line) != ''){ |
|
659 |
list($f1, $f2, $f3, $f4, $f5, $f6, $f7) = explode(':', $line); |
|
660 |
if($f1 == $user) return true; |
|
661 |
} |
|
662 |
} |
|
663 |
} |
|
664 |
return false; |
b73329
|
665 |
} |
T |
666 |
|
|
667 |
function is_group($group){ |
996bad
|
668 |
global $mod; |
M |
669 |
$group_datei = '/etc/group'; |
|
670 |
$groups = no_comments($group_datei); |
|
671 |
$lines = explode("\n", $groups); |
|
672 |
if(is_array($lines)){ |
|
673 |
foreach($lines as $line){ |
|
674 |
if(trim($line) != ''){ |
|
675 |
list($f1, $f2, $f3, $f4) = explode(':', $line); |
|
676 |
if($f1 == $group) return true; |
|
677 |
} |
|
678 |
} |
|
679 |
} |
|
680 |
return false; |
b73329
|
681 |
} |
T |
682 |
|
7fe908
|
683 |
function replaceLine($filename, $search_pattern, $new_line, $strict = 0, $append = 1) { |
663619
|
684 |
if($lines = @file($filename)) { |
0711af
|
685 |
$out = ''; |
T |
686 |
$found = 0; |
|
687 |
foreach($lines as $line) { |
|
688 |
if($strict == 0) { |
7fe908
|
689 |
if(stristr($line, $search_pattern)) { |
0711af
|
690 |
$out .= $new_line."\n"; |
T |
691 |
$found = 1; |
|
692 |
} else { |
|
693 |
$out .= $line; |
|
694 |
} |
|
695 |
} else { |
|
696 |
if(trim($line) == $search_pattern) { |
|
697 |
$out .= $new_line."\n"; |
|
698 |
$found = 1; |
|
699 |
} else { |
|
700 |
$out .= $line; |
|
701 |
} |
|
702 |
} |
d78ed1
|
703 |
if (!$found) { |
TB |
704 |
if (trim($line) == $new_line) { |
|
705 |
$found = 1; |
|
706 |
} |
|
707 |
} |
0711af
|
708 |
} |
T |
709 |
if($found == 0) { |
b9dbe7
|
710 |
//* add \n if the last line does not end with \n or \r |
7fe908
|
711 |
if(substr($out, -1) != "\n" && substr($out, -1) != "\r") $out .= "\n"; |
b9dbe7
|
712 |
//* add the new line at the end of the file |
f28f40
|
713 |
if($append == 1) $out .= $new_line."\n"; |
0711af
|
714 |
} |
7fe908
|
715 |
file_put_contents($filename, $out); |
663619
|
716 |
} |
0711af
|
717 |
} |
996bad
|
718 |
|
7fe908
|
719 |
function removeLine($filename, $search_pattern, $strict = 0) { |
663619
|
720 |
if($lines = @file($filename)) { |
0711af
|
721 |
$out = ''; |
T |
722 |
foreach($lines as $line) { |
|
723 |
if($strict == 0) { |
7fe908
|
724 |
if(!stristr($line, $search_pattern)) { |
0711af
|
725 |
$out .= $line; |
T |
726 |
} |
|
727 |
} else { |
|
728 |
if(!trim($line) == $search_pattern) { |
|
729 |
$out .= $line; |
|
730 |
} |
|
731 |
} |
|
732 |
} |
7fe908
|
733 |
file_put_contents($filename, $out); |
663619
|
734 |
} |
0711af
|
735 |
} |
T |
736 |
|
8eca28
|
737 |
function hasLine($filename, $search_pattern, $strict = 0) { |
MC |
738 |
if($lines = @file($filename)) { |
|
739 |
foreach($lines as $line) { |
|
740 |
if($strict == 0) { |
|
741 |
if(stristr($line, $search_pattern)) { |
|
742 |
return true; |
|
743 |
} |
|
744 |
} else { |
|
745 |
if(trim($line) == $search_pattern) { |
|
746 |
return true; |
|
747 |
} |
|
748 |
} |
|
749 |
} |
|
750 |
} |
|
751 |
return false; |
|
752 |
} |
|
753 |
|
0a1f02
|
754 |
function is_installed($appname) { |
7fe908
|
755 |
exec('which '.escapeshellcmd($appname).' 2> /dev/null', $out, $returncode); |
MC |
756 |
if(isset($out[0]) && stristr($out[0], $appname) && $returncode == 0) { |
0a1f02
|
757 |
return true; |
T |
758 |
} else { |
|
759 |
return false; |
|
760 |
} |
|
761 |
} |
|
762 |
|
3250e5
|
763 |
/* |
934c7d
|
764 |
* Get the port number of the ISPConfig controlpanel vhost |
T |
765 |
*/ |
|
766 |
|
|
767 |
function get_ispconfig_port_number() { |
|
768 |
global $conf; |
4ffb51
|
769 |
if($conf['nginx']['installed'] == true){ |
F |
770 |
$ispconfig_vhost_file = $conf['nginx']['vhost_conf_dir'].'/ispconfig.vhost'; |
|
771 |
$regex = '/listen (\d+)/'; |
|
772 |
} else { |
|
773 |
$ispconfig_vhost_file = $conf['apache']['vhost_conf_dir'].'/ispconfig.vhost'; |
|
774 |
$regex = '/\<VirtualHost.*\:(\d{1,})\>/'; |
|
775 |
} |
996bad
|
776 |
|
934c7d
|
777 |
if(is_file($ispconfig_vhost_file)) { |
T |
778 |
$tmp = file_get_contents($ispconfig_vhost_file); |
7fe908
|
779 |
preg_match($regex, $tmp, $matches); |
0799f8
|
780 |
$port_number = @intval($matches[1]); |
934c7d
|
781 |
if($port_number > 0) { |
T |
782 |
return $port_number; |
|
783 |
} else { |
|
784 |
return '8080'; |
|
785 |
} |
|
786 |
} |
|
787 |
} |
|
788 |
|
4ae2a0
|
789 |
/* |
d0356f
|
790 |
* Get the port number of the ISPConfig apps vhost |
TB |
791 |
*/ |
|
792 |
|
|
793 |
function get_apps_vhost_port_number() { |
|
794 |
global $conf; |
|
795 |
if($conf['nginx']['installed'] == true){ |
|
796 |
$ispconfig_vhost_file = $conf['nginx']['vhost_conf_dir'].'/apps.vhost'; |
|
797 |
$regex = '/listen (\d+)/'; |
|
798 |
} else { |
|
799 |
$ispconfig_vhost_file = $conf['apache']['vhost_conf_dir'].'/apps.vhost'; |
|
800 |
$regex = '/\<VirtualHost.*\:(\d{1,})\>/'; |
|
801 |
} |
|
802 |
|
|
803 |
if(is_file($ispconfig_vhost_file)) { |
|
804 |
$tmp = file_get_contents($ispconfig_vhost_file); |
|
805 |
preg_match($regex, $tmp, $matches); |
|
806 |
$port_number = @intval($matches[1]); |
|
807 |
if($port_number > 0) { |
|
808 |
return $port_number; |
|
809 |
} else { |
|
810 |
return '8081'; |
|
811 |
} |
|
812 |
} |
|
813 |
} |
|
814 |
|
|
815 |
/* |
4ae2a0
|
816 |
* Get the port number of the ISPConfig controlpanel vhost |
T |
817 |
*/ |
|
818 |
|
|
819 |
function is_ispconfig_ssl_enabled() { |
|
820 |
global $conf; |
|
821 |
$ispconfig_vhost_file = $conf['apache']['vhost_conf_dir'].'/ispconfig.vhost'; |
|
822 |
|
|
823 |
if(is_file($ispconfig_vhost_file)) { |
|
824 |
$tmp = file_get_contents($ispconfig_vhost_file); |
7fe908
|
825 |
if(stristr($tmp, 'SSLCertificateFile')) { |
4ae2a0
|
826 |
return true; |
T |
827 |
} else { |
|
828 |
return false; |
|
829 |
} |
|
830 |
} |
|
831 |
} |
|
832 |
|
7fe908
|
833 |
/** |
MC |
834 |
Function to find the hash file for timezone detection |
|
835 |
(c) 2012 Marius Cramer, pixcept KG, m.cramer@pixcept.de |
|
836 |
*/ |
|
837 |
|
|
838 |
|
3898c9
|
839 |
function find_hash_file($hash, $dir, $basedir = '') { |
7fe908
|
840 |
$res = opendir($dir); |
MC |
841 |
if(!$res) return false; |
|
842 |
|
|
843 |
if(substr($basedir, -1) === '/') $basedir = substr($basedir, 0, strlen($basedir) - 1); |
|
844 |
if(substr($dir, -1) === '/') $dir = substr($dir, 0, strlen($dir) - 1); |
|
845 |
if($basedir === '') $basedir = $dir; |
|
846 |
|
|
847 |
while($cur = readdir($res)) { |
|
848 |
if($cur == '.' || $cur == '..') continue; |
|
849 |
$entry = $dir.'/'.$cur; |
|
850 |
if(is_dir($entry)) { |
|
851 |
$result = find_hash_file($hash, $entry, $basedir); |
|
852 |
if($result !== false) return $result; |
|
853 |
} elseif(md5_file($entry) === $hash) { |
|
854 |
$entry = substr($entry, strlen($basedir) + 1); |
|
855 |
if(substr($entry, 0, 7) === '/posix/') $entry = substr($entry, 7); |
|
856 |
return $entry; |
|
857 |
} |
|
858 |
} |
|
859 |
closedir($res); |
|
860 |
return false; |
3898c9
|
861 |
} |
T |
862 |
|
7fe908
|
863 |
|
MC |
864 |
/** |
|
865 |
Function to get the timezone of the Linux system |
|
866 |
(c) 2012 Marius Cramer, pixcept KG, m.cramer@pixcept.de |
|
867 |
*/ |
3898c9
|
868 |
function get_system_timezone() { |
7fe908
|
869 |
$timezone = false; |
MC |
870 |
if(file_exists('/etc/timezone') && is_readable('/etc/timezone')) { |
|
871 |
$timezone = trim(file_get_contents('/etc/timezone')); |
|
872 |
if(file_exists('/usr/share/zoneinfo/' . $timezone) == false) $timezone = false; |
|
873 |
} |
3898c9
|
874 |
|
7fe908
|
875 |
if(!$timezone && is_link('/etc/localtime')) { |
MC |
876 |
$timezone = readlink('/etc/localtime'); |
|
877 |
$timezone = str_replace('/usr/share/zoneinfo/', '', $timezone); |
696af9
|
878 |
$timezone = str_replace('..', '', $timezone); |
7fe908
|
879 |
if(substr($timezone, 0, 6) === 'posix/') $timezone = substr($timezone, 6); |
MC |
880 |
} elseif(!$timezone) { |
|
881 |
$hash = md5_file('/etc/localtime'); |
|
882 |
$timezone = find_hash_file($hash, '/usr/share/zoneinfo'); |
|
883 |
} |
3898c9
|
884 |
|
7fe908
|
885 |
if(!$timezone) { |
MC |
886 |
exec('date +%Z', $tzinfo); |
|
887 |
$timezone = $tzinfo[0]; |
|
888 |
} |
da860c
|
889 |
|
MC |
890 |
if(substr($timezone, 0, 1) === '/') $timezone = substr($timezone, 1); |
7fe908
|
891 |
|
MC |
892 |
return $timezone; |
3898c9
|
893 |
} |
4f7028
|
894 |
|
ccbf14
|
895 |
function getapacheversion($get_minor = false) { |
60b700
|
896 |
global $app; |
MC |
897 |
|
|
898 |
$cmd = ''; |
|
899 |
if(is_installed('apache2ctl')) $cmd = 'apache2ctl -v'; |
|
900 |
elseif(is_installed('apachectl')) $cmd = 'apachectl -v'; |
|
901 |
else { |
4b75ea
|
902 |
ilog("Could not check apache version, apachectl not found."); |
60b700
|
903 |
return '2.2'; |
MC |
904 |
} |
|
905 |
|
|
906 |
exec($cmd, $output, $return_var); |
|
907 |
if($return_var != 0 || !$output[0]) { |
4b75ea
|
908 |
ilog("Could not check apache version, apachectl did not return any data."); |
60b700
|
909 |
return '2.2'; |
MC |
910 |
} |
|
911 |
|
|
912 |
if(preg_match('/version:\s*Apache\/(\d+)(\.(\d+)(\.(\d+))*)?(\D|$)/i', $output[0], $matches)) { |
|
913 |
return $matches[1] . (isset($matches[3]) ? '.' . $matches[3] : '') . (isset($matches[5]) && $get_minor == true ? '.' . $matches[5] : ''); |
|
914 |
} else { |
4b75ea
|
915 |
ilog("Could not check apache version, did not find version string in apachectl output."); |
60b700
|
916 |
return '2.2'; |
MC |
917 |
} |
|
918 |
} |
|
919 |
|
|
920 |
function getapachemodules() { |
|
921 |
global $app; |
|
922 |
|
|
923 |
$cmd = ''; |
|
924 |
if(is_installed('apache2ctl')) $cmd = 'apache2ctl -t -D DUMP_MODULES'; |
|
925 |
elseif(is_installed('apachectl')) $cmd = 'apachectl -t -D DUMP_MODULES'; |
|
926 |
else { |
4b75ea
|
927 |
ilog("Could not check apache modules, apachectl not found."); |
60b700
|
928 |
return array(); |
MC |
929 |
} |
|
930 |
|
0a0ca4
|
931 |
exec($cmd . ' 2>/dev/null', $output, $return_var); |
60b700
|
932 |
if($return_var != 0 || !$output[0]) { |
4b75ea
|
933 |
ilog("Could not check apache modules, apachectl did not return any data."); |
60b700
|
934 |
return array(); |
MC |
935 |
} |
|
936 |
|
|
937 |
$modules = array(); |
|
938 |
for($i = 0; $i < count($output); $i++) { |
|
939 |
if(preg_match('/^\s*(\w+)\s+\((shared|static)\)\s*$/', $output[$i], $matches)) { |
|
940 |
$modules[] = $matches[1]; |
ccbf14
|
941 |
} |
TB |
942 |
} |
60b700
|
943 |
|
MC |
944 |
return $modules; |
|
945 |
} |
4f7028
|
946 |
|
d1386a
|
947 |
?> |