Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
4c28d9 1 <?php
F 2
3 /*
4 Copyright (c) 2012, ISPConfig UG
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
b1a6a5 31 require_once '../../lib/config.inc.php';
MC 32 require_once '../../lib/app.inc.php';
4c28d9 33
F 34 //* Check permissions for module
35 $app->auth->check_module_permissions('dashboard');
36
37 $app->uses('tform');
38
39 $type = $_GET["type"];
40
41 //if($_SESSION["s"]["user"]["typ"] == 'admin') {
42
3a11d2 43 /* TODO: change sql queries */
b1a6a5 44 if($type == 'globalsearch'){
MC 45     $q = $app->db->quote(trim($_GET["q"]));
46     $authsql = " AND ".$app->tform->getAuthSQL('r');
47     $modules = explode(',', $_SESSION['s']['user']['modules']);
48
49     $result = array();
50
51     // clients
52     $result[] = _search('client', 'client', "AND limit_client = 0");
53
54     // resellers
55     $result[] = _search('client', 'reseller', "AND limit_client != 0");
56
57     // web sites
8b49ff 58     $result[] = _search('sites', 'web_vhost_domain', "AND type = 'vhost'");
b1a6a5 59
MC 60     // subdomains
8b49ff 61     $result[] = _search('sites', 'web_childdomain', "AND type = 'subdomain'", 'type=subdomain');
b1a6a5 62
MC 63     // web site aliases
8b49ff 64     $result[] = _search('sites', 'web_childdomain', "AND type = 'alias'", 'type=aliasdomain');
b1a6a5 65
MC 66     // vhostsubdomains
8b49ff 67     $result[] = _search('sites', 'web_vhost_domain', "AND type = 'vhostsubdomain'", 'type=subdomain');
b1a6a5 68
511ba5 69     // vhostaliasdomains
8b49ff 70     $result[] = _search('sites', 'web_vhost_domain', "AND type = 'vhostalias'", 'type=aliasdomain');
511ba5 71
b1a6a5 72     // FTP users
MC 73     $result[] = _search('sites', 'ftp_user');
74
75     // shell users
76     $result[] = _search('sites', 'shell_user');
77
78     // databases
79     $result[] = _search('sites', 'database');
4c28d9 80
b1a6a5 81     // database users
MC 82     $result[] = _search('sites', 'database_user');
83
84     // email domains
85     $result[] = _search('mail', 'mail_domain');
86
87     // email alias domains
88     $result[] = _search('mail', 'mail_aliasdomain', "AND type = 'aliasdomain'");
89
90     // email mailboxes
91     $result[] = _search('mail', 'mail_user');
92
93     // email aliases
94     $result[] = _search('mail', 'mail_alias', "AND type = 'alias'");
95
96     // email forwards
97     $result[] = _search('mail', 'mail_forward', "AND type = 'forward'");
98
99     // email catchalls
100     $result[] = _search('mail', 'mail_domain_catchall', "AND type = 'catchall'");
101
102     // email transports
103     $result[] = _search('mail', 'mail_transport');
104
105     // mailinglists
106     $result[] = _search('mail', 'mail_mailinglist');
107
108     // getmails
109     $result[] = _search('mail', 'mail_get');
110
111     // dns zones
112     $result[] = _search('dns', 'dns_soa');
113
114     // secondary dns zones
115     $result[] = _search('dns', 'dns_slave');
116
117     // virtual machines
118     $result[] = _search('vm', 'openvz_vm');
119
120     // virtual machines os templates
121     $result[] = _search('vm', 'openvz_ostemplate');
122
123     // virtual machines vm templates
124     $result[] = _search('vm', 'openvz_template');
125
126     // virtual machines ip addresses
127     $result[] = _search('vm', 'openvz_ip');
128
129     // directive snippets
130     $result[] = _search('admin', 'directive_snippets');
131
132     $json = $app->functions->json_encode($result);
133 }
4c28d9 134
F 135 //}
136
8b49ff 137 function _search($module, $section, $additional_sql = '', $params = ''){
4c28d9 138     global $app, $q, $authsql, $modules;
F 139
140     $result_array = array('cheader' => array(), 'cdata' => array());
141     if(in_array($module, $modules)){
142         $search_fields = array();
143         $desc_fields = array();
144         if(is_file('../'.$module.'/form/'.$section.'.tform.php')){
8b49ff 145             include '../'.$module.'/form/'.$section.'.tform.php';
b1a6a5 146
4c28d9 147             $category_title = $form["title"];
8b49ff 148             if($params == 'type=subdomain' && $section == 'web_childdomain') $category_title = 'Subdomain';
MC 149             if($params == 'type=aliasdomain' && $section == 'web_childdomain') $category_title = 'Aliasdomain';
150             if($params == 'type=subdomain' && $section == 'web_vhost_domain') $category_title = 'Subdomain (Vhost)';
151             if($params == 'type=aliasdomain' && $section == 'web_vhost_domain') $category_title = 'Aliasdomain (Vhost)';
4c28d9 152             $form_file = $form["action"];
F 153             $db_table = $form["db_table"];
154             $db_table_idx = $form["db_table_idx"];
155             $order_by = $db_table_idx;
b1a6a5 156
4c28d9 157             if(is_array($form["tabs"]) && !empty($form["tabs"])){
F 158                 foreach($form["tabs"] as $tab){
159                     if(is_array($tab['fields']) && !empty($tab['fields'])){
160                         foreach($tab['fields'] as $key => $val){
161                             if(isset($val['searchable']) && $val['searchable'] > 0){
162                                 $search_fields[] = $key." LIKE '%".$q."%'";
163                                 if($val['searchable'] == 1){
164                                     $order_by = $key;
165                                     $title_key = $key;
166                                 }
167                                 if($val['searchable'] == 2){
168                                     $desc_fields[] = $key;
169                                 }
170                             }
171                         }
172                     }
173                 }
174             }
175         }
176         unset($form);
b1a6a5 177
4c28d9 178         $where_clause = '';
F 179         if(!empty($search_fields)){
180             $where_clause = implode(' OR ', $search_fields);
181         } else {
182             // valid SQL query which returns an empty result set
183             $where_clause = '1 = 0';
184         }
59118c 185         if($where_clause != '') $where_clause = '('.$where_clause.')';
F 186         if($additional_sql != '') $where_clause .= ' '.$additional_sql.' ';
4c28d9 187         $order_clause = '';
F 188         if($order_by != '') $order_clause = ' ORDER BY '.$order_by;
b1a6a5 189
2af58c 190         $sql = "SELECT * FROM ?? WHERE ".$where_clause.$authsql.$order_clause." LIMIT 0,10";
MC 191         $results = $app->db->queryAllRecords($sql, $db_table);
b1a6a5 192
MC 193         if(is_array($results) && !empty($results)){
4c28d9 194             $lng_file = '../'.$module.'/lib/lang/'.$_SESSION['s']['language'].'_'.$section.'.lng';
b1a6a5 195             if(is_file($lng_file)) include $lng_file;
4c28d9 196             $result_array['cheader'] = array('title' => $category_title,
b1a6a5 197                 'total' => count($results),
MC 198                 'limit' => count($results)
199             );
4c28d9 200             foreach($results as $result){
F 201                 $description = '';
202                 if(!empty($desc_fields)){
203                     $desc_items = array();
204                     foreach($desc_fields as $desc_field){
205                         if($result[$desc_field] != '') $desc_items[] = $wb[$desc_field.'_txt'].': '.$result[$desc_field];
206                     }
207                     if(!empty($desc_items)) $description = implode(' - ', $desc_items);
208                 }
b1a6a5 209
4c28d9 210                 $result_array['cdata'][] = array('title' => $wb[$title_key.'_txt'].': '.$result[$title_key],
b1a6a5 211                     'description' => $description,
8b49ff 212                     'onclick' => "ISPConfig.capp('".$module."','".$module."/".$form_file.urlencode("?id=".$result[$db_table_idx]).($params != ''? urlencode('&'.$params) : '')."');",
b1a6a5 213                     'fill_text' => strtolower($result[$title_key])
MC 214                 );
215             }
4c28d9 216         }
F 217     }
218     return $result_array;
219 }
b1a6a5 220
4c28d9 221 header('Content-type: application/json');
F 222 echo $json;
b1a6a5 223 ?>