| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
require '../include/ispcp-lib.php'; |
|---|
| 22 |
|
|---|
| 23 |
check_login(__FILE__); |
|---|
| 24 |
|
|---|
| 25 |
$tpl = new pTemplate(); |
|---|
| 26 |
$tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/alias_edit.tpl'); |
|---|
| 27 |
$tpl->define_dynamic('page_message', 'page'); |
|---|
| 28 |
$tpl->define_dynamic('logged_from', 'page'); |
|---|
| 29 |
|
|---|
| 30 |
$theme_color = Config::get('USER_INITIAL_THEME'); |
|---|
| 31 |
|
|---|
| 32 |
$tpl->assign( |
|---|
| 33 |
array( |
|---|
| 34 |
'TR_EDIT_ALIAS_PAGE_TITLE' => tr('ispCP - Manage Domain Alias/Edit Alias'), |
|---|
| 35 |
'THEME_COLOR_PATH' => "../themes/$theme_color", |
|---|
| 36 |
'THEME_CHARSET' => tr('encoding'), |
|---|
| 37 |
'ISP_LOGO' => get_logo($_SESSION['user_id']) |
|---|
| 38 |
) |
|---|
| 39 |
); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
$tpl->assign( |
|---|
| 47 |
array( |
|---|
| 48 |
'TR_MANAGE_DOMAIN_ALIAS' => tr('Manage domain alias'), |
|---|
| 49 |
'TR_EDIT_ALIAS' => tr('Edit domain alias'), |
|---|
| 50 |
'TR_ALIAS_NAME' => tr('Alias name'), |
|---|
| 51 |
'TR_DOMAIN_IP' => tr('Domain IP'), |
|---|
| 52 |
'TR_FORWARD' => tr('Forward to URL'), |
|---|
| 53 |
'TR_MOUNT_POINT' => tr('Mount Point'), |
|---|
| 54 |
'TR_MODIFY' => tr('Modify'), |
|---|
| 55 |
'TR_CANCEL' => tr('Cancel'), |
|---|
| 56 |
'TR_ENABLE_FWD' => tr("Enable Forward"), |
|---|
| 57 |
'TR_ENABLE' => tr("Enable"), |
|---|
| 58 |
'TR_DISABLE' => tr("Disable"), |
|---|
| 59 |
'TR_FWD_HELP' => tr("A Forward URL has to start with 'http://'") |
|---|
| 60 |
) |
|---|
| 61 |
); |
|---|
| 62 |
|
|---|
| 63 |
gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_manage_domains.tpl'); |
|---|
| 64 |
gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_manage_domains.tpl'); |
|---|
| 65 |
|
|---|
| 66 |
gen_logged_from($tpl); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
if (isset($_POST['uaction']) && ($_POST['uaction'] === 'modify')) { |
|---|
| 70 |
if (isset($_GET['edit_id'])) { |
|---|
| 71 |
$editid = $_GET['edit_id']; |
|---|
| 72 |
} else if (isset($_SESSION['edit_ID'])) { |
|---|
| 73 |
$editid = $_SESSION['edit_ID']; |
|---|
| 74 |
} else { |
|---|
| 75 |
unset($_SESSION['edit_ID']); |
|---|
| 76 |
|
|---|
| 77 |
$_SESSION['aledit'] = '_no_'; |
|---|
| 78 |
header('Location: domains_manage.php'); |
|---|
| 79 |
die(); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
if (check_fwd_data($tpl, $editid)) { |
|---|
| 83 |
$_SESSION['aledit'] = "_yes_"; |
|---|
| 84 |
header("Location: domains_manage.php"); |
|---|
| 85 |
die(); |
|---|
| 86 |
} |
|---|
| 87 |
} else { |
|---|
| 88 |
|
|---|
| 89 |
if (isset($_GET['edit_id'])) { |
|---|
| 90 |
$editid = $_GET['edit_id']; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
$_SESSION['edit_ID'] = $editid; |
|---|
| 94 |
$tpl->assign('PAGE_MESSAGE', ""); |
|---|
| 95 |
} |
|---|
| 96 |
gen_editalias_page($tpl, $editid); |
|---|
| 97 |
|
|---|
| 98 |
$tpl->parse('PAGE', 'page'); |
|---|
| 99 |
$tpl->prnt(); |
|---|
| 100 |
|
|---|
| 101 |
if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug(); |
|---|
| 102 |
|
|---|
| 103 |
unset_messages(); |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
function gen_editalias_page(&$tpl, $edit_id) { |
|---|
| 109 |
$sql = Database::getInstance(); |
|---|
| 110 |
|
|---|
| 111 |
list($domain_id) = get_domain_default_props($sql, $_SESSION['user_id']); |
|---|
| 112 |
$res = exec_query($sql, "select * from domain_aliasses where alias_id = ? and domain_id = ?", array($edit_id, $domain_id)); |
|---|
| 113 |
|
|---|
| 114 |
if ($res->RecordCount() <= 0) { |
|---|
| 115 |
$_SESSION['aledit'] = '_no_'; |
|---|
| 116 |
header('Location: domains_manage.php'); |
|---|
| 117 |
die(); |
|---|
| 118 |
} |
|---|
| 119 |
$data = $res->FetchRow(); |
|---|
| 120 |
|
|---|
| 121 |
$ipres = exec_query($sql, "select * from server_ips where ip_id=?", array($data['alias_ip_id'])); |
|---|
| 122 |
$ipdat = $ipres->FetchRow(); |
|---|
| 123 |
$ip_data = $ipdat['ip_number'] . ' (' . $ipdat['ip_alias'] . ')'; |
|---|
| 124 |
|
|---|
| 125 |
if (isset($_POST['uaction']) && ($_POST['uaction'] == 'modify')) |
|---|
| 126 |
$url_forward = decode_idna($_POST['forward']); |
|---|
| 127 |
else |
|---|
| 128 |
$url_forward = decode_idna($data['url_forward']); |
|---|
| 129 |
|
|---|
| 130 |
if ($data["url_forward"] == "no") { |
|---|
| 131 |
$check_en = ""; |
|---|
| 132 |
$check_dis = "checked=\"checked\""; |
|---|
| 133 |
$url_forward = ""; |
|---|
| 134 |
} else { |
|---|
| 135 |
$check_en = "checked=\"checked\""; |
|---|
| 136 |
$check_dis = ""; |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
$tpl->assign( |
|---|
| 140 |
array( |
|---|
| 141 |
'ALIAS_NAME' => decode_idna($data['alias_name']), |
|---|
| 142 |
'DOMAIN_IP' => $ip_data, |
|---|
| 143 |
'FORWARD' => $url_forward, |
|---|
| 144 |
'MOUNT_POINT' => $data['alias_mount'], |
|---|
| 145 |
'CHECK_EN' => $check_en, |
|---|
| 146 |
'CHECK_DIS' => $check_dis, |
|---|
| 147 |
'ID' => $edit_id |
|---|
| 148 |
) |
|---|
| 149 |
); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
// Check input data |
|---|
| 153 |
function check_fwd_data(&$tpl, $alias_id) { |
|---|
| 154 |
$sql = Database::getInstance(); |
|---|
| 155 |
|
|---|
| 156 |
$forward_url = encode_idna($_POST['forward']); |
|---|
| 157 |
$status = $_POST['status']; |
|---|
| 158 |
|
|---|
| 159 |
$ed_error = '_off_'; |
|---|
| 160 |
$admin_login = ''; |
|---|
| 161 |
|
|---|
| 162 |
if ($forward_url != 'no') { |
|---|
| 163 |
if (!chk_forward_url($forward_url)) { |
|---|
| 164 |
$ed_error = tr("Incorrect forward syntax"); |
|---|
| 165 |
} |
|---|
| 166 |
if (!preg_match("/\/$/", $forward_url)) { |
|---|
| 167 |
$forward_url .= "/"; |
|---|
| 168 |
} |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
if ($ed_error === '_off_') { |
|---|
| 172 |
if ($_POST['status'] == 0) { |
|---|
| 173 |
$forward_url = "no"; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
$query = <<<SQL |
|---|
| 177 |
UPDATE |
|---|
| 178 |
domain_aliasses |
|---|
| 179 |
SET |
|---|
| 180 |
url_forward = ?, |
|---|
| 181 |
alias_status = ? |
|---|
| 182 |
WHERE |
|---|
| 183 |
alias_id = ? |
|---|
| 184 |
SQL; |
|---|
| 185 |
|
|---|
| 186 |
exec_query($sql, $query, array($forward_url, Config::get('ITEM_CHANGE_STATUS'), $alias_id)); |
|---|
| 187 |
check_for_lock_file(); |
|---|
| 188 |
send_request(); |
|---|
| 189 |
|
|---|
| 190 |
$admin_login = $_SESSION['user_logged']; |
|---|
| 191 |
write_log("$admin_login: change domain alias forward: " . $rs->fields['t1.alias_name']); |
|---|
| 192 |
unset($_SESSION['edit_ID']); |
|---|
| 193 |
$tpl->assign('MESSAGE', ""); |
|---|
| 194 |
return true; |
|---|
| 195 |
} else { |
|---|
| 196 |
$tpl->assign('MESSAGE', $ed_error); |
|---|
| 197 |
$tpl->parse('PAGE_MESSAGE', 'page_message'); |
|---|
| 198 |
return false; |
|---|
| 199 |
} |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
?> |
|---|