tbrehm
2009-05-05 24854cb22b746425ebad00aacd4af7e677666c03
Merged the following revisions from Trunk:

1153-1156
1176-1185
1187-1196

updated version number to 3.0.1.2
4 files added
48 files modified
7556 ■■■■ changed files
TODO.txt 2 ●●●●● patch | view | raw | blame | history
install/dist/lib/fedora.lib.php 4 ●●● patch | view | raw | blame | history
install/dist/lib/opensuse.lib.php 1756 ●●●● patch | view | raw | blame | history
install/lib/install.lib.php 47 ●●●● patch | view | raw | blame | history
install/lib/installer_base.lib.php 4 ●●● patch | view | raw | blame | history
install/sql/ispconfig3.sql 2830 ●●●● patch | view | raw | blame | history
install/tpl/apache_ispconfig.conf.master 2 ●●● patch | view | raw | blame | history
install/tpl/config.inc.php.master 4 ●●●● patch | view | raw | blame | history
install/tpl/pureftpd_mysql.conf.master 10 ●●●● patch | view | raw | blame | history
install/update.php 1 ●●●● patch | view | raw | blame | history
interface/lib/classes/tform.inc.php 6 ●●●● patch | view | raw | blame | history
interface/web/client/templates/client_edit_limits.htm 2 ●●● patch | view | raw | blame | history
interface/web/dns/dns_a_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_aaaa_edit.php 139 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_alias_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_cname_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_hinfo_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_mx_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_ns_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_ptr_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_rp_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_soa_edit.php 12 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_srv_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/dns_txt_edit.php 5 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_a.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_aaaa.tform.php 159 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_alias.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_cname.tform.php 18 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_hinfo.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_mx.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_ns.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_ptr.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_rp.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_srv.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/form/dns_txt.tform.php 16 ●●●●● patch | view | raw | blame | history
interface/web/dns/lib/lang/en_dns_aaaa.lng 15 ●●●●● patch | view | raw | blame | history
interface/web/dns/list/dns_a.list.php 2 ●●● patch | view | raw | blame | history
interface/web/dns/templates/dns_a_list.htm 167 ●●●● patch | view | raw | blame | history
interface/web/dns/templates/dns_aaaa_edit.htm 39 ●●●●● patch | view | raw | blame | history
interface/web/mail/mail_domain_catchall_edit.php 2 ●●● patch | view | raw | blame | history
interface/web/mail/mail_user_edit.php 2 ●●● patch | view | raw | blame | history
interface/web/sites/templates/web_domain_edit.htm 2 ●●● patch | view | raw | blame | history
server/conf/apache_ispconfig.conf.master 2 ●●● patch | view | raw | blame | history
server/conf/vhost.conf.master 10 ●●●● patch | view | raw | blame | history
server/lib/classes/modules.inc.php 447 ●●●● patch | view | raw | blame | history
server/mods-available/monitor_core_module.inc.php 5 ●●●●● patch | view | raw | blame | history
server/plugins-available/apache2_plugin.inc.php 1645 ●●●● patch | view | raw | blame | history
server/plugins-available/maildrop_plugin.inc.php 4 ●●●● patch | view | raw | blame | history
server/plugins-available/shelluser_base_plugin.inc.php 15 ●●●● patch | view | raw | blame | history
server/plugins-available/shelluser_jailkit_plugin.inc.php 3 ●●●●● patch | view | raw | blame | history
server/scripts/create_jailkit_user.sh 2 ●●● patch | view | raw | blame | history
server/server.php 4 ●●●● patch | view | raw | blame | history
TODO.txt
@@ -6,7 +6,6 @@
Please feel free to edit this file, add new tasks,
remove done tasks or assign yourself to a task.
Installer
--------------------------------------
@@ -71,7 +70,6 @@
Remoting framework
--------------------------------------
Interface
install/dist/lib/fedora.lib.php
@@ -83,7 +83,7 @@
        $postconf_commands = array (
            'myhostname = '.$conf['hostname'],
            'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
            'mynetworks = 127.0.0.0/8',
            'mynetworks = 127.0.0.0/8 [::1]/128',
            'virtual_alias_domains =',
            'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
            'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
@@ -554,6 +554,8 @@
        $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
        
        $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
        $content = str_replace('{language}', $conf['language'], $content);
        wf("$install_dir/interface/lib/$configfile", $content);
        
        //* Create the config file for ISPConfig server
install/dist/lib/opensuse.lib.php
@@ -1,878 +1,880 @@
<?php
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class installer_dist extends installer_base {
    function configure_postfix($options = '')
    {
        global $conf;
        $cf = $conf['postfix'];
        $config_dir = $cf['config_dir'];
        if(!is_dir($config_dir)){
            $this->error("The postfix configuration directory '$config_dir' does not exist.");
        }
        //* mysql-virtual_domains.cf
        $this->process_postfix_config('mysql-virtual_domains.cf');
        //* mysql-virtual_forwardings.cf
        $this->process_postfix_config('mysql-virtual_forwardings.cf');
        //* mysql-virtual_mailboxes.cf
        $this->process_postfix_config('mysql-virtual_mailboxes.cf');
        //* mysql-virtual_email2email.cf
        $this->process_postfix_config('mysql-virtual_email2email.cf');
        //* mysql-virtual_transports.cf
        $this->process_postfix_config('mysql-virtual_transports.cf');
        //* mysql-virtual_recipient.cf
        $this->process_postfix_config('mysql-virtual_recipient.cf');
        //* mysql-virtual_sender.cf
        $this->process_postfix_config('mysql-virtual_sender.cf');
        //* mysql-virtual_client.cf
        $this->process_postfix_config('mysql-virtual_client.cf');
        //* mysql-virtual_relaydomains.cf
        $this->process_postfix_config('mysql-virtual_relaydomains.cf');
        //* Changing mode and group of the new created config files.
        caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
                 __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
        caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
                __FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed');
        //* Creating virtual mail user and group
        $command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
        if(!is_group($cf['vmail_groupname'])) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
        if(!is_user($cf['vmail_username'])) caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $postconf_commands = array (
            'myhostname = '.$conf['hostname'],
            'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
            'mynetworks = 127.0.0.0/8',
            'virtual_alias_domains =',
            'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
            'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
            'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf',
            'virtual_mailbox_base = '.$cf['vmail_mailbox_base'],
            'virtual_uid_maps = static:'.$cf['vmail_userid'],
            'virtual_gid_maps = static:'.$cf['vmail_groupid'],
            'smtpd_sasl_auth_enable = yes',
            'broken_sasl_auth_clients = yes',
            'smtpd_sasl_authenticated_header = yes',
            'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination',
            'smtpd_use_tls = yes',
            'smtpd_tls_security_level = may',
            'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert',
            'smtpd_tls_key_file = '.$config_dir.'/smtpd.key',
            'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf',
            'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf',
            'virtual_create_maildirsize = yes',
            'virtual_maildir_extended = yes',
            'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf',
            'virtual_mailbox_limit_override = yes',
            'virtual_maildir_limit_message = "The user you are trying to reach is over quota."',
            'virtual_overquota_bounce = yes',
            'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps',
            'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf',
            'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf',
            'maildrop_destination_concurrency_limit = 1',
            'maildrop_destination_recipient_limit   = 1',
            'virtual_transport = maildrop',
            'header_checks = regexp:'.$config_dir.'/header_checks',
            'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks',
            'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks',
            'body_checks = regexp:'.$config_dir.'/body_checks',
            'inet_interfaces = all'
        );
        //* Create the header and body check files
        touch($config_dir.'/header_checks');
        touch($config_dir.'/mime_header_checks');
        touch($config_dir.'/nested_header_checks');
        touch($config_dir.'/body_checks');
        //* Make a backup copy of the main.cf file
        copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
        //* Executing the postconf commands
        foreach($postconf_commands as $cmd) {
            $command = "postconf -e '$cmd'";
            caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
        }
        if(!stristr($options,'dont-create-certs')) {
            //* Create the SSL certificate
            $command = 'cd '.$config_dir.'; '
                      .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509';
            exec($command);
            $command = 'chmod o= '.$config_dir.'/smtpd.key';
            caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
        }
        //** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
        $command = 'chmod 755  /var/run/authdaemon.courier-imap';
        caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
        //* Changing maildrop lines in posfix master.cf
        if(is_file($config_dir.'/master.cf')){
            copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
        }
        if(is_file($config_dir.'/master.cf~')){
            exec('chmod 400 '.$config_dir.'/master.cf~');
        }
        $configfile = $config_dir.'/master.cf';
        $content = rf($configfile);
        $content = str_replace('  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}',
                   '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
                     $content);
        $content = str_replace('  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}',
                   '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
                     $content);
        wf($configfile, $content);
        //* Writing the Maildrop mailfilter file
        $configfile = 'mailfilter';
        if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
            copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
        }
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
        wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
        //* Create the directory for the custom mailfilters
        $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
        caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Chmod and chown the .mailfilter file
        $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
        caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
        caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
    }
    public function configure_saslauthd() {
        global $conf;
        /*
        $configfile = 'sasl_smtpd.conf';
        if(is_file('/etc/sasl2/smtpd.conf')) copy('/etc/sasl2/smtpd.conf','/etc/sasl2/smtpd.conf~');
        if(is_file('/etc/sasl2/smtpd.conf~')) exec('chmod 400 '.'/etc/sasl2/smtpd.conf~');
        $content = rf("tpl/".$configfile.".master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
        wf('/etc/sasl2/smtpd.conf',$content);
        */
        // TODO: Chmod and chown on the config file
        /*
        // Create the spool directory
        exec('mkdir -p /var/spool/postfix/var/run/saslauthd');
        // Edit the file /etc/default/saslauthd
        $configfile = $conf["saslauthd"]["config"];
        if(is_file($configfile)) copy($configfile,$configfile.'~');
        if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
        $content = rf($configfile);
        $content = str_replace('START=no','START=yes',$content);
        $content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content);
        wf($configfile,$content);
        */
        // Edit the file /etc/init.d/saslauthd
        $configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"];
        $content = rf($configfile);
        $content = str_replace('/sbin/startproc $AUTHD_BIN -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
        $content = str_replace('/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
        wf($configfile,$content);
    }
    public function configure_pam()
    {
        global $conf;
        $pam = $conf['pam'];
        //* configure pam for SMTP authentication agains the ispconfig database
        $configfile = 'pamd_smtp';
        if(is_file("$pam/smtp"))    copy("$pam/smtp", "$pam/smtp~");
        if(is_file("$pam/smtp~"))   exec("chmod 400 $pam/smtp~");
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
        $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
        $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
        wf("$pam/smtp", $content);
        //exec("chmod 660 $pam/smtp");
        //exec("chown root:root $pam/smtp");
    }
    public function configure_courier()
    {
        global $conf;
        $config_dir = $conf['courier']['config_dir'];
        //* authmysqlrc
        $configfile = 'authmysqlrc';
        if(is_file("$config_dir/$configfile")){
            copy("$config_dir/$configfile", "$config_dir/$configfile~");
        }
        exec("chmod 400 $config_dir/$configfile~");
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
        wf("$config_dir/$configfile", $content);
        exec("chmod 660 $config_dir/$configfile");
        exec("chown root:root $config_dir/$configfile");
        //* authdaemonrc
        $configfile = $conf['courier']['config_dir'].'/authdaemonrc';
        if(is_file($configfile)){
            copy($configfile, $configfile.'~');
        }
        if(is_file($configfile.'~')){
            exec('chmod 400 '.$configfile.'~');
        }
        $content = rf($configfile);
        $content = str_replace('authmodulelist=', 'authmodulelist="authmysql"', $content);
        wf($configfile, $content);
    }
    public function configure_amavis() {
        global $conf;
        // amavisd user config file
        $configfile = 'opensuse_amavisd_conf';
        if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) copy($conf["amavis"]["config_dir"].'/amavisd.conf',$conf["courier"]["config_dir"].'/amavisd.conf~');
        if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
        $content = rf("tpl/".$configfile.".master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
        $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
        wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
        // Adding the amavisd commands to the postfix configuration
        $postconf_commands = array (
            'content_filter = amavis:[127.0.0.1]:10024',
            'receive_override_options = no_address_mappings'
        );
        // Make a backup copy of the main.cf file
        copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
        // Executing the postconf commands
        foreach($postconf_commands as $cmd) {
            $command = "postconf -e '$cmd'";
            caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        }
        // Append the configuration for amavisd to the master.cf file
        if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
        $content = rf($conf["postfix"]["config_dir"].'/master.cf');
        // Only add the content if we had not addded it before
        if(!stristr($content,"127.0.0.1:10025")) {
            unset($content);
            $content = rf("tpl/master_cf_amavis.master");
            af($conf["postfix"]["config_dir"].'/master.cf',$content);
        }
        unset($content);
        // Add the clamav user to the vscan group
        exec('groupmod --add-user clamav vscan');
    }
    public function configure_spamassassin()
    {
        global $conf;
        //* Enable spamasasssin on debian and ubuntu
        /*
        $configfile = '/etc/default/spamassassin';
        if(is_file($configfile)){
            copy($configfile, $configfile.'~');
        }
        $content = rf($configfile);
        $content = str_replace('ENABLED=0', 'ENABLED=1', $content);
        wf($configfile, $content);
        */
    }
    public function configure_getmail()
    {
        global $conf;
        $config_dir = $conf['getmail']['config_dir'];
        if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir));
        $command = "useradd -d $config_dir getmail";
        if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = "chown -R getmail $config_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = "chmod -R 700 $config_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
    }
    public function configure_pureftpd()
    {
        global $conf;
        $config_dir = $conf['pureftpd']['config_dir'];
        //* configure pam for SMTP authentication agains the ispconfig database
        $configfile = 'db/mysql.conf';
        if(is_file("$config_dir/$configfile")){
            copy("$config_dir/$configfile", "$config_dir/$configfile~");
        }
        if(is_file("$config_dir/$configfile~")){
            exec("chmod 400 $config_dir/$configfile~");
        }
        $content = rf('tpl/pureftpd_mysql.conf.master');
        $content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content);
        $content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content);
        $content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content);
        $content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content);
        $content = str_replace('{server_id}', $conf["server_id"], $content);
        wf("$config_dir/$configfile", $content);
        exec("chmod 600 $config_dir/$configfile");
        exec("chown root:root $config_dir/$configfile");
        // copy our customized copy of pureftpd.conf to the pure-ftpd config directory
        exec("cp tpl/opensuse_pureftpd_conf.master $config_dir/pure-ftpd.conf");
    }
    public function configure_mydns()
    {
        global $conf;
        // configure pam for SMTP authentication agains the ispconfig database
        $configfile = 'mydns.conf';
        if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~');
        if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~');
        $content = rf("tpl/".$configfile.".master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
        $content = str_replace('{server_id}',$conf["server_id"],$content);
        wf($conf["mydns"]["config_dir"].'/'.$configfile,$content);
        exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
        exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile);
    }
    public function configure_apache()
    {
        global $conf;
        //* Create the logging directory for the vhost logfiles
        exec('mkdir -p /var/log/ispconfig/httpd');
        //if(is_file('/etc/suphp.conf')) {
        replaceLine('/etc/suphp.conf','php=php','x-httpd-suphp=php:/srv/www/cgi-bin/php5',0,0);
        replaceLine('/etc/suphp.conf','docroot=','docroot=/srv/www',0,0);
        //}
        // Sites enabled and avaulable dirs
        exec('mkdir -p '.$conf['apache']['vhost_conf_enabled_dir']);
        exec('mkdir -p '.$conf['apache']['vhost_conf_dir']);
        $content = rf('/etc/apache2/httpd.conf');
        if(!stristr($content,'Include /etc/apache2/sites-enabled/')) {
            af('/etc/apache2/httpd.conf',"\n<Directory /srv/www>\n    Options FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
        }
        unset($content);
        //* Copy the ISPConfig configuration include
        $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
        $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
        //copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
        $content = rf("tpl/apache_ispconfig.conf.master");
        $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
        if(count($records) > 0) {
            foreach($records as $rec) {
                $content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
                $content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
            }
        }
        $content .= "\n";
        wf($vhost_conf_dir.'/ispconfig.conf',$content);
        if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
            exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
        }
    }
    public function configure_firewall()
    {
        global $conf;
        $dist_init_scripts = $conf['init_scripts'];
        if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__);
        if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__);
          @mkdir("/etc/Bastille", octdec($directory_mode));
          if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__);
          caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
          caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
          $content = rf("/etc/Bastille/bastille-firewall.cfg");
          $content = str_replace("{DNS_SERVERS}", "", $content);
          $tcp_public_services = '';
          $udp_public_services = '';
        $row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id']));
          if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
            $tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
            $udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
          } else {
            $tcp_public_services = '21 22 25 53 80 110 443 3306 8080 10000';
            $udp_public_services = '53';
          }
        if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) {
            $tcp_public_services .= ' '.intval($conf['apache']['vhost_port']);
            if($row["tcp_port"] != '') $this->db->query("UPDATE firewall SET tcp_port = tcp_port + ',".intval($conf['apache']['vhost_port'])."' WHERE server_id = ".intval($conf['server_id']));
        }
          $content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content);
          $content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content);
          wf("/etc/Bastille/bastille-firewall.cfg", $content);
          if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__);
          caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__);
          caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__);
          if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__);
          caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__);
          caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__);
          if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__);
          caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__);
          caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__);
        if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__);
          exec("which ipchains &> /dev/null", $ipchains_location, $ret_val);
          if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__);
          unset($ipchains_location);
          exec("which iptables &> /dev/null", $iptables_location, $ret_val);
          if(!is_file("/sbin/iptables") && !is_link("/sbin/iptables") && $ret_val == 0) phpcaselog(@symlink(trim(shell_exec("which iptables")), "/sbin/iptables"), 'create symlink', __FILE__, __LINE__);
          unset($iptables_location);
    }
    public function install_ispconfig()
    {
        global $conf;
        $install_dir = $conf['ispconfig_install_dir'];
        //* Create the ISPConfig installation directory
        if(!@is_dir("$install_dir")) {
            $command = "mkdir $install_dir";
            caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        }
        //* Create a ISPConfig user and group
        $command = 'groupadd ispconfig';
        if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = "useradd -g ispconfig -d $install_dir ispconfig";
        if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* copy the ISPConfig interface part
        $command = "cp -rf ../interface $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* copy the ISPConfig server part
        $command = "cp -rf ../server $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Create a symlink, so ISPConfig is accessible via web
        // Replaced by a separate vhost definition for port 8080
        // $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
        // caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Create the config file for ISPConfig interface
        $configfile = 'config.inc.php';
        if(is_file($install_dir.'/interface/lib/'.$configfile)){
            copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
        }
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
        $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
        $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
        $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
        $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
        wf("$install_dir/interface/lib/$configfile", $content);
        //* Create the config file for ISPConfig server
        $configfile = 'config.inc.php';
        if(is_file($install_dir.'/server/lib/'.$configfile)){
            copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
        }
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
        $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
        $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
        $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
        $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
        $content = str_replace('{server_id}', $conf['server_id'], $content);
        $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
        wf("$install_dir/server/lib/$configfile", $content);
        //* Enable the server modules and plugins.
        // TODO: Implement a selector which modules and plugins shall be enabled.
        $dir = $install_dir.'/server/mods-available/';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
                        include_once($install_dir.'/server/mods-available/'.$file);
                        $module_name = substr($file,0,-8);
                        $tmp = new $module_name;
                        if($tmp->onInstall()) {
                            if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
                            if (strpos($file, '_core_module') !== false) {
                                if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
                            }
                        }
                        unset($tmp);
                    }
                }
                closedir($dh);
            }
        }
        $dir = $install_dir.'/server/plugins-available/';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
                        include_once($install_dir.'/server/plugins-available/'.$file);
                        $plugin_name = substr($file,0,-8);
                        $tmp = new $plugin_name;
                        if($tmp->onInstall()) {
                            if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
                            if (strpos($file, '_core_plugin') !== false) {
                                if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
                            }
                        }
                        unset($tmp);
                    }
                }
                closedir($dh);
            }
        }
        // Update the server config
        $mail_server_enabled = ($conf['services']['mail'])?1:0;
        $web_server_enabled = ($conf['services']['web'])?1:0;
        $dns_server_enabled = ($conf['services']['dns'])?1:0;
        $file_server_enabled = ($conf['services']['file'])?1:0;
        $db_server_enabled = ($conf['services']['db'])?1:0;
        $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
        $sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled' WHERE server_id = ".intval($conf['server_id']);
        if($conf['mysql']['master_slave_setup'] == 'y') {
            $this->dbmaster->query($sql);
            $this->db->query($sql);
        } else {
            $this->db->query($sql);
        }
        //* Chmod the files
        $command = "chmod -R 750 $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* chown the files to the ispconfig user and group
        $command = "chown -R ispconfig:ispconfig $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Make the global language file directory group writable
        exec("chmod -R 770 $install_dir/interface/lib/lang");
        //* Make the temp directory for language file exports writable
        exec("chmod -R 770 $install_dir/interface/web/temp");
        //* Make all interface language file directories group writable
        $handle = @opendir($install_dir.'/interface/web');
        while ($file = @readdir ($handle)) {
               if ($file != '.' && $file != '..') {
                if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
                    $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
                    chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770);
                    while ($lang_file = @readdir ($handle2)) {
                        if ($lang_file != '.' && $lang_file != '..') {
                            chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770);
                        }
                    }
                }
            }
        }
        //* make sure that the server config file (not the interface one) is only readable by the root user
        exec("chmod 600 $install_dir/server/lib/$configfile");
        exec("chown root:root $install_dir/server/lib/$configfile");
        if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
            exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
            exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
        }
        // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
        // and must be fixed as this will allow the apache user to read the ispconfig files.
        // Later this must run as own apache server or via suexec!
        $command = 'groupmod --add-user wwwrun ispconfig';
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Make the shell scripts executable
        $command = "chmod +x $install_dir/server/scripts/*.sh";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Copy the ISPConfig vhost for the controlpanel
        // TODO: These are missing! should they be "vhost_dist_*_dir" ?
        $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
        $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
        // Dont just copy over the virtualhost template but add some custom settings
        $content = rf("tpl/apache_ispconfig.vhost.master");
        $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
        // comment out the listen directive if port is 80 or 443
        if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
            $content = str_replace('{vhost_port_listen}', '#', $content);
        } else {
            $content = str_replace('{vhost_port_listen}', '', $content);
        }
        $content = str_replace('/var/www/', '/srv/www/', $content);
        wf("$vhost_conf_dir/ispconfig.vhost", $content);
        if(!is_file('/srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
            exec('mkdir -p /srv/www/php-fcgi-scripts/ispconfig');
            exec('cp tpl/apache_ispconfig_fcgi_starter.master /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
            exec('chmod +x /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
            exec('ln -s /usr/local/ispconfig/interface/web /srv/www/ispconfig');
            exec('chown -R ispconfig:ispconfig /srv/www/php-fcgi-scripts/ispconfig');
        }
        //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
        //* and create the symlink
        if($this->install_ispconfig_interface == true && $this->is_update == false) {
            if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
            if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
                exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
            }
        }
        // Fix a setting in vhost master file for suse
        replaceLine('/usr/local/ispconfig/server/conf/vhost.conf.master',"suPHP_UserGroup","        suPHP_UserGroup <tmpl_var name='system_user'> <tmpl_var name='system_group'>",0);
        // Make the Clamav log files readable by ISPConfig
        //exec('chmod +r /var/log/clamav/clamav.log');
        //exec('chmod +r /var/log/clamav/freshclam.log');
        //* Install the update script
        if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
        exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
        exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
        exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
        exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
        exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
        exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
        if(!is_link('/usr/local/bin/ispconfig_update_from_svn.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_svn.sh');
        if(!is_link('/usr/local/bin/ispconfig_update.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update.sh');
        //set the fast cgi starter script to executable
        //exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
        //* Make the logs readable for the ispconfig user
        if(@is_file('/var/log/mail.log')) exec('chmod +r /var/log/mail.log');
        if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
        if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
        if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
        //To enable apache to read the directories
        exec('chmod a+rx /usr/local/ispconfig');
        exec('chmod -R 751 /usr/local/ispconfig/interface');
        exec('chmod a+rx /usr/local/ispconfig/interface/web');
        //* Create the ispconfig log directory
        if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig');
        if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log');
        exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh');
        exec('chown getmail /usr/local/bin/run-getmail.sh');
        exec('chmod 744 /usr/local/bin/run-getmail.sh');
    }
    public function configure_dbserver()
    {
        global $conf;
        //* If this server shall act as database server for client DB's, we configure this here
        $install_dir = $conf['ispconfig_install_dir'];
        // Create a file with the database login details which
        // are used to create the client databases.
        if(!is_dir("$install_dir/server/lib")) {
            $command = "mkdir $install_dir/server/lib";
            caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        }
        $content = rf("tpl/mysql_clientdb.conf.master");
        $content = str_replace('{username}',$conf['mysql']['admin_user'],$content);
        $content = str_replace('{password}',$conf['mysql']['admin_password'], $content);
        wf("$install_dir/server/lib/mysql_clientdb.conf",$content);
        exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf");
        exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf");
    }
    public function install_crontab()
    {
        global $conf;
        //* Root Crontab
        exec('crontab -u root -l > crontab.txt');
        $existing_root_cron_jobs = file('crontab.txt');
        // remove existing ispconfig cronjobs, in case the syntax has changed
        foreach($existing_root_cron_jobs as $key => $val) {
            if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
        }
        $root_cron_jobs = array(
            '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
            '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
        );
        foreach($root_cron_jobs as $cron_job) {
            if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
                $existing_root_cron_jobs[] = $cron_job."\n";
            }
        }
        file_put_contents('crontab.txt', $existing_root_cron_jobs);
        exec('crontab -u root crontab.txt &> /dev/null');
        unlink('crontab.txt');
        //* Getmail crontab
        if(is_user('getmail')) {
            $cf = $conf['getmail'];
            exec('crontab -u getmail -l > crontab.txt');
            $existing_cron_jobs = file('crontab.txt');
            $cron_jobs = array(
                '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log'
            );
            // remove existing ispconfig cronjobs, in case the syntax has changed
            foreach($existing_cron_jobs as $key => $val) {
                if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]);
            }
            foreach($cron_jobs as $cron_job) {
                if(!in_array($cron_job."\n", $existing_cron_jobs)) {
                    $existing_cron_jobs[] = $cron_job."\n";
                }
            }
            file_put_contents('crontab.txt', $existing_cron_jobs);
            exec('crontab -u getmail crontab.txt &> /dev/null');
            unlink('crontab.txt');
        }
        exec('touch /var/log/ispconfig/cron.log');
        exec('chmod 666 /var/log/ispconfig/cron.log');
    }
}
<?php
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class installer_dist extends installer_base {
    function configure_postfix($options = '')
    {
        global $conf;
        $cf = $conf['postfix'];
        $config_dir = $cf['config_dir'];
        if(!is_dir($config_dir)){
            $this->error("The postfix configuration directory '$config_dir' does not exist.");
        }
        //* mysql-virtual_domains.cf
        $this->process_postfix_config('mysql-virtual_domains.cf');
        //* mysql-virtual_forwardings.cf
        $this->process_postfix_config('mysql-virtual_forwardings.cf');
        //* mysql-virtual_mailboxes.cf
        $this->process_postfix_config('mysql-virtual_mailboxes.cf');
        //* mysql-virtual_email2email.cf
        $this->process_postfix_config('mysql-virtual_email2email.cf');
        //* mysql-virtual_transports.cf
        $this->process_postfix_config('mysql-virtual_transports.cf');
        //* mysql-virtual_recipient.cf
        $this->process_postfix_config('mysql-virtual_recipient.cf');
        //* mysql-virtual_sender.cf
        $this->process_postfix_config('mysql-virtual_sender.cf');
        //* mysql-virtual_client.cf
        $this->process_postfix_config('mysql-virtual_client.cf');
        //* mysql-virtual_relaydomains.cf
        $this->process_postfix_config('mysql-virtual_relaydomains.cf');
        //* Changing mode and group of the new created config files.
        caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
                 __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
        caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
                __FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed');
        //* Creating virtual mail user and group
        $command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
        if(!is_group($cf['vmail_groupname'])) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
        if(!is_user($cf['vmail_username'])) caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $postconf_commands = array (
            'myhostname = '.$conf['hostname'],
            'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
            'mynetworks = 127.0.0.0/8 [::1]/128',
            'virtual_alias_domains =',
            'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
            'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
            'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf',
            'virtual_mailbox_base = '.$cf['vmail_mailbox_base'],
            'virtual_uid_maps = static:'.$cf['vmail_userid'],
            'virtual_gid_maps = static:'.$cf['vmail_groupid'],
            'smtpd_sasl_auth_enable = yes',
            'broken_sasl_auth_clients = yes',
            'smtpd_sasl_authenticated_header = yes',
            'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination',
            'smtpd_use_tls = yes',
            'smtpd_tls_security_level = may',
            'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert',
            'smtpd_tls_key_file = '.$config_dir.'/smtpd.key',
            'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf',
            'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf',
            'virtual_create_maildirsize = yes',
            'virtual_maildir_extended = yes',
            'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf',
            'virtual_mailbox_limit_override = yes',
            'virtual_maildir_limit_message = "The user you are trying to reach is over quota."',
            'virtual_overquota_bounce = yes',
            'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps',
            'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf',
            'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf',
            'maildrop_destination_concurrency_limit = 1',
            'maildrop_destination_recipient_limit   = 1',
            'virtual_transport = maildrop',
            'header_checks = regexp:'.$config_dir.'/header_checks',
            'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks',
            'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks',
            'body_checks = regexp:'.$config_dir.'/body_checks',
            'inet_interfaces = all'
        );
        //* Create the header and body check files
        touch($config_dir.'/header_checks');
        touch($config_dir.'/mime_header_checks');
        touch($config_dir.'/nested_header_checks');
        touch($config_dir.'/body_checks');
        //* Make a backup copy of the main.cf file
        copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
        //* Executing the postconf commands
        foreach($postconf_commands as $cmd) {
            $command = "postconf -e '$cmd'";
            caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
        }
        if(!stristr($options,'dont-create-certs')) {
            //* Create the SSL certificate
            $command = 'cd '.$config_dir.'; '
                      .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509';
            exec($command);
            $command = 'chmod o= '.$config_dir.'/smtpd.key';
            caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
        }
        //** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
        $command = 'chmod 755  /var/run/authdaemon.courier-imap';
        caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
        //* Changing maildrop lines in posfix master.cf
        if(is_file($config_dir.'/master.cf')){
            copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
        }
        if(is_file($config_dir.'/master.cf~')){
            exec('chmod 400 '.$config_dir.'/master.cf~');
        }
        $configfile = $config_dir.'/master.cf';
        $content = rf($configfile);
        $content = str_replace('  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}',
                   '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
                     $content);
        $content = str_replace('  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}',
                   '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
                     $content);
        wf($configfile, $content);
        //* Writing the Maildrop mailfilter file
        $configfile = 'mailfilter';
        if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
            copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
        }
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
        wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
        //* Create the directory for the custom mailfilters
        $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
        caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Chmod and chown the .mailfilter file
        $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
        caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
        caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
    }
    public function configure_saslauthd() {
        global $conf;
        /*
        $configfile = 'sasl_smtpd.conf';
        if(is_file('/etc/sasl2/smtpd.conf')) copy('/etc/sasl2/smtpd.conf','/etc/sasl2/smtpd.conf~');
        if(is_file('/etc/sasl2/smtpd.conf~')) exec('chmod 400 '.'/etc/sasl2/smtpd.conf~');
        $content = rf("tpl/".$configfile.".master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
        wf('/etc/sasl2/smtpd.conf',$content);
        */
        // TODO: Chmod and chown on the config file
        /*
        // Create the spool directory
        exec('mkdir -p /var/spool/postfix/var/run/saslauthd');
        // Edit the file /etc/default/saslauthd
        $configfile = $conf["saslauthd"]["config"];
        if(is_file($configfile)) copy($configfile,$configfile.'~');
        if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
        $content = rf($configfile);
        $content = str_replace('START=no','START=yes',$content);
        $content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content);
        wf($configfile,$content);
        */
        // Edit the file /etc/init.d/saslauthd
        $configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"];
        $content = rf($configfile);
        $content = str_replace('/sbin/startproc $AUTHD_BIN -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
        $content = str_replace('/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
        wf($configfile,$content);
    }
    public function configure_pam()
    {
        global $conf;
        $pam = $conf['pam'];
        //* configure pam for SMTP authentication agains the ispconfig database
        $configfile = 'pamd_smtp';
        if(is_file("$pam/smtp"))    copy("$pam/smtp", "$pam/smtp~");
        if(is_file("$pam/smtp~"))   exec("chmod 400 $pam/smtp~");
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
        $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
        $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
        wf("$pam/smtp", $content);
        //exec("chmod 660 $pam/smtp");
        //exec("chown root:root $pam/smtp");
    }
    public function configure_courier()
    {
        global $conf;
        $config_dir = $conf['courier']['config_dir'];
        //* authmysqlrc
        $configfile = 'authmysqlrc';
        if(is_file("$config_dir/$configfile")){
            copy("$config_dir/$configfile", "$config_dir/$configfile~");
        }
        exec("chmod 400 $config_dir/$configfile~");
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
        wf("$config_dir/$configfile", $content);
        exec("chmod 660 $config_dir/$configfile");
        exec("chown root:root $config_dir/$configfile");
        //* authdaemonrc
        $configfile = $conf['courier']['config_dir'].'/authdaemonrc';
        if(is_file($configfile)){
            copy($configfile, $configfile.'~');
        }
        if(is_file($configfile.'~')){
            exec('chmod 400 '.$configfile.'~');
        }
        $content = rf($configfile);
        $content = str_replace('authmodulelist=', 'authmodulelist="authmysql"', $content);
        wf($configfile, $content);
    }
    public function configure_amavis() {
        global $conf;
        // amavisd user config file
        $configfile = 'opensuse_amavisd_conf';
        if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) copy($conf["amavis"]["config_dir"].'/amavisd.conf',$conf["courier"]["config_dir"].'/amavisd.conf~');
        if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
        $content = rf("tpl/".$configfile.".master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
        $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
        wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
        // Adding the amavisd commands to the postfix configuration
        $postconf_commands = array (
            'content_filter = amavis:[127.0.0.1]:10024',
            'receive_override_options = no_address_mappings'
        );
        // Make a backup copy of the main.cf file
        copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
        // Executing the postconf commands
        foreach($postconf_commands as $cmd) {
            $command = "postconf -e '$cmd'";
            caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        }
        // Append the configuration for amavisd to the master.cf file
        if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
        $content = rf($conf["postfix"]["config_dir"].'/master.cf');
        // Only add the content if we had not addded it before
        if(!stristr($content,"127.0.0.1:10025")) {
            unset($content);
            $content = rf("tpl/master_cf_amavis.master");
            af($conf["postfix"]["config_dir"].'/master.cf',$content);
        }
        unset($content);
        // Add the clamav user to the vscan group
        exec('groupmod --add-user clamav vscan');
    }
    public function configure_spamassassin()
    {
        global $conf;
        //* Enable spamasasssin on debian and ubuntu
        /*
        $configfile = '/etc/default/spamassassin';
        if(is_file($configfile)){
            copy($configfile, $configfile.'~');
        }
        $content = rf($configfile);
        $content = str_replace('ENABLED=0', 'ENABLED=1', $content);
        wf($configfile, $content);
        */
    }
    public function configure_getmail()
    {
        global $conf;
        $config_dir = $conf['getmail']['config_dir'];
        if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir));
        $command = "useradd -d $config_dir getmail";
        if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = "chown -R getmail $config_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = "chmod -R 700 $config_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
    }
    public function configure_pureftpd()
    {
        global $conf;
        $config_dir = $conf['pureftpd']['config_dir'];
        //* configure pam for SMTP authentication agains the ispconfig database
        $configfile = 'db/mysql.conf';
        if(is_file("$config_dir/$configfile")){
            copy("$config_dir/$configfile", "$config_dir/$configfile~");
        }
        if(is_file("$config_dir/$configfile~")){
            exec("chmod 400 $config_dir/$configfile~");
        }
        $content = rf('tpl/pureftpd_mysql.conf.master');
        $content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content);
        $content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content);
        $content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content);
        $content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content);
        $content = str_replace('{server_id}', $conf["server_id"], $content);
        wf("$config_dir/$configfile", $content);
        exec("chmod 600 $config_dir/$configfile");
        exec("chown root:root $config_dir/$configfile");
        // copy our customized copy of pureftpd.conf to the pure-ftpd config directory
        exec("cp tpl/opensuse_pureftpd_conf.master $config_dir/pure-ftpd.conf");
    }
    public function configure_mydns()
    {
        global $conf;
        // configure pam for SMTP authentication agains the ispconfig database
        $configfile = 'mydns.conf';
        if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~');
        if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~');
        $content = rf("tpl/".$configfile.".master");
        $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
        $content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
        $content = str_replace('{server_id}',$conf["server_id"],$content);
        wf($conf["mydns"]["config_dir"].'/'.$configfile,$content);
        exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
        exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile);
    }
    public function configure_apache()
    {
        global $conf;
        //* Create the logging directory for the vhost logfiles
        exec('mkdir -p /var/log/ispconfig/httpd');
        //if(is_file('/etc/suphp.conf')) {
        replaceLine('/etc/suphp.conf','php=php','x-httpd-suphp=php:/srv/www/cgi-bin/php5',0,0);
        replaceLine('/etc/suphp.conf','docroot=','docroot=/srv/www',0,0);
        //}
        // Sites enabled and avaulable dirs
        exec('mkdir -p '.$conf['apache']['vhost_conf_enabled_dir']);
        exec('mkdir -p '.$conf['apache']['vhost_conf_dir']);
        $content = rf('/etc/apache2/httpd.conf');
        if(!stristr($content,'Include /etc/apache2/sites-enabled/')) {
            af('/etc/apache2/httpd.conf',"\n<Directory /srv/www>\n    Options FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
        }
        unset($content);
        //* Copy the ISPConfig configuration include
        $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
        $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
        //copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
        $content = rf("tpl/apache_ispconfig.conf.master");
        $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
        if(count($records) > 0) {
            foreach($records as $rec) {
                $content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
                $content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
            }
        }
        $content .= "\n";
        wf($vhost_conf_dir.'/ispconfig.conf',$content);
        if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
            exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
        }
    }
    public function configure_firewall()
    {
        global $conf;
        $dist_init_scripts = $conf['init_scripts'];
        if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__);
        if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__);
          @mkdir("/etc/Bastille", octdec($directory_mode));
          if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__);
          caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
          caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
          $content = rf("/etc/Bastille/bastille-firewall.cfg");
          $content = str_replace("{DNS_SERVERS}", "", $content);
          $tcp_public_services = '';
          $udp_public_services = '';
        $row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id']));
          if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
            $tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
            $udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
          } else {
            $tcp_public_services = '21 22 25 53 80 110 443 3306 8080 10000';
            $udp_public_services = '53';
          }
        if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) {
            $tcp_public_services .= ' '.intval($conf['apache']['vhost_port']);
            if($row["tcp_port"] != '') $this->db->query("UPDATE firewall SET tcp_port = tcp_port + ',".intval($conf['apache']['vhost_port'])."' WHERE server_id = ".intval($conf['server_id']));
        }
          $content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content);
          $content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content);
          wf("/etc/Bastille/bastille-firewall.cfg", $content);
          if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__);
          caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__);
          caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__);
          if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__);
          caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__);
          caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__);
          if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__);
          caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__);
          caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__);
        if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__);
          exec("which ipchains &> /dev/null", $ipchains_location, $ret_val);
          if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__);
          unset($ipchains_location);
          exec("which iptables &> /dev/null", $iptables_location, $ret_val);
          if(!is_file("/sbin/iptables") && !is_link("/sbin/iptables") && $ret_val == 0) phpcaselog(@symlink(trim(shell_exec("which iptables")), "/sbin/iptables"), 'create symlink', __FILE__, __LINE__);
          unset($iptables_location);
    }
    public function install_ispconfig()
    {
        global $conf;
        $install_dir = $conf['ispconfig_install_dir'];
        //* Create the ISPConfig installation directory
        if(!@is_dir("$install_dir")) {
            $command = "mkdir $install_dir";
            caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        }
        //* Create a ISPConfig user and group
        $command = 'groupadd ispconfig';
        if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        $command = "useradd -g ispconfig -d $install_dir ispconfig";
        if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* copy the ISPConfig interface part
        $command = "cp -rf ../interface $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* copy the ISPConfig server part
        $command = "cp -rf ../server $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Create a symlink, so ISPConfig is accessible via web
        // Replaced by a separate vhost definition for port 8080
        // $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
        // caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Create the config file for ISPConfig interface
        $configfile = 'config.inc.php';
        if(is_file($install_dir.'/interface/lib/'.$configfile)){
            copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
        }
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
        $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
        $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
        $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
        $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
        $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
        $content = str_replace('{language}', $conf['language'], $content);
        wf("$install_dir/interface/lib/$configfile", $content);
        //* Create the config file for ISPConfig server
        $configfile = 'config.inc.php';
        if(is_file($install_dir.'/server/lib/'.$configfile)){
            copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
        }
        $content = rf("tpl/$configfile.master");
        $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
        $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
        $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
        $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
        $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
        $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
        $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
        $content = str_replace('{server_id}', $conf['server_id'], $content);
        $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
        wf("$install_dir/server/lib/$configfile", $content);
        //* Enable the server modules and plugins.
        // TODO: Implement a selector which modules and plugins shall be enabled.
        $dir = $install_dir.'/server/mods-available/';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
                        include_once($install_dir.'/server/mods-available/'.$file);
                        $module_name = substr($file,0,-8);
                        $tmp = new $module_name;
                        if($tmp->onInstall()) {
                            if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
                            if (strpos($file, '_core_module') !== false) {
                                if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
                            }
                        }
                        unset($tmp);
                    }
                }
                closedir($dh);
            }
        }
        $dir = $install_dir.'/server/plugins-available/';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
                        include_once($install_dir.'/server/plugins-available/'.$file);
                        $plugin_name = substr($file,0,-8);
                        $tmp = new $plugin_name;
                        if($tmp->onInstall()) {
                            if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
                            if (strpos($file, '_core_plugin') !== false) {
                                if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
                            }
                        }
                        unset($tmp);
                    }
                }
                closedir($dh);
            }
        }
        // Update the server config
        $mail_server_enabled = ($conf['services']['mail'])?1:0;
        $web_server_enabled = ($conf['services']['web'])?1:0;
        $dns_server_enabled = ($conf['services']['dns'])?1:0;
        $file_server_enabled = ($conf['services']['file'])?1:0;
        $db_server_enabled = ($conf['services']['db'])?1:0;
        $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
        $sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled' WHERE server_id = ".intval($conf['server_id']);
        if($conf['mysql']['master_slave_setup'] == 'y') {
            $this->dbmaster->query($sql);
            $this->db->query($sql);
        } else {
            $this->db->query($sql);
        }
        //* Chmod the files
        $command = "chmod -R 750 $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* chown the files to the ispconfig user and group
        $command = "chown -R ispconfig:ispconfig $install_dir";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Make the global language file directory group writable
        exec("chmod -R 770 $install_dir/interface/lib/lang");
        //* Make the temp directory for language file exports writable
        exec("chmod -R 770 $install_dir/interface/web/temp");
        //* Make all interface language file directories group writable
        $handle = @opendir($install_dir.'/interface/web');
        while ($file = @readdir ($handle)) {
               if ($file != '.' && $file != '..') {
                if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
                    $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
                    chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770);
                    while ($lang_file = @readdir ($handle2)) {
                        if ($lang_file != '.' && $lang_file != '..') {
                            chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770);
                        }
                    }
                }
            }
        }
        //* make sure that the server config file (not the interface one) is only readable by the root user
        exec("chmod 600 $install_dir/server/lib/$configfile");
        exec("chown root:root $install_dir/server/lib/$configfile");
        if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
            exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
            exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
        }
        // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
        // and must be fixed as this will allow the apache user to read the ispconfig files.
        // Later this must run as own apache server or via suexec!
        $command = 'groupmod --add-user wwwrun ispconfig';
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Make the shell scripts executable
        $command = "chmod +x $install_dir/server/scripts/*.sh";
        caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        //* Copy the ISPConfig vhost for the controlpanel
        // TODO: These are missing! should they be "vhost_dist_*_dir" ?
        $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
        $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
        // Dont just copy over the virtualhost template but add some custom settings
        $content = rf("tpl/apache_ispconfig.vhost.master");
        $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
        // comment out the listen directive if port is 80 or 443
        if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
            $content = str_replace('{vhost_port_listen}', '#', $content);
        } else {
            $content = str_replace('{vhost_port_listen}', '', $content);
        }
        $content = str_replace('/var/www/', '/srv/www/', $content);
        wf("$vhost_conf_dir/ispconfig.vhost", $content);
        if(!is_file('/srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
            exec('mkdir -p /srv/www/php-fcgi-scripts/ispconfig');
            exec('cp tpl/apache_ispconfig_fcgi_starter.master /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
            exec('chmod +x /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
            exec('ln -s /usr/local/ispconfig/interface/web /srv/www/ispconfig');
            exec('chown -R ispconfig:ispconfig /srv/www/php-fcgi-scripts/ispconfig');
        }
        //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
        //* and create the symlink
        if($this->install_ispconfig_interface == true && $this->is_update == false) {
            if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
            if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
                exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
            }
        }
        // Fix a setting in vhost master file for suse
        replaceLine('/usr/local/ispconfig/server/conf/vhost.conf.master',"suPHP_UserGroup","        suPHP_UserGroup <tmpl_var name='system_user'> <tmpl_var name='system_group'>",0);
        // Make the Clamav log files readable by ISPConfig
        //exec('chmod +r /var/log/clamav/clamav.log');
        //exec('chmod +r /var/log/clamav/freshclam.log');
        //* Install the update script
        if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
        exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
        exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
        exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
        exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
        exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
        exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
        if(!is_link('/usr/local/bin/ispconfig_update_from_svn.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_svn.sh');
        if(!is_link('/usr/local/bin/ispconfig_update.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update.sh');
        //set the fast cgi starter script to executable
        //exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
        //* Make the logs readable for the ispconfig user
        if(@is_file('/var/log/mail.log')) exec('chmod +r /var/log/mail.log');
        if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
        if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
        if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
        //To enable apache to read the directories
        exec('chmod a+rx /usr/local/ispconfig');
        exec('chmod -R 751 /usr/local/ispconfig/interface');
        exec('chmod a+rx /usr/local/ispconfig/interface/web');
        //* Create the ispconfig log directory
        if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig');
        if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log');
        exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh');
        exec('chown getmail /usr/local/bin/run-getmail.sh');
        exec('chmod 744 /usr/local/bin/run-getmail.sh');
    }
    public function configure_dbserver()
    {
        global $conf;
        //* If this server shall act as database server for client DB's, we configure this here
        $install_dir = $conf['ispconfig_install_dir'];
        // Create a file with the database login details which
        // are used to create the client databases.
        if(!is_dir("$install_dir/server/lib")) {
            $command = "mkdir $install_dir/server/lib";
            caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
        }
        $content = rf("tpl/mysql_clientdb.conf.master");
        $content = str_replace('{username}',$conf['mysql']['admin_user'],$content);
        $content = str_replace('{password}',$conf['mysql']['admin_password'], $content);
        wf("$install_dir/server/lib/mysql_clientdb.conf",$content);
        exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf");
        exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf");
    }
    public function install_crontab()
    {
        global $conf;
        //* Root Crontab
        exec('crontab -u root -l > crontab.txt');
        $existing_root_cron_jobs = file('crontab.txt');
        // remove existing ispconfig cronjobs, in case the syntax has changed
        foreach($existing_root_cron_jobs as $key => $val) {
            if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
        }
        $root_cron_jobs = array(
            '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
            '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
        );
        foreach($root_cron_jobs as $cron_job) {
            if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
                $existing_root_cron_jobs[] = $cron_job."\n";
            }
        }
        file_put_contents('crontab.txt', $existing_root_cron_jobs);
        exec('crontab -u root crontab.txt &> /dev/null');
        unlink('crontab.txt');
        //* Getmail crontab
        if(is_user('getmail')) {
            $cf = $conf['getmail'];
            exec('crontab -u getmail -l > crontab.txt');
            $existing_cron_jobs = file('crontab.txt');
            $cron_jobs = array(
                '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log'
            );
            // remove existing ispconfig cronjobs, in case the syntax has changed
            foreach($existing_cron_jobs as $key => $val) {
                if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]);
            }
            foreach($cron_jobs as $cron_job) {
                if(!in_array($cron_job."\n", $existing_cron_jobs)) {
                    $existing_cron_jobs[] = $cron_job."\n";
                }
            }
            file_put_contents('crontab.txt', $existing_cron_jobs);
            exec('crontab -u getmail crontab.txt &> /dev/null');
            unlink('crontab.txt');
        }
        exec('touch /var/log/ispconfig/cron.log');
        exec('chmod 666 /var/log/ispconfig/cron.log');
    }
}
?>
install/lib/install.lib.php
@@ -59,6 +59,9 @@
function get_distname() {
    
    $distname = '';
    $distver = '';
    $distid = '';
    $distbaseid = '';
    
    //** Debian or Ubuntu
    if(file_exists('/etc/debian_version')) {
@@ -69,13 +72,18 @@
            $distid = 'debian40';
            $distbaseid = 'debian';
            swriteln("Operating System: Debian 4.0 or compatible\n");
        }
        if(trim(file_get_contents('/etc/debian_version')) == '5.0' || trim(file_get_contents('/etc/debian_version')) == 'lenny/sid') {
        } elseif(strstr(trim(file_get_contents('/etc/debian_version')),'5.0') || trim(file_get_contents('/etc/debian_version')) == 'lenny/sid') {
            $distname = 'Debian';
            $distver = 'Lenny/Sid';
            $distid = 'debian40';
            $distbaseid = 'debian';
            swriteln("Operating System: Debian Lenny/Sid or compatible\n");
        }  else {
            $distname = 'Debian';
            $distver = 'Unknown';
            $distid = 'debian40';
            $distbaseid = 'debian';
            swriteln("Operating System: Debian or compatible, unknown version.\n");
        }
    }
    
