Ejemplo n.º 1
0
/**
 * @FIXME remove when fully migrated to new Settings class
 *
 * @param array $settings_data
 *
 * @return array
 */
function loadSettings(&$settings_data)
{
    $settings = array();
    if (is_array($settings_data) && isset($settings_data['groups']) && is_array($settings_data['groups'])) {
        // prepare for use in for-loop
        $row_stmt = Database::prepare("\n\t\t\tSELECT `settinggroup`, `varname`, `value`\n\t\t\tFROM `" . TABLE_PANEL_SETTINGS . "`\n\t\t\tWHERE `settinggroup` = :group AND `varname` = :varname\n\t\t");
        foreach ($settings_data['groups'] as $settings_part => $settings_part_details) {
            if (is_array($settings_part_details) && isset($settings_part_details['fields']) && is_array($settings_part_details['fields'])) {
                foreach ($settings_part_details['fields'] as $field_name => $field_details) {
                    if (isset($field_details['settinggroup']) && isset($field_details['varname']) && isset($field_details['default'])) {
                        // execute prepared statement
                        $row = Database::pexecute_first($row_stmt, array('group' => $field_details['settinggroup'], 'varname' => $field_details['varname']));
                        if (!empty($row)) {
                            $varvalue = $row['value'];
                        } else {
                            $varvalue = $field_details['default'];
                        }
                        $settings[$field_details['settinggroup']][$field_details['varname']] = $varvalue;
                    } else {
                        $varvalue = false;
                    }
                    $settings_data['groups'][$settings_part]['fields'][$field_name]['value'] = $varvalue;
                }
            }
        }
    }
    return $settings;
}
/**
 * This file is part of the Froxlor project.
 * Copyright (c) 2003-2009 the SysCP Team (see authors).
 * Copyright (c) 2010 the Froxlor Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function getIpPortCombinations($ssl = false)
{
    global $userinfo;
    $additional_conditions_params = array();
    $additional_conditions_array = array();
    if ($userinfo['ip'] != '-1') {
        $admin_ip_stmt = Database::prepare("\n\t\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid\n\t\t");
        $admin_ip = Database::pexecute_first($admin_ip_stmt, array('ipid' => $userinfo['ip']));
        $additional_conditions_array[] = "`ip` = :adminip";
        $additional_conditions_params['adminip'] = $admin_ip['ip'];
        $admin_ip = null;
    }
    if ($ssl !== null) {
        $additional_conditions_array[] = "`ssl` = :ssl";
        $additional_conditions_params['ssl'] = $ssl === true ? '1' : '0';
    }
    $additional_conditions = '';
    if (count($additional_conditions_array) > 0) {
        $additional_conditions = " WHERE " . implode(" AND ", $additional_conditions_array) . " ";
    }
    $result_stmt = Database::prepare("\n\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` " . $additional_conditions . " ORDER BY `ip` ASC, `port` ASC\n\t");
    Database::pexecute($result_stmt, $additional_conditions_params);
    $system_ipaddress_array = array();
    while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
        if (filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            $row['ip'] = '[' . $row['ip'] . ']';
        }
        $system_ipaddress_array[$row['id']] = $row['ip'] . ':' . $row['port'];
    }
    return $system_ipaddress_array;
}
Ejemplo n.º 3
0
 /**
  * returns an array with all entries required for all
  * webserver-vhost-configs
  *
  * @return array
  */
 public static function getVhostsToCreate()
 {
     $query = "SELECT `d`.*, `pd`.`domain` AS `parentdomain`, `c`.`loginname`,\n\t\t\t\t`d`.`phpsettingid`, `c`.`adminid`, `c`.`guid`, `c`.`email`,\n\t\t\t\t`c`.`documentroot` AS `customerroot`, `c`.`deactivated`,\n\t\t\t\t`c`.`phpenabled` AS `phpenabled`, `d`.`mod_fcgid_starter`,\n\t\t\t\t`d`.`mod_fcgid_maxrequests`\n\t\t\t\tFROM `" . TABLE_PANEL_DOMAINS . "` `d`\n\n\t\t\t\tLEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`)\n\t\t\t\tLEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`)\n\n\t\t\t\tWHERE `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> '1'\n\t\t\t\tORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;\n\t\t";
     $result_domains_stmt = Database::query($query);
     $domains = array();
     while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
         if (!checkDomainIPConfigured($domain['id'])) {
             continue;
         }
         // set whole domain
         $domains[$domain['domain']] = $domain;
         // set empty-defaults for non-ssl
         $domains[$domain['domain']]['ssl'] = '';
         $domains[$domain['domain']]['ssl_cert_file'] = '';
         $domains[$domain['domain']]['ssl_key_file'] = '';
         $domains[$domain['domain']]['ssl_ca_file'] = '';
         $domains[$domain['domain']]['ssl_cert_chainfile'] = '';
         // now, if the domain has an ssl ip/port assigned, get
         // the corresponding information from the db
         if (domainHasSslIpPort($domain['id'])) {
             $ip_stmt = Database::prepare("\n\t\t\t\t\t\tSELECT `di`.`id_domain` , `p`.`ssl`, `p`.`ssl_cert_file`, `p`.`ssl_key_file`, `p`.`ssl_ca_file`, `p`.`ssl_cert_chainfile`\n\t\t\t\t\t\tFROM `" . TABLE_DOMAINTOIP . "` `di`, `" . TABLE_PANEL_IPSANDPORTS . "` `p`\n\t\t\t\t\t\tWHERE `p`.`id` = `di`.`id_ipandports`\n\t\t\t\t\t\tAND `di`.`id_domain` = :domainid\n\t\t\t\t\t\tAND `p`.`ssl` = '1'\n\t\t\t\t\t\t");
             $ssl_ip = Database::pexecute_first($ip_stmt, array('domainid' => $domain['id']));
             // set ssl info for domain
             $domains[$domain['domain']]['ssl'] = '1';
             $domains[$domain['domain']]['ssl_cert_file'] = $ssl_ip['ssl_cert_file'];
             $domains[$domain['domain']]['ssl_key_file'] = $ssl_ip['ssl_key_file'];
             $domains[$domain['domain']]['ssl_ca_file'] = $ssl_ip['ssl_ca_file'];
             $domains[$domain['domain']]['ssl_cert_chainfile'] = $ssl_ip['ssl_cert_chainfile'];
         }
     }
     return $domains;
 }
Ejemplo n.º 4
0
 /**
  * check whether the froxlor database and its tables are in utf-8 character-set
  *
  * @param bool $fix fix db charset/collation if not utf8
  *
  * @return boolean
  */
 public function DatabaseCharset($fix = false)
 {
     // get characterset
     $cs_stmt = Database::prepare('SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = :dbname');
     $resp = Database::pexecute_first($cs_stmt, array('dbname' => Database::getDbName()));
     $charset = isset($resp['default_character_set_name']) ? $resp['default_character_set_name'] : null;
     if (!empty($charset) && strtolower($charset) != 'utf8') {
         $this->_log->logAction(ADM_ACTION, LOG_NOTICE, "database charset seems to be different from UTF-8, integrity-check can fix that");
         if ($fix) {
             // fix database
             Database::query('ALTER DATABASE `' . Database::getDbName() . '` CHARACTER SET utf8 COLLATE utf8_general_ci');
             // fix all tables
             $handle = Database::query('SHOW TABLES');
             while ($row = $handle->fetch(PDO::FETCH_ASSOC)) {
                 foreach ($row as $table) {
                     Database::query('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;');
                 }
             }
             $this->_log->logAction(ADM_ACTION, LOG_WARNING, "database charset was different from UTF-8, integrity-check fixed that");
         } else {
             return false;
         }
     }
     if ($fix) {
         return $this->DatabaseCharset();
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * read domain-related (or if empty, parentdomain-related) ssl-certificates from the database
  * and (if not empty) set the corresponding array-indices (ssl_cert_file, ssl_key_file,
  * ssl_ca_file and ssl_cert_chainfile). Hence the parameter as reference.
  *
  * @param array $domain domain-array as reference so we can set the corresponding array-indices
  *
  * @return null
  */
 public function setDomainSSLFilesArray(array &$domain = null)
 {
     // check if the domain itself has a certificate defined
     $dom_certs_stmt = Database::prepare("\n\t\t\tSELECT * FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = :domid\n\t\t");
     $dom_certs = Database::pexecute_first($dom_certs_stmt, array('domid' => $domain['id']));
     if (!is_array($dom_certs) || !isset($dom_certs['ssl_cert_file']) || $dom_certs['ssl_cert_file'] == '') {
         // maybe its parent?
         if ($domain['parentdomainid'] != null) {
             $dom_certs = Database::pexecute_first($dom_certs_stmt, array('domid' => $domain['parentdomainid']));
         }
     }
     // check if it's an array and if the most important field is set
     if (is_array($dom_certs) && isset($dom_certs['ssl_cert_file']) && $dom_certs['ssl_cert_file'] != '') {
         // get destination path
         $sslcertpath = makeCorrectDir(Settings::Get('system.customer_ssl_path'));
         // create path if it does not exist
         if (!file_exists($sslcertpath)) {
             safe_exec('mkdir -p ' . escapeshellarg($sslcertpath));
         }
         // make correct files for the certificates
         $ssl_files = array('ssl_cert_file' => makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '.crt'), 'ssl_key_file' => makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '.key'));
         if (Settings::Get('system.webserver') == 'lighttpd') {
             // put my.crt and my.key together for lighty.
             $dom_certs['ssl_cert_file'] = trim($dom_certs['ssl_cert_file']) . "\n" . trim($dom_certs['ssl_key_file']) . "\n";
             $ssl_files['ssl_key_file'] = '';
         }
         // initialize optional files
         $ssl_files['ssl_ca_file'] = '';
         $ssl_files['ssl_cert_chainfile'] = '';
         // set them if they are != empty
         if ($dom_certs['ssl_ca_file'] != '') {
             $ssl_files['ssl_ca_file'] = makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '_CA.pem');
         }
         if ($dom_certs['ssl_cert_chainfile'] != '') {
             if (Settings::Get('system.webserver') == 'nginx') {
                 // put ca.crt in my.crt, as nginx does not support a separate chain file.
                 $dom_certs['ssl_cert_file'] = trim($dom_certs['ssl_cert_file']) . "\n" . trim($dom_certs['ssl_cert_chainfile']) . "\n";
             } else {
                 $ssl_files['ssl_cert_chainfile'] = makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '_chain.pem');
             }
         }
         // create them on the filesystem
         foreach ($ssl_files as $type => $filename) {
             if ($filename != '') {
                 touch($filename);
                 $_fh = fopen($filename, 'w');
                 fwrite($_fh, $dom_certs[$type]);
                 fclose($_fh);
                 chmod($filename, 0600);
             }
         }
         // override corresponding array values
         $domain['ssl_cert_file'] = $ssl_files['ssl_cert_file'];
         $domain['ssl_key_file'] = $ssl_files['ssl_key_file'];
         $domain['ssl_ca_file'] = $ssl_files['ssl_ca_file'];
         $domain['ssl_cert_chainfile'] = $ssl_files['ssl_cert_chainfile'];
     }
     return;
 }
