modules/vhosts/include/vhosts.php
72518278
 <?php
c208bd90
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
5effc2bd
 Written 2008-2014 by schokokeks.org Hosting, namely
c208bd90
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
 
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
 http://creativecommons.org/publicdomain/zero/1.0/
 
 Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
 */
72518278
 
 require_once("inc/base.php");
 require_once("inc/error.php");
 require_once("inc/security.php");
 
 require_once('class/domain.php');
 
1ab9db55
 require_once("certs.php");
 
709c9ea2
 
4b6dffbd
 function traffic_month($vhost_id)
 {
   $vhost_id = (int) $vhost_id;
44996558
   $result = db_query("SELECT sum(mb_in+mb_out) as mb FROM vhosts.traffic where date > CURDATE() - INTERVAL 1 MONTH AND vhost_id = ?", array($vhost_id));
f1f231f5
   $data = $result->fetch();
4b6dffbd
   return $data['mb'];
 }
 
6c54f23e
 function autoipv6_address($vhost_id, $mode = 1)
aeacb601
 {
44996558
   $result = db_query("SELECT uid, v6_prefix FROM vhosts.v_vhost LEFT JOIN system.servers ON (servers.hostname = server) WHERE v_vhost.id=?", array($vhost_id));
f1f231f5
   $data = $result->fetch();
aeacb601
   if (!$data['v6_prefix'])
   {
     warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
     return "";
   }
f9339935
   list($prefix, $null) = explode('/', $data['v6_prefix']);
6c54f23e
   $vh = ':1';
   if ($mode == 2) {
     $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
   }
f9339935
   $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
aeacb601
   return $ipv6;
 }
 
 
33819571
 function list_vhosts($domainname=NULL)
72518278
 {
   $uid = (int) $_SESSION['userinfo']['uid'];
33819571
   $query = "SELECT vh.id,fqdn,domain,docroot,docroot_is_default,php,cgi,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp, stats FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid=:uid ORDER BY domain,hostname";
   $params = array(":uid" => $uid);
   if ($domainname) {
     $query = "SELECT vh.id,fqdn,domain,docroot,docroot_is_default,php,cgi,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp, stats FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE domain=:domain AND uid=:uid ORDER BY hostname";
     $params[":domain"] = $domainname;
   }
   $result = db_query($query, $params);
72518278
   $ret = array();
f1f231f5
   while ($item = $result->fetch())
72518278
     array_push($ret, $item);
   return $ret;
 }
 
efb08fd7
 function ipv6_possible($server)
a6f3794e
 {
8132c40e
   $args = array(":server" => $server);
   $result = db_query("SELECT v6_prefix FROM system.servers WHERE id=:server OR hostname=:server", $args);
f1f231f5
   $line = $result->fetch();
efb08fd7
   DEBUG("Server {$server} is v6-capable: ". ($line['v6_prefix'] != NULL));
   return ($line['v6_prefix'] != NULL);
a6f3794e
 }
 
8d92bc6d
 function empty_vhost()
 {
da0e59cc
   $vhost['id'] = NULL;
68a22607
   $vhost['hostname'] = NULL;
8d92bc6d
   
c8b7c64c
   $vhost['domain_id'] = NULL;
   $vhost['domain'] = NULL;
8d92bc6d
   
   $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
   $vhost['docroot'] = NULL;
193e38bd
   $vhost['php'] = 'php56';
926f25db
   $vhost['cgi'] = 1;
fc35e698
   $vhost['ssl'] = NULL;
c5d2cce4
   $vhost['hsts'] = -1;
8160df9c
   $vhost['suexec_user'] = NULL;
5231fb2f
   $vhost['server'] = NULL;
8d92bc6d
   $vhost['logtype'] = NULL;
6b5987de
   $vhost['errorlog'] = 0;
7fb0aeba
   $vhost['is_dav'] = 0;
   $vhost['is_svn'] = 0;
   $vhost['is_webapp'] = 0;
1ab9db55
   $vhost['webapp_id'] = NULL;
   
   $vhost['cert'] = NULL;
6b5987de
   $vhost['certid'] = NULL;
918446fe
   $vhost['ipv4'] = NULL;
98fd4f66
   $vhost['autoipv6'] = 2; // 1 => Eine IP pro User, 2 => Eine IP pro VHost
1ab9db55
 
8d92bc6d
   $vhost['options'] = '';
56c4c2ac
   $vhost['stats'] = NULL;
8d92bc6d
   return $vhost;
 }
 
 