@@ -87,13 +95,24 @@
            $distid = 'opensuse110';
            $distbaseid = 'opensuse';
            swriteln("Operating System: openSUSE 11.0 or compatible\n");
        }
        if(stristr(file_get_contents('/etc/SuSE-release'),'11.1')) {
        } elseif(stristr(file_get_contents('/etc/SuSE-release'),'11.1')) {
            $distname = 'openSUSE';
            $distver = '11.1';
            $distid = 'opensuse110';
            $distbaseid = 'opensuse';
            swriteln("Operating System: openSUSE 11.1 or compatible\n");
        } elseif(stristr(file_get_contents('/etc/SuSE-release'),'11.2')) {
            $distname = 'openSUSE';
            $distver = '11.1';
            $distid = 'opensuse110';
            $distbaseid = 'opensuse';
            swriteln("Operating System: openSUSE 11.2 or compatible\n");
        }  else {
            $distname = 'openSUSE';
            $distver = 'Unknown';
            $distid = 'opensuse110';
            $distbaseid = 'opensuse';
            swriteln("Operating System: openSUSE or compatible, unknown version.\n");
        }
    }
    
@@ -109,22 +128,30 @@
            $distid = 'fedora9';
            $distbaseid = 'fedora';
            swriteln("Operating System: Fedora 9 or compatible\n");
        }
        if(stristr($content,'Fedora release 10 (Cambridge)')) {
        } elseif(stristr($content,'Fedora release 10 (Cambridge)')) {
            $distname = 'Fedora';
            $distver = '10';
            $distid = 'fedora9';
            $distbaseid = 'fedora';
            swriteln("Operating System: Fedora 10 or compatible\n");
        }
        if(stristr($content,'CentOS release 5.2 (Final)')) {
        } elseif(stristr($content,'CentOS release 5.2 (Final)')) {
            $distname = 'CentOS';
            $distver = '5.2';
            $distid = 'centos52';
            $distbaseid = 'fedora';
            swriteln("Operating System: CentOS 5.2 or compatible\n");
        } elseif(stristr($content,'CentOS release 5.3 (Final)')) {
            $distname = 'CentOS';
            $distver = '5.3';
            $distid = 'centos52';
            $distbaseid = 'fedora';
            swriteln("Operating System: CentOS 5.3 or compatible\n");
        } else {
            $distname = 'Redhat';
            $distver = 'Unknown';
            $distid = 'fedora9';
            $distbaseid = 'fedora';
            swriteln("Operating System: Redhat or compatible, unknown version.\n");
        }
        
        
