root/trunk/gui/reseller/alias_add.php

Revision 1387, 9.2 kB (checked in by scitech, 1 month ago)

Subdomain with existing mountpoint not possible

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
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('RESELLER_TEMPLATE_PATH') . '/alias_add.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('logged_from', 'page');
29 $tpl->define_dynamic('user_entry', 'page');
30 $tpl->define_dynamic('ip_entry', 'page');
31
32 $theme_color = Config::get('USER_INITIAL_THEME');
33
34 $tpl->assign(
35         array(
36             'THEME_COLOR_PATH' => "../themes/$theme_color",
37             'THEME_CHARSET' => tr('encoding'),
38             'ISP_LOGO' => get_logo($_SESSION['user_id'])
39         )
40     );
41
42 /*
43  *
44  * static page messages.
45  *
46  */
47
48 gen_reseller_mainmenu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/main_menu_users_manage.tpl');
49 gen_reseller_menu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/menu_users_manage.tpl');
50
51 gen_logged_from($tpl);
52
53 $tpl->assign(
54         array(
55             'TR_CLIENT_ADD_ALIAS_PAGE_TITLE' => tr('ispCP Reseller : Add Alias'),
56             'TR_MANAGE_DOMAIN_ALIAS' => tr('Manage domain alias'),
57             'TR_ADD_ALIAS' => tr('Add domain alias'),
58             'TR_DOMAIN_NAME' => tr('Domain name'),
59             'TR_DOMAIN_ACCOUNT' => tr('User account'),
60             'TR_MOUNT_POINT' => tr('Directory mount point'),
61             'TR_DOMAIN_IP' => tr('Domain IP'),
62             'TR_FORWARD' => tr('Forward to URL'),
63             'TR_ADD' => tr('Add alias'),
64             'TR_DMN_HELP' => tr("You do not need 'www.' ispCP will add it on its own.")
65         )
66     );
67
68 $err_txt = '_off_';
69 if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_alias') {
70     add_domain_alias($sql, $err_txt);
71 } else {
72     // Init fileds
73     init_empty_data();
74     $tpl->assign("PAGE_MESSAGE", "");
75 }
76
77 gen_al_page($tpl, $_SESSION['user_id']);
78 gen_page_msg($tpl, $err_txt);
79 // gen_page_message($tpl);
80 $tpl->parse('PAGE', 'page');
81
82 $tpl->prnt();
83
84 if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug();
85
86 // Begin function declaration lines
87
88 function init_empty_data() {
89     global $cr_user_id, $alias_name, $domain_ip, $forward, $mount_point;
90
91     $cr_user_id = "";
92     $alias_name = "";
93     $domain_ip = "";
94     $forward = "";
95     $mount_point = "";
96 } //End of init_empty_data()
97
98 // Show data fiels
99 function gen_al_page(&$tpl, $reseller_id) {
100     global $cr_user_id, $alias_name, $domain_ip, $forward, $mount_point;
101
102     if (isset($_POST['forward'])) {
103         $forward = clean_input($_POST['forward']);
104     } else {
105         $forward = 'no';
106     }
107     $tpl->assign(
108         array('DOMAIN' => $alias_name,
109             'MP' => $mount_point,
110             'FORWARD' => $forward
111             )
112         );
113
114     generate_ip_list($tpl, $reseller_id);
115     gen_users_list($tpl, $reseller_id);
116 } // End of gen_al_page()
117
118 function add_domain_alias(&$sql, &$err_al) {
119     global $cr_user_id, $alias_name, $domain_ip, $forward, $mount_point;
120
121     $cr_user_id = $dmn_id = $_POST['usraccounts'];
122     $alias_name = encode_idna(strtolower($_POST['ndomain_name']));
123     $mount_point = array_encode_idna(strtolower($_POST['ndomain_mpoint']), true);
124     $forward = strtolower($_POST['forward']);
125
126     $query = <<<SQL_QUERY
127         SELECT
128             domain_ip_id
129         FROM
130             domain
131         WHERE
132             domain_id = ?
133 SQL_QUERY;
134
135     $rs = exec_query($sql, $query, array($cr_user_id));
136     $domain_ip = $rs->fields['domain_ip_id'];
137
138     // $mount_point = "/".$mount_point;
139     // First check is the data correct
140     if (!chk_dname($alias_name)) {
141         $err_al = tr("Incorrect domain name syntax");
142     } else if (ispcp_domain_exists($alias_name, $_SESSION['user_id'])) {
143         $err_al = tr('Domain with that name already exists on the system!');
144     } else if (!chk_mountp($mount_point) && $mount_point != '/') {
145         $err_al = tr("Incorrect mount point syntax");
146     } else if ($alias_name == Config::get('BASE_SERVER_VHOST')) {
147         $err_al = tr('Master domain cannot be used!');
148     } else if ($forward != 'no') {
149         if (!chk_forward_url($forward)) {
150             $err_al = tr("Incorrect forward syntax");
151         }
152         if (!preg_match("/\/$/", $forward)) {
153             $forward .= "/";
154         }
155     } else {
156         // now lets fix the mountpoint
157         $mount_point = array_decode_idna($mount_point, true);
158
159         $res = exec_query($sql, "select domain_id from domain_aliasses where alias_name=?", array($alias_name));
160         $res2 = exec_query($sql, "select domain_id from domain where domain_name = ?", array($alias_name));
161         if ($res->RowCount() > 0 or $res2->RowCount() > 0) {
162             // we already have domain with this name
163             $err_al = tr("Domain with this name already exist");
164         }
165
166         if (mount_point_exists($dmn_id, $mount_point)) {
167             $err_al = tr('Mount point already in use!');
168         }
169     }
170
171     if ('_off_' !== $err_al) {
172         return;
173     }
174     // Begin add new alias domain
175     $alias_name = htmlspecialchars($alias_name, ENT_QUOTES, "UTF-8");
176     check_for_lock_file();
177     $status = Config::get('ITEM_ADD_STATUS');
178
179     exec_query($sql,
180         "insert into domain_aliasses(domain_id, alias_name, alias_mount, alias_status, alias_ip_id, url_forward) values (?, ?, ?, ?, ?, ?)",
181         array($cr_user_id, $alias_name, $mount_point, $status, $domain_ip, $forward));
182
183         $als_id = $sql->Insert_ID();
184
185
186         $query = 'SELECT email FROM admin WHERE admin_id = ? LIMIT 1';
187         $rs = exec_query($sql, $query, who_owns_this($cr_user_id, 'dmn_id'));
188         $user_email = $rs->fields['email'];
189
190     // Create the 3 default addresses if wanted
191     if (Config::get('CREATE_DEFAULT_EMAIL_ADDRESSES')) client_mail_add_default_accounts($cr_user_id, $user_email, $alias_name, 'alias', $als_id);
192 /*
193     if (Config::get('CREATE_DEFAULT_EMAIL_ADDRESSES')) {
194         $query = <<<SQL_QUERY
195             INSERT INTO mail_users
196                 (mail_acc,
197                  mail_pass,
198                  mail_forward,
199                  domain_id,
200                  mail_type,
201                  sub_id,
202                  status,
203                  mail_auto_respond)
204             VALUES
205                 (?, ?, ?, ?, ?, ?, ?, ?)
206 SQL_QUERY;
207
208         // create default forwarder for webmaster@alias.tld to the account's owner
209         $rs = exec_query($sql, $query, array('webmaster',
210                 '_no_',
211                 $user_email,
212                 $cr_user_id,
213                 'alias_forward',
214                 $als_id,
215                 Config::get('ITEM_ADD_STATUS'),
216                 '_no_'));
217
218         // create default forwarder for postmaster@alias.tld to the account's reseller
219         $rs = exec_query($sql, $query, array('postmaster',
220                 '_no_',
221                 $_SESSION['user_email'],
222                 $cr_user_id,
223                 'alias_forward',
224                 $als_id,
225                 Config::get('ITEM_ADD_STATUS'),
226                 '_no_'));
227
228         // create default forwarder for abuse@alias.tld to the account's reseller
229         $rs = exec_query($sql, $query, array('abuse',
230                 '_no_',
231                 $_SESSION['user_email'],
232                 $cr_user_id,
233                 'alias_forward',
234                 $als_id,
235                 Config::get('ITEM_ADD_STATUS'),
236                 '_no_'));
237     }
238 */
239     send_request();
240     $admin_login = $_SESSION['user_logged'];
241     write_log("$admin_login: add domain alias: $alias_name");
242
243     $_SESSION["aladd"] = '_yes_';
244     header("Location: alias.php");
245     die();
246 } // End of add_domain_alias();
247
248 function gen_users_list(&$tpl, $reseller_id) {
249     $sql = Database::getInstance();
250     global $cr_user_id;
251
252     $query = <<<SQL_QUERY
253         SELECT
254             admin_id
255         FROM
256             admin
257         WHERE
258                 admin_type = 'user'
259             AND
260                 created_by = ?
261         ORDER BY
262             admin_name
263 SQL_QUERY;
264
265     $ar = exec_query($sql, $query, array($reseller_id));
266
267     if ($ar->RowCount() == 0) {
268         set_page_message(tr('You have no user records.'));
269         header("Location: alias.php");
270         die();
271         $tpl->assign('USER_ENTRY', '');
272         return false;
273     }
274
275     $i = 1;
276     while ($ad = $ar->FetchRow()) { // Process all founded users
277         $admin_id = $ad['admin_id'];
278         $selected = '';
279         // Get domain data
280         $query = <<<SQL_QUERY
281             SELECT
282                 domain_id,
283                 IFNULL(domain_name, '') AS domain_name
284             FROM
285                 domain
286             WHERE
287                 domain_admin_id = ?
288 SQL_QUERY;
289
290         $dr = exec_query($sql, $query, array($admin_id));
291         $dd = $dr->FetchRow();
292
293         $domain_id = $dd['domain_id'];
294         $domain_name = $dd['domain_name'];
295
296         if (('' == $cr_user_id) && ($i == 1))
297             $selected = 'selected';
298         else if ($cr_user_id == $domain_id)
299             $selected = 'selected';
300
301         $domain_name = decode_idna($domain_name);
302
303         $tpl->assign(
304                 array(
305                     'USER' => $domain_id,
306                     'USER_DOMAIN_ACCOUN' => $domain_name,
307                     'SELECTED' => $selected
308                 )
309             );
310         $i++;
311         $tpl->parse('USER_ENTRY', '.user_entry');
312     } //End of loop
313     return true;
314 } // End of gen_users_list()
315
316 function gen_page_msg(&$tpl, $erro_txt) {
317     if ($erro_txt != '_off_') {
318         $tpl->assign('MESSAGE', $erro_txt);
319         $tpl->parse('PAGE_MESSAGE', 'page_message');
320     } else {
321         $tpl->assign('PAGE_MESSAGE', '');
322     }
323 } //End of gen_page_msg()
324
325 ?>
Note: See TracBrowser for help on using the browser.