PageRenderTime 30ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/gui/public/client/software_install.php

https://bitbucket.org/droidzone/i-mscp
PHP | 340 lines | 268 code | 29 blank | 43 comment | 25 complexity | 02e82a33b35cf127559355d81d76298e MD5 | raw file
  1. <?php
  2. /**
  3. * i-MSCP - internet Multi Server Control Panel
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. *
  19. * @category iMSCP
  20. * @package iMSCP_Core
  21. * @subpackage Client
  22. * @copyright 2010-2013 by i-MSCP team
  23. * @author Sacha Bay <sascha.bay@i-mscp.net>
  24. * @author iMSCP Team
  25. * @link http://www.i-mscp.net i-MSCP Home Site
  26. * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL v2
  27. */
  28. /************************************************************************************
  29. * Script functions
  30. */
  31. /**
  32. * Generate Page.
  33. *
  34. * @param iMSCP_pTemplate $tpl Template engine instance
  35. * @param int $customerId Customer unique identifier
  36. * @return int Software unique identifier
  37. */
  38. function client_generatePage($tpl, $customerId)
  39. {
  40. if (!isset($_GET['id']) || $_GET['id'] == '' || !is_numeric($_GET['id'])) {
  41. showBadRequestErrorPage();
  42. exit; // Uselesss but avoid IDE warning about possible undefined variable
  43. } else {
  44. $softwareId = intval($_GET['id']);
  45. }
  46. $domainProperties = get_domain_default_props($customerId);
  47. get_software_props_install(
  48. $tpl, $domainProperties['domain_id'], $softwareId, $domainProperties['domain_created_id'],
  49. $domainProperties['domain_sqld_limit']);
  50. return $softwareId;
  51. }
  52. /************************************************************************************
  53. * Main program
  54. */
  55. // Include core library
  56. require_once 'imscp-lib.php';
  57. iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onClientScriptStart);
  58. check_login('user');
  59. customerHasFeature('aps') or showBadRequestErrorPage();
  60. /** @var $cfg iMSCP_Config_Handler_File */
  61. $cfg = iMSCP_Registry::get('config');
  62. $tpl = new iMSCP_pTemplate();
  63. $tpl->define_dynamic(
  64. array(
  65. 'layout' => 'shared/layouts/ui.tpl',
  66. 'page' => 'client/software_install.tpl',
  67. 'page_message' => 'layout',
  68. 'software_item' => 'page',
  69. 'show_domain_list' => 'page',
  70. 'software_install' => 'page',
  71. 'no_software' => 'page',
  72. 'installdb_item' => 'page',
  73. 'select_installdb' => 'page',
  74. 'require_installdb' => 'page',
  75. 'select_installdbuser' => 'page',
  76. 'installdbuser_item' => 'page',
  77. 'softwaredbuser_message' => 'page',
  78. 'create_db' => 'page',
  79. 'create_message_db' => 'page'
  80. )
  81. );
  82. if (!empty($_POST)) {
  83. $id = intval($_GET['id']);
  84. $domain_path = '';
  85. $other_dir = clean_input($_POST['other_dir'], true);
  86. $query = "
  87. SELECT
  88. `software_master_id`, `software_db`, `software_name`, `software_version`, `software_language`,
  89. `software_depot`
  90. FROM
  91. `web_software`
  92. WHERE
  93. `software_id` = ?
  94. ";
  95. $stmt = exec_query($query, $_GET['id']);
  96. $install_username = clean_input($_POST['install_username'], true);
  97. $install_password = clean_input($_POST['install_password'], true);
  98. $install_email = clean_input($_POST['install_email'], true);
  99. if (isset($_POST['createdir']) && $_POST['createdir'] == '1') {
  100. $createdir = clean_input($_POST['createdir'], true);
  101. set_page_message(tr('The directory %s was created.', $other_dir), 'success');
  102. } else {
  103. $createdir = '0';
  104. }
  105. // Check dir exists
  106. $domain = $_SESSION['user_logged'];
  107. $vfs = new iMSCP_VirtualFileSystem($domain);
  108. $list = $vfs->ls($other_dir);
  109. // Check dir exists
  110. $domainProps = get_domain_default_props($_SESSION['user_id']);
  111. $dmn_id = $domainProps['domain_id'];
  112. $dmn_name = $domainProps['domain_name'];
  113. $dmn_gid = $domainProps['domain_gid'];
  114. $dmn_uid = $domainProps['domain_uid'];
  115. $dmn_created_id = $domainProps['domain_created_id'];
  116. $dmn_created = $domainProps['domain_created'];
  117. $dmn_last_modified = $domainProps['domain_last_modified'];
  118. $dmn_mailacc_limit = $domainProps['domain_mailacc_limit'];
  119. $dmn_ftpacc_limit = $domainProps['domain_ftpacc_limit'];
  120. $dmn_traff_limit = $domainProps['domain_traffic_limit'];
  121. $dmn_sqld_limit = $domainProps['domain_sqld_limit'];
  122. $dmn_sqlu_limit = $domainProps['domain_sqlu_limit'];
  123. $dmn_status = $domainProps['domain_status'];
  124. $dmn_als_limit = $domainProps['domain_alias_limit'];
  125. $dmn_subd_limit = $domainProps['domain_subd_limit'];
  126. $dmn_ip_id = $domainProps['domain_ip_id'];
  127. $dmn_disk_limit = $domainProps['domain_disk_limit'];
  128. $dmn_disk_usage = $domainProps['domain_disk_usage'];
  129. $dmn_php = $domainProps['domain_php'];
  130. $dmn_cgi = $domainProps['domain_cgi'];
  131. $query = "
  132. SELECT
  133. `software_name` `swname`, `software_version` `swversion`
  134. FROM
  135. `web_software_inst`
  136. WHERE
  137. `domain_id` = ?
  138. AND
  139. `path` = ?
  140. ";
  141. $rspath = exec_query($query, array($dmn_id, $other_dir));
  142. list (
  143. $posted_domain_id, $posted_aliasdomain_id, $posted_subdomain_id, $posted_aliassubdomain_id, $posted_mountpath
  144. ) = explode(';', $_POST['selected_domain']);
  145. if (($posted_aliasdomain_id + $posted_subdomain_id + $posted_aliassubdomain_id) > 0) {
  146. if ($posted_aliasdomain_id > 0) {
  147. $query = "SELECT `alias_mount` `domainpath` FROM `domain_aliasses` WHERE `alias_id` = ?";
  148. $rsdomainpath = exec_query($query, $posted_aliasdomain_id);
  149. $domain_path = $rsdomainpath->fields['domainpath'];
  150. $domain_path = str_replace("/", "\/", $domain_path);
  151. } elseif ($posted_subdomain_id > 0) {
  152. $query = "SELECT `subdomain_mount` `domainpath` FROM `subdomain` WHERE `subdomain_id` = ?";
  153. $rsdomainpath = exec_query($query, $posted_subdomain_id);
  154. $domain_path = $rsdomainpath->fields['domainpath'];
  155. $domain_path = str_replace("/", "\/", $domain_path);
  156. } elseif ($posted_aliassubdomain_id > 0) {
  157. $query = "SELECT `subdomain_alias_mount` `domainpath` FROM `subdomain_alias` WHERE `subdomain_alias_id` = ?";
  158. $rsdomainpath = exec_query($query, $posted_aliassubdomain_id);
  159. $domain_path = $rsdomainpath->fields['domainpath'];
  160. $domain_path = str_replace("/", "\/", $domain_path);
  161. } else {
  162. $domain_path = $posted_mountpath;
  163. }
  164. } else {
  165. $domain_path = $posted_mountpath;
  166. }
  167. if ($stmt->fields['software_db'] == "1") {
  168. $selected_db = clean_input($_POST['selected_db'], true);
  169. $sql_user = clean_input($_POST['sql_user'], true);
  170. $query = "SELECT `sqlu_pass` FROM `sql_user` WHERE `sqlu_name` = ?";
  171. $rsdatabase = exec_query($query, $sql_user);
  172. $db_connection_ok = check_db_connection($selected_db, $sql_user, $rsdatabase->fields['sqlu_pass']);
  173. $sql_pass = $rsdatabase->fields['sqlu_pass'];
  174. }
  175. if ($stmt->fields['software_db'] == '1' && !$db_connection_ok) {
  176. set_page_message(tr('Please select a valid SQL user for the database.'), 'error');
  177. } elseif (empty($install_username) || empty($install_password) || empty($install_email)) {
  178. set_page_message(tr('All fields are required.'), 'error');
  179. } elseif (!preg_match('/htdocs/', $other_dir)) {
  180. set_page_message(tr("You cant't install the software outside the htdocs directory."), 'error');
  181. } elseif (($posted_aliasdomain_id + $posted_subdomain_id + $posted_aliassubdomain_id) > 0 && !preg_match("/" . $domain_path . "/", $other_dir)) {
  182. set_page_message(tr("You have chosen a directory which doesn't matches the domain directory."), 'error');
  183. } elseif (!$list && $createdir == '0') {
  184. set_page_message(tr("The directory %s doesn't exist. Please create it first.", $other_dir), 'error');
  185. } elseif ($rspath->recordCount() > 0) {
  186. set_page_message(tr('Please select another directory. %s (%s) is installed there.', $rspath->fields['swname'], $rspath->fields['swversion']), 'error');
  187. } elseif (checkPasswordSyntax($install_password)) {
  188. $sw_db_required = $stmt->fields['software_db'];
  189. $sw_software_name = $stmt->fields['software_name'];
  190. $sw_software_version = $stmt->fields['software_version'];
  191. $software_master_id = $stmt->fields['software_master_id'];
  192. $software_depot = $stmt->fields['software_depot'];
  193. $software_language = $stmt->fields['software_language'];
  194. $query = "SELECT `software_prefix` FROM `web_software` WHERE `software_id` = ?";
  195. $stmt = exec_query($query, $_GET['id']);
  196. $prefix = $stmt->fields['software_prefix'];
  197. if ($sw_db_required == '1') {
  198. $query = "
  199. INSERT INTO `web_software_inst` (
  200. `domain_id`, `alias_id`, `subdomain_id`, `subdomain_alias_id`,
  201. `software_id`, `software_master_id`, `software_name`,
  202. `software_version`, `software_language`, `path`, `software_prefix`,
  203. `db`, `database_user`, `database_tmp_pwd`, `install_username`,
  204. `install_password`, `install_email`, `software_status`, `software_depot`
  205. ) VALUES (
  206. ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
  207. )
  208. ";
  209. $stmt = exec_query(
  210. $query,
  211. array(
  212. $dmn_id, $posted_aliasdomain_id, $posted_subdomain_id, $posted_aliassubdomain_id, $id,
  213. $software_master_id, $sw_software_name, $sw_software_version, $software_language,
  214. $other_dir, $prefix, $selected_db, $sql_user, $sql_pass, $install_username, $install_password,
  215. $install_email, $cfg->ITEM_ADD_STATUS, $software_depot));
  216. } else {
  217. $query = "
  218. INSERT INTO `web_software_inst` (
  219. `domain_id`, `alias_id`, `subdomain_id`, `subdomain_alias_id`, `software_id`, `software_master_id`,
  220. `software_name`, `software_version`, `software_language`, `path`, `software_prefix`, `db`,
  221. `database_user`, `database_tmp_pwd`, `install_username`, `install_password`, `install_email`,
  222. `software_status`, `software_depot`
  223. ) VALUES (
  224. ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
  225. )
  226. ";
  227. $stmt = exec_query(
  228. $query,
  229. array(
  230. $dmn_id, $posted_aliasdomain_id, $posted_subdomain_id, $posted_aliassubdomain_id, $id,
  231. $software_master_id, $sw_software_name, $sw_software_version, $software_language, $other_dir,
  232. "not_required", "not_required", "not_required", "not_required", $install_username, $install_password,
  233. $install_email, $cfg->ITEM_ADD_STATUS, $software_depot));
  234. }
  235. send_request();
  236. redirectTo('software.php');
  237. }
  238. if ($stmt->fields['software_db'] == '1') {
  239. $tpl->assign(
  240. array(
  241. 'VAL_OTHER_DIR' => $other_dir,
  242. 'CHECKED_CREATEDIR' => ($createdir == '1') ? $cfg->HTML_CHECKED : '',
  243. 'VAL_INSTALL_USERNAME' => $install_username,
  244. 'VAL_INSTALL_PASSWORD' => $install_password,
  245. 'VAL_INSTALL_EMAIL' => $install_email
  246. )
  247. );
  248. } else {
  249. $tpl->assign(
  250. array(
  251. 'VAL_OTHER_DIR' => $other_dir,
  252. 'CHECKED_CREATEDIR' => ($createdir == '1') ? $cfg->HTML_CHECKED : '',
  253. 'VAL_INSTALL_USERNAME' => $install_username,
  254. 'VAL_INSTALL_PASSWORD' => $install_password,
  255. 'VAL_INSTALL_EMAIL' => $install_email
  256. )
  257. );
  258. }
  259. } else {
  260. $tpl->assign(
  261. array(
  262. 'VAL_OTHER_DIR' => '/htdocs',
  263. 'CHECKED_CREATEDIR' => '',
  264. 'VAL_INSTALL_USERNAME' => '',
  265. 'VAL_INSTALL_PASSWORD' => '',
  266. 'VAL_INSTALL_EMAIL' => ''
  267. )
  268. );
  269. }
  270. $tpl->assign(
  271. array(
  272. 'TR_PAGE_TITLE' => tr('i-MSCP - Install Software'),
  273. 'THEME_CHARSET' => tr('encoding'),
  274. 'ISP_LOGO' => layout_getUserLogo(),
  275. 'TR_INSTALL_SOFTWARE' => tr('Install Software'),
  276. 'SOFTWARE_ID' => client_generatePage($tpl, $_SESSION['user_id']),
  277. 'TR_NAME' => tr('Software'),
  278. 'TR_TYPE' => tr('Type'),
  279. 'TR_DB' => tr('Database required'),
  280. 'TR_SELECT_DOMAIN' => tr('Select Domain'),
  281. 'TR_BACK' => tr('back'),
  282. 'TR_INSTALL' => tr('install'),
  283. 'TR_PATH' => tr('Install path'),
  284. 'CHOOSE_DIR' => tr('Choose dir'),
  285. 'CREATEDIR_MESSAGE' => tr('Create directory, if not exist!'),
  286. 'TR_SELECT_DB' => tr('Select database'),
  287. 'TR_SQL_USER' => tr('SQL-User'),
  288. 'TR_SQL_PWD' => tr('Password'),
  289. 'TR_SOFTWARE_MENU' => tr('Software installation'),
  290. 'TR_INSTALLATION' => tr('Installation details'),
  291. 'TR_INSTALLATION_INFORMATION' => tr('Username and password for application login'),
  292. 'TR_INSTALL_USER' => tr('Login username'),
  293. 'TR_INSTALL_PWD' => tr('Login password'),
  294. 'TR_INSTALL_EMAIL' => tr('Email address')));
  295. generateNavigation($tpl);
  296. generatePageMessage($tpl);
  297. $tpl->parse('LAYOUT_CONTENT', 'page');
  298. iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onClientScriptEnd, array('templateEngine' => $tpl));
  299. $tpl->prnt();
  300. unsetMessages();