install/lib/installer_base.lib.php
@@ -366,7 +366,7 @@
        $postconf_commands = array (
            'myhostname = '.$conf['hostname'],
            'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
            'mynetworks = 127.0.0.0/8',
            'mynetworks = 127.0.0.0/8 [::1]/128',
            'virtual_alias_domains =',
            'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
            'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
@@ -857,6 +857,8 @@
        $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
        
        $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
        $content = str_replace('{language}', $conf['language'], $content);
        wf("$install_dir/interface/lib/$configfile", $content);
        
        //* Create the config file for ISPConfig server
install/sql/ispconfig3.sql
@@ -1,1414 +1,1416 @@
/*
Copyright (c) 2007-2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
--
-- ISPConfig 3
-- DB-Version: 3.0.0.9
--
SET FOREIGN_KEY_CHECKS = 0;
-- --------------------------------------------------------
-- --------------------------------------------------------
-- DB-STRUCTURE
-- --------------------------------------------------------
-- --------------------------------------------------------
--
-- Table structure for table  `client`
--
CREATE TABLE `client` (
  `client_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `company_name` varchar(64) default NULL,
  `contact_name` varchar(64) default NULL,
  `street` varchar(255) default NULL,
  `zip` varchar(32) default NULL,
  `city` varchar(64) default NULL,
  `state` varchar(32) default NULL,
  `country` char(2) default NULL,
  `telephone` varchar(32) default NULL,
  `mobile` varchar(32) default NULL,
  `fax` varchar(32) default NULL,
  `email` varchar(255) default NULL,
  `internet` varchar(255) NOT NULL,
  `icq` varchar(16) default NULL,
  `notes` text,
  `default_mailserver` int(11) unsigned NOT NULL default '1',
  `limit_maildomain` int(11) NOT NULL default '-1',
  `limit_mailbox` int(11) NOT NULL default '-1',
  `limit_mailalias` int(11) NOT NULL default '-1',
  `limit_mailforward` int(11) NOT NULL default '-1',
  `limit_mailcatchall` int(11) NOT NULL default '-1',
  `limit_mailrouting` int(11) NOT NULL default '0',
  `limit_mailfilter` int(11) NOT NULL default '-1',
  `limit_fetchmail` int(11) NOT NULL default '-1',
  `limit_mailquota` int(11) NOT NULL default '-1',
  `limit_spamfilter_wblist` int(11) NOT NULL default '0',
  `limit_spamfilter_user` int(11) NOT NULL default '0',
  `limit_spamfilter_policy` int(11) NOT NULL default '0',
  `default_webserver` int(11) unsigned NOT NULL default '1',
  `limit_web_ip` text,
  `limit_web_domain` int(11) NOT NULL default '-1',
  `web_php_options` varchar(255) NOT NULL default 'no,fast-cgi,cgi,mod,suphp',
  `limit_web_subdomain` int(11) NOT NULL default '-1',
  `limit_web_aliasdomain` int(11) NOT NULL default '-1',
  `limit_ftp_user` int(11) NOT NULL default '-1',
  `limit_shell_user` int(11) NOT NULL default '0',
  `ssh_chroot` varchar(255) NOT NULL DEFAULT 'no,jailkit,ssh-chroot',
  `default_dnsserver` int(11) unsigned NOT NULL default '1',
  `limit_dns_zone` int(11) NOT NULL default '-1',
  `limit_dns_record` int(11) NOT NULL default '-1',
  `default_dbserver` int(11) NOT NULL default '1',
  `limit_database` int(11) NOT NULL default '-1',
  `limit_client` int(11) NOT NULL default '0',
  `parent_client_id` int(11) unsigned NOT NULL default '0',
  `username` varchar(64) default NULL,
  `password` varchar(64) default NULL,
  `language` char(2) NOT NULL default 'en',
  `usertheme` varchar(32) NOT NULL default 'default',
  `template_master` int(11) unsigned NOT NULL default '0',
  `template_additional` varchar(255) NOT NULL default '',
  `created_at` datetime default NULL,
  PRIMARY KEY  (`client_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `client_template`
--
CREATE TABLE `client_template` (
  `template_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `template_name` varchar(64) NOT NULL,
  `template_type` varchar(1) NOT NULL default 'm',
  `limit_maildomain` int(11) NOT NULL default '-1',
  `limit_mailbox` int(11) NOT NULL default '-1',
  `limit_mailalias` int(11) NOT NULL default '-1',
  `limit_mailforward` int(11) NOT NULL default '-1',
  `limit_mailcatchall` int(11) NOT NULL default '-1',
  `limit_mailrouting` int(11) NOT NULL default '0',
  `limit_mailfilter` int(11) NOT NULL default '-1',
  `limit_fetchmail` int(11) NOT NULL default '-1',
  `limit_mailquota` int(11) NOT NULL default '-1',
  `limit_spamfilter_wblist` int(11) NOT NULL default '0',
  `limit_spamfilter_user` int(11) NOT NULL default '0',
  `limit_spamfilter_policy` int(11) NOT NULL default '0',
  `limit_web_ip` text,
  `limit_web_domain` int(11) NOT NULL default '-1',
  `limit_web_subdomain` int(11) NOT NULL default '-1',
  `limit_web_aliasdomain` int(11) NOT NULL default '-1',
  `limit_ftp_user` int(11) NOT NULL default '-1',
  `limit_shell_user` int(11) NOT NULL default '0',
  `limit_dns_zone` int(11) NOT NULL default '-1',
  `limit_dns_record` int(11) NOT NULL default '-1',
  `limit_database` int(11) NOT NULL default '-1',
  `limit_client` int(11) NOT NULL default '0',
  PRIMARY KEY  (`template_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `dns_rr`
--
CREATE TABLE `dns_rr` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) NOT NULL default '1',
  `zone` int(11) unsigned NOT NULL,
  `name` varchar(64) NOT NULL,
  `type` enum('A','AAAA','ALIAS','CNAME','HINFO','MX','NAPTR','NS','PTR','RP','SRV','TXT') default NULL,
  `data` varchar(255) NOT NULL,
  `aux` int(11) unsigned NOT NULL default '0',
  `ttl` int(11) unsigned NOT NULL default '86400',
  `active` enum('N','Y') NOT NULL default 'Y',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `rr` (`zone`,`name`,`type`,`data`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `dns_soa`
--
CREATE TABLE `dns_soa` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) NOT NULL default '1',
  `origin` varchar(255) NOT NULL,
  `ns` varchar(255) NOT NULL,
  `mbox` varchar(255) NOT NULL,
  `serial` int(11) unsigned NOT NULL default '1',
  `refresh` int(11) unsigned NOT NULL default '28800',
  `retry` int(11) unsigned NOT NULL default '7200',
  `expire` int(11) unsigned NOT NULL default '604800',
  `minimum` int(11) unsigned NOT NULL default '86400',
  `ttl` int(11) unsigned NOT NULL default '86400',
  `active` enum('N','Y') NOT NULL,
  `xfer` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `origin` (`origin`),
  KEY `active` (`active`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `dns_template`
--
CREATE TABLE `dns_template` (
  `template_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `name` varchar(64) default NULL,
  `fields` varchar(255) default NULL,
  `template` text,
  `visible` enum('N','Y') NOT NULL default 'Y',
  PRIMARY KEY  (`template_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `firewall`
--
CREATE TABLE `firewall` (
  `firewall_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `tcp_port` varchar(255) default NULL,
  `udp_port` varchar(255) default NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`firewall_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `ftp_user`
--
CREATE TABLE `ftp_user` (
  `ftp_user_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `parent_domain_id` int(11) unsigned NOT NULL default '0',
  `username` varchar(64) default NULL,
  `password` varchar(64) default NULL,
  `quota_size` int(11) NOT NULL default '-1',
  `active` enum('n','y') NOT NULL default 'y',
  `uid` varchar(64) default NULL,
  `gid` varchar(64) default NULL,
  `dir` varchar(255) default NULL,
  `quota_files` int(11) NOT NULL default '-1',
  `ul_ratio` int(11) NOT NULL default '-1',
  `dl_ratio` int(11) NOT NULL default '-1',
  `ul_bandwidth` int(11) NOT NULL default '-1',
  `dl_bandwidth` int(11) NOT NULL default '-1',
  PRIMARY KEY  (`ftp_user_id`),
  KEY `active` (`active`),
  KEY `server_id` (`server_id`),
  KEY `username` (`username`),
  KEY `quota_files` (`quota_files`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_access`
--
CREATE TABLE `mail_access` (
  `access_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) NOT NULL default '0',
  `source` varchar(255) NOT NULL,
  `access` varchar(255) NOT NULL,
  `type` set('recipient','sender','client') NOT NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`access_id`),
  KEY `server_id` (`server_id`,`source`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_content_filter`
--
CREATE TABLE `mail_content_filter` (
  `content_filter_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) NOT NULL default '0',
  `type` varchar(255) default NULL,
  `pattern` varchar(255) default NULL,
  `data` varchar(255) default NULL,
  `action` varchar(255) default NULL,
  `active` varchar(255) NOT NULL default 'y',
  PRIMARY KEY  (`content_filter_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_domain`
--
CREATE TABLE `mail_domain` (
  `domain_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `domain` varchar(255) NOT NULL default '',
  `active` enum('n','y') NOT NULL,
  PRIMARY KEY  (`domain_id`),
  KEY `server_id` (`server_id`,`domain`),
  KEY `domain_active` (`domain`,`active`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_forwarding`
--
CREATE TABLE `mail_forwarding` (
  `forwarding_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `source` varchar(255) NOT NULL,
  `destination` varchar(255) NOT NULL default '',
  `type` enum('alias','forward','catchall') NOT NULL default 'alias',
  `active` enum('n','y') NOT NULL,
  PRIMARY KEY  (`forwarding_id`),
  KEY `server_id` (`server_id`,`source`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_get`
--
CREATE TABLE `mail_get` (
  `mailget_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `type` varchar(255) default NULL,
  `source_server` varchar(255) default NULL,
  `source_username` varchar(255) default NULL,
  `source_password` varchar(64) default NULL,
  `source_delete` varchar(255) NOT NULL default 'y',
  `destination` varchar(255) default NULL,
  `active` varchar(255) NOT NULL default 'y',
  PRIMARY KEY  (`mailget_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_greylist`
--
CREATE TABLE `mail_greylist` (
  `greylist_id` int(11) unsigned NOT NULL auto_increment,
  `relay_ip` varchar(39) default NULL,
  `from_domain` varchar(255) default NULL,
  `block_expires` datetime NOT NULL default '0000-00-00 00:00:00',
  `record_expires` datetime NOT NULL default '0000-00-00 00:00:00',
  `origin_type` enum('MANUAL','AUTO') NOT NULL default 'AUTO',
  `create_time` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`greylist_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_mailman_domain`
--
CREATE TABLE `mail_mailman_domain` (
  `mailman_id` int(11) unsigned NOT NULL auto_increment,
  `server_id` int(11) unsigned NOT NULL default '0',
  `domain` varchar(255) NOT NULL default '',
  `mm_home` varchar(255) NOT NULL default '',
  `mm_wrap` varchar(255) NOT NULL default '',
  `mm_user` varchar(50) NOT NULL default '',
  `mm_group` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`mailman_id`,`server_id`,`domain`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_traffic`
--
CREATE TABLE `mail_traffic` (
  `traffic_id` int(11) unsigned NOT NULL auto_increment,
  `mailuser_id` int(11) unsigned NOT NULL,
  `month` char(7) NOT NULL,
  `traffic` bigint(20) unsigned NOT NULL,
  PRIMARY KEY  (`traffic_id`),
  KEY `mailuser_id` (`mailuser_id`,`month`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_transport`
--
CREATE TABLE `mail_transport` (
  `transport_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `domain` varchar(255) NOT NULL default '',
  `transport` varchar(255) NOT NULL,
  `sort_order` int(11) unsigned NOT NULL default '5',
  `active` enum('n','y') NOT NULL,
  PRIMARY KEY  (`transport_id`),
  KEY `server_id` (`server_id`,`transport`),
  KEY `server_id_2` (`server_id`,`domain`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_user`
--
CREATE TABLE `mail_user` (
  `mailuser_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `email` varchar(255) NOT NULL default '',
  `password` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL default '',
  `uid` int(11) unsigned NOT NULL default '5000',
  `gid` int(11) unsigned NOT NULL default '5000',
  `maildir` varchar(255) NOT NULL default '',
  `quota` int(11) NOT NULL default '0',
  `homedir` varchar(255) NOT NULL,
  `autoresponder` enum('n','y') NOT NULL default 'n',
  `autoresponder_text` mediumtext NULL,
  `custom_mailfilter` mediumtext,
  `postfix` enum('n','y') NOT NULL,
  `access` enum('n','y') NOT NULL,
  `disableimap` enum('0','1') NOT NULL default '0',
  `disablepop3` enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (`mailuser_id`),
  KEY `server_id` (`server_id`,`email`),
  KEY `email_access` (`email`,`access`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_user_filter`
--
CREATE TABLE `mail_user_filter` (
  `filter_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `mailuser_id` int(11) unsigned NOT NULL default '0',
  `rulename` varchar(64) default NULL,
  `source` varchar(255) default NULL,
  `searchterm` varchar(255) default NULL,
  `op` varchar(255) default NULL,
  `action` varchar(255) default NULL,
  `target` varchar(255) default NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`filter_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `remote_session`
--
CREATE TABLE `remote_session` (
  `remote_session` varchar(64) NOT NULL,
  `remote_userid` int(11) unsigned NOT NULL,
  `remote_functions` text NOT NULL,
  `tstamp` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`remote_session`)
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- Table structure for table  `remote_user`
--
CREATE TABLE `remote_user` (
  `remote_userid` int(11) unsigned NOT NULL auto_increment,
  `remote_username` varchar(64) NOT NULL,
  `remote_password` varchar(64) NOT NULL,
  `remote_functions` text NOT NULL,
  PRIMARY KEY  (`remote_userid`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `server`
--
CREATE TABLE `server` (
  `server_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_name` varchar(255) NOT NULL default '',
  `mail_server` tinyint(1) NOT NULL default '0',
  `web_server` tinyint(1) NOT NULL default '0',
  `dns_server` tinyint(1) NOT NULL default '0',
  `file_server` tinyint(1) NOT NULL default '0',
  `db_server` tinyint(1) NOT NULL default '0',
  `vserver_server` tinyint(1) NOT NULL default '0',
  `config` text NOT NULL,
  `updated` bigint(20) unsigned NOT NULL default '0',
  `active` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`server_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `server_ip`
--
CREATE TABLE `server_ip` (
  `server_ip_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `ip_address` varchar(39) default NULL,
  `virtualhost` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`server_ip_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
CREATE TABLE `shell_user` (
  `shell_user_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `parent_domain_id` int(11) unsigned NOT NULL default '0',
  `username` varchar(64) default NULL,
  `password` varchar(64) default NULL,
  `quota_size` int(11) NOT NULL default '-1',
  `active` enum('n','y') NOT NULL default 'y',
  `puser` varchar(255) default NULL,
  `pgroup` varchar(255) default NULL,
  `shell` varchar(255) NOT NULL default '/bin/bash',
  `dir` varchar(255) default NULL,
  `chroot` varchar(255) NOT NULL,
  PRIMARY KEY  (`shell_user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_package`
--
CREATE TABLE `software_package` (
  `package_id` int(11) unsigned NOT NULL auto_increment,
  `software_repo_id` int(11) unsigned NOT NULL,
  `package_name` varchar(64) NOT NULL,
  `package_title` varchar(64) NOT NULL,
  `package_description` text,
  `package_version` varchar(8) default NULL,
  PRIMARY KEY  (`package_id`),
  UNIQUE KEY `package_name` (`package_name`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_repo`
--
CREATE TABLE `software_repo` (
  `software_repo_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `repo_name` varchar(64) default NULL,
  `repo_url` varchar(255) default NULL,
  `repo_username` varchar(64) default NULL,
  `repo_password` varchar(64) default NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`software_repo_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_update`
--
CREATE TABLE `software_update` (
  `software_update_id` int(11) unsigned NOT NULL auto_increment,
  `software_repo_id` int(11) unsigned NOT NULL,
  `package_name` varchar(64) NOT NULL,
  `update_url` varchar(255) NOT NULL,
  `update_md5` varchar(255) NOT NULL,
  `update_dependencies` varchar(255) NOT NULL,
  `update_title` varchar(64) NOT NULL,
  `v1` tinyint(1) NOT NULL default '0',
  `v2` tinyint(1) NOT NULL default '0',
  `v3` tinyint(1) NOT NULL default '0',
  `v4` tinyint(1) NOT NULL default '0',
  `type` enum('full','update') NOT NULL default 'full',
  PRIMARY KEY  (`software_update_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_update_inst`
--
CREATE TABLE `software_update_inst` (
  `software_update_inst_id` int(11) unsigned NOT NULL auto_increment,
  `software_update_id` int(11) unsigned NOT NULL default '0',
  `package_name` varchar(64) NOT NULL,
  `server_id` int(11) unsigned NOT NULL,
  `status` enum('none','installing','installed','deleting','deleted') NOT NULL default 'none',
  PRIMARY KEY  (`software_update_inst_id`),
  UNIQUE KEY `software_update_id` (`software_update_id`,`package_name`,`server_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `spamfilter_policy`
--
CREATE TABLE `spamfilter_policy` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `policy_name` varchar(64) default NULL,
  `virus_lover` enum('N','Y') default NULL,
  `spam_lover` enum('N','Y') default NULL,
  `banned_files_lover` enum('N','Y') default NULL,
  `bad_header_lover` enum('N','Y') default NULL,
  `bypass_virus_checks` enum('N','Y') default NULL,
  `bypass_spam_checks` enum('N','Y') default NULL,
  `bypass_banned_checks` enum('N','Y') default NULL,
  `bypass_header_checks` enum('N','Y') default NULL,
  `spam_modifies_subj` enum('N','Y') default NULL,
  `virus_quarantine_to` varchar(255) default NULL,
  `spam_quarantine_to` varchar(255) default NULL,
  `banned_quarantine_to` varchar(255) default NULL,
  `bad_header_quarantine_to` varchar(255) default NULL,
  `clean_quarantine_to` varchar(255) default NULL,
  `other_quarantine_to` varchar(255) default NULL,
  `spam_tag_level` float default NULL,
  `spam_tag2_level` float default NULL,
  `spam_kill_level` float default NULL,
  `spam_dsn_cutoff_level` float default NULL,
  `spam_quarantine_cutoff_level` float default NULL,
  `addr_extension_virus` varchar(64) default NULL,
  `addr_extension_spam` varchar(64) default NULL,
  `addr_extension_banned` varchar(64) default NULL,
  `addr_extension_bad_header` varchar(64) default NULL,
  `warnvirusrecip` enum('N','Y') default NULL,
  `warnbannedrecip` enum('N','Y') default NULL,
  `warnbadhrecip` enum('N','Y') default NULL,
  `newvirus_admin` varchar(64) default NULL,
  `virus_admin` varchar(64) default NULL,
  `banned_admin` varchar(64) default NULL,
  `bad_header_admin` varchar(64) default NULL,
  `spam_admin` varchar(64) default NULL,
  `spam_subject_tag` varchar(64) default NULL,
  `spam_subject_tag2` varchar(64) default NULL,
  `message_size_limit` int(11) unsigned default NULL,
  `banned_rulenames` varchar(64) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table  `spamfilter_users`
--
CREATE TABLE `spamfilter_users` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) unsigned NOT NULL,
  `priority` tinyint(3) unsigned NOT NULL default '7',
  `policy_id` int(11) unsigned NOT NULL default '1',
  `email` varchar(255) NOT NULL,
  `fullname` varchar(64) default NULL,
  `local` varchar(1) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `spamfilter_wblist`
--
CREATE TABLE `spamfilter_wblist` (
  `wblist_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) unsigned NOT NULL,
  `wb` enum('W','B') NOT NULL default 'W',
  `rid` int(11) unsigned NOT NULL,
  `email` varchar(255) NOT NULL,
  `priority` tinyint(3) unsigned NOT NULL,
  `active` enum('y','n') NOT NULL default 'y',
  PRIMARY KEY  (`wblist_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `support_message`
--
CREATE TABLE `support_message` (
  `support_message_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `recipient_id` int(11) unsigned NOT NULL default '0',
  `sender_id` int(11) unsigned NOT NULL default '0',
  `subject` varchar(255) default NULL,
  `message` text default NULL,
  `tstamp` int(11) NOT NULL default '0',
  PRIMARY KEY  (`support_message_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_datalog`
--
CREATE TABLE `sys_datalog` (
  `datalog_id` int(11) unsigned NOT NULL auto_increment,
  `server_id` int(11) unsigned NOT NULL,
  `dbtable` varchar(255) NOT NULL default '',
  `dbidx` varchar(255) NOT NULL default '',
  `action` char(1) NOT NULL default '',
  `tstamp` int(11) NOT NULL default '0',
  `user` varchar(255) NOT NULL default '',
  `data` text NOT NULL,
  `status` set('pending','ok','warning','error') NOT NULL default 'pending',
  PRIMARY KEY  (`datalog_id`),
  KEY `server_id` (`server_id`,`status`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_dbsync`
--
CREATE TABLE `sys_dbsync` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `jobname` varchar(64) NOT NULL default '',
  `sync_interval_minutes` int(11) unsigned NOT NULL default '0',
  `db_type` varchar(16) NOT NULL default '',
  `db_host` varchar(255) NOT NULL default '',
  `db_name` varchar(64) NOT NULL default '',
  `db_username` varchar(64) NOT NULL default '',
  `db_password` varchar(64) NOT NULL default '',
  `db_tables` varchar(255) NOT NULL default 'admin,forms',
  `empty_datalog` int(11) unsigned NOT NULL default '0',
  `sync_datalog_external` int(11) unsigned NOT NULL default '0',
  `active` tinyint(1) NOT NULL default '1',
  `last_datalog_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `last_datalog_id` (`last_datalog_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_filesync`
--
CREATE TABLE `sys_filesync` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `jobname` varchar(64) NOT NULL default '',
  `sync_interval_minutes` int(11) unsigned NOT NULL default '0',
  `ftp_host` varchar(255) NOT NULL default '',
  `ftp_path` varchar(255) NOT NULL default '',
  `ftp_username` varchar(64) NOT NULL default '',
  `ftp_password` varchar(64) NOT NULL default '',
  `local_path` varchar(255) NOT NULL default '',
  `wput_options` varchar(255) NOT NULL default '--timestamping --reupload --dont-continue',
  `active` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_group`
--
CREATE TABLE `sys_group` (
  `groupid` int(11) unsigned NOT NULL auto_increment,
  `name` varchar(64) NOT NULL default '',
  `description` text NOT NULL,
  `client_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`groupid`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_ini`
--
CREATE TABLE `sys_ini` (
  `sysini_id` int(11) unsigned NOT NULL auto_increment,
  `config` longtext NOT NULL,
  PRIMARY KEY  (`sysini_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_log`
--
CREATE TABLE `sys_log` (
  `syslog_id` int(11) unsigned NOT NULL auto_increment,
  `server_id` int(11) unsigned NOT NULL default '0',
  `datalog_id` int(11) unsigned NOT NULL default '0',
  `loglevel` tinyint(4) NOT NULL default '0',
  `tstamp` int(11) unsigned NOT NULL,
  `message` text,
  PRIMARY KEY  (`syslog_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_user`
--
CREATE TABLE `sys_user` (
  `userid` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '1',
  `sys_groupid` int(11) unsigned NOT NULL default '1',
  `sys_perm_user` varchar(5) NOT NULL default 'riud',
  `sys_perm_group` varchar(5) NOT NULL default 'riud',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `username` varchar(64) NOT NULL default '',
  `passwort` varchar(64) NOT NULL default '',
  `modules` varchar(255) NOT NULL default '',
  `startmodule` varchar(255) NOT NULL default '',
  `app_theme` varchar(32) NOT NULL default 'default',
  `typ` varchar(16) NOT NULL default 'user',
  `active` tinyint(1) NOT NULL default '1',
  `language` varchar(2) NOT NULL default 'de',
  `groups` varchar(255) NOT NULL default '',
  `default_group` int(11) unsigned NOT NULL default '0',
  `client_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`userid`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `web_domain`
--
CREATE TABLE `web_domain` (
  `domain_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `ip_address` varchar(39) default NULL,
  `domain` varchar(255) default NULL,
  `type` varchar(32) default NULL,
  `parent_domain_id` int(11) unsigned NOT NULL default '0',
  `vhost_type` varchar(32) default NULL,
  `document_root` varchar(255) default NULL,
  `system_user` varchar(255) default NULL,
  `system_group` varchar(255) default NULL,
  `hd_quota` int(11) NOT NULL default '0',
  `traffic_quota` int(11) NOT NULL default '0',
  `cgi` enum('n','y') NOT NULL default 'y',
  `ssi` enum('n','y') NOT NULL default 'y',
  `suexec` enum('n','y') NOT NULL default 'y',
  `errordocs` tinyint(1) NOT NULL default '1',
  `is_subdomainwww` tinyint(1) NOT NULL default '1',
  `subdomain` enum('none','www','*') NOT NULL default 'none',
  `php` varchar(32) NOT NULL default 'y',
  `redirect_type` varchar(255) default NULL,
  `redirect_path` varchar(255) default NULL,
  `ssl` enum('n','y') NOT NULL default 'n',
  `ssl_state` varchar(255) NULL,
  `ssl_locality` varchar(255) NULL,
  `ssl_organisation` varchar(255) NULL,
  `ssl_organisation_unit` varchar(255) NULL,
  `ssl_country` varchar(255) NULL,
  `ssl_request` mediumtext NULL,
  `ssl_cert` mediumtext NULL,
  `ssl_bundle` mediumtext NULL,
  `ssl_action` varchar(16) NULL,
  `stats_password` varchar(255) default NULL,
  `apache_directives` text,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`domain_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `web_database`
--
CREATE TABLE `web_database` (
  `database_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `type` varchar(16) NOT NULL default 'y',
  `database_name` varchar(64) default NULL,
  `database_user` varchar(64) default NULL,
  `database_password` varchar(64) default NULL,
  `database_charset` varchar(64) default NULL,
  `remote_access` enum('n','y') NOT NULL default 'y',
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`database_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `attempts_login`
--
CREATE TABLE `attempts_login` (
  `ip` varchar(39) NOT NULL,
  `times` int(11) default NULL,
  `login_time` timestamp
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- Table structure for table  `monitor_data`
--
CREATE TABLE `monitor_data` (
  `server_id` int(11) unsigned NOT NULL,
  `type` varchar(255) NOT NULL,
  `created` int(11) unsigned NOT NULL,
  `data` mediumtext NOT NULL,
  `state` enum('no_state', 'unknown', 'ok', 'info', 'warning', 'critical', 'error') NOT NULL default 'unknown',
  PRIMARY KEY  (`server_id`,`type`,`created`)
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_config`
--
CREATE TABLE `sys_config` (
  `config_id` int(11) unsigned NOT NULL,
  `group` varchar(64) NOT NULL,
  `name` varchar(64) NOT NULL,
  `value` varchar(255) NOT NULL
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- iso_country_list.sql
--
-- This will create and then populate a MySQL table with a list of the names and
-- ISO 3166 codes for countries in existence as of the date below.
--
-- For updates to this file, see http://27.org/isocountrylist/
-- For more about ISO 3166, see http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
--
-- Created by getisocountrylist.pl on Sun Nov  2 14:59:20 2003.
-- Wm. Rhodes <iso_country_list@27.org>
--
--
-- Table structure for table `country`
--
CREATE TABLE `country` (
  `iso` char(2) NOT NULL PRIMARY KEY,
  `name` varchar(64) NOT NULL,
  `printable_name` varchar(64) NOT NULL,
  `iso3` char(3),
  `numcode` SMALLINT
) ENGINE=MyISAM;
-- --------------------------------------------------------
-- --------------------------------------------------------
-- DB-DATA
-- --------------------------------------------------------
-- --------------------------------------------------------
--
-- Dumping data for table `dns_template`
--
INSERT INTO `dns_template` (`template_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `name`, `fields`, `template`, `visible`) VALUES (1, 1, 1, 'riud', 'riud', '', 'Default', 'DOMAIN,IP,NS1,NS2,EMAIL', '[ZONE]\norigin={DOMAIN}.\nns={NS1}.\nmbox={EMAIL}.\nrefresh=28800\nretry=7200\nexpire=604800\nminimum=86400\nttl=86400\n\n[DNS_RECORDS]\nA|{DOMAIN}.|{IP}|0|86400\nA|www|{IP}|0|86400\nA|mail|{IP}|0|86400\nNS|{DOMAIN}.|{NS1}.|0|86400\nNS|{DOMAIN}.|{NS2}.|0|86400\nMX|{DOMAIN}.|mail.{DOMAIN}.|10|86400', 'y');
-- --------------------------------------------------------
--
-- Dumping data for table `software_repo`
--
INSERT INTO `software_repo` (`software_repo_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `repo_name`, `repo_url`, `repo_username`, `repo_password`, `active`) VALUES (1, 1, 1, 'riud', 'riud', '', 'ISPConfig Addons', 'http://repo.ispconfig.org/addons/', '', '', 'n');
-- --------------------------------------------------------
--
-- Dumping data for table `spamfilter_policy`
--
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (1, 1, 0, 'riud', 'riud', 'r', 'Non-paying', 'N', 'N', 'N', 'N', 'Y', 'Y', 'Y', 'N', 'Y', '', '', '', '', '', '', 3, 7, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (2, 1, 0, 'riud', 'riud', 'r', 'Uncensored', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'N', 'N', 'N', NULL, NULL, NULL, NULL, NULL, NULL, 3, 999, 999, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (3, 1, 0, 'riud', 'riud', 'r', 'Wants all spam', 'N', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 999, 999, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (4, 1, 0, 'riud', 'riud', 'r', 'Wants viruses', 'Y', 'N', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 6.9, 6.9, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (5, 1, 0, 'riud', 'riud', 'r', 'Normal', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 6.9, 6.9, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (6, 1, 0, 'riud', 'riud', 'r', 'Trigger happy', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 5, 5, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (7, 1, 0, 'riud', 'riud', 'r', 'Permissive', 'N', 'N', 'N', 'Y', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 10, 20, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-- --------------------------------------------------------
--
-- Dumping data for table `sys_group`
--
INSERT INTO `sys_group` (`groupid`, `name`, `description`, `client_id`) VALUES (1, 'admin', 'Administrators group', 0);
-- --------------------------------------------------------
--
-- Dumping data for table `sys_ini`
--
INSERT INTO `sys_ini` (`sysini_id`, `config`) VALUES (1, '');
-- --------------------------------------------------------
--
-- Dumping data for table `sys_user`
--
INSERT INTO `sys_user` (`userid`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `username`, `passwort`, `modules`, `startmodule`, `app_theme`, `typ`, `active`, `language`, `groups`, `default_group`, `client_id`) VALUES (1, 1, 0, 'riud', 'riud', '', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin,client,mail,monitor,sites,dns,tools,help', 'mail', 'default', 'admin', 1, 'en', '1,2', 1, 0);
-- --------------------------------------------------------
--
-- Dumping data for table `sys_config`
--
INSERT INTO sys_config VALUES ('1','db','db_version','3.0.0.9');
-- --------------------------------------------------------
--
-- iso_country_list.sql
--
-- This will create and then populate a MySQL table with a list of the names and
-- ISO 3166 codes for countries in existence as of the date below.
--
-- For updates to this file, see http://27.org/isocountrylist/
-- For more about ISO 3166, see http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
--
-- Created by getisocountrylist.pl on Sun Nov  2 14:59:20 2003.
-- Wm. Rhodes <iso_country_list@27.org>
--
--
-- Dumping data for table `country`
--
INSERT INTO `country` (`iso`, `name`, `printable_name`, `iso3`, `numcode`) VALUES
('AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4),
('AL', 'ALBANIA', 'Albania', 'ALB', 8),
('DZ', 'ALGERIA', 'Algeria', 'DZA', 12),
('AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', 16),
('AD', 'ANDORRA', 'Andorra', 'AND', 20),
('AO', 'ANGOLA', 'Angola', 'AGO', 24),
('AI', 'ANGUILLA', 'Anguilla', 'AIA', 660),
('AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL),
('AG', 'ANTIGUA AND BARBUDA', 'Antigua and Barbuda', 'ATG', 28),
('AR', 'ARGENTINA', 'Argentina', 'ARG', 32),
('AM', 'ARMENIA', 'Armenia', 'ARM', 51),
('AW', 'ARUBA', 'Aruba', 'ABW', 533),
('AU', 'AUSTRALIA', 'Australia', 'AUS', 36),
('AT', 'AUSTRIA', 'Austria', 'AUT', 40),
('AZ', 'AZERBAIJAN', 'Azerbaijan', 'AZE', 31),
('BS', 'BAHAMAS', 'Bahamas', 'BHS', 44),
('BH', 'BAHRAIN', 'Bahrain', 'BHR', 48),
('BD', 'BANGLADESH', 'Bangladesh', 'BGD', 50),
('BB', 'BARBADOS', 'Barbados', 'BRB', 52),
('BY', 'BELARUS', 'Belarus', 'BLR', 112),
('BE', 'BELGIUM', 'Belgium', 'BEL', 56),
('BZ', 'BELIZE', 'Belize', 'BLZ', 84),
('BJ', 'BENIN', 'Benin', 'BEN', 204),
('BM', 'BERMUDA', 'Bermuda', 'BMU', 60),
('BT', 'BHUTAN', 'Bhutan', 'BTN', 64),
('BO', 'BOLIVIA', 'Bolivia', 'BOL', 68),
('BA', 'BOSNIA AND HERZEGOVINA', 'Bosnia and Herzegovina', 'BIH', 70),
('BW', 'BOTSWANA', 'Botswana', 'BWA', 72),
('BV', 'BOUVET ISLAND', 'Bouvet Island', NULL, NULL),
('BR', 'BRAZIL', 'Brazil', 'BRA', 76),
('IO', 'BRITISH INDIAN OCEAN TERRITORY', 'British Indian Ocean Territory', NULL, NULL),
('BN', 'BRUNEI DARUSSALAM', 'Brunei Darussalam', 'BRN', 96),
('BG', 'BULGARIA', 'Bulgaria', 'BGR', 100),
('BF', 'BURKINA FASO', 'Burkina Faso', 'BFA', 854),
('BI', 'BURUNDI', 'Burundi', 'BDI', 108),
('KH', 'CAMBODIA', 'Cambodia', 'KHM', 116),
('CM', 'CAMEROON', 'Cameroon', 'CMR', 120),
('CA', 'CANADA', 'Canada', 'CAN', 124),
('CV', 'CAPE VERDE', 'Cape Verde', 'CPV', 132),
('KY', 'CAYMAN ISLANDS', 'Cayman Islands', 'CYM', 136),
('CF', 'CENTRAL AFRICAN REPUBLIC', 'Central African Republic', 'CAF', 140),
('TD', 'CHAD', 'Chad', 'TCD', 148),
('CL', 'CHILE', 'Chile', 'CHL', 152),
('CN', 'CHINA', 'China', 'CHN', 156),
('CX', 'CHRISTMAS ISLAND', 'Christmas Island', NULL, NULL),
('CC', 'COCOS (KEELING) ISLANDS', 'Cocos (Keeling) Islands', NULL, NULL),
('CO', 'COLOMBIA', 'Colombia', 'COL', 170),
('KM', 'COMOROS', 'Comoros', 'COM', 174),
('CG', 'CONGO', 'Congo', 'COG', 178),
('CD', 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', 'Congo, the Democratic Republic of the', 'COD', 180),
('CK', 'COOK ISLANDS', 'Cook Islands', 'COK', 184),
('CR', 'COSTA RICA', 'Costa Rica', 'CRI', 188),
('CI', 'COTE D''IVOIRE', 'Cote D''Ivoire', 'CIV', 384),
('HR', 'CROATIA', 'Croatia', 'HRV', 191),
('CU', 'CUBA', 'Cuba', 'CUB', 192),
('CY', 'CYPRUS', 'Cyprus', 'CYP', 196),
('CZ', 'CZECH REPUBLIC', 'Czech Republic', 'CZE', 203),
('DK', 'DENMARK', 'Denmark', 'DNK', 208),
('DJ', 'DJIBOUTI', 'Djibouti', 'DJI', 262),
('DM', 'DOMINICA', 'Dominica', 'DMA', 212),
('DO', 'DOMINICAN REPUBLIC', 'Dominican Republic', 'DOM', 214),
('EC', 'ECUADOR', 'Ecuador', 'ECU', 218),
('EG', 'EGYPT', 'Egypt', 'EGY', 818),
('SV', 'EL SALVADOR', 'El Salvador', 'SLV', 222),
('GQ', 'EQUATORIAL GUINEA', 'Equatorial Guinea', 'GNQ', 226),
('ER', 'ERITREA', 'Eritrea', 'ERI', 232),
('EE', 'ESTONIA', 'Estonia', 'EST', 233),
('ET', 'ETHIOPIA', 'Ethiopia', 'ETH', 231),
('FK', 'FALKLAND ISLANDS (MALVINAS)', 'Falkland Islands (Malvinas)', 'FLK', 238),
('FO', 'FAROE ISLANDS', 'Faroe Islands', 'FRO', 234),
('FJ', 'FIJI', 'Fiji', 'FJI', 242),
('FI', 'FINLAND', 'Finland', 'FIN', 246),
('FR', 'FRANCE', 'France', 'FRA', 250),
('GF', 'FRENCH GUIANA', 'French Guiana', 'GUF', 254),
('PF', 'FRENCH POLYNESIA', 'French Polynesia', 'PYF', 258),
('TF', 'FRENCH SOUTHERN TERRITORIES', 'French Southern Territories', NULL, NULL),
('GA', 'GABON', 'Gabon', 'GAB', 266),
('GM', 'GAMBIA', 'Gambia', 'GMB', 270),
('GE', 'GEORGIA', 'Georgia', 'GEO', 268),
('DE', 'GERMANY', 'Germany', 'DEU', 276),
('GH', 'GHANA', 'Ghana', 'GHA', 288),
('GI', 'GIBRALTAR', 'Gibraltar', 'GIB', 292),
('GR', 'GREECE', 'Greece', 'GRC', 300),
('GL', 'GREENLAND', 'Greenland', 'GRL', 304),
('GD', 'GRENADA', 'Grenada', 'GRD', 308),
('GP', 'GUADELOUPE', 'Guadeloupe', 'GLP', 312),
('GU', 'GUAM', 'Guam', 'GUM', 316),
('GT', 'GUATEMALA', 'Guatemala', 'GTM', 320),
('GN', 'GUINEA', 'Guinea', 'GIN', 324),
('GW', 'GUINEA-BISSAU', 'Guinea-Bissau', 'GNB', 624),
('GY', 'GUYANA', 'Guyana', 'GUY', 328),
('HT', 'HAITI', 'Haiti', 'HTI', 332),
('HM', 'HEARD ISLAND AND MCDONALD ISLANDS', 'Heard Island and Mcdonald Islands', NULL, NULL),
('VA', 'HOLY SEE (VATICAN CITY STATE)', 'Holy See (Vatican City State)', 'VAT', 336),
('HN', 'HONDURAS', 'Honduras', 'HND', 340),
('HK', 'HONG KONG', 'Hong Kong', 'HKG', 344),
('HU', 'HUNGARY', 'Hungary', 'HUN', 348),
('IS', 'ICELAND', 'Iceland', 'ISL', 352),
('IN', 'INDIA', 'India', 'IND', 356),
('ID', 'INDONESIA', 'Indonesia', 'IDN', 360),
('IR', 'IRAN, ISLAMIC REPUBLIC OF', 'Iran, Islamic Republic of', 'IRN', 364),
('IQ', 'IRAQ', 'Iraq', 'IRQ', 368),
('IE', 'IRELAND', 'Ireland', 'IRL', 372),
('IL', 'ISRAEL', 'Israel', 'ISR', 376),
('IT', 'ITALY', 'Italy', 'ITA', 380),
('JM', 'JAMAICA', 'Jamaica', 'JAM', 388),
('JP', 'JAPAN', 'Japan', 'JPN', 392),
('JO', 'JORDAN', 'Jordan', 'JOR', 400),
('KZ', 'KAZAKHSTAN', 'Kazakhstan', 'KAZ', 398),
('KE', 'KENYA', 'Kenya', 'KEN', 404),
('KI', 'KIRIBATI', 'Kiribati', 'KIR', 296),
('KP', 'KOREA, DEMOCRATIC PEOPLE''S REPUBLIC OF', 'Korea, Democratic People''s Republic of', 'PRK', 408),
('KR', 'KOREA, REPUBLIC OF', 'Korea, Republic of', 'KOR', 410),
('KW', 'KUWAIT', 'Kuwait', 'KWT', 414),
('KG', 'KYRGYZSTAN', 'Kyrgyzstan', 'KGZ', 417),
('LA', 'LAO PEOPLE''S DEMOCRATIC REPUBLIC', 'Lao People''s Democratic Republic', 'LAO', 418),
('LV', 'LATVIA', 'Latvia', 'LVA', 428),
('LB', 'LEBANON', 'Lebanon', 'LBN', 422),
('LS', 'LESOTHO', 'Lesotho', 'LSO', 426),
('LR', 'LIBERIA', 'Liberia', 'LBR', 430),
('LY', 'LIBYAN ARAB JAMAHIRIYA', 'Libyan Arab Jamahiriya', 'LBY', 434),
('LI', 'LIECHTENSTEIN', 'Liechtenstein', 'LIE', 438),
('LT', 'LITHUANIA', 'Lithuania', 'LTU', 440),
('LU', 'LUXEMBOURG', 'Luxembourg', 'LUX', 442),
('MO', 'MACAO', 'Macao', 'MAC', 446),
('MK', 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', 'Macedonia, the Former Yugoslav Republic of', 'MKD', 807),
('MG', 'MADAGASCAR', 'Madagascar', 'MDG', 450),
('MW', 'MALAWI', 'Malawi', 'MWI', 454),
('MY', 'MALAYSIA', 'Malaysia', 'MYS', 458),
('MV', 'MALDIVES', 'Maldives', 'MDV', 462),
('ML', 'MALI', 'Mali', 'MLI', 466),
('MT', 'MALTA', 'Malta', 'MLT', 470),
('MH', 'MARSHALL ISLANDS', 'Marshall Islands', 'MHL', 584),
('MQ', 'MARTINIQUE', 'Martinique', 'MTQ', 474),
('MR', 'MAURITANIA', 'Mauritania', 'MRT', 478),
('MU', 'MAURITIUS', 'Mauritius', 'MUS', 480),
('YT', 'MAYOTTE', 'Mayotte', NULL, NULL),
('MX', 'MEXICO', 'Mexico', 'MEX', 484),
('FM', 'MICRONESIA, FEDERATED STATES OF', 'Micronesia, Federated States of', 'FSM', 583),
('MD', 'MOLDOVA, REPUBLIC OF', 'Moldova, Republic of', 'MDA', 498),
('MC', 'MONACO', 'Monaco', 'MCO', 492),
('MN', 'MONGOLIA', 'Mongolia', 'MNG', 496),
('MS', 'MONTSERRAT', 'Montserrat', 'MSR', 500),
('MA', 'MOROCCO', 'Morocco', 'MAR', 504),
('MZ', 'MOZAMBIQUE', 'Mozambique', 'MOZ', 508),
('MM', 'MYANMAR', 'Myanmar', 'MMR', 104),
('NA', 'NAMIBIA', 'Namibia', 'NAM', 516),
('NR', 'NAURU', 'Nauru', 'NRU', 520),
('NP', 'NEPAL', 'Nepal', 'NPL', 524),
('NL', 'NETHERLANDS', 'Netherlands', 'NLD', 528),
('AN', 'NETHERLANDS ANTILLES', 'Netherlands Antilles', 'ANT', 530),
('NC', 'NEW CALEDONIA', 'New Caledonia', 'NCL', 540),
('NZ', 'NEW ZEALAND', 'New Zealand', 'NZL', 554),
('NI', 'NICARAGUA', 'Nicaragua', 'NIC', 558),
('NE', 'NIGER', 'Niger', 'NER', 562),
('NG', 'NIGERIA', 'Nigeria', 'NGA', 566),
('NU', 'NIUE', 'Niue', 'NIU', 570),
('NF', 'NORFOLK ISLAND', 'Norfolk Island', 'NFK', 574),
('MP', 'NORTHERN MARIANA ISLANDS', 'Northern Mariana Islands', 'MNP', 580),
('NO', 'NORWAY', 'Norway', 'NOR', 578),
('OM', 'OMAN', 'Oman', 'OMN', 512),
('PK', 'PAKISTAN', 'Pakistan', 'PAK', 586),
('PW', 'PALAU', 'Palau', 'PLW', 585),
('PS', 'PALESTINIAN TERRITORY, OCCUPIED', 'Palestinian Territory, Occupied', NULL, NULL),
('PA', 'PANAMA', 'Panama', 'PAN', 591),
('PG', 'PAPUA NEW GUINEA', 'Papua New Guinea', 'PNG', 598),
('PY', 'PARAGUAY', 'Paraguay', 'PRY', 600),
('PE', 'PERU', 'Peru', 'PER', 604),
('PH', 'PHILIPPINES', 'Philippines', 'PHL', 608),
('PN', 'PITCAIRN', 'Pitcairn', 'PCN', 612),
('PL', 'POLAND', 'Poland', 'POL', 616),
('PT', 'PORTUGAL', 'Portugal', 'PRT', 620),
('PR', 'PUERTO RICO', 'Puerto Rico', 'PRI', 630),
('QA', 'QATAR', 'Qatar', 'QAT', 634),
('RE', 'REUNION', 'Reunion', 'REU', 638),
('RO', 'ROMANIA', 'Romania', 'ROM', 642),
('RU', 'RUSSIAN FEDERATION', 'Russian Federation', 'RUS', 643),
('RW', 'RWANDA', 'Rwanda', 'RWA', 646),
('SH', 'SAINT HELENA', 'Saint Helena', 'SHN', 654),
('KN', 'SAINT KITTS AND NEVIS', 'Saint Kitts and Nevis', 'KNA', 659),
('LC', 'SAINT LUCIA', 'Saint Lucia', 'LCA', 662),
('PM', 'SAINT PIERRE AND MIQUELON', 'Saint Pierre and Miquelon', 'SPM', 666),
('VC', 'SAINT VINCENT AND THE GRENADINES', 'Saint Vincent and the Grenadines', 'VCT', 670),
('WS', 'SAMOA', 'Samoa', 'WSM', 882),
('SM', 'SAN MARINO', 'San Marino', 'SMR', 674),
('ST', 'SAO TOME AND PRINCIPE', 'Sao Tome and Principe', 'STP', 678),
('SA', 'SAUDI ARABIA', 'Saudi Arabia', 'SAU', 682),
('SN', 'SENEGAL', 'Senegal', 'SEN', 686),
('CS', 'SERBIA AND MONTENEGRO', 'Serbia and Montenegro', NULL, NULL),
('SC', 'SEYCHELLES', 'Seychelles', 'SYC', 690),
('SL', 'SIERRA LEONE', 'Sierra Leone', 'SLE', 694),
('SG', 'SINGAPORE', 'Singapore', 'SGP', 702),
('SK', 'SLOVAKIA', 'Slovakia', 'SVK', 703),
('SI', 'SLOVENIA', 'Slovenia', 'SVN', 705),
('SB', 'SOLOMON ISLANDS', 'Solomon Islands', 'SLB', 90),
('SO', 'SOMALIA', 'Somalia', 'SOM', 706),
('ZA', 'SOUTH AFRICA', 'South Africa', 'ZAF', 710),
('GS', 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', 'South Georgia and the South Sandwich Islands', NULL, NULL),
('ES', 'SPAIN', 'Spain', 'ESP', 724),
('LK', 'SRI LANKA', 'Sri Lanka', 'LKA', 144),
('SD', 'SUDAN', 'Sudan', 'SDN', 736),
('SR', 'SURINAME', 'Suriname', 'SUR', 740),
('SJ', 'SVALBARD AND JAN MAYEN', 'Svalbard and Jan Mayen', 'SJM', 744),
('SZ', 'SWAZILAND', 'Swaziland', 'SWZ', 748),
('SE', 'SWEDEN', 'Sweden', 'SWE', 752),
('CH', 'SWITZERLAND', 'Switzerland', 'CHE', 756),
('SY', 'SYRIAN ARAB REPUBLIC', 'Syrian Arab Republic', 'SYR', 760),
('TW', 'TAIWAN, PROVINCE OF CHINA', 'Taiwan, Province of China', 'TWN', 158),
('TJ', 'TAJIKISTAN', 'Tajikistan', 'TJK', 762),
('TZ', 'TANZANIA, UNITED REPUBLIC OF', 'Tanzania, United Republic of', 'TZA', 834),
('TH', 'THAILAND', 'Thailand', 'THA', 764),
('TL', 'TIMOR-LESTE', 'Timor-Leste', NULL, NULL),
('TG', 'TOGO', 'Togo', 'TGO', 768),
('TK', 'TOKELAU', 'Tokelau', 'TKL', 772),
('TO', 'TONGA', 'Tonga', 'TON', 776),
('TT', 'TRINIDAD AND TOBAGO', 'Trinidad and Tobago', 'TTO', 780),
('TN', 'TUNISIA', 'Tunisia', 'TUN', 788),
('TR', 'TURKEY', 'Turkey', 'TUR', 792),
('TM', 'TURKMENISTAN', 'Turkmenistan', 'TKM', 795),
('TC', 'TURKS AND CAICOS ISLANDS', 'Turks and Caicos Islands', 'TCA', 796),
('TV', 'TUVALU', 'Tuvalu', 'TUV', 798),
('UG', 'UGANDA', 'Uganda', 'UGA', 800),
('UA', 'UKRAINE', 'Ukraine', 'UKR', 804),
('AE', 'UNITED ARAB EMIRATES', 'United Arab Emirates', 'ARE', 784),
('GB', 'UNITED KINGDOM', 'United Kingdom', 'GBR', 826),
('US', 'UNITED STATES', 'United States', 'USA', 840),
('UM', 'UNITED STATES MINOR OUTLYING ISLANDS', 'United States Minor Outlying Islands', NULL, NULL),
('UY', 'URUGUAY', 'Uruguay', 'URY', 858),
('UZ', 'UZBEKISTAN', 'Uzbekistan', 'UZB', 860),
('VU', 'VANUATU', 'Vanuatu', 'VUT', 548),
('VE', 'VENEZUELA', 'Venezuela', 'VEN', 862),
('VN', 'VIET NAM', 'Viet Nam', 'VNM', 704),
('VG', 'VIRGIN ISLANDS, BRITISH', 'Virgin Islands, British', 'VGB', 92),
('VI', 'VIRGIN ISLANDS, U.S.', 'Virgin Islands, U.s.', 'VIR', 850),
('WF', 'WALLIS AND FUTUNA', 'Wallis and Futuna', 'WLF', 876),
('EH', 'WESTERN SAHARA', 'Western Sahara', 'ESH', 732),
('YE', 'YEMEN', 'Yemen', 'YEM', 887),
('ZM', 'ZAMBIA', 'Zambia', 'ZMB', 894),
('ZW', 'ZIMBABWE', 'Zimbabwe', 'ZWE', 716);
-- --------------------------------------------------------
-- --------------------------------------------------------
SET FOREIGN_KEY_CHECKS = 1;
/*
Copyright (c) 2007-2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
--
-- ISPConfig 3
-- DB-Version: 3.0.0.9
--
SET FOREIGN_KEY_CHECKS = 0;
-- --------------------------------------------------------
-- --------------------------------------------------------
-- DB-STRUCTURE
-- --------------------------------------------------------
-- --------------------------------------------------------
--
-- Table structure for table  `client`
--
CREATE TABLE `client` (
  `client_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `company_name` varchar(64) default NULL,
  `contact_name` varchar(64) default NULL,
  `street` varchar(255) default NULL,
  `zip` varchar(32) default NULL,
  `city` varchar(64) default NULL,
  `state` varchar(32) default NULL,
  `country` char(2) default NULL,
  `telephone` varchar(32) default NULL,
  `mobile` varchar(32) default NULL,
  `fax` varchar(32) default NULL,
  `email` varchar(255) default NULL,
  `internet` varchar(255) NOT NULL,
  `icq` varchar(16) default NULL,
  `notes` text,
  `default_mailserver` int(11) unsigned NOT NULL default '1',
  `limit_maildomain` int(11) NOT NULL default '-1',
  `limit_mailbox` int(11) NOT NULL default '-1',
  `limit_mailalias` int(11) NOT NULL default '-1',
  `limit_mailforward` int(11) NOT NULL default '-1',
  `limit_mailcatchall` int(11) NOT NULL default '-1',
  `limit_mailrouting` int(11) NOT NULL default '0',
  `limit_mailfilter` int(11) NOT NULL default '-1',
  `limit_fetchmail` int(11) NOT NULL default '-1',
  `limit_mailquota` int(11) NOT NULL default '-1',
  `limit_spamfilter_wblist` int(11) NOT NULL default '0',
  `limit_spamfilter_user` int(11) NOT NULL default '0',
  `limit_spamfilter_policy` int(11) NOT NULL default '0',
  `default_webserver` int(11) unsigned NOT NULL default '1',
  `limit_web_ip` text,
  `limit_web_domain` int(11) NOT NULL default '-1',
  `web_php_options` varchar(255) NOT NULL default 'no,fast-cgi,cgi,mod,suphp',
  `limit_web_subdomain` int(11) NOT NULL default '-1',
  `limit_web_aliasdomain` int(11) NOT NULL default '-1',
  `limit_ftp_user` int(11) NOT NULL default '-1',
  `limit_shell_user` int(11) NOT NULL default '0',
  `ssh_chroot` varchar(255) NOT NULL DEFAULT 'no,jailkit,ssh-chroot',
  `default_dnsserver` int(11) unsigned NOT NULL default '1',
  `limit_dns_zone` int(11) NOT NULL default '-1',
  `limit_dns_record` int(11) NOT NULL default '-1',
  `default_dbserver` int(11) NOT NULL default '1',
  `limit_database` int(11) NOT NULL default '-1',
  `limit_client` int(11) NOT NULL default '0',
  `parent_client_id` int(11) unsigned NOT NULL default '0',
  `username` varchar(64) default NULL,
  `password` varchar(64) default NULL,
  `language` char(2) NOT NULL default 'en',
  `usertheme` varchar(32) NOT NULL default 'default',
  `template_master` int(11) unsigned NOT NULL default '0',
  `template_additional` varchar(255) NOT NULL default '',
  `created_at` datetime default NULL,
  PRIMARY KEY  (`client_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `client_template`
--
CREATE TABLE `client_template` (
  `template_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `template_name` varchar(64) NOT NULL,
  `template_type` varchar(1) NOT NULL default 'm',
  `limit_maildomain` int(11) NOT NULL default '-1',
  `limit_mailbox` int(11) NOT NULL default '-1',
  `limit_mailalias` int(11) NOT NULL default '-1',
  `limit_mailforward` int(11) NOT NULL default '-1',
  `limit_mailcatchall` int(11) NOT NULL default '-1',
  `limit_mailrouting` int(11) NOT NULL default '0',
  `limit_mailfilter` int(11) NOT NULL default '-1',
  `limit_fetchmail` int(11) NOT NULL default '-1',
  `limit_mailquota` int(11) NOT NULL default '-1',
  `limit_spamfilter_wblist` int(11) NOT NULL default '0',
  `limit_spamfilter_user` int(11) NOT NULL default '0',
  `limit_spamfilter_policy` int(11) NOT NULL default '0',
  `limit_web_ip` text,
  `limit_web_domain` int(11) NOT NULL default '-1',
  `limit_web_subdomain` int(11) NOT NULL default '-1',
  `limit_web_aliasdomain` int(11) NOT NULL default '-1',
  `limit_ftp_user` int(11) NOT NULL default '-1',
  `limit_shell_user` int(11) NOT NULL default '0',
  `limit_dns_zone` int(11) NOT NULL default '-1',
  `limit_dns_record` int(11) NOT NULL default '-1',
  `limit_database` int(11) NOT NULL default '-1',
  `limit_client` int(11) NOT NULL default '0',
  PRIMARY KEY  (`template_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `dns_rr`
--
CREATE TABLE `dns_rr` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) NOT NULL default '1',
  `zone` int(11) unsigned NOT NULL,
  `name` varchar(64) NOT NULL,
  `type` enum('A','AAAA','ALIAS','CNAME','HINFO','MX','NAPTR','NS','PTR','RP','SRV','TXT') default NULL,
  `data` varchar(255) NOT NULL,
  `aux` int(11) unsigned NOT NULL default '0',
  `ttl` int(11) unsigned NOT NULL default '86400',
  `active` enum('N','Y') NOT NULL default 'Y',
  `stamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `serial` int(10) unsigned default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `rr` (`zone`,`name`,`type`,`data`)
) ENGINE=MyISAM  AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `dns_soa`
--
CREATE TABLE `dns_soa` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) NOT NULL default '1',
  `origin` varchar(255) NOT NULL,
  `ns` varchar(255) NOT NULL,
  `mbox` varchar(255) NOT NULL,
  `serial` int(11) unsigned NOT NULL default '1',
  `refresh` int(11) unsigned NOT NULL default '28800',
  `retry` int(11) unsigned NOT NULL default '7200',
  `expire` int(11) unsigned NOT NULL default '604800',
  `minimum` int(11) unsigned NOT NULL default '86400',
  `ttl` int(11) unsigned NOT NULL default '86400',
  `active` enum('N','Y') NOT NULL,
  `xfer` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `origin` (`origin`),
  KEY `active` (`active`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `dns_template`
--
CREATE TABLE `dns_template` (
  `template_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `name` varchar(64) default NULL,
  `fields` varchar(255) default NULL,
  `template` text,
  `visible` enum('N','Y') NOT NULL default 'Y',
  PRIMARY KEY  (`template_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `firewall`
--
CREATE TABLE `firewall` (
  `firewall_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `tcp_port` varchar(255) default NULL,
  `udp_port` varchar(255) default NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`firewall_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `ftp_user`
--
CREATE TABLE `ftp_user` (
  `ftp_user_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `parent_domain_id` int(11) unsigned NOT NULL default '0',
  `username` varchar(64) default NULL,
  `password` varchar(64) default NULL,
  `quota_size` int(11) NOT NULL default '-1',
  `active` enum('n','y') NOT NULL default 'y',
  `uid` varchar(64) default NULL,
  `gid` varchar(64) default NULL,
  `dir` varchar(255) default NULL,
  `quota_files` int(11) NOT NULL default '-1',
  `ul_ratio` int(11) NOT NULL default '-1',
  `dl_ratio` int(11) NOT NULL default '-1',
  `ul_bandwidth` int(11) NOT NULL default '-1',
  `dl_bandwidth` int(11) NOT NULL default '-1',
  PRIMARY KEY  (`ftp_user_id`),
  KEY `active` (`active`),
  KEY `server_id` (`server_id`),
  KEY `username` (`username`),
  KEY `quota_files` (`quota_files`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_access`
--
CREATE TABLE `mail_access` (
  `access_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) NOT NULL default '0',
  `source` varchar(255) NOT NULL,
  `access` varchar(255) NOT NULL,
  `type` set('recipient','sender','client') NOT NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`access_id`),
  KEY `server_id` (`server_id`,`source`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_content_filter`
--
CREATE TABLE `mail_content_filter` (
  `content_filter_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) NOT NULL default '0',
  `type` varchar(255) default NULL,
  `pattern` varchar(255) default NULL,
  `data` varchar(255) default NULL,
  `action` varchar(255) default NULL,
  `active` varchar(255) NOT NULL default 'y',
  PRIMARY KEY  (`content_filter_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_domain`
--
CREATE TABLE `mail_domain` (
  `domain_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `domain` varchar(255) NOT NULL default '',
  `active` enum('n','y') NOT NULL,
  PRIMARY KEY  (`domain_id`),
  KEY `server_id` (`server_id`,`domain`),
  KEY `domain_active` (`domain`,`active`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_forwarding`
--
CREATE TABLE `mail_forwarding` (
  `forwarding_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `source` varchar(255) NOT NULL,
  `destination` varchar(255) NOT NULL default '',
  `type` enum('alias','forward','catchall') NOT NULL default 'alias',
  `active` enum('n','y') NOT NULL,
  PRIMARY KEY  (`forwarding_id`),
  KEY `server_id` (`server_id`,`source`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_get`
--
CREATE TABLE `mail_get` (
  `mailget_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `type` varchar(255) default NULL,
  `source_server` varchar(255) default NULL,
  `source_username` varchar(255) default NULL,
  `source_password` varchar(64) default NULL,
  `source_delete` varchar(255) NOT NULL default 'y',
  `destination` varchar(255) default NULL,
  `active` varchar(255) NOT NULL default 'y',
  PRIMARY KEY  (`mailget_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_greylist`
--
CREATE TABLE `mail_greylist` (
  `greylist_id` int(11) unsigned NOT NULL auto_increment,
  `relay_ip` varchar(39) default NULL,
  `from_domain` varchar(255) default NULL,
  `block_expires` datetime NOT NULL default '0000-00-00 00:00:00',
  `record_expires` datetime NOT NULL default '0000-00-00 00:00:00',
  `origin_type` enum('MANUAL','AUTO') NOT NULL default 'AUTO',
  `create_time` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`greylist_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_mailman_domain`
--
CREATE TABLE `mail_mailman_domain` (
  `mailman_id` int(11) unsigned NOT NULL auto_increment,
  `server_id` int(11) unsigned NOT NULL default '0',
  `domain` varchar(255) NOT NULL default '',
  `mm_home` varchar(255) NOT NULL default '',
  `mm_wrap` varchar(255) NOT NULL default '',
  `mm_user` varchar(50) NOT NULL default '',
  `mm_group` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`mailman_id`,`server_id`,`domain`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_traffic`
--
CREATE TABLE `mail_traffic` (
  `traffic_id` int(11) unsigned NOT NULL auto_increment,
  `mailuser_id` int(11) unsigned NOT NULL,
  `month` char(7) NOT NULL,
  `traffic` bigint(20) unsigned NOT NULL,
  PRIMARY KEY  (`traffic_id`),
  KEY `mailuser_id` (`mailuser_id`,`month`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_transport`
--
CREATE TABLE `mail_transport` (
  `transport_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `domain` varchar(255) NOT NULL default '',
  `transport` varchar(255) NOT NULL,
  `sort_order` int(11) unsigned NOT NULL default '5',
  `active` enum('n','y') NOT NULL,
  PRIMARY KEY  (`transport_id`),
  KEY `server_id` (`server_id`,`transport`),
  KEY `server_id_2` (`server_id`,`domain`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_user`
--
CREATE TABLE `mail_user` (
  `mailuser_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_id` int(11) unsigned NOT NULL default '0',
  `email` varchar(255) NOT NULL default '',
  `password` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL default '',
  `uid` int(11) unsigned NOT NULL default '5000',
  `gid` int(11) unsigned NOT NULL default '5000',
  `maildir` varchar(255) NOT NULL default '',
  `quota` int(11) NOT NULL default '0',
  `homedir` varchar(255) NOT NULL,
  `autoresponder` enum('n','y') NOT NULL default 'n',
  `autoresponder_text` mediumtext NULL,
  `custom_mailfilter` mediumtext,
  `postfix` enum('n','y') NOT NULL,
  `access` enum('n','y') NOT NULL,
  `disableimap` enum('0','1') NOT NULL default '0',
  `disablepop3` enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (`mailuser_id`),
  KEY `server_id` (`server_id`,`email`),
  KEY `email_access` (`email`,`access`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `mail_user_filter`
--
CREATE TABLE `mail_user_filter` (
  `filter_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `mailuser_id` int(11) unsigned NOT NULL default '0',
  `rulename` varchar(64) default NULL,
  `source` varchar(255) default NULL,
  `searchterm` varchar(255) default NULL,
  `op` varchar(255) default NULL,
  `action` varchar(255) default NULL,
  `target` varchar(255) default NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`filter_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `remote_session`
--
CREATE TABLE `remote_session` (
  `remote_session` varchar(64) NOT NULL,
  `remote_userid` int(11) unsigned NOT NULL,
  `remote_functions` text NOT NULL,
  `tstamp` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`remote_session`)
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- Table structure for table  `remote_user`
--
CREATE TABLE `remote_user` (
  `remote_userid` int(11) unsigned NOT NULL auto_increment,
  `remote_username` varchar(64) NOT NULL,
  `remote_password` varchar(64) NOT NULL,
  `remote_functions` text NOT NULL,
  PRIMARY KEY  (`remote_userid`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `server`
--
CREATE TABLE `server` (
  `server_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) NOT NULL default '',
  `sys_perm_group` varchar(5) NOT NULL default '',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `server_name` varchar(255) NOT NULL default '',
  `mail_server` tinyint(1) NOT NULL default '0',
  `web_server` tinyint(1) NOT NULL default '0',
  `dns_server` tinyint(1) NOT NULL default '0',
  `file_server` tinyint(1) NOT NULL default '0',
  `db_server` tinyint(1) NOT NULL default '0',
  `vserver_server` tinyint(1) NOT NULL default '0',
  `config` text NOT NULL,
  `updated` bigint(20) unsigned NOT NULL default '0',
  `active` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`server_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `server_ip`
--
CREATE TABLE `server_ip` (
  `server_ip_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `ip_address` varchar(39) default NULL,
  `virtualhost` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`server_ip_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
CREATE TABLE `shell_user` (
  `shell_user_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `parent_domain_id` int(11) unsigned NOT NULL default '0',
  `username` varchar(64) default NULL,
  `password` varchar(64) default NULL,
  `quota_size` int(11) NOT NULL default '-1',
  `active` enum('n','y') NOT NULL default 'y',
  `puser` varchar(255) default NULL,
  `pgroup` varchar(255) default NULL,
  `shell` varchar(255) NOT NULL default '/bin/bash',
  `dir` varchar(255) default NULL,
  `chroot` varchar(255) NOT NULL,
  PRIMARY KEY  (`shell_user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_package`
--
CREATE TABLE `software_package` (
  `package_id` int(11) unsigned NOT NULL auto_increment,
  `software_repo_id` int(11) unsigned NOT NULL,
  `package_name` varchar(64) NOT NULL,
  `package_title` varchar(64) NOT NULL,
  `package_description` text,
  `package_version` varchar(8) default NULL,
  PRIMARY KEY  (`package_id`),
  UNIQUE KEY `package_name` (`package_name`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_repo`
--
CREATE TABLE `software_repo` (
  `software_repo_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `repo_name` varchar(64) default NULL,
  `repo_url` varchar(255) default NULL,
  `repo_username` varchar(64) default NULL,
  `repo_password` varchar(64) default NULL,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`software_repo_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_update`
--
CREATE TABLE `software_update` (
  `software_update_id` int(11) unsigned NOT NULL auto_increment,
  `software_repo_id` int(11) unsigned NOT NULL,
  `package_name` varchar(64) NOT NULL,
  `update_url` varchar(255) NOT NULL,
  `update_md5` varchar(255) NOT NULL,
  `update_dependencies` varchar(255) NOT NULL,
  `update_title` varchar(64) NOT NULL,
  `v1` tinyint(1) NOT NULL default '0',
  `v2` tinyint(1) NOT NULL default '0',
  `v3` tinyint(1) NOT NULL default '0',
  `v4` tinyint(1) NOT NULL default '0',
  `type` enum('full','update') NOT NULL default 'full',
  PRIMARY KEY  (`software_update_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `software_update_inst`
--
CREATE TABLE `software_update_inst` (
  `software_update_inst_id` int(11) unsigned NOT NULL auto_increment,
  `software_update_id` int(11) unsigned NOT NULL default '0',
  `package_name` varchar(64) NOT NULL,
  `server_id` int(11) unsigned NOT NULL,
  `status` enum('none','installing','installed','deleting','deleted') NOT NULL default 'none',
  PRIMARY KEY  (`software_update_inst_id`),
  UNIQUE KEY `software_update_id` (`software_update_id`,`package_name`,`server_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `spamfilter_policy`
--
CREATE TABLE `spamfilter_policy` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `policy_name` varchar(64) default NULL,
  `virus_lover` enum('N','Y') default NULL,
  `spam_lover` enum('N','Y') default NULL,
  `banned_files_lover` enum('N','Y') default NULL,
  `bad_header_lover` enum('N','Y') default NULL,
  `bypass_virus_checks` enum('N','Y') default NULL,
  `bypass_spam_checks` enum('N','Y') default NULL,
  `bypass_banned_checks` enum('N','Y') default NULL,
  `bypass_header_checks` enum('N','Y') default NULL,
  `spam_modifies_subj` enum('N','Y') default NULL,
  `virus_quarantine_to` varchar(255) default NULL,
  `spam_quarantine_to` varchar(255) default NULL,
  `banned_quarantine_to` varchar(255) default NULL,
  `bad_header_quarantine_to` varchar(255) default NULL,
  `clean_quarantine_to` varchar(255) default NULL,
  `other_quarantine_to` varchar(255) default NULL,
  `spam_tag_level` float default NULL,
  `spam_tag2_level` float default NULL,
  `spam_kill_level` float default NULL,
  `spam_dsn_cutoff_level` float default NULL,
  `spam_quarantine_cutoff_level` float default NULL,
  `addr_extension_virus` varchar(64) default NULL,
  `addr_extension_spam` varchar(64) default NULL,
  `addr_extension_banned` varchar(64) default NULL,
  `addr_extension_bad_header` varchar(64) default NULL,
  `warnvirusrecip` enum('N','Y') default NULL,
  `warnbannedrecip` enum('N','Y') default NULL,
  `warnbadhrecip` enum('N','Y') default NULL,
  `newvirus_admin` varchar(64) default NULL,
  `virus_admin` varchar(64) default NULL,
  `banned_admin` varchar(64) default NULL,
  `bad_header_admin` varchar(64) default NULL,
  `spam_admin` varchar(64) default NULL,
  `spam_subject_tag` varchar(64) default NULL,
  `spam_subject_tag2` varchar(64) default NULL,
  `message_size_limit` int(11) unsigned default NULL,
  `banned_rulenames` varchar(64) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table  `spamfilter_users`
--
CREATE TABLE `spamfilter_users` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) unsigned NOT NULL,
  `priority` tinyint(3) unsigned NOT NULL default '7',
  `policy_id` int(11) unsigned NOT NULL default '1',
  `email` varchar(255) NOT NULL,
  `fullname` varchar(64) default NULL,
  `local` varchar(1) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `spamfilter_wblist`
--
CREATE TABLE `spamfilter_wblist` (
  `wblist_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL,
  `sys_groupid` int(11) unsigned NOT NULL,
  `sys_perm_user` varchar(5) NOT NULL,
  `sys_perm_group` varchar(5) NOT NULL,
  `sys_perm_other` varchar(5) NOT NULL,
  `server_id` int(11) unsigned NOT NULL,
  `wb` enum('W','B') NOT NULL default 'W',
  `rid` int(11) unsigned NOT NULL,
  `email` varchar(255) NOT NULL,
  `priority` tinyint(3) unsigned NOT NULL,
  `active` enum('y','n') NOT NULL default 'y',
  PRIMARY KEY  (`wblist_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `support_message`
--
CREATE TABLE `support_message` (
  `support_message_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `recipient_id` int(11) unsigned NOT NULL default '0',
  `sender_id` int(11) unsigned NOT NULL default '0',
  `subject` varchar(255) default NULL,
  `message` text default NULL,
  `tstamp` int(11) NOT NULL default '0',
  PRIMARY KEY  (`support_message_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_datalog`
--
CREATE TABLE `sys_datalog` (
  `datalog_id` int(11) unsigned NOT NULL auto_increment,
  `server_id` int(11) unsigned NOT NULL,
  `dbtable` varchar(255) NOT NULL default '',
  `dbidx` varchar(255) NOT NULL default '',
  `action` char(1) NOT NULL default '',
  `tstamp` int(11) NOT NULL default '0',
  `user` varchar(255) NOT NULL default '',
  `data` text NOT NULL,
  `status` set('pending','ok','warning','error') NOT NULL default 'pending',
  PRIMARY KEY  (`datalog_id`),
  KEY `server_id` (`server_id`,`status`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_dbsync`
--
CREATE TABLE `sys_dbsync` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `jobname` varchar(64) NOT NULL default '',
  `sync_interval_minutes` int(11) unsigned NOT NULL default '0',
  `db_type` varchar(16) NOT NULL default '',
  `db_host` varchar(255) NOT NULL default '',
  `db_name` varchar(64) NOT NULL default '',
  `db_username` varchar(64) NOT NULL default '',
  `db_password` varchar(64) NOT NULL default '',
  `db_tables` varchar(255) NOT NULL default 'admin,forms',
  `empty_datalog` int(11) unsigned NOT NULL default '0',
  `sync_datalog_external` int(11) unsigned NOT NULL default '0',
  `active` tinyint(1) NOT NULL default '1',
  `last_datalog_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `last_datalog_id` (`last_datalog_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_filesync`
--
CREATE TABLE `sys_filesync` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `jobname` varchar(64) NOT NULL default '',
  `sync_interval_minutes` int(11) unsigned NOT NULL default '0',
  `ftp_host` varchar(255) NOT NULL default '',
  `ftp_path` varchar(255) NOT NULL default '',
  `ftp_username` varchar(64) NOT NULL default '',
  `ftp_password` varchar(64) NOT NULL default '',
  `local_path` varchar(255) NOT NULL default '',
  `wput_options` varchar(255) NOT NULL default '--timestamping --reupload --dont-continue',
  `active` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_group`
--
CREATE TABLE `sys_group` (
  `groupid` int(11) unsigned NOT NULL auto_increment,
  `name` varchar(64) NOT NULL default '',
  `description` text NOT NULL,
  `client_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`groupid`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_ini`
--
CREATE TABLE `sys_ini` (
  `sysini_id` int(11) unsigned NOT NULL auto_increment,
  `config` longtext NOT NULL,
  PRIMARY KEY  (`sysini_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_log`
--
CREATE TABLE `sys_log` (
  `syslog_id` int(11) unsigned NOT NULL auto_increment,
  `server_id` int(11) unsigned NOT NULL default '0',
  `datalog_id` int(11) unsigned NOT NULL default '0',
  `loglevel` tinyint(4) NOT NULL default '0',
  `tstamp` int(11) unsigned NOT NULL,
  `message` text,
  PRIMARY KEY  (`syslog_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_user`
--
CREATE TABLE `sys_user` (
  `userid` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '1',
  `sys_groupid` int(11) unsigned NOT NULL default '1',
  `sys_perm_user` varchar(5) NOT NULL default 'riud',
  `sys_perm_group` varchar(5) NOT NULL default 'riud',
  `sys_perm_other` varchar(5) NOT NULL default '',
  `username` varchar(64) NOT NULL default '',
  `passwort` varchar(64) NOT NULL default '',
  `modules` varchar(255) NOT NULL default '',
  `startmodule` varchar(255) NOT NULL default '',
  `app_theme` varchar(32) NOT NULL default 'default',
  `typ` varchar(16) NOT NULL default 'user',
  `active` tinyint(1) NOT NULL default '1',
  `language` varchar(2) NOT NULL default 'de',
  `groups` varchar(255) NOT NULL default '',
  `default_group` int(11) unsigned NOT NULL default '0',
  `client_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`userid`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `web_domain`
--
CREATE TABLE `web_domain` (
  `domain_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `ip_address` varchar(39) default NULL,
  `domain` varchar(255) default NULL,
  `type` varchar(32) default NULL,
  `parent_domain_id` int(11) unsigned NOT NULL default '0',
  `vhost_type` varchar(32) default NULL,
  `document_root` varchar(255) default NULL,
  `system_user` varchar(255) default NULL,
  `system_group` varchar(255) default NULL,
  `hd_quota` int(11) NOT NULL default '0',
  `traffic_quota` int(11) NOT NULL default '0',
  `cgi` enum('n','y') NOT NULL default 'y',
  `ssi` enum('n','y') NOT NULL default 'y',
  `suexec` enum('n','y') NOT NULL default 'y',
  `errordocs` tinyint(1) NOT NULL default '1',
  `is_subdomainwww` tinyint(1) NOT NULL default '1',
  `subdomain` enum('none','www','*') NOT NULL default 'none',
  `php` varchar(32) NOT NULL default 'y',
  `redirect_type` varchar(255) default NULL,
  `redirect_path` varchar(255) default NULL,
  `ssl` enum('n','y') NOT NULL default 'n',
  `ssl_state` varchar(255) NULL,
  `ssl_locality` varchar(255) NULL,
  `ssl_organisation` varchar(255) NULL,
  `ssl_organisation_unit` varchar(255) NULL,
  `ssl_country` varchar(255) NULL,
  `ssl_request` mediumtext NULL,
  `ssl_cert` mediumtext NULL,
  `ssl_bundle` mediumtext NULL,
  `ssl_action` varchar(16) NULL,
  `stats_password` varchar(255) default NULL,
  `apache_directives` text,
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`domain_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `web_database`
--
CREATE TABLE `web_database` (
  `database_id` int(11) unsigned NOT NULL auto_increment,
  `sys_userid` int(11) unsigned NOT NULL default '0',
  `sys_groupid` int(11) unsigned NOT NULL default '0',
  `sys_perm_user` varchar(5) default NULL,
  `sys_perm_group` varchar(5) default NULL,
  `sys_perm_other` varchar(5) default NULL,
  `server_id` int(11) unsigned NOT NULL default '0',
  `type` varchar(16) NOT NULL default 'y',
  `database_name` varchar(64) default NULL,
  `database_user` varchar(64) default NULL,
  `database_password` varchar(64) default NULL,
  `database_charset` varchar(64) default NULL,
  `remote_access` enum('n','y') NOT NULL default 'y',
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`database_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table  `attempts_login`
--
CREATE TABLE `attempts_login` (
  `ip` varchar(39) NOT NULL,
  `times` int(11) default NULL,
  `login_time` timestamp
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- Table structure for table  `monitor_data`
--
CREATE TABLE `monitor_data` (
  `server_id` int(11) unsigned NOT NULL,
  `type` varchar(255) NOT NULL,
  `created` int(11) unsigned NOT NULL,
  `data` mediumtext NOT NULL,
  `state` enum('no_state', 'unknown', 'ok', 'info', 'warning', 'critical', 'error') NOT NULL default 'unknown',
  PRIMARY KEY  (`server_id`,`type`,`created`)
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- Table structure for table  `sys_config`
--
CREATE TABLE `sys_config` (
  `config_id` int(11) unsigned NOT NULL,
  `group` varchar(64) NOT NULL,
  `name` varchar(64) NOT NULL,
  `value` varchar(255) NOT NULL
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
-- iso_country_list.sql
--
-- This will create and then populate a MySQL table with a list of the names and
-- ISO 3166 codes for countries in existence as of the date below.
--
-- For updates to this file, see http://27.org/isocountrylist/
-- For more about ISO 3166, see http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
--
-- Created by getisocountrylist.pl on Sun Nov  2 14:59:20 2003.
-- Wm. Rhodes <iso_country_list@27.org>
--
--
-- Table structure for table `country`
--
CREATE TABLE `country` (
  `iso` char(2) NOT NULL PRIMARY KEY,
  `name` varchar(64) NOT NULL,
  `printable_name` varchar(64) NOT NULL,
  `iso3` char(3),
  `numcode` SMALLINT
) ENGINE=MyISAM;
-- --------------------------------------------------------
-- --------------------------------------------------------
-- DB-DATA
-- --------------------------------------------------------
-- --------------------------------------------------------
--
-- Dumping data for table `dns_template`
--
INSERT INTO `dns_template` (`template_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `name`, `fields`, `template`, `visible`) VALUES (1, 1, 1, 'riud', 'riud', '', 'Default', 'DOMAIN,IP,NS1,NS2,EMAIL', '[ZONE]\norigin={DOMAIN}.\nns={NS1}.\nmbox={EMAIL}.\nrefresh=28800\nretry=7200\nexpire=604800\nminimum=86400\nttl=86400\n\n[DNS_RECORDS]\nA|{DOMAIN}.|{IP}|0|86400\nA|www|{IP}|0|86400\nA|mail|{IP}|0|86400\nNS|{DOMAIN}.|{NS1}.|0|86400\nNS|{DOMAIN}.|{NS2}.|0|86400\nMX|{DOMAIN}.|mail.{DOMAIN}.|10|86400', 'y');
-- --------------------------------------------------------
--
-- Dumping data for table `software_repo`
--
INSERT INTO `software_repo` (`software_repo_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `repo_name`, `repo_url`, `repo_username`, `repo_password`, `active`) VALUES (1, 1, 1, 'riud', 'riud', '', 'ISPConfig Addons', 'http://repo.ispconfig.org/addons/', '', '', 'n');
-- --------------------------------------------------------
--
-- Dumping data for table `spamfilter_policy`
--
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (1, 1, 0, 'riud', 'riud', 'r', 'Non-paying', 'N', 'N', 'N', 'N', 'Y', 'Y', 'Y', 'N', 'Y', '', '', '', '', '', '', 3, 7, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (2, 1, 0, 'riud', 'riud', 'r', 'Uncensored', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'N', 'N', 'N', NULL, NULL, NULL, NULL, NULL, NULL, 3, 999, 999, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (3, 1, 0, 'riud', 'riud', 'r', 'Wants all spam', 'N', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 999, 999, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (4, 1, 0, 'riud', 'riud', 'r', 'Wants viruses', 'Y', 'N', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 6.9, 6.9, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (5, 1, 0, 'riud', 'riud', 'r', 'Normal', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 6.9, 6.9, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (6, 1, 0, 'riud', 'riud', 'r', 'Trigger happy', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 5, 5, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `spamfilter_policy` (`id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `policy_name`, `virus_lover`, `spam_lover`, `banned_files_lover`, `bad_header_lover`, `bypass_virus_checks`, `bypass_spam_checks`, `bypass_banned_checks`, `bypass_header_checks`, `spam_modifies_subj`, `virus_quarantine_to`, `spam_quarantine_to`, `banned_quarantine_to`, `bad_header_quarantine_to`, `clean_quarantine_to`, `other_quarantine_to`, `spam_tag_level`, `spam_tag2_level`, `spam_kill_level`, `spam_dsn_cutoff_level`, `spam_quarantine_cutoff_level`, `addr_extension_virus`, `addr_extension_spam`, `addr_extension_banned`, `addr_extension_bad_header`, `warnvirusrecip`, `warnbannedrecip`, `warnbadhrecip`, `newvirus_admin`, `virus_admin`, `banned_admin`, `bad_header_admin`, `spam_admin`, `spam_subject_tag`, `spam_subject_tag2`, `message_size_limit`, `banned_rulenames`) VALUES (7, 1, 0, 'riud', 'riud', 'r', 'Permissive', 'N', 'N', 'N', 'Y', 'N', 'N', 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, 3, 10, 20, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-- --------------------------------------------------------
--
-- Dumping data for table `sys_group`
--
INSERT INTO `sys_group` (`groupid`, `name`, `description`, `client_id`) VALUES (1, 'admin', 'Administrators group', 0);
-- --------------------------------------------------------
--
-- Dumping data for table `sys_ini`
--
INSERT INTO `sys_ini` (`sysini_id`, `config`) VALUES (1, '');
-- --------------------------------------------------------
--
-- Dumping data for table `sys_user`
--
INSERT INTO `sys_user` (`userid`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `username`, `passwort`, `modules`, `startmodule`, `app_theme`, `typ`, `active`, `language`, `groups`, `default_group`, `client_id`) VALUES (1, 1, 0, 'riud', 'riud', '', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin,client,mail,monitor,sites,dns,tools,help', 'mail', 'default', 'admin', 1, 'en', '1,2', 1, 0);
-- --------------------------------------------------------
--
-- Dumping data for table `sys_config`
--
INSERT INTO sys_config VALUES ('1','db','db_version','3.0.1.2');
-- --------------------------------------------------------
--
-- iso_country_list.sql
--
-- This will create and then populate a MySQL table with a list of the names and
-- ISO 3166 codes for countries in existence as of the date below.
--
-- For updates to this file, see http://27.org/isocountrylist/
-- For more about ISO 3166, see http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
--
-- Created by getisocountrylist.pl on Sun Nov  2 14:59:20 2003.
-- Wm. Rhodes <iso_country_list@27.org>
--
--
-- Dumping data for table `country`
--
INSERT INTO `country` (`iso`, `name`, `printable_name`, `iso3`, `numcode`) VALUES
('AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4),
('AL', 'ALBANIA', 'Albania', 'ALB', 8),
('DZ', 'ALGERIA', 'Algeria', 'DZA', 12),
('AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', 16),
('AD', 'ANDORRA', 'Andorra', 'AND', 20),
('AO', 'ANGOLA', 'Angola', 'AGO', 24),
('AI', 'ANGUILLA', 'Anguilla', 'AIA', 660),
('AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL),
('AG', 'ANTIGUA AND BARBUDA', 'Antigua and Barbuda', 'ATG', 28),
('AR', 'ARGENTINA', 'Argentina', 'ARG', 32),
('AM', 'ARMENIA', 'Armenia', 'ARM', 51),
('AW', 'ARUBA', 'Aruba', 'ABW', 533),
('AU', 'AUSTRALIA', 'Australia', 'AUS', 36),
('AT', 'AUSTRIA', 'Austria', 'AUT', 40),
('AZ', 'AZERBAIJAN', 'Azerbaijan', 'AZE', 31),
('BS', 'BAHAMAS', 'Bahamas', 'BHS', 44),
('BH', 'BAHRAIN', 'Bahrain', 'BHR', 48),
('BD', 'BANGLADESH', 'Bangladesh', 'BGD', 50),
('BB', 'BARBADOS', 'Barbados', 'BRB', 52),
('BY', 'BELARUS', 'Belarus', 'BLR', 112),
('BE', 'BELGIUM', 'Belgium', 'BEL', 56),
('BZ', 'BELIZE', 'Belize', 'BLZ', 84),
('BJ', 'BENIN', 'Benin', 'BEN', 204),
('BM', 'BERMUDA', 'Bermuda', 'BMU', 60),
('BT', 'BHUTAN', 'Bhutan', 'BTN', 64),
('BO', 'BOLIVIA', 'Bolivia', 'BOL', 68),
('BA', 'BOSNIA AND HERZEGOVINA', 'Bosnia and Herzegovina', 'BIH', 70),
('BW', 'BOTSWANA', 'Botswana', 'BWA', 72),
('BV', 'BOUVET ISLAND', 'Bouvet Island', NULL, NULL),
('BR', 'BRAZIL', 'Brazil', 'BRA', 76),
('IO', 'BRITISH INDIAN OCEAN TERRITORY', 'British Indian Ocean Territory', NULL, NULL),
('BN', 'BRUNEI DARUSSALAM', 'Brunei Darussalam', 'BRN', 96),
('BG', 'BULGARIA', 'Bulgaria', 'BGR', 100),
('BF', 'BURKINA FASO', 'Burkina Faso', 'BFA', 854),
('BI', 'BURUNDI', 'Burundi', 'BDI', 108),
('KH', 'CAMBODIA', 'Cambodia', 'KHM', 116),
('CM', 'CAMEROON', 'Cameroon', 'CMR', 120),
('CA', 'CANADA', 'Canada', 'CAN', 124),
('CV', 'CAPE VERDE', 'Cape Verde', 'CPV', 132),
('KY', 'CAYMAN ISLANDS', 'Cayman Islands', 'CYM', 136),
('CF', 'CENTRAL AFRICAN REPUBLIC', 'Central African Republic', 'CAF', 140),
('TD', 'CHAD', 'Chad', 'TCD', 148),
('CL', 'CHILE', 'Chile', 'CHL', 152),
('CN', 'CHINA', 'China', 'CHN', 156),
('CX', 'CHRISTMAS ISLAND', 'Christmas Island', NULL, NULL),
('CC', 'COCOS (KEELING) ISLANDS', 'Cocos (Keeling) Islands', NULL, NULL),
('CO', 'COLOMBIA', 'Colombia', 'COL', 170),
('KM', 'COMOROS', 'Comoros', 'COM', 174),
('CG', 'CONGO', 'Congo', 'COG', 178),
('CD', 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', 'Congo, the Democratic Republic of the', 'COD', 180),
('CK', 'COOK ISLANDS', 'Cook Islands', 'COK', 184),
('CR', 'COSTA RICA', 'Costa Rica', 'CRI', 188),
('CI', 'COTE D''IVOIRE', 'Cote D''Ivoire', 'CIV', 384),
('HR', 'CROATIA', 'Croatia', 'HRV', 191),
('CU', 'CUBA', 'Cuba', 'CUB', 192),
('CY', 'CYPRUS', 'Cyprus', 'CYP', 196),
('CZ', 'CZECH REPUBLIC', 'Czech Republic', 'CZE', 203),
('DK', 'DENMARK', 'Denmark', 'DNK', 208),
('DJ', 'DJIBOUTI', 'Djibouti', 'DJI', 262),
('DM', 'DOMINICA', 'Dominica', 'DMA', 212),
('DO', 'DOMINICAN REPUBLIC', 'Dominican Republic', 'DOM', 214),
('EC', 'ECUADOR', 'Ecuador', 'ECU', 218),
('EG', 'EGYPT', 'Egypt', 'EGY', 818),
('SV', 'EL SALVADOR', 'El Salvador', 'SLV', 222),
('GQ', 'EQUATORIAL GUINEA', 'Equatorial Guinea', 'GNQ', 226),
('ER', 'ERITREA', 'Eritrea', 'ERI', 232),
('EE', 'ESTONIA', 'Estonia', 'EST', 233),
('ET', 'ETHIOPIA', 'Ethiopia', 'ETH', 231),
('FK', 'FALKLAND ISLANDS (MALVINAS)', 'Falkland Islands (Malvinas)', 'FLK', 238),
('FO', 'FAROE ISLANDS', 'Faroe Islands', 'FRO', 234),
('FJ', 'FIJI', 'Fiji', 'FJI', 242),
('FI', 'FINLAND', 'Finland', 'FIN', 246),
('FR', 'FRANCE', 'France', 'FRA', 250),
('GF', 'FRENCH GUIANA', 'French Guiana', 'GUF', 254),
('PF', 'FRENCH POLYNESIA', 'French Polynesia', 'PYF', 258),
('TF', 'FRENCH SOUTHERN TERRITORIES', 'French Southern Territories', NULL, NULL),
('GA', 'GABON', 'Gabon', 'GAB', 266),
('GM', 'GAMBIA', 'Gambia', 'GMB', 270),
('GE', 'GEORGIA', 'Georgia', 'GEO', 268),
('DE', 'GERMANY', 'Germany', 'DEU', 276),
('GH', 'GHANA', 'Ghana', 'GHA', 288),
('GI', 'GIBRALTAR', 'Gibraltar', 'GIB', 292),
('GR', 'GREECE', 'Greece', 'GRC', 300),
('GL', 'GREENLAND', 'Greenland', 'GRL', 304),
('GD', 'GRENADA', 'Grenada', 'GRD', 308),
('GP', 'GUADELOUPE', 'Guadeloupe', 'GLP', 312),
('GU', 'GUAM', 'Guam', 'GUM', 316),
('GT', 'GUATEMALA', 'Guatemala', 'GTM', 320),
('GN', 'GUINEA', 'Guinea', 'GIN', 324),
('GW', 'GUINEA-BISSAU', 'Guinea-Bissau', 'GNB', 624),
('GY', 'GUYANA', 'Guyana', 'GUY', 328),
('HT', 'HAITI', 'Haiti', 'HTI', 332),
('HM', 'HEARD ISLAND AND MCDONALD ISLANDS', 'Heard Island and Mcdonald Islands', NULL, NULL),
('VA', 'HOLY SEE (VATICAN CITY STATE)', 'Holy See (Vatican City State)', 'VAT', 336),
('HN', 'HONDURAS', 'Honduras', 'HND', 340),
('HK', 'HONG KONG', 'Hong Kong', 'HKG', 344),
('HU', 'HUNGARY', 'Hungary', 'HUN', 348),
('IS', 'ICELAND', 'Iceland', 'ISL', 352),
('IN', 'INDIA', 'India', 'IND', 356),
('ID', 'INDONESIA', 'Indonesia', 'IDN', 360),
('IR', 'IRAN, ISLAMIC REPUBLIC OF', 'Iran, Islamic Republic of', 'IRN', 364),
('IQ', 'IRAQ', 'Iraq', 'IRQ', 368),
('IE', 'IRELAND', 'Ireland', 'IRL', 372),
('IL', 'ISRAEL', 'Israel', 'ISR', 376),
('IT', 'ITALY', 'Italy', 'ITA', 380),
('JM', 'JAMAICA', 'Jamaica', 'JAM', 388),
('JP', 'JAPAN', 'Japan', 'JPN', 392),
('JO', 'JORDAN', 'Jordan', 'JOR', 400),
('KZ', 'KAZAKHSTAN', 'Kazakhstan', 'KAZ', 398),
('KE', 'KENYA', 'Kenya', 'KEN', 404),
('KI', 'KIRIBATI', 'Kiribati', 'KIR', 296),
('KP', 'KOREA, DEMOCRATIC PEOPLE''S REPUBLIC OF', 'Korea, Democratic People''s Republic of', 'PRK', 408),
('KR', 'KOREA, REPUBLIC OF', 'Korea, Republic of', 'KOR', 410),
('KW', 'KUWAIT', 'Kuwait', 'KWT', 414),
('KG', 'KYRGYZSTAN', 'Kyrgyzstan', 'KGZ', 417),
('LA', 'LAO PEOPLE''S DEMOCRATIC REPUBLIC', 'Lao People''s Democratic Republic', 'LAO', 418),
('LV', 'LATVIA', 'Latvia', 'LVA', 428),
('LB', 'LEBANON', 'Lebanon', 'LBN', 422),
('LS', 'LESOTHO', 'Lesotho', 'LSO', 426),
('LR', 'LIBERIA', 'Liberia', 'LBR', 430),
('LY', 'LIBYAN ARAB JAMAHIRIYA', 'Libyan Arab Jamahiriya', 'LBY', 434),
('LI', 'LIECHTENSTEIN', 'Liechtenstein', 'LIE', 438),
('LT', 'LITHUANIA', 'Lithuania', 'LTU', 440),
('LU', 'LUXEMBOURG', 'Luxembourg', 'LUX', 442),
('MO', 'MACAO', 'Macao', 'MAC', 446),
('MK', 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', 'Macedonia, the Former Yugoslav Republic of', 'MKD', 807),
('MG', 'MADAGASCAR', 'Madagascar', 'MDG', 450),
('MW', 'MALAWI', 'Malawi', 'MWI', 454),
('MY', 'MALAYSIA', 'Malaysia', 'MYS', 458),
('MV', 'MALDIVES', 'Maldives', 'MDV', 462),
('ML', 'MALI', 'Mali', 'MLI', 466),
('MT', 'MALTA', 'Malta', 'MLT', 470),
('MH', 'MARSHALL ISLANDS', 'Marshall Islands', 'MHL', 584),
('MQ', 'MARTINIQUE', 'Martinique', 'MTQ', 474),
('MR', 'MAURITANIA', 'Mauritania', 'MRT', 478),
('MU', 'MAURITIUS', 'Mauritius', 'MUS', 480),
('YT', 'MAYOTTE', 'Mayotte', NULL, NULL),
('MX', 'MEXICO', 'Mexico', 'MEX', 484),
('FM', 'MICRONESIA, FEDERATED STATES OF', 'Micronesia, Federated States of', 'FSM', 583),
('MD', 'MOLDOVA, REPUBLIC OF', 'Moldova, Republic of', 'MDA', 498),
('MC', 'MONACO', 'Monaco', 'MCO', 492),
('MN', 'MONGOLIA', 'Mongolia', 'MNG', 496),
('MS', 'MONTSERRAT', 'Montserrat', 'MSR', 500),
('MA', 'MOROCCO', 'Morocco', 'MAR', 504),
('MZ', 'MOZAMBIQUE', 'Mozambique', 'MOZ', 508),
('MM', 'MYANMAR', 'Myanmar', 'MMR', 104),
('NA', 'NAMIBIA', 'Namibia', 'NAM', 516),
('NR', 'NAURU', 'Nauru', 'NRU', 520),
('NP', 'NEPAL', 'Nepal', 'NPL', 524),
('NL', 'NETHERLANDS', 'Netherlands', 'NLD', 528),
('AN', 'NETHERLANDS ANTILLES', 'Netherlands Antilles', 'ANT', 530),
('NC', 'NEW CALEDONIA', 'New Caledonia', 'NCL', 540),
('NZ', 'NEW ZEALAND', 'New Zealand', 'NZL', 554),
('NI', 'NICARAGUA', 'Nicaragua', 'NIC', 558),
('NE', 'NIGER', 'Niger', 'NER', 562),
('NG', 'NIGERIA', 'Nigeria', 'NGA', 566),
('NU', 'NIUE', 'Niue', 'NIU', 570),
('NF', 'NORFOLK ISLAND', 'Norfolk Island', 'NFK', 574),
('MP', 'NORTHERN MARIANA ISLANDS', 'Northern Mariana Islands', 'MNP', 580),
('NO', 'NORWAY', 'Norway', 'NOR', 578),
('OM', 'OMAN', 'Oman', 'OMN', 512),
('PK', 'PAKISTAN', 'Pakistan', 'PAK', 586),
('PW', 'PALAU', 'Palau', 'PLW', 585),
('PS', 'PALESTINIAN TERRITORY, OCCUPIED', 'Palestinian Territory, Occupied', NULL, NULL),
('PA', 'PANAMA', 'Panama', 'PAN', 591),
('PG', 'PAPUA NEW GUINEA', 'Papua New Guinea', 'PNG', 598),
('PY', 'PARAGUAY', 'Paraguay', 'PRY', 600),
('PE', 'PERU', 'Peru', 'PER', 604),
('PH', 'PHILIPPINES', 'Philippines', 'PHL', 608),
('PN', 'PITCAIRN', 'Pitcairn', 'PCN', 612),
('PL', 'POLAND', 'Poland', 'POL', 616),
('PT', 'PORTUGAL', 'Portugal', 'PRT', 620),
('PR', 'PUERTO RICO', 'Puerto Rico', 'PRI', 630),
('QA', 'QATAR', 'Qatar', 'QAT', 634),
('RE', 'REUNION', 'Reunion', 'REU', 638),
('RO', 'ROMANIA', 'Romania', 'ROM', 642),
('RU', 'RUSSIAN FEDERATION', 'Russian Federation', 'RUS', 643),
('RW', 'RWANDA', 'Rwanda', 'RWA', 646),
('SH', 'SAINT HELENA', 'Saint Helena', 'SHN', 654),
('KN', 'SAINT KITTS AND NEVIS', 'Saint Kitts and Nevis', 'KNA', 659),
('LC', 'SAINT LUCIA', 'Saint Lucia', 'LCA', 662),
('PM', 'SAINT PIERRE AND MIQUELON', 'Saint Pierre and Miquelon', 'SPM', 666),
('VC', 'SAINT VINCENT AND THE GRENADINES', 'Saint Vincent and the Grenadines', 'VCT', 670),
('WS', 'SAMOA', 'Samoa', 'WSM', 882),
('SM', 'SAN MARINO', 'San Marino', 'SMR', 674),
('ST', 'SAO TOME AND PRINCIPE', 'Sao Tome and Principe', 'STP', 678),
('SA', 'SAUDI ARABIA', 'Saudi Arabia', 'SAU', 682),
('SN', 'SENEGAL', 'Senegal', 'SEN', 686),
('CS', 'SERBIA AND MONTENEGRO', 'Serbia and Montenegro', NULL, NULL),
('SC', 'SEYCHELLES', 'Seychelles', 'SYC', 690),
('SL', 'SIERRA LEONE', 'Sierra Leone', 'SLE', 694),
('SG', 'SINGAPORE', 'Singapore', 'SGP', 702),
('SK', 'SLOVAKIA', 'Slovakia', 'SVK', 703),
('SI', 'SLOVENIA', 'Slovenia', 'SVN', 705),
('SB', 'SOLOMON ISLANDS', 'Solomon Islands', 'SLB', 90),
('SO', 'SOMALIA', 'Somalia', 'SOM', 706),
('ZA', 'SOUTH AFRICA', 'South Africa', 'ZAF', 710),
('GS', 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', 'South Georgia and the South Sandwich Islands', NULL, NULL),
('ES', 'SPAIN', 'Spain', 'ESP', 724),
('LK', 'SRI LANKA', 'Sri Lanka', 'LKA', 144),
('SD', 'SUDAN', 'Sudan', 'SDN', 736),
('SR', 'SURINAME', 'Suriname', 'SUR', 740),
('SJ', 'SVALBARD AND JAN MAYEN', 'Svalbard and Jan Mayen', 'SJM', 744),
('SZ', 'SWAZILAND', 'Swaziland', 'SWZ', 748),
('SE', 'SWEDEN', 'Sweden', 'SWE', 752),
('CH', 'SWITZERLAND', 'Switzerland', 'CHE', 756),
('SY', 'SYRIAN ARAB REPUBLIC', 'Syrian Arab Republic', 'SYR', 760),
('TW', 'TAIWAN, PROVINCE OF CHINA', 'Taiwan, Province of China', 'TWN', 158),
('TJ', 'TAJIKISTAN', 'Tajikistan', 'TJK', 762),
('TZ', 'TANZANIA, UNITED REPUBLIC OF', 'Tanzania, United Republic of', 'TZA', 834),
('TH', 'THAILAND', 'Thailand', 'THA', 764),
('TL', 'TIMOR-LESTE', 'Timor-Leste', NULL, NULL),
('TG', 'TOGO', 'Togo', 'TGO', 768),
('TK', 'TOKELAU', 'Tokelau', 'TKL', 772),
('TO', 'TONGA', 'Tonga', 'TON', 776),
('TT', 'TRINIDAD AND TOBAGO', 'Trinidad and Tobago', 'TTO', 780),
('TN', 'TUNISIA', 'Tunisia', 'TUN', 788),
('TR', 'TURKEY', 'Turkey', 'TUR', 792),
('TM', 'TURKMENISTAN', 'Turkmenistan', 'TKM', 795),
('TC', 'TURKS AND CAICOS ISLANDS', 'Turks and Caicos Islands', 'TCA', 796),
('TV', 'TUVALU', 'Tuvalu', 'TUV', 798),
('UG', 'UGANDA', 'Uganda', 'UGA', 800),
('UA', 'UKRAINE', 'Ukraine', 'UKR', 804),
('AE', 'UNITED ARAB EMIRATES', 'United Arab Emirates', 'ARE', 784),
('GB', 'UNITED KINGDOM', 'United Kingdom', 'GBR', 826),
('US', 'UNITED STATES', 'United States', 'USA', 840),
('UM', 'UNITED STATES MINOR OUTLYING ISLANDS', 'United States Minor Outlying Islands', NULL, NULL),
('UY', 'URUGUAY', 'Uruguay', 'URY', 858),
('UZ', 'UZBEKISTAN', 'Uzbekistan', 'UZB', 860),
('VU', 'VANUATU', 'Vanuatu', 'VUT', 548),
('VE', 'VENEZUELA', 'Venezuela', 'VEN', 862),
('VN', 'VIET NAM', 'Viet Nam', 'VNM', 704),
('VG', 'VIRGIN ISLANDS, BRITISH', 'Virgin Islands, British', 'VGB', 92),
('VI', 'VIRGIN ISLANDS, U.S.', 'Virgin Islands, U.s.', 'VIR', 850),
('WF', 'WALLIS AND FUTUNA', 'Wallis and Futuna', 'WLF', 876),
('EH', 'WESTERN SAHARA', 'Western Sahara', 'ESH', 732),
('YE', 'YEMEN', 'Yemen', 'YEM', 887),
('ZM', 'ZAMBIA', 'Zambia', 'ZMB', 894),
('ZW', 'ZIMBABWE', 'Zimbabwe', 'ZWE', 716);
-- --------------------------------------------------------
-- --------------------------------------------------------
SET FOREIGN_KEY_CHECKS = 1;
install/tpl/apache_ispconfig.conf.master
@@ -4,7 +4,7 @@
# ISPConfig Logfile configuration for vlogger
################################################
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
LogFormat "%v %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
CustomLog "| /usr/sbin/vlogger -s access.log -t \"%Y%m%d-access.log\" /var/log/ispconfig/httpd" combined_ispconfig
<Directory /var/www/clients>
install/tpl/config.inc.php.master
@@ -57,7 +57,7 @@
//** Application
define('ISPC_APP_TITLE', 'ISPConfig');
define('ISPC_APP_VERSION', '3.0.1.1');
define('ISPC_APP_VERSION', '3.0.1.2');
//** Database
@@ -133,7 +133,7 @@
//** Default Language
$conf["language"] = 'en';
$conf["language"] = '{language}';
//** Misc.
install/tpl/pureftpd_mysql.conf.master
@@ -97,21 +97,21 @@
# The number should be in Megabytes.
# Pure-FTPd must have been compiled with virtual quotas support.
MySQLGetQTASZ  SELECT quota_size FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L"
MySQLGetQTASZ  SELECT quota_size FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_size != '-1' AND username="\L"
# Optional : ratios. The server has to be compiled with ratio support.
MySQLGetRatioUL SELECT ul_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L"
MySQLGetRatioDL SELECT dl_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L"
MySQLGetRatioUL SELECT ul_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND ul_ratio != '-1' AND username="\L"
MySQLGetRatioDL SELECT dl_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND dl_ratio != '-1' AND username="\L"
# Optional : bandwidth throttling.
# The server has to be compiled with throttling support.
# Values are in KB/s .
MySQLGetBandwidthUL SELECT ul_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L"
MySQLGetBandwidthDL SELECT dl_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L"
MySQLGetBandwidthUL SELECT ul_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND ul_bandwidth != '-1' AND username="\L"
MySQLGetBandwidthDL SELECT dl_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND dl_bandwidth != '-1' AND username="\L"
# Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :
# 1) You know what you are doing.
install/update.php
@@ -88,6 +88,7 @@
$conf['mysql']['charset'] = 'utf8';
$conf["mysql"]["ispconfig_user"] = $conf_old["db_user"];
$conf["mysql"]["ispconfig_password"] = $conf_old["db_password"];
$conf['language'] = $conf_old['language'];
if(isset($conf_old["dbmaster_host"])) $conf["mysql"]["master_host"] = $conf_old["dbmaster_host"];
if(isset($conf_old["dbmaster_database"])) $conf["mysql"]["master_database"] = $conf_old["dbmaster_database"];
interface/lib/classes/tform.inc.php
@@ -160,11 +160,11 @@
                        foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) {
                                switch ($field['datatype']) {
                                case 'VARCHAR':
                                        $new_record[$key] = stripslashes($record[$key]);
                                        $new_record[$key] = $record[$key];
                                break;
                                case 'TEXT':
                                        $new_record[$key] = stripslashes($record[$key]);
                                        $new_record[$key] = $record[$key];
                                break;
                                case 'DATE':
@@ -186,7 +186,7 @@
                                break;
                                default:
                                        $new_record[$key] = stripslashes($record[$key]);
                                        $new_record[$key] = $record[$key];
                                }
                        }
interface/web/client/templates/client_edit_limits.htm
@@ -75,7 +75,7 @@
            </div>
      <div class="ctrlHolder">
          <label for="limit_mailquota">{tmpl_var name='limit_mailquota_txt'}</label>
        <input name="limit_mailquota" id="limit_mailquota" value="{tmpl_var name='limit_mailquota'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" />
        <input name="limit_mailquota" id="limit_mailquota" value="{tmpl_var name='limit_mailquota'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" />&nbsp;MB
            </div>
      <div class="ctrlHolder">
          <label for="limit_spamfilter_wblist">{tmpl_var name='limit_spamfilter_wblist_txt'}</label>
interface/web/dns/dns_a_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_aaaa_edit.php
New file
@@ -0,0 +1,139 @@
<?php
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/******************************************
* Begin Form configuration
******************************************/
$tform_def_file = "form/dns_aaaa.tform.php";
/******************************************
* End Form configuration
******************************************/
require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');
//* Check permissions for module
$app->auth->check_module_permissions('dns');
// Loading classes
$app->uses('tpl,tform,tform_actions,validate_dns');
$app->load('tform_actions');
class page_action extends tform_actions {
    function onShowNew() {
        global $app, $conf;
        // we will check only users, not admins
        if($_SESSION["s"]["user"]["typ"] == 'user') {
            // Get the limits of the client
            $client_group_id = $_SESSION["s"]["user"]["default_group"];
            $client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
            // Check if the user may add another mailbox.
            if($client["limit_dns_record"] >= 0) {
                $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id");
                if($tmp["number"] >= $client["limit_dns_record"]) {
                    $app->error($app->tform->wordbook["limit_dns_record_txt"]);
                }
            }
        }
        parent::onShowNew();
    }
    function onSubmit() {
        global $app, $conf;
        // Get the parent soa record of the domain
        $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = '".intval($_POST["zone"])."' AND ".$app->tform->getAuthSQL('r'));
        // Check if Domain belongs to user
        if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"];
        // Check the client limits, if user is not the admin
        if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
            // Get the limits of the client
            $client_group_id = $_SESSION["s"]["user"]["default_group"];
            $client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
            // Check if the user may add another mailbox.
            if($this->id == 0 && $client["limit_dns_record"] >= 0) {
                $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id");
                if($tmp["number"] >= $client["limit_dns_record"]) {
                    $app->error($app->tform->wordbook["limit_dns_record_txt"]);
                }
            }
        } // end if user is not admin
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    function onAfterInsert() {
        global $app, $conf;
        //* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
        $soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = '".intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r'));
        $app->db->datalogUpdate('dns_rr', "sys_groupid = ".$soa['sys_groupid'], 'id', $this->id);
        //* Update the serial number of the SOA record
        $soa_id = intval($_POST["zone"]);
        $serial = $app->validate_dns->increase_serial($soa["serial"]);
        $app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id);
    }
    function onAfterUpdate() {
        global $app, $conf;
        //* Update the serial number of the SOA record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = '".intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r'));
        $soa_id = intval($_POST["zone"]);
        $serial = $app->validate_dns->increase_serial($soa["serial"]);
        $app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id);
    }
}
$page = new page_action;
$page->onLoad();
?>
interface/web/dns/dns_alias_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_cname_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_hinfo_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_mx_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_ns_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_ptr_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_rp_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_soa_edit.php
@@ -175,6 +175,18 @@
            // And we want to update all rr records too, that belong to this record
            $app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
        }
        //** When the client group has changed, change also the owner of the record if the owner is not the admin user
        if($this->oldDataRecord["client_group_id"] != $this->dataRecord["client_group_id"] && $this->dataRecord["sys_userid"] != 1) {
            $client_group_id = intval($this->dataRecord["client_group_id"]);
            $tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
            if($tmp["userid"] > 0) {
                $app->db->query("UPDATE dns_soa SET sys_userid = ".$tmp["userid"]." WHERE id = ".$this->id);
                $app->db->query("UPDATE dns_rr SET sys_userid = ".$tmp["userid"]." WHERE zone = ".$this->id);
            }
        }
    }
    
}
interface/web/dns/dns_srv_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/dns_txt_edit.php
@@ -100,6 +100,11 @@
        // Set the server ID of the rr record to the same server ID as the parent record.
        $this->dataRecord["server_id"] = $soa["server_id"];
        
        // Update the serial number  and timestamp of the RR record
        $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
        $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
        $this->dataRecord["stamp"] = date('Y-m-d H:i:s');
        parent::onSubmit();
    }
    
