commit | author | age
|
31f6ce
|
1 |
<?php |
M |
2 |
/* |
|
3 |
Copyright (c) 2008, Till Brehm, projektfarm Gmbh |
|
4 |
All rights reserved. |
|
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
|
7 |
are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
|
17 |
|
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
|
29 |
|
|
30 |
class tools_sites { |
|
31 |
|
b1a6a5
|
32 |
function replacePrefix($name, $dataRecord) { |
MC |
33 |
// No input -> no possible output -> go out! |
|
34 |
if ($name=="") return ""; |
31f6ce
|
35 |
|
b1a6a5
|
36 |
// Array containing keys to search |
MC |
37 |
$keywordlist=array('CLIENTNAME', 'CLIENTID', 'DOMAINID'); |
31f6ce
|
38 |
|
b1a6a5
|
39 |
// Try to match the key within the string |
MC |
40 |
foreach ($keywordlist as $keyword) { |
|
41 |
if (substr_count($name, '['.$keyword.']') > 0) { |
|
42 |
switch ($keyword) { |
|
43 |
case 'CLIENTNAME': |
|
44 |
$name=str_replace('['.$keyword.']', $this->getClientName($dataRecord), $name); |
|
45 |
break; |
|
46 |
case 'CLIENTID': |
|
47 |
$name=str_replace('['.$keyword.']', $this->getClientID($dataRecord), $name); |
|
48 |
break; |
|
49 |
case 'DOMAINID': |
|
50 |
$name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'], $name); |
|
51 |
break; |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
return $name; |
|
56 |
} |
31f6ce
|
57 |
|
b1a6a5
|
58 |
function removePrefix($name, $currentPrefix, $globalPrefix) { |
MC |
59 |
if($name == "") return ""; |
31f6ce
|
60 |
|
b1a6a5
|
61 |
if($currentPrefix === '') return $name; // empty prefix, do not change name |
MC |
62 |
if($currentPrefix === '#') $currentPrefix = $globalPrefix; // entry has no prefix set, maybe it was created before this function was introduced |
|
63 |
|
|
64 |
if($currentPrefix === '') return $name; // no current prefix and global prefix is empty -> nothing to remove here. |
|
65 |
|
|
66 |
return preg_replace('/^' . preg_quote($currentPrefix, '/') . '/', '', $name); // return name without prefix |
|
67 |
} |
|
68 |
|
|
69 |
function getPrefix($currentPrefix, $userPrefix, $adminPrefix = false) { |
|
70 |
global $app; |
|
71 |
|
|
72 |
if($currentPrefix !== '#') return $currentPrefix; // return the currently set prefix for this entry (# = no prefix set yet) |
|
73 |
|
|
74 |
if($adminPrefix === false) $adminPrefix = $userPrefix; |
|
75 |
|
|
76 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) return $adminPrefix; |
|
77 |
else return $userPrefix; |
|
78 |
} |
|
79 |
|
|
80 |
function getClientName($dataRecord) { |
|
81 |
global $app, $conf; |
|
82 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
83 |
// Get the group-id of the user if the logged in user is neither admin nor reseller |
|
84 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
85 |
} else { |
|
86 |
// Get the group-id from the data itself |
|
87 |
if(isset($dataRecord['client_group_id'])) { |
|
88 |
$client_group_id = $dataRecord['client_group_id']; |
|
89 |
} elseif (isset($dataRecord['parent_domain_id'])) { |
|
90 |
$tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); |
|
91 |
$client_group_id = $tmp['sys_groupid']; |
|
92 |
} elseif(isset($dataRecord['sys_groupid'])) { |
|
93 |
$client_group_id = $dataRecord['sys_groupid']; |
|
94 |
} else { |
|
95 |
$client_group_id = 0; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $app->functions->intval($client_group_id)); |
|
100 |
$clientName = $tmp['name']; |
|
101 |
if ($clientName == "") $clientName = 'default'; |
|
102 |
$clientName = $this->convertClientName($clientName); |
|
103 |
return $clientName; |
|
104 |
} |
|
105 |
|
|
106 |
function getClientID($dataRecord) { |
|
107 |
global $app, $conf; |
|
108 |
|
|
109 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
110 |
// Get the group-id of the user |
|
111 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
112 |
} else { |
|
113 |
// Get the group-id from the data itself |
|
114 |
if(isset($dataRecord['client_group_id'])) { |
|
115 |
$client_group_id = $dataRecord['client_group_id']; |
|
116 |
} elseif (isset($dataRecord['parent_domain_id']) && $dataRecord['parent_domain_id'] != 0) { |
|
117 |
$tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); |
|
118 |
$client_group_id = $tmp['sys_groupid']; |
|
119 |
} elseif(isset($dataRecord['sys_groupid'])) { |
|
120 |
$client_group_id = $dataRecord['sys_groupid']; |
|
121 |
} else { |
|
122 |
$client_group_id = 0; |
|
123 |
} |
|
124 |
} |
|
125 |
$tmp = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = " . $app->functions->intval($client_group_id)); |
|
126 |
$clientID = $tmp['client_id']; |
|
127 |
if ($clientID == '') $clientID = '0'; |
|
128 |
return $clientID; |
|
129 |
} |
|
130 |
|
|
131 |
function convertClientName($name){ |
|
132 |
$allowed = 'abcdefghijklmnopqrstuvwxyz0123456789_'; |
|
133 |
$res = ''; |
|
134 |
$name = strtolower(trim($name)); |
|
135 |
for ($i=0; $i < strlen($name); $i++){ |
|
136 |
if ($name[$i] == ' ') continue; |
|
137 |
if (strpos($allowed, $name[$i]) !== false){ |
|
138 |
$res .= $name[$i]; |
|
139 |
} |
|
140 |
else { |
|
141 |
$res .= '_'; |
|
142 |
} |
|
143 |
} |
|
144 |
return $res; |
|
145 |
} |
|
146 |
|
|
147 |
function getDomainModuleDomains() { |
|
148 |
global $app; |
|
149 |
|
|
150 |
$sql = "SELECT domain_id, domain FROM domain WHERE"; |
|
151 |
if ($_SESSION["s"]["user"]["typ"] == 'admin') { |
|
152 |
$sql .= " 1"; |
|
153 |
} else { |
|
154 |
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0; |
|
155 |
$sql .= " sys_groupid IN (".$groups.")"; |
|
156 |
} |
|
157 |
$sql .= " ORDER BY domain"; |
|
158 |
return $app->db->queryAllRecords($sql); |
|
159 |
} |
|
160 |
|
|
161 |
function checkDomainModuleDomain($domain_id) { |
|
162 |
global $app; |
|
163 |
|
|
164 |
$sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . $app->functions->intval($domain_id); |
|
165 |
if ($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
166 |
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0; |
|
167 |
$sql .= " AND sys_groupid IN (".$groups.")"; |
|
168 |
} |
|
169 |
$domain = $app->db->queryOneRecord($sql); |
|
170 |
if(!$domain || !$domain['domain_id']) return false; |
|
171 |
return $domain['domain']; |
|
172 |
} |
|
173 |
|
31f6ce
|
174 |
} |
M |
175 |
|
|
176 |
?> |