/** * * @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); }
/** * @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'); } }