interface/web/dns/form/dns_a.tform.php
@@ -132,6 +132,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_aaaa.tform.php
New file
@@ -0,0 +1,159 @@
<?php
/*
    Form Definition
    Tabledefinition
    Datatypes:
    - INTEGER (Forces the input to Int)
    - DOUBLE
    - CURRENCY (Formats the values to currency notation)
    - VARCHAR (no format check, maxlength: 255)
    - TEXT (no format check)
    - DATE (Dateformat, automatic conversion to timestamps)
    Formtype:
    - TEXT (Textfield)
    - TEXTAREA (Textarea)
    - PASSWORD (Password textfield, input is not shown when edited)
    - SELECT (Select option field)
    - RADIO
    - CHECKBOX
    - CHECKBOXARRAY
    - FILE
    VALUE:
    - Wert oder Array
    Hint:
    The ID field of the database table is not part of the datafield definition.
    The ID field must be always auto incement (int or bigint).
*/
$form["title"]             = "DNS AAAA";
$form["description"]     = "";
$form["name"]             = "dns_aaaa";
$form["action"]            = "dns_aaaa_edit.php";
$form["db_table"]        = "dns_rr";
$form["db_table_idx"]    = "id";
$form["db_history"]        = "yes";
$form["tab_default"]    = "dns";
$form["list_default"]    = "dns_a_list.php";
$form["auth"]            = 'yes'; // yes / no
$form["auth_preset"]["userid"]  = 0; // 0 = id of the user, > 0 id must match with id of current user
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
$form["tabs"]['dns'] = array (
    'title'     => "DNS AAAA",
    'width'     => 100,
    'template'     => "templates/dns_aaaa_edit.htm",
    'fields'     => array (
    ##################################
    # Begin Datatable fields
    ##################################
        'server_id' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'SELECT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'zone' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => @intval($_REQUEST["zone"]),
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'name' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'validators'    => array (     0 => array (    'type'    => 'REGEX',
                                                        'regex' => '/^[\w\.\-\*]{0,64}$/',
                                                        'errmsg'=> 'name_error_regex'),
                                    ),
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'type' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => 'AAAA',
            'value'        => '',
            'width'        => '5',
            'maxlength'    => '5'
        ),
        'data' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'validators'    => array (     0 => array (    'type'    => 'NOTEMPTY',
                                                        'errmsg'=> 'data_error_empty'),
                                        1 => array (    'type'    => 'REGEX',
                                                        'regex' => '/^\s*((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}(:|((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){4}(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}(:[0-9A-Fa-f]{1,4}){0,2}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4}){0,4}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))(%.+)?\s*$/',
                                                        'errmsg'=> 'data_error_regex'),
                                    ),
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        /*
        'aux' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '0',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
        */
        'ttl' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '86400',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
        'active' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'CHECKBOX',
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
    )
);
?>
interface/web/dns/form/dns_alias.tform.php
@@ -134,6 +134,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_cname.tform.php
@@ -78,7 +78,7 @@
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'validators'    => array (     0 => array (    'type'    => 'REGEX',
                                                        'regex' => '/^[\w\.\-]{0,64}$/',
                                                        'regex' => '/^[\w\.\-\*]{0,64}$/',
                                                        'errmsg'=> 'name_error_regex'),
                                    ),
            'default'    => '',
