Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
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
d22277 95     if($php_type == 'php-fpm' || ($php_type == 'hhvm' && $server_type == 'nginx')){
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) {
d22277 103             if($php_type == 'php-fpm' || ($php_type == 'hhvm' && $server_type == 'nginx')){
7fe908 104                 $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
MC 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');
d22277 195     if (!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
1fa8f4 196
d22277 197     $m_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND master_directive_snippets_id > 0 AND type = ? ORDER BY name ASC", $server_type);
MB 198     
199     $snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND master_directive_snippets_id = 0 AND type = ? ORDER BY name ASC", $server_type);
1fa8f4 200
d22277 201     $json = json_encode(array('m_snippets' => $m_snippets, 'snippets' => $snippets));
1fa8f4 202 }
FT 203
8173c6 204 if($type == 'getclientssldata'){
2af58c 205     $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $web_id);
MC 206     $sys_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE groupid = ?", $web['sys_groupid']);
207     $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $sys_group['client_id']);
8173c6 208     if(is_array($client) && !empty($client)){
FT 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 ?>