root/trunk/gui/client/alias_add.php

Revision 1387, 7.0 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('CLIENT_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_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_manage_domains.tpl');
49 gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_manage_domains.tpl');
50
51 gen_logged_from($tpl);
52
53 check_permissions($tpl);
54
55 $tpl->assign(
56              array(
57                         'TR_CLIENT_ADD_ALIAS_PAGE_TITLE' => tr('ispCP Client : Add Alias'),
58                         'TR_MANAGE_DOMAIN_ALIAS' => tr('Manage domain alias'),
59                         'TR_ADD_ALIAS' => tr('Add domain alias'),
60                         'TR_DOMAIN_NAME' => tr('Domain name'),
61                         'TR_DOMAIN_ACCOUNT' => tr('User account'),
62                         'TR_MOUNT_POINT' => tr('Directory mount point'),
63                         'TR_DOMAIN_IP' => tr('Domain IP'),
64                         'TR_FORWARD' => tr('Forward to URL'),
65                         'TR_ADD' => tr('Add alias'),
66                         'TR_DMN_HELP' => tr("You do not need 'www.' ispCP will add it on its own.")
67                     )
68             );
69
70 check_domainalias_permissions($sql, $_SESSION['user_id']);
71
72 $err_txt = '_off_';
73 if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_alias') {
74     add_domain_alias($sql, $err_txt);
75 } else {
76 // Init fileds
77     init_empty_data();
78     $tpl-> assign("PAGE_MESSAGE", "");
79 }
80
81 //
82 // Begin function declaration lines
83 //
84
85 function check_domainalias_permissions($sql, $user_id) {
86
87     list($dmn_id,
88         $dmn_name,
89         $dmn_gid,
90         $dmn_uid,
91         $dmn_created_id,
92         $dmn_created,
93         $dmn_last_modified,
94         $dmn_mailacc_limit,
95         $dmn_ftpacc_limit,
96         $dmn_traff_limit,
97         $dmn_sqld_limit,
98         $dmn_sqlu_limit,
99         $dmn_status,
100         $dmn_als_limit,
101         $dmn_subd_limit,
102         $dmn_ip_id,
103         $dmn_disk_limit,
104         $dmn_disk_usage,
105         $dmn_php,
106         $dmn_cgi) = get_domain_default_props($sql, $user_id);
107
108
109         $als_cnt = get_domain_running_als_cnt($sql, $dmn_id);
110
111         if ($dmn_als_limit != 0 &&  $als_cnt >= $dmn_als_limit) {
112             set_page_message(tr('Domain alias limit reached!'));
113             header("Location: domains_manage.php");
114             die();
115         }
116 }
117
118 function init_empty_data() {
119     global $cr_user_id, $alias_name, $domain_ip, $forward, $mount_point;
120
121     $cr_user_id = "";
122     $alias_name    = "";
123     $domain_ip    = "";
124     $forward    = "";
125     $mount_point= "";
126
127 }//End of init_empty_data()
128
129
130 // Show data fiels
131 function gen_al_page(&$tpl, $reseller_id) {
132     global $cr_user_id, $alias_name, $domain_ip, $forward, $mount_point;
133
134     if (isset($_POST['forward'])) {
135         $forward = $_POST['forward'];
136     } else {
137         $forward = 'no';
138     }
139     $tpl -> assign(
140                 array(
141                         'DOMAIN'    => $alias_name,
142                         'MP'        => $mount_point,
143                         'FORWARD'    => $forward
144                 )
145     );
146
147 }// End of gen_al_page()
148
149 function add_domain_alias(&$sql, &$err_al) {
150     global $cr_user_id, $alias_name, $domain_ip, $forward, $mount_point;
151
152
153     $cr_user_id = $domain_id = get_user_domain_id($sql, $_SESSION['user_id']);
154     $alias_name    = strtolower($_POST['ndomain_name']);
155     $mount_point = strtolower($_POST['ndomain_mpoint']);
156     $forward = strtolower(clean_input($_POST['forward']));
157
158     $query = "
159         SELECT
160             `domain_ip_id`
161         FROM
162             `domain`
163         WHERE
164             `domain_id` = ?
165     ";
166
167     $rs = exec_query($sql, $query, array($cr_user_id));
168     $domain_ip = $rs -> fields['domain_ip_id'];
169
170     $alias_name = encode_idna($alias_name);
171     $mount_point = array_encode_idna($mount_point, true);
172
173     //$mount_point = "/".$mount_point;
174
175     // First check if the data is correct
176     if (!chk_dname($alias_name)) {
177         $err_al = tr("Incorrect domain name syntax");
178     } else if (ispcp_domain_exists($alias_name, 0)) {
179      $err_al = tr('Domain with that name already exists on the system!');
180     } else if (!chk_mountp($mount_point) && $mount_point != '/') {
181         $err_al = tr("Incorrect mount point syntax");
182     } else if ($alias_name == Config::get('BASE_SERVER_VHOST')) {
183         $err_al = tr('Master domain cannot be used!');
184     } else if ($forward != 'no') {
185         if (!chk_forward_url($forward)) {
186             $err_al = tr("Incorrect forward syntax");
187         }
188         if (!preg_match("/\/$/", $forward)) {
189             $forward .= "/";
190         }
191     } else {
192         //now lets fix the mountpoint
193         $mount_point = array_decode_idna($mount_point, true);
194
195         $query = "SELECT `domain_id` FROM `domain_aliasses` WHERE `alias_name`=?";
196         $res = exec_query($sql, $query, array($alias_name));
197         $query = "SELECT `domain_id` FROM `domain` WHERE `domain_name`=?";
198         $res2 = exec_query($sql, $query, array($alias_name));
199         if ($res->RowCount() > 0 or $res2->RowCount() > 0) {
200             // we already have domain with this name
201          $err_al = tr("Domain with this name already exist");
202         }
203
204         if (mount_point_exists($domain_id, $mount_point)) {
205             $err_al = tr('Mount point already in use!');
206         }
207     }
208
209     if('_off_' !== $err_al) {
210         return;
211     }
212
213     // Begin add new alias domain
214     $alias_name = htmlspecialchars($alias_name, ENT_QUOTES, "UTF-8");
215     check_for_lock_file();
216
217     $status = Config::get('ITEM_ORDERED_STATUS');
218
219     $query = "INSERT INTO `domain_aliasses` (`domain_id`, `alias_name`, `alias_mount`, `alias_status`, `alias_ip_id`, `url_forward`) values (?, ?, ?, ?, ?, ?)";
220     exec_query($sql, $query, array($cr_user_id, $alias_name, $mount_point, $status, $domain_ip, $forward));
221
222     $als_id = $sql->Insert_ID();
223
224     $admin_login = $_SESSION['user_logged'];
225
226     if ($status == Config::get('ITEM_ORDERED_STATUS')) {
227         // notify the reseller:
228         send_alias_order_email($alias_name);
229     
230         write_log("$admin_login: add domain alias for activation: $alias_name.");
231         set_page_message(tr('Alias scheduled for activation!'));
232     } else {
233         send_request();
234         write_log("$admin_login: domain alias scheduled for addition: $alias_name.");
235         set_page_message(tr('Alias scheduled for addition!'));
236     }
237
238
239     header( "Location: domains_manage.php" );
240     die();
241 }// End of add_domain_alias();
242
243
244 function gen_page_msg(&$tpl, $erro_txt) {
245
246     if ($erro_txt != '_off_') {
247
248      $tpl -> assign('MESSAGE', $erro_txt);
249         $tpl -> parse('PAGE_MESSAGE', 'page_message');
250
251     } else {
252
253      $tpl -> assign('PAGE_MESSAGE', '');
254     }
255 }//End of gen_page_msg()
256
257 gen_al_page($tpl, $_SESSION['user_id']);
258 gen_page_msg($tpl, $err_txt);
259
260 //gen_page_message($tpl);
261
262 $tpl->parse('PAGE', 'page');
263 $tpl->prnt();
264
265 if (Config::get('DUMP_GUI_DEBUG'))
266     dump_gui_debug();
267
268 ?>
Note: See TracBrowser for help on using the browser.