Falko Timme
2015-01-07 8173c6f28d9fd55fa249d76330bf7709923c4fcd
commit | author | age
0ae8da 1 <?php
F 2
3 /*
4 Copyright (c) 2005, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
7fe908 31 require_once '../../lib/config.inc.php';
MC 32 require_once '../../lib/app.inc.php';
0ae8da 33
F 34 //* Check permissions for module
35 $app->auth->check_module_permissions('sites');
36
7b47c0 37 $app->uses('getconf,tform');
b4687b 38
65ea2e 39 $server_id = $app->functions->intval($_GET["server_id"]);
M 40 $web_id = $app->functions->intval($_GET["web_id"]);
62e4b3 41 $php_type = $_GET["php_type"];
7b47c0 42 $client_group_id = $app->functions->intval($_GET['client_group_id']);
0ae8da 43 $type = $_GET["type"];
F 44
6882ab 45 //if($_SESSION["s"]["user"]["typ"] == 'admin') {
0ae8da 46
7fe908 47 if($type == 'getservertype'){
MC 48     $json = '{"servertype":"';
49     $server_type = 'apache';
50     $web_config = $app->getconf->get_server_config($server_id, 'web');
51     if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
52     $json .= $server_type;
53     unset($webconfig);
54     $json .= '"}';
55 }
5672cd 56
7fe908 57 if($type == 'getserverid'){
MC 58     $json = '{"serverid":"';
59     $sql = "SELECT server_id FROM web_domain WHERE domain_id = $web_id AND ".$app->tform->getAuthSQL('r');
60     $server = $app->db->queryOneRecord($sql);
61     $json .= $server['server_id'];
62     unset($server);
63     $json .= '"}';
64 }
65
66 if($type == 'getphpfastcgi'){
67     $json = '{';
68
69     $server_type = 'apache';
70     $web_config = $app->getconf->get_server_config($server_id, 'web');
71     if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
72     if($server_type == 'nginx' && $php_type == 'fast-cgi') $php_type = 'php-fpm';
73     $sql_where = '';
74
75     //* Client: If the logged in user is not admin and has no sub clients (no reseller)
76     if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
604c0c 77         $sql_where = " AND (client_id = 0 OR client_id = ".$app->functions->intval($_SESSION["s"]["user"]["client_id"]) . ")";
7fe908 78         //* Reseller: If the logged in user is not admin and has sub clients (is a reseller)
MC 79     } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
80         $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = $client_group_id");
81         //$sql_where = " AND (client_id = 0 OR client_id = ".$_SESSION["s"]["user"]["client_id"];
82         $sql_where = " AND (client_id = 0";
83         if($app->functions->intval($client['client_id']) > 0) $sql_where .= " OR client_id = ".$app->functions->intval($client['client_id']);
84         $sql_where .= ")";
85         //* Admin: If the logged in user is admin
86     } else {
87         //$sql_where = '';
88         $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = $client_group_id");
89         //$sql_where = " AND (client_id = 0 OR client_id = ".$_SESSION["s"]["user"]["client_id"];
90         $sql_where = " AND (client_id = 0";
91         if($app->functions->intval($client['client_id']) > 0) $sql_where .= " OR client_id = ".$app->functions->intval($client['client_id']);
92         $sql_where .= ")";
5672cd 93     }
7fe908 94
MC 95     if($php_type == 'php-fpm'){
96         $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = $server_id".$sql_where);
5672cd 97     }
7fe908 98     if($php_type == 'fast-cgi'){
MC 99         $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = $server_id".$sql_where);
10b4c8 100     }
7fe908 101     $php_select = "";
MC 102     if(is_array($php_records) && !empty($php_records)) {
103         foreach( $php_records as $php_record) {
104             if($php_type == 'php-fpm'){
105                 $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
106             } else {
107                 $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
108             }
109             $json .= '"'.$php_version.'": "'.$php_record['name'].'",';
110         }
10b4c8 111     }
7fe908 112     unset($php_records);
MC 113     if(substr($json, -1) == ',') $json = substr($json, 0, -1);
114     $json .= '}';
115 }
116
117 if($type == 'getphptype'){
118     $json = '{"phptype":"';
119     $sql = "SELECT php FROM web_domain WHERE domain_id = $web_id AND ".$app->tform->getAuthSQL('r');
120     $php = $app->db->queryOneRecord($sql);
121     $json .= $php['php'];
122     unset($php);
123     $json .= '"}';
124 }
125
126 if($type == 'getredirecttype'){
127     $json = '{"redirecttype":"';
128     $sql = "SELECT redirect_type FROM web_domain WHERE domain_id = $web_id AND ".$app->tform->getAuthSQL('r');
129     $redirect = $app->db->queryOneRecord($sql);
130     $json .= $redirect['redirect_type'];
131     unset($redirect);
132     $json .= '"}';
133 }
134
135 if($type == 'get_ipv4'){
136     $result = array();
137
138     // ipv4
139     //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")");
140     $result[] = $app->functions->suggest_ips('IPv4');
141
142     $json = $app->functions->json_encode($result);
143 }
144
145 if($type == 'get_ipv6'){
146     $result = array();
147
148     // ipv6
149     //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")");
150     $result[] = $app->functions->suggest_ips('IPv6');
151
152     $json = $app->functions->json_encode($result);
153 }
154
155 if($type == 'getdatabaseusers') {
156     $json = '{}';
157
158     $sql = "SELECT sys_groupid FROM web_domain WHERE domain_id = $web_id AND ".$app->tform->getAuthSQL('r');
159     $group = $app->db->queryOneRecord($sql);
160     if($group) {
604c0c 161         $sql = "SELECT database_user_id, database_user FROM web_database_user WHERE sys_groupid = '" . $app->functions->intval($group['sys_groupid']) . "'";
7fe908 162         $records = $app->db->queryAllRecords($sql);
MC 163
164         $tmp_array = array();
165         foreach($records as $record) {
166             $tmp_array[$record['database_user_id']] = $record['database_user'];
167         }
168         $json = $app->functions->json_encode($tmp_array);
169         unset($records, $group, $tmp_array);
170     }
171 }
172
173 if($type == 'get_use_combobox'){
174     $json = '{"usecombobox":"';
175     $use_combobox = 'y';
176     $server_config_array = $app->getconf->get_global_config();
177     if($server_config_array['misc']['use_combobox'] != 'y') $use_combobox = 'n';
178     $json .= $use_combobox;
179     unset($server_config_array);
180     $json .= '"}';
181 }
182
183 if($type == 'get_use_loadindicator'){
184     $json = '{"useloadindicator":"';
185     $use_loadindicator = 'y';
186     $server_config_array = $app->getconf->get_global_config();
187     if($server_config_array['misc']['use_loadindicator'] != 'y') $use_loadindicator = 'n';
188     $json .= $use_loadindicator;
189     unset($server_config_array);
190     $json .= '"}';
191 }
0ae8da 192
1fa8f4 193 if ($type == 'getdirectivesnippet') {
FT 194     $server_type = 'apache';
195     $web_config = $app->getconf->get_server_config($server_id, 'web');
196     if (!empty($web_config['server_type']))
197         $server_type = $web_config['server_type'];
198
199     $snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND type = ? ORDER BY name ASC", $server_type);
200
201     $json = json_encode($snippets);
202 }
203
8173c6 204 if($type == 'getclientssldata'){
FT 205     $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", intval($web_id));
206     $sys_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE groupid = ?", intval($web['sys_groupid']));
207     $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", intval($sys_group['client_id']));
208     if(is_array($client) && !empty($client)){
209         if($client['telephone'] == '' && $client['mobile'] != '') $client['telephone'] = $client['mobile'];
210         
211         $fname = '';
212         $lname = '';
213         $parts = preg_split("/\s+/", $client['contact_name']);
214         if(sizeof($parts) == 2){
215             $fname = $parts[0];
216             $lname = $parts[1];
217         }
218         if(sizeof($parts) > 2){
219             $fname = $parts[0].' ';
220             for($i=1;$i<sizeof($parts);$i++){
221                 if($i == (sizeof($parts) - 1)){
222                     $lname .= $parts[$i];
223                 } else {
224                     if(preg_match('@^(von|van|ten|ter|zur|zu|auf|sieber)$@i', $parts[$i])){
225                         $lname .= implode(' ', array_slice($parts, $i));
226                         break;
227                     } else {
228                         $fname .= $parts[$i].' ';
229                     }
230                 }
231             }
232         }
233         $fname = trim($fname);
234         $lname = trim($lname);
235         $client['fname'] = $fname;
236         $client['lname'] = $lname;
237         if(trim($client['company_name']) == '') $client['company_name'] = $fname.' '.$lname;
238     }
239     $json = $app->functions->json_encode($client);
240 }
241
6882ab 242 //}
5672cd 243
4c28d9 244 header('Content-type: application/json');
0ae8da 245 echo $json;
7fe908 246 ?>