modules/vhosts/save.php
8d92bc6d
 <?php
 
 require_once('session/start.php');
 
 require_once('vhosts.php');
 
 require_once('inc/security.php');
 require_once('class/domain.php');
 
 require_role(ROLE_SYSTEMUSER);
 
 require_once("inc/debug.php");
 global $debugmode;
 
 
 if ($_GET['action'] == 'edit')
 {
   check_form_token('vhosts_edit_vhost');
   $id = (int) $_GET['vhost'];
   $vhost = empty_vhost();
   if ($id != 0)
     $vhost = get_vhost_details( $id );
   DEBUG($vhost);
 
   $hostname = filter_input_hostname($_POST['hostname']);
 
f1d119a9
   $domainid = (int) $_POST['domain'];
   if ($domainid != -1) {
     $domain = new Domain( (int) $_POST['domain'] );
     if ($domain->useraccount != $_SESSION['userinfo']['uid'])
       system_failure('Ungültige Domain');
     $domainid = $domain->id;
   }
8d92bc6d
 
   if (! is_array($_POST['options']))
     $_POST['options'] = array();
   $aliaswww = in_array('aliaswww', $_POST['options']);
 
7fb0aeba
   $docroot = '';
8d92bc6d
   $php = '';
f0f3361f
   if ($_POST['vhost_type'] == 'regular' || $_POST['vhost_type'] == 'dav')
7fb0aeba
   {
     $defaultdocroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domain->fqdn).'/htdocs';
   
     if (! check_path( $_POST['docroot'] ))
       system_failure("Eingegebener Pfad enthält ungültige Angaben");
33c1bcb0
     $docroot = $vhost['homedir'].'/websites/'.$_POST['docroot'];
7fb0aeba
   
     if (($_POST['use_default_docroot'] == '1') || ($docroot == $defaultdocroot)) {
       $docroot = '';
     }
   
     DEBUG("Document-Root: ".$docroot);
f0f3361f
   }
   $php = '';
   if ($_POST['vhost_type'] == 'regular')
   {
7fb0aeba
     switch ($_POST['php']) {
       case 'mod_php':
         $php = 'mod_php';
         break;
       case 'fastcgi':
         $php = 'fastcgi';
         break;
       /* Wenn etwas anderes kommt, ist das "kein PHP". So einfach ist das. */
     }
   }
f0f3361f
   if ($_POST['vhost_type'] == 'regular') {
     $vhost['is_dav'] = 0;
     $vhost['is_svn'] = 0;
     $vhost['is_webapp'] = 0;
   }
7fb0aeba
   elseif ($_POST['vhost_type'] == 'dav') {
     $vhost['is_dav'] = 1;
     $vhost['is_svn'] = 0;
     $vhost['is_webapp'] = 0;
   }
   elseif ($_POST['vhost_type'] == 'svn') {
     $vhost['is_dav'] = 0;
     $vhost['is_svn'] = 1;
     $vhost['is_webapp'] = 0;
   }
   elseif ($_POST['vhost_type'] == 'webapp') {
     $vhost['is_dav'] = 0;
     $vhost['is_svn'] = 0;
     $vhost['is_webapp'] = 1;
3c2fddca
     $vhost['webapp_id'] = (int) $_POST['webapp'];
8d92bc6d
   }
 
7fb0aeba
   
fc35e698
   $ssl = '';
   switch ($_POST['ssl']) {
     case 'http':
       $ssl = 'http';
       break;
     case 'https':
       $ssl = 'https';
       break;
     case 'forward':
       $ssl = 'forward';
       break;
     /* Wenn etwas anderes kommt, ist das "beides". So einfach ist das. */
   }
 
8d92bc6d
   $logtype = '';
   switch ($_POST['logtype']) {
     case 'anonymous':
       $logtype = 'anonymous';
       break;
     case 'default':
       $logtype = 'default';
       break;
     /* Wenn etwas anderes kommt, ist das "kein Logging". So einfach ist das. */
   }
 
2b282fad
   $errorlog = 0;
   if (isset($_POST['errorlog']) and ($_POST['errorlog'] == 1))
     $errorlog = 1;
 
8d92bc6d
   DEBUG("PHP: {$php} / Logging: {$logtype}");
 
   $old_options = explode(',', $vhost['options']);
   $new_options = array();
   foreach ($old_options AS $op)
   {
     if ($op != 'aliaswww')
       array_push($new_options, $op);
   }
   if ($aliaswww)
     array_push($new_options, 'aliaswww');
 
   DEBUG($old_options);
   DEBUG($new_options);
   $options = implode(',', $new_options);
   DEBUG('New options: '.$options);
 
   $vhost['hostname'] = $hostname;
