function check_subdomain_data(&$tpl, &$sql, $user_id) { $domain_id = get_user_domain_id($sql, $user_id); if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_subd') { if ($_POST['subdomain_name'] === '') { set_page_message(tr('Please specify subdomain name!')); return; } $sub_name = strtolower($_POST['subdomain_name']); $sub_name = get_punny($sub_name); if (isset($_POST['subdomain_mnt_pt']) && $_POST['subdomain_mnt_pt'] !== '') { $sub_mnt_pt = strtolower($_POST['subdomain_mnt_pt']); $sub_mnt_pt = decode_idna($sub_mnt_pt); } if (subdmn_exists($sql, $user_id, $domain_id, $sub_name) > 0) { set_page_message(tr('Subdomain already exists!')); } else { if (chk_subdname($sub_name . "." . $_SESSION['user_logged']) > 0) { set_page_message(tr('Wrong subdomain syntax!')); } else { if (subdmn_mnt_pt_exists($sql, $user_id, $domain_id, $sub_name, $sub_mnt_pt)) { set_page_message(tr('Subdomain mount point already exists!')); } else { if (chk_mountp($sub_mnt_pt) > 0) { set_page_message(tr('Incorrect mount point syntax')); } else { subdomain_schedule($sql, $user_id, $domain_id, $sub_name, $sub_mnt_pt); set_page_message(tr('Subdomain scheduled for addition!')); header('Location:manage_domains.php'); exit(0); } } } } } }
/** * @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'); } }