|
- <?php
- /*
- Copyright (c) 2016, Kristián Feldsam, FELDSAM s.r.o. <info@feldsam.cz>
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of ISPConfig nor the names of its contributors
- may be used to endorse or promote products derived from this software without
- specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
- /******************************************
- * Begin Form configuration
- ******************************************/
-
- $tform_def_file = "form/ftp_bd_service.tform.php";
-
- /******************************************
- * End Form configuration
- ******************************************/
-
- require_once '../../lib/config.inc.php';
- require_once '../../lib/app.inc.php';
-
- //* Check permissions for module
- $app->auth->check_module_permissions('webdns');
-
- // Loading classes
- $app->uses('tpl,tform,remoting,tform_actions,tools_sites,remoting_lib');
- $app->load('tform_actions');
-
- class page_action extends tform_actions {
-
-
- function onSubmit() {
- global $app, $conf;
-
- $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
-
- // check for domain unique name
- if($app->db->queryOneRecord('SELECT domain_id FROM domain WHERE domain = "'.$fields['domain'].'"')) {
- $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
- }
-
- if($app->tform->errorMessage)
- {
- $this->onError();
- return;
- }
-
- if($_POST['create'] != 1)
- {
- $app->tform->errorMessage = 'DUMMY';
- $app->tpl->setVar($this->dataRecord);
- $this->onShow();
- return;
- }
-
- // Domain OK, continue
- $remote = new remote_actions;
-
- // load template
- $template = $app->db->queryOneRecord("SELECT * FROM wizard_template WHERE template_id = ? LIMIT 0,1", $fields['template_id']);
-
- // client prefix and group id
- $res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_id']));
- $client_group_id = $res['groupid'];
- $client_prefix = 'c'.$fields['client_id'];
-
- // add domain
- $domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain']));
-
- //---------------------------------------------------
- // generate username
- $generated_username = $client_prefix.substr(sha1(rand()), 0, 8);
-
- if($fields['db'])
- {
- // add database user
- $db_user_params = array(
- 'server_id' => $template['database_server_id'],
- 'database_user' => $generated_username,
- 'database_password' => substr(sha1(rand()), 0, 10)
- );
- $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');
-
- // add database
- $params = array(
- 'server_id' => $template['database_server_id'],
- 'parent_domain_id' => $site_id,
- 'type' => $fields['db_type'],
- 'database_quota' => $template['database_quota'],
- 'database_name' => $db_user_params['database_user'],
- 'database_user_id' => $db_user_id,
- 'database_charset' => $template['database_charset'],
- 'remote_access' => $template['database_remote_access'],
- 'remote_ips' => $template['database_remote_ips'],
- 'active' => 'y'
- );
- $remote->sites_database_add($fields['client_id'], $params);
- }
-
- if($fields['ftp']) {
- // add ftp user
- $ftp_params = array(
- 'server_id' => $template['web_server_id'],
- 'parent_domain_id' => $site_id,
- 'username' => $generated_username,
- 'password' => substr(sha1(rand()), 0, 10),
- 'quota_size' => $template['hd_quota'],
- 'dir' => $site_data['document_root'],
- 'uid' => $site_data['system_user'],
- 'gid' => $site_data['system_group'],
- 'sys_groupid' => $site_data['sys_groupid'],
- 'quota_files' => $template['quota_files'],
- 'ul_ratio' => $template['ul_ratio'],
- 'dl_ratio' => $template['dl_ratio'],
- 'ul_bandwidth' => $template['ul_bandwidth'],
- 'dl_bandwidth' => $template['dl_bandwidth'],
- 'active' => 'y',
- );
- $remote->insert_query('../sites/form/ftp_user.tform.php', $fields['client_id'], $ftp_params);
- }
-
-
- // results
- echo '
- <div class="page-header">
- <h1>New service</h1>
- </div>
- <div class="table-wrapper marginTop15">
- <table class="table">
- <thead class="dark">
- <!--tr>
- <th colspan="2">'.$fields['domain'].'</th>
- </tr--!>
- </thead>
- <tbody>';
- if(isset($db_user_params)) {
- echo
- '<tr class="info">
- <th>DB name/user</th>
- <th>DB password</th>
- </tr>
- <tr>
- <td>'.$db_user_params['database_user'].'</td>
- <td>'.$db_user_params['database_password'].'</td>
- </tr>';
- }
- if(isset($ftp_params)) {
- echo'
- <tr class="info">
- <th>FTP user</th>
- <th>FTP password</th>
- </tr>
- <tr>
- <td>'.$ftp_params['username'].'</td>
- <td>'.$ftp_params['password'].'</td>
- </tr>';
- }
-
- echo'
- </tbody>
- </table>
- </div>
- ';
- }
-
- }
-
- class remote_actions extends remoting {
- public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
- return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier);
- }
-
- public function sites_database_add($client_id, $params)
- {
- global $app;
-
- $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
- if($sql !== false) {
- $app->uses('sites_database_plugin');
-
- $this->id = 0;
- $this->dataRecord = $params;
- $app->sites_database_plugin->processDatabaseInsert($this);
-
- $retval = $this->insertQueryExecute($sql, $params);
-
- // set correct values for backup_interval and backup_copies
- if(isset($params['backup_interval']) || isset($params['backup_copies'])){
- $sql_set = array();
- if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
- if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
- //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
- $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
- }
-
- return $retval;
- }
-
- return false;
- }
- }
-
- $page = new page_action;
- $page->onLoad();
|