ISPConfig module for simplify the creation of websites and DNS zones in a only step
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

222 líneas
8.8 KiB

  1. <?php
  2. /*
  3. Copyright (c) 2007, Till Brehm, projektfarm Gmbh
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without modification,
  6. are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. * Neither the name of ISPConfig nor the names of its contributors
  13. may be used to endorse or promote products derived from this software without
  14. specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  19. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  20. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  24. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /******************************************
  27. * Begin Form configuration
  28. ******************************************/
  29. $tform_def_file = "form/ftp_user.tform.php";
  30. /******************************************
  31. * End Form configuration
  32. ******************************************/
  33. require_once '../../lib/config.inc.php';
  34. require_once '../../lib/app.inc.php';
  35. //* Check permissions for module
  36. $app->auth->check_module_permissions('sites');
  37. // Loading classes
  38. $app->uses('tpl,tform,tform_actions');
  39. $app->load('tform_actions');
  40. class page_action extends tform_actions {
  41. function onShowNew() {
  42. global $app, $conf;
  43. // we will check only users, not admins
  44. if($_SESSION["s"]["user"]["typ"] == 'user') {
  45. if(!$app->tform->checkClientLimit('limit_ftp_user')) {
  46. $app->error($app->tform->wordbook["limit_ftp_user_txt"]);
  47. }
  48. if(!$app->tform->checkResellerLimit('limit_ftp_user')) {
  49. $app->error('Reseller: '.$app->tform->wordbook["limit_ftp_user_txt"]);
  50. }
  51. }
  52. parent::onShowNew();
  53. }
  54. function onShowEnd() {
  55. global $app, $conf, $interfaceConf;
  56. /*
  57. * If the names are restricted -> remove the restriction, so that the
  58. * data can be edited
  59. */
  60. $app->uses('getconf,tools_sites');
  61. $global_config = $app->getconf->get_global_config('sites');
  62. $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
  63. if ($this->dataRecord['username'] != ""){
  64. /* REMOVE the restriction */
  65. $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix));
  66. }
  67. if($this->dataRecord['username'] == "") {
  68. $app->tpl->setVar("username_prefix", $ftpuser_prefix);
  69. } else {
  70. $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix']));
  71. }
  72. parent::onShowEnd();
  73. }
  74. function onSubmit() {
  75. global $app, $conf;
  76. // Get the record of the parent domain
  77. if(isset($this->dataRecord["parent_domain_id"])) {
  78. $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]);
  79. if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
  80. } else {
  81. $tmp = $app->tform->getDataRecord($this->id);
  82. $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), $tmp["parent_domain_id"]);
  83. if(!$parent_domain) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
  84. unset($tmp);
  85. }
  86. // Set a few fixed values
  87. $this->dataRecord["server_id"] = $parent_domain["server_id"];
  88. //die(print_r($this->dataRecord));
  89. if(isset($this->dataRecord['username']) && trim($this->dataRecord['username']) == '') $app->tform->errorMessage .= $app->tform->lng('username_error_empty').'<br />';
  90. if(isset($this->dataRecord['username']) && empty($this->dataRecord['parent_domain_id'])) $app->tform->errorMessage .= $app->tform->lng('parent_domain_id_error_empty').'<br />';
  91. if(isset($this->dataRecord['dir']) && stristr($this->dataRecord['dir'], '..')) $app->tform->errorMessage .= $app->tform->lng('dir_dot_error').'<br />';
  92. if(isset($this->dataRecord['dir']) && stristr($this->dataRecord['dir'], './')) $app->tform->errorMessage .= $app->tform->lng('dir_slashdot_error').'<br />';
  93. parent::onSubmit();
  94. }
  95. function onBeforeInsert() {
  96. global $app, $conf, $interfaceConf;
  97. $app->uses('getconf,tools_sites');
  98. $global_config = $app->getconf->get_global_config('sites');
  99. $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
  100. $this->dataRecord['username_prefix'] = $ftpuser_prefix;
  101. if ($app->tform->errorMessage == '') {
  102. $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username'];
  103. }
  104. parent::onBeforeInsert();
  105. }
  106. function onAfterInsert() {
  107. global $app, $conf;
  108. $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
  109. $server_id = $app->functions->intval($web["server_id"]);
  110. $dir = $web["document_root"];
  111. $uid = $web["system_user"];
  112. $gid = $web["system_group"];
  113. // Check system user and group
  114. if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) {
  115. $app->error('Invalid system user or group');
  116. }
  117. // The FTP user shall be owned by the same group then the website
  118. $sys_groupid = $app->functions->intval($web['sys_groupid']);
  119. $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?";
  120. $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id);
  121. }
  122. function onBeforeUpdate() {
  123. global $app, $conf, $interfaceConf;
  124. /*
  125. * If the names should be restricted -> do it!
  126. */
  127. $app->uses('getconf,tools_sites');
  128. $global_config = $app->getconf->get_global_config('sites');
  129. $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
  130. $old_record = $app->tform->getDataRecord($this->id);
  131. $ftpuser_prefix = $app->tools_sites->getPrefix($old_record['username_prefix'], $ftpuser_prefix);
  132. $this->dataRecord['username_prefix'] = $ftpuser_prefix;
  133. /* restrict the names */
  134. if ($app->tform->errorMessage == '') {
  135. $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username'];
  136. }
  137. }
  138. function onAfterUpdate() {
  139. global $app, $conf;
  140. //* When the site of the FTP user has been changed
  141. if(isset($this->dataRecord['parent_domain_id']) && $this->oldDataRecord['parent_domain_id'] != $this->dataRecord['parent_domain_id']) {
  142. $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
  143. $server_id = $app->functions->intval($web["server_id"]);
  144. $dir = $web["document_root"];
  145. $uid = $web["system_user"];
  146. $gid = $web["system_group"];
  147. // The FTP user shall be owned by the same group then the website
  148. $sys_groupid = $app->functions->intval($web['sys_groupid']);
  149. $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?";
  150. $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id);
  151. }
  152. //* 2. check to ensure that the FTP user path is not changed to a path outside of the docroot by a normal user
  153. if(isset($this->dataRecord['dir']) && $this->dataRecord['dir'] != $this->oldDataRecord['dir'] && !$app->auth->is_admin()) {
  154. $vd = new validate_ftpuser;
  155. $error_message = $vd->ftp_dir('dir', $this->dataRecord['dir'], '');
  156. //* This check should normally never be triggered
  157. //* Set the path to a safe path (web doc root).
  158. if($error_message != '') {
  159. $ftp_data = $app->db->queryOneRecord("SELECT parent_domain_id FROM ftp_user WHERE ftp_user_id = ?", $app->tform->primary_id);
  160. $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $ftp_data["parent_domain_id"]);
  161. $dir = $web["document_root"];
  162. $sql = "UPDATE ftp_user SET dir = ? WHERE ftp_user_id = ?";
  163. $app->db->query($sql, $dir, $this->id);
  164. $app->log("Error in FTP path settings of FTP user ".$this->dataRecord['username'], 1);
  165. }
  166. }
  167. }
  168. }
  169. $page = new page_action;
  170. $page->onLoad();
  171. ?>