S
sevY
Hi zusammen,
ich habe mir ein kleines Adminpanel zum Anlegen von vhost, webalizer, temp_site gebaut.
SysCP & Co waren mir zu oversized.
Mein Problem:
Ich möchte als UID ftpuser und als GID apache nehmen.
PHP 5.0.4 (via APXS2 unter Apache2) führt das Kommando allerdings mit diesen Parametern nicht aus.
Laut manual muss der ausführende Superuser sein. Der apache läuft als apache:apache
Wie bekomme ich nun das ganze hin?
Hier das Script:
Hier die Config
Viele Grüße
Yves
ich habe mir ein kleines Adminpanel zum Anlegen von vhost, webalizer, temp_site gebaut.
SysCP & Co waren mir zu oversized.
Mein Problem:
Ich möchte als UID ftpuser und als GID apache nehmen.
PHP 5.0.4 (via APXS2 unter Apache2) führt das Kommando allerdings mit diesen Parametern nicht aus.
Laut manual muss der ausführende Superuser sein. Der apache läuft als apache:apache
Wie bekomme ich nun das ganze hin?
Hier das Script:
PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
require_once('config.inc.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="default.inc.css" type="text/css">
<title>ROPEnetwork Setup Tool</title>
</head>
<body>
<?php
if(isset($_POST['setup']) && is_dir($webroot.'/'.$_POST['directory'])) {
$base=$webroot.'/'.$_POST['directory'].'/'.$_POST['domain'];
if(isset($_POST['create_docroot'])) {
mkdir($base,intval(0777,8)) or exit('Error while creating '.$base);
chmod($base,intval(0774,8)) or exit('Error while changing mode for '.$base.' to 0774');
chown($base,$uid) or exit('Error while changing owner of '.$base.' to '.$uid);
chgrp($base,$gid) or exit('Error while changing group of '.$base.' to '.$gid);
$folderset=array(array('htdocs',0774),array('logs',0070),array('session',0070),array('tmp',0070),array('cgi',0740),array('webalizer',0770),array('webalizer/'.$_POST['domain'],0770));
foreach($folderset as $part) {
mkdir($base.'/'.$part[0],intval(0777,8)) or exit('Error while creating '.$base.'/'.$part[0]);
chmod($base.'/'.$part[0],intval($part[1],8)) or exit('Error while changing mode for '.$base.' to 0774');
chown($base.'/'.$part[0],$uid) or exit('Error while changing owner of '.$base.' to '.$uid);
chgrp($base.'/'.$part[0],$gid) or exit('Error while changing group of '.$base.' to '.$gid);
}
}
if(isset($_POST['create_html'])) {
copy($html_tpl,$base.'/htdocs/index.html') or exit('Error while copying '.$html_tpl.' to '.$base.'/htdocs/index.html');
}
if(isset($_POST['create_vhost'])) {
file_put_contents($vhostdir.'/'.$_POST['domain'].'.conf',ereg_replace('{LOG}',$logdir,ereg_replace('{DOMAIN}',$_POST['domain'],ereg_replace('{BASE}',$base,file_get_contents($vhost_tpl))))) or exit('Error while writing Apache2 vHost to '.$vhostdir.'/'.$_POST['domain'].'.conf');
}
if(isset($_POST['create_webalizer'])) {
file_put_contents($webalizerdir.'/'.$_POST['domain'].'.webalizer',ereg_replace('{LOG}',$logdir,ereg_replace('{DOMAIN}',$_POST['domain'],ereg_replace('{BASE}',$base,file_get_contents($webalizer_tpl))))) or exit('Error while writing Webalizer Config to '.$webalizerdir.'/'.$_POST['domain'].'.webalizer');
}
}
?>
<div class="main">
<div class="content">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="setup" value="1">
<select class="singleline" name="directory">
<?php
foreach(scandir($webroot) as $directory) {
echo '<option value="'.$directory.'">'.$directory.'</option>';
}
?>
</select><br>
<input class="singleline" type="text" name="domain" value="domain.tld"><br>
<input type="checkbox" name="create_docroot" checked="checked"> Create Docroot?<br>
<input type="checkbox" name="create_vhost" checked="checked"> Create vHost?<br>
<input type="checkbox" name="create_webalizer" checked="checked"> Create Webalizer?<br>
<input type="checkbox" name="create_html" checked="checked"> Create HTML?<br>
<input class="submit" type="submit" value="Setup"></form></div></div>
</body>
</html>
Hier die Config
PHP:
<?php
error_reporting(0);
$webroot='/var/www';
$uid='ftpuser';
$gid='apache';
$html_tpl='default/default.tpl';
$vhost_tpl='default/default.conf';
$webalizer_tpl='default/default.webalizer';
$vhostdir='/etc/apache2/vhosts.d';
$webalizerdir='/etc/webalizer/vhosts';
$logdir='/var/log/apache2';
?>
Viele Grüße
Yves