@@ -132,6 +132,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_hinfo.tform.php
@@ -131,6 +131,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_mx.tform.php
@@ -132,6 +132,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_ns.tform.php
@@ -132,6 +132,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_ptr.tform.php
@@ -134,6 +134,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_rp.tform.php
@@ -132,6 +132,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_srv.tform.php
@@ -129,6 +129,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/form/dns_txt.tform.php
@@ -129,6 +129,22 @@
            'default'    => 'Y',
            'value'        => array(0 => 'N',1 => 'Y')
        ),
        'stamp' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '30',
            'maxlength'    => '255'
        ),
        'serial' => array (
            'datatype'    => 'INTEGER',
            'formtype'    => 'TEXT',
            'default'    => '',
            'value'        => '',
            'width'        => '10',
            'maxlength'    => '10'
        ),
    ##################################
    # ENDE Datatable fields
    ##################################
interface/web/dns/lib/lang/en_dns_aaaa.lng
New file
@@ -0,0 +1,15 @@
<?php
$wb["server_id_txt"] = 'Server';
$wb["zone_txt"] = 'Zone';
$wb["name_txt"] = 'Hostname';
$wb["type_txt"] = 'type';
$wb["data_txt"] = 'IPv6-Address';
$wb["ttl_txt"] = 'TTL';
$wb["active_txt"] = 'Active';
$wb["limit_dns_record_txt"] = 'The max. number of DNS records for your account is reached.';
$wb["no_zone_perm"] = 'You do not have the permission to add a record to this DNS zone.';
$wb["name_error_empty"] = 'The hostname is empty.';
$wb["name_error_regex"] = 'The hostname has the wrong format.';
$wb["data_error_empty"] = 'IP-Address empty';
$wb["data_error_regex"] = 'IP-Address format invalid';
?>
interface/web/dns/list/dns_a.list.php
@@ -121,7 +121,7 @@
                            'prefix'    => "",
                            'suffix'    => "",
                            'width'        => "",
                            'value'        => array('A'=>'A','ALIAS'=>'ALIAS','CNAME'=>'CNAME','HINFO'=>'HINFO','MX'=>'MX','NS'=>'NS','PTR'=>'PTR','RP'=>'RP','SRV'=>'SRV','TXT'=>'TXT'));
                            'value'        => array('A'=>'A','AAAA' => 'AAAA','ALIAS'=>'ALIAS','CNAME'=>'CNAME','HINFO'=>'HINFO','MX'=>'MX','NS'=>'NS','PTR'=>'PTR','RP'=>'RP','SRV'=>'SRV','TXT'=>'TXT'));
