/** * Check input data * @param EasySCP_TemplateEngine $tpl * @param int $alias_id */ function check_fwd_data($tpl, $alias_id) { $sql = EasySCP_Registry::get('Db'); $cfg = EasySCP_Registry::get('Config'); $forward_url = strtolower(clean_input($_POST['forward'])); // unset errors $ed_error = '_off_'; // NXW: Unused variable so... // $admin_login = ''; if (isset($_POST['status']) && $_POST['status'] == 1) { $forward_prefix = clean_input($_POST['forward_prefix']); if (substr_count($forward_url, '.') <= 2) { $ret = validates_dname($forward_url); } else { $ret = validates_dname($forward_url, true); } if (!$ret) { $ed_error = tr("Wrong domain part in forward URL!"); } else { $forward_url = encode_idna($forward_prefix . $forward_url); } $check_en = $cfg->HTML_CHECKED; $check_dis = ''; $tpl->assign(array('FORWARD' => tohtml($forward_url), 'HTTP_YES' => $forward_prefix === 'http://' ? $cfg->HTML_SELECTED : '', 'HTTPS_YES' => $forward_prefix === 'https://' ? $cfg->HTML_SELECTED : '', 'FTP_YES' => $forward_prefix === 'ftp://' ? $cfg->HTML_SELECTED : '', 'CHECK_EN' => $check_en, 'CHECK_DIS' => $check_dis, 'DISABLE_FORWARD' => '', 'READONLY_FORWARD' => '')); } else { $check_en = $cfg->HTML_CHECKED; $check_dis = ''; $forward_url = 'no'; $tpl->assign(array('READONLY_FORWARD' => $cfg->HTML_READONLY, 'DISABLE_FORWARD' => $cfg->HTML_DISABLED, 'CHECK_EN' => $check_en, 'CHECK_DIS' => $check_dis)); } if ($ed_error === '_off_') { $query = "\n\t\t\tUPDATE\n\t\t\t\t`domain_aliasses`\n\t\t\tSET\n\t\t\t\t`url_forward` = ?,\n\t\t\t\t`status` = ?\n\t\t\tWHERE\n\t\t\t\t`alias_id` = ?\n\t\t"; exec_query($sql, $query, array($forward_url, $cfg->ITEM_CHANGE_STATUS, $alias_id)); $query = "\n\t\t\tUPDATE\n\t\t\t\t`subdomain_alias`\n\t\t\tSET\n\t\t\t\t`status` = ?\n\t\t\tWHERE\n\t\t\t\t`alias_id` = ?\n\t\t"; exec_query($sql, $query, array($cfg->ITEM_CHANGE_STATUS, $alias_id)); send_request('110 DOMAIN alias ' . $alias_id); // NXW: oh my god... Should be review... /* $admin_login = $_SESSION['user_logged']; write_log("$admin_login: changes domain alias forward: " . $rs->fields['t1.alias_name']); */ unset($_SESSION['edit_ID']); $tpl->assign('MESSAGE', ""); return true; } else { $tpl->assign('MESSAGE', $ed_error); return false; } }
/** * Check correction of entered users data */ function check_user_data() { global $dmn_name; // domain name global $dmn_expire; // Domain expire date global $dmn_chp; // choosed hosting plan global $dmn_pt; global $validation_err_msg; $sql = EasySCP_Registry::get('Db'); $cfg = EasySCP_Registry::get('Config'); // personal template $event_txt = ''; if (isset($_POST['dmn_name'])) { $dmn_name = strtolower(trim($_POST['dmn_name'])); } if (isset($_POST['dmn_expire_date'])) { $dmn_expire = clean_input($_POST['dmn_expire_date']); } if (isset($_POST['dmn_tpl'])) { $dmn_chp = $_POST['dmn_tpl']; } if (isset($_POST['chtpl'])) { $dmn_pt = $_POST['chtpl']; } // Check if input string is a valid domain names if (!validates_dname($dmn_name)) { set_page_message($validation_err_msg, 'warning'); return false; } // Should be perfomed after domain names syntax validation now $dmn_name = encode_idna($dmn_name); if (easyscp_domain_exists($dmn_name, $_SESSION['user_id'])) { $event_txt = tr('Domain with that name already exists on the system!'); } else { if ($dmn_name == $cfg->BASE_SERVER_VHOST) { $event_txt = tr('Master domain cannot be used!'); } } // we have plans only for admins if (isset($cfg->HOSTING_PLANS_LEVEL) && $cfg->HOSTING_PLANS_LEVEL === 'admin') { $dmn_pt = '_no_'; } if (!empty($event_txt)) { // There are wrong input data set_page_message($event_txt, 'error'); return false; } else { if ($dmn_pt == '_yes_' || !isset($_POST['dmn_tpl'])) { // send through the session the data $_SESSION['dmn_name'] = $dmn_name; $_SESSION['dmn_expire_date'] = $dmn_expire; $_SESSION['dmn_tpl'] = $dmn_chp; $_SESSION['chtpl'] = $dmn_pt; $_SESSION['step_one'] = "_yes_"; user_goto('user_add2.php'); } else { // check if reseller limits are not touched $ehp_error = ''; // fill dummy to satisfy warning... if (reseller_limits_check($sql, $ehp_error, $_SESSION['user_id'], $dmn_chp)) { // send through the session the data $_SESSION['dmn_name'] = $dmn_name; $_SESSION['dmn_expire_date'] = $dmn_expire; $_SESSION['dmn_tpl'] = $dmn_chp; $_SESSION['chtpl'] = $dmn_pt; $_SESSION['step_one'] = "_yes_"; user_goto('user_add3.php'); } else { set_page_message(tr("Hosting plan values exceed reseller maximum values!"), 'warning'); return false; } } } }
/** * Save data for new user in db */ function add_user_data($reseller_id) { global $hpid, $dmn_name, $dmn_expire, $dmn_user_name, $admin_login, $user_email, $customer_id, $first_name, $last_name, $gender, $firm, $zip, $city, $state, $country, $street_one, $street_two, $phone, $fax, $inpass, $domain_ip, $dns, $backup, $countbackup; $sql = EasySCP_Registry::get('Db'); $cfg = EasySCP_Registry::get('Config'); // Let's get Desired Hosting Plan Data; $err_msg = ''; if (!empty($err_msg)) { set_page_message($err_msg, 'error'); return false; } if (isset($_SESSION["ch_hpprops"])) { $props = $_SESSION["ch_hpprops"]; unset($_SESSION["ch_hpprops"]); } else { if (isset($cfg->HOSTING_PLANS_LEVEL) && $cfg->HOSTING_PLANS_LEVEL === 'admin') { $query = 'SELECT `props` FROM `hosting_plans` WHERE `id` = ?'; $res = exec_query($sql, $query, $hpid); } else { $query = "SELECT `props` FROM `hosting_plans` WHERE `reseller_id` = ? AND `id` = ?"; $res = exec_query($sql, $query, array($reseller_id, $hpid)); } $data = $res->fetchRow(); $props = unserialize($data['props']); } $php = $props['allow_php']; $phpe = $props['allow_php_editor']; $cgi = $props['allow_cgi']; $sub = $props['subdomain_cnt']; $als = $props['alias_cnt']; $mail = $props['mail_cnt']; $ftp = $props['ftp_cnt']; $sql_db = $props['db_cnt']; $sql_user = $props['sqluser_cnt']; $traff = $props['traffic']; $disk = $props['disk']; $backup = $props['allow_backup']; $countbackup = $props['disk_countbackup']; $dns = $props['allow_dns']; $ssl = $props['allow_ssl']; $php = preg_replace("/\\_/", "", $php); $phpe = preg_replace("/\\_/", "", $phpe); $cgi = preg_replace("/\\_/", "", $cgi); $ssl = preg_replace("/\\_/", "", $ssl); $backup = preg_replace("/\\_/", "", $backup); $countbackup = preg_replace("/\\_/", "", $countbackup); $dns = preg_replace("/\\_/", "", $dns); $pure_user_pass = $inpass; $inpass = crypt_user_pass($inpass); $first_name = clean_input($first_name); $last_name = clean_input($last_name); $firm = clean_input($firm); $zip = clean_input($zip); $city = clean_input($city); $state = clean_input($state); $country = clean_input($country); $phone = clean_input($phone); $fax = clean_input($fax); $street_one = clean_input($street_one); $street_two = clean_input($street_two); $customer_id = clean_input($customer_id); if (!validates_dname(decode_idna($dmn_user_name))) { return; } $query = "\n\t\tINSERT INTO `admin` (\n\t\t\t`admin_name`, `admin_pass`, `admin_type`, `domain_created`,\n\t\t\t`created_by`, `fname`, `lname`,\n\t\t\t`firm`, `zip`, `city`, `state`,\n\t\t\t`country`, `email`, `phone`,\n\t\t\t`fax`, `street1`, `street2`,\n\t\t\t`customer_id`, `gender`\n\t\t)\n\t\tVALUES (\n\t\t\t?, ?, 'user', unix_timestamp(),\n\t\t\t?, ?, ?,\n\t\t\t?, ?, ?, ?,\n\t\t\t?, ?, ?,\n\t\t\t?, ?, ?,\n\t\t\t?, ?\n\t\t)\n\t"; exec_query($sql, $query, array($dmn_user_name, $inpass, $reseller_id, $first_name, $last_name, $firm, $zip, $city, $state, $country, $user_email, $phone, $fax, $street_one, $street_two, $customer_id, $gender)); print $sql->errorMsg(); $record_id = $sql->insertId(); $query = "\n\t\tINSERT INTO `domain` (\n\t\t\t`domain_name`, `domain_admin_id`,\n\t\t\t`domain_created_id`, `domain_created`, `domain_expires`,\n\t\t\t`domain_mailacc_limit`, `domain_ftpacc_limit`,\n\t\t\t`domain_traffic_limit`, `domain_sqld_limit`,\n\t\t\t`domain_sqlu_limit`, `status`,\n\t\t\t`domain_subd_limit`, `domain_alias_limit`,\n\t\t\t`domain_ip_id`, `domain_disk_limit`,\n\t\t\t`domain_disk_usage`, `domain_php`, `domain_php_edit`, `domain_cgi`,\n\t\t\t`allowbackup`, `domain_dns`, `domain_ssl`, `domain_disk_countbackup`\n\t\t)\n\t\tVALUES (\n\t\t\t:domain_name, :domain_admin_id,\n\t\t\t:domain_created_id, unix_timestamp(), :domain_expires,\n\t\t\t:domain_mailacc_limit, :domain_ftpacc_limit,\n\t\t\t:domain_traffic_limit, :domain_sqld_limit,\n\t\t\t:domain_sqlu_limit, :status,\n\t\t\t:domain_subd_limit, :domain_alias_limit,\n\t\t\t:domain_ip_id, :domain_disk_limit,\n\t\t\t'0', :domain_php, :domain_php_edit, :domain_cgi,\n\t\t\t:allowbackup, :domain_dns, :domain_ssl, :domain_disk_countbackup\n\t\t)\n\t"; $param = array(':domain_name' => $dmn_name, ':domain_admin_id' => $record_id, ':domain_created_id' => $reseller_id, ':domain_expires' => $dmn_expire, ':domain_mailacc_limit' => $mail, ':domain_ftpacc_limit' => $ftp, ':domain_traffic_limit' => $traff, ':domain_sqld_limit' => $sql_db, ':domain_sqlu_limit' => $sql_user, ':status' => $cfg->ITEM_ADD_STATUS, ':domain_subd_limit' => $sub, ':domain_alias_limit' => $als, ':domain_ip_id' => $domain_ip, ':domain_disk_limit' => $disk, ':domain_php' => $php, ':domain_php_edit' => $phpe, ':domain_cgi' => $cgi, ':allowbackup' => $backup, ':domain_dns' => $dns, ':domain_ssl' => $ssl, ':domain_disk_countbackup' => $countbackup); DB::prepare($query); DB::execute($param); $dmn_id = DB::getInstance()->lastInsertId(); // AddDefaultDNSEntries($dmn_id, 0, $dmn_name, $domain_ip); // TODO: Check if max user and group id is reached // update domain and gid $domain_gid = $cfg->APACHE_SUEXEC_MIN_GID + $dmn_id; $domain_uid = $cfg->APACHE_SUEXEC_MIN_UID + $dmn_id; $query = "\n\t\tUPDATE `domain`\n\t\tSET `domain_gid`=?,\n\t\t\t`domain_uid`=?\n\t\tWHERE `domain_id`=?\n\t"; exec_query($sql, $query, array($domain_gid, $domain_uid, $dmn_id)); // Add statistics group $query = "\n\t\tINSERT INTO `htaccess_users`\n\t\t\t(`dmn_id`, `uname`, `upass`, `status`)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?)\n\t"; exec_query($sql, $query, array($dmn_id, $dmn_name, crypt_user_pass_with_salt($pure_user_pass), $cfg->ITEM_ADD_STATUS)); $user_id = $sql->insertId(); $query = "\n\t\tINSERT INTO `htaccess_groups`\n\t\t\t(`dmn_id`, `ugroup`, `members`, `status`)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?)\n\t"; exec_query($sql, $query, array($dmn_id, $cfg->AWSTATS_GROUP_AUTH, $user_id, $cfg->ITEM_ADD_STATUS)); // Create the 3 default addresses if wanted if ($cfg->CREATE_DEFAULT_EMAIL_ADDRESSES) { client_mail_add_default_accounts($dmn_id, $user_email, $dmn_name); // 'domain', 0 } // let's send mail to user send_add_user_auto_msg($reseller_id, $dmn_user_name, $pure_user_pass, $user_email, $first_name, $last_name, tr('Domain account')); // $user_def_lang = $cfg->USER_INITIAL_LANG; $user_def_lang = ''; // $user_theme_color = $cfg->USER_INITIAL_THEME; $user_theme_color = ''; $query = "\n\t\tINSERT INTO `user_gui_props`\n\t\t\t(`user_id`, `lang`, `layout`)\n\t\tVALUES\n\t\t\t(?, ?, ?)\n\t"; exec_query($sql, $query, array($record_id, $user_def_lang, $user_theme_color)); // send request to daemon // TODO Prüfen, da es hier zu einem Fehler kommt ("Domain data has been altered. Please enter again.") send_request('110 DOMAIN domain ' . $dmn_id); send_request('130 MAIL ' . $dmn_id); $admin_login = $_SESSION['user_logged']; write_log("{$admin_login}: add user: {$dmn_user_name} (for domain {$dmn_name})"); write_log("{$admin_login}: add domain: {$dmn_name}"); update_reseller_c_props($reseller_id); if (isset($_POST['add_alias']) && $_POST['add_alias'] === 'on') { // we have to add some aliases for this looser $_SESSION['dmn_id'] = $dmn_id; $_SESSION['dmn_ip'] = $domain_ip; $_SESSION['user_add3_add_alias'] = "_yes_"; user_goto('user_add4.php?accout=' . $dmn_id); } else { // we have not to add alias $_SESSION['user_add3_added'] = "_yes_"; user_goto('users.php?psi=last'); } }
/** * * @global <type> $cr_user_id * @global <type> $alias_name * @global <type> $domain_ip * @global <type> $forward * @global <type> $forward_prefix * @global <type> $mount_point * @global <type> $validation_err_msg * @param <type> $err_al * @return <type> */ function add_domain_alias(&$err_al) { global $cr_user_id, $alias_name, $domain_ip, $forward, $forward_prefix, $mount_point, $validation_err_msg; $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); $cr_user_id = $dmn_id = $_SESSION['dmn_id']; $alias_name = strtolower(clean_input($_POST['ndomain_name'])); $domain_ip = $_SESSION['dmn_ip']; $mount_point = array_encode_idna(strtolower($_POST['ndomain_mpoint']), true); if ($_POST['status'] == 1) { $forward = encode_idna(strtolower(clean_input($_POST['forward']))); $forward_prefix = clean_input($_POST['forward_prefix']); } else { $forward = 'no'; $forward_prefix = ''; } // Check if input string is a valid domain names if (!validates_dname($alias_name)) { set_page_message($validation_err_msg, 'warning'); return; } // Should be perfomed after domain names syntax validation now $alias_name = encode_idna($alias_name); if (easyscp_domain_exists($alias_name, $_SESSION['user_id'])) { $err_al = tr('Domain with that name already exists on the system!'); } else { if (!validates_mpoint($mount_point) && $mount_point != '/') { $err_al = tr("Incorrect mount point syntax"); } else { if ($_POST['status'] == 1) { $aurl = @parse_url($forward_prefix . decode_idna($forward)); if ($aurl === false) { $err_al = tr("Wrong address in forward URL!"); } else { $domain = $aurl['host']; if (substr_count($domain, '.') <= 2) { $ret = validates_dname($domain); } else { $ret = validates_dname($domain, true); } if (!$ret) { $err_al = tr("Wrong domain part in forward URL!"); } else { $domain = encode_idna($aurl['host']); $forward = $aurl['scheme'] . '://'; if (isset($aurl['user'])) { $forward .= $aurl['user'] . (isset($aurl['pass']) ? ':' . $aurl['pass'] : '') . '@'; } $forward .= $domain; if (isset($aurl['port'])) { $forward .= ':' . $aurl['port']; } if (isset($aurl['path'])) { $forward .= $aurl['path']; } else { $forward .= '/'; } if (isset($aurl['query'])) { $forward .= '?' . $aurl['query']; } if (isset($aurl['fragment'])) { $forward .= '#' . $aurl['fragment']; } } } } else { $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain_aliasses`\n\t\t\tWHERE\n\t\t\t\t`alias_name` = ?\n\t\t;"; $res = exec_query($sql, $query, $alias_name); $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain`\n\t\t\tWHERE\n\t\t\t\t`domain_name` = ?\n\t\t;"; $res2 = exec_query($sql, $query, $alias_name); if ($res->rowCount() > 0 || $res2->rowCount() > 0) { // we already have a domain with this name $err_al = tr("Domain with this name already exist"); } if (mount_point_exists($dmn_id, $mount_point)) { $err_al = tr('Mount point already in use!'); } } } } if ('_off_' !== $err_al) { set_page_message($err_al, 'error'); return; } // Begin add new alias domain $query = "\n\t\tINSERT INTO\n\t\t\t`domain_aliasses` (\n\t\t\t\t`domain_id`, `alias_name`, `alias_mount`, `status`,\n\t\t\t\t`alias_ip_id`, `url_forward`\n\t\t\t)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?, ?, ?)\n\t;"; exec_query($sql, $query, array($cr_user_id, $alias_name, $mount_point, $cfg->ITEM_ADD_STATUS, $domain_ip, $forward)); $alias_id = $sql->insertId(); update_reseller_c_props(get_reseller_id($cr_user_id)); send_request('110 DOMAIN alias ' . $alias_id); $admin_login = $_SESSION['user_logged']; write_log("{$admin_login}: add domain alias: {$alias_name}"); $_SESSION['alias_added_succesfully'] = 1; user_goto('user_add4.php?accout=' . $cr_user_id); }
/** * Check input data * @param EasySCP_TemplateEngine $tpl * @param EasySCP_Database $sql * @param int $subdomain_id * @param string $dmn_type */ function check_fwd_data($tpl, $sql, $subdomain_id, $dmn_type, $dmn_id) { $forward_url = clean_input($_POST['forward']); // unset errors $ed_error = '_off_'; if (isset($_POST['status']) && $_POST['status'] == 1) { $forward_prefix = clean_input($_POST['forward_prefix']); $surl = @parse_url($forward_prefix . decode_idna($forward_url)); $domain = $surl['host']; if (substr_count($domain, '.') <= 2) { $ret = validates_dname($domain); } else { $ret = validates_dname($domain, true); } if (!$ret) { $ed_error = tr('Wrong domain part in forward URL!'); } else { $forward_url = encode_idna($forward_prefix . $forward_url); } $check_en = 'checked="checked"'; $check_dis = ''; $tpl->assign(array('FORWARD' => $forward_url, 'HTTP_YES' => $forward_prefix === 'http://' ? 'selected="selected"' : '', 'HTTPS_YES' => $forward_prefix === 'https://' ? 'selected="selected"' : '', 'FTP_YES' => $forward_prefix === 'ftp://' ? 'selected="selected"' : '', 'CHECK_EN' => $check_en, 'CHECK_DIS' => $check_dis)); } else { $check_en = ''; $check_dis = 'checked="checked"'; $forward_url = 'no'; $tpl->assign(array('READONLY_FORWARD' => ' readonly', 'DISABLE_FORWARD' => ' disabled="disabled"', 'CHECK_EN' => $check_en, 'CHECK_DIS' => $check_dis)); } if ($ed_error === '_off_') { if ($dmn_type === 'dmn') { $subdomainQuery = ' UPDATE `subdomain` SET `subdomain_url_forward` = ?, `status` = ? WHERE `subdomain_id` = ? '; $domainQuery = ' UPDATE domain SET status = ? where domain_id = ? '; } else { $subdomainQuery = ' UPDATE `subdomain_alias` SET `subdomain_alias_url_forward` = ?, `status` = ? WHERE `subdomain_alias_id` = ? '; $domainQuery = ' UPDATE domain_aliasses SET status = ? where alias_id = ? '; } exec_query($sql, $subdomainQuery, array($forward_url, EasySCP_Registry::get('Config')->ITEM_CHANGE_STATUS, $subdomain_id)); exec_query($sql, $domainQuery, array(EasySCP_Registry::get('Config')->ITEM_CHANGE_STATUS, $dmn_id)); if ($_POST['dmn_type'] == 'als') { send_request('110 DOMAIN alias ' . $dmn_id); } else { send_request('110 DOMAIN domain ' . $dmn_id); } $admin_login = $_SESSION['user_logged']; write_log("{$admin_login}: change domain alias forward: " . $subdomain_id); unset($_SESSION['edit_ID']); $tpl->assign('MESSAGE', ''); return true; } else { $tpl->assign('MESSAGE', $ed_error); return false; } }
/** * @global <type> $validation_err_msg * @param $err_sub * @param int $user_id * @param $dmn_name * @return void <type> */ function check_subdomain_data(&$err_sub, $user_id, $dmn_name) { global $validation_err_msg; $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); // $vfs = new EasySCP_VirtualFileSystem($dmn_name, $sql); $dmn_id = $domain_id = get_user_domain_id($user_id); if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_subd') { if (empty($_POST['subdomain_name'])) { $err_sub = tr('Please specify subdomain name!'); return; } $sub_name = strtolower($_POST['subdomain_name']); if ($_POST['status'] == 1) { $forward = clean_input($_POST['forward']); $forward_prefix = clean_input($_POST['forward_prefix']); } else { $forward = 'no'; $forward_prefix = ''; } // Should be perfomed after domain names syntax validation now //$sub_name = encode_idna($sub_name); if (isset($_POST['subdomain_mnt_pt']) && $_POST['subdomain_mnt_pt'] !== '') { $sub_mnt_pt = array_encode_idna(strtolower($_POST['subdomain_mnt_pt']), true); } else { $sub_mnt_pt = "/"; } if ($_POST['dmn_type'] === 'als') { if (!isset($_POST['als_id'])) { $err_sub = tr('No valid alias domain selected!'); return; } // $query_alias = " // SELECT // `alias_mount` // FROM // `domain_aliasses` // WHERE // `alias_id` = ? // ;"; // // $rs = exec_query($sql, $query_alias, $_POST['als_id']); // // $als_mnt = $rs->fields['alias_mount']; $query_dmn = "\n\t\t\t\tSELECT\n\t\t\t\t\tdomain_name\n\t\t\t\tFROM \n\t\t\t\t\tdomain_aliasses,\n\t\t\t\t\tdomain\n\t\t\t\tWHERE\n\t\t\t\t\tdomain_aliasses.domain_id = domain.domain_id\n\t\t\t\tAND\n\t\t\t\t\talias_id = ?\n\t\t\t"; $dmn_rs = exec_query($sql, $query_dmn, $_POST['als_id']); $master_dmn_name = $dmn_rs->fields['domain_name']; if ($sub_mnt_pt[0] != '/') { $sub_mnt_pt = '/' . $sub_mnt_pt; } // $sub_mnt_pt = $als_mnt.$sub_mnt_pt; $sub_mnt_pt = str_replace('//', '/', $sub_mnt_pt); $domain_id = $_POST['als_id']; $sub_mnt_path = $cfg->APACHE_WWW_DIR . '/' . $master_dmn_name . $sub_mnt_pt; } else { $sub_mnt_path = $cfg->APACHE_WWW_DIR . '/' . $dmn_name . $sub_mnt_pt; } // First check if input string is a valid domain names if (!validates_subdname($sub_name, decode_idna($dmn_name))) { $err_sub = $validation_err_msg; return; } // Should be perfomed after domain names syntax validation now $sub_name = encode_idna($sub_name); if (subdmn_exists($user_id, $domain_id, $sub_name)) { $err_sub = tr('Subdomain already exists or is not allowed!'); } elseif ($_POST['dmn_type'] != 'als' && mount_point_exists($dmn_id, array_encode_idna($sub_mnt_pt, true))) { $err_sub = tr('Mount point already in use!'); } elseif ($_POST['dmn_type'] != 'als' && send_request('160 SYSTEM direxists ' . array_encode_idna($sub_mnt_path, true))) { $err_sub = tr("Can't use an existing folder as mount point!"); // }elseif ($vfs->exists($sub_mnt_pt)) { // $err_sub = tr("Can't use an existing folder as mount point!"); } elseif ($_POST['dmn_type'] != 'als' && !validates_mpoint($sub_mnt_pt)) { $err_sub = tr('Incorrect mount point syntax!'); } elseif ($_POST['status'] == 1) { $surl = @parse_url($forward_prefix . decode_idna($forward)); if ($surl === false) { $err_sub = tr('Wrong domain part in forward URL!'); } else { $domain = $surl['host']; if (substr_count($domain, '.') <= 2) { $ret = validates_dname($domain); } else { $ret = validates_dname($domain, true); } if (!$ret) { $err_sub = tr('Wrong domain part in forward URL!'); } else { $domain = encode_idna($surl['host']); $forward = $surl['scheme'] . '://'; if (isset($surl['user'])) { $forward .= $surl['user'] . (isset($surl['pass']) ? ':' . $surl['pass'] : '') . '@'; } $forward .= $domain; if (isset($surl['port'])) { $forward .= ':' . $surl['port']; } if (isset($surl['path'])) { $forward .= $surl['path']; } else { $forward .= '/'; } if (isset($surl['query'])) { $forward .= '?' . $surl['query']; } if (isset($surl['fragment'])) { $forward .= '#' . $surl['fragment']; } } } } else { // now let's fix the mountpoint $sub_mnt_pt = array_encode_idna($sub_mnt_pt, true); } if ('_off_' !== $err_sub) { return; } $subdomain_id = $_POST['subdmn_id']; subdomain_schedule($user_id, $domain_id, $sub_name, $sub_mnt_pt, $forward, $subdomain_id); set_page_message(tr('Subdomain scheduled for addition!'), 'success'); user_goto('domains_manage.php'); } }
/** * * @global <type> $cr_user_id * @global <type> $alias_name * @global <type> $domain_ip * @global <type> $forward * @global <type> $forward_prefix * @global <type> $mount_point * @global <type> $validation_err_msg * @param <type> $err_al * @return <type> */ function add_domain_alias(&$err_al) { global $cr_user_id, $alias_name, $domain_ip, $forward, $forward_prefix, $mount_point, $validation_err_msg; $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); $cr_user_id = $_POST['usraccounts']; $alias_name = strtolower($_POST['ndomain_name']); $mount_point = array_encode_idna(strtolower($_POST['ndomain_mpoint']), true); if ($_POST['status'] == 1) { $forward = encode_idna(strtolower(clean_input($_POST['forward']))); $forward_prefix = clean_input($_POST['forward_prefix']); } else { $forward = 'no'; $forward_prefix = ''; } $query = "\n\t\tSELECT\n\t\t\t`domain_ip_id`\n\t\tFROM\n\t\t\t`domain`\n\t\tWHERE\n\t\t\t`domain_id` = ?\n\t;"; $rs = exec_query($sql, $query, $cr_user_id); $domain_ip = $rs->fields['domain_ip_id']; // First check if input string is a valid domain names if (!validates_dname($alias_name)) { $err_al = $validation_err_msg; return; } // Should be perfomed after domain names syntax validation now $alias_name = encode_idna($alias_name); if (easyscp_domain_exists($alias_name, $_SESSION['user_id'])) { $err_al = tr('Domain with that name already exists on the system!'); // } else if (!validates_mpoint($mount_point) && $mount_point != '/') { // $err_al = tr("Incorrect mount point syntax"); } else { if ($alias_name == $cfg->BASE_SERVER_VHOST) { $err_al = tr('Master domain cannot be used!'); } else { if ($_POST['status'] == 1) { $aurl = @parse_url($forward_prefix . decode_idna($forward)); if ($aurl === false) { $err_al = tr("Wrong address in forward URL!"); } else { $domain = $aurl['host']; if (substr_count($domain, '.') <= 2) { $ret = validates_dname($domain); } else { $ret = validates_dname($domain, true); } if (!$ret) { $err_al = tr("Wrong domain part in forward URL!"); } else { $domain = encode_idna($aurl['host']); $forward = $aurl['scheme'] . '://'; if (isset($aurl['user'])) { $forward .= $aurl['user'] . (isset($aurl['pass']) ? ':' . $aurl['pass'] : '') . '@'; } $forward .= $domain; if (isset($aurl['port'])) { $forward .= ':' . $aurl['port']; } if (isset($aurl['path'])) { $forward .= $aurl['path']; } else { $forward .= '/'; } if (isset($aurl['query'])) { $forward .= '?' . $aurl['query']; } if (isset($aurl['fragment'])) { $forward .= '#' . $aurl['fragment']; } } } } else { $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain_aliasses`\n\t\t\tWHERE\n\t\t\t\t`alias_name` = ?\n\t\t;"; $res = exec_query($sql, $query, $alias_name); $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain`\n\t\t\tWHERE\n\t\t\t\t`domain_name` = ?\n\t\t;"; $res2 = exec_query($sql, $query, $alias_name); if ($res->rowCount() > 0 || $res2->rowCount() > 0) { // we already have domain with this name $err_al = tr("Domain with this name already exist"); } $query = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(`subdomain_id`) AS cnt\n\t\t\tFROM\n\t\t\t\t`subdomain`\n\t\t\tWHERE\n\t\t\t\t\t`domain_id` = ?\n\t\t\t\tAND `subdomain_mount` = ?\n\t\t\t;"; $subdomres = exec_query($sql, $query, array($cr_user_id, $mount_point)); $subdomdata = $subdomres->fetchRow(); $query = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(`subdomain_alias_id`) AS alscnt\n\t\t\tFROM\n\t\t\t\t`subdomain_alias`\n\t\t\tWHERE\n\t\t\t\t\t`alias_id`\n\t\t\t\tIN (\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`alias_id`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`domain_aliasses`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`domain_id` = ?\n\t\t\t\t\t)\n\t\t\t\tAND\n\t\t\t\t\t`subdomain_alias_mount` = ?\n\t\t;"; $alssubdomres = exec_query($sql, $query, array($cr_user_id, $mount_point)); $alssubdomdata = $alssubdomres->fetchRow(); if ($subdomdata['cnt'] > 0 || $alssubdomdata['alscnt'] > 0) { $err_al = tr("There is a subdomain with the same mount point!"); } } } } if ('_off_' !== $err_al) { return; } // Begin add new alias domain $alias_name = htmlspecialchars($alias_name, ENT_QUOTES, "UTF-8"); $query = "\n\t\tINSERT INTO\n\t\t\t`domain_aliasses` (\n\t\t\t\t`domain_id`, `alias_name`, `alias_mount`, `status`,\n\t\t\t\t`alias_ip_id`, `url_forward`\n\t\t\t)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?, ?, ?)\n\t;"; exec_query($sql, $query, array($cr_user_id, $alias_name, $mount_point, $cfg->ITEM_ADD_STATUS, $domain_ip, $forward)); $als_id = $sql->insertId(); update_reseller_c_props(get_reseller_id($cr_user_id)); $query = "\n\t\tSELECT\n\t\t\t`email`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_id` = ?\n\t\tLIMIT 1\n\t;"; $rs = exec_query($sql, $query, who_owns_this($cr_user_id, 'dmn_id')); $user_email = $rs->fields['email']; // Create the three default addresses if required if ($cfg->CREATE_DEFAULT_EMAIL_ADDRESSES) { client_mail_add_default_accounts($cr_user_id, $user_email, $alias_name, 'alias', $als_id); } send_request('110 DOMAIN alias ' . $als_id); $admin_login = $_SESSION['user_logged']; write_log("{$admin_login}: add domain alias: {$alias_name}"); $_SESSION["aladd"] = '_yes_'; user_goto('alias.php'); }
/** * * @global <type> $cr_user_id * @global <type> $alias_name * @global <type> $domain_ip * @global <type> $forward * @global <type> $forward_prefix * @global <type> $mount_point * @global <type> $validation_err_msg * @param <type> $err_al * @return <type> */ function add_domain_alias(&$err_al) { global $cr_user_id, $alias_name, $domain_ip, $forward, $forward_prefix, $mount_point, $validation_err_msg; $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); $cr_user_id = get_user_domain_id($_SESSION['user_id']); $alias_name = strtolower($_POST['ndomain_name']); // $mount_point = array_encode_idna(strtolower($_POST['ndomain_mpoint']), true); if ($_POST['status'] == 1) { $forward = encode_idna(strtolower(clean_input($_POST['forward']))); $forward_prefix = clean_input($_POST['forward_prefix']); } else { $forward = 'no'; $forward_prefix = ''; } $query = "\n\t\tSELECT\n\t\t\t`domain_ip_id`\n\t\tFROM\n\t\t\t`domain`\n\t\tWHERE\n\t\t\t`domain_id` = ?\n\t"; $rs = exec_query($sql, $query, $cr_user_id); $domain_ip = $rs->fields['domain_ip_id']; // First check if input string is a valid domain names if (!validates_dname($alias_name)) { $err_al = $validation_err_msg; return; } // Should be perfomed after domain names syntax validation now $alias_name = encode_idna($alias_name); if (easyscp_domain_exists($alias_name, 0)) { $err_al = tr('Domain with that name already exists on the system!'); // } else if (!validates_mpoint($mount_point) && $mount_point != '/') { // $err_al = tr("Incorrect mount point syntax"); } else { if ($alias_name == $cfg->BASE_SERVER_VHOST) { $err_al = tr('Master domain cannot be used!'); } else { if ($_POST['status'] == 1) { $aurl = @parse_url($forward_prefix . decode_idna($forward)); if ($aurl === false) { $err_al = tr("Wrong address in forward URL!"); } else { $domain = $aurl['host']; if (substr_count($domain, '.') <= 2) { $ret = validates_dname($domain); } else { $ret = validates_dname($domain, true); } if (!$ret) { $err_al = tr("Wrong domain part in forward URL!"); } else { $domain = encode_idna($aurl['host']); $forward = $aurl['scheme'] . '://'; if (isset($aurl['user'])) { $forward .= $aurl['user'] . (isset($aurl['pass']) ? ':' . $aurl['pass'] : '') . '@'; } $forward .= $domain; if (isset($aurl['port'])) { $forward .= ':' . $aurl['port']; } if (isset($aurl['path'])) { $forward .= $aurl['path']; } else { $forward .= '/'; } if (isset($aurl['query'])) { $forward .= '?' . $aurl['query']; } if (isset($aurl['fragment'])) { $forward .= '#' . $aurl['fragment']; } } } } else { $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain_aliasses`\n\t\t\tWHERE\n\t\t\t\t`alias_name` = ?\n\t\t;"; $res = exec_query($sql, $query, $alias_name); $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain`\n\t\t\tWHERE\n\t\t\t\t`domain_name` = ?\n\t\t;"; $res2 = exec_query($sql, $query, $alias_name); if ($res->rowCount() > 0 || $res2->rowCount() > 0) { // we already have domain with this name $err_al = tr("Domain with this name already exist"); } // $query = " // SELECT // COUNT(`subdomain_id`) AS cnt // FROM // `subdomain` // WHERE // `domain_id` = ? // AND // `subdomain_mount` = ? // ;"; // $subdomres = exec_query($sql, $query, array($cr_user_id, $mount_point)); // $subdomdata = $subdomres->fetchRow(); // // $query = " // SELECT // COUNT(`subdomain_alias_id`) AS alscnt // FROM // `subdomain_alias` // WHERE // `alias_id` // IN ( // SELECT // `alias_id` // FROM // `domain_aliasses` // WHERE // `domain_id` = ? // ) // AND // `subdomain_alias_mount` = ? // ;"; // $alssubdomres = exec_query($sql, $query, array($cr_user_id, $mount_point)); // $alssubdomdata = $alssubdomres->fetchRow(); // // if ($subdomdata['cnt'] > 0 || $alssubdomdata['alscnt'] > 0) { // $err_al = tr("There is a subdomain with the same mount point!"); // } } } } if ('_off_' !== $err_al) { return; } // Begin add new alias domain $status = $cfg->ITEM_ORDERED_STATUS; $query = "\n\t\tINSERT INTO\n\t\t\t`domain_aliasses` (\n\t\t\t\t`domain_id`, `alias_name`, `alias_mount`, `status`,\n\t\t\t\t`alias_ip_id`, `url_forward`\n\t\t\t)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?, ?, ?)\n\t;"; exec_query($sql, $query, array($cr_user_id, $alias_name, $mount_point, $status, $domain_ip, $forward)); $dmn_id = $sql->insertId(); AddDefaultDNSEntries(0, $dmn_id, $alias_name, $domain_ip); update_reseller_c_props(get_reseller_id($cr_user_id)); $admin_login = $_SESSION['user_logged']; if ($status == $cfg->ITEM_ORDERED_STATUS) { // notify the reseller: send_alias_order_email($alias_name); write_log("{$admin_login}: add domain alias for activation: {$alias_name}."); set_page_message(tr('Alias scheduled for activation!'), 'success'); } else { // TODO: Check // send_request('110 DOMAIN alias '.$dmn_id); write_log("{$admin_login}: domain alias scheduled for addition: {$alias_name}."); set_page_message(tr('Alias scheduled for addition!'), 'success'); } user_goto('domains_manage.php'); }