Marius Cramer
2014-08-13 42539643c396f9d8865dcf9a51b13dc869709d16
commit | author | age
18341e 1 <?php
T 2 /*
3 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/web_aliasdomain.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
7fe908 41 require_once '../../lib/config.inc.php';
MC 42 require_once '../../lib/app.inc.php';
18341e 43
910093 44 //* Check permissions for module
T 45 $app->auth->check_module_permissions('sites');
18341e 46
T 47 // Loading classes
10b4c8 48 $app->uses('tpl,tform,tform_actions,tools_sites');
18341e 49 $app->load('tform_actions');
T 50
51 class page_action extends tform_actions {
7fe908 52
d4d985 53     var $parent_domain_record;
7fe908 54
4fae7e 55     function onShowNew() {
T 56         global $app, $conf;
7fe908 57
4fae7e 58         // we will check only users, not admins
T 59         if($_SESSION["s"]["user"]["typ"] == 'user') {
7fe908 60             if(!$app->tform->checkClientLimit('limit_web_aliasdomain', "type = 'alias'")) {
3cebc3 61                 $app->error($app->tform->wordbook["limit_web_aliasdomain_txt"]);
T 62             }
7fe908 63             if(!$app->tform->checkResellerLimit('limit_web_aliasdomain', "type = 'alias'")) {
3cebc3 64                 $app->error('Reseller: '.$app->tform->wordbook["limit_web_aliasdomain_txt"]);
4fae7e 65             }
T 66         }
7fe908 67
4fae7e 68         parent::onShowNew();
T 69     }
7fe908 70
18341e 71     function onShowEnd() {
T 72         global $app, $conf;
7fe908 73
05457e 74         /*
V 75          * Now we have to check, if we should use the domain-module to select the domain
76          * or not
77          */
78         $app->uses('ini_parser,getconf');
79         $settings = $app->getconf->get_global_config('domains');
80         if ($settings['use_domain_module'] == 'y') {
81             /*
82              * The domain-module is in use.
83             */
10b4c8 84             $domains = $app->tools_sites->getDomainModuleDomains();
05457e 85             $domain_select = '';
V 86             if(is_array($domains) && sizeof($domains) > 0) {
87                 /* We have domains in the list, so create the drop-down-list */
88                 foreach( $domains as $domain) {
4e18bd 89                     $domain_select .= "<option value=" . $domain['domain_id'] ;
05457e 90                     if ($domain['domain'] == $this->dataRecord["domain"]) {
V 91                         $domain_select .= " selected";
92                     }
8c1761 93                     $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n";
05457e 94                 }
V 95             }
96             else {
97                 /*
98                  * We have no domains in the domain-list. This means, we can not add ANY new domain.
99                  * To avoid, that the variable "domain_option" is empty and so the user can
100                  * free enter a domain, we have to create a empty option!
101                 */
102                 $domain_select .= "<option value=''></option>\r\n";
103             }
7fe908 104             $app->tpl->setVar("domain_option", $domain_select);
05457e 105         }
7fe908 106
bfcdef 107         if($_SESSION["s"]["user"]["typ"] == 'admin') {
7fe908 108             // Directive Snippets
bfcdef 109             $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y'");
T 110             $proxy_directive_snippets_txt = '';
111             if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
112                 foreach($proxy_directive_snippets as $proxy_directive_snippet){
113                     $proxy_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$proxy_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.$proxy_directive_snippet['snippet'].'</pre></a> ';
114                 }
115             }
116             if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------';
7fe908 117             $app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt);
bfcdef 118         }
7fe908 119
18341e 120         parent::onShowEnd();
7fe908 121
18341e 122     }
T 123
124     function onSubmit() {
125         global $app, $conf;
896a58 126         
FT 127         // Get the record of the parent domain
128         if(!@$this->dataRecord["parent_domain_id"] && $this->id) {
129             $tmp = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
130             if($tmp) $this->dataRecord["parent_domain_id"] = $tmp['parent_domain_id'];
131             unset($tmp);
132         }
7fe908 133
9a02e2 134         // Get the record of the parent domain
MC 135         $parent_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval(@$this->dataRecord["parent_domain_id"]) . " AND ".$app->tform->getAuthSQL('r'));
896a58 136         
9a02e2 137         if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
7fe908 138         /* check if the domain module is used - and check if the selected domain can be used! */
4e18bd 139         $app->uses('ini_parser,getconf');
M 140         $settings = $app->getconf->get_global_config('domains');
141         if ($settings['use_domain_module'] == 'y') {
7fe908 142             $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']);
MC 143             if(!$domain_check) {
144                 // invalid domain selected
145                 $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
146             } else {
147                 $this->dataRecord['domain'] = $domain_check;
148             }
149         }
150
43b345 151         // nginx: if redirect type is proxy and redirect path is no URL, display error
7fe908 152         if($this->dataRecord["redirect_type"] == 'proxy' && substr($this->dataRecord['redirect_path'], 0, 1) == '/'){
43b345 153             $app->tform->errorMessage .= $app->tform->lng("error_proxy_requires_url")."<br />";
T 154         }
7fe908 155
18341e 156         // Set a few fixed values
T 157         $this->dataRecord["type"] = 'alias';
158         $this->dataRecord["server_id"] = $parent_domain["server_id"];
7fe908 159
d4d985 160         $this->parent_domain_record = $parent_domain;
7fe908 161
8cf78b 162         //* make sure that the domain is lowercase
04620b 163         if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
896a58 164         
18341e 165         parent::onSubmit();
T 166     }
7fe908 167
d4d985 168     function onAfterInsert() {
T 169         global $app, $conf;
7fe908 170
65ea2e 171         $app->db->query('UPDATE web_domain SET sys_groupid = '.$app->functions->intval($this->parent_domain_record['sys_groupid']).' WHERE domain_id = '.$this->id);
7fe908 172
d4d985 173     }
7fe908 174
8cf78b 175     function onAfterUpdate() {
T 176         global $app, $conf;
7fe908 177
8cf78b 178         //* Check if parent domain has been changed
T 179         if($this->dataRecord['parent_domain_id'] != $this->oldDataRecord['parent_domain_id']) {
7fe908 180
8cf78b 181             //* Update the domain owner
65ea2e 182             $app->db->query('UPDATE web_domain SET sys_groupid = '.$app->functions->intval($this->parent_domain_record['sys_groupid']).' WHERE domain_id = '.$this->id);
7fe908 183
8cf78b 184             //* Update the old website, so that the vhost alias gets removed
T 185             //* We force the update by inserting a transaction record without changes manually.
604c0c 186             $old_website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$app->functions->intval($this->oldDataRecord['domain_id']));
9a02e2 187             $app->db->datalogSave('web_domain', 'UPDATE', 'domain_id', $app->functions->intval($this->oldDataRecord['parent_domain_id']), $old_website, $old_website, true);
8cf78b 188         }
7fe908 189
8cf78b 190     }
7fe908 191
18341e 192 }
T 193
194 $page = new page_action;
195 $page->onLoad();
196
7fe908 197 ?>