?>
interface/web/dns/templates/dns_a_list.htm
@@ -1,82 +1,85 @@
  <div class="pnl_toolsarea">
    <fieldset><legend>Tools</legend>
      <div class="buttons">
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_a_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>A</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_alias_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>ALIAS</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_cname_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>CNAME</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_hinfo_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>HINFO</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_mx_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>MX</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_ns_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>NS</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_ptr_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>PTR</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_rp_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>RP</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_srv_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>SRV</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_txt_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>TXT</span>
        </button>
      </div>
    </fieldset>
  </div>
  <div class="pnl_listarea">
    <fieldset><legend><tmpl_var name="list_head_txt"></legend>
      <table class="list">
        <thead>
          <tr>
            <th class="tbl_col_active" scope="col"><tmpl_var name="active_txt"></th>
            <th class="tbl_col_type" scope="col"><tmpl_var name="type_txt"></th>
            <th class="tbl_col_name" scope="col"><tmpl_var name="name_txt"></th>
            <th class="tbl_col_data" scope="col"><tmpl_var name="data_txt"></th>
            <th class="tbl_col_aux" scope="col"><tmpl_var name="aux_txt"></th>
            <th class="tbl_col_buttons" scope="col">&nbsp;</th>
          </tr>
          <tr>
            <td class="tbl_col_active"><select name="search_active" onChange="changeTab('dns_records','dns/dns_soa_edit.php');">{tmpl_var name='search_active'}</select></td>
            <td class="tbl_col_type"><select name="search_type" onChange="changeTab('dns_records','dns/dns_soa_edit.php');">{tmpl_var name='search_type'}</select></td>
            <td class="tbl_col_name"><input type="text" name="search_name" value="{tmpl_var name='search_name'}" /></td>
            <td class="tbl_col_data"><input type="text" name="search_data" value="{tmpl_var name='search_data'}" /></td>
            <td class="tbl_col_aux"><input type="text" name="search_aux" value="{tmpl_var name='search_aux'}" /></td>
            <td class="tbl_col_buttons"><div class="buttons"><button type="button" class="icons16 icoFilter" name="Filter" id="Filter" value="{tmpl_var name="filter_txt"}" onClick="changeTab('dns_records','dns/dns_soa_edit.php');"><span>{tmpl_var name="filter_txt"}</span></button></div></td>
          </tr>
        </thead>
        <tbody>
          <tmpl_loop name="records">
          <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
            <td class="tbl_col_active"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');"><img src="themes/{tmpl_var name='theme'}/icons/{tmpl_var name='_active_'}" border="0" /></a></td>
            <td class="tbl_col_type"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="type"}</a></td>
            <td class="tbl_col_name"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="name"}</a></td>
            <td class="tbl_col_data"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="data"}</a></td>
            <td class="tbl_col_aux"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="aux"}</a></td>
            <td class="tbl_col_buttons">
              <div class="buttons icons16">
                <a class="icons16 icoDelete" href="javascript: del_record('dns/dns_rr_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a>
              </div>
            </td>
          </tr>
          </tmpl_loop>
        </tbody>
        <tfoot>
          <tr>
            <td class="tbl_footer tbl_paging" colspan="6"><tmpl_var name="paging"></td>
          </tr>
        </tfoot>
      </table>
    </fieldset>
  </div>
  <div class="pnl_toolsarea">
    <fieldset><legend>Tools</legend>
      <div class="buttons">
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_a_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>A</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_aaaa_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>AAAA</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_alias_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>ALIAS</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_cname_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>CNAME</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_hinfo_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>HINFO</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_mx_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>MX</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_ns_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>NS</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_ptr_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>PTR</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_rp_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>RP</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_srv_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>SRV</span>
        </button>
        <button class="iconstxt icoAdd" type="button" onClick="loadContent('dns/dns_txt_edit.php?zone={tmpl_var name='parent_id'}');">
          <span>TXT</span>
        </button>
      </div>
    </fieldset>
  </div>
  <div class="pnl_listarea">
    <fieldset><legend><tmpl_var name="list_head_txt"></legend>
      <table class="list">
        <thead>
          <tr>
            <th class="tbl_col_active" scope="col"><tmpl_var name="active_txt"></th>
            <th class="tbl_col_type" scope="col"><tmpl_var name="type_txt"></th>
            <th class="tbl_col_name" scope="col"><tmpl_var name="name_txt"></th>
            <th class="tbl_col_data" scope="col"><tmpl_var name="data_txt"></th>
            <th class="tbl_col_aux" scope="col"><tmpl_var name="aux_txt"></th>
            <th class="tbl_col_buttons" scope="col">&nbsp;</th>
          </tr>
          <tr>
            <td class="tbl_col_active"><select name="search_active" onChange="changeTab('dns_records','dns/dns_soa_edit.php');">{tmpl_var name='search_active'}</select></td>
            <td class="tbl_col_type"><select name="search_type" onChange="changeTab('dns_records','dns/dns_soa_edit.php');">{tmpl_var name='search_type'}</select></td>
            <td class="tbl_col_name"><input type="text" name="search_name" value="{tmpl_var name='search_name'}" /></td>
            <td class="tbl_col_data"><input type="text" name="search_data" value="{tmpl_var name='search_data'}" /></td>
            <td class="tbl_col_aux"><input type="text" name="search_aux" value="{tmpl_var name='search_aux'}" /></td>
            <td class="tbl_col_buttons"><div class="buttons"><button type="button" class="icons16 icoFilter" name="Filter" id="Filter" value="{tmpl_var name="filter_txt"}" onClick="changeTab('dns_records','dns/dns_soa_edit.php');"><span>{tmpl_var name="filter_txt"}</span></button></div></td>
          </tr>
        </thead>
        <tbody>
          <tmpl_loop name="records">
          <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
            <td class="tbl_col_active"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');"><img src="themes/{tmpl_var name='theme'}/icons/{tmpl_var name='_active_'}" border="0" /></a></td>
            <td class="tbl_col_type"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="type"}</a></td>
            <td class="tbl_col_name"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="name"}</a></td>
            <td class="tbl_col_data"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="data"}</a></td>
            <td class="tbl_col_aux"><a href="#" onClick="loadContent('dns/dns_{tmpl_var name='type_lowercase'}_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="aux"}</a></td>
            <td class="tbl_col_buttons">
              <div class="buttons icons16">
                <a class="icons16 icoDelete" href="javascript: del_record('dns/dns_rr_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a>
              </div>
            </td>
          </tr>
          </tmpl_loop>
        </tbody>
        <tfoot>
          <tr>
            <td class="tbl_footer tbl_paging" colspan="6"><tmpl_var name="paging"></td>
          </tr>
        </tfoot>
      </table>
    </fieldset>
  </div>