709c9ea2
 function empty_alias()
 {
68a22607
   $alias['hostname'] = NULL;
709c9ea2
   
f1d119a9
   $alias['domain_id'] = -1;
d96a86aa
   $alias['domain'] = $_SESSION['userinfo']['username'].'.'.config('masterdomain');
709c9ea2
   
68a22607
   $alias['options'] = NULL;
709c9ea2
   return $alias;
 }
 
 
c8b7c64c
 function userdomain() {
   if (config('user_vhosts_domain') === NULL) {
     return NULL;
   }
   $result = db_query("SELECT id,name FROM vhosts.v_domains WHERE name=:dom", array(":dom" => config('user_vhosts_domain')));
   $res = $result->fetch();
   return $res;
 }
 
0c8b89b3
 function user_uses_userdomain()
 {
   global $config;
   $uid = (int) $_SESSION['userinfo']['uid'];
   $userdomain = userdomain();
   $result = db_query("SELECT id FROM vhosts.vhost WHERE domain=:domid AND user=:uid", array(":uid" => $uid, ":domid" => $userdomain['id']));
   if ($result->rowCount() > 0) {
     DEBUG("User hat ".$result->rowCount()." Domains *.schokokeks.net");
     return True;
   }
   DEBUG("User hat keine Domains *.schokokeks.net");
   return false;
 }
c8b7c64c
 
8d92bc6d
 function domainselect($selected = NULL, $selectattribute = '')
72518278
 {
d96a86aa
   global $domainlist, $config;
72518278
   if ($domainlist == NULL)
     $domainlist = get_domain_list($_SESSION['customerinfo']['customerno'],
                                   $_SESSION['userinfo']['uid']);
   $selected = (int) $selected;
 
8d92bc6d
   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
f97ab0cd
   $found = false;
72518278
   foreach ($domainlist as $dom)
   {
f97ab0cd
     $s = '';
     if ($selected == $dom->id) {
       $s = ' selected="selected" ';
       $found = true;
     }
72518278
     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
   }
0c8b89b3
   $userdomain = userdomain();
   $user_needs_userdomain = $userdomain && (count($domainlist) == 0 || user_uses_userdomain());
   $user_needs_userdomain = $user_needs_userdomain || ($selected == -2);
   if (count($domainlist) > 0 && $user_needs_userdomain) {
c8b7c64c
     $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
   }
0c8b89b3
   if ($userdomain && (count($domainlist) == 0 || user_uses_userdomain())) {
c8b7c64c
     $s = ($selected == -1 ? ' selected="selected"' : '');
     $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
   }
0c8b89b3
   if ($selected == -2) {
     $s = ($selected == -2 ? ' selected="selected"' : '');
     $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
     if ($selected > 0 and ! $found) {
       system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
     }
f97ab0cd
   }
0c8b89b3
   $ret .= '</select>';
72518278
   return $ret;
 }
 
 
 
 function get_vhost_details($id)
 {
0c8b89b3
   DEBUG("Lese #{$id}...");
72518278
   $id = (int) $id;
   $uid = (int) $_SESSION['userinfo']['uid'];
8132c40e
   $result = db_query("SELECT vh.*,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid=:uid AND vh.id=:id", array(":uid" => $uid, ":id" => $id));
f1f231f5
   if ($result->rowCount() != 1)
72518278
     system_failure('Interner Fehler beim Auslesen der Daten');
 
f1f231f5
   $ret = $result->fetch();
96ea0412
 
c8b7c64c
   if ($ret['domain_id'] === NULL) {
     $ret['domain_id'] = -2;
   }
705192a6
   $ret['cert'] = $ret['certid'];
c8b7c64c
   $userdomain = userdomain();
   if ($ret['domain_id'] == $userdomain['id']) {
     $user = $_SESSION['userinfo']['username'];
     $ret['domain_id'] = -1;
     if ($ret['hostname'] == $user) {
       $ret['hostname'] = NULL;
193ff409
     } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
       $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
c8b7c64c
     } else {
       system_failure('Userdomain ohne Username!');
     }
   }
