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 |
|
58 |
$result[] = _search('sites', 'web_domain', "AND type = 'vhost'"); |
|
59 |
|
|
60 |
// subdomains |
|
61 |
$result[] = _search('sites', 'web_subdomain', "AND type = 'subdomain'"); |
|
62 |
|
|
63 |
// web site aliases |
|
64 |
$result[] = _search('sites', 'web_aliasdomain', "AND type = 'alias'"); |
|
65 |
|
|
66 |
// vhostsubdomains |
|
67 |
$result[] = _search('sites', 'web_vhost_subdomain', "AND type = 'vhostsubdomain'"); |
|
68 |
|
511ba5
|
69 |
// vhostaliasdomains |
DM |
70 |
$result[] = _search('sites', 'web_vhost_aliasdomain', "AND type = 'vhostalias'"); |
|
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 |
|
59118c
|
137 |
function _search($module, $section, $additional_sql = ''){ |
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')){ |
b1a6a5
|
145 |
include_once '../'.$module.'/form/'.$section.'.tform.php'; |
MC |
146 |
|
4c28d9
|
147 |
$category_title = $form["title"]; |
F |
148 |
$form_file = $form["action"]; |
|
149 |
$db_table = $form["db_table"]; |
|
150 |
$db_table_idx = $form["db_table_idx"]; |
|
151 |
$order_by = $db_table_idx; |
b1a6a5
|
152 |
|
4c28d9
|
153 |
if(is_array($form["tabs"]) && !empty($form["tabs"])){ |
F |
154 |
foreach($form["tabs"] as $tab){ |
|
155 |
if(is_array($tab['fields']) && !empty($tab['fields'])){ |
|
156 |
foreach($tab['fields'] as $key => $val){ |
|
157 |
if(isset($val['searchable']) && $val['searchable'] > 0){ |
|
158 |
$search_fields[] = $key." LIKE '%".$q."%'"; |
|
159 |
if($val['searchable'] == 1){ |
|
160 |
$order_by = $key; |
|
161 |
$title_key = $key; |
|
162 |
} |
|
163 |
if($val['searchable'] == 2){ |
|
164 |
$desc_fields[] = $key; |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
unset($form); |
b1a6a5
|
173 |
|
4c28d9
|
174 |
$where_clause = ''; |
F |
175 |
if(!empty($search_fields)){ |
|
176 |
$where_clause = implode(' OR ', $search_fields); |
|
177 |
} else { |
|
178 |
// valid SQL query which returns an empty result set |
|
179 |
$where_clause = '1 = 0'; |
|
180 |
} |
59118c
|
181 |
if($where_clause != '') $where_clause = '('.$where_clause.')'; |
F |
182 |
if($additional_sql != '') $where_clause .= ' '.$additional_sql.' '; |
4c28d9
|
183 |
$order_clause = ''; |
F |
184 |
if($order_by != '') $order_clause = ' ORDER BY '.$order_by; |
b1a6a5
|
185 |
|
2af58c
|
186 |
$sql = "SELECT * FROM ?? WHERE ".$where_clause.$authsql.$order_clause." LIMIT 0,10"; |
MC |
187 |
$results = $app->db->queryAllRecords($sql, $db_table); |
b1a6a5
|
188 |
|
MC |
189 |
if(is_array($results) && !empty($results)){ |
4c28d9
|
190 |
$lng_file = '../'.$module.'/lib/lang/'.$_SESSION['s']['language'].'_'.$section.'.lng'; |
b1a6a5
|
191 |
if(is_file($lng_file)) include $lng_file; |
4c28d9
|
192 |
$result_array['cheader'] = array('title' => $category_title, |
b1a6a5
|
193 |
'total' => count($results), |
MC |
194 |
'limit' => count($results) |
|
195 |
); |
4c28d9
|
196 |
foreach($results as $result){ |
F |
197 |
$description = ''; |
|
198 |
if(!empty($desc_fields)){ |
|
199 |
$desc_items = array(); |
|
200 |
foreach($desc_fields as $desc_field){ |
|
201 |
if($result[$desc_field] != '') $desc_items[] = $wb[$desc_field.'_txt'].': '.$result[$desc_field]; |
|
202 |
} |
|
203 |
if(!empty($desc_items)) $description = implode(' - ', $desc_items); |
|
204 |
} |
b1a6a5
|
205 |
|
4c28d9
|
206 |
$result_array['cdata'][] = array('title' => $wb[$title_key.'_txt'].': '.$result[$title_key], |
b1a6a5
|
207 |
'description' => $description, |
06339e
|
208 |
'onclick' => "ISPConfig.capp('".$module."','".$module."/".$form_file."?id=".$result[$db_table_idx]."');", |
b1a6a5
|
209 |
'fill_text' => strtolower($result[$title_key]) |
MC |
210 |
); |
|
211 |
} |
4c28d9
|
212 |
} |
F |
213 |
} |
|
214 |
return $result_array; |
|
215 |
} |
b1a6a5
|
216 |
|
4c28d9
|
217 |
header('Content-type: application/json'); |
F |
218 |
echo $json; |
b1a6a5
|
219 |
?> |