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