c5d2cce4
   if ($ret['hsts'] === NULL) {
     DEBUG('HSTS: '.$ret['hsts']);
     $ret['hsts'] = -1;
   }
96ea0412
   $ret['server'] = $ret['server_id'];
1ab9db55
   DEBUG($ret);
   return $ret;
72518278
 }
 
 
 function get_aliases($vhost)
 {
44996558
   $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", array($vhost));
72518278
   $ret = array();
f1f231f5
   while ($item = $result->fetch()) {
72518278
     array_push($ret, $item);
709c9ea2
   }
   return $ret;
 }
 
 
 
 function get_all_aliases($vhost)
 {
76f04610
   //$vhost = get_vhost_details( (int) $vhost );
709c9ea2
   $aliases = get_aliases($vhost['id']);
   $ret = array();
   if (strstr($vhost['options'], 'aliaswww')) {
68a22607
     array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : NULL)));
709c9ea2
   }
   foreach ($aliases as $item) {
     array_push($ret, $item);
     if (strstr($item['options'], 'aliaswww')) {
68a22607
       array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : NULL)));
709c9ea2
     }
   }
72518278
   return $ret;
 }
 
709c9ea2
 
3c2fddca
 function list_available_webapps()
 {
   $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
   $ret = array();
f1f231f5
   while ($item = $result->fetch())
3c2fddca
     array_push($ret, $item);
   return $ret;
 }
 
 
8d92bc6d
 function delete_vhost($id)
 {
   $id = (int) $id;
   if ($id == 0)
     system_failure("id == 0");
   $vhost = get_vhost_details($id);
3048f62f
   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
8132c40e
   db_query("DELETE FROM vhosts.vhost WHERE id=?", array($vhost['id']));
8d92bc6d
 }
 
709c9ea2
 
7fb0aeba
 
 function make_svn_vhost($id) 
 {
   $id = (int) $id;
   if ($id == 0)
     system_failure("id == 0");
3048f62f
   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
8132c40e
   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES (?, 'svn')", array($id));
   db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
7fb0aeba
 }
 
 function make_dav_vhost($id) 
 {
   $id = (int) $id;
   if ($id == 0)
     system_failure("id == 0");
3048f62f
   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
8132c40e
   db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES (?, 'dav', 'nouserfile')", array($id));
   db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
7fb0aeba
 }
 
3c2fddca
 function make_regular_vhost($id)
7fb0aeba
 {
   $id = (int) $id;
   if ($id == 0)
     system_failure("id == 0");
3048f62f
   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
8132c40e
   db_query("DELETE FROM vhosts.dav WHERE vhost=?", array($id));
   db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
7fb0aeba
 }
 
 
 function make_webapp_vhost($id, $webapp) 
 {
   $id = (int) $id;
   $webapp = (int) $webapp;
   if ($id == 0)
     system_failure("id == 0");
8132c40e
   $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", array($webapp));
f1f231f5
   if ($result->rowCount() == 0)
3c2fddca
     system_failure("webapp-id invalid");
f1f231f5
   $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
3048f62f
   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
8132c40e
   db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", array($id, $webapp));
3c2fddca
   mail('webapps-setup@schokokeks.org', 'setup', 'setup');
7fb0aeba
 }
 
 
0e9c1998
 function check_hostname_collision($hostname, $domain) 
 {
e4bde9b6
   $uid = (int) $_SESSION['userinfo']['uid'];
0e9c1998
   # Neuer vhost => Prüfe Duplikat
0c8b89b3
   $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
8132c40e
   $domaincheck = "domain=:domain";
0e9c1998
   if ($domain == -1) {
0c8b89b3
     $userdomain = userdomain();
     if ($hostname) {
       $hostname .= ".".$_SESSION['userinfo']['username'];
     }
     $args[":domain"] = $userdomain['id'];
c8b7c64c
   }
   if ($domain == -2) {
8132c40e
     unset($args[":domain"]);
0c8b89b3
     $domaincheck = "domain IS NULL";
0e9c1998
   }
0c8b89b3
   $hostnamecheck = "hostname=:hostname";
   if (! $hostname) {
     $hostnamecheck = "hostname IS NULL";
     unset($args[":hostname"]);
   }
   $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
f1f231f5
   if ($result->rowCount() > 0) {
0e9c1998
     system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
   }
0c8b89b3
   if ($domain <= -1) {
e4bde9b6
     return ;
   }
68e2d11b
   unset($args[":uid"]);
0c8b89b3
   $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
f1f231f5
   if ($result->rowCount() > 0) {
     $data = $result->fetch();
0e9c1998
     $vh = get_vhost_details($data['vhost']);
     system_failure('Dieser Hostname ist bereits als Alias für »'.$vh['fqdn'].'« eingerichtet');
   }
 }
 
