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");
20 var $objectclasses = array("gosaProxyAccount");
21 var $ReadOnly = false;
22 var $uid = "";
23 var $view_logged = FALSE;
24 var $multiple_support = TRUE;
26 /*! \brief Initialize proxy acoount
27 @param $config GOsa configuration object
28 @param $dn Object dn
29 */
30 public function proxyAccount (&$config, $dn= NULL)
31 {
32 plugin::plugin ($config, $dn);
34 /* Setting uid to default */
35 if(isset($this->attrs['uid'][0])){
36 $this->uid = $this->attrs['uid'][0];
37 }
38 }
41 /*! \brief Create html output for this class
42 */
43 public function execute()
44 {
45 /* Call parent execute */
46 plugin::execute();
48 /* Log view */
49 if($this->is_account && !$this->view_logged){
50 $this->view_logged = TRUE;
51 new log("view","users/".get_class($this),$this->dn);
52 }
54 $display= "";
55 $smarty= get_smarty();
57 /* Assign radio boxes */
58 foreach (array("F", "T", "B", "N") as $val){
59 if (preg_match("/".$val."/",$this->gosaProxyAcctFlags)){
60 $smarty->assign("filter$val", "checked");
61 $smarty->assign($val."state", "");
62 } else {
63 $smarty->assign("filter$val", "");
64 if(session::get('js')==1){
65 $smarty->assign($val."state", "disabled");
66 }else{
67 $smarty->assign($val."state", "");
68 }
69 }
70 }
72 /* Assign ACLs */
73 $tmp = $this->plInfo();
74 foreach($tmp['plProvidedAcls'] as $acl => $desc){
75 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
76 $smarty->assign($acl."_W",$this->acl_is_writeable($acl,$this->ReadOnly));
77 }
79 /* Assign working time */
80 $smarty->assign("starthour" ,($this->gosaProxyWorkingStart / 60));
81 $smarty->assign("startminute", ($this->gosaProxyWorkingStart % 60));
82 $smarty->assign("stophour", ($this->gosaProxyWorkingStop / 60));
83 $smarty->assign("stopminute", ($this->gosaProxyWorkingStop % 60));
84 $hours= array();
85 for($i=0; $i<24; $i++){
86 $hours[]= sprintf("%02d",$i);
87 }
88 $smarty->assign("hours", $hours);
89 $smarty->assign("minutes", array("00","15","30","45"));
91 /* Assign quota values */
92 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
93 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
94 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
95 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
96 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
97 if ($this->is_account){
98 $smarty->assign("proxyState", "checked");
99 } else {
100 $smarty->assign("proxyState", "");
101 }
104 /* Handle input grey out and javascript enabled/disable of input fields
105 */
106 if($this->multiple_support_active){
108 /* In Multiple edit, everything is enabled */
109 $changeB = "";
110 $smarty->assign("pstate", "");
111 $smarty->assign("ProxyWorkingStateChange","");
112 }else{
114 /* Depeding on the account status, we disable or
115 * enable all input fields
116 */
117 if (!$this->is_account){
118 $smarty->assign("pstate", "disabled");
119 } else {
120 $smarty->assign("pstate", "");
121 }
123 /* Create JS activation string for everal input fields */
124 $ProxyWorkingStateChange ="\n";
125 if($this->acl_is_writeable("gosaProxyFlagT")){
126 $ProxyWorkingStateChange.= "changeState('startHour'); \n";
127 $ProxyWorkingStateChange.= "changeState('startMinute'); \n";
128 $ProxyWorkingStateChange.= "changeState('stopHour'); \n";
129 $ProxyWorkingStateChange.= "changeState('stopMinute'); \n";
130 }
131 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
132 $changeB = "";
133 if($this->acl_is_writeable("gosaProxyFlagB")){
134 $changeB =
135 "changeSubselectState('filterB', 'quota_size');
136 changeSubselectState('filterB', 'quota_unit');
137 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
138 }
139 }
141 /* Assign filter settings */
142 $smarty->assign("changeB",$changeB);
143 foreach(array("T","B","F") as $attr){
144 if(in_array("filter".$attr,$this->multi_boxes)){
145 $smarty->assign("use_filter".$attr,TRUE);
146 }else{
147 $smarty->assign("use_filter".$attr,FALSE);
148 }
149 }
150 $smarty->assign("proxyAccountACL",$this->getacl("",$this->ReadOnly));
151 $smarty->assign("use_proxy",in_array("proxy",$this->multi_boxes));
152 $smarty->assign("multiple_support",$this->multiple_support_active);
153 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
154 return($display);
155 }
158 /*! \brief Removes proxy account from current object
159 */
160 public function remove_from_parent()
161 {
162 if($this->acl_is_removeable() && $this->initially_was_account){
163 plugin::remove_from_parent();
164 $ldap= $this->config->get_ldap_link();
165 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
166 $this->attributes, "Save");
167 $ldap->cd($this->dn);
168 $this->cleanup();
169 $ldap->modify ($this->attrs);
171 /* Log last action */
172 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
174 if (!$ldap->success()){
175 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
176 }
178 /* Optionally execute a command after we're done */
179 $this->handle_post_events("remove",array("uid" => $this->uid));
180 }
181 }
184 /*! \brief Check given input
185 @return array Returns an array of error messages
186 */
187 public function check()
188 {
189 /* Call common method to give check the hook */
190 $message= plugin::check();
192 /* We've got only one value to check for positive integer or emtpy field */
193 if ($this->is_account && $this->acl_is_writeable("gosaProxyQuota")){
194 if (isset($_POST["quota_size"])){
195 if ($_POST["quota_size"] == "gosaProxyQuota"){
196 $message[]= msgPool::invalid(_("Quota Setting"));
197 }elseif ($_POST["quota_size"] <= 0){
198 $message[]= msgPool::invalid(_("Quota Setting"),$_POST["quota_size"],"/^[0-9]/");
199 }
200 }
201 }
202 return $message;
203 }
205 /*! \brief Save POST data to object
206 */
207 public function save_object()
208 {
209 /* Do we need to flip is_account state? */
210 if (isset($_POST['connectivityTab'])){
211 if (isset($_POST['proxy'])){
212 if (!$this->is_account && $_POST['proxy'] == "B"){
213 if($this->acl_is_createable()){
214 $this->is_account= TRUE;
215 }
216 }
217 } else {
218 if($this->acl_is_removeable()){
219 $this->is_account= FALSE;
220 }
221 }
222 }
224 /* Save flag value */
225 if ($this->is_account || $this->multiple_support_active){
227 $flags= "";
228 $acl= "";
229 foreach(array("F", "T", "B") as $key){
230 if($this->acl_is_writeable("gosaProxyFlag".$key)){
232 /* Add acl */
233 if (isset($_POST["filter$key"])){
234 $flags.= $key;
235 }
236 }else{
238 /* Keep all flags that can't be written*/
239 if(preg_match("/".$key."/",$this->gosaProxyAcctFlags)){
240 $flags .=$key;
241 }
242 }
243 }
244 if ("[$flags]" != $this->gosaProxyAcctFlags){
245 $this->is_modified= TRUE;
246 }
247 $this->gosaProxyAcctFlags= "[$flags]";
249 /* Save time values */
250 if ($this->acl_is_writeable("gosaProxyFlagT")){
251 if(isset($_POST['startMinute'])){
252 $old= $this->gosaProxyWorkingStart;
253 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
254 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
255 }
257 if (isset($_POST['stopMinute'])){
258 $old= $this->gosaProxyWorkingStop;
259 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
260 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
261 }
262 }
264 /* Save quota values */
265 if ($this->acl_is_writeable("gosaProxyFlagB")){
266 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
267 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
268 }
269 }
271 /*Save quota period */
272 if($this->acl_is_writeable("gosaProxyFlagB")){
273 if(isset($_POST["gosaProxyQuotaPeriod"])){
274 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
275 }
276 }
277 }
278 }
281 /*! \brief Save settings to ldap
282 */
283 public function save()
284 {
285 plugin::save();
287 /* Write back to ldap */
288 $ldap= $this->config->get_ldap_link();
289 $ldap->cd($this->dn);
290 $this->cleanup();
291 $ldap->modify ($this->attrs);
293 /* Log last action */
294 if($this->initially_was_account){
295 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
296 }else{
297 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
298 }
300 if (!$ldap->success()){
301 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
302 }
304 /* Optionally execute a command after we're done */
305 if ($this->initially_was_account == $this->is_account){
306 if ($this->is_modified){
307 $this->handle_post_events("modify",array("uid" => $this->uid));
308 }
309 } else {
310 $this->handle_post_events("add",array("uid" => $this->uid));
311 }
313 }
316 /*! \brief Static Function returning an ACL information array.
317 @return Array Returns an ACL array
318 */
319 static function plInfo()
320 {
321 return (array(
322 "plShortName" => _("Proxy"),
323 "plDescription" => _("Proxy account")." : <u>"._("Connectivity addon")."</u>",
324 "plSelfModify" => TRUE,
325 "plDepends" => array("user"),
326 "plPriority" => 21, // Position in tabs
327 "plSection" => array("personal" => _("My account")),
328 "plCategory" => array("users"),
329 "plOptions" => array(),
331 "plProvidedAcls" => array(
332 "gosaProxyFlagF" => _("Filter unwanted content"),
333 "gosaProxyFlagT" => _("Limit proxy access"),
334 "gosaProxyFlagB" => _("Restrict proxy usage by quota"))
335 ));
336 }
339 /*! \brief Save html POSTs in multiple edit.
340 */
341 public function multiple_save_object()
342 {
343 if (isset($_POST['connectivityTab'])){
344 plugin::multiple_save_object();
345 if(isset($_POST['use_proxy'])){
346 $this->multi_boxes[] = "proxy";
347 }
348 foreach(array("T","B","F") as $attr){
349 if(isset($_POST["use_filter".$attr])){
350 $this->multi_boxes[] = "filter".$attr;
351 }
352 }
353 $this->save_object();
354 }
355 }
358 /*! \brief Returns all modified values. \
359 All selected an modified values will be returned \
360 in an array.
361 @return array Returns an array containing all attribute modifications
362 */
363 public function get_multi_edit_values()
364 {
365 $ret = plugin::get_multi_edit_values();
366 if(in_array("proxy",$this->multi_boxes)){
367 $ret['is_account'] = $this->is_account;
368 }
370 if(in_array("filterT",$this->multi_boxes)){
371 $ret['gosaProxyWorkingStart'] = $this->gosaProxyWorkingStart;
372 $ret['gosaProxyWorkingStop'] = $this->gosaProxyWorkingStop;
373 }
374 if(in_array("filterB",$this->multi_boxes)){
375 $ret['gosaProxyQuota'] = $this->gosaProxyQuota;
376 $ret['gosaProxyQuotaPeriod'] = $this->gosaProxyQuotaPeriod;
377 }
379 foreach(array("B","T","F") as $attr){
380 $name = "filter".$attr;
381 if(in_array($name,$this->multi_boxes)){
382 $ret[$name] = preg_match("/".$attr."/",$this->gosaProxyAcctFlags);
383 }
384 }
386 return($ret);
387 }
390 /*! \brief Sets modified attributes in mutliple edit. \
391 All collected values from "get_multi_edit_values()" \
392 will be applied to this plugin.
393 @param array An array containing modified attributes returned by get_multi_edit_values();
394 */
395 public function set_multi_edit_values($values)
396 {
397 plugin::set_multi_edit_values($values);
398 if(isset($values['is_account'])){
399 $this->is_account = $values['is_account'];
400 }
401 foreach(array("B","T","F") as $attr){
402 $name = "filter".$attr;
403 if(isset($values[$name])){
404 if($values[$name] && !preg_match("/".$attr."/",$this->gosaProxyAcctFlags)){
405 $this->gosaProxyAcctFlags = preg_replace("/\]/",$attr."]",$this->gosaProxyAcctFlags);
406 }elseif(!$values[$name] && preg_match("/".$attr."/",$this->gosaProxyAcctFlags)){
407 $this->gosaProxyAcctFlags = preg_replace("/".$attr."/","",$this->gosaProxyAcctFlags);
408 }
409 }
410 }
411 }
414 /*! \brief Initialize multiple edit ui for this plugin. \
415 This function sets plugin defaults in multiple edit.
416 @param array Attributes used in all object
417 @param array All used attributes.
418 */
419 public function init_multiple_support($attrs,$all)
420 {
421 plugin::init_multiple_support($attrs,$all);
422 if(isset($attrs['objectClass']) && in_array("gosaProxyAccount",$attrs['objectClass'])){
423 $this->is_account = TRUE;
424 }
425 }
426 }
428 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
429 ?>