1 <?php
2 class proxyAccount extends plugin
3 {
4 /* Definitions */
5 var $plHeadline= "Proxy";
6 var $plDescription= "This does something";
8 /* Proxy attributes */
9 var $gosaProxyAcctFlags= "[N ]";
10 var $gosaProxyID= "";
11 var $gosaProxyWorkingStart= 420;
12 var $gosaProxyWorkingStop= 1020;
13 var $gosaProxyQuota= "5g";
14 var $gosaProxyQuotaPeriod= "m";
16 /* attribute list for save action */
17 var $attributes= array("gosaProxyID", "gosaProxyAcctFlags", "gosaProxyWorkingStart",
18 "gosaProxyWorkingStop", "gosaProxyQuota", "gosaProxyQuotaPeriod");
19 var $objectclasses= array("gosaProxyAccount");
20 var $ReadOnly = false;
22 function proxyAccount ($config, $dn= NULL)
23 {
24 plugin::plugin ($config, $dn);
25 }
27 function execute()
28 {
29 /* Call parent execute */
30 // plugin::execute();
32 $display= "";
34 /* Prepare templating */
35 $smarty= get_smarty();
38 if((!$this->ReadOnly)&& ($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) {
39 $smarty->assign('proxyAccountACL', "");
40 }else{
41 $smarty->assign('proxyAccountACL', " disabled ");
42 }
44 /* Assign radio boxes */
45 foreach (array("F", "T", "B", "N") as $val){
47 if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
48 $smarty->assign("filter$val", "checked");
50 /* Add state variables for on-the-fly state-changing of checkboxes */
51 $smarty->assign($val."state", "");
53 } else {
54 $smarty->assign("filter$val", "");
56 /* Same as above */
57 if($_SESSION['js']==1){
58 $smarty->assign($val."state", "disabled");
59 }else{
60 $smarty->assign($val."state", "");
61 }
62 }
63 }
65 $tmp = $this->plInfo();
66 foreach($tmp['plProvidedAcls'] as $acl => $desc){
67 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
68 $smarty->assign($acl."_W",$this->acl_is_writeable($acl,$this->ReadOnly));
69 }
71 /* Assign working time */
72 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
73 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
74 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
75 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
76 $hours= array();
77 for($i=0; $i<24; $i++){
78 $hours[]= sprintf("%02d",$i);
79 }
80 $smarty->assign("hours", $hours);
81 $smarty->assign("minutes", array("00","15","30","45"));
83 /* Assign quota values */
84 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
85 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
86 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
87 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
88 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
89 if ($this->is_account){
90 $smarty->assign("proxyState", "checked");
91 } else {
92 $smarty->assign("proxyState", "");
93 }
95 /* Prepare correct state */
96 if (!$this->is_account){
97 $smarty->assign("pstate", "disabled");
98 } else {
99 $smarty->assign("pstate", "");
100 }
102 $changeA = "";
104 if($this->acl_is_writeable("gosaProxyFlag_F")){
105 $changeA .="changeState('filterF');\n";
106 }
107 $ProxyWorkingStateChange ="\n";
108 if($this->acl_is_writeable("gosaProxyWorkingTime")){
109 $changeA .= "changeState('filterT');\n";
110 $ProxyWorkingStateChange.= "changeState('startHour'); \n";
111 $ProxyWorkingStateChange.= "changeState('startMinute'); \n";
112 $ProxyWorkingStateChange.= "changeState('stopHour'); \n";
113 $ProxyWorkingStateChange.= "changeState('stopMinute'); \n";
114 }
116 $changeA .= $ProxyWorkingStateChange;
118 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
120 $changeB = "";
121 if($this->acl_is_writeable("gosaProxyQuota")){
122 $changeA .= "changeState('filterB');";
123 $changeB =
124 "changeSubselectState('filterB', 'quota_size');
125 changeSubselectState('filterB', 'quota_unit');
126 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
127 }
129 $smarty->assign("changeB",$changeB);
130 $smarty->assign("changeA",$changeA);
132 /* Show main page */
133 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
134 return($display);
135 }
137 function remove_from_parent()
138 {
139 if($this->acl_is_removeable()){
141 plugin::remove_from_parent();
143 $ldap= $this->config->get_ldap_link();
144 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
145 $this->attributes, "Save");
146 $ldap->cd($this->dn);
147 $this->cleanup();
148 $ldap->modify ($this->attrs);
150 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/proxy account with dn '%s' failed."),$this->dn));
152 /* Optionally execute a command after we're done */
153 $this->handle_post_events("remove");
154 }
155 }
157 /* Check values */
158 function check()
159 {
160 /* Call common method to give check the hook */
161 $message= plugin::check();
163 /* We've got only one value to check for positive integer or emtpy field */
164 if ($this->is_account){
165 if($this->acl_is_writeable("gosaProxyQuota")){
166 if (isset($_POST["quota_size"])){
167 if ($_POST["quota_size"] == "gosaProxyQuota"){
168 $message[]= _("Numerical value for Quota Setting is empty.");
169 }elseif ($_POST["quota_size"] <= 0){
170 $message[]= _("Numerical value for Quota Setting is not valid.");
171 }
172 }
173 }
174 }
176 return $message;
177 }
179 /* Save data to object */
180 function save_object()
181 {
182 /* Do we need to flip is_account state? */
183 if ($this->parent != NULL){
184 if (isset($_POST['connectivityTab'])){
185 if (isset($_POST['proxy'])){
186 if (!$this->is_account && $_POST['proxy'] == "B"){
187 if($this->acl_is_createable()){
188 $this->is_account= TRUE;
189 }
190 }
191 } else {
192 if($this->acl_is_removeable()){
193 $this->is_account= FALSE;
194 }
195 }
196 }
197 }
199 /* Save flag value */
200 if ($this->is_account){
203 $flags= "";
204 $acl= "";
205 foreach(array("F", "T", "B") as $key){
206 if($this->acl_is_writeable("gosaProxyFlag".$key)){
208 /* Add acl */
209 if (isset($_POST["filter$key"])){
210 $flags.= $key;
211 }
212 }else{
214 /* Keep all flags that can't be written*/
215 if(preg_match("/".$key."/",$this->gosaProxyAcctFlags)){
216 $flags .=$key;
217 }
218 }
219 }
220 if ("[$flags]" != $this->gosaProxyAcctFlags){
221 $this->is_modified= TRUE;
222 }
223 $this->gosaProxyAcctFlags= "[$flags]";
225 /* Save time values */
226 if ($this->acl_is_writeable("gosaProxyWorkingTime")){
227 if(isset($_POST['startMinute'])){
228 $old= $this->gosaProxyWorkingStart;
229 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
230 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
231 }
233 if (isset($_POST['stopMinute'])){
234 $old= $this->gosaProxyWorkingStop;
235 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
236 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
237 }
238 }
240 /* Save quota values */
241 if ($this->acl_is_writeable("gosaProxyQuota")){
242 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
243 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
244 }
245 }
247 /*Save quota period */
248 if($this->acl_is_writeable("gosaProxyQuotaPeriod")){
249 if(isset($_POST["gosaProxyQuotaPeriod"])){
250 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
251 }
252 }
253 }
254 }
257 /* Save to LDAP */
258 function save()
259 {
260 plugin::save();
262 /* Write back to ldap */
263 $ldap= $this->config->get_ldap_link();
264 $ldap->cd($this->dn);
265 $this->cleanup();
266 $ldap->modify ($this->attrs);
268 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/proxy account with dn '%s' failed."),$this->dn));
270 /* Optionally execute a command after we're done */
271 if ($this->initially_was_account == $this->is_account){
272 if ($this->is_modified){
273 $this->handle_post_events("mofify");
274 }
275 } else {
276 $this->handle_post_events("add");
277 }
279 }
281 /* Return plugin informations for acl handling
282 #FIME There possibly some attributes that can be combined to one acl. */
283 function plInfo()
284 {
285 return (array(
286 "plShortName" => _("Proxy"),
287 "plDescription" => _("Proxy account"),
288 "plSelfModify" => TRUE,
289 "plDepends" => array("user"),
290 "plPriority" => 7, // Position in tabs
291 "plSection" => "personal", // This belongs to personal
292 "plCategory" => array("users"),
293 "plOptions" => array(),
295 "plProvidedAcls" => array(
296 "gosaProxyID" => _("gosaProxyID"),
298 "gosaProxyFlagF" => _("Filter unwanted content"),
299 "gosaProxyFlagT" => _("Limit proxy access"),
300 "gosaProxyFlagB" => _("Restrict proxy usage by quota"),
302 "gosaProxyWorkingTime" => _("Limit proxy access"),
303 "gosaProxyQuota" => _("Limit quota"),
304 "gosaProxyQuotaPeriod" => _("Quota limit period"))
305 ));
306 }
307 }
309 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
310 ?>