8d92bc6d
 function save_vhost($vhost)
 {
   if (! is_array($vhost))
     system_failure('$vhost kein array!');
   $id = (int) $vhost['id'];
8132c40e
   $hostname = $vhost['hostname'];
56c4c2ac
   $domain = (int) $vhost['domain_id'];
8d92bc6d
   if ($domain == 0)
709c9ea2
     system_failure('$domain == 0');
c8b7c64c
   if ($vhost['domain_id'] == -2)
8132c40e
     $domain = NULL;
0eea1a0f
   if ($id == 0) {
0e9c1998
     check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
0eea1a0f
   }
c5d2cce4
   $hsts = (int) $vhost['hsts'];
   if ($hsts < 0) {
8132c40e
     $hsts = NULL;
c5d2cce4
   }
8132c40e
   $suexec_user = NULL;
8160df9c
 
   $available_suexec = available_suexec_users();
   foreach ($available_suexec AS $u)
     if ($u['uid'] == $vhost['suexec_user'])
       $suexec_user = $u['uid'];
 
8132c40e
   $server = NULL;
5231fb2f
   $available_servers = additional_servers();
   if (in_array($vhost['server'], $available_servers)) {
     $server = (int) $vhost['server'];
   }
   if ($server == my_server_id()) {
8132c40e
     $server = NULL;
5231fb2f
   }
 
125ebada
   if ($vhost['is_svn']) {
8132c40e
     if (! $vhost['options']) {
       $vhost['options']='nodocroot';
     } else {
6962c43c
       $vhost['options'].=",nodocroot";
8132c40e
     }
389f593a
   }
8d92bc6d
 
0b48c845
   $cert = NULL;
1ab9db55
   $certs = user_certs();
   foreach ($certs as $c)
     if ($c['id'] == $vhost['cert'])
       $cert = $c['id'];
 
8132c40e
   $ipv4 = NULL;
918446fe
   $ipv4_avail = user_ipaddrs();
   if (in_array($vhost['ipv4'], $ipv4_avail))
   {
8132c40e
     $ipv4 = $vhost['ipv4'];
918446fe
   }
3e7cffe2
 
6c54f23e
   $autoipv6 = 1;
   if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
     $autoipv6 = $vhost['autoipv6'];
   }
3e7cffe2
 
944e0c44
   if (!($vhost['ssl'] == 'forward' || $vhost['ssl'] == 'http' ||
         $vhost['ssl'] == 'https')) {
7881fa0e
     $vhost['ssl'] = NULL;
   }
 
0b48c845
   $args = array(":hostname" => ($hostname ? $hostname : NULL),
8132c40e
                 ":domain" => $domain,
7881fa0e
                 ":docroot" => ($vhost['docroot'] ? $vhost['docroot'] : NULL),
8132c40e
                 ":php" => $vhost['php'],
                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
                 ":ssl" => $vhost['ssl'],
                 ":hsts" => $hsts,
                 ":suexec_user" => $suexec_user,
                 ":server" => $server,
0b48c845
                 ":logtype" => ($vhost['logtype'] ? $vhost['logtype'] : NULL),
8132c40e
                 ":errorlog" => (int) $vhost['errorlog'],
                 ":cert" => $cert,
                 ":ipv4" => $ipv4,
                 ":autoipv6" => $autoipv6,
25321645
                 ":options" => $vhost['options'],
0b48c845
                 ":stats" => ($vhost['stats'] ? $vhost['stats'] : NULL),
8132c40e
                 ":id" => $id);