interface/web/dns/templates/dns_aaaa_edit.htm
New file
@@ -0,0 +1,39 @@
<h2><tmpl_var name="list_head_txt"></h2>
<p><tmpl_var name="list_desc_txt"></p>
<div class="panel panel_dns_aaaa">
  <div class="pnl_formsarea">
    <fieldset class="inlineLabels">
      <div class="ctrlHolder">
          <label for="name">{tmpl_var name='name_txt'}</label>
        <input name="name" id="name" value="{tmpl_var name='name'}" size="30" maxlength="255" type="text" class="textInput" />
                <p class="formHint">{tmpl_var name='name_hint_txt'}</p>
            </div>
      <div class="ctrlHolder">
          <label for="data">{tmpl_var name='data_txt'}</label>
        <input name="data" id="data" value="{tmpl_var name='data'}" size="30" maxlength="255" type="text" class="textInput formLengthIPv4" />
            </div>
      <div class="ctrlHolder">
          <label for="ttl">{tmpl_var name='ttl_txt'}</label>
        <input name="ttl" id="ttl" value="{tmpl_var name='ttl'}" size="10" maxlength="10" type="text" class="textInput" />
            </div>
      <div class="ctrlHolder">
                <p class="label">{tmpl_var name='active_txt'}</p>
                    <div class="multiField">
                        {tmpl_var name='active'}
                    </div>
            </div>
    </fieldset>
    <input type="hidden" name="id" value="{tmpl_var name='id'}">
    <input type="hidden" name="zone" value="{tmpl_var name='zone'}">
    <input type="hidden" name="type" value="{tmpl_var name='type'}">
    <div class="buttonHolder buttons">
      <button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','dns/dns_aaaa_edit.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
      <button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('dns/dns_soa_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
    </div>
  </div>
</div>
interface/web/mail/mail_domain_catchall_edit.php
@@ -61,7 +61,7 @@
            $client = $app->db->queryOneRecord("SELECT limit_mailcatchall FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
            
            // Check if the user may add another mailbox.
            if($client["limit_mailforward"] >= 0) {
            if($client["limit_mailcatchall"] >= 0) {
                $tmp = $app->db->queryOneRecord("SELECT count(forwarding_id) as number FROM mail_forwarding WHERE sys_groupid = $client_group_id and type = 'catchall'");
                if($tmp["number"] >= $client["limit_mailcatchall"]) {
                    $app->error($app->tform->wordbook["limit_mailcatchall_txt"]);
interface/web/mail/mail_user_edit.php
@@ -254,7 +254,7 @@
            if($policy_id > 0) {
                if($tmp_user["id"] > 0) {
                    // There is already a record that we will update
                    $app->db->datalogUpdate('spamfilter_users', "policy_id = $ploicy_id", 'id', $tmp_user["id"]);
                    $app->db->datalogUpdate('spamfilter_users', "policy_id = $policy_id", 'id', $tmp_user["id"]);
                } else {
                    // We create a new record
                    $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) 
interface/web/sites/templates/web_domain_edit.htm
@@ -47,7 +47,7 @@
            </div>
      <div class="ctrlHolder">
          <label for="hd_quota">{tmpl_var name='hd_quota_txt'}</label>
        <input name="hd_quota" id="hd_quota" value="{tmpl_var name='hd_quota'}" size="7" maxlength="7" type="text" class="textInput formLengthLimit" />
        <input name="hd_quota" id="hd_quota" value="{tmpl_var name='hd_quota'}" size="7" maxlength="7" type="text" class="textInput formLengthLimit" />&nbsp;MB
            </div>
<!--
      <div class="ctrlHolder">
server/conf/apache_ispconfig.conf.master
@@ -3,7 +3,7 @@
# ISPConfig Logfile configuration for vlogger
################################################
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
LogFormat "%v %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
CustomLog "| /usr/sbin/vlogger -s access.log -t \"%Y%m%d-access.log\" /var/log/ispconfig/httpd" combined_ispconfig
<Directory /var/www/clients>
server/conf/vhost.conf.master
@@ -36,7 +36,7 @@
    
    <Directory {tmpl_var name='web_document_root_www'}>
        Options FollowSymLinks
        AllowOverride Indexes AuthConfig Limit
        AllowOverride Indexes AuthConfig Limit FileInfo
        Order allow,deny
        Allow from all
<tmpl_if name='ssi' op='==' value='y'>
@@ -56,7 +56,7 @@
    </Directory>
    <Directory {tmpl_var name='web_document_root'}>
        Options FollowSymLinks
        AllowOverride Indexes AuthConfig Limit
        AllowOverride Indexes AuthConfig Limit FileInfo
        Order allow,deny
        Allow from all
<tmpl_if name='ssi' op='==' value='y'>
@@ -185,7 +185,7 @@
    
    <Directory {tmpl_var name='web_document_root_www'}>
        Options FollowSymLinks
        AllowOverride Indexes AuthConfig Limit
        AllowOverride Indexes AuthConfig Limit FileInfo
        Order allow,deny
        Allow from all
<tmpl_if name='ssi' op='==' value='y'>
@@ -205,7 +205,7 @@
    </Directory>
    <Directory {tmpl_var name='web_document_root'}>
        Options FollowSymLinks
        AllowOverride Indexes AuthConfig Limit
        AllowOverride Indexes AuthConfig Limit FileInfo
        Order allow,deny
        Allow from all
<tmpl_if name='ssi' op='==' value='y'>
@@ -292,4 +292,4 @@
</VirtualHost>
</IfModule>
</tmpl_if>
</tmpl_if>
server/lib/classes/modules.inc.php
@@ -1,215 +1,234 @@
<?php
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class modules {
    var $notification_hooks = array();
    var $current_datalog_id = 0;
    var $debug = false;
    /*
     This function is called to load the modules from the mods-enabled or the mods-core folder
    */
    function loadModules($type) {
        global $app, $conf;
        $subPath = 'mods-enabled';
        if ($type == 'core') $subPath = 'mods-core';
        $modules_dir = $conf["rootpath"].$conf["fs_div"].$subPath.$conf["fs_div"];
        if (is_dir($modules_dir)) {
            if ($dh = opendir($modules_dir)) {
                while (($file = readdir($dh)) !== false) {
                    if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
                        $module_name = substr($file,0,-8);
                        include_once($modules_dir.$file);
                        if($this->debug) $app->log("Loading Module: $module_name",LOGLEVEL_DEBUG);
                        $app->loaded_modules[$module_name] = new $module_name;
                        $app->loaded_modules[$module_name]->onLoad();
                    }
                }
            }
        } else {
            $app->log("Modules directory missing: $modules_dir",LOGLEVEL_ERROR);
        }
    }
    /*
     This function is called by the modules to register for a specific
     table change notification
    */
    function registerTableHook($table_name,$module_name,$function_name) {
        global $app;
        $this->notification_hooks[$table_name][] = array('module' => $module_name, 'function' => $function_name);
        if($this->debug) $app->log("Registered TableHook '$table_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
    }
    /*
     This function goes through all new records in the
     sys_datalog table and and calls the function in the
     modules that hooked on to the table change.
    */
    function processDatalog() {
        global $app,$conf;
        //* If its a multiserver setup
        if($app->db->dbHost != $app->dbmaster->dbHost) {
            $sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
            $records = $app->dbmaster->queryAllRecords($sql);
            foreach($records as $d) {
                if(!$data = unserialize(stripslashes($d["data"]))) {
                    $data = unserialize($d["data"]);
                }
                $replication_error = false;
                $this->current_datalog_id = $d["datalog_id"];
                if(count($data['new']) > 0) {
                    if($d["action"] == 'i' || $d["action"] == 'u') {
                        $idx = explode(":",$d["dbidx"]);
                        $tmp_sql1 = '';
                        $tmp_sql2 = '';
                        foreach($data['new'] as $fieldname => $val) {
                            $tmp_sql1 .= "`$fieldname`,";
                            $tmp_sql2 .= "'$val',";
                        }
                        $tmp_sql1 = substr($tmp_sql1,0,-1);
                        $tmp_sql2 = substr($tmp_sql2,0,-1);
                        //$tmp_sql1 .= "$idx[0]";
                        //$tmp_sql2 .= "$idx[1]";
                        $sql = "REPLACE INTO $d[dbtable] ($tmp_sql1) VALUES ($tmp_sql2)";
                        $app->db->query($sql);
                        if($app->db->errorNumber > 0) {
                            $replication_error = true;
                            $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
                        }
                        $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
                    }
                    /*
                    if($d["action"] == 'u') {
                        $sql = "UPDATE $d[dbtable] SET ";
                        foreach($data['new'] as $fieldname => $val) {
                            $sql .= "`$fieldname` = '$val',";
                        }
                        $sql = substr($sql,0,-1);
                        $idx = explode(":",$d["dbidx"]);
                        $sql .= " WHERE $idx[0] = $idx[1]";
                        $app->db->query($sql);
                        if($app->db->errorNumber > 0) {
                            $replication_error = true;
                            $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
                        }
                        $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
                    }
                    */
                    if($d["action"] == 'd') {
                        $idx = explode(":",$d["dbidx"]);
                        $sql = "DELETE FROM $d[dbtable] ";
                        $sql .= " WHERE $idx[0] = $idx[1]";
                        $app->db->query($sql);
                        if($app->db->errorNumber > 0) {
                            $replication_error = true;
                            $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
                        }
                        $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
                    }
                    if($replication_error == false) {
                        $this->raiseTableHook($d["dbtable"],$d["action"],$data);
                        //$app->dbmaster->query("DELETE FROM sys_datalog WHERE datalog_id = ".$d["datalog_id"]);
                        //$app->log("Deleting sys_datalog ID ".$d["datalog_id"],LOGLEVEL_DEBUG);
                        $app->dbmaster->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
                        $app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
                    } else {
                        $app->log("Error in Replication, changes were not processed.",LOGLEVEL_ERROR);
                        /*
                         * If there is any error in processing the datalog we can't continue, because
                         * we do not know if the newer actions require this (old) one.
                         */
                        return;
                    }
                } else {
                    $app->log("Datalog does not conatin any changes for this record ".$d["datalog_id"],LOGLEVEL_DEBUG);
                }
            }
        //* if we have a single server setup
        } else {
            $sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
            $records = $app->db->queryAllRecords($sql);
            foreach($records as $d) {
                if(!$data = unserialize(utf8_encode(stripslashes($d["data"])))) {
                    $data = unserialize(utf8_encode($d["data"]));
                }
                $this->current_datalog_id = $d["datalog_id"];
                $this->raiseTableHook($d["dbtable"],$d["action"],$data);
                //$app->db->query("DELETE FROM sys_datalog WHERE datalog_id = ".$rec["datalog_id"]);
                //$app->log("Deleting sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG);
                $app->db->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
                $app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
            }
        }
    }
    function raiseTableHook($table_name,$action,$data) {
        global $app;
        // Get the hooks for this table
        $hooks = (isset($this->notification_hooks[$table_name]))?$this->notification_hooks[$table_name]:'';
        if($this->debug) $app->log("Raised TableHook for table: '$table_name'",LOGLEVEL_DEBUG);
        if(is_array($hooks)) {
            foreach($hooks as $hook) {
                $module_name = $hook["module"];
                $function_name = $hook["function"];
                // Claa the processing function of the module
                if($this->debug) $app->log("Call function '$function_name' in module '$module_name' raised by TableHook '$table_name'.",LOGLEVEL_DEBUG);
                call_user_method($function_name,$app->loaded_modules[$module_name],$table_name,$action,$data);
                unset($module_name);
                unset($function_name);
            }
        }
        unset($hook);
        unset($hooks);
    }
}
<?php
/*
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class modules {
    var $notification_hooks = array();
    var $current_datalog_id = 0;
    var $debug = false;
    /*
     This function is called to load the modules from the mods-enabled or the mods-core folder
    */
    function loadModules($type) {
        global $app, $conf;
        $subPath = 'mods-enabled';
        if ($type == 'core') $subPath = 'mods-core';
        $modules_dir = $conf["rootpath"].$conf["fs_div"].$subPath.$conf["fs_div"];
        if (is_dir($modules_dir)) {
            if ($dh = opendir($modules_dir)) {
                while (($file = readdir($dh)) !== false) {
                    if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
                        $module_name = substr($file,0,-8);
                        include_once($modules_dir.$file);
                        if($this->debug) $app->log("Loading Module: $module_name",LOGLEVEL_DEBUG);
                        $app->loaded_modules[$module_name] = new $module_name;
                        $app->loaded_modules[$module_name]->onLoad();
                    }
                }
            }
        } else {
            $app->log("Modules directory missing: $modules_dir",LOGLEVEL_ERROR);
        }
    }
    /*
     This function is called by the modules to register for a specific
     table change notification
    */
    function registerTableHook($table_name,$module_name,$function_name) {
        global $app;
        $this->notification_hooks[$table_name][] = array('module' => $module_name, 'function' => $function_name);
        if($this->debug) $app->log("Registered TableHook '$table_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
    }
    /*
     This function goes through all new records in the
     sys_datalog table and and calls the function in the
     modules that hooked on to the table change.
    */
    function processDatalog() {
        global $app,$conf;
        //* If its a multiserver setup
        if($app->db->dbHost != $app->dbmaster->dbHost) {
            $sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
            $records = $app->dbmaster->queryAllRecords($sql);
            foreach($records as $d) {
                //** encode data to utf-8 and unserialize it
                if(!$data = unserialize(utf8_encode(stripslashes($d["data"])))) {
                    $data = unserialize(utf8_encode($d["data"]));
                }
                //** Decode data back to locale
                foreach($data['old'] as $key => $val) {
                    $data['old'][$key] = utf8_decode($val);
                }
                foreach($data['new'] as $key => $val) {
                    $data['new'][$key] = utf8_decode($val);
                }
                $replication_error = false;
                $this->current_datalog_id = $d["datalog_id"];
                if(count($data['new']) > 0) {
                    if($d["action"] == 'i' || $d["action"] == 'u') {
                        $idx = explode(":",$d["dbidx"]);
                        $tmp_sql1 = '';
                        $tmp_sql2 = '';
                        foreach($data['new'] as $fieldname => $val) {
                            $tmp_sql1 .= "`$fieldname`,";
                            $tmp_sql2 .= "'$val',";
                        }
                        $tmp_sql1 = substr($tmp_sql1,0,-1);
                        $tmp_sql2 = substr($tmp_sql2,0,-1);
                        //$tmp_sql1 .= "$idx[0]";
                        //$tmp_sql2 .= "$idx[1]";
                        $sql = "REPLACE INTO $d[dbtable] ($tmp_sql1) VALUES ($tmp_sql2)";
                        $app->db->query($sql);
                        if($app->db->errorNumber > 0) {
                            $replication_error = true;
                            $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
                        }
                        $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
                    }
                    /*
                    if($d["action"] == 'u') {
                        $sql = "UPDATE $d[dbtable] SET ";
                        foreach($data['new'] as $fieldname => $val) {
                            $sql .= "`$fieldname` = '$val',";
                        }
                        $sql = substr($sql,0,-1);
                        $idx = explode(":",$d["dbidx"]);
                        $sql .= " WHERE $idx[0] = $idx[1]";
                        $app->db->query($sql);
                        if($app->db->errorNumber > 0) {
                            $replication_error = true;
                            $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
                        }
                        $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
                    }
                    */
                    if($d["action"] == 'd') {
                        $idx = explode(":",$d["dbidx"]);
                        $sql = "DELETE FROM $d[dbtable] ";
                        $sql .= " WHERE $idx[0] = $idx[1]";
                        $app->db->query($sql);
                        if($app->db->errorNumber > 0) {
                            $replication_error = true;
                            $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
                        }
                        $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
                    }
                    if($replication_error == false) {
                        $this->raiseTableHook($d["dbtable"],$d["action"],$data);
                        //$app->dbmaster->query("DELETE FROM sys_datalog WHERE datalog_id = ".$d["datalog_id"]);
                        //$app->log("Deleting sys_datalog ID ".$d["datalog_id"],LOGLEVEL_DEBUG);
                        $app->dbmaster->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
                        $app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
                    } else {
                        $app->log("Error in Replication, changes were not processed.",LOGLEVEL_ERROR);
                        /*
                         * If there is any error in processing the datalog we can't continue, because
                         * we do not know if the newer actions require this (old) one.
                         */
                        return;
                    }
                } else {
                    $app->log("Datalog does not conatin any changes for this record ".$d["datalog_id"],LOGLEVEL_DEBUG);
                }
            }
        //* if we have a single server setup
        } else {
            $sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
            $records = $app->db->queryAllRecords($sql);
            foreach($records as $d) {
                //** encode data to utf-8 to be able to unserialize it and then unserialize it
                if(!$data = unserialize(utf8_encode(stripslashes($d["data"])))) {
                    $data = unserialize(utf8_encode($d["data"]));
                }
                //** decode data back to current locale
                foreach($data['old'] as $key => $val) {
                    $data['old'][$key] = utf8_decode($val);
                }
                foreach($data['new'] as $key => $val) {
                    $data['new'][$key] = utf8_decode($val);
                }
                $this->current_datalog_id = $d["datalog_id"];
                $this->raiseTableHook($d["dbtable"],$d["action"],$data);
                //$app->db->query("DELETE FROM sys_datalog WHERE datalog_id = ".$rec["datalog_id"]);
                //$app->log("Deleting sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG);
                $app->db->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
                $app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
            }
        }
    }
    function raiseTableHook($table_name,$action,$data) {
        global $app;
        // Get the hooks for this table
        $hooks = (isset($this->notification_hooks[$table_name]))?$this->notification_hooks[$table_name]:'';
        if($this->debug) $app->log("Raised TableHook for table: '$table_name'",LOGLEVEL_DEBUG);
        if(is_array($hooks)) {
            foreach($hooks as $hook) {
                $module_name = $hook["module"];
                $function_name = $hook["function"];
                // Claa the processing function of the module
                if($this->debug) $app->log("Call function '$function_name' in module '$module_name' raised by TableHook '$table_name'.",LOGLEVEL_DEBUG);
                call_user_method($function_name,$app->loaded_modules[$module_name],$table_name,$action,$data);
                unset($module_name);
                unset($function_name);
            }
        }
        unset($hook);
        unset($hooks);
    }
}
?>
server/mods-available/monitor_core_module.inc.php
@@ -221,7 +221,7 @@
                $usePercent = floatval($data[$i]['percent']);
                
                //* We dont want to check the cdrom drive as a cd / dvd is always 100% full
                if($data[$i]['type'] != 'iso9660') {
                if($data[$i]['type'] != 'iso9660' && $data[$i]['type'] != 'cramfs') {
                    if ($usePercent > 75) $state = $this->_setState($state, 'info');
                    if ($usePercent > 80) $state = $this->_setState($state, 'warning');
                    if ($usePercent > 90) $state = $this->_setState($state, 'critical');
@@ -701,7 +701,8 @@
         *  This monitoring is expensive, so do it only once a hour
         */
        $min = date('i');
        if ($min != 0) return;
        $hour = date('H');
        if ($min != 0 && $hour != 23) return;
        global $app;
        global $conf;
server/plugins-available/apache2_plugin.inc.php
@@ -1,815 +1,832 @@
<?php
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class apache2_plugin {
    var $plugin_name = 'apache2_plugin';
    var $class_name = 'apache2_plugin';
    // private variables
    var $action = '';
    //* This function is called during ispconfig installation to determine
    //  if a symlink shall be created for this plugin.
    function onInstall() {
        global $conf;
        if($conf['services']['web'] == true) {
            return true;
        } else {
            return false;
        }
    }
    /*
         This function is called when the plugin is loaded
    */
    function onLoad() {
        global $app;
        /*
        Register for the events
        */
        $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'ssl');
        $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'ssl');
        $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'ssl');
        $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
        $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'update');
        $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'delete');
        $app->plugins->registerEvent('server_ip_insert',$this->plugin_name,'server_ip');
        $app->plugins->registerEvent('server_ip_update',$this->plugin_name,'server_ip');
        $app->plugins->registerEvent('server_ip_delete',$this->plugin_name,'server_ip');
    }
    // Handle the creation of SSL certificates
    function ssl($event_name,$data) {
        global $app, $conf;
        if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl");
        $ssl_dir = $data["new"]["document_root"]."/ssl";
        $domain = $data["new"]["domain"];
        $key_file = $ssl_dir.'/'.$domain.".key.org";
          $key_file2 = $ssl_dir.'/'.$domain.".key";
          $csr_file = $ssl_dir.'/'.$domain.".csr";
          $crt_file = $ssl_dir.'/'.$domain.".crt";
        //* Create a SSL Certificate
        if($data["new"]["ssl_action"] == 'create') {
            $rand_file = $ssl_dir."/random_file";
            $rand_data = md5(uniqid(microtime(),1));
            for($i=0; $i<1000; $i++){
                $rand_data .= md5(uniqid(microtime(),1));
                $rand_data .= md5(uniqid(microtime(),1));
                $rand_data .= md5(uniqid(microtime(),1));
                $rand_data .= md5(uniqid(microtime(),1));
            }
            file_put_contents($rand_file, $rand_data);
            $ssl_password = substr(md5(uniqid(microtime(),1)), 0, 15);
            $ssl_cnf = "        RANDFILE               = $rand_file
        [ req ]
        default_bits           = 1024
        default_keyfile        = keyfile.pem
        distinguished_name     = req_distinguished_name
        attributes             = req_attributes
        prompt                 = no
        output_password        = $ssl_password
        [ req_distinguished_name ]
        C                      = ".$data['new']['ssl_country']."
        ST                     = ".$data['new']['ssl_state']."
        L                      = ".$data['new']['ssl_locality']."
        O                      = ".$data['new']['ssl_organisation']."
        OU                     = ".$data['new']['ssl_organisation_unit']."
        CN                     = $domain
        emailAddress           = webmaster@".$data['new']['domain']."
        [ req_attributes ]
        challengePassword              = A challenge password";
            $ssl_cnf_file = $ssl_dir."/openssl.conf";
            file_put_contents($ssl_cnf_file,$ssl_cnf);
            $rand_file = escapeshellcmd($rand_file);
            $key_file = escapeshellcmd($key_file);
            $key_file2 = escapeshellcmd($key_file2);
            $ssl_days = 3650;
            $csr_file = escapeshellcmd($csr_file);
            $config_file = escapeshellcmd($ssl_cnf_file);
            $crt_file = escapeshellcmd($crt_file);
            if(is_file($ssl_cnf_file)){
                  exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 1024 && openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file && openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -in $csr_file -out $crt_file -days $ssl_days -config $config_file && openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
                $app->log("Creating SSL Cert for: $domain",LOGLEVEL_DEBUG);
            }
            exec("chmod 400 $key_file2");
            @unlink($config_file);
            @unlink($rand_file);
            $ssl_request = file_get_contents($csr_file);
            $ssl_cert = file_get_contents($crt_file);
            $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data["new"]["domain"]."'");
            $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
        }
        //* Save a SSL certificate to disk
        if($data["new"]["ssl_action"] == 'save') {
            $ssl_dir = $data["new"]["document_root"]."/ssl";
            $domain = $data["new"]["domain"];
              $csr_file = $ssl_dir.'/'.$domain.".csr";
              $crt_file = $ssl_dir.'/'.$domain.".crt";
            $bundle_file = $ssl_dir.'/'.$domain.".bundle";
            file_put_contents($csr_file,$data["new"]["ssl_request"]);
            file_put_contents($crt_file,$data["new"]["ssl_cert"]);
            if(trim($data["new"]["ssl_bundle"]) != '') file_put_contents($bundle_file,$data["new"]["ssl_bundle"]);
            $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
            $app->log("Saving SSL Cert for: $domain",LOGLEVEL_DEBUG);
        }
        //* Delete a SSL certificate
        if($data["new"]["ssl_action"] == 'del') {
            $ssl_dir = $data["new"]["document_root"]."/ssl";
            $domain = $data["new"]["domain"];
              $csr_file = $ssl_dir.'/'.$domain.".csr";
              $crt_file = $ssl_dir.'/'.$domain.".crt";
            $bundle_file = $ssl_dir.'/'.$domain.".bundle";
            unlink($csr_file);
            unlink($crt_file);
            unlink($bundle_file);
            $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
            $app->log("Deleting SSL Cert for: $domain",LOGLEVEL_DEBUG);
        }
    }
    function insert($event_name,$data) {
        global $app, $conf;
        $this->action = 'insert';
        // just run the update function
        $this->update($event_name,$data);
    }
    function update($event_name,$data) {
        global $app, $conf;
        if($this->action != 'insert') $this->action = 'update';
        if($data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
            $old_parent_domain_id = intval($data["old"]["parent_domain_id"]);
            $new_parent_domain_id = intval($data["new"]["parent_domain_id"]);
            // If the parent_domain_id has been chenged, we will have to update the old site as well.
            if($this->action == 'update' && $data["new"]["parent_domain_id"] != $data["old"]["parent_domain_id"]) {
                $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$old_parent_domain_id." AND active = 'y'");
                $data["new"] = $tmp;
                $data["old"] = $tmp;
                $this->action = 'update';
                $this->update($event_name,$data);
            }
            // This is not a vhost, so we need to update the parent record instead.
            $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$new_parent_domain_id." AND active = 'y'");
            $data["new"] = $tmp;
            $data["old"] = $tmp;
            $this->action = 'update';
        }
        // load the server configuration options
        $app->uses("getconf");
        $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
        if($data["new"]["document_root"] == '') {
            $app->log("document_root not set",LOGLEVEL_WARN);
            return 0;
        }
        if($data["new"]["system_user"] == 'root' or $data["new"]["system_group"] == 'root') {
            $app->log("Websites can not be owned by the root user or group.",LOGLEVEL_WARN);
            return 0;
        }
        //* If the client of the site has been changed, we have a change of the document root
        if($this->action == 'update' && $data["new"]["document_root"] != $data["old"]["document_root"]) {
            //* Get the old client ID
            $old_client = $app->dbmaster->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
            $old_client_id = intval($old_client["client_id"]);
            unset($old_client);
            //* Remove the old symlinks
            $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
            if(is_array($tmp_symlinks_array)) {
                foreach($tmp_symlinks_array as $tmp_symlink) {
                    $tmp_symlink = str_replace("[client_id]",$old_client_id,$tmp_symlink);
                    $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
                    // Remove trailing slash
                    if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                    // create the symlinks, if not exist
                    if(!is_link($tmp_symlink)) {
                        exec("rm -f ".escapeshellcmd($tmp_symlink));
                        $app->log("Removed Symlink: rm -f ".$tmp_symlink,LOGLEVEL_DEBUG);
                    }
                }
            }
            //* Move the site data
            $tmp_docroot = explode('/',$data["new"]["document_root"]);
            unset($tmp_docroot[count($tmp_docroot)-1]);
            $new_dir = implode('/',$tmp_docroot);
            $tmp_docroot = explode('/',$data["old"]["document_root"]);
            unset($tmp_docroot[count($tmp_docroot)-1]);
            $old_dir = implode('/',$tmp_docroot);
            exec('rm -rf '.$data["new"]["document_root"]);
            if(!is_dir($new_dir)) exec('mkdir -p '.$new_dir);
            exec('mv '.$data["old"]["document_root"].' '.$new_dir);
            $app->log("Moving site to new document root: ".'mv '.$data["old"]["document_root"].' '.$new_dir,LOGLEVEL_DEBUG);
            //* Change the home directory and group of the website user
            $command = 'usermod';
            $command .= ' --home '.escapeshellcmd($data["new"]["document_root"]);
            $command .= ' --gid '.escapeshellcmd($data['new']['system_group']);
            $command .= ' '.escapeshellcmd($data["new"]["system_user"]);
            exec($command);
        }
        //print_r($data);
        // Check if the directories are there and create them if nescessary.
        if(!is_dir($data["new"]["document_root"]."/web")) exec("mkdir -p ".$data["new"]["document_root"]."/web");
        if(!is_dir($data["new"]["document_root"]."/web/error") and $data["new"]["errordocs"]) exec("mkdir -p ".$data["new"]["document_root"]."/web/error");
        //if(!is_dir($data["new"]["document_root"]."/log")) exec("mkdir -p ".$data["new"]["document_root"]."/log");
        if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl");
        if(!is_dir($data["new"]["document_root"]."/cgi-bin")) exec("mkdir -p ".$data["new"]["document_root"]."/cgi-bin");
        if(!is_dir($data["new"]["document_root"]."/tmp")) exec("mkdir -p ".$data["new"]["document_root"]."/tmp");
        // Remove the symlink for the site, if site is renamed
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            if(is_dir('/var/log/ispconfig/httpd/'.$data["old"]["domain"])) exec('rm -rf /var/log/ispconfig/httpd/'.$data["old"]["domain"]);
            if(is_link($data["old"]["document_root"]."/log")) unlink($data["old"]["document_root"]."/log");
        }
        // Create the symlink for the logfiles
        if(!is_dir('/var/log/ispconfig/httpd/'.$data["new"]["domain"])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data["new"]["domain"]);
        if(!is_link($data["new"]["document_root"]."/log")) {
            exec("ln -s /var/log/ispconfig/httpd/".$data["new"]["domain"]." ".$data["new"]["document_root"]."/log");
            $app->log("Creating Symlink: ln -s /var/log/ispconfig/httpd/".$data["new"]["domain"]." ".$data["new"]["document_root"]."/log",LOGLEVEL_DEBUG);
        }
        /*
        // Create the symlink for the logfiles
        // This does not work as vlogger can not log trogh symlinks.
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            if(is_dir($data["old"]["document_root"]."/log")) exec('rm -rf '.$data["old"]["document_root"]."/log");
            if(is_link('/var/log/ispconfig/httpd/'.$data["old"]["domain"])) unlink('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
        }
        // Create the symlink for the logfiles
        if(!is_dir($data["new"]["document_root"]."/log")) exec('mkdir -p '.$data["new"]["document_root"]."/log");
        if(!is_link('/var/log/ispconfig/httpd/'.$data["new"]["domain"])) {
            exec("ln -s ".$data["new"]["document_root"]."/log /var/log/ispconfig/httpd/".$data["new"]["domain"]);
            $app->log("Creating Symlink: ln -s ".$data["new"]["document_root"]."/log /var/log/ispconfig/httpd/".$data["new"]["domain"],LOGLEVEL_DEBUG);
        }
        */
        // Get the client ID
        $client = $app->dbmaster->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["new"]["sys_groupid"]));
        $client_id = intval($client["client_id"]);
        unset($client);
        // Remove old symlinks, if site is renamed
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
            if(is_array($tmp_symlinks_array)) {
                foreach($tmp_symlinks_array as $tmp_symlink) {
                    $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
                    $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
                    // Remove trailing slash
                    if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                    // remove the symlinks, if not exist
                    if(is_link($tmp_symlink)) {
                        exec("rm -f ".escapeshellcmd($tmp_symlink));
                        $app->log("Removed Symlink: rm -f ".$tmp_symlink,LOGLEVEL_DEBUG);
                    }
                }
            }
        }
        // Create the symlinks for the sites
        $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
        if(is_array($tmp_symlinks_array)) {
            foreach($tmp_symlinks_array as $tmp_symlink) {
                $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
                $tmp_symlink = str_replace("[website_domain]",$data["new"]["domain"],$tmp_symlink);
                // Remove trailing slash
                if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                //* Remove symlink if target folder has been changed.
                if($data["old"]["document_root"] != '' && $data["old"]["document_root"] != $data["new"]["document_root"] && is_link($tmp_symlink)) {
                    unlink($tmp_symlink);
                }
                // create the symlinks, if not exist
                if(!is_link($tmp_symlink)) {
                    exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink));
                    $app->log("Creating Symlink: ln -s ".$data["new"]["document_root"]."/ ".$tmp_symlink,LOGLEVEL_DEBUG);
                }
            }
        }
        if($this->action == 'insert' && $data["new"]["type"] == 'vhost') {
            // Copy the error pages
            if($data["new"]["errordocs"]){
                $error_page_path = escapeshellcmd($data["new"]["document_root"])."/web/error/";
                if (file_exists("/usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2))){
                    exec("cp /usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
                }
                else {
                    if (file_exists("/usr/local/ispconfig/server/conf-custom/error/400.html")){
                        exec("cp /usr/local/ispconfig/server/conf-custom/error/*.html ".$error_page_path);
                    }
                    else {
                        exec("cp /usr/local/ispconfig/server/conf/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
                    }
                }
                exec("chmod -R a+r ".$error_page_path);
            }
            // copy the standard index page
            if (file_exists("/usr/local/ispconfig/server/conf-custom/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2))){
                exec("cp /usr/local/ispconfig/server/conf-custom/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
            }
            else {
                if (file_exists("/usr/local/ispconfig/server/conf-custom/index/standard_index.html")){
                    exec("cp /usr/local/ispconfig/server/conf-custom/index/standard_index.html ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
                }
                else {
                    exec("cp /usr/local/ispconfig/server/conf/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
                    exec("cp /usr/local/ispconfig/server/conf/index/favicon.ico ".escapeshellcmd($data["new"]["document_root"])."/web/");
                    exec("cp /usr/local/ispconfig/server/conf/index/robots.txt ".escapeshellcmd($data["new"]["document_root"])."/web/");
                    exec("cp /usr/local/ispconfig/server/conf/index/.htaccess ".escapeshellcmd($data["new"]["document_root"])."/web/");
                }
            }
            exec("chmod -R a+r ".escapeshellcmd($data["new"]["document_root"])."/web/");
        }
        // Create group and user, if not exist
        $app->uses("system");
        $groupname = escapeshellcmd($data["new"]["system_group"]);
        if($data["new"]["system_group"] != '' && !$app->system->is_group($data["new"]["system_group"])) {
            exec("groupadd $groupname");
            $app->log("Adding the group: $groupname",LOGLEVEL_DEBUG);
        }
        $username = escapeshellcmd($data["new"]["system_user"]);
        if($data["new"]["system_user"] != '' && !$app->system->is_user($data["new"]["system_user"])) {
            exec("useradd -d ".escapeshellcmd($data["new"]["document_root"])." -g $groupname $username -s /bin/false");
            $app->log("Adding the user: $username",LOGLEVEL_DEBUG);
        }
        // Set the quota for the user
        if($username != '' && $app->system->is_user($username)) {
            if($data["new"]["hd_quota"] > 0){
                $blocks_soft = $data["new"]["hd_quota"] * 1024;
                $blocks_hard = $blocks_soft + 1024;
              } else {
                $blocks_soft = $blocks_hard = 0;
              }
            exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
            exec("setquota -T -u $username 604800 604800 -a &> /dev/null");
        }
        if($this->action == 'insert') {
            // Chown and chmod the directories below the document root
            exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
            // The document root itself has to be owned by root
            exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]));
        }
        // make temp direcory writable for the apache user and the website user
        exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp"));
        // Create the vhost config file
        $app->load('tpl');
        $tpl = new tpl();
        $tpl->newTemplate("vhost.conf.master");
        $vhost_data = $data["new"];
        $vhost_data["web_document_root"] = $data["new"]["document_root"]."/web";
        $vhost_data["web_document_root_www"] = $web_config["website_basedir"]."/".$data["new"]["domain"]."/web";
        $vhost_data["web_basedir"] = $web_config["website_basedir"];
        // Check if a SSL cert exists
        $ssl_dir = $data["new"]["document_root"]."/ssl";
        $domain = $data["new"]["domain"];
          $key_file = $ssl_dir.'/'.$domain.".key";
          $crt_file = $ssl_dir.'/'.$domain.".crt";
        $bundle_file = $ssl_dir.'/'.$domain.".bundle";
        if($data["new"]["ssl"] == 'y' && @is_file($crt_file) && @is_file($key_file)) {
            $vhost_data["ssl_enabled"] = 1;
            $app->log("Enable SSL for: $domain",LOGLEVEL_DEBUG);
        } else {
            $vhost_data["ssl_enabled"] = 0;
            $app->log("Disable SSL for: $domain",LOGLEVEL_DEBUG);
        }
        if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
        //$vhost_data["document_root"] = $data["new"]["document_root"]."/web";
        $tpl->setVar($vhost_data);
        // Rewrite rules
        $rewrite_rules = array();
        if($data["new"]["redirect_type"] != '') {
            $rewrite_rules[] = array(    'rewrite_domain'     => $data["new"]["domain"],
                                        'rewrite_type'         => ($data["new"]["redirect_type"] == 'no')?'':'['.$data["new"]["redirect_type"].']',
                                        'rewrite_target'     => $data["new"]["redirect_path"]);
            switch($data["new"]["subdomain"]) {
            case 'www':
                $rewrite_rules[] = array(    'rewrite_domain'     => 'www.'.$data["new"]["domain"],
                                            'rewrite_type'         => ($data["new"]["redirect_type"] == 'no')?'':'['.$data["new"]["redirect_type"].']',
                                            'rewrite_target'     => $data["new"]["redirect_path"]);
                break;
            case '*':
                // TODO
                //$rewrite_rules[] = array(    'rewrite_domain'     => '*'.$alias["domain"],
                //                            'rewrite_type'         => $alias["redirect_type"],
                //                            'rewrite_target'     => $alias["redirect_path"]);
                break;
            }
        }
        // get alias domains (co-domains and subdomains)
        $aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]." AND active = 'y'");
        switch($data["new"]["subdomain"]) {
        case 'www':
            $server_alias .= 'www.'.$data["new"]["domain"].' ';
            break;
        case '*':
            $server_alias .= '*.'.$data["new"]["domain"].' ';
            break;
        }
        if(is_array($aliases)) {
            foreach($aliases as $alias) {
                switch($alias["subdomain"]) {
                case 'www':
                    $server_alias .= 'www.'.$alias["domain"].' '.$alias["domain"].' ';
                    break;
                case '*':
                    $server_alias .= '*.'.$alias["domain"].' '.$alias["domain"].' ';
                    break;
                default:
                    $server_alias .= $alias["domain"].' ';
                    break;
                }
                $app->log("Add server alias: $alias[domain]",LOGLEVEL_DEBUG);
                // Rewriting
                if($alias["redirect_type"] != '') {
                    $rewrite_rules[] = array(    'rewrite_domain'     => $alias["domain"],
                                                'rewrite_type'         => ($alias["redirect_type"] == 'no')?'':'['.$alias["redirect_type"].']',
                                                'rewrite_target'     => $alias["redirect_path"]);
                    switch($alias["subdomain"]) {
                    case 'www':
                        $rewrite_rules[] = array(    'rewrite_domain'     => 'www.'.$alias["domain"],
                                                    'rewrite_type'         => ($alias["redirect_type"] == 'no')?'':'['.$alias["redirect_type"].']',
                                                    'rewrite_target'     => $alias["redirect_path"]);
                        break;
                    case '*':
                        // TODO
                        //$rewrite_rules[] = array(    'rewrite_domain'     => '*'.$alias["domain"],
                        //                            'rewrite_type'         => $alias["redirect_type"],
                        //                            'rewrite_target'     => $alias["redirect_path"]);
                        break;
                    }
                }
            }
        }
        $tpl->setVar('alias',trim($server_alias));
        if(count($rewrite_rules) > 0) {
            $tpl->setVar('rewrite_enabled',1);
        } else {
            $tpl->setVar('rewrite_enabled',0);
        }
        $tpl->setLoop('redirects',$rewrite_rules);
        /**
         * install fast-cgi starter script and add script aliasd config
         * first we create the script directory if not already created, then copy over the starter script
         * settings are copied over from the server ini config for now
         * TODO: Create form for fastcgi configs per site.
         */
        if ($data["new"]["php"] == "fast-cgi")
        {
            $fastcgi_config = $app->getconf->get_server_config($conf["server_id"], 'fastcgi');
            $fastcgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$fastcgi_config["fastcgi_starter_path"]);
            $fastcgi_starter_path = str_replace("[client_id]",$client_id,$fastcgi_starter_path);
            if (!is_dir($fastcgi_starter_path))
            {
                exec("mkdir -p ".escapeshellcmd($fastcgi_starter_path));
                exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." ".escapeshellcmd($fastcgi_starter_path));
                $app->log("Creating fastcgi starter script directory: $fastcgi_starter_path",LOGLEVEL_DEBUG);
            }
            $fcgi_tpl = new tpl();
            $fcgi_tpl->newTemplate("php-fcgi-starter.master");
            $fcgi_tpl->setVar('php_ini_path',$fastcgi_config["fastcgi_phpini_path"]);
            $fcgi_tpl->setVar('document_root',$data["new"]["document_root"]);
            $fcgi_tpl->setVar('php_fcgi_children',$fastcgi_config["fastcgi_children"]);
            $fcgi_tpl->setVar('php_fcgi_max_requests',$fastcgi_config["fastcgi_max_requests"]);
            $fcgi_tpl->setVar('php_fcgi_bin',$fastcgi_config["fastcgi_bin"]);
            $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config["fastcgi_starter_script"]);
            file_put_contents($fcgi_starter_script,$fcgi_tpl->grab());
            unset($fcgi_tpl);
            $app->log("Creating fastcgi starter script: $fcgi_starter_script",LOGLEVEL_DEBUG);
            exec("chmod 755 $fcgi_starter_script");
            exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $fcgi_starter_script");
            $tpl->setVar('fastcgi_alias',$fastcgi_config["fastcgi_alias"]);
            $tpl->setVar('fastcgi_starter_path',$fastcgi_starter_path);
            $tpl->setVar('fastcgi_starter_script',$fastcgi_config["fastcgi_starter_script"]);
        }
        /**
         * install cgi starter script and add script alias to config.
         * This is needed to allow cgi with suexec (to do so, we need a bin in the document-path!)
         * first we create the script directory if not already created, then copy over the starter script.
         * TODO: we have to fetch the data from the server-settings.
         */
        if ($data["new"]["php"] == "cgi")
        {
            //$cgi_config = $app->getconf->get_server_config($conf["server_id"], 'cgi');
            $cgi_config["cgi_starter_path"] = $web_config["website_basedir"]."/php-cgi-scripts/[system_user]/";
            $cgi_config["cgi_starter_script"] = "php-cgi-starter";
            $cgi_config["cgi_bin"] = "/usr/bin/php-cgi";
            $cgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$cgi_config["cgi_starter_path"]);
            $cgi_starter_path = str_replace("[client_id]",$client_id,$cgi_starter_path);
            if (!is_dir($cgi_starter_path))
            {
                exec("mkdir -p ".escapeshellcmd($cgi_starter_path));
                exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." ".escapeshellcmd($cgi_starter_path));
                $app->log("Creating cgi starter script directory: $cgi_starter_path",LOGLEVEL_DEBUG);
            }
            $cgi_tpl = new tpl();
            $cgi_tpl->newTemplate("php-cgi-starter.master");
            // This works, because php "rewrites" a symlink to the physical path
            $cgi_tpl->setVar('open_basedir', $data["new"]["document_root"]);
            // This will NOT work!
            //$cgi_tpl->setVar('open_basedir', "/var/www/" . $data["new"]["domain"]);
            $cgi_tpl->setVar('php_cgi_bin',$cgi_config["cgi_bin"]);
            $cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config["cgi_starter_script"]);
            file_put_contents($cgi_starter_script,$cgi_tpl->grab());
            unset($cgi_tpl);
            $app->log("Creating cgi starter script: $cgi_starter_script",LOGLEVEL_DEBUG);
            exec("chmod 755 $cgi_starter_script");
            exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $cgi_starter_script");
            $tpl->setVar('cgi_starter_path',$cgi_starter_path);
            $tpl->setVar('cgi_starter_script',$cgi_config["cgi_starter_script"]);
        }
        $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
        file_put_contents($vhost_file,$tpl->grab());
        $app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);
        unset($tpl);
        // Set the symlink to enable the vhost
        $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["new"]["domain"].'.vhost');
        if($data["new"]["active"] == 'y' && !is_link($vhost_symlink)) {
            symlink($vhost_file,$vhost_symlink);
            $app->log("Creating the symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
        }
        // Remove the symlink, if site is inactive
        if($data["new"]["active"] == 'n' && is_link($vhost_symlink)) {
            unlink($vhost_symlink);
            $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
        }
        // remove old symlink and vhost file, if domain name of the site has changed
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_symlink);
            $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
            $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_file);
            $app->log("Removing File $vhost_file",LOGLEVEL_DEBUG);
        }
        //* Create .htaccess and .htpasswd file for website statistics
        if(!is_file($data["new"]["document_root"].'/web/stats/.htaccess')) {
            if(!is_dir($data["new"]["document_root"].'/web/stats')) mkdir($data["new"]["document_root"].'/web/stats');
            $ht_file = "AuthType Basic\nAuthName \"Members Only\"\nAuthUserFile ".$data["new"]["document_root"]."/.htpasswd_stats\n<limit GET PUT POST>\nrequire valid-user\n</limit>";
            file_put_contents($data["new"]["document_root"].'/web/stats/.htaccess',$ht_file);
            chmod($data["new"]["document_root"].'/web/stats/.htaccess',0664);
            unset($ht_file);
        }
        if(!is_file($data["new"]["document_root"].'/.htpasswd_stats') || $data["new"]["stats_password"] != $data["old"]["stats_password"]) {
            if(trim($data["new"]["stats_password"]) != '') {
                $htp_file = 'admin:'.trim($data["new"]["stats_password"]);
                file_put_contents($data["new"]["document_root"].'/.htpasswd_stats',$htp_file);
                chmod($data["new"]["document_root"].'/.htpasswd_stats',0664);
                unset($htp_file);
            }
        }
        // request a httpd reload when all records have been processed
        $app->services->restartServiceDelayed('httpd','reload');
    }
    function delete($event_name,$data) {
        global $app, $conf;
        // load the server configuration options
        $app->uses("getconf");
        $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
        if($data["old"]["type"] != "vhost" && $data["old"]["parent_domain_id"] > 0) {
            //* This is a alias domain or subdomain, so we have to update the website instead
            $parent_domain_id = intval($data["old"]["parent_domain_id"]);
            $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$parent_domain_id." AND active = 'y'");
            $data["new"] = $tmp;
            $data["old"] = $tmp;
            $this->action = 'update';
            // just run the update function
            $this->update($event_name,$data);
        } else {
            //* This is a website
            // Deleting the vhost file, symlink and the data directory
            $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_symlink);
            $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
            $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_file);
            $app->log("Removing vhost file: $vhost_file",LOGLEVEL_DEBUG);
            $docroot = escapeshellcmd($data["old"]["document_root"]);
            if($docroot != '' && !stristr($docroot,'..')) exec("rm -rf $docroot");
            //remove the php fastgi starter script if available
            if ($data["old"]["php"] == "fast-cgi")
            {
                $fastcgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["fastcgi_starter_path"]);
                if (is_dir($fastcgi_starter_path))
                {
                    exec("rm -rf $fastcgi_starter_path");
                }
            }
            //remove the php cgi starter script if available
            if ($data["old"]["php"] == "cgi")
            {
                // TODO: fetch the date from the server-settings
                $web_config["cgi_starter_path"] = $web_config["website_basedir"]."/php-cgi-scripts/[system_user]/";
                $cgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["cgi_starter_path"]);
                if (is_dir($cgi_starter_path))
                {
                    exec("rm -rf $cgi_starter_path");
                }
            }
            $app->log("Removing website: $docroot",LOGLEVEL_DEBUG);
            // Delete the symlinks for the sites
            $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
            $client_id = intval($client["client_id"]);
            unset($client);
            $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
            if(is_array($tmp_symlinks_array)) {
                foreach($tmp_symlinks_array as $tmp_symlink) {
                    $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
                    $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
                    // Remove trailing slash
                    if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                    // create the symlinks, if not exist
                    if(is_link($tmp_symlink)) {
                        unlink($tmp_symlink);
                        $app->log("Removing symlink: ".$tmp_symlink,LOGLEVEL_DEBUG);
                    }
                }
            }
            // end removing symlinks
            // Delete the log file directory
            $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
            if($data["old"]["domain"] != '' && !stristr($vhost_logfile_dir,'..')) exec("rm -rf $vhost_logfile_dir");
            $app->log("Removing website logfile directory: $vhost_logfile_dir",LOGLEVEL_DEBUG);
            //delete the web user
            $command = 'userdel';
            $command .= ' '.$data["old"]["system_user"];
            exec($command);
        }
    }
    //* This function is called when a IP on the server is inserted, updated or deleted
    function server_ip($event_name,$data) {
        global $app, $conf;
        // load the server configuration options
        $app->uses("getconf");
        $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
        $app->load('tpl');
        $tpl = new tpl();
        $tpl->newTemplate("apache_ispconfig.conf.master");
        $records = $app->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
        if(count($records) > 0) {
            $tpl->setLoop('ip_adresses',$records);
        }
        $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/ispconfig.conf');
        file_put_contents($vhost_file,$tpl->grab());
        $app->log("Writing the conf file: ispconfig.conf",LOGLEVEL_DEBUG);
        unset($tpl);
    }
} // end class
<?php
/*
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class apache2_plugin {
    var $plugin_name = 'apache2_plugin';
    var $class_name = 'apache2_plugin';
    // private variables
    var $action = '';
    //* This function is called during ispconfig installation to determine
    //  if a symlink shall be created for this plugin.
    function onInstall() {
        global $conf;
        if($conf['services']['web'] == true) {
            return true;
        } else {
            return false;
        }
    }
    /*
         This function is called when the plugin is loaded
    */
    function onLoad() {
        global $app;
        /*
        Register for the events
        */
        $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'ssl');
        $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'ssl');
        $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'ssl');
        $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
        $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'update');
        $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'delete');
        $app->plugins->registerEvent('server_ip_insert',$this->plugin_name,'server_ip');
        $app->plugins->registerEvent('server_ip_update',$this->plugin_name,'server_ip');
        $app->plugins->registerEvent('server_ip_delete',$this->plugin_name,'server_ip');
    }
    // Handle the creation of SSL certificates
    function ssl($event_name,$data) {
        global $app, $conf;
        if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl");
        $ssl_dir = $data["new"]["document_root"]."/ssl";
        $domain = $data["new"]["domain"];
        $key_file = $ssl_dir.'/'.$domain.".key.org";
          $key_file2 = $ssl_dir.'/'.$domain.".key";
          $csr_file = $ssl_dir.'/'.$domain.".csr";
          $crt_file = $ssl_dir.'/'.$domain.".crt";
        //* Create a SSL Certificate
        if($data["new"]["ssl_action"] == 'create') {
            $rand_file = $ssl_dir."/random_file";
            $rand_data = md5(uniqid(microtime(),1));
            for($i=0; $i<1000; $i++){
                $rand_data .= md5(uniqid(microtime(),1));
                $rand_data .= md5(uniqid(microtime(),1));
                $rand_data .= md5(uniqid(microtime(),1));
                $rand_data .= md5(uniqid(microtime(),1));
            }
            file_put_contents($rand_file, $rand_data);
            $ssl_password = substr(md5(uniqid(microtime(),1)), 0, 15);
            $ssl_cnf = "        RANDFILE               = $rand_file
        [ req ]
        default_bits           = 1024
        default_keyfile        = keyfile.pem
        distinguished_name     = req_distinguished_name
        attributes             = req_attributes
        prompt                 = no
        output_password        = $ssl_password
        [ req_distinguished_name ]
        C                      = ".$data['new']['ssl_country']."
        ST                     = ".$data['new']['ssl_state']."
        L                      = ".$data['new']['ssl_locality']."
        O                      = ".$data['new']['ssl_organisation']."
        OU                     = ".$data['new']['ssl_organisation_unit']."
        CN                     = $domain
        emailAddress           = webmaster@".$data['new']['domain']."
        [ req_attributes ]
        challengePassword              = A challenge password";
            $ssl_cnf_file = $ssl_dir."/openssl.conf";
            file_put_contents($ssl_cnf_file,$ssl_cnf);
            $rand_file = escapeshellcmd($rand_file);
            $key_file = escapeshellcmd($key_file);
            $key_file2 = escapeshellcmd($key_file2);
            $ssl_days = 3650;
            $csr_file = escapeshellcmd($csr_file);
            $config_file = escapeshellcmd($ssl_cnf_file);
            $crt_file = escapeshellcmd($crt_file);
            if(is_file($ssl_cnf_file)){
                  exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 1024 && openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file && openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -in $csr_file -out $crt_file -days $ssl_days -config $config_file && openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
                $app->log("Creating SSL Cert for: $domain",LOGLEVEL_DEBUG);
            }
            exec("chmod 400 $key_file2");
            @unlink($config_file);
            @unlink($rand_file);
            $ssl_request = file_get_contents($csr_file);
            $ssl_cert = file_get_contents($crt_file);
            $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data["new"]["domain"]."'");
            $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
        }
        //* Save a SSL certificate to disk
        if($data["new"]["ssl_action"] == 'save') {
            $ssl_dir = $data["new"]["document_root"]."/ssl";
            $domain = $data["new"]["domain"];
              $csr_file = $ssl_dir.'/'.$domain.".csr";
              $crt_file = $ssl_dir.'/'.$domain.".crt";
            $bundle_file = $ssl_dir.'/'.$domain.".bundle";
            file_put_contents($csr_file,$data["new"]["ssl_request"]);
            file_put_contents($crt_file,$data["new"]["ssl_cert"]);
            if(trim($data["new"]["ssl_bundle"]) != '') file_put_contents($bundle_file,$data["new"]["ssl_bundle"]);
            $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
            $app->log("Saving SSL Cert for: $domain",LOGLEVEL_DEBUG);
        }
        //* Delete a SSL certificate
        if($data["new"]["ssl_action"] == 'del') {
            $ssl_dir = $data["new"]["document_root"]."/ssl";
            $domain = $data["new"]["domain"];
              $csr_file = $ssl_dir.'/'.$domain.".csr";
              $crt_file = $ssl_dir.'/'.$domain.".crt";
            $bundle_file = $ssl_dir.'/'.$domain.".bundle";
            unlink($csr_file);
            unlink($crt_file);
            unlink($bundle_file);
            $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
            $app->log("Deleting SSL Cert for: $domain",LOGLEVEL_DEBUG);
        }
    }
    function insert($event_name,$data) {
        global $app, $conf;
        $this->action = 'insert';
        // just run the update function
        $this->update($event_name,$data);
    }
    function update($event_name,$data) {
        global $app, $conf;
        if($this->action != 'insert') $this->action = 'update';
        if($data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
            $old_parent_domain_id = intval($data["old"]["parent_domain_id"]);
            $new_parent_domain_id = intval($data["new"]["parent_domain_id"]);
            // If the parent_domain_id has been chenged, we will have to update the old site as well.
            if($this->action == 'update' && $data["new"]["parent_domain_id"] != $data["old"]["parent_domain_id"]) {
                $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$old_parent_domain_id." AND active = 'y'");
                $data["new"] = $tmp;
                $data["old"] = $tmp;
                $this->action = 'update';
                $this->update($event_name,$data);
            }
            // This is not a vhost, so we need to update the parent record instead.
            $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$new_parent_domain_id." AND active = 'y'");
            $data["new"] = $tmp;
            $data["old"] = $tmp;
            $this->action = 'update';
        }
        // load the server configuration options
        $app->uses("getconf");
        $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
        if($data["new"]["document_root"] == '') {
            $app->log("document_root not set",LOGLEVEL_WARN);
            return 0;
        }
        if($data["new"]["system_user"] == 'root' or $data["new"]["system_group"] == 'root') {
            $app->log("Websites can not be owned by the root user or group.",LOGLEVEL_WARN);
            return 0;
        }
        //* If the client of the site has been changed, we have a change of the document root
        if($this->action == 'update' && $data["new"]["document_root"] != $data["old"]["document_root"]) {
            //* Get the old client ID
            $old_client = $app->dbmaster->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
            $old_client_id = intval($old_client["client_id"]);
            unset($old_client);
            //* Remove the old symlinks
            $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
            if(is_array($tmp_symlinks_array)) {
                foreach($tmp_symlinks_array as $tmp_symlink) {
                    $tmp_symlink = str_replace("[client_id]",$old_client_id,$tmp_symlink);
                    $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
                    // Remove trailing slash
                    if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                    // create the symlinks, if not exist
                    if(!is_link($tmp_symlink)) {
                        exec("rm -f ".escapeshellcmd($tmp_symlink));
                        $app->log("Removed Symlink: rm -f ".$tmp_symlink,LOGLEVEL_DEBUG);
                    }
                }
            }
            //* Move the site data
            $tmp_docroot = explode('/',$data["new"]["document_root"]);
            unset($tmp_docroot[count($tmp_docroot)-1]);
            $new_dir = implode('/',$tmp_docroot);
            $tmp_docroot = explode('/',$data["old"]["document_root"]);
            unset($tmp_docroot[count($tmp_docroot)-1]);
            $old_dir = implode('/',$tmp_docroot);
            exec('rm -rf '.$data["new"]["document_root"]);
            if(!is_dir($new_dir)) exec('mkdir -p '.$new_dir);
            exec('mv '.$data["old"]["document_root"].' '.$new_dir);
            $app->log("Moving site to new document root: ".'mv '.$data["old"]["document_root"].' '.$new_dir,LOGLEVEL_DEBUG);
            //* Change the home directory and group of the website user
            $command = 'usermod';
            $command .= ' --home '.escapeshellcmd($data["new"]["document_root"]);
            $command .= ' --gid '.escapeshellcmd($data['new']['system_group']);
            $command .= ' '.escapeshellcmd($data["new"]["system_user"]);
            exec($command);
        }
        //print_r($data);
        // Check if the directories are there and create them if nescessary.
        if(!is_dir($data["new"]["document_root"]."/web")) exec("mkdir -p ".$data["new"]["document_root"]."/web");
        if(!is_dir($data["new"]["document_root"]."/web/error") and $data["new"]["errordocs"]) exec("mkdir -p ".$data["new"]["document_root"]."/web/error");
        //if(!is_dir($data["new"]["document_root"]."/log")) exec("mkdir -p ".$data["new"]["document_root"]."/log");
        if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl");
        if(!is_dir($data["new"]["document_root"]."/cgi-bin")) exec("mkdir -p ".$data["new"]["document_root"]."/cgi-bin");
        if(!is_dir($data["new"]["document_root"]."/tmp")) exec("mkdir -p ".$data["new"]["document_root"]."/tmp");
        // Remove the symlink for the site, if site is renamed
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            if(is_dir('/var/log/ispconfig/httpd/'.$data["old"]["domain"])) exec('rm -rf /var/log/ispconfig/httpd/'.$data["old"]["domain"]);
            if(is_link($data["old"]["document_root"]."/log")) unlink($data["old"]["document_root"]."/log");
        }
        // Create the symlink for the logfiles
        if(!is_dir('/var/log/ispconfig/httpd/'.$data["new"]["domain"])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data["new"]["domain"]);
        if(!is_link($data["new"]["document_root"]."/log")) {
            exec("ln -s /var/log/ispconfig/httpd/".$data["new"]["domain"]." ".$data["new"]["document_root"]."/log");
            $app->log("Creating Symlink: ln -s /var/log/ispconfig/httpd/".$data["new"]["domain"]." ".$data["new"]["document_root"]."/log",LOGLEVEL_DEBUG);
        }
        /*
        // Create the symlink for the logfiles
        // This does not work as vlogger can not log trogh symlinks.
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            if(is_dir($data["old"]["document_root"]."/log")) exec('rm -rf '.$data["old"]["document_root"]."/log");
            if(is_link('/var/log/ispconfig/httpd/'.$data["old"]["domain"])) unlink('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
        }
        // Create the symlink for the logfiles
        if(!is_dir($data["new"]["document_root"]."/log")) exec('mkdir -p '.$data["new"]["document_root"]."/log");
        if(!is_link('/var/log/ispconfig/httpd/'.$data["new"]["domain"])) {
            exec("ln -s ".$data["new"]["document_root"]."/log /var/log/ispconfig/httpd/".$data["new"]["domain"]);
            $app->log("Creating Symlink: ln -s ".$data["new"]["document_root"]."/log /var/log/ispconfig/httpd/".$data["new"]["domain"],LOGLEVEL_DEBUG);
        }
        */
        // Get the client ID
        $client = $app->dbmaster->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["new"]["sys_groupid"]));
        $client_id = intval($client["client_id"]);
        unset($client);
        // Remove old symlinks, if site is renamed
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
            if(is_array($tmp_symlinks_array)) {
                foreach($tmp_symlinks_array as $tmp_symlink) {
                    $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
                    $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
                    // Remove trailing slash
                    if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                    // remove the symlinks, if not exist
                    if(is_link($tmp_symlink)) {
                        exec("rm -f ".escapeshellcmd($tmp_symlink));
                        $app->log("Removed Symlink: rm -f ".$tmp_symlink,LOGLEVEL_DEBUG);
                    }
                }
            }
        }
        // Create the symlinks for the sites
        $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
        if(is_array($tmp_symlinks_array)) {
            foreach($tmp_symlinks_array as $tmp_symlink) {
                $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
                $tmp_symlink = str_replace("[website_domain]",$data["new"]["domain"],$tmp_symlink);
                // Remove trailing slash
                if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                //* Remove symlink if target folder has been changed.
                if($data["old"]["document_root"] != '' && $data["old"]["document_root"] != $data["new"]["document_root"] && is_link($tmp_symlink)) {
                    unlink($tmp_symlink);
                }
                // create the symlinks, if not exist
                if(!is_link($tmp_symlink)) {
                    exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink));
                    $app->log("Creating Symlink: ln -s ".$data["new"]["document_root"]."/ ".$tmp_symlink,LOGLEVEL_DEBUG);
                }
            }
        }
        if($this->action == 'insert' && $data["new"]["type"] == 'vhost') {
            // Copy the error pages
            if($data["new"]["errordocs"]){
                $error_page_path = escapeshellcmd($data["new"]["document_root"])."/web/error/";
                if (file_exists("/usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2))){
                    exec("cp /usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
                }
                else {
                    if (file_exists("/usr/local/ispconfig/server/conf-custom/error/400.html")){
                        exec("cp /usr/local/ispconfig/server/conf-custom/error/*.html ".$error_page_path);
                    }
                    else {
                        exec("cp /usr/local/ispconfig/server/conf/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
                    }
                }
                exec("chmod -R a+r ".$error_page_path);
            }
            // copy the standard index page
            if (file_exists("/usr/local/ispconfig/server/conf-custom/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2))){
                exec("cp /usr/local/ispconfig/server/conf-custom/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
            }
            else {
                if (file_exists("/usr/local/ispconfig/server/conf-custom/index/standard_index.html")){
                    exec("cp /usr/local/ispconfig/server/conf-custom/index/standard_index.html ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
                }
                else {
                    exec("cp /usr/local/ispconfig/server/conf/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
                    exec("cp /usr/local/ispconfig/server/conf/index/favicon.ico ".escapeshellcmd($data["new"]["document_root"])."/web/");
                    exec("cp /usr/local/ispconfig/server/conf/index/robots.txt ".escapeshellcmd($data["new"]["document_root"])."/web/");
                    exec("cp /usr/local/ispconfig/server/conf/index/.htaccess ".escapeshellcmd($data["new"]["document_root"])."/web/");
                }
            }
            exec("chmod -R a+r ".escapeshellcmd($data["new"]["document_root"])."/web/");
        //** Copy the error documents on update when the error document checkbox has been activated and was deactivated before
        } elseif ($this->action == 'update' && $data["new"]["type"] == 'vhost' && $data["old"]["errordocs"] == 0 && $data["new"]["errordocs"] == 1) {
            $error_page_path = escapeshellcmd($data["new"]["document_root"])."/web/error/";
            if (file_exists("/usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2))){
                exec("cp /usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
            }
            else {
                if (file_exists("/usr/local/ispconfig/server/conf-custom/error/400.html")){
                    exec("cp /usr/local/ispconfig/server/conf-custom/error/*.html ".$error_page_path);
                }
                else {
                    exec("cp /usr/local/ispconfig/server/conf/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
                }
            }
            exec("chmod -R a+r ".$error_page_path);
        }  // end copy error docs
        // Create group and user, if not exist
        $app->uses("system");
        $groupname = escapeshellcmd($data["new"]["system_group"]);
        if($data["new"]["system_group"] != '' && !$app->system->is_group($data["new"]["system_group"])) {
            exec("groupadd $groupname");
            $app->log("Adding the group: $groupname",LOGLEVEL_DEBUG);
        }
        $username = escapeshellcmd($data["new"]["system_user"]);
        if($data["new"]["system_user"] != '' && !$app->system->is_user($data["new"]["system_user"])) {
            exec("useradd -d ".escapeshellcmd($data["new"]["document_root"])." -g $groupname $username -s /bin/false");
            $app->log("Adding the user: $username",LOGLEVEL_DEBUG);
        }
        // Set the quota for the user
        if($username != '' && $app->system->is_user($username)) {
            if($data["new"]["hd_quota"] > 0){
                $blocks_soft = $data["new"]["hd_quota"] * 1024;
                $blocks_hard = $blocks_soft + 1024;
              } else {
                $blocks_soft = $blocks_hard = 0;
              }
            exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
            exec("setquota -T -u $username 604800 604800 -a &> /dev/null");
        }
        if($this->action == 'insert') {
            // Chown and chmod the directories below the document root
            exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
            // The document root itself has to be owned by root
            exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]));
        }
        // make temp direcory writable for the apache user and the website user
        exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp"));
        // Create the vhost config file
        $app->load('tpl');
        $tpl = new tpl();
        $tpl->newTemplate("vhost.conf.master");
        $vhost_data = $data["new"];
        $vhost_data["web_document_root"] = $data["new"]["document_root"]."/web";
        $vhost_data["web_document_root_www"] = $web_config["website_basedir"]."/".$data["new"]["domain"]."/web";
        $vhost_data["web_basedir"] = $web_config["website_basedir"];
        // Check if a SSL cert exists
        $ssl_dir = $data["new"]["document_root"]."/ssl";
        $domain = $data["new"]["domain"];
          $key_file = $ssl_dir.'/'.$domain.".key";
          $crt_file = $ssl_dir.'/'.$domain.".crt";
        $bundle_file = $ssl_dir.'/'.$domain.".bundle";
        if($data["new"]["ssl"] == 'y' && @is_file($crt_file) && @is_file($key_file)) {
            $vhost_data["ssl_enabled"] = 1;
            $app->log("Enable SSL for: $domain",LOGLEVEL_DEBUG);
        } else {
            $vhost_data["ssl_enabled"] = 0;
            $app->log("Disable SSL for: $domain",LOGLEVEL_DEBUG);
        }
        if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
        //$vhost_data["document_root"] = $data["new"]["document_root"]."/web";
        $tpl->setVar($vhost_data);
        // Rewrite rules
        $rewrite_rules = array();
        if($data["new"]["redirect_type"] != '') {
            $rewrite_rules[] = array(    'rewrite_domain'     => $data["new"]["domain"],
                                        'rewrite_type'         => ($data["new"]["redirect_type"] == 'no')?'':'['.$data["new"]["redirect_type"].']',
                                        'rewrite_target'     => $data["new"]["redirect_path"]);
            switch($data["new"]["subdomain"]) {
            case 'www':
                $rewrite_rules[] = array(    'rewrite_domain'     => 'www.'.$data["new"]["domain"],
                                            'rewrite_type'         => ($data["new"]["redirect_type"] == 'no')?'':'['.$data["new"]["redirect_type"].']',
                                            'rewrite_target'     => $data["new"]["redirect_path"]);
                break;
            case '*':
                // TODO
                //$rewrite_rules[] = array(    'rewrite_domain'     => '*'.$alias["domain"],
                //                            'rewrite_type'         => $alias["redirect_type"],
                //                            'rewrite_target'     => $alias["redirect_path"]);
                break;
            }
        }
        // get alias domains (co-domains and subdomains)
        $aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]." AND active = 'y'");
        switch($data["new"]["subdomain"]) {
        case 'www':
            $server_alias .= 'www.'.$data["new"]["domain"].' ';
            break;
        case '*':
            $server_alias .= '*.'.$data["new"]["domain"].' ';
            break;
        }
        if(is_array($aliases)) {
            foreach($aliases as $alias) {
                switch($alias["subdomain"]) {
                case 'www':
                    $server_alias .= 'www.'.$alias["domain"].' '.$alias["domain"].' ';
                    break;
                case '*':
                    $server_alias .= '*.'.$alias["domain"].' '.$alias["domain"].' ';
                    break;
                default:
                    $server_alias .= $alias["domain"].' ';
                    break;
                }
                $app->log("Add server alias: $alias[domain]",LOGLEVEL_DEBUG);
                // Rewriting
                if($alias["redirect_type"] != '') {
                    $rewrite_rules[] = array(    'rewrite_domain'     => $alias["domain"],
                                                'rewrite_type'         => ($alias["redirect_type"] == 'no')?'':'['.$alias["redirect_type"].']',
                                                'rewrite_target'     => $alias["redirect_path"]);
                    switch($alias["subdomain"]) {
                    case 'www':
                        $rewrite_rules[] = array(    'rewrite_domain'     => 'www.'.$alias["domain"],
                                                    'rewrite_type'         => ($alias["redirect_type"] == 'no')?'':'['.$alias["redirect_type"].']',
                                                    'rewrite_target'     => $alias["redirect_path"]);
                        break;
                    case '*':
                        // TODO
                        //$rewrite_rules[] = array(    'rewrite_domain'     => '*'.$alias["domain"],
                        //                            'rewrite_type'         => $alias["redirect_type"],
                        //                            'rewrite_target'     => $alias["redirect_path"]);
                        break;
                    }
                }
            }
        }
        $tpl->setVar('alias',trim($server_alias));
        if(count($rewrite_rules) > 0) {
            $tpl->setVar('rewrite_enabled',1);
        } else {
            $tpl->setVar('rewrite_enabled',0);
        }
        $tpl->setLoop('redirects',$rewrite_rules);
        /**
         * install fast-cgi starter script and add script aliasd config
         * first we create the script directory if not already created, then copy over the starter script
         * settings are copied over from the server ini config for now
         * TODO: Create form for fastcgi configs per site.
         */
        if ($data["new"]["php"] == "fast-cgi")
        {
            $fastcgi_config = $app->getconf->get_server_config($conf["server_id"], 'fastcgi');
            $fastcgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$fastcgi_config["fastcgi_starter_path"]);
            $fastcgi_starter_path = str_replace("[client_id]",$client_id,$fastcgi_starter_path);
            if (!is_dir($fastcgi_starter_path))
            {
                exec("mkdir -p ".escapeshellcmd($fastcgi_starter_path));
                exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." ".escapeshellcmd($fastcgi_starter_path));
                $app->log("Creating fastcgi starter script directory: $fastcgi_starter_path",LOGLEVEL_DEBUG);
            }
            $fcgi_tpl = new tpl();
            $fcgi_tpl->newTemplate("php-fcgi-starter.master");
            $fcgi_tpl->setVar('php_ini_path',$fastcgi_config["fastcgi_phpini_path"]);
            $fcgi_tpl->setVar('document_root',$data["new"]["document_root"]);
            $fcgi_tpl->setVar('php_fcgi_children',$fastcgi_config["fastcgi_children"]);
            $fcgi_tpl->setVar('php_fcgi_max_requests',$fastcgi_config["fastcgi_max_requests"]);
            $fcgi_tpl->setVar('php_fcgi_bin',$fastcgi_config["fastcgi_bin"]);
            $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config["fastcgi_starter_script"]);
            file_put_contents($fcgi_starter_script,$fcgi_tpl->grab());
            unset($fcgi_tpl);
            $app->log("Creating fastcgi starter script: $fcgi_starter_script",LOGLEVEL_DEBUG);
            exec("chmod 755 $fcgi_starter_script");
            exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $fcgi_starter_script");
            $tpl->setVar('fastcgi_alias',$fastcgi_config["fastcgi_alias"]);
            $tpl->setVar('fastcgi_starter_path',$fastcgi_starter_path);
            $tpl->setVar('fastcgi_starter_script',$fastcgi_config["fastcgi_starter_script"]);
        }
        /**
         * install cgi starter script and add script alias to config.
         * This is needed to allow cgi with suexec (to do so, we need a bin in the document-path!)
         * first we create the script directory if not already created, then copy over the starter script.
         * TODO: we have to fetch the data from the server-settings.
         */
        if ($data["new"]["php"] == "cgi")
        {
            //$cgi_config = $app->getconf->get_server_config($conf["server_id"], 'cgi');
            $cgi_config["cgi_starter_path"] = $web_config["website_basedir"]."/php-cgi-scripts/[system_user]/";
            $cgi_config["cgi_starter_script"] = "php-cgi-starter";
            $cgi_config["cgi_bin"] = "/usr/bin/php-cgi";
            $cgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$cgi_config["cgi_starter_path"]);
            $cgi_starter_path = str_replace("[client_id]",$client_id,$cgi_starter_path);
            if (!is_dir($cgi_starter_path))
            {
                exec("mkdir -p ".escapeshellcmd($cgi_starter_path));
                exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." ".escapeshellcmd($cgi_starter_path));
                $app->log("Creating cgi starter script directory: $cgi_starter_path",LOGLEVEL_DEBUG);
            }
            $cgi_tpl = new tpl();
            $cgi_tpl->newTemplate("php-cgi-starter.master");
            // This works, because php "rewrites" a symlink to the physical path
            $cgi_tpl->setVar('open_basedir', $data["new"]["document_root"]);
            // This will NOT work!
            //$cgi_tpl->setVar('open_basedir', "/var/www/" . $data["new"]["domain"]);
            $cgi_tpl->setVar('php_cgi_bin',$cgi_config["cgi_bin"]);
            $cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config["cgi_starter_script"]);
            file_put_contents($cgi_starter_script,$cgi_tpl->grab());
            unset($cgi_tpl);
            $app->log("Creating cgi starter script: $cgi_starter_script",LOGLEVEL_DEBUG);
            exec("chmod 755 $cgi_starter_script");
            exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $cgi_starter_script");
            $tpl->setVar('cgi_starter_path',$cgi_starter_path);
            $tpl->setVar('cgi_starter_script',$cgi_config["cgi_starter_script"]);
        }
        $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
        file_put_contents($vhost_file,$tpl->grab());
        $app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);
        unset($tpl);
        // Set the symlink to enable the vhost
        $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["new"]["domain"].'.vhost');
        if($data["new"]["active"] == 'y' && !is_link($vhost_symlink)) {
            symlink($vhost_file,$vhost_symlink);
            $app->log("Creating the symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
        }
        // Remove the symlink, if site is inactive
        if($data["new"]["active"] == 'n' && is_link($vhost_symlink)) {
            unlink($vhost_symlink);
            $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
        }
        // remove old symlink and vhost file, if domain name of the site has changed
        if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
            $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_symlink);
            $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
            $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_file);
            $app->log("Removing File $vhost_file",LOGLEVEL_DEBUG);
        }
        //* Create .htaccess and .htpasswd file for website statistics
        if(!is_file($data["new"]["document_root"].'/web/stats/.htaccess')) {
            if(!is_dir($data["new"]["document_root"].'/web/stats')) mkdir($data["new"]["document_root"].'/web/stats');
            $ht_file = "AuthType Basic\nAuthName \"Members Only\"\nAuthUserFile ".$data["new"]["document_root"]."/.htpasswd_stats\n<limit GET PUT POST>\nrequire valid-user\n</limit>";
            file_put_contents($data["new"]["document_root"].'/web/stats/.htaccess',$ht_file);
            chmod($data["new"]["document_root"].'/web/stats/.htaccess',0664);
            unset($ht_file);
        }
        if(!is_file($data["new"]["document_root"].'/.htpasswd_stats') || $data["new"]["stats_password"] != $data["old"]["stats_password"]) {
            if(trim($data["new"]["stats_password"]) != '') {
                $htp_file = 'admin:'.trim($data["new"]["stats_password"]);
                file_put_contents($data["new"]["document_root"].'/.htpasswd_stats',$htp_file);
                chmod($data["new"]["document_root"].'/.htpasswd_stats',0664);
                unset($htp_file);
            }
        }
        // request a httpd reload when all records have been processed
        $app->services->restartServiceDelayed('httpd','reload');
    }
    function delete($event_name,$data) {
        global $app, $conf;
        // load the server configuration options
        $app->uses("getconf");
        $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
        if($data["old"]["type"] != "vhost" && $data["old"]["parent_domain_id"] > 0) {
            //* This is a alias domain or subdomain, so we have to update the website instead
            $parent_domain_id = intval($data["old"]["parent_domain_id"]);
            $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$parent_domain_id." AND active = 'y'");
            $data["new"] = $tmp;
            $data["old"] = $tmp;
            $this->action = 'update';
            // just run the update function
            $this->update($event_name,$data);
        } else {
            //* This is a website
            // Deleting the vhost file, symlink and the data directory
            $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_symlink);
            $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
            $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
            unlink($vhost_file);
            $app->log("Removing vhost file: $vhost_file",LOGLEVEL_DEBUG);
            $docroot = escapeshellcmd($data["old"]["document_root"]);
            if($docroot != '' && !stristr($docroot,'..')) exec("rm -rf $docroot");
            //remove the php fastgi starter script if available
            if ($data["old"]["php"] == "fast-cgi")
            {
                $fastcgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["fastcgi_starter_path"]);
                if (is_dir($fastcgi_starter_path))
                {
                    exec("rm -rf $fastcgi_starter_path");
                }
            }
            //remove the php cgi starter script if available
            if ($data["old"]["php"] == "cgi")
            {
                // TODO: fetch the date from the server-settings
                $web_config["cgi_starter_path"] = $web_config["website_basedir"]."/php-cgi-scripts/[system_user]/";
                $cgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["cgi_starter_path"]);
                if (is_dir($cgi_starter_path))
                {
                    exec("rm -rf $cgi_starter_path");
                }
            }
            $app->log("Removing website: $docroot",LOGLEVEL_DEBUG);
            // Delete the symlinks for the sites
            $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
            $client_id = intval($client["client_id"]);
            unset($client);
            $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
            if(is_array($tmp_symlinks_array)) {
                foreach($tmp_symlinks_array as $tmp_symlink) {
                    $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
                    $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
                    // Remove trailing slash
                    if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
                    // create the symlinks, if not exist
                    if(is_link($tmp_symlink)) {
                        unlink($tmp_symlink);
                        $app->log("Removing symlink: ".$tmp_symlink,LOGLEVEL_DEBUG);
                    }
                }
            }
            // end removing symlinks
            // Delete the log file directory
            $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
            if($data["old"]["domain"] != '' && !stristr($vhost_logfile_dir,'..')) exec("rm -rf $vhost_logfile_dir");
            $app->log("Removing website logfile directory: $vhost_logfile_dir",LOGLEVEL_DEBUG);
            //delete the web user
            $command = 'userdel';
            $command .= ' '.$data["old"]["system_user"];
            exec($command);
        }
    }
    //* This function is called when a IP on the server is inserted, updated or deleted
    function server_ip($event_name,$data) {
        global $app, $conf;
        // load the server configuration options
        $app->uses("getconf");
        $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
        $app->load('tpl');
        $tpl = new tpl();
        $tpl->newTemplate("apache_ispconfig.conf.master");
        $records = $app->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
        if(count($records) > 0) {
            $tpl->setLoop('ip_adresses',$records);
        }
        $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/ispconfig.conf');
        file_put_contents($vhost_file,$tpl->grab());
        $app->log("Writing the conf file: ispconfig.conf",LOGLEVEL_DEBUG);
        unset($tpl);
    }
} // end class
?>
server/plugins-available/maildrop_plugin.inc.php
@@ -116,6 +116,10 @@
            if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
            $file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst';
            if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
            $file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst.gdbm';
            if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
            $file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst.lock';
            if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
            $file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.msg';
            if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
            $file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
