PageRenderTime 84ms CodeModel.GetById 23ms RepoModel.GetById 11ms app.codeStats 0ms

/gui/public/reseller/user_add3.php

https://bitbucket.org/droidzone/i-mscp
PHP | 456 lines | 313 code | 69 blank | 74 comment | 27 complexity | 80d4cd5185efd1d3a93ff2dae470a106 MD5 | raw file
  1. <?php
  2. /**
  3. * i-MSCP - internet Multi Server Control Panel
  4. *
  5. * The contents of this file are subject to the Mozilla Public License
  6. * Version 1.1 (the "License"); you may not use this file except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS"
  11. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  12. * License for the specific language governing rights and limitations
  13. * under the License.
  14. *
  15. * The Original Code is "VHCS - Virtual Hosting Control System".
  16. *
  17. * The Initial Developer of the Original Code is moleSoftware GmbH.
  18. * Portions created by Initial Developer are Copyright (C) 2001-2006
  19. * by moleSoftware GmbH. All Rights Reserved.
  20. *
  21. * Portions created by the ispCP Team are Copyright (C) 2006-2010 by
  22. * isp Control Panel. All Rights Reserved.
  23. *
  24. * Portions created by the i-MSCP Team are Copyright (C) 2010-2013 by
  25. * i-MSCP - internet Multi Server Control Panel. All Rights Reserved.
  26. *
  27. * @category i-MSCP
  28. * @package iMSCP_Core
  29. * @subpackage Reseller
  30. * @copyright 2001-2006 by moleSoftware GmbH
  31. * @copyright 2006-2010 by ispCP | http://isp-control.net
  32. * @copyright 2010-2013 by i-MSCP | http://i-mscp.net
  33. * @author ispCP Team
  34. * @author i-MSCP Team
  35. * @link http://i-mscp.net
  36. */
  37. /************************************************************************************
  38. * Script functions
  39. */
  40. /**
  41. * Get data from previous page.
  42. *
  43. * @return bool
  44. */
  45. function init_in_values()
  46. {
  47. global $dmn_name, $dmn_expire, $dmn_user_name, $hpid;
  48. if (isset($_SESSION['dmn_expire'])) {
  49. $dmn_expire = $_SESSION['dmn_expire'];
  50. }
  51. if (isset($_SESSION['step_one'])) {
  52. $step_two = $_SESSION['dmn_name'] . ";" . $_SESSION['dmn_tpl'];
  53. $hpid = $_SESSION['dmn_tpl'];
  54. unset($_SESSION['dmn_name']);
  55. unset($_SESSION['dmn_tpl']);
  56. unset($_SESSION['chtpl']);
  57. unset($_SESSION['step_one']);
  58. } elseif (isset($_SESSION['step_two_data'])) {
  59. $step_two = $_SESSION['step_two_data'];
  60. unset($_SESSION['step_two_data']);
  61. } elseif (isset($_SESSION['local_data'])) {
  62. $step_two = $_SESSION['local_data'];
  63. unset($_SESSION['local_data']);
  64. } else {
  65. $step_two = "'';0";
  66. }
  67. list($dmn_name, $hpid) = explode(";", $step_two);
  68. $dmn_user_name = $dmn_name;
  69. if (!validates_dname(decode_idna($dmn_name)) || ($hpid == '')) {
  70. return false;
  71. }
  72. return true;
  73. }
  74. /**
  75. * Generates page add user 3.
  76. *
  77. * @param iMSCP_pTemplate $tpl Template engine
  78. * @return void
  79. */
  80. function gen_user_add3_page(&$tpl)
  81. {
  82. global $dmn_name, $hpid, $dmn_user_name, $user_email, $customer_id, $first_name,
  83. $last_name, $gender, $firm, $zip, $city, $state, $country, $street_one,
  84. $street_two, $mail, $phone, $fax;
  85. /** @var $cfg iMSCP_Config_Handler_File */
  86. $cfg = iMSCP_Registry::get('config');
  87. $dmn_user_name = decode_idna($dmn_user_name);
  88. $tpl->assign(
  89. array(
  90. 'VL_USERNAME' => tohtml($dmn_user_name),
  91. 'VL_USR_PASS' => passgen(),
  92. 'VL_MAIL' => tohtml($user_email),
  93. 'VL_USR_ID' => $customer_id,
  94. 'VL_USR_NAME' => tohtml($first_name),
  95. 'VL_LAST_USRNAME' => tohtml($last_name),
  96. 'VL_USR_FIRM' => tohtml($firm),
  97. 'VL_USR_POSTCODE' => tohtml($zip),
  98. 'VL_USRCITY' => tohtml($city),
  99. 'VL_USRSTATE' => tohtml($state),
  100. 'VL_MALE' => ($gender == 'M') ? $cfg->HTML_SELECTED : '',
  101. 'VL_FEMALE' => ($gender == 'F') ? $cfg->HTML_SELECTED : '',
  102. 'VL_UNKNOWN' => ($gender == 'U') ? $cfg->HTML_SELECTED : '',
  103. 'VL_COUNTRY' => tohtml($country),
  104. 'VL_STREET1' => tohtml($street_one),
  105. 'VL_STREET2' => tohtml($street_two),
  106. 'VL_MAIL' => tohtml($mail),
  107. 'VL_PHONE' => tohtml($phone),
  108. 'VL_FAX' => tohtml($fax)));
  109. generate_ip_list($tpl, $_SESSION['user_id']);
  110. $_SESSION['local_data'] = "$dmn_name;$hpid";
  111. }
  112. /**
  113. * Init global value with empty values.
  114. *
  115. * @return void
  116. */
  117. function gen_empty_data()
  118. {
  119. global $user_email, $customer_id, $first_name, $last_name, $gender, $firm, $zip,
  120. $city, $state, $country, $street_one, $street_two, $mail, $phone, $fax, $domain_ip;
  121. $user_email = $customer_id = $first_name = $last_name = $firm = $zip = $city =
  122. $state = $country = $street_one = $street_two = $phone = $mail = $fax =
  123. $domain_ip = '';
  124. $gender = 'U';
  125. }
  126. /**
  127. * Save data for new user in db.
  128. *
  129. * @param int $reseller_id Reseller unique identifier
  130. * @return bool TRUE on success, FALSE otherwiser
  131. */
  132. function add_user_data($reseller_id)
  133. {
  134. global $hpid, $dmn_name, $dmn_expire, $dmn_user_name, $admin_login, $user_email,
  135. $customer_id, $first_name, $last_name, $gender, $firm, $zip, $city, $state,
  136. $country, $street_one, $street_two, $mail, $phone, $fax, $inpass, $domain_ip,
  137. $dns, $backup, $software_allowed, $external_mail;
  138. /** @var $cfg iMSCP_Config_Handler_File */
  139. $cfg = iMSCP_Registry::get('config');
  140. if (isset($_SESSION['ch_hpprops'])) {
  141. $props = $_SESSION['ch_hpprops'];
  142. unset($_SESSION['ch_hpprops']);
  143. } else {
  144. if (isset($cfg->HOSTING_PLANS_LEVEL) && $cfg->HOSTING_PLANS_LEVEL === 'admin') {
  145. $query = 'SELECT `props` FROM `hosting_plans` WHERE `id` = ?';
  146. $stmt = exec_query($query, $hpid);
  147. } else {
  148. $query = "SELECT `props` FROM `hosting_plans` WHERE `reseller_id` = ? AND `id` = ?";
  149. $stmt = exec_query($query, array($reseller_id, $hpid));
  150. }
  151. $data = $stmt->fetchRow();
  152. $props = $data['props'];
  153. }
  154. list(
  155. $php, $cgi, $sub, $als, $mail, $ftp, $sql_db, $sql_user, $traff, $disk,
  156. $backup, $dns, $software_allowed, $phpini_system, $phpini_al_allow_url_fopen,
  157. $phpini_al_display_errors, $phpini_al_disable_functions, $phpini_post_max_size,
  158. $phpini_upload_max_filesize, $phpini_max_execution_time,
  159. $phpini_max_input_time, $phpini_memory_limit, $external_mail
  160. ) = array_pad(explode(';', $props), 24, 'no');
  161. $php = preg_replace("/\_/", '', $php);
  162. $cgi = preg_replace("/\_/", '', $cgi);
  163. $backup = preg_replace("/\_/", '', $backup);
  164. $dns = preg_replace("/\_/", '', $dns);
  165. $software_allowed = preg_replace("/\_/", '', $software_allowed);
  166. $external_mail = preg_replace("/\_/", '', $external_mail);
  167. $pure_user_pass = $inpass;
  168. $inpass = cryptPasswordWithSalt($inpass);
  169. $first_name = clean_input($first_name);
  170. $last_name = clean_input($last_name);
  171. $firm = clean_input($firm);
  172. $zip = clean_input($zip);
  173. $city = clean_input($city);
  174. $state = clean_input($state);
  175. $country = clean_input($country);
  176. $phone = clean_input($phone);
  177. $fax = clean_input($fax);
  178. $street_one = clean_input($street_one);
  179. $street_two = clean_input($street_two);
  180. $customer_id = clean_input($customer_id);
  181. if (!validates_dname(decode_idna($dmn_user_name))) {
  182. return false;
  183. }
  184. iMSCP_Events_Manager::getInstance()->dispatch(
  185. iMSCP_Events::onBeforeAddDomain,
  186. array(
  187. 'domainName' => $dmn_name,
  188. 'createdBy' => $reseller_id,
  189. 'customerId' => $customer_id,
  190. 'customerEmail' => $user_email
  191. )
  192. );
  193. $query = "
  194. INSERT INTO
  195. `admin` (
  196. `admin_name`, `admin_pass`, `admin_type`, `domain_created`,
  197. `created_by`, `fname`, `lname`, `firm`, `zip`, `city`, `state`,
  198. `country`, `email`, `phone`, `fax`, `street1`, `street2`,
  199. `customer_id`, `gender`
  200. ) VALUES (
  201. ?, ?, 'user', unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
  202. )
  203. ";
  204. exec_query($query, array(
  205. $dmn_user_name, $inpass, $reseller_id, $first_name,
  206. $last_name, $firm, $zip, $city, $state, $country,
  207. $user_email, $phone, $fax, $street_one, $street_two,
  208. $customer_id, $gender));
  209. /** @var $db iMSCP_Database */
  210. $db = iMSCP_Registry::get('db');
  211. $record_id = $db->insertId();
  212. $query = "
  213. INSERT INTO
  214. `domain` (
  215. `domain_name`, `domain_admin_id`, `domain_created_id`, `domain_created`,
  216. `domain_expires`, `domain_mailacc_limit`, `domain_ftpacc_limit`,
  217. `domain_traffic_limit`, `domain_sqld_limit`, `domain_sqlu_limit`,
  218. `domain_status`, `domain_subd_limit`, `domain_alias_limit`,
  219. `domain_ip_id`, `domain_disk_limit`, `domain_disk_usage`,
  220. `domain_php`, `domain_cgi`, `allowbackup`, `domain_dns`,
  221. `domain_software_allowed`, `phpini_perm_system`, `phpini_perm_allow_url_fopen`,
  222. `phpini_perm_display_errors`, `phpini_perm_disable_functions`, `domain_external_mail`
  223. ) VALUES (
  224. ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
  225. )
  226. ";
  227. exec_query($query, array($dmn_name, $record_id, $reseller_id, time(), $dmn_expire,
  228. $mail, $ftp, $traff, $sql_db, $sql_user,
  229. $cfg->ITEM_ADD_STATUS, $sub, $als, $domain_ip, $disk, 0,
  230. $php, $cgi, $backup, $dns, $software_allowed,
  231. $phpini_system, $phpini_al_allow_url_fopen,
  232. $phpini_al_display_errors, $phpini_al_disable_functions, $external_mail));
  233. $dmn_id = $db->insertId();
  234. iMSCP_Events_Manager::getInstance()->dispatch(
  235. iMSCP_Events::onAfterAddDomain,
  236. array(
  237. 'domainName' => $dmn_name,
  238. 'createdBy' => $reseller_id,
  239. 'customerId' => $record_id,
  240. 'customerEmail' => $user_email,
  241. 'domainId' => $dmn_id
  242. )
  243. );
  244. // save php.ini if exist
  245. if ($phpini_system == 'yes') {
  246. /* @var $phpini iMSCP_PHPini */
  247. $phpini = iMSCP_PHPini::getInstance();
  248. //fill it with the custom values - other thake from default
  249. $phpini->setData('phpiniSystem', 'yes');
  250. $phpini->setData('phpiniPostMaxSize', $phpini_post_max_size);
  251. $phpini->setData('phpiniUploadMaxFileSize', $phpini_upload_max_filesize);
  252. $phpini->setData('phpiniMaxExecutionTime', $phpini_max_execution_time);
  253. $phpini->setData('phpiniMaxInputTime', $phpini_max_input_time);
  254. $phpini->setData('phpiniMemoryLimit', $phpini_memory_limit);
  255. // save it to php_ini table
  256. $phpini->saveCustomPHPiniIntoDb($dmn_id);
  257. }
  258. $query = "
  259. INSERT INTO
  260. `htaccess_users` (
  261. `dmn_id`, `uname`, `upass`, `status`
  262. ) VALUES (
  263. ?, ?, ?, ?
  264. )
  265. ";
  266. exec_query($query, array($dmn_id, $dmn_name,
  267. cryptPasswordWithSalt($pure_user_pass),
  268. $cfg->ITEM_ADD_STATUS));
  269. $user_id = $db->insertId();
  270. $query = "
  271. INSERT INTO
  272. `htaccess_groups` (
  273. `dmn_id`, `ugroup`, `members`, `status`
  274. ) VALUES (
  275. ?, ?, ?, ?
  276. )
  277. ";
  278. exec_query($query, array($dmn_id, $cfg->WEBSTATS_GROUP_AUTH, $user_id, $cfg->ITEM_ADD_STATUS));
  279. // Create default addresses if needed
  280. if ($cfg->CREATE_DEFAULT_EMAIL_ADDRESSES) {
  281. client_mail_add_default_accounts($dmn_id, $user_email, $dmn_name);
  282. }
  283. // let's send mail to user
  284. send_add_user_auto_msg($reseller_id, $dmn_user_name, $pure_user_pass, $user_email,
  285. $first_name, $last_name, tr('User'));
  286. $user_def_lang = $cfg->USER_INITIAL_LANG;
  287. $user_theme_color = $cfg->USER_INITIAL_THEME;
  288. $query = "
  289. INSERT INTO
  290. `user_gui_props` (
  291. `user_id`, `lang`, `layout`
  292. ) VALUES (
  293. ?, ?, ?
  294. )
  295. ";
  296. exec_query($query, array($record_id, $user_def_lang, $user_theme_color));
  297. send_request();
  298. $admin_login = $_SESSION['user_logged'];
  299. write_log("$admin_login: add user: $dmn_user_name (for domain $dmn_name)", E_USER_NOTICE);
  300. write_log("$admin_login: add domain: $dmn_name", E_USER_NOTICE);
  301. update_reseller_c_props($reseller_id);
  302. if (isset($_POST['add_alias']) && $_POST['add_alias'] === 'on') {
  303. $_SESSION['dmn_id'] = $dmn_id;
  304. $_SESSION['dmn_ip'] = $domain_ip;
  305. redirectTo('user_add4.php');
  306. } else {
  307. $_SESSION['user_add3_added'] = '_yes_';
  308. redirectTo('users.php?psi=last');
  309. }
  310. return true;
  311. }
  312. /************************************************************************************
  313. * Main script
  314. */
  315. // Include core library
  316. require 'imscp-lib.php';
  317. iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onResellerScriptStart);
  318. check_login('reseller');
  319. /** @var $cfg iMSCP_Config_Handler_File */
  320. $cfg = iMSCP_Registry::get('config');
  321. $tpl = new iMSCP_pTemplate();
  322. $tpl->define_dynamic(
  323. array(
  324. 'layout' => 'shared/layouts/ui.tpl',
  325. 'page' => 'reseller/user_add3.tpl',
  326. 'page_message' => 'layout',
  327. 'ip_entry' => 'page',
  328. 'alias_feature' => 'page'
  329. )
  330. );
  331. $tpl->assign(
  332. array(
  333. 'TR_PAGE_TITLE' => tr('i-MSCP - User/Add domain account - step 3'),
  334. 'THEME_CHARSET' => tr('encoding'),
  335. 'ISP_LOGO' => layout_getUserLogo(),
  336. 'TR_ADD_USER' => tr('Add user'),
  337. 'TR_CORE_DATA' => tr('Core data'),
  338. 'TR_USERNAME' => tr('Username'),
  339. 'TR_PASSWORD' => tr('Password'),
  340. 'TR_REP_PASSWORD' => tr('Repeat password'),
  341. 'TR_DMN_IP' => tr('Domain IP'),
  342. 'TR_USREMAIL' => tr('Email'),
  343. 'TR_ADDITIONAL_DATA' => tr('Additional data'),
  344. 'TR_CUSTOMER_ID' => tr('Customer ID'),
  345. 'TR_FIRSTNAME' => tr('First name'),
  346. 'TR_LASTNAME' => tr('Last name'),
  347. 'TR_GENDER' => tr('Gender'),
  348. 'TR_MALE' => tr('Male'),
  349. 'TR_FEMALE' => tr('Female'),
  350. 'TR_UNKNOWN' => tr('Unknown'),
  351. 'TR_COMPANY' => tr('Company'),
  352. 'TR_POST_CODE' => tr('Zip/Postal code'),
  353. 'TR_CITY' => tr('City'),
  354. 'TR_STATE_PROVINCE' => tr('State/Province'),
  355. 'TR_COUNTRY' => tr('Country'),
  356. 'TR_STREET1' => tr('Street 1'),
  357. 'TR_STREET2' => tr('Street 2'),
  358. 'TR_MAIL' => tr('Email'),
  359. 'TR_PHONE' => tr('Phone'),
  360. 'TR_FAX' => tr('Fax'),
  361. 'TR_BTN_ADD_USER' => tr('Add user'),
  362. 'TR_ADD_ALIASES' => tr('Add other domains to this account'),
  363. 'VL_USR_PASS' => passgen()));
  364. generateNavigation($tpl);
  365. if (!init_in_values()) {
  366. set_page_message(tr('Data were been altered. Please try again.'), 'error');
  367. unsetMessages();
  368. redirectTo('user_add1.php');
  369. }
  370. if (isset($_POST['uaction']) && ($_POST['uaction'] === 'user_add3_nxt') &&
  371. !isset($_SESSION['step_two_data'])
  372. ) {
  373. if (check_ruser_data($tpl, '_no_')) {
  374. add_user_data($_SESSION['user_id']);
  375. }
  376. } else {
  377. unset($_SESSION['step_two_data']);
  378. gen_empty_data();
  379. }
  380. gen_user_add3_page($tpl);
  381. if (!resellerHasFeature('domain_aliases')) {
  382. $tpl->assign('ALIAS_FEATURE', '');
  383. }
  384. generatePageMessage($tpl);
  385. $tpl->parse('LAYOUT_CONTENT', 'page');
  386. iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onResellerScriptEnd, array('templateEngine' => $tpl));
  387. $tpl->prnt();