84aaa608
   if ($id != 0) {
3048f62f
     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
8132c40e
     db_query("UPDATE vhosts.vhost SET hostname=:hostname, domain=:domain, docroot=:docroot, php=:php, cgi=:cgi, `ssl`=:ssl, hsts=:hsts, `suexec_user`=:suexec_user, `server`=:server, logtype=:logtype, errorlog=:errorlog, certid=:cert, ipv4=:ipv4, autoipv6=:autoipv6, options=:options, stats=:stats WHERE id=:id", $args);
84aaa608
   }
   else {
8132c40e
     $args[":user"] = $_SESSION['userinfo']['uid'];
     unset($args[":id"]);
3048f62f
     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
8132c40e
     $result = db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, cgi, `ssl`, hsts, `suexec_user`, `server`, logtype, errorlog, certid, ipv4, autoipv6, options, stats) VALUES ".
                        "(:user, :hostname, :domain, :docroot, :php, :cgi, :ssl, :hsts, :suexec_user, :server, :logtype, :errorlog, :cert, :ipv4, :autoipv6, :options, :stats)", $args);
d88d35dc
     $id = db_insert_id();
84aaa608
   }
3c2fddca
   $oldvhost = get_vhost_details($id);
   /*
     these vars may be 0 or 1.
     So newval > oldval means that it has been switched on yet.
   */
   if ($vhost['is_dav'] > $oldvhost['is_dav'])
7fb0aeba
       make_dav_vhost($id);
3c2fddca
   elseif ($vhost['is_svn'] > $oldvhost['is_svn'])
7fb0aeba
       make_svn_vhost($id);
3c2fddca
   elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
       make_webapp_vhost($id, $vhost['webapp_id']);
   elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
       make_regular_vhost($id);
8d92bc6d
 }
 
 
709c9ea2
 function get_alias_details($id)
 {
   $id = (int) $id;
   $uid = (int) $_SESSION['userinfo']['uid'];
8132c40e
   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id=?", array($id));
709c9ea2
   
f1f231f5
   if ($result->rowCount() != 1)
709c9ea2
     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
   
f1f231f5
   $alias = $result->fetch();
f1d119a9
   
7acabcf1
   if ($alias['domain_id'] == NULL) {
f1d119a9
     $alias['domain_id'] = -1;
7acabcf1
   }
709c9ea2
 
   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
   get_vhost_details( (int) $alias['vhost'] );
 
   return $alias;
 }
 
 
 function delete_alias($id)
 {
   $id = (int) $id;
   $alias = get_alias_details($id);
 
3048f62f
   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
8132c40e
   db_query("DELETE FROM vhosts.alias WHERE id=?", array($id));
709c9ea2
 }
 
 function save_alias($alias)
 {
   if (! is_array($alias))
     system_failure('$alias kein array!');
b314bdc8
   $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
56c4c2ac
   $domain = (int) $alias['domain_id'];
709c9ea2
   if ($domain == 0)
     system_failure('$domain == 0');
c8b7c64c
   if ($alias['domain_id'] == -2)
8132c40e
     $domain = NULL;
709c9ea2
   $vhost = get_vhost_details( (int) $alias['vhost']);
748f9a75
   if (! $alias['hostname']) {
     $alias['hostname'] = NULL;
   }
8132c40e
   $args = array(":hostname" => $alias['hostname'],
                 ":domain" => $domain,
                 ":vhost" => $vhost['id'],
                 ":options" => $alias['options'],
                 ":id" => $id);
709c9ea2
   if ($id == 0) {
8132c40e
     unset($args[":id"]);
3048f62f
     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
8132c40e
     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args);
709c9ea2
   }
   else {
8132c40e
     unset($args[":vhost"]);
3048f62f
     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
8132c40e
     db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args);
709c9ea2
   }
 }
 
72518278
 
8160df9c
 function available_suexec_users()
 {
   $uid = (int) $_SESSION['userinfo']['uid'];
8132c40e
   $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", array($uid));
8160df9c
   $ret = array();
f1f231f5
   while ($i = $result->fetch())
8160df9c
     $ret[] = $i;
   DEBUG('available suexec-users:');
   DEBUG($ret);
   return $ret;
 
 }
72518278
 
1ab9db55
 
 function user_ipaddrs()
 {
   $uid = (int) $_SESSION['userinfo']['uid'];
8132c40e
   $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", array($uid));
1ab9db55
   $ret = array();
f1f231f5
   while ($i = $result->fetch())
1ab9db55
   {
     $ret[] = $i['ipaddr'];
   }
   DEBUG($ret);
   return $ret;
 }
 
 
72518278
 ?>