server/plugins-available/shelluser_base_plugin.inc.php
@@ -77,15 +77,16 @@
            $uid = intval($app->system->getuid($data['new']['puser']));
            if($uid > $this->min_uid) {
                $command = 'useradd';
                $command .= ' --home '.escapeshellcmd($data['new']['dir']);
                $command .= ' --gid '.escapeshellcmd($data['new']['pgroup']);
                $command .= ' --non-unique ';
                $command .= ' --password '.escapeshellcmd($data['new']['password']);
                $command .= ' --shell '.escapeshellcmd($data['new']['shell']);
                $command .= ' --uid '.escapeshellcmd($uid);
                $command .= ' -d '.escapeshellcmd($data['new']['dir']);
                $command .= ' -g '.escapeshellcmd($data['new']['pgroup']);
                $command .= ' -o '; // non unique
                if($data['new']['password'] != '') $command .= ' -p '.escapeshellcmd($data['new']['password']);
                $command .= ' -s '.escapeshellcmd($data['new']['shell']);
                $command .= ' -u '.escapeshellcmd($uid);
                $command .= ' '.escapeshellcmd($data['new']['username']);
            
                exec($command);
                $app->log("Executed command: ".$command,LOGLEVEL_DEBUG);
                $app->log("Added shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG);
                
                //* Disable shell user temporarily if we use jailkit
@@ -125,7 +126,7 @@
                    $command .= ' '.escapeshellcmd($data['old']['username']);
            
                    exec($command);
                    // $app->log("Updated shelluser: $command ",LOGLEVEL_DEBUG);
                    $app->log("Executed command: $command ",LOGLEVEL_DEBUG);
                    $app->log("Updated shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG);
                } else {
                    // The user does not exist, so we insert it now
server/plugins-available/shelluser_jailkit_plugin.inc.php
@@ -234,6 +234,9 @@
            $jailkit_chroot_userhome = $this->_get_home_dir($this->data['new']['username']);
            $jailkit_chroot_puserhome = $this->_get_home_dir($this->data['new']['puser']);
            
            if(!is_dir($this->data['new']['dir'].'/etc')) mkdir($this->data['new']['dir'].'/etc');
            if(!is_file($this->data['new']['dir'].'/etc/passwd')) exec('touch '.$this->data['new']['dir'].'/etc/passwd');
            // IMPORTANT!
            // ALWAYS create the user. Even if the user was created before
            // if we check if the user exists, then a update (no shell -> jailkit) will not work
server/scripts/create_jailkit_user.sh
@@ -22,7 +22,7 @@
CHROOT_P_USER_HOMEDIR=$6
### Add the chroot user ###
jk_jailuser  -s $CHROOT_SHELL -j $CHROOT_HOMEDIR $CHROOT_USERNAME
jk_jailuser -n -s $CHROOT_SHELL -j $CHROOT_HOMEDIR $CHROOT_USERNAME
### Reconfigure the chroot home directory for the user ###
usermod --home=$CHROOT_HOMEDIR/.$CHROOT_USERHOMEDIR $CHROOT_USERNAME
server/server.php
@@ -54,7 +54,7 @@
// Check if another process is running
if(is_file($conf["temppath"].$conf["fs_div"].".ispconfig_lock")){
  clearstatcache();
  for($i=0;$i<120;$i++){ // Wait max. 1200 sec, then proceed
  for($i=0;$i<1200;$i++){ // Wait max. 1200 sec, then proceed
    if(is_file($conf["temppath"].$conf["fs_div"].".ispconfig_lock")){
      $app->log("There is already a lockfile set. Waiting another 10 seconds...", LOGLEVEL_DEBUG);
      sleep(10);
@@ -127,4 +127,4 @@
die("finished.\n");
?>
?>