f1d119a9
   $vhost['domainid'] = $domainid;
8d92bc6d
   $vhost['docroot'] = $docroot;
   $vhost['php'] = $php;
fc35e698
   $vhost['ssl'] = $ssl;
8d92bc6d
   $vhost['logtype'] = $logtype;
2b282fad
   $vhost['errorlog'] = $errorlog; 
8d92bc6d
   $vhost['options'] = $options;
     
7fb0aeba
   DEBUG($vhost);
8d92bc6d
   save_vhost($vhost);
 
   if (! $debugmode)
63a0529b
     header('Location: vhosts');
8d92bc6d
 
 }
709c9ea2
 elseif ($_GET['action'] == 'addalias')
 {
   check_form_token('vhosts_add_alias');
   $id = (int) $_GET['vhost'];
   $vhost = get_vhost_details( $id );
   DEBUG($vhost);
 
   $alias = empty_alias();
   $alias['vhost'] = $vhost['id'];
 
   
   $hostname = filter_input_hostname($_POST['hostname']);
7acabcf1
   $domainid = (int) $_POST['domain'];
   if ($domainid != -1) {
     $domain = new Domain( (int) $_POST['domain'] );
     if ($domain->useraccount != $_SESSION['userinfo']['uid'])
       system_failure('Ungültige Domain');
     $domainid = $domain->id;
   }
709c9ea2
 
   if (! is_array($_POST['options']))
     $_POST['options'] = array();
   $aliaswww = in_array('aliaswww', $_POST['options']);
   $forward = in_array('forward', $_POST['options']);
 
   $new_options = array();
   if ($aliaswww)
     array_push($new_options, 'aliaswww');
   if ($forward)
     array_push($new_options, 'forward');
   DEBUG($new_options);
   $options = implode(',', $new_options);
   DEBUG('New options: '.$options);
 
   $alias['hostname'] = $hostname;
7acabcf1
   $alias['domainid'] = $domainid;
709c9ea2
     
   $alias ['options'] = $options;
     
   save_alias($alias);
 
   if (! $debugmode)
63a0529b
     header('Location: aliases?vhost='.$vhost['id']);
709c9ea2
 
 }
 elseif ($_GET['action'] == 'deletealias')
 {
   $title = "Subdomain löschen";
   $section = 'vhosts_vhosts';
   
   $alias = get_alias_details( (int) $_GET['alias'] );
   DEBUG($alias);
f1d119a9
   $alias_string = $alias['fqdn'];
709c9ea2
   
   $vhost = get_vhost_details( $alias['vhost'] );
   DEBUG($vhost);
f1d119a9
   $vhost_string = $vhost['fqdn'];
709c9ea2
   
   $sure = user_is_sure();
   if ($sure === NULL)
   {
     are_you_sure("action=deletealias&amp;alias={$_GET['alias']}", "Möchten Sie das Alias »{$alias_string}« für die Subdomain »{$vhost_string}« wirklich löschen?");
   }
   elseif ($sure === true)
   {
     delete_alias($alias['id']);
     if (! $debugmode)
63a0529b
       header('Location: aliases?vhost='.$vhost['id']);
709c9ea2
   }
   elseif ($sure === false)
   {
     if (! $debugmode)
63a0529b
       header('Location: aliases?vhost='.$vhost['id']);
709c9ea2
   }
 }
8d92bc6d
 elseif ($_GET['action'] == 'delete')
 {
709c9ea2
   $title = "Subdomain löschen";
   $section = 'vhosts_vhosts';
   
8d92bc6d
   $vhost = get_vhost_details( (int) $_GET['vhost'] );
f1d119a9
   $vhost_string = $vhost['fqdn'];
8d92bc6d
   
   $sure = user_is_sure();
   if ($sure === NULL)
   {
     are_you_sure("action=delete&amp;vhost={$_GET['vhost']}", "Möchten Sie die Subdomain »{$vhost_string}« wirklich löschen?");
   }
   elseif ($sure === true)
   {
     delete_vhost($vhost['id']);
     if (! $debugmode)
63a0529b
       header("Location: vhosts");
8d92bc6d
   }
   elseif ($sure === false)
   {
     if (! $debugmode)
63a0529b
       header("Location: vhosts");
8d92bc6d
   }
 }
 else
   system_failure("Unimplemented action");
 
 output('');
 
 
 ?>