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 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
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. |
|
18 |
|
|
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 |
|
33 |
linux distribution. e.g. debian40 for Debian Linux 4.0 |
|
34 |
*/ |
|
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 |
} |
|
50 |
?> |
|
51 |
|
|
52 |
*/ |
|
53 |
error_reporting(E_ALL|E_STRICT); |
|
54 |
|
|
55 |
|
|
56 |
$FILE = realpath('../install.php'); |
|
57 |
|
cc3fb3
|
58 |
//** Get distribution identifier |
9200ad
|
59 |
function get_distname() { |
cc3fb3
|
60 |
|
f629e2
|
61 |
$distname = ''; |
24854c
|
62 |
$distver = ''; |
T |
63 |
$distid = ''; |
|
64 |
$distbaseid = ''; |
f629e2
|
65 |
|
T |
66 |
//** Debian or Ubuntu |
cc3fb3
|
67 |
if(file_exists('/etc/debian_version')) { |
O |
68 |
|
|
69 |
if(trim(file_get_contents('/etc/debian_version')) == '4.0') { |
344393
|
70 |
$distname = 'Debian'; |
T |
71 |
$distver = '4.0'; |
|
72 |
$distid = 'debian40'; |
90511b
|
73 |
$distbaseid = 'debian'; |
03ade5
|
74 |
swriteln("Operating System: Debian 4.0 or compatible\n"); |
24854c
|
75 |
} elseif(strstr(trim(file_get_contents('/etc/debian_version')),'5.0') || trim(file_get_contents('/etc/debian_version')) == 'lenny/sid') { |
344393
|
76 |
$distname = 'Debian'; |
T |
77 |
$distver = 'Lenny/Sid'; |
|
78 |
$distid = 'debian40'; |
90511b
|
79 |
$distbaseid = 'debian'; |
03ade5
|
80 |
swriteln("Operating System: Debian Lenny/Sid or compatible\n"); |
24854c
|
81 |
} else { |
T |
82 |
$distname = 'Debian'; |
|
83 |
$distver = 'Unknown'; |
|
84 |
$distid = 'debian40'; |
|
85 |
$distbaseid = 'debian'; |
|
86 |
swriteln("Operating System: Debian or compatible, unknown version.\n"); |
cc3fb3
|
87 |
} |
O |
88 |
} |
|
89 |
|
7d89f5
|
90 |
//** OpenSuSE |
T |
91 |
elseif(file_exists("/etc/SuSE-release")) { |
|
92 |
if(stristr(file_get_contents('/etc/SuSE-release'),'11.0')) { |
344393
|
93 |
$distname = 'openSUSE'; |
T |
94 |
$distver = '11.0'; |
|
95 |
$distid = 'opensuse110'; |
90511b
|
96 |
$distbaseid = 'opensuse'; |
7d89f5
|
97 |
swriteln("Operating System: openSUSE 11.0 or compatible\n"); |
24854c
|
98 |
} elseif(stristr(file_get_contents('/etc/SuSE-release'),'11.1')) { |
a21c72
|
99 |
$distname = 'openSUSE'; |
T |
100 |
$distver = '11.1'; |
|
101 |
$distid = 'opensuse110'; |
|
102 |
$distbaseid = 'opensuse'; |
|
103 |
swriteln("Operating System: openSUSE 11.1 or compatible\n"); |
24854c
|
104 |
} elseif(stristr(file_get_contents('/etc/SuSE-release'),'11.2')) { |
T |
105 |
$distname = 'openSUSE'; |
|
106 |
$distver = '11.1'; |
|
107 |
$distid = 'opensuse110'; |
|
108 |
$distbaseid = 'opensuse'; |
|
109 |
swriteln("Operating System: openSUSE 11.2 or compatible\n"); |
|
110 |
} else { |
|
111 |
$distname = 'openSUSE'; |
|
112 |
$distver = 'Unknown'; |
|
113 |
$distid = 'opensuse110'; |
|
114 |
$distbaseid = 'opensuse'; |
|
115 |
swriteln("Operating System: openSUSE or compatible, unknown version.\n"); |
a21c72
|
116 |
} |
7d89f5
|
117 |
} |
T |
118 |
|
|
119 |
|
cc3fb3
|
120 |
//** Redhat |
0711af
|
121 |
elseif(file_exists("/etc/redhat-release")) { |
T |
122 |
|
|
123 |
$content = file_get_contents('/etc/redhat-release'); |
|
124 |
|
|
125 |
if(stristr($content,'Fedora release 9 (Sulphur)')) { |
344393
|
126 |
$distname = 'Fedora'; |
T |
127 |
$distver = '9'; |
|
128 |
$distid = 'fedora9'; |
90511b
|
129 |
$distbaseid = 'fedora'; |
0711af
|
130 |
swriteln("Operating System: Fedora 9 or compatible\n"); |
24854c
|
131 |
} elseif(stristr($content,'Fedora release 10 (Cambridge)')) { |
5939ea
|
132 |
$distname = 'Fedora'; |
F |
133 |
$distver = '10'; |
|
134 |
$distid = 'fedora9'; |
|
135 |
$distbaseid = 'fedora'; |
|
136 |
swriteln("Operating System: Fedora 10 or compatible\n"); |
06e20d
|
137 |
} elseif(stristr($content,'Fedora release 10')) { |
T |
138 |
$distname = 'Fedora'; |
|
139 |
$distver = '11'; |
|
140 |
$distid = 'fedora9'; |
|
141 |
$distbaseid = 'fedora'; |
|
142 |
swriteln("Operating System: Fedora 11 or compatible\n"); |
24854c
|
143 |
} elseif(stristr($content,'CentOS release 5.2 (Final)')) { |
663619
|
144 |
$distname = 'CentOS'; |
T |
145 |
$distver = '5.2'; |
|
146 |
$distid = 'centos52'; |
|
147 |
$distbaseid = 'fedora'; |
|
148 |
swriteln("Operating System: CentOS 5.2 or compatible\n"); |
24854c
|
149 |
} elseif(stristr($content,'CentOS release 5.3 (Final)')) { |
T |
150 |
$distname = 'CentOS'; |
|
151 |
$distver = '5.3'; |
|
152 |
$distid = 'centos52'; |
|
153 |
$distbaseid = 'fedora'; |
|
154 |
swriteln("Operating System: CentOS 5.3 or compatible\n"); |
|
155 |
} else { |
|
156 |
$distname = 'Redhat'; |
|
157 |
$distver = 'Unknown'; |
|
158 |
$distid = 'fedora9'; |
|
159 |
$distbaseid = 'fedora'; |
|
160 |
swriteln("Operating System: Redhat or compatible, unknown version.\n"); |
663619
|
161 |
} |
T |
162 |
|
0711af
|
163 |
|
7d89f5
|
164 |
} else { |
T |
165 |
die('unrecognized linux distribution'); |
cc3fb3
|
166 |
} |
O |
167 |
|
90511b
|
168 |
return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'baseid' => $distbaseid); |
9200ad
|
169 |
} |
T |
170 |
|
|
171 |
function sread() { |
ba66cd
|
172 |
$input = fgets(STDIN); |
9200ad
|
173 |
return rtrim($input); |
T |
174 |
} |
|
175 |
|
239ce8
|
176 |
function swrite($text = '') { |
9200ad
|
177 |
echo $text; |
T |
178 |
} |
|
179 |
|
239ce8
|
180 |
function swriteln($text = '') { |
9200ad
|
181 |
echo $text."\n"; |
T |
182 |
} |
|
183 |
|
|
184 |
function ilog($msg){ |
66b4f9
|
185 |
exec("echo `date` \"- [ISPConfig] - \"".$msg." >> ".ISPC_LOG_FILE); |
9200ad
|
186 |
} |
T |
187 |
|
|
188 |
function error($msg){ |
c87c0a
|
189 |
ilog($msg); |
P |
190 |
die($msg."\n"); |
9200ad
|
191 |
} |
T |
192 |
|
|
193 |
function caselog($command, $file = '', $line = '', $success = '', $failure = ''){ |
c87c0a
|
194 |
exec($command,$arr,$ret_val); |
P |
195 |
$arr = NULL; |
|
196 |
if(!empty($file) && !empty($line)){ |
|
197 |
$pre = $file.', Line '.$line.': '; |
|
198 |
} else { |
|
199 |
$pre = ''; |
|
200 |
} |
|
201 |
if($ret_val != 0){ |
|
202 |
if($failure == '') $failure = 'could not '.$command; |
|
203 |
ilog($pre.'WARNING: '.$failure); |
|
204 |
} else { |
|
205 |
if($success == '') $success = $command; |
|
206 |
ilog($pre.$success); |
|
207 |
} |
9200ad
|
208 |
} |
T |
209 |
|
|
210 |
function phpcaselog($ret_val, $msg, $file = '', $line = ''){ |
c87c0a
|
211 |
if(!empty($file) && !empty($line)){ |
P |
212 |
$pre = $file.', Line '.$line.': '; |
|
213 |
} else { |
|
214 |
$pre = ''; |
|
215 |
} |
|
216 |
if($ret_val == true){ |
|
217 |
ilog($pre.$msg); |
|
218 |
} else { |
|
219 |
ilog($pre.'WARNING: could not '.$msg); |
|
220 |
} |
|
221 |
return $ret_val; |
9200ad
|
222 |
} |
T |
223 |
|
|
224 |
function mkdirs($strPath, $mode = '0755'){ |
2ffaf4
|
225 |
if(isset($strPath) && $strPath != ''){ |
c87c0a
|
226 |
//* Verzeichnisse rekursiv erzeugen |
P |
227 |
if(is_dir($strPath)){ |
|
228 |
return true; |
|
229 |
} |
|
230 |
$pStrPath = dirname($strPath); |
|
231 |
if(!mkdirs($pStrPath, $mode)){ |
|
232 |
return false; |
|
233 |
} |
|
234 |
$old_umask = umask(0); |
|
235 |
$ret_val = mkdir($strPath, octdec($mode)); |
|
236 |
umask($old_umask); |
|
237 |
return $ret_val; |
|
238 |
} |
|
239 |
return false; |
9200ad
|
240 |
} |
T |
241 |
|
|
242 |
function rf($file){ |
c87c0a
|
243 |
clearstatcache(); |
P |
244 |
if(!$fp = fopen ($file, 'rb')){ |
|
245 |
ilog('WARNING: could not open file '.$file); |
|
246 |
} |
|
247 |
return filesize($file) > 0 ? fread($fp, filesize($file)) : ''; |
9200ad
|
248 |
} |
T |
249 |
|
|
250 |
function wf($file, $content){ |
c87c0a
|
251 |
mkdirs(dirname($file)); |
P |
252 |
if(!$fp = fopen ($file, 'wb')){ |
|
253 |
ilog('WARNING: could not open file '.$file); |
|
254 |
} |
|
255 |
fwrite($fp, $content); |
|
256 |
fclose($fp); |
9200ad
|
257 |
} |
T |
258 |
|
|
259 |
function af($file, $content){ |
c87c0a
|
260 |
mkdirs(dirname($file)); |
P |
261 |
if(!$fp = fopen ($file, 'ab')){ |
|
262 |
ilog('WARNING: could not open file '.$file); |
|
263 |
} |
|
264 |
fwrite($fp,$content); |
|
265 |
fclose($fp); |
9200ad
|
266 |
} |
T |
267 |
|
|
268 |
function aftsl($file, $content){ |
c87c0a
|
269 |
if(!$fp = fopen ($file, 'ab')){ |
P |
270 |
ilog('WARNING: could not open file '.$file); |
|
271 |
} |
|
272 |
fwrite($fp,$content); |
|
273 |
fclose($fp); |
9200ad
|
274 |
} |
T |
275 |
|
|
276 |
function unix_nl($input){ |
c87c0a
|
277 |
$output = str_replace("\r\n", "\n", $input); |
P |
278 |
$output = str_replace("\r", "\n", $output); |
|
279 |
return $output; |
9200ad
|
280 |
} |
T |
281 |
|
|
282 |
function remove_blank_lines($input, $file = 1){ |
c87c0a
|
283 |
//TODO ? Leerzeilen l�schen |
P |
284 |
if($file){ |
|
285 |
$content = unix_nl(rf($input)); // WTF -pedro ! |
|
286 |
}else{ |
|
287 |
$content = $input; |
|
288 |
} |
|
289 |
$lines = explode("\n", $content); |
|
290 |
if(!empty($lines)){ |
|
291 |
foreach($lines as $line){ |
|
292 |
if(trim($line) != '') $new_lines[] = $line; |
|
293 |
} |
|
294 |
} |
|
295 |
if(is_array($new_lines)){ |
|
296 |
$content = implode("\n", $new_lines); |
|
297 |
} else { |
|
298 |
$content = ''; |
|
299 |
} |
|
300 |
if($file){ |
|
301 |
wf($input, $content); |
|
302 |
}else{ |
|
303 |
return $content; |
|
304 |
} |
9200ad
|
305 |
} |
T |
306 |
|
|
307 |
function no_comments($file, $comment = '#'){ |
c87c0a
|
308 |
$content = unix_nl(rf($file)); |
P |
309 |
$lines = explode("\n", $content); |
|
310 |
if(!empty($lines)){ |
|
311 |
foreach($lines as $line){ |
|
312 |
if(strstr($line, $comment)){ |
|
313 |
$pos = strpos($line, $comment); |
|
314 |
if($pos != 0){ |
|
315 |
$new_lines[] = substr($line,0,$pos); |
|
316 |
}else{ |
|
317 |
$new_lines[] = ''; |
|
318 |
} |
|
319 |
}else{ |
|
320 |
$new_lines[] = $line; |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
if(is_array($new_lines)){ |
|
325 |
$content_without_comments = implode("\n", $new_lines); |
|
326 |
$new_lines = NULL; |
|
327 |
return $content_without_comments; |
|
328 |
} else { |
|
329 |
return ''; |
|
330 |
} |
9200ad
|
331 |
} |
T |
332 |
|
|
333 |
function find_includes($file){ |
|
334 |
global $httpd_root; |
|
335 |
clearstatcache(); |
|
336 |
if(is_file($file) && filesize($file) > 0){ |
|
337 |
$includes[] = $file; |
|
338 |
$inhalt = unix_nl(no_comments($file)); |
|
339 |
$lines = explode("\n", $inhalt); |
|
340 |
if(!empty($lines)){ |
|
341 |
foreach($lines as $line){ |
2ffaf4
|
342 |
if(stristr($line, 'include ')){ |
P |
343 |
$include_file = str_replace("\n", '', trim(shell_exec("echo \"$line\" | awk '{print \$2}'"))); |
|
344 |
if(substr($include_file,0,1) != '/'){ |
|
345 |
$include_file = $httpd_root.'/'.$include_file; |
9200ad
|
346 |
} |
T |
347 |
if(is_file($include_file)){ |
|
348 |
if($further_includes = find_includes($include_file)){ |
|
349 |
$includes = array_merge($includes, $further_includes); |
|
350 |
} |
|
351 |
} else { |
2ffaf4
|
352 |
if(strstr($include_file, '*')){ |
9200ad
|
353 |
$more_files = explode("\n", shell_exec("ls -l $include_file | awk '{print \$9}'")); |
T |
354 |
if(!empty($more_files)){ |
|
355 |
foreach($more_files as $more_file){ |
|
356 |
if(is_file($more_file)){ |
|
357 |
if($further_includes = find_includes($more_file)){ |
|
358 |
$includes = array_merge($includes, $further_includes); |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
unset($more_files); |
|
364 |
$more_files = explode("\n", shell_exec("ls -l $include_file | awk '{print \$10}'")); |
|
365 |
if(!empty($more_files)){ |
|
366 |
foreach($more_files as $more_file){ |
|
367 |
if(is_file($more_file)){ |
|
368 |
if($further_includes = find_includes($more_file)){ |
|
369 |
$includes = array_merge($includes, $further_includes); |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
} |
|
379 |
} |
|
380 |
if(is_array($includes)){ |
|
381 |
$includes = array_unique($includes); |
|
382 |
return $includes; |
|
383 |
} else { |
|
384 |
return false; |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
function comment_out($file, $string){ |
c87c0a
|
389 |
$inhalt = no_comments($file); |
P |
390 |
$gesamt_inhalt = rf($file); |
|
391 |
$modules = explode(',', $string); |
|
392 |
foreach($modules as $val){ |
|
393 |
$val = trim($val); |
|
394 |
if(strstr($inhalt, $val)){ |
|
395 |
$gesamt_inhalt = str_replace($val, '##ISPConfig INSTALL## '.$val, $gesamt_inhalt); |
|
396 |
} |
|
397 |
} |
|
398 |
wf($file, $gesamt_inhalt); |
9200ad
|
399 |
} |
T |
400 |
|
|
401 |
function is_word($string, $text, $params = ''){ |
c87c0a
|
402 |
//* params: i ?? |
P |
403 |
return preg_match("/\b$string\b/$params", $text); |
|
404 |
/* |
9200ad
|
405 |
if(preg_match("/\b$string\b/$params", $text)) { |
T |
406 |
return true; |
|
407 |
} else { |
|
408 |
return false; |
|
409 |
} |
c87c0a
|
410 |
*/ |
9200ad
|
411 |
} |
T |
412 |
|
|
413 |
function grep($content, $string, $params = ''){ |
|
414 |
// params: i, v, w |
|
415 |
$content = unix_nl($content); |
|
416 |
$lines = explode("\n", $content); |
|
417 |
foreach($lines as $line){ |
|
418 |
if(!strstr($params, 'w')){ |
|
419 |
if(strstr($params, 'i')){ |
|
420 |
if(strstr($params, 'v')){ |
|
421 |
if(!stristr($line, $string)) $find[] = $line; |
|
422 |
} else { |
|
423 |
if(stristr($line, $string)) $find[] = $line; |
|
424 |
} |
|
425 |
} else { |
|
426 |
if(strstr($params, 'v')){ |
|
427 |
if(!strstr($line, $string)) $find[] = $line; |
|
428 |
} else { |
|
429 |
if(strstr($line, $string)) $find[] = $line; |
|
430 |
} |
|
431 |
} |
|
432 |
} else { |
|
433 |
if(strstr($params, 'i')){ |
|
434 |
if(strstr($params, 'v')){ |
|
435 |
if(!is_word($string, $line, 'i')) $find[] = $line; |
|
436 |
} else { |
|
437 |
if(is_word($string, $line, 'i')) $find[] = $line; |
|
438 |
} |
|
439 |
} else { |
|
440 |
if(strstr($params, 'v')){ |
|
441 |
if(!is_word($string, $line)) $find[] = $line; |
|
442 |
} else { |
|
443 |
if(is_word($string, $line)) $find[] = $line; |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
} |
|
448 |
if(is_array($find)){ |
|
449 |
$ret_val = implode("\n", $find); |
|
450 |
if(substr($ret_val,-1) != "\n") $ret_val .= "\n"; |
|
451 |
$find = NULL; |
|
452 |
return $ret_val; |
|
453 |
} else { |
|
454 |
return false; |
|
455 |
} |
|
456 |
} |
|
457 |
|
|
458 |
function edit_xinetd_conf($service){ |
c87c0a
|
459 |
$xinetd_conf = '/etc/xinetd.conf'; |
P |
460 |
$contents = unix_nl(rf($xinetd_conf)); |
|
461 |
$lines = explode("\n", $contents); |
|
462 |
$j = sizeof($lines); |
|
463 |
for($i=0;$i<sizeof($lines);$i++){ |
|
464 |
if(grep($lines[$i], $service, 'w')){ |
|
465 |
$fundstelle_anfang = $i; |
|
466 |
$j = $i; |
|
467 |
$parts = explode($lines[$i], $contents); |
|
468 |
} |
|
469 |
if($j < sizeof($lines)){ |
|
470 |
if(strstr($lines[$i], '}')){ |
|
471 |
$fundstelle_ende = $i; |
|
472 |
$j = sizeof($lines); |
|
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
if(isset($fundstelle_anfang) && isset($fundstelle_ende)){ |
|
477 |
for($i=$fundstelle_anfang;$i<=$fundstelle_ende;$i++){ |
|
478 |
if(strstr($lines[$i], 'disable')){ |
|
479 |
$disable = explode('=', $lines[$i]); |
|
480 |
$disable[1] = ' yes'; |
|
481 |
$lines[$i] = implode('=', $disable); |
|
482 |
} |
|
483 |
} |
|
484 |
} |
|
485 |
$fundstelle_anfang = NULL; |
|
486 |
$fundstelle_ende = NULL; |
|
487 |
$contents = implode("\n", $lines); |
|
488 |
wf($xinetd_conf, $contents); |
9200ad
|
489 |
} |
T |
490 |
|
4f7028
|
491 |
//* Converts a ini string to array |
T |
492 |
function ini_to_array($ini) { |
|
493 |
$config = ''; |
|
494 |
$ini = str_replace("\r\n", "\n", $ini); |
|
495 |
$lines = explode("\n", $ini); |
|
496 |
foreach($lines as $line) { |
|
497 |
$line = trim($line); |
|
498 |
if($line != '') { |
|
499 |
if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) { |
|
500 |
$section = strtolower($matches[1]); |
|
501 |
} elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) { |
|
502 |
$item = trim($matches[1]); |
|
503 |
$config[$section][$item] = trim($matches[2]); |
|
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
return $config; |
|
508 |
} |
|
509 |
|
|
510 |
|
|
511 |
//* Converts a config array to a string |
a171d6
|
512 |
function array_to_ini($config_array = '') { |
4f7028
|
513 |
if($config_array == '') $config_array = $this->config; |
T |
514 |
$content = ''; |
|
515 |
foreach($config_array as $section => $data) { |
|
516 |
$content .= "[$section]\n"; |
|
517 |
foreach($data as $item => $value) { |
|
518 |
if($item != ''){ |
|
519 |
$content .= "$item=$value\n"; |
|
520 |
} |
|
521 |
} |
|
522 |
$content .= "\n"; |
|
523 |
} |
|
524 |
return $content; |
|
525 |
} |
|
526 |
|
b73329
|
527 |
function is_user($user){ |
T |
528 |
global $mod; |
|
529 |
$user_datei = '/etc/passwd'; |
|
530 |
$users = no_comments($user_datei); |
|
531 |
$lines = explode("\n", $users); |
|
532 |
if(is_array($lines)){ |
|
533 |
foreach($lines as $line){ |
|
534 |
if(trim($line) != ""){ |
|
535 |
list($f1, $f2, $f3, $f4, $f5, $f6, $f7) = explode(":", $line); |
|
536 |
if($f1 == $user) return true; |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
return false; |
|
541 |
} |
|
542 |
|
|
543 |
function is_group($group){ |
|
544 |
global $mod; |
|
545 |
$group_datei = '/etc/group'; |
|
546 |
$groups = no_comments($group_datei); |
|
547 |
$lines = explode("\n", $groups); |
|
548 |
if(is_array($lines)){ |
|
549 |
foreach($lines as $line){ |
|
550 |
if(trim($line) != ""){ |
|
551 |
list($f1, $f2, $f3, $f4) = explode(":", $line); |
|
552 |
if($f1 == $group) return true; |
|
553 |
} |
|
554 |
} |
|
555 |
} |
|
556 |
return false; |
|
557 |
} |
|
558 |
|
f28f40
|
559 |
function replaceLine($filename,$search_pattern,$new_line,$strict = 0,$append = 1) { |
663619
|
560 |
if($lines = @file($filename)) { |
0711af
|
561 |
$out = ''; |
T |
562 |
$found = 0; |
|
563 |
foreach($lines as $line) { |
|
564 |
if($strict == 0) { |
|
565 |
if(stristr($line,$search_pattern)) { |
|
566 |
$out .= $new_line."\n"; |
|
567 |
$found = 1; |
|
568 |
} else { |
|
569 |
$out .= $line; |
|
570 |
} |
|
571 |
} else { |
|
572 |
if(trim($line) == $search_pattern) { |
|
573 |
$out .= $new_line."\n"; |
|
574 |
$found = 1; |
|
575 |
} else { |
|
576 |
$out .= $line; |
|
577 |
} |
|
578 |
} |
|
579 |
} |
|
580 |
if($found == 0) { |
b9dbe7
|
581 |
//* add \n if the last line does not end with \n or \r |
T |
582 |
if(substr($out,-1) != "\n" && substr($out,-1) != "\r") $out .= "\n"; |
|
583 |
//* add the new line at the end of the file |
f28f40
|
584 |
if($append == 1) $out .= $new_line."\n"; |
0711af
|
585 |
} |
T |
586 |
file_put_contents($filename,$out); |
663619
|
587 |
} |
0711af
|
588 |
} |
T |
589 |
|
|
590 |
function removeLine($filename,$search_pattern,$strict = 0) { |
663619
|
591 |
if($lines = @file($filename)) { |
0711af
|
592 |
$out = ''; |
T |
593 |
foreach($lines as $line) { |
|
594 |
if($strict == 0) { |
|
595 |
if(!stristr($line,$search_pattern)) { |
|
596 |
$out .= $line; |
|
597 |
} |
|
598 |
} else { |
|
599 |
if(!trim($line) == $search_pattern) { |
|
600 |
$out .= $line; |
|
601 |
} |
|
602 |
} |
|
603 |
} |
|
604 |
file_put_contents($filename,$out); |
663619
|
605 |
} |
0711af
|
606 |
} |
T |
607 |
|
0a1f02
|
608 |
function is_installed($appname) { |
76f197
|
609 |
exec('which '.escapeshellcmd($appname).' > /dev/null 2> /dev/null',$out); |
aee6fd
|
610 |
if(isset($out[0]) && stristr($out[0],$appname)) { |
0a1f02
|
611 |
return true; |
T |
612 |
} else { |
|
613 |
return false; |
|
614 |
} |
|
615 |
} |
|
616 |
|
4f7028
|
617 |
|
T |
618 |
|
d1386a
|
619 |
?> |