ISPConfig module for simplify the creation of websites and DNS zones in a only step
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

227 行
7.4 KiB

  1. <?php
  2. /*
  3. Copyright (c) 2016, Kristián Feldsam, FELDSAM s.r.o. <info@feldsam.cz>
  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_bd_service.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('webdns');
  37. // Loading classes
  38. $app->uses('tpl,tform,remoting,tform_actions,tools_sites,remoting_lib');
  39. $app->load('tform_actions');
  40. class page_action extends tform_actions {
  41. function onSubmit() {
  42. global $app, $conf;
  43. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  44. // check for domain unique name
  45. if($app->db->queryOneRecord('SELECT domain_id FROM domain WHERE domain = "'.$fields['domain'].'"')) {
  46. $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
  47. }
  48. if($app->tform->errorMessage)
  49. {
  50. $this->onError();
  51. return;
  52. }
  53. if($_POST['create'] != 1)
  54. {
  55. $app->tform->errorMessage = 'DUMMY';
  56. $app->tpl->setVar($this->dataRecord);
  57. $this->onShow();
  58. return;
  59. }
  60. // Domain OK, continue
  61. $remote = new remote_actions;
  62. // load template
  63. $template = $app->db->queryOneRecord("SELECT * FROM wizard_template WHERE template_id = ? LIMIT 0,1", $fields['template_id']);
  64. // client prefix and group id
  65. $res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_id']));
  66. $client_group_id = $res['groupid'];
  67. $client_prefix = 'c'.$fields['client_id'];
  68. // add domain
  69. $domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain']));
  70. //---------------------------------------------------
  71. // generate username
  72. $generated_username = $client_prefix.substr(sha1(rand()), 0, 8);
  73. if($fields['db'])
  74. {
  75. // add database user
  76. $db_user_params = array(
  77. 'server_id' => $template['database_server_id'],
  78. 'database_user' => $generated_username,
  79. 'database_password' => substr(sha1(rand()), 0, 10)
  80. );
  81. $db_user_id = $remote->insert_query('../sites/form/database_user.tform.php', $fields['client_id'], $db_user_params, 'sites:web_database_user:on_after_insert');
  82. // add database
  83. $params = array(
  84. 'server_id' => $template['database_server_id'],
  85. 'parent_domain_id' => $site_id,
  86. 'type' => $fields['db_type'],
  87. 'database_quota' => $template['database_quota'],
  88. 'database_name' => $db_user_params['database_user'],
  89. 'database_user_id' => $db_user_id,
  90. 'database_charset' => $template['database_charset'],
  91. 'remote_access' => $template['database_remote_access'],
  92. 'remote_ips' => $template['database_remote_ips'],
  93. 'active' => 'y'
  94. );
  95. $remote->sites_database_add($fields['client_id'], $params);
  96. }
  97. if($fields['ftp']) {
  98. // add ftp user
  99. $ftp_params = array(
  100. 'server_id' => $template['web_server_id'],
  101. 'parent_domain_id' => $site_id,
  102. 'username' => $generated_username,
  103. 'password' => substr(sha1(rand()), 0, 10),
  104. 'quota_size' => $template['hd_quota'],
  105. 'dir' => $site_data['document_root'],
  106. 'uid' => $site_data['system_user'],
  107. 'gid' => $site_data['system_group'],
  108. 'sys_groupid' => $site_data['sys_groupid'],
  109. 'quota_files' => $template['quota_files'],
  110. 'ul_ratio' => $template['ul_ratio'],
  111. 'dl_ratio' => $template['dl_ratio'],
  112. 'ul_bandwidth' => $template['ul_bandwidth'],
  113. 'dl_bandwidth' => $template['dl_bandwidth'],
  114. 'active' => 'y',
  115. );
  116. $remote->insert_query('../sites/form/ftp_user.tform.php', $fields['client_id'], $ftp_params);
  117. }
  118. // results
  119. echo '
  120. <div class="page-header">
  121. <h1>New service</h1>
  122. </div>
  123. <div class="table-wrapper marginTop15">
  124. <table class="table">
  125. <thead class="dark">
  126. <!--tr>
  127. <th colspan="2">'.$fields['domain'].'</th>
  128. </tr--!>
  129. </thead>
  130. <tbody>';
  131. if(isset($db_user_params)) {
  132. echo
  133. '<tr class="info">
  134. <th>DB name/user</th>
  135. <th>DB password</th>
  136. </tr>
  137. <tr>
  138. <td>'.$db_user_params['database_user'].'</td>
  139. <td>'.$db_user_params['database_password'].'</td>
  140. </tr>';
  141. }
  142. if(isset($ftp_params)) {
  143. echo'
  144. <tr class="info">
  145. <th>FTP user</th>
  146. <th>FTP password</th>
  147. </tr>
  148. <tr>
  149. <td>'.$ftp_params['username'].'</td>
  150. <td>'.$ftp_params['password'].'</td>
  151. </tr>';
  152. }
  153. echo'
  154. </tbody>
  155. </table>
  156. </div>
  157. ';
  158. }
  159. }
  160. class remote_actions extends remoting {
  161. public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
  162. return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier);
  163. }
  164. public function sites_database_add($client_id, $params)
  165. {
  166. global $app;
  167. $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
  168. if($sql !== false) {
  169. $app->uses('sites_database_plugin');
  170. $this->id = 0;
  171. $this->dataRecord = $params;
  172. $app->sites_database_plugin->processDatabaseInsert($this);
  173. $retval = $this->insertQueryExecute($sql, $params);
  174. // set correct values for backup_interval and backup_copies
  175. if(isset($params['backup_interval']) || isset($params['backup_copies'])){
  176. $sql_set = array();
  177. if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
  178. if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
  179. //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
  180. $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
  181. }
  182. return $retval;
  183. }
  184. return false;
  185. }
  186. }
  187. $page = new page_action;
  188. $page->onLoad();