root/trunk/gui/admin/admin_add.php

Revision 1390, 8.7 kB (checked in by simple, 1 month ago)

fix according to http://www.isp-control.net/ispcp/ticket/1564
* clear untechnical message
* including the required length
* message according to config-setting (passwd_strong or not)
changed all files with chk_password and error message in it, as well as the language files base and de_DE to add the string

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('ADMIN_TEMPLATE_PATH') . '/admin_add.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28
29 $theme_color = Config::get('USER_INITIAL_THEME');
30
31 $tpl->assign(
32         array(
33             'TR_ADMIN_ADD_USER_PAGE_TITLE' => tr('ispCP - Admin/Manage users/Add User'),
34             'THEME_COLOR_PATH' => "../themes/$theme_color",
35             'THEME_CHARSET' => tr('encoding'),
36             'ISP_LOGO' => get_logo($_SESSION['user_id'])
37         )
38     );
39
40 function add_user(&$tpl, &$sql) {
41     if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_user') {
42         if (check_user_data()) {
43             $upass = crypt_user_pass($_POST['pass']);
44
45             $user_id = $_SESSION['user_id'];
46
47             $username = clean_input($_POST['username']);
48             $fname = clean_input($_POST['fname']);
49             $lname = clean_input($_POST['lname']);
50             $gender = clean_input($_POST['gender']);
51             $firm = clean_input($_POST['firm']);
52             $zip = clean_input($_POST['zip']);
53             $city = clean_input($_POST['city']);
54             $country = clean_input($_POST['country']);
55             $email = clean_input($_POST['email']);
56             $phone = clean_input($_POST['phone']);
57             $fax = clean_input($_POST['fax']);
58             $street1 = clean_input($_POST['street1']);
59             $street2 = clean_input($_POST['street2']);
60
61             if (get_gender_by_code($gender, true) === null) {
62                 $gender = '';
63             }
64
65             $query = <<<SQL_QUERY
66                     insert into
67                             admin
68                             (
69                                 admin_name,
70                                 admin_pass,
71                                 admin_type,
72                                 domain_created,
73                                 created_by,
74                                 fname,
75                                 lname,
76                                 firm,
77                                 zip,
78                                 city,
79                                 country,
80                                 email,
81                                 phone,
82                                 fax,
83                                 street1,
84                                 street2,
85                                 gender
86                             )
87                             values
88                             (
89                                 ?,
90                                 ?,
91                                 'admin',
92                                 unix_timestamp(),
93                                 ?,
94                                 ?,
95                                 ?,
96                                 ?,
97                                 ?,
98                                 ?,
99                                 ?,
100                                 ?,
101                                 ?,
102                                 ?,
103                                 ?,
104                                 ?,
105                                 ?
106                             )
107 SQL_QUERY;
108
109             $rs = exec_query($sql, $query, array($username,
110                     $upass,
111                     $user_id,
112                     $fname,
113                     $lname,
114                     $firm,
115                     $zip,
116                     $city,
117                     $country,
118                     $email,
119                     $phone,
120                     $fax,
121                     $street1,
122                     $street2,
123                     $gender));
124
125             $new_admin_id = $sql->Insert_ID();
126
127             $user_logged = $_SESSION['user_logged'];
128
129             write_log("$user_logged: add admin: $username");
130
131             $user_def_lang = $_SESSION['user_def_lang'];
132             $user_theme_color = $_SESSION['user_theme'];
133             $user_logo = 0;
134
135             $query = <<<SQL_QUERY
136                     insert into
137                         user_gui_props
138                             (
139                                 user_id,
140                                 lang,
141                                 layout,
142                                 logo
143                             )
144                         values
145                             (
146                               ?,?,?,?
147                             )
148 SQL_QUERY;
149
150             $rs = exec_query($sql, $query, array($new_admin_id,
151                     $user_def_lang,
152                     $user_theme_color,
153                     $user_logo));
154
155             send_add_user_auto_msg ($user_id,
156                 clean_input($_POST['username']),
157                 clean_input($_POST['pass']),
158                 clean_input($_POST['email']),
159                 clean_input($_POST['fname']),
160                 clean_input($_POST['lname']),
161                 tr('Administrator'),
162                 $gender
163                 );
164
165             $_SESSION['user_added'] = 1;
166
167             header("Location: manage_users.php");
168             die();
169         } //check user data
170         else {
171             $tpl->assign(
172                     array(
173                         'EMAIL' => clean_input($_POST['email']),
174                         'USERNAME' => clean_input($_POST['username']),
175                         'FIRST_NAME' => clean_input($_POST['fname']),
176                         'LAST_NAME' => clean_input($_POST['lname']),
177                         'FIRM' => clean_input($_POST['firm']),
178                         'ZIP' => clean_input($_POST['zip']),
179                         'CITY' => clean_input($_POST['city']),
180                         'COUNTRY' => clean_input($_POST['country']),
181                         'STREET_1' => clean_input($_POST['street1']),
182                         'STREET_2' => clean_input($_POST['street2']),
183                         'PHONE' => clean_input($_POST['phone']),
184                         'FAX' => clean_input($_POST['fax']),
185                         'VL_MALE' => (($_POST['gender'] == 'M') ? 'selected' : ''),
186                         'VL_FEMALE' => (($_POST['gender'] == 'F') ? 'selected' : ''),
187                         'VL_UNKNOWN' => ((($_POST['gender'] == 'U') || (empty($_POST['gender']))) ? 'selected' : '')
188                     )
189                 );
190         }
191     } else {
192         $tpl->assign(
193                 array(
194                     'EMAIL' => '',
195                     'USERNAME' => '',
196                     'FIRST_NAME' => '',
197                     'LAST_NAME' => '',
198                     'FIRM' => '',
199                     'ZIP' => '',
200                     'CITY' => '',
201                     'COUNTRY' => '',
202                     'STREET_1' => '',
203                     'STREET_2' => '',
204                     'PHONE' => '',
205                     'FAX' => '',
206                     'VL_MALE' => '',
207                     'VL_FEMALE' => '',
208                     'VL_UNKNOWN' => 'selected'
209                 )
210             );
211     } // else
212 }
213
214 function check_user_data() {
215     $sql = Database::getInstance();
216
217     if (!chk_username($_POST['username'])) {
218         set_page_message(tr("Incorrect username length or syntax!"));
219
220         return false;
221     }
222     if (!chk_password($_POST['pass'])) {
223         if(Config::get('PASSWD_STRONG')){
224       set_page_message(sprintf(tr('The password must be at least %s long and contain letters and numbers to be valid.'), Config::get('PASSWD_CHARS')));
225     } else {
226       set_page_message(sprintf(tr('Password data is shorter than %s signs or includes not permitted signs!'), Config::get('PASSWD_CHARS')));
227     }
228
229         return false;
230     }
231     if ($_POST['pass'] != $_POST['pass_rep']) {
232         set_page_message(tr("Entered passwords do not match!"));
233
234         return false;
235     }
236     if (!chk_email($_POST['email'])) {
237         set_page_message(tr("Incorrect email length or syntax!"));
238
239         return false;
240     }
241
242     $query = <<<SQL_QUERY
243         select
244             admin_id
245         from
246             admin
247         where
248             admin_name = ?
249
250 SQL_QUERY;
251
252     $username = clean_input($_POST['username']);
253
254     $rs = exec_query($sql, $query, array($username));
255
256     if ($rs->RecordCount() != 0) {
257         set_page_message(tr('This user name already exist!'));
258
259         return false;
260     }
261
262     return true;
263 }
264
265 /*
266  *
267  * static page messages.
268  *
269  */
270 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_users_manage.tpl');
271 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_users_manage.tpl');
272
273 add_user($tpl, $sql);
274
275 $tpl->assign(
276         array(
277             'TR_EMPTY_OR_WORNG_DATA' => tr('Empty data or wrong field!'),
278             'TR_PASSWORD_NOT_MATCH' => tr("Passwords don't match!"),
279             'TR_ADD_ADMIN' => tr('Add admin'),
280             'TR_CORE_DATA' => tr('Core data'),
281             'TR_USERNAME' => tr('Username'),
282             'TR_PASSWORD' => tr('Password'),
283             'TR_PASSWORD_REPEAT' => tr('Repeat password'),
284             'TR_EMAIL' => tr('Email'),
285             'TR_ADDITIONAL_DATA' => tr('Additional data'),
286             'TR_FIRST_NAME' => tr('First name'),
287             'TR_LAST_NAME' => tr('Last name'),
288             'TR_GENDER' => tr('Gender'),
289             'TR_MALE' => tr('Male'),
290             'TR_FEMALE' => tr('Female'),
291             'TR_UNKNOWN' => tr('Unknown'),
292             'TR_COMPANY' => tr('Company'),
293             'TR_ZIP_POSTAL_CODE' => tr('Zip/Postal code'),
294             'TR_CITY' => tr('City'),
295             'TR_COUNTRY' => tr('Country'),
296             'TR_STREET_1' => tr('Street 1'),
297             'TR_STREET_2' => tr('Street 2'),
298             'TR_PHONE' => tr('Phone'),
299             'TR_FAX' => tr('Fax'),
300             'TR_PHONE' => tr('Phone'),
301             'TR_ADD' => tr('Add'),
302             'GENPAS' => passgen()
303         )
304
305     );
306
307 gen_page_message($tpl);
308
309 $tpl->parse('PAGE', 'page');
310 $tpl->prnt();
311
312 if (Config::get('DUMP_GUI_DEBUG'))
313     dump_gui_debug();
314
315 unset_messages();
316
317 ?>
Note: See TracBrowser for help on using the browser.