Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
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":"';
8c517c 59     $sql = "SELECT server_id FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r');
2af58c 60     $server = $app->db->queryOneRecord($sql, $web_id);
7fe908 61     $json .= $server['server_id'];
MC 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'])) {
2af58c 80         $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = ?", $client_group_id);
7fe908 81         //$sql_where = " AND (client_id = 0 OR client_id = ".$_SESSION["s"]["user"]["client_id"];
MC 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 = '';
2af58c 88         $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = ?", $client_group_id);
7fe908 89         //$sql_where = " AND (client_id = 0 OR client_id = ".$_SESSION["s"]["user"]["client_id"];
MC 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'){
2af58c 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 = ?".$sql_where, $server_id);
MC 97     } elseif($php_type == 'fast-cgi'){
98         $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ?".$sql_where, $server_id);
10b4c8 99     }
7fe908 100     $php_select = "";
MC 101     if(is_array($php_records) && !empty($php_records)) {
102         foreach( $php_records as $php_record) {
103             if($php_type == 'php-fpm'){
104                 $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
105             } else {
106                 $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
107             }
108             $json .= '"'.$php_version.'": "'.$php_record['name'].'",';
109         }
10b4c8 110     }
7fe908 111     unset($php_records);
MC 112     if(substr($json, -1) == ',') $json = substr($json, 0, -1);
113     $json .= '}';
114 }
115
116 if($type == 'getphptype'){
117     $json = '{"phptype":"';
2af58c 118     $sql = "SELECT php FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r');
MC 119     $php = $app->db->queryOneRecord($sql, $web_id);
7fe908 120     $json .= $php['php'];
MC 121     unset($php);
122     $json .= '"}';
123 }
124
125 if($type == 'getredirecttype'){
126     $json = '{"redirecttype":"';
2af58c 127     $sql = "SELECT redirect_type FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r');
MC 128     $redirect = $app->db->queryOneRecord($sql, $web_id);
7fe908 129     $json .= $redirect['redirect_type'];
MC 130     unset($redirect);
131     $json .= '"}';
132 }
133
134 if($type == 'get_ipv4'){
135     $result = array();
136
137     // ipv4
138     //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")");
139     $result[] = $app->functions->suggest_ips('IPv4');
140
141     $json = $app->functions->json_encode($result);
142 }
143
144 if($type == 'get_ipv6'){
145     $result = array();
146
147     // ipv6
148     //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")");
149     $result[] = $app->functions->suggest_ips('IPv6');
150
151     $json = $app->functions->json_encode($result);
152 }
153
154 if($type == 'getdatabaseusers') {
155     $json = '{}';
156
2af58c 157     $sql = "SELECT sys_groupid FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r');
MC 158     $group = $app->db->queryOneRecord($sql, $web_id);
7fe908 159     if($group) {
2af58c 160         $sql = "SELECT database_user_id, database_user FROM web_database_user WHERE sys_groupid = ?";
MC 161         $records = $app->db->queryAllRecords($sql, $group['sys_groupid']);
7fe908 162
MC 163         $tmp_array = array();
164         foreach($records as $record) {
165             $tmp_array[$record['database_user_id']] = $record['database_user'];
166         }
167         $json = $app->functions->json_encode($tmp_array);
168         unset($records, $group, $tmp_array);
169     }
170 }
171
172 if($type == 'get_use_combobox'){
173     $json = '{"usecombobox":"';
174     $use_combobox = 'y';
175     $server_config_array = $app->getconf->get_global_config();
176     if($server_config_array['misc']['use_combobox'] != 'y') $use_combobox = 'n';
177     $json .= $use_combobox;
178     unset($server_config_array);
179     $json .= '"}';
180 }
181
182 if($type == 'get_use_loadindicator'){
183     $json = '{"useloadindicator":"';
184     $use_loadindicator = 'y';
185     $server_config_array = $app->getconf->get_global_config();
186     if($server_config_array['misc']['use_loadindicator'] != 'y') $use_loadindicator = 'n';
187     $json .= $use_loadindicator;
188     unset($server_config_array);
189     $json .= '"}';
190 }
0ae8da 191
1fa8f4 192 if ($type == 'getdirectivesnippet') {
FT 193     $server_type = 'apache';
194     $web_config = $app->getconf->get_server_config($server_id, 'web');
195     if (!empty($web_config['server_type']))
196         $server_type = $web_config['server_type'];
197
198     $snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND type = ? ORDER BY name ASC", $server_type);
199
200     $json = json_encode($snippets);
201 }
202
8173c6 203 if($type == 'getclientssldata'){
2af58c 204     $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $web_id);
MC 205     $sys_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE groupid = ?", $web['sys_groupid']);
206     $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $sys_group['client_id']);
8173c6 207     if(is_array($client) && !empty($client)){
FT 208         if($client['telephone'] == '' && $client['mobile'] != '') $client['telephone'] = $client['mobile'];
209         
210         $fname = '';
211         $lname = '';
212         $parts = preg_split("/\s+/", $client['contact_name']);
213         if(sizeof($parts) == 2){
214             $fname = $parts[0];
215             $lname = $parts[1];
216         }
217         if(sizeof($parts) > 2){
218             $fname = $parts[0].' ';
219             for($i=1;$i<sizeof($parts);$i++){
220                 if($i == (sizeof($parts) - 1)){
221                     $lname .= $parts[$i];
222                 } else {
223                     if(preg_match('@^(von|van|ten|ter|zur|zu|auf|sieber)$@i', $parts[$i])){
224                         $lname .= implode(' ', array_slice($parts, $i));
225                         break;
226                     } else {
227                         $fname .= $parts[$i].' ';
228                     }
229                 }
230             }
231         }
232         $fname = trim($fname);
233         $lname = trim($lname);
234         $client['fname'] = $fname;
235         $client['lname'] = $lname;
236         if(trim($client['company_name']) == '') $client['company_name'] = $fname.' '.$lname;
237     }
238     $json = $app->functions->json_encode($client);
239 }
240
6882ab 241 //}
5672cd 242
4c28d9 243 header('Content-type: application/json');
0ae8da 244 echo $json;
7fe908 245 ?>