Ejemplo n.º 6
0
 /**
  * check whether the directory is protected using panel_htpasswd
  */
 public function isUserProtected()
 {
     $up_stmt = Database::prepare("\n\t\t\tSELECT COUNT(`id`) as `usrprot` FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `path` = :dir\n\t\t");
     $up_res = Database::pexecute_first($up_stmt, array('dir' => $this->_dir));
     if ($up_res != false && isset($up_res['usrprot'])) {
         return $up_res['usrprot'] > 0 ? true : false;
     }
     return false;
 }
/**
 * check whether a domain has subdomains added as full-domains
 * #329
 * 
 *  @param int $id domain-id
 *  
 *  @return boolean
 */
function domainHasMainSubDomains($id = 0)
{
    $result_stmt = Database::prepare("\n\t\tSELECT COUNT(`id`) as `mainsubs` FROM `" . TABLE_PANEL_DOMAINS . "`\n\t\tWHERE `ismainbutsubto` = :id");
    $result = Database::pexecute_first($result_stmt, array('id' => $id));
    if (isset($result['mainsubs']) && $result['mainsubs'] > 0) {
        return true;
    }
    return false;
}
/**
 * returns the loginname of a customer by given uid
 * 
 * @param int $uid uid of customer
 * 
 * @return string customers loginname
 */
function getLoginNameByUid($uid = null)
{
    $result_stmt = Database::prepare("\n\t\tSELECT `loginname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `guid` = :guid\n\t");
    $result = Database::pexecute_first($result_stmt, array('guid' => $uid));
    if (is_array($result) && isset($result['loginname'])) {
        return $result['loginname'];
    }
    return false;
}
/**
 * This file is part of the Froxlor project.
 * Copyright (c) 2003-2009 the SysCP Team (see authors).
 * Copyright (c) 2010 the Froxlor Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function getCustomerDetail($customerid, $varname)
{
    $customer_stmt = Database::prepare("\n\t\tSELECT `" . $varname . "` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :customerid\n\t");
    $customer = Database::pexecute_first($customer_stmt, array('customerid' => $customerid));
    if (isset($customer[$varname])) {
        return $customer[$varname];
    } else {
        return false;
    }
}
/**
 * returns true or false whether a given domain id
 * is the std-subdomain of a customer
 *
 * @param int domain-id
 *
 * @return boolean
 */
function isCustomerStdSubdomain($did = 0)
{
    if ($did > 0) {
        $result_stmt = Database::prepare("\n\t\t\tSELECT `customerid` FROM `" . TABLE_PANEL_CUSTOMERS . "`\n\t\t\tWHERE `standardsubdomain` = :did\n\t\t");
        $result = Database::pexecute_first($result_stmt, array('did' => $did));
        if (is_array($result) && isset($result['customerid']) && $result['customerid'] > 0) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 11
0
/**
 * returns the redirect-id for a given 
 * domain-id
 * 
 * @param integer $domainid id of the domain
 * 
 * @return integer redirect-code-id
 */
function getDomainRedirectId($domainid = 0)
{
    $code = 1;
    if ($domainid > 0) {
        $result_stmt = Database::prepare("\n\t\t\tSELECT `r`.`id` as `redirect`\n\t\t\tFROM `" . TABLE_PANEL_REDIRECTCODES . "` `r`, `" . TABLE_PANEL_DOMAINREDIRECTS . "` `rc`\n\t\t\tWHERE `r`.`id` = `rc`.`rid` and `rc`.`did` = :domainid\n\t\t");
        $result = Database::pexecute_first($result_stmt, array('domainid' => $domainid));
        if (is_array($result) && isset($result['redirect'])) {
            $code = (int) $result['redirect'];
        }
    }
    return $code;
}
Ejemplo n.º 12
0
 /**
  * return the php-configuration from the database
  * 
  * @param int $php_config_id id of the php-configuration
  * 
  * @return array
  */
 public function getPhpConfig($php_config_id)
 {
     $php_config_id = intval($php_config_id);
     // If domain has no config, we will use the default one.
     if ($php_config_id == 0) {
         $php_config_id = 1;
     }
     if (!isset($this->php_configs_cache[$php_config_id])) {
         $stmt = Database::prepare("\n\t\t\t\t\tSELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = :id");
         $this->_php_configs_cache[$php_config_id] = Database::pexecute_first($stmt, array('id' => $php_config_id));
     }
     return $this->_php_configs_cache[$php_config_id];
 }
/**
 * Function to move a given customer to a given admin/reseller
 * and update all its references accordingly
 *
 * @param int $id customer-id
 * @param int $adminid target-admin-id
 *
 * @return true on sucess, error-message on failure
 */
function moveCustomerToAdmin($id = 0, $adminid = 0)
{
    if ($id <= 0 || $adminid <= 0) {
        return "no valid id's given";
    }
    // get current admin-id
    $cAdmin_stmt = Database::prepare("\n\t\tSELECT `adminid` FROM `" . TABLE_PANEL_CUSTOMERS . "`\n\t\tWHERE `customerid` = :cid\n\t");
    $cAdmin = Database::pexecute_first($cAdmin_stmt, array('cid' => $id));
    // Update customer entry
    $updCustomer_stmt = Database::prepare("\n\t\tUPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `adminid` = :adminid WHERE `customerid` = :cid\n\t");
    Database::pexecute($updCustomer_stmt, array('adminid' => $cAdmin['adminid'], 'cid' => $id));
    // Update customer-domains
    $updDomains_stmt = Database::prepare("\n\t\tUPDATE `" . TABLE_PANEL_DOMAINS . "` SET `adminid` = :adminid WHERE `customerid` = :cid\n\t");
    Database::pexecute($updDomains_stmt, array('adminid' => $cAdmin['adminid'], 'cid' => $id));
    // Update customer-tickets
    $updTickets_stmt = Database::prepare("\n\t\tUPDATE `" . TABLE_PANEL_TICKETS . "` SET `adminid` = :adminid WHERE `customerid` = :cid\n\t");
    Database::pexecute($updTickets_stmt, array('adminid' => $cAdmin['adminid'], 'cid' => $id));
    // now, recalculate the resource-usage for the old and the new admin
    updateCounters(false);
    return true;
}
/**
 * This file is part of the Froxlor project.
 * Copyright (c) 2016 the Froxlor Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
 *
 * @copyright (c) the authors
 * @author Froxlor team <*****@*****.**> (2016-)
 * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package Functions
 *
 */
function getAllowedDomainEntry($domain_id, $area = 'customer', $userinfo, &$idna_convert)
{
    $dom_data = array('did' => $domain_id);
    $where_clause = '';
    if ($area == 'admin') {
        if ($userinfo['domains_see_all'] != '1') {
            $where_clause = '`adminid` = :uid AND ';
            $dom_data['uid'] = $userinfo['userid'];
        }
    } else {
        $where_clause = '`customerid` = :uid AND ';
        $dom_data['uid'] = $userinfo['userid'];
    }
    $dom_stmt = Database::prepare("\n\t\tSELECT domain, isbinddomain\n\t\tFROM `" . TABLE_PANEL_DOMAINS . "`\n\t\tWHERE " . $where_clause . " id = :did\n\t");
    $domain = Database::pexecute_first($dom_stmt, $dom_data);
    if ($domain) {
        if ($domain['isbinddomain'] != '1') {
            standard_error('dns_domain_nodns');
        }
        return $idna_convert->decode($domain['domain']);
    }
    standard_error('dns_notfoundorallowed');
}
Ejemplo n.º 15
0
                 }
                 redirectTo($filename, array('page' => $page, 's' => $s));
             }
         } else {
             $customer_add_data = (include_once dirname(__FILE__) . '/lib/formfields/admin/formfield.customer.php');
             $customer_add_form = HTMLform2::genHTMLform($customer_add_data);
             eval("echo \"" . getTemplate("customers/customers_add") . "\";");
         }
     }
 } elseif ($action == 'edit' && $id != 0) {
     $result_data = array('id' => $id);
     $result_stmt = Database::prepare("\n\t\t\tSELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "`\n\t\t\tWHERE `customerid` = :id" . ($userinfo['customers_see_all'] ? '' : " AND `adminid` = :adminid"));
     if ($userinfo['customers_see_all'] == '0') {
         $result_data['adminid'] = $userinfo['adminid'];
     }
     $result = Database::pexecute_first($result_stmt, $result_data);
     /*
      * information for moving customer
      */
     $available_admins_stmt = Database::prepare("\n                        SELECT * FROM `" . TABLE_PANEL_ADMINS . "`\n                        WHERE (`customers` = '-1' OR `customers` > `customers_used`)");
     Database::pexecute($available_admins_stmt);
     $admin_select = makeoption("-----", 0, true, true, true);
     $admin_select_cnt = 0;
     while ($available_admin = $available_admins_stmt->fetch()) {
         $admin_select .= makeoption($available_admin['name'] . " (" . $available_admin['loginname'] . ")", $available_admin['adminid'], null, true, true);
         $admin_select_cnt++;
     }
     /*
      * end of moving customer stuff
      */
     if ($result['loginname'] != '') {
Ejemplo n.º 16
0
 if (isset($_POST['selectserveralias'])) {
     $iswildcarddomain = $_POST['selectserveralias'] == '0' ? '1' : '0';
     $wwwserveralias = $_POST['selectserveralias'] == '1' ? '1' : '0';
 } else {
     $iswildcarddomain = $result['iswildcarddomain'];
     $wwwserveralias = $result['wwwserveralias'];
 }
 if ($result['parentdomainid'] != '0' && ($result['subcanemaildomain'] == '1' || $result['subcanemaildomain'] == '2') && isset($_POST['isemaildomain'])) {
     $isemaildomain = intval($_POST['isemaildomain']);
 } else {
     $isemaildomain = $result['isemaildomain'];
 }
 $aliasdomain_check = array('id' => 0);
 if ($aliasdomain != 0) {
     $aliasdomain_stmt = Database::prepare("SELECT `id` FROM `" . TABLE_PANEL_DOMAINS . "` `d`,`" . TABLE_PANEL_CUSTOMERS . "` `c`\n\t\t\t\t\t\tWHERE `d`.`customerid`= :customerid\n\t\t\t\t\t\tAND `d`.`aliasdomain` IS NULL\n\t\t\t\t\t\tAND `d`.`id`<>`c`.`standardsubdomain`\n\t\t\t\t\t\tAND `c`.`customerid`= :customerid\n\t\t\t\t\t\tAND `d`.`id`= :id");
     $aliasdomain_check = Database::pexecute_first($aliasdomain_stmt, array("customerid" => $result['customerid'], "id" => $aliasdomain));
 }
 if ($aliasdomain_check['id'] != $aliasdomain) {
     standard_error('domainisaliasorothercustomer');
 }
 if (isset($_POST['openbasedir_path']) && $_POST['openbasedir_path'] == '1') {
     $openbasedir_path = '1';
 } else {
     $openbasedir_path = '0';
 }
 if (isset($_POST['ssl_redirect']) && $_POST['ssl_redirect'] == '1') {
     // a ssl-redirect only works if there actually is a
     // ssl ip/port assigned to the domain
     if (domainHasSslIpPort($id) == true) {
         $ssl_redirect = '1';
         $_doredirect = true;
Ejemplo n.º 17
0
     $langfile = $lngfile['file'];
 } else {
     $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => Settings::Get('panel.standardlanguage')));
     $langfile = $lngfile['file'];
 }
 // include english language file (fallback)
 include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php');
 // include admin/customer language file
 include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile);
 // Get mail templates from database; the ones from 'admin' are fetched for fallback
 $result2_stmt = Database::prepare("\n\t\t\tSELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`\n\t\t\tWHERE `adminid` = :adminid\n\t\t\tAND `language` = :lang\n\t\t\tAND `templategroup` = 'mails' AND `varname` = :varname\n\t\t");
 $resul2_data = array('adminid' => $row['adminid'], 'lang' => $row['def_language'], 'varname' => 'trafficmaxpercent_subject');
 $result2 = Database::pexecute_first($result2_stmt, $result2_data);
 $mail_subject = html_entity_decode(replace_variables($result2['value'] != '' ? $result2['value'] : $lng['mails']['trafficmaxpercent']['subject'], $replace_arr));
 $resul2_data['varname'] = 'trafficmaxpercent_mailbody';
 $result2 = Database::pexecute_first($result2_stmt, $result2_data);
 $mail_body = html_entity_decode(replace_variables($result2['value'] != '' ? $result2['value'] : $lng['mails']['trafficmaxpercent']['mailbody'], $replace_arr));
 $_mailerror = false;
 try {
     $mail->SetFrom($row['email'], $row['name']);
     $mail->Subject = $mail_subject;
     $mail->AltBody = $mail_body;
     $mail->MsgHTML(nl2br($mail_body));
     $mail->AddAddress($row['email'], $row['name']);
     $mail->Send();
 } catch (phpmailerException $e) {
     $mailerr_msg = $e->errorMessage();
     $_mailerror = true;
 } catch (Exception $e) {
     $mailerr_msg = $e->getMessage();
     $_mailerror = true;
Ejemplo n.º 18
0
 /**
  * return the admin-data of a specific admin
  *
  * @param int $adminid id of the admin-user
  *
  * @return array
  */
 private function _getAdminData($adminid)
 {
     $adminid = intval($adminid);
     if (!isset($this->_admin_cache[$adminid])) {
         $stmt = Database::prepare("\n\t\t\t\t\tSELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = :id");
         $this->_admin_cache[$adminid] = Database::pexecute_first($stmt, array('id' => $adminid));
     }
     return $this->_admin_cache[$adminid];
 }
Ejemplo n.º 19
0
             } else {
                 $result['email_full'] = $idna_convert->decode($result['email_full']);
                 $result = htmlentities_array($result);
                 $forwarder_add_data = (include_once dirname(__FILE__) . '/lib/formfields/customer/email/formfield.emails_addforwarder.php');
                 $forwarder_add_form = htmlform::genHTMLForm($forwarder_add_data);
                 $title = $forwarder_add_data['emails_addforwarder']['title'];
                 $image = $forwarder_add_data['emails_addforwarder']['image'];
                 eval("echo \"" . getTemplate("email/forwarder_add") . "\";");
             }
         }
     } else {
         standard_error('allresourcesused');
     }
 } elseif ($action == 'delete' && $id != 0) {
     $stmt = Database::prepare("SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid`, `popaccountid` FROM `" . TABLE_MAIL_VIRTUAL . "`\n\t\t\tWHERE `customerid`='" . (int) $userinfo['customerid'] . "'\n\t\t\tAND `id`='" . (int) $id . "'");
     $result = Database::pexecute_first($stmt, array("cid" => $userinfo['customerid']));
     if (isset($result['destination']) && $result['destination'] != '') {
         if (isset($_POST['forwarderid'])) {
             $forwarderid = intval($_POST['forwarderid']);
         } elseif (isset($_GET['forwarderid'])) {
             $forwarderid = intval($_GET['forwarderid']);
         } else {
             $forwarderid = 0;
         }
         $result['destination'] = explode(' ', $result['destination']);
         if (isset($result['destination'][$forwarderid]) && $result['email'] != $result['destination'][$forwarderid]) {
             $forwarder = $result['destination'][$forwarderid];
             if (isset($_POST['send']) && $_POST['send'] == 'send') {
                 unset($result['destination'][$forwarderid]);
                 $result['destination'] = implode(' ', $result['destination']);
                 $stmt = Database::prepare("UPDATE `" . TABLE_MAIL_VIRTUAL . "`\n\t\t\t\t\t\tSET `destination` = :dest\n\t\t\t\t\t\tWHERE `customerid`= :cid\n\t\t\t\t\t\tAND `id`= :id");
 protected function getVhostContent($domain, $ssl_vhost = false, $ipid)
 {
     if ($ssl_vhost === true && $domain['ssl'] != '1' && $domain['ssl_redirect'] != '1') {
         return '';
     }
     $vhost_content = '';
     $vhost_content .= $this->getServerNames($domain) . " {\n";
     // respect ssl_redirect settings, #542
     if ($ssl_vhost == false && $domain['ssl'] == '1' && $domain['ssl_redirect'] == '1') {
         // We must not check if our port differs from port 443,
         // but if there is a destination-port != 443
         $_sslport = '';
         // This returns the first port that is != 443 with ssl enabled, if any
         // ordered by ssl-certificate (if any) so that the ip/port combo
         // with certificate is used
         $ssldestport_stmt = Database::prepare("SELECT `ip`.`port` FROM " . TABLE_PANEL_IPSANDPORTS . " `ip`\n\t\t\t\tLEFT JOIN `" . TABLE_DOMAINTOIP . "` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`)\n\t\t\t\tWHERE `dip`.`id_domain` = :domainid\n\t\t\t\tAND `ip`.`ssl` = '1'  AND `ip`.`port` != 443\n\t\t\t\tORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;");
         $ssldestport = Database::pexecute_first($ssldestport_stmt, array('domainid' => $domain['id']));
         if ($ssldestport['port'] != '') {
             $_sslport = ":" . $ssldestport['port'];
         }
         $domain['documentroot'] = 'https://' . $domain['domain'] . $_sslport . '/';
     }
     // avoid using any whitespaces
     $domain['documentroot'] = trim($domain['documentroot']);
     if (preg_match('/^https?\\:\\/\\//', $domain['documentroot'])) {
         $vhost_content .= '  url.redirect = (' . "\n";
         $vhost_content .= '     "^/(.*)$" => "' . $this->idnaConvert->encode_uri($domain['documentroot']) . '$1"' . "\n";
         $vhost_content .= '  )' . "\n";
     } else {
         mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid'], true, true);
         $only_webroot = false;
         if ($ssl_vhost === false && $domain['ssl_redirect'] == '1') {
             $only_webroot = true;
         }
         $vhost_content .= $this->getWebroot($domain, $ssl_vhost);
         if (!$only_webroot) {
             if ($this->_deactivated == false) {
                 $vhost_content .= $this->create_htaccess($domain);
                 $vhost_content .= $this->create_pathOptions($domain);
                 $vhost_content .= $this->composePhpOptions($domain);
                 $vhost_content .= $this->getStats($domain);
                 $ipandport_stmt = Database::prepare("\n\t\t\t\t\t\tSELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "`\n\t\t\t\t\t\tWHERE `id` = :id\n\t\t\t\t\t");
                 $ipandport = Database::pexecute_first($ipandport_stmt, array('id' => $ipid));
                 $domain['ip'] = $ipandport['ip'];
                 $domain['port'] = $ipandport['port'];
                 $domain['ssl_cert_file'] = $ipandport['ssl_cert_file'];
                 $domain['ssl_key_file'] = $ipandport['ssl_key_file'];
                 $domain['ssl_ca_file'] = $ipandport['ssl_ca_file'];
                 // #418
                 $domain['ssl_cert_chainfile'] = $ipandport['ssl_cert_chainfile'];
                 // SSL STUFF
                 $dssl = new DomainSSL();
                 // this sets the ssl-related array-indices in the $domain array
                 // if the domain has customer-defined ssl-certificates
                 $dssl->setDomainSSLFilesArray($domain);
                 $vhost_content .= $this->getSslSettings($domain, $ssl_vhost);
                 if ($domain['specialsettings'] != "") {
                     $vhost_content .= $this->processSpecialConfigTemplate($domain['specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
                 }
                 if ($ipandport['default_vhostconf_domain'] != '') {
                     $vhost_content .= $this->processSpecialConfigTemplate($ipandport['default_vhostconf_domain'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
                 }
                 if (Settings::Get('system.default_vhostconf') != '') {
                     $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_vhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
                 }
             }
             $vhost_content .= $this->getLogFiles($domain);
         }
     }
     $vhost_content .= '}' . "\n";
     return $vhost_content;
 }
Ejemplo n.º 21
0
             Database::pexecute($upd_stmt, array('id' => $id));
             $del_stmt = Database::prepare("\n\t\t\t\t\tDELETE FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = :id");
             Database::pexecute($del_stmt, array('id' => $id));
             inserttask('1');
             $log->logAction(ADM_ACTION, LOG_INFO, "php.ini setting with id #" . (int) $id . " has been deleted by '" . $userinfo['loginname'] . "'");
             redirectTo($filename, array('page' => $page, 's' => $s));
         } else {
             ask_yesno('phpsetting_reallydelete', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $result['description']);
         }
     } else {
         standard_error('nopermissionsorinvalidid');
     }
 }
 if ($action == 'edit') {
     $result_stmt = Database::prepare("\n\t\t\tSELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = :id");
     $result = Database::pexecute_first($result_stmt, array('id' => $id));
     if ($result['id'] != 0 && $result['id'] == $id && (int) $userinfo['change_serversettings'] == 1) {
         if (isset($_POST['send']) && $_POST['send'] == 'send') {
             $description = validate($_POST['description'], 'description');
             $phpsettings = validate(str_replace("\r\n", "\n", $_POST['phpsettings']), 'phpsettings', '/^[^\\0]*$/');
             if (Settings::Get('system.mod_fcgid') == 1) {
                 $binary = makeCorrectFile(validate($_POST['binary'], 'binary'));
                 $file_extensions = validate($_POST['file_extensions'], 'file_extensions', '/^[a-zA-Z0-9\\s]*$/');
                 $mod_fcgid_starter = validate($_POST['mod_fcgid_starter'], 'mod_fcgid_starter', '/^[0-9]*$/', '', array('-1', ''));
                 $mod_fcgid_maxrequests = validate($_POST['mod_fcgid_maxrequests'], 'mod_fcgid_maxrequests', '/^[0-9]*$/', '', array('-1', ''));
                 $mod_fcgid_umask = validate($_POST['mod_fcgid_umask'], 'mod_fcgid_umask', '/^[0-9]*$/');
                 // disable fpm stuff
                 $fpm_enableslowlog = 0;
                 $fpm_reqtermtimeout = 0;
                 $fpm_reqslowtimeout = 0;
             } elseif (Settings::Get('phpfpm.enabled') == 1) {
Ejemplo n.º 22
0
/**
 * Function which updates all counters of used ressources in panel_admins and panel_customers
 * @param bool Set to true to get an array with debug information
 * @return array Contains debug information if parameter 'returndebuginfo' is set to true
 *
 * @author Florian Lippert <*****@*****.**> (2003-2009)
 * @author Froxlor team <*****@*****.**> (2010-)
 */
function updateCounters($returndebuginfo = false)
{
    $returnval = array();
    if ($returndebuginfo === true) {
        $returnval = array('admins' => array(), 'customers' => array());
    }
    // Customers
    $customers_stmt = Database::prepare('SELECT * FROM `' . TABLE_PANEL_CUSTOMERS . '` ORDER BY `customerid`');
    Database::pexecute($customers_stmt);
    $admin_resources = array();
    while ($customer = $customers_stmt->fetch(PDO::FETCH_ASSOC)) {
        $cur_adm = $customer['adminid'];
        // initialize admin-resources array for admin $customer['adminid']
        if (!isset($admin_resources[$cur_adm])) {
            $admin_resources[$cur_adm] = array();
        }
        _addResourceCountEx($admin_resources[$cur_adm], $customer, 'diskspace_used', 'diskspace');
        _addResourceCountEx($admin_resources[$cur_adm], $customer, 'traffic_used', 'traffic_used');
        // !!! yes, USED and USED
        foreach (array('mysqls', 'ftps', 'emails', 'email_accounts', 'tickets', 'email_forwarders', 'email_quota', 'subdomains') as $field) {
            _addResourceCount($admin_resources[$cur_adm], $customer, $field . '_used', $field);
        }
        $customer_mysqls_stmt = Database::prepare('SELECT COUNT(*) AS `number_mysqls` FROM `' . TABLE_PANEL_DATABASES . '`
			WHERE `customerid` = :cid');
        $customer_mysqls = Database::pexecute_first($customer_mysqls_stmt, array("cid" => $customer['customerid']));
        $customer['mysqls_used_new'] = (int) $customer_mysqls['number_mysqls'];
        $customer_emails_stmt = Database::prepare('SELECT COUNT(*) AS `number_emails` FROM `' . TABLE_MAIL_VIRTUAL . '`
			WHERE `customerid` = :cid');
        $customer_emails = Database::pexecute_first($customer_emails_stmt, array("cid" => $customer['customerid']));
        $customer['emails_used_new'] = (int) $customer_emails['number_emails'];
        $customer_emails_result_stmt = Database::prepare('SELECT `email`, `email_full`, `destination`, `popaccountid` AS `number_email_forwarders` FROM `' . TABLE_MAIL_VIRTUAL . '`
			WHERE `customerid` = :cid');
        Database::pexecute($customer_emails_result_stmt, array("cid" => $customer['customerid']));
        $customer_email_forwarders = 0;
        $customer_email_accounts = 0;
        while ($customer_emails_row = $customer_emails_result_stmt->fetch(PDO::FETCH_ASSOC)) {
            if ($customer_emails_row['destination'] != '') {
                $customer_emails_row['destination'] = explode(' ', makeCorrectDestination($customer_emails_row['destination']));
                $customer_email_forwarders += count($customer_emails_row['destination']);
                if (in_array($customer_emails_row['email_full'], $customer_emails_row['destination'])) {
                    $customer_email_forwarders -= 1;
                    $customer_email_accounts++;
                }
            }
        }
        $customer['email_accounts_used_new'] = $customer_email_accounts;
        $customer['email_forwarders_used_new'] = $customer_email_forwarders;
        $customer_ftps_stmt = Database::prepare('SELECT COUNT(*) AS `number_ftps` FROM `' . TABLE_FTP_USERS . '` WHERE `customerid` = :cid');
        $customer_ftps = Database::pexecute_first($customer_ftps_stmt, array("cid" => $customer['customerid']));
        $customer['ftps_used_new'] = (int) $customer_ftps['number_ftps'] - 1;
        $customer_tickets_stmt = Database::prepare('SELECT COUNT(*) AS `number_tickets` FROM `' . TABLE_PANEL_TICKETS . '` WHERE `answerto` = "0" AND `customerid` =  :cid');
        $customer_tickets = Database::pexecute_first($customer_tickets_stmt, array("cid" => $customer['customerid']));
        $customer['tickets_used_new'] = (int) $customer_tickets['number_tickets'];
        $customer_subdomains_stmt = Database::prepare('SELECT COUNT(*) AS `number_subdomains` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `customerid` = :cid AND `parentdomainid` IS NOT NULL');
        $customer_subdomains = Database::pexecute_first($customer_subdomains_stmt, array("cid" => $customer['customerid']));
        $customer['subdomains_used_new'] = (int) $customer_subdomains['number_subdomains'];
        $customer_email_quota_stmt = Database::prepare('SELECT SUM(`quota`) AS `email_quota` FROM `' . TABLE_MAIL_USERS . '` WHERE `customerid` = :cid');
        $customer_email_quota = Database::pexecute_first($customer_email_quota_stmt, array("cid" => $customer['customerid']));
        $customer['email_quota_used_new'] = (int) $customer_email_quota['email_quota'];
        $stmt = Database::prepare('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` 
			SET `mysqls_used` = :mysqls_used,
				`emails_used` = :emails_used,
				`email_accounts_used` = :email_accounts_used,
				`email_forwarders_used` = :email_forwarders_used,
				`email_quota_used` = :email_quota_used,
				`ftps_used` = :ftps_used, 
				`tickets_used` = :tickets_used,
				`subdomains_used` = :subdomains_used
			WHERE `customerid` = :cid');
        $params = array("mysqls_used" => $customer['mysqls_used_new'], "emails_used" => $customer['emails_used_new'], "email_accounts_used" => $customer['email_accounts_used_new'], "email_forwarders_used" => $customer['email_forwarders_used_new'], "email_quota_used" => $customer['email_quota_used_new'], "ftps_used" => $customer['ftps_used_new'], "tickets_used" => $customer['tickets_used_new'], "subdomains_used" => $customer['subdomains_used_new'], "cid" => $customer['customerid']);
        Database::pexecute($stmt, $params);
        if ($returndebuginfo === true) {
            $returnval['customers'][$customer['customerid']] = $customer;
        }
    }
    // Admins
    $admins_stmt = Database::prepare('SELECT * FROM `' . TABLE_PANEL_ADMINS . '` ORDER BY `adminid`');
    Database::pexecute($admins_stmt, array());
    while ($admin = $admins_stmt->fetch(PDO::FETCH_ASSOC)) {
        $admin_customers_stmt = Database::prepare('SELECT COUNT(*) AS `number_customers` FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `adminid` = :aid');
        $admin_customers = Database::pexecute_first($admin_customers_stmt, array("aid" => $admin['adminid']));
        $admin['customers_used_new'] = $admin_customers['number_customers'];
        $admin_domains_stmt = Database::prepare('SELECT COUNT(*) AS `number_domains` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `adminid` = :aid AND `isemaildomain` = "1"');
        $admin_domains = Database::pexecute_first($admin_domains_stmt, array("aid" => $admin['adminid']));
        $admin['domains_used_new'] = $admin_domains['number_domains'];
        $cur_adm = $admin['adminid'];
        if (!isset($admin_resources[$cur_adm])) {
            $admin_resources[$cur_adm] = array();
        }
        foreach (array('diskspace_used', 'traffic_used', 'mysqls_used', 'ftps_used', 'emails_used', 'email_accounts_used', 'tickets_used', 'email_forwarders_used', 'email_quota_used', 'subdomains_used') as $field) {
            _initArrField($field, $admin_resources[$cur_adm], 0);
            $admin[$field . '_new'] = $admin_resources[$cur_adm][$field];
        }
        $stmt = Database::prepare('UPDATE `' . TABLE_PANEL_ADMINS . '` 
			SET `customers_used` = :customers_used,
				`domains_used` = :domains_used,
				`diskspace_used` = :diskspace_used,
				`mysqls_used` = :mysqls_used,
				`emails_used` = :emails_used,
				`email_accounts_used` = :email_accounts_used,
				`email_forwarders_used` = :email_forwarders_used,
				`email_quota_used` = :email_quota_used,
				`ftps_used` = :ftps_used, 
				`tickets_used` = :tickets_used,
				`subdomains_used` = :subdomains_used,
				`traffic_used` = :traffic_used
			WHERE `adminid` = :aid');
        $params = array("customers_used" => $admin['customers_used_new'], "domains_used" => $admin['domains_used_new'], "diskspace_used" => $admin['diskspace_used_new'], "mysqls_used" => $admin['mysqls_used_new'], "emails_used" => $admin['emails_used_new'], "email_accounts_used" => $admin['email_accounts_used_new'], "email_forwarders_used" => $admin['email_forwarders_used_new'], "email_quota_used" => $admin['email_quota_used_new'], "ftps_used" => $admin['ftps_used_new'], "tickets_used" => $admin['tickets_used_new'], "subdomains_used" => $admin['subdomains_used_new'], "traffic_used" => $admin['traffic_used_new'], "aid" => $admin['adminid']);
        Database::pexecute($stmt, $params);
        if ($returndebuginfo === true) {
            $returnval['admins'][$admin['adminid']] = $admin;
        }
    }
    return $returnval;
}
 /**
  * We compose the virtualhost entry for one domain
  */
 protected function getVhostContent($domain, $ssl_vhost = false)
 {
     if ($ssl_vhost === true && ($domain['ssl_redirect'] != '1' && $domain['ssl'] != '1')) {
         return '';
     }
     $query = "SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` `i`, `" . TABLE_DOMAINTOIP . "` `dip`\n\t\t\tWHERE dip.id_domain = :domainid AND i.id = dip.id_ipandports ";
     if ($ssl_vhost === true && ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1')) {
         // by ordering by cert-file the row with filled out SSL-Fields will be shown last, thus it is enough to fill out 1 set of SSL-Fields
         $query .= "AND i.ssl = '1' ORDER BY i.ssl_cert_file ASC;";
     } else {
         $query .= "AND i.ssl = '0';";
     }
     $vhost_content = '';
     $result_stmt = Database::prepare($query);
     Database::pexecute($result_stmt, array('domainid' => $domain['id']));
     $ipportlist = '';
     $_vhost_content = '';
     while ($ipandport = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
         $ipport = '';
         $domain['ip'] = $ipandport['ip'];
         $domain['port'] = $ipandport['port'];
         if ($domain['ssl'] == '1') {
             $domain['ssl_cert_file'] = $ipandport['ssl_cert_file'];
             $domain['ssl_key_file'] = $ipandport['ssl_key_file'];
             $domain['ssl_ca_file'] = $ipandport['ssl_ca_file'];
             $domain['ssl_cert_chainfile'] = $ipandport['ssl_cert_chainfile'];
             // SSL STUFF
             $dssl = new DomainSSL();
             // this sets the ssl-related array-indices in the $domain array
             // if the domain has customer-defined ssl-certificates
             $dssl->setDomainSSLFilesArray($domain);
         }
         if (filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
             $ipport = '[' . $domain['ip'] . ']:' . $domain['port'] . ' ';
         } else {
             $ipport = $domain['ip'] . ':' . $domain['port'] . ' ';
         }
         if ($ipandport['default_vhostconf_domain'] != '') {
             $_vhost_content .= $this->processSpecialConfigTemplate($ipandport['default_vhostconf_domain'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
         }
         $ipportlist .= $ipport;
     }
     $vhost_content .= '<VirtualHost ' . trim($ipportlist) . '>' . "\n";
     $vhost_content .= $this->getServerNames($domain);
     if ($ssl_vhost == false && $domain['ssl'] == '1' && $domain['ssl_redirect'] == '1') {
         // We must not check if our port differs from port 443,
         // but if there is a destination-port != 443
         $_sslport = '';
         // This returns the first port that is != 443 with ssl enabled, if any
         // ordered by ssl-certificate (if any) so that the ip/port combo
         // with certificate is used
         $ssldestport_stmt = Database::prepare("\n\t\t\t\tSELECT `ip`.`port` FROM " . TABLE_PANEL_IPSANDPORTS . " `ip`\n\t\t\t\tLEFT JOIN `" . TABLE_DOMAINTOIP . "` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`)\n\t\t\t\tWHERE `dip`.`id_domain` = :domainid\n\t\t\t\tAND `ip`.`ssl` = '1'  AND `ip`.`port` != 443\n\t\t\t\tORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;\n\t\t\t");
         $ssldestport = Database::pexecute_first($ssldestport_stmt, array('domainid' => $domain['id']));
         if ($ssldestport['port'] != '') {
             $_sslport = ":" . $ssldestport['port'];
         }
         $domain['documentroot'] = 'https://' . $domain['domain'] . $_sslport . '/';
     }
     if ($ssl_vhost === true && $domain['ssl'] == '1' && Settings::Get('system.use_ssl') == '1') {
         if ($domain['ssl_cert_file'] == '') {
             $domain['ssl_cert_file'] = Settings::Get('system.ssl_cert_file');
         }
         if ($domain['ssl_key_file'] == '') {
             $domain['ssl_key_file'] = Settings::Get('system.ssl_key_file');
         }
         if ($domain['ssl_ca_file'] == '') {
             $domain['ssl_ca_file'] = Settings::Get('system.ssl_ca_file');
         }
         if ($domain['ssl_cert_chainfile'] == '') {
             $domain['ssl_cert_chainfile'] = Settings::Get('system.ssl_cert_chainfile');
         }
         if ($domain['ssl_cert_file'] != '') {
             $vhost_content .= '  SSLEngine On' . "\n";
             $vhost_content .= '  SSLProtocol ALL -SSLv2 -SSLv3' . "\n";
             // this makes it more secure, thx to Marcel (08/2013)
             $vhost_content .= '  SSLHonorCipherOrder On' . "\n";
             $vhost_content .= '  SSLCipherSuite ' . Settings::Get('system.ssl_cipher_list') . "\n";
             $vhost_content .= '  SSLVerifyDepth 10' . "\n";
             $vhost_content .= '  SSLCertificateFile ' . makeCorrectFile($domain['ssl_cert_file']) . "\n";
             if ($domain['ssl_key_file'] != '') {
                 $vhost_content .= '  SSLCertificateKeyFile ' . makeCorrectFile($domain['ssl_key_file']) . "\n";
             }
             if ($domain['ssl_ca_file'] != '') {
                 $vhost_content .= '  SSLCACertificateFile ' . makeCorrectFile($domain['ssl_ca_file']) . "\n";
             }
             if ($domain['ssl_cert_chainfile'] != '') {
                 $vhost_content .= '  SSLCertificateChainFile ' . makeCorrectFile($domain['ssl_cert_chainfile']) . "\n";
             }
         }
     }
     if (preg_match('/^https?\\:\\/\\//', $domain['documentroot'])) {
         $corrected_docroot = $this->idnaConvert->encode($domain['documentroot']);
         // Get domain's redirect code
         $code = getDomainRedirectCode($domain['id']);
         $modrew_red = '';
         if ($code != '') {
             $modrew_red = '[R=' . $code . ';L,NE]';
         }
         // redirect everything, not only root-directory, #541
         $vhost_content .= '  <IfModule mod_rewrite.c>' . "\n";
         $vhost_content .= '    RewriteEngine On' . "\n";
         if (!$ssl_vhost) {
             $vhost_content .= '    RewriteCond %{HTTPS} off' . "\n";
         }
         $vhost_content .= '    RewriteRule ^/(.*) ' . $corrected_docroot . '$1 ' . $modrew_red . "\n";
         $vhost_content .= '  </IfModule>' . "\n";
         $vhost_content .= '  Redirect ' . $code . ' / ' . $this->idnaConvert->encode($domain['documentroot']) . "\n";
     } else {
         mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid'], true, true);
         $vhost_content .= $this->getWebroot($domain);
         if ($this->_deactivated == false) {
             $vhost_content .= $this->composePhpOptions($domain, $ssl_vhost);
             $vhost_content .= $this->getStats($domain);
         }
         $vhost_content .= $this->getLogfiles($domain);
         if ($domain['specialsettings'] != '') {
             $vhost_content .= $this->processSpecialConfigTemplate($domain['specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
         }
         if ($_vhost_content != '') {
             $vhost_content .= $_vhost_content;
         }
         if (Settings::Get('system.default_vhostconf') != '') {
             $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_vhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
         }
     }
     $vhost_content .= '</VirtualHost>' . "\n";
     return $vhost_content;
 }
Ejemplo n.º 24
0
function callAwstatsGetTraffic($customerid, $outputdir, $usersdomainlist)
{
    global $cronlog;
    $returnval = 0;
    foreach ($usersdomainlist as $domainid => $singledomain) {
        // as we check for the config-model awstats will only parse
        // 'real' domains and no subdomains which are aliases in the
        // model-config-file.
        $returnval += awstatsDoSingleDomain($singledomain, $outputdir);
    }
    /**
     * as of #124, awstats traffic is saved in bytes instead
     * of kilobytes (like webalizer does)
     */
    $returnval = floatval($returnval / 1024);
    /**
     * now, because this traffic is being saved daily, we have to
     * subtract the values  from all the month's values to return
     * a sane value for our panel_traffic and to remain the whole stats
     * (awstats overwrites the customers .html stats-files)
     */
    if ($customerid !== false) {
        $result_stmt = Database::prepare("\n\t\t\tSELECT SUM(`http`) as `trafficmonth` FROM `" . TABLE_PANEL_TRAFFIC . "`\n\t\t\tWHERE `customerid` = :customerid\n\t\t\tAND `year` = :year AND `month` = :month\n\t\t");
        $result_data = array('customerid' => $customerid, 'year' => date('Y', time()), 'month' => date('m', time()));
        $result = Database::pexecute_first($result_stmt, $result_data);
        if (is_array($result) && isset($result['trafficmonth'])) {
            $returnval = $returnval - floatval($result['trafficmonth']);
        }
    }
    return floatval($returnval);
}
Ejemplo n.º 25
0
 protected function getVhostContent($domain, $ssl_vhost = false)
 {
     if ($ssl_vhost === true && $domain['ssl'] != '1' && $domain['ssl_redirect'] != '1') {
         return '';
     }
     $vhost_content = '';
     $_vhost_content = '';
     $query = "SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` `i`, `" . TABLE_DOMAINTOIP . "` `dip`\n\t\t\tWHERE dip.id_domain = :domainid AND i.id = dip.id_ipandports ";
     if ($ssl_vhost === true && ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1')) {
         // by ordering by cert-file the row with filled out SSL-Fields will be shown last,
         // thus it is enough to fill out 1 set of SSL-Fields
         $query .= "AND i.ssl = 1 ORDER BY i.ssl_cert_file ASC;";
     } else {
         $query .= "AND i.ssl = '0';";
     }
     // start vhost
     $vhost_content .= 'server { ' . "\n";
     $result_stmt = Database::prepare($query);
     Database::pexecute($result_stmt, array('domainid' => $domain['id']));
     while ($ipandport = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
         $domain['ip'] = $ipandport['ip'];
         $domain['port'] = $ipandport['port'];
         if ($domain['ssl'] == '1') {
             $domain['ssl_cert_file'] = $ipandport['ssl_cert_file'];
             $domain['ssl_key_file'] = $ipandport['ssl_key_file'];
             $domain['ssl_ca_file'] = $ipandport['ssl_ca_file'];
             $domain['ssl_cert_chainfile'] = $ipandport['ssl_cert_chainfile'];
             // SSL STUFF
             $dssl = new DomainSSL();
             // this sets the ssl-related array-indices in the $domain array
             // if the domain has customer-defined ssl-certificates
             $dssl->setDomainSSLFilesArray($domain);
         }
         if (filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
             $ipport = '[' . $domain['ip'] . ']:' . $domain['port'];
         } else {
             $ipport = $domain['ip'] . ':' . $domain['port'];
         }
         if ($ipandport['default_vhostconf_domain'] != '') {
             $_vhost_content .= $this->processSpecialConfigTemplate($ipandport['default_vhostconf_domain'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n";
         }
         $vhost_content .= "\t" . 'listen ' . $ipport . ($ssl_vhost == true ? ' ssl' : '') . ';' . "\n";
     }
     // get all server-names
     $vhost_content .= $this->getServerNames($domain);
     // respect ssl_redirect settings, #542
     if ($ssl_vhost == false && $domain['ssl'] == '1' && $domain['ssl_redirect'] == '1') {
         // We must not check if our port differs from port 443,
         // but if there is a destination-port != 443
         $_sslport = '';
         // This returns the first port that is != 443 with ssl enabled, if any
         // ordered by ssl-certificate (if any) so that the ip/port combo
         // with certificate is used
         $ssldestport_stmt = Database::prepare("SELECT `ip`.`port` FROM " . TABLE_PANEL_IPSANDPORTS . " `ip`\n\t\t\t\tLEFT JOIN `" . TABLE_DOMAINTOIP . "` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`)\n\t\t\t\tWHERE `dip`.`id_domain` = :domainid\n\t\t\t\tAND `ip`.`ssl` = '1'  AND `ip`.`port` != 443\n\t\t\t\tORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;");
         $ssldestport = Database::pexecute_first($ssldestport_stmt, array('domainid' => $domain['id']));
         if ($ssldestport['port'] != '') {
             $_sslport = ":" . $ssldestport['port'];
         }
         $domain['documentroot'] = 'https://' . $domain['domain'] . $_sslport . '/';
     }
     // if the documentroot is an URL we just redirect
     if (preg_match('/^https?\\:\\/\\//', $domain['documentroot'])) {
         $uri = $this->idnaConvert->encode($domain['documentroot']);
         if (substr($uri, -1) == '/') {
             $uri = substr($uri, 0, -1);
         }
         $vhost_content .= "\t" . 'rewrite ^(.*) ' . $uri . '$1 permanent;' . "\n";
     } else {
         mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid'], true);
         $vhost_content .= $this->getLogFiles($domain);
         $vhost_content .= $this->getWebroot($domain, $ssl_vhost);
         if ($this->_deactivated == false) {
             if ($ssl_vhost === true && $domain['ssl'] == '1' && Settings::Get('system.use_ssl') == '1') {
                 $vhost_content .= $this->composeSslSettings($domain);
             }
             $vhost_content = $this->mergeVhostCustom($vhost_content, $this->create_pathOptions($domain)) . "\n";
             $vhost_content .= $this->composePhpOptions($domain, $ssl_vhost);
             $vhost_content .= isset($this->needed_htpasswds[$domain['id']]) ? $this->needed_htpasswds[$domain['id']] . "\n" : '';
             if ($domain['specialsettings'] != "") {
                 $vhost_content = $this->mergeVhostCustom($vhost_content, $this->processSpecialConfigTemplate($domain['specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost));
             }
             if ($_vhost_content != '') {
                 $vhost_content = $this->mergeVhostCustom($vhost_content, $_vhost_content);
             }
             if (Settings::Get('system.default_vhostconf') != '') {
                 $vhost_content = $this->mergeVhostCustom($vhost_content, $this->processSpecialConfigTemplate(Settings::Get('system.default_vhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n");
             }
         }
     }
     $vhost_content .= "\n}\n\n";
     return $vhost_content;
 }
Ejemplo n.º 26
0
/**
 * This file is part of the Froxlor project.
 * Copyright (c) 2016 the Froxlor Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
 *
 * @copyright (c) the authors
 * @author Froxlor team <*****@*****.**> (2016-)
 * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package Functions
 *
 */
function createDomainZone($domain_id, $froxlorhostname = false, $isMainButSubTo = false)
{
    if (!$froxlorhostname) {
        // get domain-name
        $dom_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAINS . "` WHERE id = :did");
        $domain = Database::pexecute_first($dom_stmt, array('did' => $domain_id));
    } else {
        $domain = $domain_id;
    }
    if ($domain['isbinddomain'] != '1') {
        return;
    }
    $dom_entries = array();
    if (!$froxlorhostname) {
        // select all entries
        $sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC");
        Database::pexecute($sel_stmt, array('did' => $domain_id));
        $dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    // check for required records
    $required_entries = array();
    addRequiredEntry('@', 'A', $required_entries);
    addRequiredEntry('@', 'AAAA', $required_entries);
    if (!$isMainButSubTo) {
        addRequiredEntry('@', 'NS', $required_entries);
    }
    if ($domain['isemaildomain'] === '1') {
        addRequiredEntry('@', 'MX', $required_entries);
        if (Settings::Get('system.dns_createmailentry')) {
            foreach (['imap', 'pop3', 'mail', 'smtp'] as $record) {
                foreach (['AAAA', 'A'] as $type) {
                    addRequiredEntry($record, $type, $required_entries);
                }
            }
        }
    }
    // additional required records by setting
    if ($domain['iswildcarddomain'] == '1') {
        addRequiredEntry('*', 'A', $required_entries);
        addRequiredEntry('*', 'AAAA', $required_entries);
    } elseif ($domain['wwwserveralias'] == '1') {
        addRequiredEntry('www', 'A', $required_entries);
        addRequiredEntry('www', 'AAAA', $required_entries);
    }
    if (!$froxlorhostname) {
        // additional required records for subdomains
        $subdomains_stmt = Database::prepare("\n\t\t\tSELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `" . TABLE_PANEL_DOMAINS . "`\n\t\t\tWHERE `parentdomainid` = :domainid\n\t\t");
        Database::pexecute($subdomains_stmt, array('domainid' => $domain_id));
        while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) {
            // Listing domains is enough as there currently is no support for choosing
            // different ips for a subdomain => use same IPs as toplevel
            addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
            addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
            // Check whether to add a www.-prefix
            if ($subdomain['iswildcarddomain'] == '1') {
                addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
                addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
            } elseif ($subdomain['wwwserveralias'] == '1') {
                addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
                addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
            }
        }
    }
    // additional required records for SPF and DKIM if activated
    if ($domain['isemaildomain'] == '1') {
        if (Settings::Get('spf.use_spf') == '1') {
            // check for SPF content later
            addRequiredEntry('@SPF@', 'TXT', $required_entries);
        }
        if (Settings::Get('dkim.use_dkim') == '1') {
            // check for DKIM content later
            addRequiredEntry('dkim_' . $domain['dkim_id'] . '._domainkey', 'TXT', $required_entries);
            // check for ASDP
            if (Settings::Get('dkim.dkim_add_adsp') == "1") {
                addRequiredEntry('_adsp._domainkey', 'TXT', $required_entries);
            }
        }
    }
    $primary_ns = null;
    $zonerecords = array();
    // now generate all records and unset the required entries we have
    foreach ($dom_entries as $entry) {
        if (array_key_exists($entry['type'], $required_entries) && array_key_exists(md5($entry['record']), $required_entries[$entry['type']])) {
            unset($required_entries[$entry['type']][md5($entry['record'])]);
        }
        if (Settings::Get('spf.use_spf') == '1' && $entry['type'] == 'TXT' && $entry['record'] == '@' && strtolower(substr($entry['content'], 0, 7)) == '"v=spf1') {
            // unset special spf required-entry
            unset($required_entries[$entry['type']][md5("@SPF@")]);
        }
        if (empty($primary_ns) && $entry['type'] == 'NS') {
            // use the first NS entry as primary ns
            $primary_ns = $entry['content'];
        }
        $zonerecords[] = new DnsEntry($entry['record'], $entry['type'], $entry['content'], $entry['prio'], $entry['ttl']);
    }
    // add missing required entries
    if (!empty($required_entries)) {
        // A / AAAA records
        if (array_key_exists("A", $required_entries) || array_key_exists("AAAA", $required_entries)) {
            if ($froxlorhostname) {
                // use all available IP's for the froxlor-hostname
                $result_ip_stmt = Database::prepare("\n\t\t\t\t\tSELECT `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "` GROUP BY `ip`\n\t\t\t\t");
                Database::pexecute($result_ip_stmt);
            } else {
                $result_ip_stmt = Database::prepare("\n\t\t\t\t\tSELECT `p`.`ip` AS `ip`\n\t\t\t\t\tFROM `" . TABLE_PANEL_IPSANDPORTS . "` `p`, `" . TABLE_DOMAINTOIP . "` `di`\n\t\t\t\t\tWHERE `di`.`id_domain` = :domainid AND `p`.`id` = `di`.`id_ipandports`\n\t\t\t\t\tGROUP BY `p`.`ip`;\n\t\t\t\t");
                Database::pexecute($result_ip_stmt, array('domainid' => $domain_id));
            }
            $all_ips = $result_ip_stmt->fetchAll(PDO::FETCH_ASSOC);
            foreach ($all_ips as $ip) {
                foreach ($required_entries as $type => $records) {
                    foreach ($records as $record) {
                        if ($type == 'A' && filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
                            $zonerecords[] = new DnsEntry($record, 'A', $ip['ip']);
                        } elseif ($type == 'AAAA' && filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) {
                            $zonerecords[] = new DnsEntry($record, 'AAAA', $ip['ip']);
                        }
                    }
                }
            }
            unset($required_entries['A']);
            unset($required_entries['AAAA']);
        }
        // NS records
        if (array_key_exists("NS", $required_entries)) {
            if (Settings::Get('system.nameservers') != '') {
                $nameservers = explode(',', Settings::Get('system.nameservers'));
                foreach ($nameservers as $nameserver) {
                    $nameserver = trim($nameserver);
                    // append dot to hostname
                    if (substr($nameserver, -1, 1) != '.') {
                        $nameserver .= '.';
                    }
                    foreach ($required_entries as $type => $records) {
                        if ($type == 'NS') {
                            foreach ($records as $record) {
                                if (empty($primary_ns)) {
                                    // use the first NS entry as primary ns
                                    $primary_ns = $nameserver;
                                }
                                $zonerecords[] = new DnsEntry($record, 'NS', $nameserver);
                            }
                        }
                    }
                }
                unset($required_entries['NS']);
            }
        }
        // MX records
        if (array_key_exists("MX", $required_entries)) {
            if (Settings::Get('system.mxservers') != '') {
                $mxservers = explode(',', Settings::Get('system.mxservers'));
                foreach ($mxservers as $mxserver) {
                    if (substr($mxserver, -1, 1) != '.') {
                        $mxserver .= '.';
                    }
                    // split in prio and server
                    $mx_details = explode(" ", $mxserver);
                    if (count($mx_details) == 1) {
                        $mx_details[1] = $mx_details[0];
                        $mx_details[0] = 10;
                    }
                    foreach ($required_entries as $type => $records) {
                        if ($type == 'MX') {
                            foreach ($records as $record) {
                                $zonerecords[] = new DnsEntry($record, 'MX', $mx_details[1], $mx_details[0]);
                            }
                        }
                    }
                }
                unset($required_entries['MX']);
            }
        }
        // TXT (SPF and DKIM)
        if (array_key_exists("TXT", $required_entries)) {
            if (Settings::Get('dkim.use_dkim') == '1') {
                $dkim_entries = generateDkimEntries($domain);
            }
            foreach ($required_entries as $type => $records) {
                if ($type == 'TXT') {
                    foreach ($records as $record) {
                        if ($record == '@SPF@') {
                            $txt_content = Settings::Get('spf.spf_entry');
                            $zonerecords[] = new DnsEntry('@', 'TXT', encloseTXTContent($txt_content));
                        } elseif ($record == 'dkim_' . $domain['dkim_id'] . '._domainkey' && !empty($dkim_entries)) {
                            // check for multiline entry
                            $multiline = false;
                            if (substr($dkim_entries[0], 0, 1) == '(') {
                                $multiline = true;
                            }
                            $zonerecords[] = new DnsEntry($record, 'TXT', encloseTXTContent($dkim_entries[0], $multiline));
                        } elseif ($record == '_adsp._domainkey' && !empty($dkim_entries) && isset($dkim_entries[1])) {
                            $zonerecords[] = new DnsEntry($record, 'TXT', encloseTXTContent($dkim_entries[1]));
                        }
                    }
                }
            }
        }
    }
    if (empty($primary_ns)) {
        // TODO log error: no NS given, use system-hostname
        $primary_ns = Settings::Get('system.hostname');
    }
    if (!$isMainButSubTo) {
        $date = date('Ymd');
        $domain['bindserial'] = preg_match('/^' . $date . '/', $domain['bindserial']) ? $domain['bindserial'] + 1 : $date . '00';
        if (!$froxlorhostname) {
            $upd_stmt = Database::prepare("\n\t\t\t\t\tUPDATE `" . TABLE_PANEL_DOMAINS . "` SET\n\t\t\t\t\t`bindserial` = :serial\n\t\t\t\t\t WHERE `id` = :id\n\t\t\t\t");
            Database::pexecute($upd_stmt, array('serial' => $domain['bindserial'], 'id' => $domain['id']));
        }
        $soa_content = $primary_ns . " " . escapeSoaAdminMail(Settings::Get('panel.adminmail')) . " (" . PHP_EOL;
        $soa_content .= $domain['bindserial'] . "\t; serial" . PHP_EOL;
        // TODO for now, dummy time-periods
        $soa_content .= "1800\t; refresh (30 mins)" . PHP_EOL;
        $soa_content .= "900\t; retry (15 mins)" . PHP_EOL;
        $soa_content .= "604800\t; expire (7 days)" . PHP_EOL;
        $soa_content .= "1200\t)\t; minimum (20 mins)";
        $soa_record = new DnsEntry('@', 'SOA', $soa_content);
        array_unshift($zonerecords, $soa_record);
    }
    $zone = new DnsZone((int) Settings::Get('system.defaultttl'), $domain['domain'], $domain['bindserial'], $zonerecords);
    return $zone;
}
Ejemplo n.º 27
0
 $result = Database::pexecute_first($result_stmt, array('id' => $id));
 if ($result['ip'] != '') {
     if (isset($_POST['send']) && $_POST['send'] == 'send') {
         $ip = validate_ip($_POST['ip']);
         $port = validate($_POST['port'], 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array('stringisempty', 'myport'));
         $listen_statement = isset($_POST['listen_statement']) ? 1 : 0;
         $namevirtualhost_statement = isset($_POST['namevirtualhost_statement']) ? 1 : 0;
         $vhostcontainer = isset($_POST['vhostcontainer']) ? 1 : 0;
         $specialsettings = validate(str_replace("\r\n", "\n", $_POST['specialsettings']), 'specialsettings', '/^[^\\0]*$/');
         $vhostcontainer_servername_statement = isset($_POST['vhostcontainer_servername_statement']) ? 1 : 0;
         $default_vhostconf_domain = validate(str_replace("\r\n", "\n", $_POST['default_vhostconf_domain']), 'default_vhostconf_domain', '/^[^\\0]*$/');
         $docroot = validate($_POST['docroot'], 'docroot');
         $result_checkfordouble_stmt = Database::prepare("\n\t\t\t\t\tSELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`\n\t\t\t\t\tWHERE `ip` = :ip AND `port` = :port");
         $result_checkfordouble = Database::pexecute_first($result_checkfordouble_stmt, array('ip' => $ip, 'port' => $port));
         $result_sameipotherport_stmt = Database::prepare("\n\t\t\t\t\tSELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`\n\t\t\t\t\tWHERE `ip` = :ip AND `id` <> :id");
         $result_sameipotherport = Database::pexecute_first($result_sameipotherport_stmt, array('ip' => $ip, 'id' => $id));
         if ((int) Settings::Get('system.use_ssl') == 1 && isset($_POST['ssl']) && $_POST['ssl'] != 0) {
             $ssl = 1;
             $ssl_cert_file = validate($_POST['ssl_cert_file'], 'ssl_cert_file');
             $ssl_key_file = validate($_POST['ssl_key_file'], 'ssl_key_file');
             $ssl_ca_file = validate($_POST['ssl_ca_file'], 'ssl_ca_file');
             $ssl_cert_chainfile = validate($_POST['ssl_cert_chainfile'], 'ssl_cert_chainfile');
         } else {
             $ssl = 0;
             $ssl_cert_file = '';
             $ssl_key_file = '';
             $ssl_ca_file = '';
             $ssl_cert_chainfile = '';
         }
         if ($listen_statement != '1') {
             $listen_statement = '0';
Ejemplo n.º 28
0
if ($page == 'overview') {
    $log->logAction(USR_ACTION, LOG_NOTICE, "viewed customer_index");
    $domain_stmt = Database::prepare("SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "`\n\t\tWHERE `customerid` = :customerid\n\t\tAND `parentdomainid` = '0'\n\t\tAND `id` <> :standardsubdomain\n\t");
    Database::pexecute($domain_stmt, array("customerid" => $userinfo['customerid'], "standardsubdomain" => $userinfo['standardsubdomain']));
    $domains = '';
    $domainArray = array();
    while ($row = $domain_stmt->fetch(PDO::FETCH_ASSOC)) {
        $domainArray[] = $idna_convert->decode($row['domain']);
    }
    natsort($domainArray);
    $domains = implode(',<br />', $domainArray);
    // standard-subdomain
    $stdsubdomain = '';
    if ($userinfo['standardsubdomain'] != '0') {
        $std_domain_stmt = Database::prepare("\n\t\t\tSELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "`\n\t\t\tWHERE `customerid` = :customerid\n\t\t\tAND `id` = :standardsubdomain\n\t\t");
        $std_domain = Database::pexecute_first($std_domain_stmt, array("customerid" => $userinfo['customerid'], "standardsubdomain" => $userinfo['standardsubdomain']));
        $stdsubdomain = $std_domain['domain'];
    }
    $userinfo['email'] = $idna_convert->decode($userinfo['email']);
    $yesterday = time() - 60 * 60 * 24;
    $month = date('M Y', $yesterday);
    $userinfo['diskspace'] = round($userinfo['diskspace'] / 1024, Settings::Get('panel.decimal_places'));
    $userinfo['diskspace_used'] = round($userinfo['diskspace_used'] / 1024, Settings::Get('panel.decimal_places'));
    $userinfo['traffic'] = round($userinfo['traffic'] / (1024 * 1024), Settings::Get('panel.decimal_places'));
    $userinfo['traffic_used'] = round($userinfo['traffic_used'] / (1024 * 1024), Settings::Get('panel.decimal_places'));
    $userinfo = str_replace_array('-1', $lng['customer']['unlimited'], $userinfo, 'diskspace traffic mysqls emails email_accounts email_forwarders email_quota ftps tickets subdomains');
    $services_enabled = "";
    $se = array();
    if ($userinfo['imap'] == '1') {
        $se[] = "IMAP";
    }
Ejemplo n.º 29
0
 $subtodomains = makeoption($lng['domains']['nosubtomaindomain'], 0, null, true);
 $result_domains_stmt = Database::prepare("\n\t\t\t\t\tSELECT `d`.`id`, `d`.`domain` FROM `" . TABLE_PANEL_DOMAINS . "` `d`, `" . TABLE_PANEL_CUSTOMERS . "` `c`\n\t\t\t\t\tWHERE `d`.`aliasdomain` IS NULL AND `d`.`parentdomainid` = '0' AND `d`.`id` <> :id\n\t\t\t\t\tAND `c`.`standardsubdomain`<>`d`.`id` AND `c`.`customerid`=`d`.`customerid`" . ($userinfo['customers_see_all'] ? '' : " AND `d`.`adminid` = :adminid") . "\n\t\t\t\t\tORDER BY `d`.`domain` ASC\n\t\t\t\t");
 $params = array('id' => $result['id']);
 if ($userinfo['customers_see_all'] == '0') {
     $params['adminid'] = $userinfo['adminid'];
 }
 Database::pexecute($result_domains_stmt, $params);
 while ($row_domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
     $subtodomains .= makeoption($idna_convert->decode($row_domain['domain']), $row_domain['id'], $result['ismainbutsubto']);
 }
 if ($userinfo['ip'] == "-1") {
     $result_ipsandports_stmt = Database::query("\n\t\t\t\t\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `ssl`='0' ORDER BY `ip`, `port` ASC\n\t\t\t\t\t");
     $result_ssl_ipsandports_stmt = Database::query("\n\t\t\t\t\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `ssl`='1' ORDER BY `ip`, `port` ASC\n\t\t\t\t\t");
 } else {
     $admin_ip_stmt = Database::prepare("\n\t\t\t\t\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid ORDER BY `ip`, `port` ASC\n\t\t\t\t\t");
     $admin_ip = Database::pexecute_first($admin_ip_stmt, array('ipid' => $userinfo['ip']));
     $result_ipsandports_stmt = Database::prepare("\n\t\t\t\t\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `ssl`='0' AND `ip` = :ipid ORDER BY `ip`, `port` ASC\n\t\t\t\t\t");
     Database::pexecute($result_ipsandports_stmt, array('ipid' => $admin_ip['ip']));
     $result_ssl_ipsandports_stmt = Database::prepare("\n\t\t\t\t\t\tSELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `ssl`='1' AND `ip` = :ipid ORDER BY `ip`, `port` ASC\n\t\t\t\t\t");
     Database::pexecute($result_ssl_ipsandports_stmt, array('ipid' => $admin_ip['ip']));
 }
 $ipsandports = array();
 while ($row_ipandport = $result_ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
     if (filter_var($row_ipandport['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
         $row_ipandport['ip'] = '[' . $row_ipandport['ip'] . ']';
     }
     $ipsandports[] = array('label' => $row_ipandport['ip'] . ':' . $row_ipandport['port'] . '<br />', 'value' => $row_ipandport['id']);
 }
 $ssl_ipsandports = array();
 while ($row_ssl_ipandport = $result_ssl_ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
     if (filter_var($row_ssl_ipandport['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
Ejemplo n.º 30
0
 }
 /**
  * Total Traffic
  */
 fwrite($debugHandler, 'total traffic for ' . $row['loginname'] . ' started' . "\n");
 $current_traffic = array();
 $current_traffic['http'] = floatval($httptraffic);
 $current_traffic['ftp_up'] = floatval($ftptraffic['up_bytes_sum'] / 1024);
 $current_traffic['ftp_down'] = floatval($ftptraffic['down_bytes_sum'] / 1024);
 $current_traffic['mail'] = floatval($mailtraffic);
 $current_traffic['all'] = $current_traffic['http'] + $current_traffic['ftp_up'] + $current_traffic['ftp_down'] + $current_traffic['mail'];
 $ins_data = array('customerid' => $row['customerid'], 'year' => date('Y', time()), 'month' => date('m', time()), 'day' => date('d', time()), 'stamp' => time(), 'http' => $current_traffic['http'], 'ftp_up' => $current_traffic['ftp_up'], 'ftp_down' => $current_traffic['ftp_down'], 'mail' => $current_traffic['mail']);
 $ins_stmt = Database::prepare("\n\t\tINSERT INTO `" . TABLE_PANEL_TRAFFIC . "` SET\n\t\t`customerid` = :customerid,\n\t\t`year` = :year,\n\t\t`month` = :month,\n\t\t`day` = :day,\n\t\t`stamp` = :stamp,\n\t\t`http` = :http,\n\t\t`ftp_up` = :ftp_up,\n\t\t`ftp_down` = :ftp_down,\n\t\t`mail` = :mail\n\t");
 Database::pexecute($ins_stmt, $ins_data);
 $sum_month_traffic_stmt = Database::prepare("\n\t\tSELECT SUM(`http`) AS `http`, SUM(`ftp_up`) AS `ftp_up`, SUM(`ftp_down`) AS `ftp_down`, SUM(`mail`) AS `mail`\n\t\tFROM `" . TABLE_PANEL_TRAFFIC . "` WHERE `year` = :year AND `month` = :month AND `customerid` = :customerid\n\t");
 $sum_month_traffic = Database::pexecute_first($sum_month_traffic_stmt, array('year' => date('Y', time()), 'month' => date('m', time()), 'customerid' => $row['customerid']));
 $sum_month_traffic['all'] = $sum_month_traffic['http'] + $sum_month_traffic['ftp_up'] + $sum_month_traffic['ftp_down'] + $sum_month_traffic['mail'];
 if (!isset($admin_traffic[$row['adminid']]) || !is_array($admin_traffic[$row['adminid']])) {
     $admin_traffic[$row['adminid']]['http'] = 0;
     $admin_traffic[$row['adminid']]['ftp_up'] = 0;
     $admin_traffic[$row['adminid']]['ftp_down'] = 0;
     $admin_traffic[$row['adminid']]['mail'] = 0;
     $admin_traffic[$row['adminid']]['all'] = 0;
     $admin_traffic[$row['adminid']]['sum_month'] = 0;
 }
 $admin_traffic[$row['adminid']]['http'] += $current_traffic['http'];
 $admin_traffic[$row['adminid']]['ftp_up'] += $current_traffic['ftp_up'];
 $admin_traffic[$row['adminid']]['ftp_down'] += $current_traffic['ftp_down'];
 $admin_traffic[$row['adminid']]['mail'] += $current_traffic['mail'];
 $admin_traffic[$row['adminid']]['all'] += $current_traffic['all'];
 $admin_traffic[$row['adminid']]['sum_month'] += $sum_month_traffic['all'];